includes/acp/acp_jabber.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Thu, 08 Mar 2012 01:28:49 +0400
changeset 10 2829504a06be
parent 0 ceef6d64c21d
permissions -rw-r--r--
cubometry-style based on prosilver
indvdum@0
     1
<?php
indvdum@0
     2
/**
indvdum@0
     3
*
indvdum@0
     4
* @package acp
indvdum@0
     5
* @version $Id$
indvdum@0
     6
* @copyright (c) 2005 phpBB Group
indvdum@0
     7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
indvdum@0
     8
*
indvdum@0
     9
* @todo Check/enter/update transport info
indvdum@0
    10
*/
indvdum@0
    11
indvdum@0
    12
/**
indvdum@0
    13
* @ignore
indvdum@0
    14
*/
indvdum@0
    15
if (!defined('IN_PHPBB'))
indvdum@0
    16
{
indvdum@0
    17
	exit;
indvdum@0
    18
}
indvdum@0
    19
indvdum@0
    20
/**
indvdum@0
    21
* @package acp
indvdum@0
    22
*/
indvdum@0
    23
class acp_jabber
indvdum@0
    24
{
indvdum@0
    25
	var $u_action;
indvdum@0
    26
indvdum@0
    27
	function main($id, $mode)
indvdum@0
    28
	{
indvdum@0
    29
		global $db, $user, $auth, $template;
indvdum@0
    30
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
indvdum@0
    31
indvdum@0
    32
		$user->add_lang('acp/board');
indvdum@0
    33
indvdum@0
    34
		include_once($phpbb_root_path . 'includes/functions_jabber.' . $phpEx);
indvdum@0
    35
indvdum@0
    36
		$action	= request_var('action', '');
indvdum@0
    37
		$submit = (isset($_POST['submit'])) ? true : false;
indvdum@0
    38
indvdum@0
    39
		if ($mode != 'settings')
indvdum@0
    40
		{
indvdum@0
    41
			return;
indvdum@0
    42
		}
indvdum@0
    43
indvdum@0
    44
		$this->tpl_name = 'acp_jabber';
indvdum@0
    45
		$this->page_title = 'ACP_JABBER_SETTINGS';
indvdum@0
    46
indvdum@0
    47
		$jab_enable			= request_var('jab_enable',			(bool)		$config['jab_enable']);
indvdum@0
    48
		$jab_host			= request_var('jab_host',			(string)	$config['jab_host']);
indvdum@0
    49
		$jab_port			= request_var('jab_port',			(int)		$config['jab_port']);
indvdum@0
    50
		$jab_username		= request_var('jab_username',		(string)	$config['jab_username']);
indvdum@0
    51
		$jab_password		= request_var('jab_password',		(string)	$config['jab_password']);
indvdum@0
    52
		$jab_package_size	= request_var('jab_package_size',	(int)		$config['jab_package_size']);
indvdum@0
    53
		$jab_use_ssl		= request_var('jab_use_ssl',		(bool)		$config['jab_use_ssl']);
indvdum@0
    54
indvdum@0
    55
		$form_name = 'acp_jabber';
indvdum@0
    56
		add_form_key($form_name);
indvdum@0
    57
indvdum@0
    58
		if ($submit)
indvdum@0
    59
		{
indvdum@0
    60
			if (!check_form_key($form_name))
indvdum@0
    61
			{
indvdum@0
    62
				trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
indvdum@0
    63
			}
indvdum@0
    64
indvdum@0
    65
			$error = array();
indvdum@0
    66
indvdum@0
    67
			$message = $user->lang['JAB_SETTINGS_CHANGED'];
indvdum@0
    68
			$log = 'JAB_SETTINGS_CHANGED';
indvdum@0
    69
indvdum@0
    70
			// Is this feature enabled? Then try to establish a connection
indvdum@0
    71
			if ($jab_enable)
indvdum@0
    72
			{
indvdum@0
    73
				$jabber = new jabber($jab_host, $jab_port, $jab_username, $jab_password, $jab_use_ssl);
indvdum@0
    74
indvdum@0
    75
				if (!$jabber->connect())
indvdum@0
    76
				{
indvdum@0
    77
					trigger_error($user->lang['ERR_JAB_CONNECT'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
indvdum@0
    78
				}
indvdum@0
    79
indvdum@0
    80
				// We'll try to authorise using this account
indvdum@0
    81
				if (!$jabber->login())
indvdum@0
    82
				{
indvdum@0
    83
					trigger_error($user->lang['ERR_JAB_AUTH'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
indvdum@0
    84
				}
indvdum@0
    85
indvdum@0
    86
				$jabber->disconnect();
indvdum@0
    87
			}
indvdum@0
    88
			else
indvdum@0
    89
			{
indvdum@0
    90
				// This feature is disabled.
indvdum@0
    91
				// We update the user table to be sure all users that have IM as notify type are set to both as notify type
indvdum@0
    92
				// We set this to both because users still have their jabber address entered and may want to receive jabber notifications again once it is re-enabled.
indvdum@0
    93
				$sql_ary = array(
indvdum@0
    94
					'user_notify_type'		=> NOTIFY_BOTH,
indvdum@0
    95
				);
indvdum@0
    96
indvdum@0
    97
				$sql = 'UPDATE ' . USERS_TABLE . '
indvdum@0
    98
					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
indvdum@0
    99
					WHERE user_notify_type = ' . NOTIFY_IM;
indvdum@0
   100
				$db->sql_query($sql);
indvdum@0
   101
			}
indvdum@0
   102
indvdum@0
   103
			set_config('jab_enable', $jab_enable);
indvdum@0
   104
			set_config('jab_host', $jab_host);
indvdum@0
   105
			set_config('jab_port', $jab_port);
indvdum@0
   106
			set_config('jab_username', $jab_username);
indvdum@0
   107
			set_config('jab_password', $jab_password);
indvdum@0
   108
			set_config('jab_package_size', $jab_package_size);
indvdum@0
   109
			set_config('jab_use_ssl', $jab_use_ssl);
indvdum@0
   110
indvdum@0
   111
			add_log('admin', 'LOG_' . $log);
indvdum@0
   112
			trigger_error($message . adm_back_link($this->u_action));
indvdum@0
   113
		}
indvdum@0
   114
indvdum@0
   115
		$template->assign_vars(array(
indvdum@0
   116
			'U_ACTION'				=> $this->u_action,
indvdum@0
   117
			'JAB_ENABLE'			=> $jab_enable,
indvdum@0
   118
			'L_JAB_SERVER_EXPLAIN'	=> sprintf($user->lang['JAB_SERVER_EXPLAIN'], '<a href="http://www.jabber.org/">', '</a>'),
indvdum@0
   119
			'JAB_HOST'				=> $jab_host,
indvdum@0
   120
			'JAB_PORT'				=> ($jab_port) ? $jab_port : '',
indvdum@0
   121
			'JAB_USERNAME'			=> $jab_username,
indvdum@0
   122
			'JAB_PASSWORD'			=> $jab_password,
indvdum@0
   123
			'JAB_PACKAGE_SIZE'		=> $jab_package_size,
indvdum@0
   124
			'JAB_USE_SSL'			=> $jab_use_ssl,
indvdum@0
   125
			'S_CAN_USE_SSL'			=> jabber::can_use_ssl(),
indvdum@0
   126
			'S_GTALK_NOTE'			=> (!@function_exists('dns_get_record')) ? true : false,
indvdum@0
   127
		));
indvdum@0
   128
	}
indvdum@0
   129
}
indvdum@0
   130
indvdum@0
   131
?>