1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-09 10:16:36 +02:00

[ticket/11698] Moving all autoloadable files to phpbb/

PHPBB3-11698
This commit is contained in:
Nils Adermann
2013-07-14 01:32:34 -04:00
parent 4186c05bb4
commit 7030578bbe
273 changed files with 37 additions and 52 deletions

View File

@@ -560,7 +560,7 @@ class acp_search
return $finder
->extension_suffix('_backend')
->extension_directory('/search')
->core_path('includes/search/')
->core_path('phpbb/search/')
->get_classes();
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +0,0 @@
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>

View File

@@ -1,259 +0,0 @@
<?php
/**
*
* @package auth
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Apache authentication provider for phpBB3
*
* @package auth
*/
class phpbb_auth_provider_apache extends phpbb_auth_provider_base
{
/**
* Apache Authentication Constructor
*
* @param phpbb_db_driver $db
* @param phpbb_config $config
* @param phpbb_request $request
* @param phpbb_user $user
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_request $request, phpbb_user $user, $phpbb_root_path, $php_ext)
{
$this->db = $db;
$this->config = $config;
$this->request = $request;
$this->user = $user;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* {@inheritdoc}
*/
public function init()
{
if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER) || $this->user->data['username'] !== htmlspecialchars_decode($this->request->server('PHP_AUTH_USER')))
{
return $this->user->lang['APACHE_SETUP_BEFORE_USE'];
}
return false;
}
/**
* {@inheritdoc}
*/
public function login($username, $password)
{
// do not allow empty password
if (!$password)
{
return array(
'status' => LOGIN_ERROR_PASSWORD,
'error_msg' => 'NO_PASSWORD_SUPPLIED',
'user_row' => array('user_id' => ANONYMOUS),
);
}
if (!$username)
{
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER))
{
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE',
'user_row' => array('user_id' => ANONYMOUS),
);
}
$php_auth_user = htmlspecialchars_decode($this->request->server('PHP_AUTH_USER'));
$php_auth_pw = htmlspecialchars_decode($this->request->server('PHP_AUTH_PW'));
if (!empty($php_auth_user) && !empty($php_auth_pw))
{
if ($php_auth_user !== $username)
{
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
$sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type
FROM ' . USERS_TABLE . "
WHERE username = '" . $this->db->sql_escape($php_auth_user) . "'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if ($row)
{
// User inactive...
if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
{
return array(
'status' => LOGIN_ERROR_ACTIVE,
'error_msg' => 'ACTIVE_ERROR',
'user_row' => $row,
);
}
// Successful login...
return array(
'status' => LOGIN_SUCCESS,
'error_msg' => false,
'user_row' => $row,
);
}
// this is the user's first login so create an empty profile
return array(
'status' => LOGIN_SUCCESS_CREATE_PROFILE,
'error_msg' => false,
'user_row' => user_row_apache($php_auth_user, $php_auth_pw),
);
}
// Not logged into apache
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE',
'user_row' => array('user_id' => ANONYMOUS),
);
}
/**
* {@inheritdoc}
*/
public function autologin()
{
if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER))
{
return array();
}
$php_auth_user = htmlspecialchars_decode($this->request->server('PHP_AUTH_USER'));
$php_auth_pw = htmlspecialchars_decode($this->request->server('PHP_AUTH_PW'));
if (!empty($php_auth_user) && !empty($php_auth_pw))
{
set_var($php_auth_user, $php_auth_user, 'string', true);
set_var($php_auth_pw, $php_auth_pw, 'string', true);
$sql = 'SELECT *
FROM ' . USERS_TABLE . "
WHERE username = '" . $this->db->sql_escape($php_auth_user) . "'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if ($row)
{
return ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) ? array() : $row;
}
if (!function_exists('user_add'))
{
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
// create the user if he does not exist yet
user_add(user_row_apache($php_auth_user, $php_auth_pw));
$sql = 'SELECT *
FROM ' . USERS_TABLE . "
WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($php_auth_user)) . "'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if ($row)
{
return $row;
}
}
return array();
}
/**
* This function generates an array which can be passed to the user_add
* function in order to create a user
*
* @param string $username The username of the new user.
* @param string $password The password of the new user.
* @return array Contains data that can be passed directly to
* the user_add function.
*/
private function user_row($username, $password)
{
// first retrieve default group id
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'
AND group_type = " . GROUP_SPECIAL;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row)
{
trigger_error('NO_GROUP');
}
// generate user account data
return array(
'username' => $username,
'user_password' => phpbb_hash($password),
'user_email' => '',
'group_id' => (int) $row['group_id'],
'user_type' => USER_NORMAL,
'user_ip' => $this->user->ip,
'user_new' => ($this->config['new_member_post_limit']) ? 1 : 0,
);
}
/**
* {@inheritdoc}
*/
public function validate_session($user)
{
// Check if PHP_AUTH_USER is set and handle this case
if ($this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER))
{
$php_auth_user = $this->request->server('PHP_AUTH_USER');
return ($php_auth_user === $user['username']) ? true : false;
}
// PHP_AUTH_USER is not set. A valid session is now determined by the user type (anonymous/bot or not)
if ($user['user_type'] == USER_IGNORE)
{
return true;
}
return false;
}
}

View File

@@ -1,72 +0,0 @@
<?php
/**
*
* @package auth
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Base authentication provider class that all other providers should implement
*
* @package auth
*/
abstract class phpbb_auth_provider_base implements phpbb_auth_provider_interface
{
/**
* {@inheritdoc}
*/
public function init()
{
return;
}
/**
* {@inheritdoc}
*/
public function autologin()
{
return;
}
/**
* {@inheritdoc}
*/
public function acp()
{
return;
}
/**
* {@inheritdoc}
*/
public function get_acp_template($new_config)
{
return;
}
/**
* {@inheritdoc}
*/
public function logout($data, $new_session)
{
return;
}
/**
* {@inheritdoc}
*/
public function validate_session($user)
{
return;
}
}

View File

@@ -1,297 +0,0 @@
<?php
/**
*
* @package auth
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Database authentication provider for phpBB3
*
* This is for authentication via the integrated user table
*
* @package auth
*/
class phpbb_auth_provider_db extends phpbb_auth_provider_base
{
/**
* Database Authentication Constructor
*
* @param phpbb_db_driver $db
* @param phpbb_config $config
* @param phpbb_request $request
* @param phpbb_user $user
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_request $request, phpbb_user $user, $phpbb_root_path, $php_ext)
{
$this->db = $db;
$this->config = $config;
$this->request = $request;
$this->user = $user;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* {@inheritdoc}
*/
public function login($username, $password)
{
// Auth plugins get the password untrimmed.
// For compatibility we trim() here.
$password = trim($password);
// do not allow empty password
if (!$password)
{
return array(
'status' => LOGIN_ERROR_PASSWORD,
'error_msg' => 'NO_PASSWORD_SUPPLIED',
'user_row' => array('user_id' => ANONYMOUS),
);
}
if (!$username)
{
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
$username_clean = utf8_clean_string($username);
$sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts
FROM ' . USERS_TABLE . "
WHERE username_clean = '" . $this->db->sql_escape($username_clean) . "'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (($this->user->ip && !$this->config['ip_login_limit_use_forwarded']) ||
($this->user->forwarded_for && $this->config['ip_login_limit_use_forwarded']))
{
$sql = 'SELECT COUNT(*) AS attempts
FROM ' . LOGIN_ATTEMPT_TABLE . '
WHERE attempt_time > ' . (time() - (int) $this->config['ip_login_limit_time']);
if ($this->config['ip_login_limit_use_forwarded'])
{
$sql .= " AND attempt_forwarded_for = '" . $this->db->sql_escape($this->user->forwarded_for) . "'";
}
else
{
$sql .= " AND attempt_ip = '" . $this->db->sql_escape($this->user->ip) . "' ";
}
$result = $this->db->sql_query($sql);
$attempts = (int) $this->db->sql_fetchfield('attempts');
$this->db->sql_freeresult($result);
$attempt_data = array(
'attempt_ip' => $this->user->ip,
'attempt_browser' => trim(substr($this->user->browser, 0, 149)),
'attempt_forwarded_for' => $this->user->forwarded_for,
'attempt_time' => time(),
'user_id' => ($row) ? (int) $row['user_id'] : 0,
'username' => $username,
'username_clean' => $username_clean,
);
$sql = 'INSERT INTO ' . LOGIN_ATTEMPT_TABLE . $this->db->sql_build_array('INSERT', $attempt_data);
$result = $this->db->sql_query($sql);
}
else
{
$attempts = 0;
}
if (!$row)
{
if ($this->config['ip_login_limit_max'] && $attempts >= $this->config['ip_login_limit_max'])
{
return array(
'status' => LOGIN_ERROR_ATTEMPTS,
'error_msg' => 'LOGIN_ERROR_ATTEMPTS',
'user_row' => array('user_id' => ANONYMOUS),
);
}
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
$show_captcha = ($this->config['max_login_attempts'] && $row['user_login_attempts'] >= $this->config['max_login_attempts']) ||
($this->config['ip_login_limit_max'] && $attempts >= $this->config['ip_login_limit_max']);
// If there are too many login attempts, we need to check for a confirm image
// Every auth module is able to define what to do by itself...
if ($show_captcha)
{
// Visual Confirmation handling
if (!class_exists('phpbb_captcha_factory', false))
{
include ($this->phpbb_root_path . 'includes/captcha/captcha_factory.' . $this->php_ext);
}
$captcha = phpbb_captcha_factory::get_instance($this->config['captcha_plugin']);
$captcha->init(CONFIRM_LOGIN);
$vc_response = $captcha->validate($row);
if ($vc_response)
{
return array(
'status' => LOGIN_ERROR_ATTEMPTS,
'error_msg' => 'LOGIN_ERROR_ATTEMPTS',
'user_row' => $row,
);
}
else
{
$captcha->reset();
}
}
// If the password convert flag is set we need to convert it
if ($row['user_pass_convert'])
{
// enable super globals to get literal value
// this is needed to prevent unicode normalization
$super_globals_disabled = $this->request->super_globals_disabled();
if ($super_globals_disabled)
{
$this->request->enable_super_globals();
}
// in phpBB2 passwords were used exactly as they were sent, with addslashes applied
$password_old_format = isset($_REQUEST['password']) ? (string) $_REQUEST['password'] : '';
$password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format;
$password_new_format = $this->request->variable('password', '', true);
if ($super_globals_disabled)
{
$this->request->disable_super_globals();
}
if ($password == $password_new_format)
{
if (!function_exists('utf8_to_cp1252'))
{
include($this->phpbb_root_path . 'includes/utf/data/recode_basic.' . $this->php_ext);
}
// cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding
// plain md5 support left in for conversions from other systems.
if ((strlen($row['user_password']) == 34 && (phpbb_check_hash(md5($password_old_format), $row['user_password']) || phpbb_check_hash(md5(utf8_to_cp1252($password_old_format)), $row['user_password'])))
|| (strlen($row['user_password']) == 32 && (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password'])))
{
$hash = phpbb_hash($password_new_format);
// Update the password in the users table to the new format and remove user_pass_convert flag
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_password = \'' . $this->db->sql_escape($hash) . '\',
user_pass_convert = 0
WHERE user_id = ' . $row['user_id'];
$this->db->sql_query($sql);
$row['user_pass_convert'] = 0;
$row['user_password'] = $hash;
}
else
{
// Although we weren't able to convert this password we have to
// increase login attempt count to make sure this cannot be exploited
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_login_attempts = user_login_attempts + 1
WHERE user_id = ' . (int) $row['user_id'] . '
AND user_login_attempts < ' . LOGIN_ATTEMPTS_MAX;
$this->db->sql_query($sql);
return array(
'status' => LOGIN_ERROR_PASSWORD_CONVERT,
'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT',
'user_row' => $row,
);
}
}
}
// Check password ...
if (!$row['user_pass_convert'] && phpbb_check_hash($password, $row['user_password']))
{
// Check for old password hash...
if (strlen($row['user_password']) == 32)
{
$hash = phpbb_hash($password);
// Update the password in the users table to the new format
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_password = '" . $this->db->sql_escape($hash) . "',
user_pass_convert = 0
WHERE user_id = {$row['user_id']}";
$this->db->sql_query($sql);
$row['user_password'] = $hash;
}
$sql = 'DELETE FROM ' . LOGIN_ATTEMPT_TABLE . '
WHERE user_id = ' . $row['user_id'];
$this->db->sql_query($sql);
if ($row['user_login_attempts'] != 0)
{
// Successful, reset login attempts (the user passed all stages)
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_login_attempts = 0
WHERE user_id = ' . $row['user_id'];
$this->db->sql_query($sql);
}
// User inactive...
if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
{
return array(
'status' => LOGIN_ERROR_ACTIVE,
'error_msg' => 'ACTIVE_ERROR',
'user_row' => $row,
);
}
// Successful login... set user_login_attempts to zero...
return array(
'status' => LOGIN_SUCCESS,
'error_msg' => false,
'user_row' => $row,
);
}
// Password incorrect - increase login attempts
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_login_attempts = user_login_attempts + 1
WHERE user_id = ' . (int) $row['user_id'] . '
AND user_login_attempts < ' . LOGIN_ATTEMPTS_MAX;
$this->db->sql_query($sql);
// Give status about wrong password...
return array(
'status' => ($show_captcha) ? LOGIN_ERROR_ATTEMPTS : LOGIN_ERROR_PASSWORD,
'error_msg' => ($show_captcha) ? 'LOGIN_ERROR_ATTEMPTS' : 'LOGIN_ERROR_PASSWORD',
'user_row' => $row,
);
}
}

View File

@@ -1,10 +0,0 @@
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>

View File

@@ -1,105 +0,0 @@
<?php
/**
*
* @package auth
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* The interface authentication provider classes have to implement.
*
* @package auth
*/
interface phpbb_auth_provider_interface
{
/**
* Checks whether the user is currently identified to the authentication
* provider.
* Called in acp_board while setting authentication plugins.
* Changing to an authentication provider will not be permitted in acp_board
* if there is an error.
*
* @return boolean|string False if the user is identified, otherwise an
* error message, or null if not implemented.
*/
public function init();
/**
* Performs login.
*
* @param string $username The name of the user being authenticated.
* @param string $password The password of the user.
* @return array An associative array of the format:
* array(
* 'status' => status constant
* 'error_msg' => string
* 'user_row' => array
* )
*/
public function login($username, $password);
/**
* Autologin function
*
* @return array|null containing the user row, empty if no auto login
* should take place, or null if not impletmented.
*/
public function autologin();
/**
* This function is used to output any required fields in the authentication
* admin panel. It also defines any required configuration table fields.
*
* @return array|null Returns null if not implemented or an array of the
* configuration fields of the provider.
*/
public function acp();
/**
* This function updates the template with variables related to the acp
* options with whatever configuraton values are passed to it as an array.
* It then returns the name of the acp file related to this authentication
* provider.
* @param array $new_config Contains the new configuration values that
* have been set in acp_board.
* @return array|null Returns null if not implemented or an array with
* the template file name and an array of the vars
* that the template needs that must conform to the
* following example:
* array(
* 'TEMPLATE_FILE' => string,
* 'TEMPLATE_VARS' => array(...),
* )
*/
public function get_acp_template($new_config);
/**
* Performs additional actions during logout.
*
* @param array $data An array corresponding to
* phpbb_session::data
* @param boolean $new_session True for a new session, false for no new
* session.
*/
public function logout($data, $new_session);
/**
* The session validation function checks whether the user is still logged
* into phpBB.
*
* @param array $user
* @return boolean true if the given user is authenticated, false if the
* session should be closed, or null if not implemented.
*/
public function validate_session($user);
}

View File

@@ -1,346 +0,0 @@
<?php
/**
*
* @package auth
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Database authentication provider for phpBB3
*
* This is for authentication via the integrated user table
*
* @package auth
*/
class phpbb_auth_provider_ldap extends phpbb_auth_provider_base
{
/**
* LDAP Authentication Constructor
*
* @param phpbb_db_driver $db
* @param phpbb_config $config
* @param phpbb_user $user
*/
public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_user $user)
{
$this->db = $db;
$this->config = $config;
$this->user = $user;
}
/**
* {@inheritdoc}
*/
public function init()
{
if (!@extension_loaded('ldap'))
{
return $this->user->lang['LDAP_NO_LDAP_EXTENSION'];
}
$this->config['ldap_port'] = (int) $this->config['ldap_port'];
if ($this->config['ldap_port'])
{
$ldap = @ldap_connect($this->config['ldap_server'], $this->config['ldap_port']);
}
else
{
$ldap = @ldap_connect($this->config['ldap_server']);
}
if (!$ldap)
{
return $this->user->lang['LDAP_NO_SERVER_CONNECTION'];
}
@ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
if ($this->config['ldap_user'] || $this->config['ldap_password'])
{
if (!@ldap_bind($ldap, htmlspecialchars_decode($this->config['ldap_user']), htmlspecialchars_decode($this->config['ldap_password'])))
{
return $this->user->lang['LDAP_INCORRECT_USER_PASSWORD'];
}
}
// ldap_connect only checks whether the specified server is valid, so the connection might still fail
$search = @ldap_search(
$ldap,
htmlspecialchars_decode($this->config['ldap_base_dn']),
$this->ldap_user_filter($this->user->data['username']),
(empty($this->config['ldap_email'])) ?
array(htmlspecialchars_decode($this->config['ldap_uid'])) :
array(htmlspecialchars_decode($this->config['ldap_uid']), htmlspecialchars_decode($this->config['ldap_email'])),
0,
1
);
if ($search === false)
{
return $this->user->lang['LDAP_SEARCH_FAILED'];
}
$result = @ldap_get_entries($ldap, $search);
@ldap_close($ldap);
if (!is_array($result) || sizeof($result) < 2)
{
return sprintf($this->user->lang['LDAP_NO_IDENTITY'], $this->user->data['username']);
}
if (!empty($this->config['ldap_email']) && !isset($result[0][htmlspecialchars_decode($this->config['ldap_email'])]))
{
return $this->user->lang['LDAP_NO_EMAIL'];
}
return false;
}
/**
* {@inheritdoc}
*/
public function login($username, $password)
{
// do not allow empty password
if (!$password)
{
return array(
'status' => LOGIN_ERROR_PASSWORD,
'error_msg' => 'NO_PASSWORD_SUPPLIED',
'user_row' => array('user_id' => ANONYMOUS),
);
}
if (!$username)
{
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
if (!@extension_loaded('ldap'))
{
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
'error_msg' => 'LDAP_NO_LDAP_EXTENSION',
'user_row' => array('user_id' => ANONYMOUS),
);
}
$this->config['ldap_port'] = (int) $this->config['ldap_port'];
if ($this->config['ldap_port'])
{
$ldap = @ldap_connect($this->config['ldap_server'], $this->config['ldap_port']);
}
else
{
$ldap = @ldap_connect($this->config['ldap_server']);
}
if (!$ldap)
{
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
'error_msg' => 'LDAP_NO_SERVER_CONNECTION',
'user_row' => array('user_id' => ANONYMOUS),
);
}
@ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
if ($this->config['ldap_user'] || $this->config['ldap_password'])
{
if (!@ldap_bind($ldap, htmlspecialchars_decode($this->config['ldap_user']), htmlspecialchars_decode($this->config['ldap_password'])))
{
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
'error_msg' => 'LDAP_NO_SERVER_CONNECTION',
'user_row' => array('user_id' => ANONYMOUS),
);
}
}
$search = @ldap_search(
$ldap,
htmlspecialchars_decode($this->config['ldap_base_dn']),
$this->ldap_user_filter($username),
(empty($this->config['ldap_email'])) ?
array(htmlspecialchars_decode($this->config['ldap_uid'])) :
array(htmlspecialchars_decode($this->config['ldap_uid']), htmlspecialchars_decode($this->config['ldap_email'])),
0,
1
);
$ldap_result = @ldap_get_entries($ldap, $search);
if (is_array($ldap_result) && sizeof($ldap_result) > 1)
{
if (@ldap_bind($ldap, $ldap_result[0]['dn'], htmlspecialchars_decode($password)))
{
@ldap_close($ldap);
$sql ='SELECT user_id, username, user_password, user_passchg, user_email, user_type
FROM ' . USERS_TABLE . "
WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if ($row)
{
unset($ldap_result);
// User inactive...
if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
{
return array(
'status' => LOGIN_ERROR_ACTIVE,
'error_msg' => 'ACTIVE_ERROR',
'user_row' => $row,
);
}
// Successful login... set user_login_attempts to zero...
return array(
'status' => LOGIN_SUCCESS,
'error_msg' => false,
'user_row' => $row,
);
}
else
{
// retrieve default group id
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'
AND group_type = " . GROUP_SPECIAL;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row)
{
trigger_error('NO_GROUP');
}
// generate user account data
$ldap_user_row = array(
'username' => $username,
'user_password' => phpbb_hash($password),
'user_email' => (!empty($this->config['ldap_email'])) ? utf8_htmlspecialchars($ldap_result[0][htmlspecialchars_decode($this->config['ldap_email'])][0]) : '',
'group_id' => (int) $row['group_id'],
'user_type' => USER_NORMAL,
'user_ip' => $this->user->ip,
'user_new' => ($this->config['new_member_post_limit']) ? 1 : 0,
);
unset($ldap_result);
// this is the user's first login so create an empty profile
return array(
'status' => LOGIN_SUCCESS_CREATE_PROFILE,
'error_msg' => false,
'user_row' => $ldap_user_row,
);
}
}
else
{
unset($ldap_result);
@ldap_close($ldap);
// Give status about wrong password...
return array(
'status' => LOGIN_ERROR_PASSWORD,
'error_msg' => 'LOGIN_ERROR_PASSWORD',
'user_row' => array('user_id' => ANONYMOUS),
);
}
}
@ldap_close($ldap);
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
/**
* {@inheritdoc}
*/
public function acp()
{
// These are fields required in the config table
return array(
'ldap_server', 'ldap_port', 'ldap_base_dn', 'ldap_uid', 'ldap_user_filter', 'ldap_email', 'ldap_user', 'ldap_password',
);
}
/**
* {@inheritdoc}
*/
public function get_acp_template($new_config)
{
return array(
'TEMPLATE_FILE' => 'auth_provider_ldap.html',
'TEMPLATE_VARS' => array(
'AUTH_LDAP_DN' => $new_config['ldap_base_dn'],
'AUTH_LDAP_EMAIL' => $new_config['ldap_email'],
'AUTH_LDAP_PASSORD' => $new_config['ldap_password'],
'AUTH_LDAP_PORT' => $new_config['ldap_port'],
'AUTH_LDAP_SERVER' => $new_config['ldap_server'],
'AUTH_LDAP_UID' => $new_config['ldap_uid'],
'AUTH_LDAP_USER' => $new_config['ldap_user'],
'AUTH_LDAP_USER_FILTER' => $new_config['ldap_user_filter'],
),
);
}
/**
* Generates a filter string for ldap_search to find a user
*
* @param $username string Username identifying the searched user
*
* @return string A filter string for ldap_search
*/
private function ldap_user_filter($username)
{
$filter = '(' . $this->config['ldap_uid'] . '=' . $this->ldap_escape(htmlspecialchars_decode($username)) . ')';
if ($this->config['ldap_user_filter'])
{
$_filter = ($this->config['ldap_user_filter'][0] == '(' && substr($this->config['ldap_user_filter'], -1) == ')') ? $this->config['ldap_user_filter'] : "({$this->config['ldap_user_filter']})";
$filter = "(&{$filter}{$_filter})";
}
return $filter;
}
/**
* Escapes an LDAP AttributeValue
*
* @param string $string The string to be escaped
* @return string The escaped string
*/
private function ldap_escape($string)
{
return str_replace(array('*', '\\', '(', ')'), array('\\*', '\\\\', '\\(', '\\)'), $string);
}
}

View File

@@ -1,138 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Base class for avatar drivers
* @package phpBB3
*/
abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface
{
/**
* Avatar driver name
* @var string
*/
protected $name;
/**
* Current board configuration
* @var phpbb_config
*/
protected $config;
/**
* Current $phpbb_root_path
* @var string
*/
protected $phpbb_root_path;
/**
* Current $php_ext
* @var string
*/
protected $php_ext;
/**
* Cache driver
* @var phpbb_cache_driver_interface
*/
protected $cache;
/**
* Array of allowed avatar image extensions
* Array is used for setting the allowed extensions in the fileupload class
* and as a base for a regex of allowed extensions, which will be formed by
* imploding the array with a "|".
*
* @var array
*/
protected $allowed_extensions = array(
'gif',
'jpg',
'jpeg',
'png',
);
/**
* Construct a driver object
*
* @param phpbb_config $config phpBB configuration
* @param phpbb_request $request Request object
* @param string $phpbb_root_path Path to the phpBB root
* @param string $php_ext PHP file extension
* @param phpbb_cache_driver_interface $cache Cache driver
*/
public function __construct(phpbb_config $config, $phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null)
{
$this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->cache = $cache;
}
/**
* @inheritdoc
*/
public function get_custom_html($user, $row, $alt = '')
{
return '';
}
/**
* @inheritdoc
*/
public function prepare_form_acp($user)
{
return array();
}
/**
* @inheritdoc
*/
public function delete($row)
{
return true;
}
/**
* @inheritdoc
*/
public function get_template_name()
{
$driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this));
$template = "ucp_avatar_options_$driver.html";
return $template;
}
/**
* @inheritdoc
*/
public function get_name()
{
return $this->name;
}
/**
* Sets the name of the driver.
*
* @param string $name Driver name
*/
public function set_name($name)
{
$this->name = $name;
}
}

View File

@@ -1,172 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Handles avatars hosted at gravatar.com
* @package phpBB3
*/
class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver
{
/**
* The URL for the gravatar service
*/
const GRAVATAR_URL = '//secure.gravatar.com/avatar/';
/**
* @inheritdoc
*/
public function get_data($row)
{
return array(
'src' => $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
/**
* @inheritdoc
*/
public function get_custom_html($user, $row, $alt = '')
{
return '<img src="' . $this->get_gravatar_url($row) . '" ' .
($row['avatar_width'] ? ('width="' . $row['avatar_width'] . '" ') : '') .
($row['avatar_height'] ? ('height="' . $row['avatar_height'] . '" ') : '') .
'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
}
/**
* @inheritdoc
*/
public function prepare_form($request, $template, $user, $row, &$error)
{
$template->assign_vars(array(
'AVATAR_GRAVATAR_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $request->variable('avatar_gravatar_width', 0),
'AVATAR_GRAVATAR_HEIGHT' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_height']) ? $row['avatar_height'] : $request->variable('avatar_gravatar_width', 0),
'AVATAR_GRAVATAR_EMAIL' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar']) ? $row['avatar'] : '',
));
return true;
}
/**
* @inheritdoc
*/
public function process_form($request, $template, $user, $row, &$error)
{
$row['avatar'] = $request->variable('avatar_gravatar_email', '');
$row['avatar_width'] = $request->variable('avatar_gravatar_width', 0);
$row['avatar_height'] = $request->variable('avatar_gravatar_height', 0);
if (!function_exists('validate_data'))
{
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
$validate_array = validate_data(
array(
'email' => $row['avatar'],
),
array(
'email' => array(
array('string', false, 6, 60),
array('email'))
)
);
$error = array_merge($error, $validate_array);
if (!empty($error))
{
return false;
}
// Make sure getimagesize works...
if (function_exists('getimagesize') && ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0))
{
/**
* default to the minimum of the maximum allowed avatar size if the size
* is not or only partially entered
*/
$row['avatar_width'] = $row['avatar_height'] = min($this->config['avatar_max_width'], $this->config['avatar_max_height']);
$url = $this->get_gravatar_url($row);
if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = getimagesize($url)) === false))
{
$error[] = 'UNABLE_GET_IMAGE_SIZE';
return false;
}
if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
{
$error[] = 'AVATAR_NO_SIZE';
return false;
}
$row['avatar_width'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_width'] : $image_data[0];
$row['avatar_height'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_height'] : $image_data[1];
}
if ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0)
{
$error[] = 'AVATAR_NO_SIZE';
return false;
}
if ($this->config['avatar_max_width'] || $this->config['avatar_max_height'])
{
if ($row['avatar_width'] > $this->config['avatar_max_width'] || $row['avatar_height'] > $this->config['avatar_max_height'])
{
$error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $row['avatar_width'], $row['avatar_height']);
return false;
}
}
if ($this->config['avatar_min_width'] || $this->config['avatar_min_height'])
{
if ($row['avatar_width'] < $this->config['avatar_min_width'] || $row['avatar_height'] < $this->config['avatar_min_height'])
{
$error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $row['avatar_width'], $row['avatar_height']);
return false;
}
}
return array(
'avatar' => $row['avatar'],
'avatar_width' => $row['avatar_width'],
'avatar_height' => $row['avatar_height'],
);
}
/**
* Build gravatar URL for output on page
*
* @return string Gravatar URL
*/
protected function get_gravatar_url($row)
{
$url = self::GRAVATAR_URL;
$url .= md5(strtolower(trim($row['avatar'])));
if ($row['avatar_width'] || $row['avatar_height'])
{
$url .= '?s=' . max($row['avatar_width'], $row['avatar_height']);
}
return $url;
}
}

View File

@@ -1,116 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Interface for avatar drivers
* @package phpBB3
*/
interface phpbb_avatar_driver_interface
{
/**
* Returns the name of the driver.
*
* @return string Name of driver.
*/
public function get_name();
/**
* Get the avatar url and dimensions
*
* @param array $row User data or group data that has been cleaned with
* phpbb_avatar_manager::clean_row
* @return array Avatar data, must have keys src, width and height, e.g.
* ['src' => '', 'width' => 0, 'height' => 0]
*/
public function get_data($row);
/**
* Returns custom html if it is needed for displaying this avatar
*
* @param phpbb_user $user phpBB user object
* @param array $row User data or group data that has been cleaned with
* phpbb_avatar_manager::clean_row
* @param string $alt Alternate text for avatar image
*
* @return string HTML
*/
public function get_custom_html($user, $row, $alt = '');
/**
* Prepare form for changing the settings of this avatar
*
* @param phpbb_request $request Request object
* @param phpbb_template $template Template object
* @param phpbb_user $user User object
* @param array $row User data or group data that has been cleaned with
* phpbb_avatar_manager::clean_row
* @param array &$error Reference to an error array that is filled by this
* function. Key values can either be a string with a language key or
* an array that will be passed to vsprintf() with the language key in
* the first array key.
*
* @return bool True if form has been successfully prepared
*/
public function prepare_form($request, $template, $user, $row, &$error);
/**
* Prepare form for changing the acp settings of this avatar
*
* @param phpbb_user $user phpBB user object
*
* @return array Array of configuration options as consumed by acp_board.
* The setting for enabling/disabling the avatar will be handled by
* the avatar manager.
*/
public function prepare_form_acp($user);
/**
* Process form data
*
* @param phpbb_request $request Request object
* @param phpbb_template $template Template object
* @param phpbb_user $user User object
* @param array $row User data or group data that has been cleaned with
* phpbb_avatar_manager::clean_row
* @param array &$error Reference to an error array that is filled by this
* function. Key values can either be a string with a language key or
* an array that will be passed to vsprintf() with the language key in
* the first array key.
*
* @return array Array containing the avatar data as follows:
* ['avatar'], ['avatar_width'], ['avatar_height']
*/
public function process_form($request, $template, $user, $row, &$error);
/**
* Delete avatar
*
* @param array $row User data or group data that has been cleaned with
* phpbb_avatar_manager::clean_row
*
* @return bool True if avatar has been deleted or there is no need to delete,
* i.e. when the avatar is not hosted locally.
*/
public function delete($row);
/**
* Get the avatar driver's template name
*
* @return string Avatar driver's template name
*/
public function get_template_name();
}

View File

@@ -1,197 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Handles avatars selected from the board gallery
* @package phpBB3
*/
class phpbb_avatar_driver_local extends phpbb_avatar_driver
{
/**
* @inheritdoc
*/
public function get_data($row)
{
return array(
'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
/**
* @inheritdoc
*/
public function prepare_form($request, $template, $user, $row, &$error)
{
$avatar_list = $this->get_avatar_list($user);
$category = $request->variable('avatar_local_cat', '');
foreach ($avatar_list as $cat => $null)
{
if (!empty($avatar_list[$cat]))
{
$template->assign_block_vars('avatar_local_cats', array(
'NAME' => $cat,
'SELECTED' => ($cat == $category),
));
}
if ($cat != $category)
{
unset($avatar_list[$cat]);
}
}
if (!empty($avatar_list[$category]))
{
$template->assign_vars(array(
'AVATAR_LOCAL_SHOW' => true,
));
$table_cols = isset($row['avatar_gallery_cols']) ? $row['avatar_gallery_cols'] : 4;
$row_count = $col_count = $avatar_pos = 0;
$avatar_count = sizeof($avatar_list[$category]);
reset($avatar_list[$category]);
while ($avatar_pos < $avatar_count)
{
$img = current($avatar_list[$category]);
next($avatar_list[$category]);
if ($col_count == 0)
{
++$row_count;
$template->assign_block_vars('avatar_local_row', array(
));
}
$template->assign_block_vars('avatar_local_row.avatar_local_col', array(
'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'],
'AVATAR_NAME' => $img['name'],
'AVATAR_FILE' => $img['filename'],
));
$template->assign_block_vars('avatar_local_row.avatar_local_option', array(
'AVATAR_FILE' => $img['filename'],
'S_OPTIONS_AVATAR' => $img['filename']
));
$col_count = ($col_count + 1) % $table_cols;
++$avatar_pos;
}
}
return true;
}
/**
* @inheritdoc
*/
public function prepare_form_acp($user)
{
return array(
'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true),
);
}
/**
* @inheritdoc
*/
public function process_form($request, $template, $user, $row, &$error)
{
$avatar_list = $this->get_avatar_list($user);
$category = $request->variable('avatar_local_cat', '');
$file = $request->variable('avatar_local_file', '');
if (empty($category) || empty($file))
{
$error[] = 'NO_AVATAR_SELECTED';
return false;
}
if (!isset($avatar_list[$category][urldecode($file)]))
{
$error[] = 'AVATAR_URL_NOT_FOUND';
return false;
}
return array(
'avatar' => ($category != $user->lang['MAIN']) ? $category . '/' . $file : $file,
'avatar_width' => $avatar_list[$category][urldecode($file)]['width'],
'avatar_height' => $avatar_list[$category][urldecode($file)]['height'],
);
}
/**
* Get a list of avatars that are locally available
* Results get cached for 24 hours (86400 seconds)
*
* @param phpbb_user $user User object
*
* @return array Array containing the locally available avatars
*/
protected function get_avatar_list($user)
{
$avatar_list = ($this->cache == null) ? false : $this->cache->get('avatar_local_list');
if ($avatar_list === false)
{
$avatar_list = array();
$path = $this->phpbb_root_path . $this->config['avatar_gallery_path'];
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file_info)
{
$file_path = $file_info->getPath();
$image = $file_info->getFilename();
// Match all images in the gallery folder
if (preg_match('#^[^&\'"<>]+\.(?:' . implode('|', $this->allowed_extensions) . ')$#i', $image) && is_file($file_path . '/' . $image))
{
if (function_exists('getimagesize'))
{
$dims = getimagesize($file_path . '/' . $image);
}
else
{
$dims = array(0, 0);
}
$cat = ($path == $file_path) ? $user->lang['MAIN'] : str_replace("$path/", '', $file_path);
$avatar_list[$cat][$image] = array(
'file' => ($cat != $user->lang['MAIN']) ? rawurlencode($cat) . '/' . rawurlencode($image) : rawurlencode($image),
'filename' => rawurlencode($image),
'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))),
'width' => $dims[0],
'height' => $dims[1],
);
}
}
ksort($avatar_list);
if ($this->cache != null)
{
$this->cache->put('avatar_local_list', $avatar_list, 86400);
}
}
return $avatar_list;
}
}

View File

@@ -1,164 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Handles avatars hosted remotely
* @package phpBB3
*/
class phpbb_avatar_driver_remote extends phpbb_avatar_driver
{
/**
* @inheritdoc
*/
public function get_data($row)
{
return array(
'src' => $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
/**
* @inheritdoc
*/
public function prepare_form($request, $template, $user, $row, &$error)
{
$template->assign_vars(array(
'AVATAR_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $request->variable('avatar_remote_width', 0),
'AVATAR_REMOTE_HEIGHT' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_height']) ? $row['avatar_height'] : $request->variable('avatar_remote_width', 0),
'AVATAR_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '',
));
return true;
}
/**
* @inheritdoc
*/
public function process_form($request, $template, $user, $row, &$error)
{
$url = $request->variable('avatar_remote_url', '');
$width = $request->variable('avatar_remote_width', 0);
$height = $request->variable('avatar_remote_height', 0);
if (!preg_match('#^(http|https|ftp)://#i', $url))
{
$url = 'http://' . $url;
}
if (!function_exists('validate_data'))
{
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
$validate_array = validate_data(
array(
'url' => $url,
),
array(
'url' => array('string', true, 5, 255),
)
);
$error = array_merge($error, $validate_array);
if (!empty($error))
{
return false;
}
// Check if this url looks alright
// This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible
if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.('. implode('|', $this->allowed_extensions) . ')$#i', $url))
{
$error[] = 'AVATAR_URL_INVALID';
return false;
}
// Make sure getimagesize works...
if (function_exists('getimagesize'))
{
if (($width <= 0 || $height <= 0) && (($image_data = getimagesize($url)) === false))
{
$error[] = 'UNABLE_GET_IMAGE_SIZE';
return false;
}
if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
{
$error[] = 'AVATAR_NO_SIZE';
return false;
}
$width = ($width && $height) ? $width : $image_data[0];
$height = ($width && $height) ? $height : $image_data[1];
}
if ($width <= 0 || $height <= 0)
{
$error[] = 'AVATAR_NO_SIZE';
return false;
}
if (!class_exists('fileupload'))
{
include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext);
}
$types = fileupload::image_types();
$extension = strtolower(filespec::get_extension($url));
if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]])))
{
if (!isset($types[$image_data[2]]))
{
$error[] = 'UNABLE_GET_IMAGE_SIZE';
}
else
{
$error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
}
return false;
}
if ($this->config['avatar_max_width'] || $this->config['avatar_max_height'])
{
if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height'])
{
$error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
return false;
}
}
if ($this->config['avatar_min_width'] || $this->config['avatar_min_height'])
{
if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height'])
{
$error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
return false;
}
}
return array(
'avatar' => $url,
'avatar_width' => $width,
'avatar_height' => $height,
);
}
}

View File

@@ -1,185 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Handles avatars uploaded to the board
* @package phpBB3
*/
class phpbb_avatar_driver_upload extends phpbb_avatar_driver
{
/**
* @inheritdoc
*/
public function get_data($row, $ignore_config = false)
{
return array(
'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
/**
* @inheritdoc
*/
public function prepare_form($request, $template, $user, $row, &$error)
{
if (!$this->can_upload())
{
return false;
}
$template->assign_vars(array(
'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false,
'AVATAR_UPLOAD_SIZE' => $this->config['avatar_filesize'],
));
return true;
}
/**
* @inheritdoc
*/
public function process_form($request, $template, $user, $row, &$error)
{
if (!$this->can_upload())
{
return false;
}
if (!class_exists('fileupload'))
{
include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext);
}
$upload = new fileupload('AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false));
$url = $request->variable('avatar_upload_url', '');
$upload_file = $request->file('avatar_upload_file');
if (!empty($upload_file['name']))
{
$file = $upload->form_upload('avatar_upload_file');
}
elseif (!empty($this->config['allow_avatar_remote_upload']) && !empty($url))
{
if (!preg_match('#^(http|https|ftp)://#i', $url))
{
$url = 'http://' . $url;
}
if (!function_exists('validate_data'))
{
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
$validate_array = validate_data(
array(
'url' => $url,
),
array(
'url' => array('string', true, 5, 255),
)
);
$error = array_merge($error, $validate_array);
if (!empty($error))
{
return false;
}
$file = $upload->remote_upload($url);
}
else
{
$error[] = 'NO_AVATAR_SELECTED';
return false;
}
$prefix = $this->config['avatar_salt'] . '_';
$file->clean_filename('avatar', $prefix, $row['id']);
$destination = $this->config['avatar_path'];
// Adjust destination path (no trailing slash)
if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
{
$destination = substr($destination, 0, -1);
}
$destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
{
$destination = '';
}
// Move file and overwrite any existing image
$file->move_file($destination, true);
if (sizeof($file->error))
{
$file->remove();
$error = array_merge($error, $file->error);
return false;
}
return array(
'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'),
'avatar_width' => $file->get('width'),
'avatar_height' => $file->get('height'),
);
}
/**
* @inheritdoc
*/
public function prepare_form_acp($user)
{
return array(
'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'avatar_filesize' => array('lang' => 'MAX_FILESIZE', 'validate' => 'int:0', 'type' => 'number:0', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rwpath', 'type' => 'text:20:255', 'explain' => true),
);
}
/**
* @inheritdoc
*/
public function delete($row)
{
$ext = substr(strrchr($row['avatar'], '.'), 1);
$filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext;
if (file_exists($filename))
{
@unlink($filename);
}
return true;
}
/**
* Check if user is able to upload an avatar
*
* @return bool True if user can upload, false if not
*/
protected function can_upload()
{
return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on'));
}
}

View File

@@ -1,309 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* @package avatar
*/
class phpbb_avatar_manager
{
/**
* phpBB configuration
* @var phpbb_config
*/
protected $config;
/**
* Array that contains a list of enabled drivers
* @var array
*/
static protected $enabled_drivers = false;
/**
* Array that contains all available avatar drivers which are passed via the
* service container
* @var array
*/
protected $avatar_drivers;
/**
* Service container object
* @var object
*/
protected $container;
/**
* Default avatar data row
* @var array
*/
static protected $default_row = array(
'avatar' => '',
'avatar_type' => '',
'avatar_width' => '',
'avatar_height' => '',
);
/**
* Construct an avatar manager object
*
* @param phpbb_config $config phpBB configuration
* @param array $avatar_drivers Avatar drivers passed via the service container
* @param object $container Container object
*/
public function __construct(phpbb_config $config, $avatar_drivers, $container)
{
$this->config = $config;
$this->avatar_drivers = $avatar_drivers;
$this->container = $container;
}
/**
* Get the driver object specified by the avatar type
*
* @param string $avatar_type Avatar type; by default an avatar's service container name
* @param bool $load_enabled Load only enabled avatars
*
* @return object Avatar driver object
*/
public function get_driver($avatar_type, $load_enabled = true)
{
if (self::$enabled_drivers === false)
{
$this->load_enabled_drivers();
}
$avatar_drivers = ($load_enabled) ? self::$enabled_drivers : $this->get_all_drivers();
// Legacy stuff...
switch ($avatar_type)
{
case AVATAR_GALLERY:
$avatar_type = 'avatar.driver.local';
break;
case AVATAR_UPLOAD:
$avatar_type = 'avatar.driver.upload';
break;
case AVATAR_REMOTE:
$avatar_type = 'avatar.driver.remote';
break;
}
if (!isset($avatar_drivers[$avatar_type]))
{
return null;
}
/*
* There is no need to handle invalid avatar types as the following code
* will cause a ServiceNotFoundException if the type does not exist
*/
$driver = $this->container->get($avatar_type);
return $driver;
}
/**
* Load the list of enabled drivers
* This is executed once and fills self::$enabled_drivers
*/
protected function load_enabled_drivers()
{
if (!empty($this->avatar_drivers))
{
self::$enabled_drivers = array();
foreach ($this->avatar_drivers as $driver)
{
if ($this->is_enabled($driver))
{
self::$enabled_drivers[$driver->get_name()] = $driver->get_name();
}
}
asort(self::$enabled_drivers);
}
}
/**
* Get a list of all avatar drivers
*
* As this function will only be called in the ACP avatar settings page, it
* doesn't make much sense to cache the list of all avatar drivers like the
* list of the enabled drivers.
*
* @return array Array containing a list of all avatar drivers
*/
public function get_all_drivers()
{
$drivers = array();
if (!empty($this->avatar_drivers))
{
foreach ($this->avatar_drivers as $driver)
{
$drivers[$driver->get_name()] = $driver->get_name();
}
asort($drivers);
}
return $drivers;
}
/**
* Get a list of enabled avatar drivers
*
* @return array Array containing a list of the enabled avatar drivers
*/
public function get_enabled_drivers()
{
if (self::$enabled_drivers === false)
{
$this->load_enabled_drivers();
}
return self::$enabled_drivers;
}
/**
* Strip out user_ and group_ prefixes from keys
*
* @param array $row User data or group data
*
* @return array User data or group data with keys that have been
* stripped from the preceding "user_" or "group_"
*/
static public function clean_row($row)
{
// Upon creation of a user/group $row might be empty
if (empty($row))
{
return self::$default_row;
}
$keys = array_keys($row);
$values = array_values($row);
$keys = array_map(array('phpbb_avatar_manager', 'strip_prefix'), $keys);
return array_combine($keys, $values);
}
/**
* Strip prepending user_ or group_ prefix from key
*
* @param string Array key
* @return string Key that has been stripped from its prefix
*/
static protected function strip_prefix($key)
{
return preg_replace('#^(?:user_|group_)#', '', $key);
}
/**
* Clean driver names that are returned from template files
* Underscores are replaced with dots
*
* @param string $name Driver name
*
* @return string Cleaned driver name
*/
static public function clean_driver_name($name)
{
return str_replace('_', '.', $name);
}
/**
* Prepare driver names for use in template files
* Dots are replaced with underscores
*
* @param string $name Clean driver name
*
* @return string Prepared driver name
*/
static public function prepare_driver_name($name)
{
return str_replace('.', '_', $name);
}
/**
* Check if avatar is enabled
*
* @param object $driver Avatar driver object
*
* @return bool True if avatar is enabled, false if it's disabled
*/
public function is_enabled($driver)
{
$config_name = $this->get_driver_config_name($driver);
return $this->config["allow_avatar_{$config_name}"];
}
/**
* Get the settings array for enabling/disabling an avatar driver
*
* @param object $driver Avatar driver object
*
* @return array Array of configuration options as consumed by acp_board
*/
public function get_avatar_settings($driver)
{
$config_name = $this->get_driver_config_name($driver);
return array(
'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper($config_name), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
);
}
/**
* Get the config name of an avatar driver
*
* @param object $driver Avatar driver object
*
* @return string Avatar driver config name
*/
public function get_driver_config_name($driver)
{
return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver));
}
/**
* Replace "error" strings with their real, localized form
*
* @param phpbb_user phpBB User object
* @param array $error Array containing error strings
* Key values can either be a string with a language key or an array
* that will be passed to vsprintf() with the language key in the
* first array key.
*
* @return array Array containing the localized error strings
*/
public function localize_errors(phpbb_user $user, $error)
{
foreach ($error as $key => $lang)
{
if (is_array($lang))
{
$lang_key = array_shift($lang);
$error[$key] = vsprintf($user->lang($lang_key), $lang);
}
else
{
$error[$key] = $user->lang("$lang");
}
}
return $error;
}
}

View File

@@ -1,75 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005, 2009 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ACM for APC
* @package acm
*/
class phpbb_cache_driver_apc extends phpbb_cache_driver_memory
{
var $extension = 'apc';
/**
* Purge cache data
*
* @return null
*/
function purge()
{
apc_clear_cache('user');
parent::purge();
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
{
return apc_fetch($this->key_prefix . $var);
}
/**
* Store data in the cache
*
* @access protected
* @param string $var Cache key
* @param mixed $data Data to store
* @param int $ttl Time-to-live of cached data
* @return bool True if the operation succeeded
*/
function _write($var, $data, $ttl = 2592000)
{
return apc_store($this->key_prefix . $var, $data, $ttl);
}
/**
* Remove an item from the cache
*
* @access protected
* @param string $var Cache key
* @return bool True if the operation succeeded
*/
function _delete($var)
{
return apc_delete($this->key_prefix . $var);
}
}

View File

@@ -1,23 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* @package acm
*/
abstract class phpbb_cache_driver_base implements phpbb_cache_driver_interface
{
}

View File

@@ -1,112 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005, 2009 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ACM for eAccelerator
* @package acm
* @todo Missing locks from destroy() talk with David
*/
class phpbb_cache_driver_eaccelerator extends phpbb_cache_driver_memory
{
var $extension = 'eaccelerator';
var $function = 'eaccelerator_get';
var $serialize_header = '#phpbb-serialized#';
/**
* Purge cache data
*
* @return null
*/
function purge()
{
foreach (eaccelerator_list_keys() as $var)
{
// @todo Check why the substr()
// @todo Only unset vars matching $this->key_prefix
eaccelerator_rm(substr($var['name'], 1));
}
parent::purge();
}
/**
* Perform cache garbage collection
*
* @return null
*/
function tidy()
{
eaccelerator_gc();
set_config('cache_last_gc', time(), true);
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
{
$result = eaccelerator_get($this->key_prefix . $var);
if ($result === null)
{
return false;
}
// Handle serialized objects
if (is_string($result) && strpos($result, $this->serialize_header . 'O:') === 0)
{
$result = unserialize(substr($result, strlen($this->serialize_header)));
}
return $result;
}
/**
* Store data in the cache
*
* @access protected
* @param string $var Cache key
* @param mixed $data Data to store
* @param int $ttl Time-to-live of cached data
* @return bool True if the operation succeeded
*/
function _write($var, $data, $ttl = 2592000)
{
// Serialize objects and make them easy to detect
$data = (is_object($data)) ? $this->serialize_header . serialize($data) : $data;
return eaccelerator_put($this->key_prefix . $var, $data, $ttl);
}
/**
* Remove an item from the cache
*
* @access protected
* @param string $var Cache key
* @return bool True if the operation succeeded
*/
function _delete($var)
{
return eaccelerator_rm($this->key_prefix . $var);
}
}

View File

@@ -1,740 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005, 2009 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ACM File Based Caching
* @package acm
*/
class phpbb_cache_driver_file extends phpbb_cache_driver_base
{
var $vars = array();
var $var_expires = array();
var $is_modified = false;
var $sql_rowset = array();
var $sql_row_pointer = array();
var $cache_dir = '';
/**
* Set cache path
*/
function __construct($cache_dir = null)
{
global $phpbb_root_path;
$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/';
}
/**
* Load global cache
*/
function load()
{
return $this->_read('data_global');
}
/**
* Unload cache object
*/
function unload()
{
$this->save();
unset($this->vars);
unset($this->var_expires);
unset($this->sql_rowset);
unset($this->sql_row_pointer);
$this->vars = array();
$this->var_expires = array();
$this->sql_rowset = array();
$this->sql_row_pointer = array();
}
/**
* Save modified objects
*/
function save()
{
if (!$this->is_modified)
{
return;
}
global $phpEx;
if (!$this->_write('data_global'))
{
if (!function_exists('phpbb_is_writable'))
{
global $phpbb_root_path;
include($phpbb_root_path . 'includes/functions.' . $phpEx);
}
// Now, this occurred how often? ... phew, just tell the user then...
if (!phpbb_is_writable($this->cache_dir))
{
// We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())
die('Fatal: ' . $this->cache_dir . ' is NOT writable.');
exit;
}
die('Fatal: Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx);
exit;
}
$this->is_modified = false;
}
/**
* Tidy cache
*/
function tidy()
{
global $phpEx;
$dir = @opendir($this->cache_dir);
if (!$dir)
{
return;
}
$time = time();
while (($entry = readdir($dir)) !== false)
{
if (!preg_match('/^(sql_|data_(?!global))/', $entry))
{
continue;
}
if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
{
continue;
}
// Skip the PHP header
fgets($handle);
// Skip expiration
$expires = (int) fgets($handle);
fclose($handle);
if ($time >= $expires)
{
$this->remove_file($this->cache_dir . $entry);
}
}
closedir($dir);
if (file_exists($this->cache_dir . 'data_global.' . $phpEx))
{
if (!sizeof($this->vars))
{
$this->load();
}
foreach ($this->var_expires as $var_name => $expires)
{
if ($time >= $expires)
{
$this->destroy($var_name);
}
}
}
set_config('cache_last_gc', time(), true);
}
/**
* Get saved cache object
*/
function get($var_name)
{
if ($var_name[0] == '_')
{
global $phpEx;
if (!$this->_exists($var_name))
{
return false;
}
return $this->_read('data' . $var_name);
}
else
{
return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
}
}
/**
* Put data into cache
*/
function put($var_name, $var, $ttl = 31536000)
{
if ($var_name[0] == '_')
{
$this->_write('data' . $var_name, $var, time() + $ttl);
}
else
{
$this->vars[$var_name] = $var;
$this->var_expires[$var_name] = time() + $ttl;
$this->is_modified = true;
}
}
/**
* Purge cache data
*/
function purge()
{
// Purge all phpbb cache files
$dir = @opendir($this->cache_dir);
if (!$dir)
{
return;
}
while (($entry = readdir($dir)) !== false)
{
if (strpos($entry, 'container_') !== 0 &&
strpos($entry, 'url_matcher') !== 0 &&
strpos($entry, 'sql_') !== 0 &&
strpos($entry, 'data_') !== 0 &&
strpos($entry, 'ctpl_') !== 0 &&
strpos($entry, 'tpl_') !== 0)
{
continue;
}
$this->remove_file($this->cache_dir . $entry);
}
closedir($dir);
unset($this->vars);
unset($this->var_expires);
unset($this->sql_rowset);
unset($this->sql_row_pointer);
$this->vars = array();
$this->var_expires = array();
$this->sql_rowset = array();
$this->sql_row_pointer = array();
$this->is_modified = false;
}
/**
* Destroy cache data
*/
function destroy($var_name, $table = '')
{
global $phpEx;
if ($var_name == 'sql' && !empty($table))
{
if (!is_array($table))
{
$table = array($table);
}
$dir = @opendir($this->cache_dir);
if (!$dir)
{
return;
}
while (($entry = readdir($dir)) !== false)
{
if (strpos($entry, 'sql_') !== 0)
{
continue;
}
if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
{
continue;
}
// Skip the PHP header
fgets($handle);
// Skip expiration
fgets($handle);
// Grab the query, remove the LF
$query = substr(fgets($handle), 0, -1);
fclose($handle);
foreach ($table as $check_table)
{
// Better catch partial table names than no table names. ;)
if (strpos($query, $check_table) !== false)
{
$this->remove_file($this->cache_dir . $entry);
break;
}
}
}
closedir($dir);
return;
}
if (!$this->_exists($var_name))
{
return;
}
if ($var_name[0] == '_')
{
$this->remove_file($this->cache_dir . 'data' . $var_name . ".$phpEx", true);
}
else if (isset($this->vars[$var_name]))
{
$this->is_modified = true;
unset($this->vars[$var_name]);
unset($this->var_expires[$var_name]);
// We save here to let the following cache hits succeed
$this->save();
}
}
/**
* Check if a given cache entry exist
*/
function _exists($var_name)
{
if ($var_name[0] == '_')
{
global $phpEx;
return file_exists($this->cache_dir . 'data' . $var_name . ".$phpEx");
}
else
{
if (!sizeof($this->vars))
{
$this->load();
}
if (!isset($this->var_expires[$var_name]))
{
return false;
}
return (time() > $this->var_expires[$var_name]) ? false : isset($this->vars[$var_name]);
}
}
/**
* Load cached sql query
*/
function sql_load($query)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
if (($rowset = $this->_read('sql_' . md5($query))) === false)
{
return false;
}
$query_id = sizeof($this->sql_rowset);
$this->sql_rowset[$query_id] = $rowset;
$this->sql_row_pointer[$query_id] = 0;
return $query_id;
}
/**
* {@inheritDoc}
*/
function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
$query_id = sizeof($this->sql_rowset);
$this->sql_rowset[$query_id] = array();
$this->sql_row_pointer[$query_id] = 0;
while ($row = $db->sql_fetchrow($query_result))
{
$this->sql_rowset[$query_id][] = $row;
}
$db->sql_freeresult($query_result);
if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query))
{
return $query_id;
}
return $query_result;
}
/**
* Ceck if a given sql query exist in cache
*/
function sql_exists($query_id)
{
return isset($this->sql_rowset[$query_id]);
}
/**
* Fetch row from cache (database)
*/
function sql_fetchrow($query_id)
{
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
{
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
}
return false;
}
/**
* Fetch a field from the current row of a cached database result (database)
*/
function sql_fetchfield($query_id, $field)
{
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
{
return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false;
}
return false;
}
/**
* Seek a specific row in an a cached database result (database)
*/
function sql_rowseek($rownum, $query_id)
{
if ($rownum >= sizeof($this->sql_rowset[$query_id]))
{
return false;
}
$this->sql_row_pointer[$query_id] = $rownum;
return true;
}
/**
* Free memory used for a cached database result (database)
*/
function sql_freeresult($query_id)
{
if (!isset($this->sql_rowset[$query_id]))
{
return false;
}
unset($this->sql_rowset[$query_id]);
unset($this->sql_row_pointer[$query_id]);
return true;
}
/**
* Read cached data from a specified file
*
* @access private
* @param string $filename Filename to write
* @return mixed False if an error was encountered, otherwise the data type of the cached data
*/
function _read($filename)
{
global $phpEx;
$file = "{$this->cache_dir}$filename.$phpEx";
$type = substr($filename, 0, strpos($filename, '_'));
if (!file_exists($file))
{
return false;
}
if (!($handle = @fopen($file, 'rb')))
{
return false;
}
// Skip the PHP header
fgets($handle);
if ($filename == 'data_global')
{
$this->vars = $this->var_expires = array();
$time = time();
while (($expires = (int) fgets($handle)) && !feof($handle))
{
// Number of bytes of data
$bytes = substr(fgets($handle), 0, -1);
if (!is_numeric($bytes) || ($bytes = (int) $bytes) === 0)
{
// We cannot process the file without a valid number of bytes
// so we discard it
fclose($handle);
$this->vars = $this->var_expires = array();
$this->is_modified = false;
$this->remove_file($file);
return false;
}
if ($time >= $expires)
{
fseek($handle, $bytes, SEEK_CUR);
continue;
}
$var_name = substr(fgets($handle), 0, -1);
// Read the length of bytes that consists of data.
$data = fread($handle, $bytes - strlen($var_name));
$data = @unserialize($data);
// Don't use the data if it was invalid
if ($data !== false)
{
$this->vars[$var_name] = $data;
$this->var_expires[$var_name] = $expires;
}
// Absorb the LF
fgets($handle);
}
fclose($handle);
$this->is_modified = false;
return true;
}
else
{
$data = false;
$line = 0;
while (($buffer = fgets($handle)) && !feof($handle))
{
$buffer = substr($buffer, 0, -1); // Remove the LF
// $buffer is only used to read integers
// if it is non numeric we have an invalid
// cache file, which we will now remove.
if (!is_numeric($buffer))
{
break;
}
if ($line == 0)
{
$expires = (int) $buffer;
if (time() >= $expires)
{
break;
}
if ($type == 'sql')
{
// Skip the query
fgets($handle);
}
}
else if ($line == 1)
{
$bytes = (int) $buffer;
// Never should have 0 bytes
if (!$bytes)
{
break;
}
// Grab the serialized data
$data = fread($handle, $bytes);
// Read 1 byte, to trigger EOF
fread($handle, 1);
if (!feof($handle))
{
// Somebody tampered with our data
$data = false;
}
break;
}
else
{
// Something went wrong
break;
}
$line++;
}
fclose($handle);
// unserialize if we got some data
$data = ($data !== false) ? @unserialize($data) : $data;
if ($data === false)
{
$this->remove_file($file);
return false;
}
return $data;
}
}
/**
* Write cache data to a specified file
*
* 'data_global' is a special case and the generated format is different for this file:
* <code>
* <?php exit; ?>
* (expiration)
* (length of var and serialised data)
* (var)
* (serialised data)
* ... (repeat)
* </code>
*
* The other files have a similar format:
* <code>
* <?php exit; ?>
* (expiration)
* (query) [SQL files only]
* (length of serialised data)
* (serialised data)
* </code>
*
* @access private
* @param string $filename Filename to write
* @param mixed $data Data to store
* @param int $expires Timestamp when the data expires
* @param string $query Query when caching SQL queries
* @return bool True if the file was successfully created, otherwise false
*/
function _write($filename, $data = null, $expires = 0, $query = '')
{
global $phpEx;
$file = "{$this->cache_dir}$filename.$phpEx";
$lock = new phpbb_lock_flock($file);
$lock->acquire();
if ($handle = @fopen($file, 'wb'))
{
// File header
fwrite($handle, '<' . '?php exit; ?' . '>');
if ($filename == 'data_global')
{
// Global data is a different format
foreach ($this->vars as $var => $data)
{
if (strpos($var, "\r") !== false || strpos($var, "\n") !== false)
{
// CR/LF would cause fgets() to read the cache file incorrectly
// do not cache test entries, they probably won't be read back
// the cache keys should really be alphanumeric with a few symbols.
continue;
}
$data = serialize($data);
// Write out the expiration time
fwrite($handle, "\n" . $this->var_expires[$var] . "\n");
// Length of the remaining data for this var (ignoring two LF's)
fwrite($handle, strlen($data . $var) . "\n");
fwrite($handle, $var . "\n");
fwrite($handle, $data);
}
}
else
{
fwrite($handle, "\n" . $expires . "\n");
if (strpos($filename, 'sql_') === 0)
{
fwrite($handle, $query . "\n");
}
$data = serialize($data);
fwrite($handle, strlen($data) . "\n");
fwrite($handle, $data);
}
fclose($handle);
if (!function_exists('phpbb_chmod'))
{
global $phpbb_root_path;
include($phpbb_root_path . 'includes/functions.' . $phpEx);
}
phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
$return_value = true;
}
else
{
$return_value = false;
}
$lock->release();
return $return_value;
}
/**
* Removes/unlinks file
*/
function remove_file($filename, $check = false)
{
if (!function_exists('phpbb_is_writable'))
{
global $phpbb_root_path, $phpEx;
include($phpbb_root_path . 'includes/functions.' . $phpEx);
}
if ($check && !phpbb_is_writable($this->cache_dir))
{
// E_USER_ERROR - not using language entry - intended.
trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR);
}
return @unlink($filename);
}
}

View File

@@ -1,144 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* An interface that all cache drivers must implement
*
* @package acm
*/
interface phpbb_cache_driver_interface
{
/**
* Load global cache
*/
public function load();
/**
* Unload cache object
*/
public function unload();
/**
* Save modified objects
*/
public function save();
/**
* Tidy cache
*/
public function tidy();
/**
* Get saved cache object
*/
public function get($var_name);
/**
* Put data into cache
*/
public function put($var_name, $var, $ttl = 0);
/**
* Purge cache data
*/
public function purge();
/**
* Destroy cache data
*/
public function destroy($var_name, $table = '');
/**
* Check if a given cache entry exists
*/
public function _exists($var_name);
/**
* Load result of an SQL query from cache.
*
* @param string $query SQL query
*
* @return int|bool Query ID (integer) if cache contains a rowset
* for the specified query.
* False otherwise.
*/
public function sql_load($query);
/**
* Save result of an SQL query in cache.
*
* In persistent cache stores, this function stores the query
* result to persistent storage. In other words, there is no need
* to call save() afterwards.
*
* @param phpbb_db_driver $db Database connection
* @param string $query SQL query, should be used for generating storage key
* @param mixed $query_result The result from dbal::sql_query, to be passed to
* dbal::sql_fetchrow to get all rows and store them
* in cache.
* @param int $ttl Time to live, after this timeout the query should
* expire from the cache.
* @return int|mixed If storing in cache succeeded, an integer $query_id
* representing the query should be returned. Otherwise
* the original $query_result should be returned.
*/
public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl);
/**
* Check if result for a given SQL query exists in cache.
*
* @param int $query_id
* @return bool
*/
public function sql_exists($query_id);
/**
* Fetch row from cache (database)
*
* @param int $query_id
* @return array|bool The query result if found in the cache, otherwise
* false.
*/
public function sql_fetchrow($query_id);
/**
* Fetch a field from the current row of a cached database result (database)
*
* @param int $query_id
* @param $field The name of the column.
* @return string|bool The field of the query result if found in the cache,
* otherwise false.
*/
public function sql_fetchfield($query_id, $field);
/**
* Seek a specific row in an a cached database result (database)
*
* @param int $rownum Row to seek to.
* @param int $query_id
* @return bool
*/
public function sql_rowseek($rownum, $query_id);
/**
* Free memory used for a cached database result (database)
*
* @param int $query_id
* @return bool
*/
public function sql_freeresult($query_id);
}

View File

@@ -1,129 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005, 2009 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
if (!defined('PHPBB_ACM_MEMCACHE_PORT'))
{
define('PHPBB_ACM_MEMCACHE_PORT', 11211);
}
if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS'))
{
define('PHPBB_ACM_MEMCACHE_COMPRESS', false);
}
if (!defined('PHPBB_ACM_MEMCACHE_HOST'))
{
define('PHPBB_ACM_MEMCACHE_HOST', 'localhost');
}
if (!defined('PHPBB_ACM_MEMCACHE'))
{
//can define multiple servers with host1/port1,host2/port2 format
define('PHPBB_ACM_MEMCACHE', PHPBB_ACM_MEMCACHE_HOST . '/' . PHPBB_ACM_MEMCACHE_PORT);
}
/**
* ACM for Memcached
* @package acm
*/
class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory
{
var $extension = 'memcache';
var $memcache;
var $flags = 0;
function __construct()
{
// Call the parent constructor
parent::__construct();
$this->memcache = new Memcache;
foreach(explode(',', PHPBB_ACM_MEMCACHE) as $u)
{
$parts = explode('/', $u);
$this->memcache->addServer(trim($parts[0]), trim($parts[1]));
}
$this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0;
}
/**
* Unload the cache resources
*
* @return null
*/
function unload()
{
parent::unload();
$this->memcache->close();
}
/**
* Purge cache data
*
* @return null
*/
function purge()
{
$this->memcache->flush();
parent::purge();
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
{
return $this->memcache->get($this->key_prefix . $var);
}
/**
* Store data in the cache
*
* @access protected
* @param string $var Cache key
* @param mixed $data Data to store
* @param int $ttl Time-to-live of cached data
* @return bool True if the operation succeeded
*/
function _write($var, $data, $ttl = 2592000)
{
if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl))
{
return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl);
}
return true;
}
/**
* Remove an item from the cache
*
* @access protected
* @param string $var Cache key
* @return bool True if the operation succeeded
*/
function _delete($var)
{
return $this->memcache->delete($this->key_prefix . $var);
}
}

View File

@@ -1,439 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ACM Abstract Memory Class
* @package acm
*/
abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
{
var $key_prefix;
var $vars = array();
var $is_modified = false;
var $sql_rowset = array();
var $sql_row_pointer = array();
var $cache_dir = '';
/**
* Set cache path
*/
function __construct()
{
global $phpbb_root_path, $dbname, $table_prefix;
$this->cache_dir = $phpbb_root_path . 'cache/';
$this->key_prefix = substr(md5($dbname . $table_prefix), 0, 8) . '_';
if (!isset($this->extension) || !extension_loaded($this->extension))
{
global $acm_type;
trigger_error("Could not find required extension [{$this->extension}] for the ACM module $acm_type.", E_USER_ERROR);
}
if (isset($this->function) && !function_exists($this->function))
{
global $acm_type;
trigger_error("The required function [{$this->function}] is not available for the ACM module $acm_type.", E_USER_ERROR);
}
}
/**
* Load global cache
*/
function load()
{
// grab the global cache
$this->vars = $this->_read('global');
if ($this->vars !== false)
{
return true;
}
return false;
}
/**
* Unload cache object
*/
function unload()
{
$this->save();
unset($this->vars);
unset($this->sql_rowset);
unset($this->sql_row_pointer);
$this->vars = array();
$this->sql_rowset = array();
$this->sql_row_pointer = array();
}
/**
* Save modified objects
*/
function save()
{
if (!$this->is_modified)
{
return;
}
$this->_write('global', $this->vars, 2592000);
$this->is_modified = false;
}
/**
* Tidy cache
*/
function tidy()
{
// cache has auto GC, no need to have any code here :)
set_config('cache_last_gc', time(), true);
}
/**
* Get saved cache object
*/
function get($var_name)
{
if ($var_name[0] == '_')
{
if (!$this->_exists($var_name))
{
return false;
}
return $this->_read($var_name);
}
else
{
return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
}
}
/**
* Put data into cache
*/
function put($var_name, $var, $ttl = 2592000)
{
if ($var_name[0] == '_')
{
$this->_write($var_name, $var, $ttl);
}
else
{
$this->vars[$var_name] = $var;
$this->is_modified = true;
}
}
/**
* Purge cache data
*/
function purge()
{
// Purge all phpbb cache files
$dir = @opendir($this->cache_dir);
if (!$dir)
{
return;
}
while (($entry = readdir($dir)) !== false)
{
if (strpos($entry, 'container_') !== 0 &&
strpos($entry, 'url_matcher') !== 0 &&
strpos($entry, 'sql_') !== 0 &&
strpos($entry, 'data_') !== 0 &&
strpos($entry, 'ctpl_') !== 0 &&
strpos($entry, 'tpl_') !== 0)
{
continue;
}
$this->remove_file($this->cache_dir . $entry);
}
closedir($dir);
unset($this->vars);
unset($this->sql_rowset);
unset($this->sql_row_pointer);
$this->vars = array();
$this->sql_rowset = array();
$this->sql_row_pointer = array();
$this->is_modified = false;
}
/**
* Destroy cache data
*/
function destroy($var_name, $table = '')
{
if ($var_name == 'sql' && !empty($table))
{
if (!is_array($table))
{
$table = array($table);
}
foreach ($table as $table_name)
{
// gives us the md5s that we want
$temp = $this->_read('sql_' . $table_name);
if ($temp === false)
{
continue;
}
// delete each query ref
foreach ($temp as $md5_id => $void)
{
$this->_delete('sql_' . $md5_id);
}
// delete the table ref
$this->_delete('sql_' . $table_name);
}
return;
}
if (!$this->_exists($var_name))
{
return;
}
if ($var_name[0] == '_')
{
$this->_delete($var_name);
}
else if (isset($this->vars[$var_name]))
{
$this->is_modified = true;
unset($this->vars[$var_name]);
// We save here to let the following cache hits succeed
$this->save();
}
}
/**
* Check if a given cache entry exist
*/
function _exists($var_name)
{
if ($var_name[0] == '_')
{
return $this->_isset($var_name);
}
else
{
if (!sizeof($this->vars))
{
$this->load();
}
return isset($this->vars[$var_name]);
}
}
/**
* Load cached sql query
*/
function sql_load($query)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
$query_id = sizeof($this->sql_rowset);
if (($result = $this->_read('sql_' . md5($query))) === false)
{
return false;
}
$this->sql_rowset[$query_id] = $result;
$this->sql_row_pointer[$query_id] = 0;
return $query_id;
}
/**
* {@inheritDoc}
*/
function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
$hash = md5($query);
// determine which tables this query belongs to
// Some queries use backticks, namely the get_database_size() query
// don't check for conformity, the SQL would error and not reach here.
if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs))
{
// Bail out if the match fails.
return $query_result;
}
$tables = array_map('trim', explode(',', $regs[1]));
foreach ($tables as $table_name)
{
// Remove backticks
$table_name = ($table_name[0] == '`') ? substr($table_name, 1, -1) : $table_name;
if (($pos = strpos($table_name, ' ')) !== false)
{
$table_name = substr($table_name, 0, $pos);
}
$temp = $this->_read('sql_' . $table_name);
if ($temp === false)
{
$temp = array();
}
$temp[$hash] = true;
// This must never expire
$this->_write('sql_' . $table_name, $temp, 0);
}
// store them in the right place
$query_id = sizeof($this->sql_rowset);
$this->sql_rowset[$query_id] = array();
$this->sql_row_pointer[$query_id] = 0;
while ($row = $db->sql_fetchrow($query_result))
{
$this->sql_rowset[$query_id][] = $row;
}
$db->sql_freeresult($query_result);
$this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl);
return $query_id;
}
/**
* Ceck if a given sql query exist in cache
*/
function sql_exists($query_id)
{
return isset($this->sql_rowset[$query_id]);
}
/**
* Fetch row from cache (database)
*/
function sql_fetchrow($query_id)
{
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
{
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
}
return false;
}
/**
* Fetch a field from the current row of a cached database result (database)
*/
function sql_fetchfield($query_id, $field)
{
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
{
return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false;
}
return false;
}
/**
* Seek a specific row in an a cached database result (database)
*/
function sql_rowseek($rownum, $query_id)
{
if ($rownum >= sizeof($this->sql_rowset[$query_id]))
{
return false;
}
$this->sql_row_pointer[$query_id] = $rownum;
return true;
}
/**
* Free memory used for a cached database result (database)
*/
function sql_freeresult($query_id)
{
if (!isset($this->sql_rowset[$query_id]))
{
return false;
}
unset($this->sql_rowset[$query_id]);
unset($this->sql_row_pointer[$query_id]);
return true;
}
/**
* Removes/unlinks file
*/
function remove_file($filename, $check = false)
{
if (!function_exists('phpbb_is_writable'))
{
global $phpbb_root_path, $phpEx;
include($phpbb_root_path . 'includes/functions.' . $phpEx);
}
if ($check && !phpbb_is_writable($this->cache_dir))
{
// E_USER_ERROR - not using language entry - intended.
trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR);
}
return @unlink($filename);
}
/**
* Check if a cache var exists
*
* @access protected
* @param string $var Cache key
* @return bool True if it exists, otherwise false
*/
function _isset($var)
{
// Most caches don't need to check
return true;
}
}

View File

@@ -1,154 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005, 2009 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ACM Null Caching
* @package acm
*/
class phpbb_cache_driver_null extends phpbb_cache_driver_base
{
/**
* Set cache path
*/
function __construct()
{
}
/**
* Load global cache
*/
function load()
{
return true;
}
/**
* Unload cache object
*/
function unload()
{
}
/**
* Save modified objects
*/
function save()
{
}
/**
* Tidy cache
*/
function tidy()
{
// This cache always has a tidy room.
set_config('cache_last_gc', time(), true);
}
/**
* Get saved cache object
*/
function get($var_name)
{
return false;
}
/**
* Put data into cache
*/
function put($var_name, $var, $ttl = 0)
{
}
/**
* Purge cache data
*/
function purge()
{
}
/**
* Destroy cache data
*/
function destroy($var_name, $table = '')
{
}
/**
* Check if a given cache entry exist
*/
function _exists($var_name)
{
return false;
}
/**
* Load cached sql query
*/
function sql_load($query)
{
return false;
}
/**
* {@inheritDoc}
*/
function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
{
return $query_result;
}
/**
* Ceck if a given sql query exist in cache
*/
function sql_exists($query_id)
{
return false;
}
/**
* Fetch row from cache (database)
*/
function sql_fetchrow($query_id)
{
return false;
}
/**
* Fetch a field from the current row of a cached database result (database)
*/
function sql_fetchfield($query_id, $field)
{
return false;
}
/**
* Seek a specific row in an a cached database result (database)
*/
function sql_rowseek($rownum, $query_id)
{
return false;
}
/**
* Free memory used for a cached database result (database)
*/
function sql_freeresult($query_id)
{
return false;
}
}

View File

@@ -1,166 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
if (!defined('PHPBB_ACM_REDIS_PORT'))
{
define('PHPBB_ACM_REDIS_PORT', 6379);
}
if (!defined('PHPBB_ACM_REDIS_HOST'))
{
define('PHPBB_ACM_REDIS_HOST', 'localhost');
}
/**
* ACM for Redis
*
* Compatible with the php extension phpredis available
* at https://github.com/nicolasff/phpredis
*
* @package acm
*/
class phpbb_cache_driver_redis extends phpbb_cache_driver_memory
{
var $extension = 'redis';
var $redis;
/**
* Creates a redis cache driver.
*
* The following global constants affect operation:
*
* PHPBB_ACM_REDIS_HOST
* PHPBB_ACM_REDIS_PORT
* PHPBB_ACM_REDIS_PASSWORD
* PHPBB_ACM_REDIS_DB
*
* There are no publicly documented constructor parameters.
*/
function __construct()
{
// Call the parent constructor
parent::__construct();
$this->redis = new Redis();
$args = func_get_args();
if (!empty($args))
{
$ok = call_user_func_array(array($this->redis, 'connect'), $args);
}
else
{
$ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
}
if (!$ok)
{
trigger_error('Could not connect to redis server');
}
if (defined('PHPBB_ACM_REDIS_PASSWORD'))
{
if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD))
{
global $acm_type;
trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR);
}
}
$this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$this->redis->setOption(Redis::OPT_PREFIX, $this->key_prefix);
if (defined('PHPBB_ACM_REDIS_DB'))
{
if (!$this->redis->select(PHPBB_ACM_REDIS_DB))
{
global $acm_type;
trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR);
}
}
}
/**
* Unload the cache resources
*
* @return null
*/
function unload()
{
parent::unload();
$this->redis->close();
}
/**
* Purge cache data
*
* @return null
*/
function purge()
{
$this->redis->flushDB();
parent::purge();
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
{
return $this->redis->get($var);
}
/**
* Store data in the cache
*
* @access protected
* @param string $var Cache key
* @param mixed $data Data to store
* @param int $ttl Time-to-live of cached data
* @return bool True if the operation succeeded
*/
function _write($var, $data, $ttl = 2592000)
{
return $this->redis->setex($var, $ttl, $data);
}
/**
* Remove an item from the cache
*
* @access protected
* @param string $var Cache key
* @return bool True if the operation succeeded
*/
function _delete($var)
{
if ($this->redis->delete($var) > 0)
{
return true;
}
return false;
}
}

View File

@@ -1,78 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ACM for WinCache
* @package acm
*/
class phpbb_cache_driver_wincache extends phpbb_cache_driver_memory
{
var $extension = 'wincache';
/**
* Purge cache data
*
* @return null
*/
function purge()
{
wincache_ucache_clear();
parent::purge();
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
{
$success = false;
$result = wincache_ucache_get($this->key_prefix . $var, $success);
return ($success) ? $result : false;
}
/**
* Store data in the cache
*
* @access protected
* @param string $var Cache key
* @param mixed $data Data to store
* @param int $ttl Time-to-live of cached data
* @return bool True if the operation succeeded
*/
function _write($var, $data, $ttl = 2592000)
{
return wincache_ucache_set($this->key_prefix . $var, $data, $ttl);
}
/**
* Remove an item from the cache
*
* @access protected
* @param string $var Cache key
* @return bool True if the operation succeeded
*/
function _delete($var)
{
return wincache_ucache_delete($this->key_prefix . $var);
}
}

View File

@@ -1,112 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005, 2009 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ACM for XCache
* @package acm
*
* To use this module you need ini_get() enabled and the following INI settings configured as follows:
* - xcache.var_size > 0
* - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set)
*
*/
class phpbb_cache_driver_xcache extends phpbb_cache_driver_memory
{
var $extension = 'XCache';
function __construct()
{
parent::__construct();
if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0)
{
trigger_error('Increase xcache.var_size setting above 0 or enable ini_get() to use this ACM module.', E_USER_ERROR);
}
}
/**
* Purge cache data
*
* @return null
*/
function purge()
{
// Run before for XCache, if admin functions are disabled it will terminate execution
parent::purge();
// If the admin authentication is enabled but not set up, this will cause a nasty error.
// Not much we can do about it though.
$n = xcache_count(XC_TYPE_VAR);
for ($i = 0; $i < $n; $i++)
{
xcache_clear_cache(XC_TYPE_VAR, $i);
}
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
{
$result = xcache_get($this->key_prefix . $var);
return ($result !== null) ? $result : false;
}
/**
* Store data in the cache
*
* @access protected
* @param string $var Cache key
* @param mixed $data Data to store
* @param int $ttl Time-to-live of cached data
* @return bool True if the operation succeeded
*/
function _write($var, $data, $ttl = 2592000)
{
return xcache_set($this->key_prefix . $var, $data, $ttl);
}
/**
* Remove an item from the cache
*
* @access protected
* @param string $var Cache key
* @return bool True if the operation succeeded
*/
function _delete($var)
{
return xcache_unset($this->key_prefix . $var);
}
/**
* Check if a cache var exists
*
* @access protected
* @param string $var Cache key
* @return bool True if it exists, otherwise false
*/
function _isset($var)
{
return xcache_isset($this->key_prefix . $var);
}
}

View File

@@ -1,406 +0,0 @@
<?php
/**
*
* @package acm
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Class for grabbing/handling cached entries
* @package acm
*/
class phpbb_cache_service
{
/**
* Cache driver.
*
* @var phpbb_cache_driver_interface
*/
protected $driver;
/**
* The config.
*
* @var phpbb_config
*/
protected $config;
/**
* Database connection.
*
* @var phpbb_db_driver
*/
protected $db;
/**
* Root path.
*
* @var string
*/
protected $phpbb_root_path;
/**
* PHP extension.
*
* @var string
*/
protected $php_ext;
/**
* Creates a cache service around a cache driver
*
* @param phpbb_cache_driver_interface $driver The cache driver
* @param phpbb_config $config The config
* @param phpbb_db_driver $db Database connection
* @param string $phpbb_root_path Root path
* @param string $php_ext PHP extension
*/
public function __construct(phpbb_cache_driver_interface $driver, phpbb_config $config, phpbb_db_driver $db, $phpbb_root_path, $php_ext)
{
$this->set_driver($driver);
$this->config = $config;
$this->db = $db;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Returns the cache driver used by this cache service.
*
* @return phpbb_cache_driver_interface The cache driver
*/
public function get_driver()
{
return $this->driver;
}
/**
* Replaces the cache driver used by this cache service.
*
* @param phpbb_cache_driver_interface $driver The cache driver
*/
public function set_driver(phpbb_cache_driver_interface $driver)
{
$this->driver = $driver;
}
public function __call($method, $arguments)
{
return call_user_func_array(array($this->driver, $method), $arguments);
}
/**
* Obtain list of naughty words and build preg style replacement arrays for use by the
* calling script
*/
function obtain_word_list()
{
if (($censors = $this->driver->get('_word_censors')) === false)
{
$sql = 'SELECT word, replacement
FROM ' . WORDS_TABLE;
$result = $this->db->sql_query($sql);
$censors = array();
while ($row = $this->db->sql_fetchrow($result))
{
$censors['match'][] = get_censor_preg_expression($row['word']);
$censors['replace'][] = $row['replacement'];
}
$this->db->sql_freeresult($result);
$this->driver->put('_word_censors', $censors);
}
return $censors;
}
/**
* Obtain currently listed icons
*/
function obtain_icons()
{
if (($icons = $this->driver->get('_icons')) === false)
{
// Topic icons
$sql = 'SELECT *
FROM ' . ICONS_TABLE . '
ORDER BY icons_order';
$result = $this->db->sql_query($sql);
$icons = array();
while ($row = $this->db->sql_fetchrow($result))
{
$icons[$row['icons_id']]['img'] = $row['icons_url'];
$icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
$icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
$icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
}
$this->db->sql_freeresult($result);
$this->driver->put('_icons', $icons);
}
return $icons;
}
/**
* Obtain ranks
*/
function obtain_ranks()
{
if (($ranks = $this->driver->get('_ranks')) === false)
{
$sql = 'SELECT *
FROM ' . RANKS_TABLE . '
ORDER BY rank_min DESC';
$result = $this->db->sql_query($sql);
$ranks = array();
while ($row = $this->db->sql_fetchrow($result))
{
if ($row['rank_special'])
{
$ranks['special'][$row['rank_id']] = array(
'rank_title' => $row['rank_title'],
'rank_image' => $row['rank_image']
);
}
else
{
$ranks['normal'][] = array(
'rank_title' => $row['rank_title'],
'rank_min' => $row['rank_min'],
'rank_image' => $row['rank_image']
);
}
}
$this->db->sql_freeresult($result);
$this->driver->put('_ranks', $ranks);
}
return $ranks;
}
/**
* Obtain allowed extensions
*
* @param mixed $forum_id If false then check for private messaging, if int then check for forum id. If true, then only return extension informations.
*
* @return array allowed extensions array.
*/
function obtain_attach_extensions($forum_id)
{
if (($extensions = $this->driver->get('_extensions')) === false)
{
$extensions = array(
'_allowed_post' => array(),
'_allowed_pm' => array(),
);
// The rule is to only allow those extensions defined. ;)
$sql = 'SELECT e.extension, g.*
FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
WHERE e.group_id = g.group_id
AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$extension = strtolower(trim($row['extension']));
$extensions[$extension] = array(
'display_cat' => (int) $row['cat_id'],
'download_mode' => (int) $row['download_mode'],
'upload_icon' => trim($row['upload_icon']),
'max_filesize' => (int) $row['max_filesize'],
'allow_group' => $row['allow_group'],
'allow_in_pm' => $row['allow_in_pm'],
'group_name' => $row['group_name'],
);
$allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
// Store allowed extensions forum wise
if ($row['allow_group'])
{
$extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
}
if ($row['allow_in_pm'])
{
$extensions['_allowed_pm'][$extension] = 0;
}
}
$this->db->sql_freeresult($result);
$this->driver->put('_extensions', $extensions);
}
// Forum post
if ($forum_id === false)
{
// We are checking for private messages, therefore we only need to get the pm extensions...
$return = array('_allowed_' => array());
foreach ($extensions['_allowed_pm'] as $extension => $check)
{
$return['_allowed_'][$extension] = 0;
$return[$extension] = $extensions[$extension];
}
$extensions = $return;
}
else if ($forum_id === true)
{
return $extensions;
}
else
{
$forum_id = (int) $forum_id;
$return = array('_allowed_' => array());
foreach ($extensions['_allowed_post'] as $extension => $check)
{
// Check for allowed forums
if (is_array($check))
{
$allowed = (!in_array($forum_id, $check)) ? false : true;
}
else
{
$allowed = true;
}
if ($allowed)
{
$return['_allowed_'][$extension] = 0;
$return[$extension] = $extensions[$extension];
}
}
$extensions = $return;
}
if (!isset($extensions['_allowed_']))
{
$extensions['_allowed_'] = array();
}
return $extensions;
}
/**
* Obtain active bots
*/
function obtain_bots()
{
if (($bots = $this->driver->get('_bots')) === false)
{
switch ($this->db->sql_layer)
{
case 'mssql':
case 'mssql_odbc':
case 'mssqlnative':
$sql = 'SELECT user_id, bot_agent, bot_ip
FROM ' . BOTS_TABLE . '
WHERE bot_active = 1
ORDER BY LEN(bot_agent) DESC';
break;
case 'firebird':
$sql = 'SELECT user_id, bot_agent, bot_ip
FROM ' . BOTS_TABLE . '
WHERE bot_active = 1
ORDER BY CHAR_LENGTH(bot_agent) DESC';
break;
// LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
default:
$sql = 'SELECT user_id, bot_agent, bot_ip
FROM ' . BOTS_TABLE . '
WHERE bot_active = 1
ORDER BY LENGTH(bot_agent) DESC';
break;
}
$result = $this->db->sql_query($sql);
$bots = array();
while ($row = $this->db->sql_fetchrow($result))
{
$bots[] = $row;
}
$this->db->sql_freeresult($result);
$this->driver->put('_bots', $bots);
}
return $bots;
}
/**
* Obtain cfg file data
*/
function obtain_cfg_items($style)
{
$parsed_array = $this->driver->get('_cfg_' . $style['style_path']);
if ($parsed_array === false)
{
$parsed_array = array();
}
$filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg';
if (!file_exists($filename))
{
return $parsed_array;
}
if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
{
// Re-parse cfg file
$parsed_array = parse_cfg_file($filename);
$parsed_array['filetime'] = @filemtime($filename);
$this->driver->put('_cfg_' . $style['style_path'], $parsed_array);
}
return $parsed_array;
}
/**
* Obtain disallowed usernames
*/
function obtain_disallowed_usernames()
{
if (($usernames = $this->driver->get('_disallowed_usernames')) === false)
{
$sql = 'SELECT disallow_username
FROM ' . DISALLOW_TABLE;
$result = $this->db->sql_query($sql);
$usernames = array();
while ($row = $this->db->sql_fetchrow($result))
{
$usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
}
$this->db->sql_freeresult($result);
$this->driver->put('_disallowed_usernames', $usernames);
}
return $usernames;
}
}

View File

@@ -1,170 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* The class loader resolves class names to file system paths and loads them if
* necessary.
*
* Classes have to be of the form phpbb_(dir_)*(classpart_)*, so directory names
* must never contain underscores. Example: phpbb_dir_subdir_class_name is a
* valid class name, while phpbb_dir_sub_dir_class_name is not.
*
* If every part of the class name is a directory, the last directory name is
* also used as the filename, e.g. phpbb_dir would resolve to dir/dir.php.
*
* @package phpBB3
*/
class phpbb_class_loader
{
private $prefix;
private $path;
private $php_ext;
private $cache;
/**
* A map of looked up class names to paths relative to $this->path.
* This map is stored in cache and looked up if the cache is available.
*
* @var array
*/
private $cached_paths = array();
/**
* Creates a new phpbb_class_loader, which loads files with the given
* file extension from the given path.
*
* @param string $prefix Required class name prefix for files to be loaded
* @param string $path Directory to load files from
* @param string $php_ext The file extension for PHP files
* @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface.
*/
public function __construct($prefix, $path, $php_ext = 'php', phpbb_cache_driver_interface $cache = null)
{
$this->prefix = $prefix;
$this->path = $path;
$this->php_ext = $php_ext;
$this->set_cache($cache);
}
/**
* Provide the class loader with a cache to store paths. If set to null, the
* the class loader will resolve paths by checking for the existance of every
* directory in the class name every time.
*
* @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface.
*/
public function set_cache(phpbb_cache_driver_interface $cache = null)
{
if ($cache)
{
$this->cached_paths = $cache->get('class_loader_' . $this->prefix);
if ($this->cached_paths === false)
{
$this->cached_paths = array();
}
}
$this->cache = $cache;
}
/**
* Registers the class loader as an autoloader using SPL.
*/
public function register()
{
spl_autoload_register(array($this, 'load_class'));
}
/**
* Removes the class loader from the SPL autoloader stack.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'load_class'));
}
/**
* Resolves a phpBB class name to a relative path which can be included.
*
* @param string $class The class name to resolve, must have a phpbb_
* prefix
* @return string|bool A relative path to the file containing the
* class or false if looking it up failed.
*/
public function resolve_path($class)
{
if (isset($this->cached_paths[$class]))
{
return $this->path . $this->cached_paths[$class] . '.' . $this->php_ext;
}
if (!preg_match('/^' . $this->prefix . '[a-zA-Z0-9_]+$/', $class))
{
return false;
}
$parts = explode('_', substr($class, strlen($this->prefix)));
$dirs = '';
for ($i = 0, $n = sizeof($parts); $i < $n && is_dir($this->path . $dirs . $parts[$i]); $i++)
{
$dirs .= $parts[$i] . '/';
}
// no file name left => use last dir name as file name
if ($i == sizeof($parts))
{
$parts[] = $parts[$i - 1];
}
$relative_path = $dirs . implode(array_slice($parts, $i, sizeof($parts) - $i), '_');
if (!file_exists($this->path . $relative_path . '.' . $this->php_ext))
{
return false;
}
if ($this->cache)
{
$this->cached_paths[$class] = $relative_path;
$this->cache->put('class_loader_' . $this->prefix, $this->cached_paths);
}
return $this->path . $relative_path . '.' . $this->php_ext;
}
/**
* Resolves a class name to a path and then includes it.
*
* @param string $class The class name which is being loaded.
*/
public function load_class($class)
{
if (substr($class, 0, strlen($this->prefix)) === $this->prefix)
{
$path = $this->resolve_path($class);
if ($path)
{
require $path;
}
}
}
}

View File

@@ -1,170 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Configuration container class
* @package phpBB3
*/
class phpbb_config implements ArrayAccess, IteratorAggregate, Countable
{
/**
* The configuration data
* @var array(string => string)
*/
protected $config;
/**
* Creates a configuration container with a default set of values
*
* @param array(string => string) $config The configuration data.
*/
public function __construct(array $config)
{
$this->config = $config;
}
/**
* Retrieves an ArrayIterator over the configuration values.
*
* @return ArrayIterator An iterator over all config data
*/
public function getIterator()
{
return new ArrayIterator($this->config);
}
/**
* Checks if the specified config value exists.
*
* @param string $key The configuration option's name.
* @return bool Whether the configuration option exists.
*/
public function offsetExists($key)
{
return isset($this->config[$key]);
}
/**
* Retrieves a configuration value.
*
* @param string $key The configuration option's name.
* @return string The configuration value
*/
public function offsetGet($key)
{
return (isset($this->config[$key])) ? $this->config[$key] : '';
}
/**
* Temporarily overwrites the value of a configuration variable.
*
* The configuration change will not persist. It will be lost
* after the request.
*
* @param string $key The configuration option's name.
* @param string $value The temporary value.
*/
public function offsetSet($key, $value)
{
$this->config[$key] = $value;
}
/**
* Called when deleting a configuration value directly, triggers an error.
*
* @param string $key The configuration option's name.
*/
public function offsetUnset($key)
{
trigger_error('Config values have to be deleted explicitly with the phpbb_config::delete($key) method.', E_USER_ERROR);
}
/**
* Retrieves the number of configuration options currently set.
*
* @return int Number of config options
*/
public function count()
{
return count($this->config);
}
/**
* Removes a configuration option
*
* @param String $key The configuration option's name
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached
* @return null
*/
public function delete($key, $use_cache = true)
{
unset($this->config[$key]);
}
/**
* Sets a configuration option's value
*
* @param string $key The configuration option's name
* @param string $value New configuration value
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached.
*/
public function set($key, $value, $use_cache = true)
{
$this->config[$key] = $value;
}
/**
* Sets a configuration option's value only if the old_value matches the
* current configuration value or the configuration value does not exist yet.
*
* @param string $key The configuration option's name
* @param string $old_value Current configuration value
* @param string $new_value New configuration value
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached.
* @return bool True if the value was changed, false otherwise.
*/
public function set_atomic($key, $old_value, $new_value, $use_cache = true)
{
if (!isset($this->config[$key]) || $this->config[$key] == $old_value)
{
$this->config[$key] = $new_value;
return true;
}
return false;
}
/**
* Increments an integer configuration value.
*
* @param string $key The configuration option's name
* @param int $increment Amount to increment by
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached.
*/
function increment($key, $increment, $use_cache = true)
{
if (!isset($this->config[$key]))
{
$this->config[$key] = 0;
}
$this->config[$key] += $increment;
}
}

View File

@@ -1,207 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Configuration container class
* @package phpBB3
*/
class phpbb_config_db extends phpbb_config
{
/**
* Cache instance
* @var phpbb_cache_driver_interface
*/
protected $cache;
/**
* Database connection
* @var phpbb_db_driver
*/
protected $db;
/**
* Name of the database table used for configuration.
* @var string
*/
protected $table;
/**
* Creates a configuration container with a default set of values
*
* @param phpbb_db_driver $db Database connection
* @param phpbb_cache_driver_interface $cache Cache instance
* @param string $table Configuration table name
*/
public function __construct(phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $table)
{
$this->db = $db;
$this->cache = $cache;
$this->table = $table;
if (($config = $cache->get('config')) !== false)
{
$sql = 'SELECT config_name, config_value
FROM ' . $this->table . '
WHERE is_dynamic = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$config[$row['config_name']] = $row['config_value'];
}
$this->db->sql_freeresult($result);
}
else
{
$config = $cached_config = array();
$sql = 'SELECT config_name, config_value, is_dynamic
FROM ' . $this->table;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if (!$row['is_dynamic'])
{
$cached_config[$row['config_name']] = $row['config_value'];
}
$config[$row['config_name']] = $row['config_value'];
}
$this->db->sql_freeresult($result);
$cache->put('config', $cached_config);
}
parent::__construct($config);
}
/**
* Removes a configuration option
*
* @param String $key The configuration option's name
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached
* @return null
*/
public function delete($key, $use_cache = true)
{
$sql = 'DELETE FROM ' . $this->table . "
WHERE config_name = '" . $this->db->sql_escape($key) . "'";
$this->db->sql_query($sql);
unset($this->config[$key]);
if ($use_cache)
{
$this->cache->destroy('config');
}
}
/**
* Sets a configuration option's value
*
* @param string $key The configuration option's name
* @param string $value New configuration value
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached.
*/
public function set($key, $value, $use_cache = true)
{
$this->set_atomic($key, false, $value, $use_cache);
}
/**
* Sets a configuration option's value only if the old_value matches the
* current configuration value or the configuration value does not exist yet.
*
* @param string $key The configuration option's name
* @param mixed $old_value Current configuration value or false to ignore
* the old value
* @param string $new_value New configuration value
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached
* @return bool True if the value was changed, false otherwise
*/
public function set_atomic($key, $old_value, $new_value, $use_cache = true)
{
$sql = 'UPDATE ' . $this->table . "
SET config_value = '" . $this->db->sql_escape($new_value) . "'
WHERE config_name = '" . $this->db->sql_escape($key) . "'";
if ($old_value !== false)
{
$sql .= " AND config_value = '" . $this->db->sql_escape($old_value) . "'";
}
$result = $this->db->sql_query($sql);
if (!$this->db->sql_affectedrows($result) && isset($this->config[$key]))
{
return false;
}
if (!isset($this->config[$key]))
{
$sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', array(
'config_name' => $key,
'config_value' => $new_value,
'is_dynamic' => ($use_cache) ? 0 : 1));
$this->db->sql_query($sql);
}
if ($use_cache)
{
$this->cache->destroy('config');
}
$this->config[$key] = $new_value;
return true;
}
/**
* Increments an integer config value directly in the database.
*
* Using this method instead of setting the new value directly avoids race
* conditions and unlike set_atomic it cannot fail.
*
* @param string $key The configuration option's name
* @param int $increment Amount to increment by
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached.
*/
function increment($key, $increment, $use_cache = true)
{
if (!isset($this->config[$key]))
{
$this->set($key, '0', $use_cache);
}
$sql_update = $this->db->cast_expr_to_string($this->db->cast_expr_to_bigint('config_value') . ' + ' . (int) $increment);
$this->db->sql_query('UPDATE ' . $this->table . '
SET config_value = ' . $sql_update . "
WHERE config_name = '" . $this->db->sql_escape($key) . "'");
if ($use_cache)
{
$this->cache->destroy('config');
}
$this->config[$key] += $increment;
}
}

View File

@@ -1,163 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Manages configuration options with an arbitrary length value stored in a TEXT
* column. In constrast to class phpbb_config_db, values are never cached and
* prefetched, but every get operation sends a query to the database.
*
* @package phpBB3
*/
class phpbb_config_db_text
{
/**
* Database connection
* @var phpbb_db_driver
*/
protected $db;
/**
* Name of the database table used.
* @var string
*/
protected $table;
/**
* @param phpbb_db_driver $db Database connection
* @param string $table Table name
*/
public function __construct(phpbb_db_driver $db, $table)
{
$this->db = $db;
$this->table = $this->db->sql_escape($table);
}
/**
* Sets the configuration option with the name $key to $value.
*
* @param string $key The configuration option's name
* @param string $value New configuration value
*
* @return null
*/
public function set($key, $value)
{
$this->set_array(array($key => $value));
}
/**
* Gets the configuration value for the name $key.
*
* @param string $key The configuration option's name
*
* @return string|null String result on success
* null if there is no such option
*/
public function get($key)
{
$map = $this->get_array(array($key));
return isset($map[$key]) ? $map[$key] : null;
}
/**
* Removes the configuration option with the name $key.
*
* @param string $key The configuration option's name
*
* @return null
*/
public function delete($key)
{
$this->delete_array(array($key));
}
/**
* Mass set configuration options: Receives an associative array,
* treats array keys as configuration option names and associated
* array values as their configuration option values.
*
* @param array $map Map from configuration names to values
*
* @return null
*/
public function set_array(array $map)
{
$this->db->sql_transaction('begin');
foreach ($map as $key => $value)
{
$sql = 'UPDATE ' . $this->table . "
SET config_value = '" . $this->db->sql_escape($value) . "'
WHERE config_name = '" . $this->db->sql_escape($key) . "'";
$result = $this->db->sql_query($sql);
if (!$this->db->sql_affectedrows($result))
{
$sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', array(
'config_name' => $key,
'config_value' => $value,
));
$this->db->sql_query($sql);
}
}
$this->db->sql_transaction('commit');
}
/**
* Mass get configuration options: Receives a set of configuration
* option names and returns the result as a key => value map where
* array keys are configuration option names and array values are
* associated config option values.
*
* @param array $keys Set of configuration option names
*
* @return array Map from configuration names to values
*/
public function get_array(array $keys)
{
$sql = 'SELECT *
FROM ' . $this->table . '
WHERE ' . $this->db->sql_in_set('config_name', $keys, false, true);
$result = $this->db->sql_query($sql);
$map = array();
while ($row = $this->db->sql_fetchrow($result))
{
$map[$row['config_name']] = $row['config_value'];
}
$this->db->sql_freeresult($result);
return $map;
}
/**
* Mass delete configuration options.
*
* @param array $keys Set of configuration option names
*
* @return null
*/
public function delete_array(array $keys)
{
$sql = 'DELETE
FROM ' . $this->table . '
WHERE ' . $this->db->sql_in_set('config_name', $keys, false, true);
$result = $this->db->sql_query($sql);
}
}

View File

@@ -1,651 +0,0 @@
<?php
/**
*
* @package phpbb
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* phpbb_visibility
* Handle fetching and setting the visibility for topics and posts
* @package phpbb
*/
class phpbb_content_visibility
{
/**
* Database object
* @var phpbb_db_driver
*/
protected $db;
/**
* User object
* @var phpbb_user
*/
protected $user;
/**
* Auth object
* @var phpbb_auth
*/
protected $auth;
/**
* phpBB root path
* @var string
*/
protected $phpbb_root_path;
/**
* PHP Extension
* @var string
*/
protected $php_ext;
/**
* Constructor
*
* @param phpbb_auth $auth Auth object
* @param phpbb_db_driver $db Database object
* @param phpbb_user $user User object
* @param string $phpbb_root_path Root path
* @param string $php_ext PHP Extension
* @return null
*/
public function __construct(phpbb_auth $auth, phpbb_db_driver $db, phpbb_user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table)
{
$this->auth = $auth;
$this->db = $db;
$this->user = $user;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->forums_table = $forums_table;
$this->posts_table = $posts_table;
$this->topics_table = $topics_table;
$this->users_table = $users_table;
}
/**
* Can the current logged-in user soft-delete posts?
*
* @param $forum_id int Forum ID whose permissions to check
* @param $poster_id int Poster ID of the post in question
* @param $post_locked bool Is the post locked?
* @return bool
*/
public function can_soft_delete($forum_id, $poster_id, $post_locked)
{
if ($this->auth->acl_get('m_softdelete', $forum_id))
{
return true;
}
else if ($this->auth->acl_get('f_softdelete', $forum_id) && $poster_id == $this->user->data['user_id'] && !$post_locked)
{
return true;
}
return false;
}
/**
* Get the topics post count or the forums post/topic count based on permissions
*
* @param $mode string One of topic_posts, forum_posts or forum_topics
* @param $data array Array with the topic/forum data to calculate from
* @param $forum_id int The forum id is used for permission checks
* @return int Number of posts/topics the user can see in the topic/forum
*/
public function get_count($mode, $data, $forum_id)
{
if (!$this->auth->acl_get('m_approve', $forum_id))
{
return (int) $data[$mode . '_approved'];
}
return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted'];
}
/**
* Create topic/post visibility SQL for a given forum ID
*
* Note: Read permissions are not checked.
*
* @param $mode string Either "topic" or "post"
* @param $forum_id int The forum id is used for permission checks
* @param $table_alias string Table alias to prefix in SQL queries
* @return string The appropriate combination SQL logic for topic/post_visibility
*/
public function get_visibility_sql($mode, $forum_id, $table_alias = '')
{
if ($this->auth->acl_get('m_approve', $forum_id))
{
return '1 = 1';
}
return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED;
}
/**
* Create topic/post visibility SQL for a set of forums
*
* Note: Read permissions are not checked. Forums without read permissions
* should not be in $forum_ids
*
* @param $mode string Either "topic" or "post"
* @param $forum_ids array Array of forum ids which the posts/topics are limited to
* @param $table_alias string Table alias to prefix in SQL queries
* @return string The appropriate combination SQL logic for topic/post_visibility
*/
public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '')
{
$where_sql = '(';
$approve_forums = array_intersect($forum_ids, array_keys($this->auth->acl_getf('m_approve', true)));
if (sizeof($approve_forums))
{
// Remove moderator forums from the rest
$forum_ids = array_diff($forum_ids, $approve_forums);
if (!sizeof($forum_ids))
{
// The user can see all posts/topics in all specified forums
return $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums);
}
else
{
// Moderator can view all posts/topics in some forums
$where_sql .= $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ' OR ';
}
}
else
{
// The user is just a normal user
return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . '
AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true);
}
$where_sql .= '(' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . '
AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids) . '))';
return $where_sql;
}
/**
* Create topic/post visibility SQL for all forums on the board
*
* Note: Read permissions are not checked. Forums without read permissions
* should be in $exclude_forum_ids
*
* @param $mode string Either "topic" or "post"
* @param $exclude_forum_ids array Array of forum ids which are excluded
* @param $table_alias string Table alias to prefix in SQL queries
* @return string The appropriate combination SQL logic for topic/post_visibility
*/
public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '')
{
$where_sqls = array();
$approve_forums = array_diff(array_keys($this->auth->acl_getf('m_approve', true)), $exclude_forum_ids);
if (sizeof($exclude_forum_ids))
{
$where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . '
AND ' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ')';
}
else
{
$where_sqls[] = $table_alias . $mode . '_visibility = ' . ITEM_APPROVED;
}
if (sizeof($approve_forums))
{
$where_sqls[] = $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums);
return '(' . implode(' OR ', $where_sqls) . ')';
}
// There is only one element, so we just return that one
return $where_sqls[0];
}
/**
* Change visibility status of one post or all posts of a topic
*
* @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED}
* @param $post_id mixed Post ID or array of post IDs to act on,
* if it is empty, all posts of topic_id will be modified
* @param $topic_id int Topic where $post_id is found
* @param $forum_id int Forum where $topic_id is found
* @param $user_id int User performing the action
* @param $time int Timestamp when the action is performed
* @param $reason string Reason why the visibilty was changed.
* @param $is_starter bool Is this the first post of the topic changed?
* @param $is_latest bool Is this the last post of the topic changed?
* @param $limit_visibility mixed Limit updating per topic_id to a certain visibility
* @param $limit_delete_time mixed Limit updating per topic_id to a certain deletion time
* @return array Changed post data, empty array if an error occured.
*/
public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false)
{
if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED)))
{
return array();
}
if ($post_id)
{
if (is_array($post_id))
{
$where_sql = $this->db->sql_in_set('post_id', array_map('intval', $post_id));
}
else
{
$where_sql = 'post_id = ' . (int) $post_id;
}
$where_sql .= ' AND topic_id = ' . (int) $topic_id;
}
else
{
$where_sql = 'topic_id = ' . (int) $topic_id;
// Limit the posts to a certain visibility and deletion time
// This allows us to only restore posts, that were approved
// when the topic got soft deleted. So previous soft deleted
// and unapproved posts are still soft deleted/unapproved
if ($limit_visibility !== false)
{
$where_sql .= ' AND post_visibility = ' . (int) $limit_visibility;
}
if ($limit_delete_time !== false)
{
$where_sql .= ' AND post_delete_time = ' . (int) $limit_delete_time;
}
}
$sql = 'SELECT poster_id, post_id, post_postcount, post_visibility
FROM ' . $this->posts_table . '
WHERE ' . $where_sql;
$result = $this->db->sql_query($sql);
$post_ids = $poster_postcounts = $postcounts = $postcount_visibility = array();
while ($row = $this->db->sql_fetchrow($result))
{
$post_ids[] = (int) $row['post_id'];
if ($row['post_visibility'] != $visibility)
{
if ($row['post_postcount'] && !isset($poster_postcounts[(int) $row['poster_id']]))
{
$poster_postcounts[(int) $row['poster_id']] = 1;
}
else if ($row['post_postcount'])
{
$poster_postcounts[(int) $row['poster_id']]++;
}
if (!isset($postcount_visibility[$row['post_visibility']]))
{
$postcount_visibility[$row['post_visibility']] = 1;
}
else
{
$postcount_visibility[$row['post_visibility']]++;
}
}
}
$this->db->sql_freeresult($result);
if (empty($post_ids))
{
return array();
}
$data = array(
'post_visibility' => (int) $visibility,
'post_delete_user' => (int) $user_id,
'post_delete_time' => ((int) $time) ?: time(),
'post_delete_reason' => truncate_string($reason, 255, 255, false),
);
$sql = 'UPDATE ' . $this->posts_table . '
SET ' . $this->db->sql_build_array('UPDATE', $data) . '
WHERE ' . $this->db->sql_in_set('post_id', $post_ids);
$this->db->sql_query($sql);
// Group the authors by post count, to reduce the number of queries
foreach ($poster_postcounts as $poster_id => $num_posts)
{
$postcounts[$num_posts][] = $poster_id;
}
// Update users postcounts
foreach ($postcounts as $num_posts => $poster_ids)
{
if ($visibility == ITEM_DELETED)
{
$sql = 'UPDATE ' . $this->users_table . '
SET user_posts = 0
WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . '
AND user_posts < ' . $num_posts;
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->users_table . '
SET user_posts = user_posts - ' . $num_posts . '
WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . '
AND user_posts >= ' . $num_posts;
$this->db->sql_query($sql);
}
else
{
$sql = 'UPDATE ' . $this->users_table . '
SET user_posts = user_posts + ' . $num_posts . '
WHERE ' . $this->db->sql_in_set('user_id', $poster_ids);
$this->db->sql_query($sql);
}
}
$update_topic_postcount = true;
// Sync the first/last topic information if needed
if (!$is_starter && $is_latest)
{
// update_post_information can only update the last post info ...
if ($topic_id)
{
update_post_information('topic', $topic_id, false);
}
if ($forum_id)
{
update_post_information('forum', $forum_id, false);
}
}
else if ($is_starter && $topic_id)
{
if (!function_exists('sync'))
{
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
// ... so we need to use sync, if the first post is changed.
// The forum is resynced recursive by sync() itself.
sync('topic', 'topic_id', $topic_id, true);
// sync recalculates the topic replies and forum posts by itself, so we don't do that.
$update_topic_postcount = false;
}
// Update the topic's reply count and the forum's post count
if ($update_topic_postcount)
{
$cur_posts = $cur_unapproved_posts = $cur_softdeleted_posts = 0;
foreach ($postcount_visibility as $post_visibility => $visibility_posts)
{
// We need to substract the posts from the counters ...
if ($post_visibility == ITEM_APPROVED)
{
$cur_posts += $visibility_posts;
}
else if ($post_visibility == ITEM_UNAPPROVED)
{
$cur_unapproved_posts += $visibility_posts;
}
else if ($post_visibility == ITEM_DELETED)
{
$cur_softdeleted_posts += $visibility_posts;
}
}
$sql_ary = array();
if ($visibility == ITEM_DELETED)
{
if ($cur_posts)
{
$sql_ary['posts_approved'] = ' - ' . $cur_posts;
}
if ($cur_unapproved_posts)
{
$sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts;
}
if ($cur_posts + $cur_unapproved_posts)
{
$sql_ary['posts_softdeleted'] = ' + ' . ($cur_posts + $cur_unapproved_posts);
}
}
else
{
if ($cur_unapproved_posts)
{
$sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts;
}
if ($cur_softdeleted_posts)
{
$sql_ary['posts_softdeleted'] = ' - ' . $cur_softdeleted_posts;
}
if ($cur_softdeleted_posts + $cur_unapproved_posts)
{
$sql_ary['posts_approved'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts);
}
}
if (sizeof($sql_ary))
{
$topic_sql = $forum_sql = array();
foreach ($sql_ary as $field => $value_change)
{
$topic_sql[] = 'topic_' . $field . ' = topic_' . $field . $value_change;
$forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change;
}
// Update the number for replies and posts
$sql = 'UPDATE ' . $this->topics_table . '
SET ' . implode(', ', $topic_sql) . '
WHERE topic_id = ' . (int) $topic_id;
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->forums_table . '
SET ' . implode(', ', $forum_sql) . '
WHERE forum_id = ' . (int) $forum_id;
$this->db->sql_query($sql);
}
}
return $data;
}
/**
* Set topic visibility
*
* Allows approving (which is akin to undeleting/restore) or soft deleting an entire topic.
* Calls set_post_visibility as needed.
*
* Note: By default, when a soft deleted topic is restored. Only posts that
* were approved at the time of soft deleting, are being restored.
* Same applies to soft deleting. Only approved posts will be marked
* as soft deleted.
* If you want to update all posts, use the force option.
*
* @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED}
* @param $topic_id mixed Topic ID to act on
* @param $forum_id int Forum where $topic_id is found
* @param $user_id int User performing the action
* @param $time int Timestamp when the action is performed
* @param $reason string Reason why the visibilty was changed.
* @param $force_update_all bool Force to update all posts within the topic
* @return array Changed topic data, empty array if an error occured.
*/
public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false)
{
if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED)))
{
return array();
}
if (!$force_update_all)
{
$sql = 'SELECT topic_visibility, topic_delete_time
FROM ' . $this->topics_table . '
WHERE topic_id = ' . (int) $topic_id;
$result = $this->db->sql_query($sql);
$original_topic_data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$original_topic_data)
{
// The topic does not exist...
return array();
}
}
// Note, we do not set a reason for the posts, just for the topic
$data = array(
'topic_visibility' => (int) $visibility,
'topic_delete_user' => (int) $user_id,
'topic_delete_time' => ((int) $time) ?: time(),
'topic_delete_reason' => truncate_string($reason, 255, 255, false),
);
$sql = 'UPDATE ' . $this->topics_table . '
SET ' . $this->db->sql_build_array('UPDATE', $data) . '
WHERE topic_id = ' . (int) $topic_id;
$this->db->sql_query($sql);
if (!$this->db->sql_affectedrows())
{
return array();
}
if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED)
{
// If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion.
self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']);
}
else if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED)
{
// If we're soft deleting a topic we only approved posts are soft deleted.
self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']);
}
else
{
self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true);
}
return $data;
}
/**
* Add post to topic and forum statistics
*
* @param $data array Contains information from the topics table about given topic
* @param $sql_data array Populated with the SQL changes, may be empty at call time
* @return void
*/
public function add_post_to_statistic($data, &$sql_data)
{
$sql_data[$this->topics_table] = (($sql_data[$this->topics_table]) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved + 1';
$sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved + 1';
if ($data['post_postcount'])
{
$sql_data[$this->users_table] = (($sql_data[$this->users_table]) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts + 1';
}
set_config_count('num_posts', 1, true);
}
/**
* Remove post from topic and forum statistics
*
* @param $data array Contains information from the topics table about given topic
* @param $sql_data array Populated with the SQL changes, may be empty at call time
* @return void
*/
public function remove_post_from_statistic($data, &$sql_data)
{
$sql_data[$this->topics_table] = ((!empty($sql_data[$this->topics_table])) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1';
$sql_data[$this->forums_table] = ((!empty($sql_data[$this->forums_table])) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1';
if ($data['post_postcount'])
{
$sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1';
}
set_config_count('num_posts', -1, true);
}
/**
* Remove topic from forum statistics
*
* @param $topic_id int The topic to act on
* @param $forum_id int Forum where the topic is found
* @param $topic_row array Contains information from the topic, may be empty at call time
* @param $sql_data array Populated with the SQL changes, may be empty at call time
* @return void
*/
public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data)
{
// Do we need to grab some topic informations?
if (!sizeof($topic_row))
{
$sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility
FROM ' . $this->topics_table . '
WHERE topic_id = ' . (int) $topic_id;
$result = $this->db->sql_query($sql);
$topic_row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
}
// If this is an edited topic or the first post the topic gets completely disapproved later on...
$sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_topics_approved = forum_topics_approved - 1';
$sql_data[$this->forums_table] .= ', forum_posts_approved = forum_posts_approved - ' . $topic_row['topic_posts_approved'];
$sql_data[$this->forums_table] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved'];
$sql_data[$this->forums_table] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted'];
set_config_count('num_topics', -1, true);
set_config_count('num_posts', $topic_row['topic_posts_approved'] * (-1), true);
// Get user post count information
$sql = 'SELECT poster_id, COUNT(post_id) AS num_posts
FROM ' . $this->posts_table . '
WHERE topic_id = ' . (int) $topic_id . '
AND post_postcount = 1
AND post_visibility = ' . ITEM_APPROVED . '
GROUP BY poster_id';
$result = $this->db->sql_query($sql);
$postcounts = array();
while ($row = $this->db->sql_fetchrow($result))
{
$postcounts[(int) $row['num_posts']][] = (int) $row['poster_id'];
}
$this->db->sql_freeresult($result);
// Decrement users post count
foreach ($postcounts as $num_posts => $poster_ids)
{
$sql = 'UPDATE ' . $this->users_table . '
SET user_posts = 0
WHERE user_posts < ' . $num_posts . '
AND ' . $this->db->sql_in_set('user_id', $poster_ids);
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->users_table . '
SET user_posts = user_posts - ' . $num_posts . '
WHERE user_posts >= ' . $num_posts . '
AND ' . $this->db->sql_in_set('user_id', $poster_ids);
$this->db->sql_query($sql);
}
}
}

View File

@@ -1,24 +0,0 @@
<?php
/**
*
* @package controller
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Controller exception class
* @package phpBB3
*/
class phpbb_controller_exception extends RuntimeException
{
}

View File

@@ -1,139 +0,0 @@
<?php
/**
*
* @package controller
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
use Symfony\Component\HttpFoundation\Response;
/**
* Controller helper class, contains methods that do things for controllers
* @package phpBB3
*/
class phpbb_controller_helper
{
/**
* Template object
* @var phpbb_template
*/
protected $template;
/**
* User object
* @var phpbb_user
*/
protected $user;
/**
* phpBB root path
* @var string
*/
protected $phpbb_root_path;
/**
* PHP extension
* @var string
*/
protected $php_ext;
/**
* Constructor
*
* @param phpbb_template $template Template object
* @param phpbb_user $user User object
* @param string $phpbb_root_path phpBB root path
* @param string $php_ext PHP extension
*/
public function __construct(phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext)
{
$this->template = $template;
$this->user = $user;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Automate setting up the page and creating the response object.
*
* @param string $handle The template handle to render
* @param string $page_title The title of the page to output
* @param int $status_code The status code to be sent to the page header
* @return Response object containing rendered page
*/
public function render($template_file, $page_title = '', $status_code = 200)
{
page_header($page_title);
$this->template->set_filenames(array(
'body' => $template_file,
));
page_footer(true, false, false);
return new Response($this->template->assign_display('body'), $status_code);
}
/**
* Generate a URL
*
* @param string $route The route to travel
* @param mixed $params String or array of additional url parameters
* @param bool $is_amp Is url using &amp; (true) or & (false)
* @param string $session_id Possibility to use a custom session id instead of the global one
* @return string The URL already passed through append_sid()
*/
public function url($route, $params = false, $is_amp = true, $session_id = false)
{
$route_params = '';
if (($route_delim = strpos($route, '?')) !== false)
{
$route_params = substr($route, $route_delim);
$route = substr($route, 0, $route_delim);
}
if (is_array($params) && !empty($params))
{
$params = array_merge(array(
'controller' => $route,
), $params);
}
else if (is_string($params) && $params)
{
$params = 'controller=' . $route . (($is_amp) ? '&amp;' : '&') . $params;
}
else
{
$params = array('controller' => $route);
}
return append_sid($this->phpbb_root_path . 'app.' . $this->php_ext . $route_params, $params, $is_amp, $session_id);
}
/**
* Output an error, effectively the same thing as trigger_error
*
* @param string $message The error message
* @param string $code The error code (e.g. 404, 500, 503, etc.)
* @return Response A Reponse instance
*/
public function error($message, $code = 500)
{
$this->template->assign_vars(array(
'MESSAGE_TEXT' => $message,
'MESSAGE_TITLE' => $this->user->lang('INFORMATION'),
));
return $this->render('message_body.html', $this->user->lang('INFORMATION'), $code);
}
}

View File

@@ -1,82 +0,0 @@
<?php
/**
*
* @package controller
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
/**
* Controller interface
* @package phpBB3
*/
class phpbb_controller_provider
{
/**
* YAML file(s) containing route information
* @var array
*/
protected $routing_paths;
/**
* Construct method
*
* @param array() $routing_paths Array of strings containing paths
* to YAML files holding route information
*/
public function __construct($routing_paths = array())
{
$this->routing_paths = $routing_paths;
}
/**
* Locate paths containing routing files
* This sets an internal property but does not return the paths.
*
* @return The current instance of this object for method chaining
*/
public function import_paths_from_finder(phpbb_extension_finder $finder)
{
// We hardcode the path to the core config directory
// because the finder cannot find it
$this->routing_paths = array_merge(array('config'), array_map('dirname', array_keys($finder
->directory('config')
->prefix('routing')
->suffix('yml')
->find()
)));
return $this;
}
/**
* Get a list of controllers and return it
*
* @param string $base_path Base path to prepend to file paths
* @return array Array of controllers and their route information
*/
public function find($base_path = '')
{
$routes = new RouteCollection;
foreach ($this->routing_paths as $path)
{
$loader = new YamlFileLoader(new FileLocator($base_path . $path));
$routes->addCollection($loader->load('routing.yml'));
}
return $routes;
}
}

View File

@@ -1,154 +0,0 @@
<?php
/**
*
* @package controller
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller manager class
* @package phpBB3
*/
class phpbb_controller_resolver implements ControllerResolverInterface
{
/**
* User object
* @var phpbb_user
*/
protected $user;
/**
* ContainerInterface object
* @var ContainerInterface
*/
protected $container;
/**
* phpbb_style object
* @var phpbb_style
*/
protected $style;
/**
* Construct method
*
* @param phpbb_user $user User Object
* @param ContainerInterface $container ContainerInterface object
* @param phpbb_style $style
*/
public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style = null)
{
$this->user = $user;
$this->container = $container;
$this->style = $style;
}
/**
* Load a controller callable
*
* @param Symfony\Component\HttpFoundation\Request $request Symfony Request object
* @return bool|Callable Callable or false
* @throws phpbb_controller_exception
*/
public function getController(Request $request)
{
$controller = $request->attributes->get('_controller');
if (!$controller)
{
throw new phpbb_controller_exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']);
}
// Require a method name along with the service name
if (stripos($controller, ':') === false)
{
throw new phpbb_controller_exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']);
}
list($service, $method) = explode(':', $controller);
if (!$this->container->has($service))
{
throw new phpbb_controller_exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service));
}
$controller_object = $this->container->get($service);
/*
* If this is an extension controller, we'll try to automatically set
* the style paths for the extension (the ext author can change them
* if necessary).
*/
$controller_dir = explode('_', get_class($controller_object));
// 0 phpbb, 1 ext, 2 vendor, 3 extension name, ...
if (!is_null($this->style) && isset($controller_dir[3]) && $controller_dir[1] === 'ext')
{
$controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles';
if (is_dir($controller_style_dir))
{
$this->style->set_style(array($controller_style_dir, 'styles'));
}
}
return array($controller_object, $method);
}
/**
* Dependencies should be specified in the service definition and can be
* then accessed in __construct(). Arguments are sent through the URL path
* and should match the parameters of the method you are using as your
* controller.
*
* @param Symfony\Component\HttpFoundation\Request $request Symfony Request object
* @param mixed $controller A callable (controller class, method)
* @return bool False
* @throws phpbb_controller_exception
*/
public function getArguments(Request $request, $controller)
{
// At this point, $controller contains the object and method name
list($object, $method) = $controller;
$mirror = new ReflectionMethod($object, $method);
$arguments = array();
$parameters = $mirror->getParameters();
$attributes = $request->attributes->all();
foreach ($parameters as $param)
{
if (array_key_exists($param->name, $attributes))
{
$arguments[] = $attributes[$param->name];
}
else if ($param->getClass() && $param->getClass()->isInstance($request))
{
$arguments[] = $request;
}
else if ($param->isDefaultValueAvailable())
{
$arguments[] = $param->getDefaultValue();
}
else
{
throw new phpbb_controller_exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name));
}
}
return $arguments;
}
}

View File

@@ -1,138 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Cron manager class.
*
* Finds installed cron tasks, stores task objects, provides task selection.
*
* @package phpBB3
*/
class phpbb_cron_manager
{
/**
* Set of phpbb_cron_task_wrapper objects.
* Array holding all tasks that have been found.
*
* @var array
*/
protected $tasks = array();
protected $phpbb_root_path;
protected $php_ext;
/**
* Constructor. Loads all available tasks.
*
* @param array|Traversable $tasks Provides an iterable set of task names
*/
public function __construct($tasks, $phpbb_root_path, $php_ext)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->load_tasks($tasks);
}
/**
* Loads tasks given by name, wraps them
* and puts them into $this->tasks.
*
* @param array|Traversable $tasks Array of instances of phpbb_cron_task
*
* @return null
*/
public function load_tasks($tasks)
{
foreach ($tasks as $task)
{
$this->tasks[] = $this->wrap_task($task);
}
}
/**
* Finds a task that is ready to run.
*
* If several tasks are ready, any one of them could be returned.
*
* If no tasks are ready, null is returned.
*
* @return phpbb_cron_task_wrapper|null
*/
public function find_one_ready_task()
{
foreach ($this->tasks as $task)
{
if ($task->is_ready())
{
return $task;
}
}
return null;
}
/**
* Finds all tasks that are ready to run.
*
* @return array List of tasks which are ready to run (wrapped in phpbb_cron_task_wrapper).
*/
public function find_all_ready_tasks()
{
$tasks = array();
foreach ($this->tasks as $task)
{
if ($task->is_ready())
{
$tasks[] = $task;
}
}
return $tasks;
}
/**
* Finds a task by name.
*
* If there is no task with the specified name, null is returned.
*
* Web runner uses this method to resolve names to tasks.
*
* @param string $name Name of the task to look up.
* @return phpbb_cron_task A task corresponding to the given name, or null.
*/
public function find_task($name)
{
foreach ($this->tasks as $task)
{
if ($task->get_name() == $name)
{
return $task;
}
}
return null;
}
/**
* Wraps a task inside an instance of phpbb_cron_task_wrapper.
*
* @param phpbb_cron_task $task The task.
* @return phpbb_cron_task_wrapper The wrapped task.
*/
public function wrap_task(phpbb_cron_task $task)
{
return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->php_ext);
}
}

View File

@@ -1,76 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Cron task base class. Provides sensible defaults for cron tasks
* and partially implements cron task interface, making writing cron tasks easier.
*
* At a minimum, subclasses must override the run() method.
*
* Cron tasks need not inherit from this base class. If desired,
* they may implement cron task interface directly.
*
* @package phpBB3
*/
abstract class phpbb_cron_task_base implements phpbb_cron_task
{
private $name;
/**
* Returns the name of the task.
*
* @return string Name of wrapped task.
*/
public function get_name()
{
return $this->name;
}
/**
* Sets the name of the task.
*
* @param string $name The task name
*/
public function set_name($name)
{
$this->name = $name;
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* For example, a cron task that prunes forums can only run when
* forum pruning is enabled.
*
* @return bool
*/
public function is_runnable()
{
return true;
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* @return bool
*/
public function should_run()
{
return true;
}
}

View File

@@ -1,93 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Prune all forums cron task.
*
* It is intended to be invoked from system cron.
* This task will find all forums for which pruning is enabled, and will
* prune all forums as necessary.
*
* @package phpBB3
*/
class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
protected $db;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension
* @param phpbb_config $config The config
* @param phpbb_db_driver $db The db connection
*/
public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, phpbb_db_driver $db)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
$this->db = $db;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!function_exists('auto_prune'))
{
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
FROM ' . FORUMS_TABLE . "
WHERE enable_prune = 1
AND prune_next < " . time();
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if ($row['prune_days'])
{
auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
}
if ($row['prune_viewed'])
{
auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
}
}
$this->db->sql_freeresult($result);
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* This cron task will only run when system cron is utilised.
*
* @return bool
*/
public function is_runnable()
{
return (bool) $this->config['use_system_cron'];
}
}

View File

@@ -1,163 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Prune one forum cron task.
*
* It is intended to be used when cron is invoked via web.
* This task can decide whether it should be run using data obtained by viewforum
* code, without making additional database queries.
*
* @package phpBB3
*/
class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
protected $db;
/**
* If $forum_data is given, it is assumed to contain necessary information
* about a single forum that is to be pruned.
*
* If $forum_data is not given, forum id will be retrieved via request_var
* and a database query will be performed to load the necessary information
* about the forum.
*/
protected $forum_data;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension
* @param phpbb_config $config The config
* @param phpbb_db_driver $db The db connection
*/
public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, phpbb_db_driver $db)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
$this->db = $db;
}
/**
* Manually set forum data.
*
* @param array $forum_data Information about a forum to be pruned.
*/
public function set_forum_data($forum_data)
{
$this->forum_data = $forum_data;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!function_exists('auto_prune'))
{
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
if ($this->forum_data['prune_days'])
{
auto_prune($this->forum_data['forum_id'], 'posted', $this->forum_data['forum_flags'], $this->forum_data['prune_days'], $this->forum_data['prune_freq']);
}
if ($this->forum_data['prune_viewed'])
{
auto_prune($this->forum_data['forum_id'], 'viewed', $this->forum_data['forum_flags'], $this->forum_data['prune_viewed'], $this->forum_data['prune_freq']);
}
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* This cron task will not run when system cron is utilised, as in
* such cases prune_all_forums task would run instead.
*
* Additionally, this task must be given the forum data, either via
* the constructor or parse_parameters method.
*
* @return bool
*/
public function is_runnable()
{
return !$this->config['use_system_cron'] && $this->forum_data;
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* Forum pruning interval is specified in the forum data.
*
* @return bool
*/
public function should_run()
{
return $this->forum_data['enable_prune'] && $this->forum_data['prune_next'] < time();
}
/**
* Returns parameters of this cron task as an array.
* The array has one key, f, whose value is id of the forum to be pruned.
*
* @return array
*/
public function get_parameters()
{
return array('f' => $this->forum_data['forum_id']);
}
/**
* Parses parameters found in $request, which is an instance of
* phpbb_request_interface.
*
* It is expected to have a key f whose value is id of the forum to be pruned.
*
* @param phpbb_request_interface $request Request object.
*
* @return null
*/
public function parse_parameters(phpbb_request_interface $request)
{
$this->forum_data = null;
if ($request->is_set('f'))
{
$forum_id = $request->variable('f', 0);
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
FROM ' . FORUMS_TABLE . "
WHERE forum_id = $forum_id";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if ($row)
{
$this->forum_data = $row;
}
}
}
}

View File

@@ -1,82 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Queue cron task. Sends email and jabber messages queued by other scripts.
*
* @package phpBB3
*/
class phpbb_cron_task_core_queue extends phpbb_cron_task_base
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension
* @param phpbb_config $config The config
*/
public function __construct($phpbb_root_path, $php_ext, phpbb_config $config)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!class_exists('queue'))
{
include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
}
$queue = new queue();
$queue->process();
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* Queue task is only run if the email queue (file) exists.
*
* @return bool
*/
public function is_runnable()
{
return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->php_ext);
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between queue runs is specified in board configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['last_queue_run'] < time() - $this->config['queue_interval_config'];
}
}

View File

@@ -1,76 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Tidy cache cron task.
*
* @package phpBB3
*/
class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base
{
protected $config;
protected $cache;
/**
* Constructor.
*
* @param phpbb_config $config The config
* @param phpbb_cache_driver_interface $cache The cache driver
*/
public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache)
{
$this->config = $config;
$this->cache = $cache;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
$this->cache->tidy();
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* Tidy cache cron task runs if the cache implementation in use
* supports tidying.
*
* @return bool
*/
public function is_runnable()
{
return true;
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between cache tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['cache_last_gc'] < time() - $this->config['cache_gc'];
}
}

View File

@@ -1,70 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Tidy database cron task.
*
* @package phpBB3
*/
class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension
* @param phpbb_config $config The config
*/
public function __construct($phpbb_root_path, $php_ext, phpbb_config $config)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!function_exists('tidy_database'))
{
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
tidy_database();
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between database tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['database_last_gc'] < time() - $this->config['database_gc'];
}
}

View File

@@ -1,109 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Tidy search cron task.
*
* Will only run when the currently selected search backend supports tidying.
*
* @package phpBB3
*/
class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base
{
protected $phpbb_root_path;
protected $php_ext;
protected $auth;
protected $config;
protected $db;
protected $user;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension
* @param phpbb_auth $auth The auth
* @param phpbb_config $config The config
* @param phpbb_db_driver $db The db connection
* @param phpbb_user $user The user
*/
public function __construct($phpbb_root_path, $php_ext, phpbb_auth $auth, phpbb_config $config, phpbb_db_driver $db, phpbb_user $user)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->auth = $auth;
$this->config = $config;
$this->db = $db;
$this->user = $user;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
// Select the search method
$search_type = basename($this->config['search_type']);
if (!class_exists($search_type))
{
include($this->phpbb_root_path . "includes/search/$search_type." . $this->php_ext);
}
// We do some additional checks in the module to ensure it can actually be utilised
$error = false;
$search = new $search_type($error, $this->phpbb_root_path, $this->php_ext, $this->auth, $this->config, $this->db, $this->user);
if (!$error)
{
$search->tidy();
}
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* Search cron task is runnable in all normal use. It may not be
* runnable if the search backend implementation selected in board
* configuration does not exist.
*
* @return bool
*/
public function is_runnable()
{
// Select the search method
$search_type = basename($this->config['search_type']);
return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->php_ext);
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between search tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['search_last_gc'] < time() - $this->config['search_gc'];
}
}

View File

@@ -1,63 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Tidy sessions cron task.
*
* @package phpBB3
*/
class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base
{
protected $config;
protected $user;
/**
* Constructor.
*
* @param phpbb_config $config The config
* @param phpbb_user $user The user
*/
public function __construct(phpbb_config $config, phpbb_user $user)
{
$this->config = $config;
$this->user = $user;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
$this->user->session_gc();
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between session tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['session_last_gc'] < time() - $this->config['session_gc'];
}
}

View File

@@ -1,84 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Tidy warnings cron task.
*
* Will only run when warnings are configured to expire.
*
* @package phpBB3
*/
class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension
* @param phpbb_config $config The config
*/
public function __construct($phpbb_root_path, $php_ext, phpbb_config $config)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!function_exists('tidy_warnings'))
{
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
tidy_warnings();
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* If warnings are set to never expire, this cron task will not run.
*
* @return bool
*/
public function is_runnable()
{
return (bool) $this->config['warnings_expire_days'];
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between warnings tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['warnings_last_gc'] < time() - $this->config['warnings_gc'];
}
}

View File

@@ -1,52 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Parametrized cron task interface.
*
* Parametrized cron tasks are somewhat of a cross between regular cron tasks and
* delayed jobs. Whereas regular cron tasks perform some action globally,
* parametrized cron tasks perform actions on a particular object (or objects).
* Parametrized cron tasks do not make sense and are not usable without
* specifying these objects.
*
* @package phpBB3
*/
interface phpbb_cron_task_parametrized extends phpbb_cron_task
{
/**
* Returns parameters of this cron task as an array.
*
* The array must map string keys to string values.
*
* @return array
*/
public function get_parameters();
/**
* Parses parameters found in $request, which is an instance of
* phpbb_request_interface.
*
* $request contains user input and must not be trusted.
* Cron task must validate all data before using it.
*
* @param phpbb_request_interface $request Request object.
*
* @return null
*/
public function parse_parameters(phpbb_request_interface $request);
}

View File

@@ -1,55 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Cron task interface
* @package phpBB3
*/
interface phpbb_cron_task
{
/**
* Returns the name of the task.
*
* @return string Name of wrapped task.
*/
public function get_name();
/**
* Runs this cron task.
*
* @return null
*/
public function run();
/**
* Returns whether this cron task can run, given current board configuration.
*
* For example, a cron task that prunes forums can only run when
* forum pruning is enabled.
*
* @return bool
*/
public function is_runnable();
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* @return bool
*/
public function should_run();
}

View File

@@ -1,108 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Cron task wrapper class.
* Enhances cron tasks with convenience methods that work identically for all tasks.
*
* @package phpBB3
*/
class phpbb_cron_task_wrapper
{
protected $task;
protected $phpbb_root_path;
protected $php_ext;
/**
* Constructor.
*
* Wraps a task $task, which must implement cron_task interface.
*
* @param phpbb_cron_task $task The cron task to wrap.
*/
public function __construct(phpbb_cron_task $task, $phpbb_root_path, $php_ext)
{
$this->task = $task;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Returns whether the wrapped task is parametrised.
*
* Parametrized tasks accept parameters during initialization and must
* normally be scheduled with parameters.
*
* @return bool Whether or not this task is parametrized.
*/
public function is_parametrized()
{
return $this->task instanceof phpbb_cron_task_parametrized;
}
/**
* Returns whether the wrapped task is ready to run.
*
* A task is ready to run when it is runnable according to current configuration
* and enough time has passed since it was last run.
*
* @return bool Whether the wrapped task is ready to run.
*/
public function is_ready()
{
return $this->task->is_runnable() && $this->task->should_run();
}
/**
* Returns a url through which this task may be invoked via web.
*
* When system cron is not in use, running a cron task is accomplished
* by outputting an image with the url returned by this function as
* source.
*
* @return string URL through which this task may be invoked.
*/
public function get_url()
{
$name = $this->get_name();
if ($this->is_parametrized())
{
$params = $this->task->get_parameters();
$extra = '';
foreach ($params as $key => $value)
{
$extra .= '&amp;' . $key . '=' . urlencode($value);
}
}
else
{
$extra = '';
}
$url = append_sid($this->phpbb_root_path . 'cron.' . $this->php_ext, 'cron_type=' . $name . $extra);
return $url;
}
/**
* Forwards all other method calls to the wrapped task implementation.
*
* @return mixed
*/
public function __call($name, $args)
{
return call_user_func_array(array($this->task, $name), $args);
}
}

View File

@@ -1,158 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*/
/**
* phpBB custom extensions to the PHP DateTime class
* This handles the relative formats phpBB employs
*/
class phpbb_datetime extends DateTime
{
/**
* String used to wrap the date segment which should be replaced by today/tomorrow/yesterday
*/
const RELATIVE_WRAPPER = '|';
/**
* @var user User who is the context for this DateTime instance
*/
protected $user;
/**
* @var array Date formats are preprocessed by phpBB, to save constant recalculation they are cached.
*/
static protected $format_cache = array();
/**
* Constructs a new instance of phpbb_datetime, expanded to include an argument to inject
* the user context and modify the timezone to the users selected timezone if one is not set.
*
* @param string $time String in a format accepted by strtotime().
* @param DateTimeZone $timezone Time zone of the time.
* @param user User object for context.
*/
public function __construct($user, $time = 'now', DateTimeZone $timezone = null)
{
$this->user = $user;
$timezone = $timezone ?: $this->user->timezone;
parent::__construct($time, $timezone);
}
/**
* Formats the current date time into the specified format
*
* @param string $format Optional format to use for output, defaults to users chosen format
* @param boolean $force_absolute Force output of a non relative date
* @return string Formatted date time
*/
public function format($format = '', $force_absolute = false)
{
$format = $format ? $format : $this->user->date_format;
$format = self::format_cache($format, $this->user);
$relative = ($format['is_short'] && !$force_absolute);
$now = new self($this->user, 'now', $this->user->timezone);
$timestamp = $this->getTimestamp();
$now_ts = $now->getTimeStamp();
$delta = $now_ts - $timestamp;
if ($relative)
{
/*
* Check the delta is less than or equal to 1 hour
* and the delta not more than a minute in the past
* and the delta is either greater than -5 seconds or timestamp
* and current time are of the same minute (they must be in the same hour already)
* finally check that relative dates are supported by the language pack
*/
if ($delta <= 3600 && $delta > -60 &&
($delta >= -5 || (($now_ts / 60) % 60) == (($timestamp / 60) % 60))
&& isset($this->user->lang['datetime']['AGO']))
{
return $this->user->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60)));
}
else
{
$midnight = clone $now;
$midnight->setTime(0, 0, 0);
$midnight = $midnight->getTimestamp();
$day = false;
if ($timestamp > $midnight + 86400)
{
$day = 'TOMORROW';
}
else if ($timestamp > $midnight)
{
$day = 'TODAY';
}
else if ($timestamp > $midnight - 86400)
{
$day = 'YESTERDAY';
}
if ($day !== false)
{
// Format using the short formatting and finally swap out the relative token placeholder with the correct value
return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang']));
}
}
}
return strtr(parent::format($format['format_long']), $format['lang']);
}
/**
* Magic method to convert DateTime object to string
*
* @return Formatted date time, according to the users default settings.
*/
public function __toString()
{
return $this->format();
}
/**
* Pre-processes the specified date format
*
* @param string $format Output format
* @param user $user User object to use for localisation
* @return array Processed date format
*/
static protected function format_cache($format, $user)
{
$lang = $user->lang_name;
if (!isset(self::$format_cache[$lang]))
{
self::$format_cache[$lang] = array();
}
if (!isset(self::$format_cache[$lang][$format]))
{
// Is the user requesting a friendly date format (i.e. 'Today 12:42')?
self::$format_cache[$lang][$format] = array(
'is_short' => strpos($format, self::RELATIVE_WRAPPER) !== false,
'format_short' => substr($format, 0, strpos($format, self::RELATIVE_WRAPPER)) . self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER . substr(strrchr($format, self::RELATIVE_WRAPPER), 1),
'format_long' => str_replace(self::RELATIVE_WRAPPER, '', $format),
'lang' => array_filter($user->lang['datetime'], 'is_string'),
);
// Short representation of month in format? Some languages use different terms for the long and short format of May
if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false))
{
self::$format_cache[$lang][$format]['lang']['May'] = $user->lang['datetime']['May_short'];
}
}
return self::$format_cache[$lang][$format];
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,538 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Firebird/Interbase Database Abstraction Layer
* Minimum Requirement is Firebird 2.1
* @package dbal
*/
class phpbb_db_driver_firebird extends phpbb_db_driver
{
var $last_query_text = '';
var $service_handle = false;
var $affected_rows = 0;
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->server = $sqlserver . (($port) ? ':' . $port : '');
$this->dbname = str_replace('\\', '/', $database);
// There are three possibilities to connect to an interbase db
if (!$this->server)
{
$use_database = $this->dbname;
}
else if (strpos($this->server, '//') === 0)
{
$use_database = $this->server . $this->dbname;
}
else
{
$use_database = $this->server . ':' . $this->dbname;
}
if ($this->persistency)
{
if (!function_exists('ibase_pconnect'))
{
$this->connect_error = 'ibase_pconnect function does not exist, is interbase extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3);
}
else
{
if (!function_exists('ibase_connect'))
{
$this->connect_error = 'ibase_connect function does not exist, is interbase extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3);
}
// Do not call ibase_service_attach if connection failed,
// otherwise error message from ibase_(p)connect call will be clobbered.
if ($this->db_connect_id && function_exists('ibase_service_attach') && $this->server)
{
$this->service_handle = @ibase_service_attach($this->server, $this->user, $sqlpassword);
}
else
{
$this->service_handle = false;
}
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache forced to false for Interbase
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
/**
* force $use_cache false. I didn't research why the caching code there is no caching code
* but I assume its because the IB extension provides a direct method to access it
* without a query.
*/
$use_cache = false;
if ($this->service_handle !== false && function_exists('ibase_server_info'))
{
return @ibase_server_info($this->service_handle, IBASE_SVC_SERVER_VERSION);
}
return ($raw) ? '2.1' : 'Firebird/Interbase';
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return true;
break;
case 'commit':
return @ibase_commit();
break;
case 'rollback':
return @ibase_rollback();
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->last_query_text = $query;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
$array = array();
// We overcome Firebird's 32767 char limit by binding vars
if (strlen($query) > 32767)
{
if (preg_match('/^(INSERT INTO[^(]++)\\(([^()]+)\\) VALUES[^(]++\\((.*?)\\)$/s', $query, $regs))
{
if (strlen($regs[3]) > 32767)
{
preg_match_all('/\'(?:[^\']++|\'\')*+\'|[\d-.]+/', $regs[3], $vals, PREG_PATTERN_ORDER);
$inserts = $vals[0];
unset($vals);
foreach ($inserts as $key => $value)
{
if (!empty($value) && $value[0] === "'" && strlen($value) > 32769) // check to see if this thing is greater than the max + 'x2
{
$inserts[$key] = '?';
$array[] = str_replace("''", "'", substr($value, 1, -1));
}
}
$query = $regs[1] . '(' . $regs[2] . ') VALUES (' . implode(', ', $inserts) . ')';
}
}
else if (preg_match('/^(UPDATE ([\\w_]++)\\s+SET )([\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|\\d+)(?:,\\s*[\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+))*+)\\s+(WHERE.*)$/s', $query, $data))
{
if (strlen($data[3]) > 32767)
{
$update = $data[1];
$where = $data[4];
preg_match_all('/(\\w++)\\s*=\\s*(\'(?:[^\']++|\'\')*+\'|[\d-.]++)/', $data[3], $temp, PREG_SET_ORDER);
unset($data);
$cols = array();
foreach ($temp as $value)
{
if (!empty($value[2]) && $value[2][0] === "'" && strlen($value[2]) > 32769) // check to see if this thing is greater than the max + 'x2
{
$array[] = str_replace("''", "'", substr($value[2], 1, -1));
$cols[] = $value[1] . '=?';
}
else
{
$cols[] = $value[1] . '=' . $value[2];
}
}
$query = $update . implode(', ', $cols) . ' ' . $where;
unset($cols);
}
}
}
if (!function_exists('ibase_affected_rows') && (preg_match('/^UPDATE ([\w_]++)\s+SET [\w_]++\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+)(?:,\s*[\w_]++\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+))*+\s+(WHERE.*)?$/s', $query, $regs) || preg_match('/^DELETE FROM ([\w_]++)\s*(WHERE\s*.*)?$/s', $query, $regs)))
{
$affected_sql = 'SELECT COUNT(*) as num_rows_affected FROM ' . $regs[1];
if (!empty($regs[2]))
{
$affected_sql .= ' ' . $regs[2];
}
if (!($temp_q_id = @ibase_query($this->db_connect_id, $affected_sql)))
{
return false;
}
$temp_result = @ibase_fetch_assoc($temp_q_id);
@ibase_free_result($temp_q_id);
$this->affected_rows = ($temp_result) ? $temp_result['NUM_ROWS_AFFECTED'] : false;
}
if (sizeof($array))
{
$p_query = @ibase_prepare($this->db_connect_id, $query);
array_unshift($array, $p_query);
$this->query_result = call_user_func_array('ibase_execute', $array);
unset($array);
if ($this->query_result === false)
{
$this->sql_error($query);
}
}
else if (($this->query_result = @ibase_query($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if (!$this->transaction)
{
if (function_exists('ibase_commit_ret'))
{
@ibase_commit_ret();
}
else
{
// way cooler than ibase_commit_ret :D
@ibase_query('COMMIT RETAIN;');
}
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
$query = 'SELECT FIRST ' . $total . ((!empty($offset)) ? ' SKIP ' . $offset : '') . substr($query, 6);
return $this->sql_query($query, $cache_ttl);
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
// PHP 5+ function
if (function_exists('ibase_affected_rows'))
{
return ($this->db_connect_id) ? @ibase_affected_rows($this->db_connect_id) : false;
}
else
{
return $this->affected_rows;
}
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
if ($query_id === false)
{
return false;
}
$row = array();
$cur_row = @ibase_fetch_object($query_id, IBASE_TEXT);
if (!$cur_row)
{
return false;
}
foreach (get_object_vars($cur_row) as $key => $value)
{
$row[strtolower($key)] = (is_string($value)) ? trim(str_replace(array("\\0", "\\n"), array("\0", "\n"), $value)) : $value;
}
return (sizeof($row)) ? $row : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
$query_id = $this->query_result;
if ($query_id !== false && $this->last_query_text != '')
{
if ($this->query_result && preg_match('#^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)#i', $this->last_query_text, $tablename))
{
$sql = 'SELECT GEN_ID(' . $tablename[1] . '_gen, 0) AS new_id FROM RDB$DATABASE';
if (!($temp_q_id = @ibase_query($this->db_connect_id, $sql)))
{
return false;
}
$temp_result = @ibase_fetch_assoc($temp_q_id);
@ibase_free_result($temp_q_id);
return ($temp_result) ? $temp_result['NEW_ID'] : false;
}
}
return false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
if (isset($this->open_queries[(int) $query_id]))
{
unset($this->open_queries[(int) $query_id]);
return @ibase_free_result($query_id);
}
return false;
}
/**
* Escape string used in sql query
*/
function sql_escape($msg)
{
return str_replace(array("'", "\0"), array("''", ''), $msg);
}
/**
* Build LIKE expression
* @access private
*/
function _sql_like_expression($expression)
{
return $expression . " ESCAPE '\\'";
}
/**
* Build db-specific query data
* @access private
*/
function _sql_custom_build($stage, $data)
{
return $data;
}
function _sql_bit_and($column_name, $bit, $compare = '')
{
return 'BIN_AND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
}
function _sql_bit_or($column_name, $bit, $compare = '')
{
return 'BIN_OR(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
}
/**
* @inheritdoc
*/
function cast_expr_to_bigint($expression)
{
// Precision must be from 1 to 18
return 'CAST(' . $expression . ' as DECIMAL(18, 0))';
}
/**
* @inheritdoc
*/
function cast_expr_to_string($expression)
{
return 'CAST(' . $expression . ' as VARCHAR(255))';
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
// Need special handling here because ibase_errmsg returns
// connection errors, however if the interbase extension
// is not installed then ibase_errmsg does not exist and
// we cannot call it.
if (function_exists('ibase_errmsg'))
{
$msg = @ibase_errmsg();
if (!$msg)
{
$msg = $this->connect_error;
}
}
else
{
$msg = $this->connect_error;
}
return array(
'message' => $msg,
'code' => (@function_exists('ibase_errcode') ? @ibase_errcode() : '')
);
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
if ($this->service_handle !== false)
{
@ibase_service_detach($this->service_handle);
}
return @ibase_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
switch ($mode)
{
case 'start':
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @ibase_query($this->db_connect_id, $query);
while ($void = @ibase_fetch_object($result, IBASE_TEXT))
{
// Take the time spent on parsing rows into account
}
@ibase_free_result($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,472 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* MSSQL Database Abstraction Layer
* Minimum Requirement is MSSQL 2000+
* @package dbal
*/
class phpbb_db_driver_mssql extends phpbb_db_driver
{
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
if (!function_exists('mssql_connect'))
{
$this->connect_error = 'mssql_connect function does not exist, is mssql extension installed?';
return $this->sql_error('');
}
$this->persistency = $persistency;
$this->user = $sqluser;
$this->dbname = $database;
$port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':';
$this->server = $sqlserver . (($port) ? $port_delimiter . $port : '');
@ini_set('mssql.charset', 'UTF-8');
@ini_set('mssql.textlimit', 2147483647);
@ini_set('mssql.textsize', 2147483647);
$this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mssql_connect($this->server, $this->user, $sqlpassword, $new_link);
if ($this->db_connect_id && $this->dbname != '')
{
if (!@mssql_select_db($this->dbname, $this->db_connect_id))
{
@mssql_close($this->db_connect_id);
return false;
}
}
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache If true, it is safe to retrieve the value from the cache
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
global $cache;
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mssql_version')) === false)
{
$result_id = @mssql_query("SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')", $this->db_connect_id);
$row = false;
if ($result_id)
{
$row = @mssql_fetch_assoc($result_id);
@mssql_free_result($result_id);
}
$this->sql_server_version = ($row) ? trim(implode(' ', $row)) : 0;
if (!empty($cache) && $use_cache)
{
$cache->put('mssql_version', $this->sql_server_version);
}
}
if ($raw)
{
return $this->sql_server_version;
}
return ($this->sql_server_version) ? 'MSSQL<br />' . $this->sql_server_version : 'MSSQL';
}
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return $expr1 . ' + ' . $expr2;
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return @mssql_query('BEGIN TRANSACTION', $this->db_connect_id);
break;
case 'commit':
return @mssql_query('COMMIT TRANSACTION', $this->db_connect_id);
break;
case 'rollback':
return @mssql_query('ROLLBACK TRANSACTION', $this->db_connect_id);
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
if (($this->query_result = @mssql_query($query, $this->db_connect_id)) === false)
{
$this->sql_error($query);
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
// Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
if ($total)
{
// We need to grab the total number of rows + the offset number of rows to get the correct result
if (strpos($query, 'SELECT DISTINCT') === 0)
{
$query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
}
else
{
$query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
}
}
$result = $this->sql_query($query, $cache_ttl);
// Seek by $offset rows
if ($offset)
{
$this->sql_rowseek($offset, $result);
}
return $result;
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->db_connect_id) ? @mssql_rows_affected($this->db_connect_id) : false;
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
if ($query_id === false)
{
return false;
}
$row = @mssql_fetch_assoc($query_id);
// I hope i am able to remove this later... hopefully only a PHP or MSSQL bug
if ($row)
{
foreach ($row as $key => $value)
{
$row[$key] = ($value === ' ' || $value === NULL) ? '' : $value;
}
}
return $row;
}
/**
* Seek to given row number
* rownum is zero-based
*/
function sql_rowseek($rownum, &$query_id)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
return ($query_id !== false) ? @mssql_data_seek($query_id, $rownum) : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
$result_id = @mssql_query('SELECT SCOPE_IDENTITY()', $this->db_connect_id);
if ($result_id)
{
if ($row = @mssql_fetch_assoc($result_id))
{
@mssql_free_result($result_id);
return $row['computed'];
}
@mssql_free_result($result_id);
}
return false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
if (isset($this->open_queries[$query_id]))
{
unset($this->open_queries[$query_id]);
return @mssql_free_result($query_id);
}
return false;
}
/**
* Escape string used in sql query
*/
function sql_escape($msg)
{
return str_replace(array("'", "\0"), array("''", ''), $msg);
}
/**
* {@inheritDoc}
*/
function sql_lower_text($column_name)
{
return "LOWER(SUBSTRING($column_name, 1, DATALENGTH($column_name)))";
}
/**
* Build LIKE expression
* @access private
*/
function _sql_like_expression($expression)
{
return $expression . " ESCAPE '\\'";
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
if (function_exists('mssql_get_last_message'))
{
$error = array(
'message' => @mssql_get_last_message(),
'code' => '',
);
// Get error code number
$result_id = @mssql_query('SELECT @@ERROR as code', $this->db_connect_id);
if ($result_id)
{
$row = @mssql_fetch_assoc($result_id);
$error['code'] = $row['code'];
@mssql_free_result($result_id);
}
// Get full error message if possible
$sql = 'SELECT CAST(description as varchar(255)) as message
FROM master.dbo.sysmessages
WHERE error = ' . $error['code'];
$result_id = @mssql_query($sql);
if ($result_id)
{
$row = @mssql_fetch_assoc($result_id);
if (!empty($row['message']))
{
$error['message'] .= '<br />' . $row['message'];
}
@mssql_free_result($result_id);
}
}
else
{
$error = array(
'message' => $this->connect_error,
'code' => '',
);
}
return $error;
}
/**
* Build db-specific query data
* @access private
*/
function _sql_custom_build($stage, $data)
{
return $data;
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @mssql_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
switch ($mode)
{
case 'start':
$html_table = false;
@mssql_query('SET SHOWPLAN_TEXT ON;', $this->db_connect_id);
if ($result = @mssql_query($query, $this->db_connect_id))
{
@mssql_next_result($result);
while ($row = @mssql_fetch_row($result))
{
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
}
@mssql_query('SET SHOWPLAN_TEXT OFF;', $this->db_connect_id);
@mssql_free_result($result);
if ($html_table)
{
$this->html_hold .= '</table>';
}
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @mssql_query($query, $this->db_connect_id);
while ($void = @mssql_fetch_assoc($result))
{
// Take the time spent on parsing rows into account
}
@mssql_free_result($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,65 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* MSSQL Database Base Abstraction Layer
* @package dbal
*/
abstract class phpbb_db_driver_mssql_base extends phpbb_db_driver
{
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return $expr1 . ' + ' . $expr2;
}
/**
* Escape string used in sql query
*/
function sql_escape($msg)
{
return str_replace(array("'", "\0"), array("''", ''), $msg);
}
/**
* {@inheritDoc}
*/
function sql_lower_text($column_name)
{
return "LOWER(SUBSTRING($column_name, 1, DATALENGTH($column_name)))";
}
/**
* Build LIKE expression
* @access private
*/
function _sql_like_expression($expression)
{
return $expression . " ESCAPE '\\'";
}
/**
* Build db-specific query data
* @access private
*/
function _sql_custom_build($stage, $data)
{
return $data;
}
}

View File

@@ -1,383 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Unified ODBC functions
* Unified ODBC functions support any database having ODBC driver, for example Adabas D, IBM DB2, iODBC, Solid, Sybase SQL Anywhere...
* Here we only support MSSQL Server 2000+ because of the provided schema
*
* @note number of bytes returned for returning data depends on odbc.defaultlrl php.ini setting.
* If it is limited to 4K for example only 4K of data is returned max, resulting in incomplete theme data for example.
* @note odbc.defaultbinmode may affect UTF8 characters
*
* @package dbal
*/
class phpbb_db_driver_mssql_odbc extends phpbb_db_driver_mssql_base
{
var $last_query_text = '';
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->dbname = $database;
$port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':';
$this->server = $sqlserver . (($port) ? $port_delimiter . $port : '');
$max_size = @ini_get('odbc.defaultlrl');
if (!empty($max_size))
{
$unit = strtolower(substr($max_size, -1, 1));
$max_size = (int) $max_size;
if ($unit == 'k')
{
$max_size = floor($max_size / 1024);
}
else if ($unit == 'g')
{
$max_size *= 1024;
}
else if (is_numeric($unit))
{
$max_size = floor((int) ($max_size . $unit) / 1048576);
}
$max_size = max(8, $max_size) . 'M';
@ini_set('odbc.defaultlrl', $max_size);
}
if ($this->persistency)
{
if (!function_exists('odbc_pconnect'))
{
$this->connect_error = 'odbc_pconnect function does not exist, is odbc extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @odbc_pconnect($this->server, $this->user, $sqlpassword);
}
else
{
if (!function_exists('odbc_connect'))
{
$this->connect_error = 'odbc_connect function does not exist, is odbc extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @odbc_connect($this->server, $this->user, $sqlpassword);
}
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache If true, it is safe to retrieve the value from the cache
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
global $cache;
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mssqlodbc_version')) === false)
{
$result_id = @odbc_exec($this->db_connect_id, "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')");
$row = false;
if ($result_id)
{
$row = @odbc_fetch_array($result_id);
@odbc_free_result($result_id);
}
$this->sql_server_version = ($row) ? trim(implode(' ', $row)) : 0;
if (!empty($cache) && $use_cache)
{
$cache->put('mssqlodbc_version', $this->sql_server_version);
}
}
if ($raw)
{
return $this->sql_server_version;
}
return ($this->sql_server_version) ? 'MSSQL (ODBC)<br />' . $this->sql_server_version : 'MSSQL (ODBC)';
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return @odbc_exec($this->db_connect_id, 'BEGIN TRANSACTION');
break;
case 'commit':
return @odbc_exec($this->db_connect_id, 'COMMIT TRANSACTION');
break;
case 'rollback':
return @odbc_exec($this->db_connect_id, 'ROLLBACK TRANSACTION');
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->last_query_text = $query;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
if (($this->query_result = @odbc_exec($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
// Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
if ($total)
{
// We need to grab the total number of rows + the offset number of rows to get the correct result
if (strpos($query, 'SELECT DISTINCT') === 0)
{
$query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
}
else
{
$query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
}
}
$result = $this->sql_query($query, $cache_ttl);
// Seek by $offset rows
if ($offset)
{
$this->sql_rowseek($offset, $result);
}
return $result;
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->db_connect_id) ? @odbc_num_rows($this->query_result) : false;
}
/**
* Fetch current row
* @note number of bytes returned depends on odbc.defaultlrl php.ini setting. If it is limited to 4K for example only 4K of data is returned max.
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
return ($query_id !== false) ? @odbc_fetch_array($query_id) : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
$result_id = @odbc_exec($this->db_connect_id, 'SELECT @@IDENTITY');
if ($result_id)
{
if (@odbc_fetch_array($result_id))
{
$id = @odbc_result($result_id, 1);
@odbc_free_result($result_id);
return $id;
}
@odbc_free_result($result_id);
}
return false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
if (isset($this->open_queries[(int) $query_id]))
{
unset($this->open_queries[(int) $query_id]);
return @odbc_free_result($query_id);
}
return false;
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
if (function_exists('odbc_errormsg'))
{
$error = array(
'message' => @odbc_errormsg(),
'code' => @odbc_error(),
);
}
else
{
$error = array(
'message' => $this->connect_error,
'code' => '',
);
}
return $error;
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @odbc_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
switch ($mode)
{
case 'start':
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @odbc_exec($this->db_connect_id, $query);
while ($void = @odbc_fetch_array($result))
{
// Take the time spent on parsing rows into account
}
@odbc_free_result($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,613 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
* This is the MS SQL Server Native database abstraction layer.
* PHP mssql native driver required.
* @author Chris Pucci
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Prior to version 1.1 the SQL Server Native PHP driver didn't support sqlsrv_num_rows, or cursor based seeking so we recall all rows into an array
* and maintain our own cursor index into that array.
*/
class result_mssqlnative
{
public function result_mssqlnative($queryresult = false)
{
$this->m_cursor = 0;
$this->m_rows = array();
$this->m_num_fields = sqlsrv_num_fields($queryresult);
$this->m_field_meta = sqlsrv_field_metadata($queryresult);
while ($row = sqlsrv_fetch_array($queryresult, SQLSRV_FETCH_ASSOC))
{
if ($row !== null)
{
foreach($row as $k => $v)
{
if (is_object($v) && method_exists($v, 'format'))
{
$row[$k] = $v->format("Y-m-d\TH:i:s\Z");
}
}
$this->m_rows[] = $row;//read results into memory, cursors are not supported
}
}
$this->m_row_count = sizeof($this->m_rows);
}
private function array_to_obj($array, &$obj)
{
foreach ($array as $key => $value)
{
if (is_array($value))
{
$obj->$key = new stdClass();
array_to_obj($value, $obj->$key);
}
else
{
$obj->$key = $value;
}
}
return $obj;
}
public function fetch($mode = SQLSRV_FETCH_BOTH, $object_class = 'stdClass')
{
if ($this->m_cursor >= $this->m_row_count || $this->m_row_count == 0)
{
return false;
}
$ret = false;
$arr_num = array();
if ($mode == SQLSRV_FETCH_NUMERIC || $mode == SQLSRV_FETCH_BOTH)
{
foreach($this->m_rows[$this->m_cursor] as $key => $value)
{
$arr_num[] = $value;
}
}
switch ($mode)
{
case SQLSRV_FETCH_ASSOC:
$ret = $this->m_rows[$this->m_cursor];
break;
case SQLSRV_FETCH_NUMERIC:
$ret = $arr_num;
break;
case 'OBJECT':
$ret = $this->array_to_obj($this->m_rows[$this->m_cursor], $o = new $object_class);
break;
case SQLSRV_FETCH_BOTH:
default:
$ret = $this->m_rows[$this->m_cursor] + $arr_num;
break;
}
$this->m_cursor++;
return $ret;
}
public function get($pos, $fld)
{
return $this->m_rows[$pos][$fld];
}
public function num_rows()
{
return $this->m_row_count;
}
public function seek($iRow)
{
$this->m_cursor = min($iRow, $this->m_row_count);
}
public function num_fields()
{
return $this->m_num_fields;
}
public function field_name($nr)
{
$arr_keys = array_keys($this->m_rows[0]);
return $arr_keys[$nr];
}
public function field_type($nr)
{
$i = 0;
$int_type = -1;
$str_type = '';
foreach ($this->m_field_meta as $meta)
{
if ($nr == $i)
{
$int_type = $meta['Type'];
break;
}
$i++;
}
//http://msdn.microsoft.com/en-us/library/cc296183.aspx contains type table
switch ($int_type)
{
case SQLSRV_SQLTYPE_BIGINT: $str_type = 'bigint'; break;
case SQLSRV_SQLTYPE_BINARY: $str_type = 'binary'; break;
case SQLSRV_SQLTYPE_BIT: $str_type = 'bit'; break;
case SQLSRV_SQLTYPE_CHAR: $str_type = 'char'; break;
case SQLSRV_SQLTYPE_DATETIME: $str_type = 'datetime'; break;
case SQLSRV_SQLTYPE_DECIMAL/*($precision, $scale)*/: $str_type = 'decimal'; break;
case SQLSRV_SQLTYPE_FLOAT: $str_type = 'float'; break;
case SQLSRV_SQLTYPE_IMAGE: $str_type = 'image'; break;
case SQLSRV_SQLTYPE_INT: $str_type = 'int'; break;
case SQLSRV_SQLTYPE_MONEY: $str_type = 'money'; break;
case SQLSRV_SQLTYPE_NCHAR/*($charCount)*/: $str_type = 'nchar'; break;
case SQLSRV_SQLTYPE_NUMERIC/*($precision, $scale)*/: $str_type = 'numeric'; break;
case SQLSRV_SQLTYPE_NVARCHAR/*($charCount)*/: $str_type = 'nvarchar'; break;
case SQLSRV_SQLTYPE_NTEXT: $str_type = 'ntext'; break;
case SQLSRV_SQLTYPE_REAL: $str_type = 'real'; break;
case SQLSRV_SQLTYPE_SMALLDATETIME: $str_type = 'smalldatetime'; break;
case SQLSRV_SQLTYPE_SMALLINT: $str_type = 'smallint'; break;
case SQLSRV_SQLTYPE_SMALLMONEY: $str_type = 'smallmoney'; break;
case SQLSRV_SQLTYPE_TEXT: $str_type = 'text'; break;
case SQLSRV_SQLTYPE_TIMESTAMP: $str_type = 'timestamp'; break;
case SQLSRV_SQLTYPE_TINYINT: $str_type = 'tinyint'; break;
case SQLSRV_SQLTYPE_UNIQUEIDENTIFIER: $str_type = 'uniqueidentifier'; break;
case SQLSRV_SQLTYPE_UDT: $str_type = 'UDT'; break;
case SQLSRV_SQLTYPE_VARBINARY/*($byteCount)*/: $str_type = 'varbinary'; break;
case SQLSRV_SQLTYPE_VARCHAR/*($charCount)*/: $str_type = 'varchar'; break;
case SQLSRV_SQLTYPE_XML: $str_type = 'xml'; break;
default: $str_type = $int_type;
}
return $str_type;
}
public function free()
{
unset($this->m_rows);
return;
}
}
/**
* @package dbal
*/
class phpbb_db_driver_mssqlnative extends phpbb_db_driver_mssql_base
{
var $m_insert_id = NULL;
var $last_query_text = '';
var $query_options = array();
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
// Test for driver support, to avoid suppressed fatal error
if (!function_exists('sqlsrv_connect'))
{
$this->connect_error = 'Native MS SQL Server driver for PHP is missing or needs to be updated. Version 1.1 or later is required to install phpBB3. You can download the driver from: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx';
return $this->sql_error('');
}
//set up connection variables
$this->persistency = $persistency;
$this->user = $sqluser;
$this->dbname = $database;
$port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':';
$this->server = $sqlserver . (($port) ? $port_delimiter . $port : '');
//connect to database
$this->db_connect_id = sqlsrv_connect($this->server, array(
'Database' => $this->dbname,
'UID' => $this->user,
'PWD' => $sqlpassword
));
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache If true, it is safe to retrieve the value from the cache
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
global $cache;
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mssql_version')) === false)
{
$arr_server_info = sqlsrv_server_info($this->db_connect_id);
$this->sql_server_version = $arr_server_info['SQLServerVersion'];
if (!empty($cache) && $use_cache)
{
$cache->put('mssql_version', $this->sql_server_version);
}
}
if ($raw)
{
return $this->sql_server_version;
}
return ($this->sql_server_version) ? 'MSSQL<br />' . $this->sql_server_version : 'MSSQL';
}
/**
* {@inheritDoc}
*/
function sql_buffer_nested_transactions()
{
return true;
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return sqlsrv_begin_transaction($this->db_connect_id);
break;
case 'commit':
return sqlsrv_commit($this->db_connect_id);
break;
case 'rollback':
return sqlsrv_rollback($this->db_connect_id);
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->last_query_text = $query;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
if (($this->query_result = @sqlsrv_query($this->db_connect_id, $query, array(), $this->query_options)) === false)
{
$this->sql_error($query);
}
// reset options for next query
$this->query_options = array();
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
// total == 0 means all results - not zero results
if ($offset == 0 && $total !== 0)
{
if (strpos($query, "SELECT") === false)
{
$query = "TOP {$total} " . $query;
}
else
{
$query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query);
}
}
else if ($offset > 0)
{
$query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query);
$query = 'SELECT *
FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3
FROM (SELECT 1 AS line2, sub1.* FROM (' . $query . ') AS sub1) as sub2) AS sub3';
if ($total > 0)
{
$query .= ' WHERE line3 BETWEEN ' . ($offset+1) . ' AND ' . ($offset + $total);
}
else
{
$query .= ' WHERE line3 > ' . $offset;
}
}
$result = $this->sql_query($query, $cache_ttl);
return $result;
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->db_connect_id) ? @sqlsrv_rows_affected($this->query_result) : false;
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
if ($query_id === false)
{
return false;
}
$row = @sqlsrv_fetch_array($query_id, SQLSRV_FETCH_ASSOC);
if ($row)
{
foreach ($row as $key => $value)
{
$row[$key] = ($value === ' ' || $value === NULL) ? '' : $value;
}
// remove helper values from LIMIT queries
if (isset($row['line2']))
{
unset($row['line2'], $row['line3']);
}
}
return (sizeof($row)) ? $row : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
$result_id = @sqlsrv_query($this->db_connect_id, 'SELECT @@IDENTITY');
if ($result_id !== false)
{
$row = @sqlsrv_fetch_array($result_id);
$id = $row[0];
@sqlsrv_free_stmt($result_id);
return $id;
}
else
{
return false;
}
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
if (isset($this->open_queries[(int) $query_id]))
{
unset($this->open_queries[(int) $query_id]);
return @sqlsrv_free_stmt($query_id);
}
return false;
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
if (function_exists('sqlsrv_errors'))
{
$errors = @sqlsrv_errors(SQLSRV_ERR_ERRORS);
$error_message = '';
$code = 0;
if ($errors != null)
{
foreach ($errors as $error)
{
$error_message .= "SQLSTATE: " . $error[ 'SQLSTATE'] . "\n";
$error_message .= "code: " . $error[ 'code'] . "\n";
$code = $error['code'];
$error_message .= "message: " . $error[ 'message'] . "\n";
}
$this->last_error_result = $error_message;
$error = $this->last_error_result;
}
else
{
$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
}
$error = array(
'message' => $error,
'code' => $code,
);
}
else
{
$error = array(
'message' => $this->connect_error,
'code' => '',
);
}
return $error;
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @sqlsrv_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
switch ($mode)
{
case 'start':
$html_table = false;
@sqlsrv_query($this->db_connect_id, 'SET SHOWPLAN_TEXT ON;');
if ($result = @sqlsrv_query($this->db_connect_id, $query))
{
@sqlsrv_next_result($result);
while ($row = @sqlsrv_fetch_array($result))
{
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
}
@sqlsrv_query($this->db_connect_id, 'SET SHOWPLAN_TEXT OFF;');
@sqlsrv_free_stmt($result);
if ($html_table)
{
$this->html_hold .= '</table>';
}
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @sqlsrv_query($this->db_connect_id, $query);
while ($void = @sqlsrv_fetch_array($result))
{
// Take the time spent on parsing rows into account
}
@sqlsrv_free_stmt($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
/**
* Utility method used to retrieve number of rows
* Emulates mysql_num_rows
* Used in acp_database.php -> write_data_mssqlnative()
* Requires a static or keyset cursor to be definde via
* mssqlnative_set_query_options()
*/
function mssqlnative_num_rows($res)
{
if ($res !== false)
{
return sqlsrv_num_rows($res);
}
else
{
return false;
}
}
/**
* Allows setting mssqlnative specific query options passed to sqlsrv_query as 4th parameter.
*/
function mssqlnative_set_query_options($options)
{
$this->query_options = $options;
}
}

View File

@@ -1,472 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* MySQL4 Database Abstraction Layer
* Compatible with:
* MySQL 3.23+
* MySQL 4.0+
* MySQL 4.1+
* MySQL 5.0+
* @package dbal
*/
class phpbb_db_driver_mysql extends phpbb_db_driver_mysql_base
{
var $multi_insert = true;
var $connect_error = '';
/**
* Connect to server
* @access public
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->server = $sqlserver . (($port) ? ':' . $port : '');
$this->dbname = $database;
$this->sql_layer = 'mysql4';
if ($this->persistency)
{
if (!function_exists('mysql_pconnect'))
{
$this->connect_error = 'mysql_pconnect function does not exist, is mysql extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @mysql_pconnect($this->server, $this->user, $sqlpassword);
}
else
{
if (!function_exists('mysql_connect'))
{
$this->connect_error = 'mysql_connect function does not exist, is mysql extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @mysql_connect($this->server, $this->user, $sqlpassword, $new_link);
}
if ($this->db_connect_id && $this->dbname != '')
{
if (@mysql_select_db($this->dbname, $this->db_connect_id))
{
// Determine what version we are using and if it natively supports UNICODE
if (version_compare($this->sql_server_info(true), '4.1.0', '>='))
{
@mysql_query("SET NAMES 'utf8'", $this->db_connect_id);
// enforce strict mode on databases that support it
if (version_compare($this->sql_server_info(true), '5.0.2', '>='))
{
$result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id);
$row = @mysql_fetch_assoc($result);
@mysql_free_result($result);
$modes = array_map('trim', explode(',', $row['sql_mode']));
// TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES
if (!in_array('TRADITIONAL', $modes))
{
if (!in_array('STRICT_ALL_TABLES', $modes))
{
$modes[] = 'STRICT_ALL_TABLES';
}
if (!in_array('STRICT_TRANS_TABLES', $modes))
{
$modes[] = 'STRICT_TRANS_TABLES';
}
}
$mode = implode(',', $modes);
@mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id);
}
}
else if (version_compare($this->sql_server_info(true), '4.0.0', '<'))
{
$this->sql_layer = 'mysql';
}
return $this->db_connect_id;
}
}
return $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache If true, it is safe to retrieve the value from the cache
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
global $cache;
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysql_version')) === false)
{
$result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id);
$row = @mysql_fetch_assoc($result);
@mysql_free_result($result);
$this->sql_server_version = $row['version'];
if (!empty($cache) && $use_cache)
{
$cache->put('mysql_version', $this->sql_server_version);
}
}
return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version;
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return @mysql_query('BEGIN', $this->db_connect_id);
break;
case 'commit':
return @mysql_query('COMMIT', $this->db_connect_id);
break;
case 'rollback':
return @mysql_query('ROLLBACK', $this->db_connect_id);
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
{
$this->sql_error($query);
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false;
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
return ($query_id !== false) ? @mysql_fetch_assoc($query_id) : false;
}
/**
* Seek to given row number
* rownum is zero-based
*/
function sql_rowseek($rownum, &$query_id)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
return ($query_id !== false) ? @mysql_data_seek($query_id, $rownum) : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
if (isset($this->open_queries[(int) $query_id]))
{
unset($this->open_queries[(int) $query_id]);
return @mysql_free_result($query_id);
}
return false;
}
/**
* Escape string used in sql query
*/
function sql_escape($msg)
{
if (!$this->db_connect_id)
{
return @mysql_real_escape_string($msg);
}
return @mysql_real_escape_string($msg, $this->db_connect_id);
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
if ($this->db_connect_id)
{
$error = array(
'message' => @mysql_error($this->db_connect_id),
'code' => @mysql_errno($this->db_connect_id),
);
}
else if (function_exists('mysql_error'))
{
$error = array(
'message' => @mysql_error(),
'code' => @mysql_errno(),
);
}
else
{
$error = array(
'message' => $this->connect_error,
'code' => '',
);
}
return $error;
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @mysql_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
static $test_prof;
// current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING
if ($test_prof === null)
{
$test_prof = false;
if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<'))
{
$test_prof = true;
}
}
switch ($mode)
{
case 'start':
$explain_query = $query;
if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
{
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
}
else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
{
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
}
if (preg_match('/^SELECT/', $explain_query))
{
$html_table = false;
// begin profiling
if ($test_prof)
{
@mysql_query('SET profiling = 1;', $this->db_connect_id);
}
if ($result = @mysql_query("EXPLAIN $explain_query", $this->db_connect_id))
{
while ($row = @mysql_fetch_assoc($result))
{
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
}
@mysql_free_result($result);
if ($html_table)
{
$this->html_hold .= '</table>';
}
if ($test_prof)
{
$html_table = false;
// get the last profile
if ($result = @mysql_query('SHOW PROFILE ALL;', $this->db_connect_id))
{
$this->html_hold .= '<br />';
while ($row = @mysql_fetch_assoc($result))
{
// make <unknown> HTML safe
if (!empty($row['Source_function']))
{
$row['Source_function'] = str_replace(array('<', '>'), array('&lt;', '&gt;'), $row['Source_function']);
}
// remove unsupported features
foreach ($row as $key => $val)
{
if ($val === null)
{
unset($row[$key]);
}
}
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
}
@mysql_free_result($result);
if ($html_table)
{
$this->html_hold .= '</table>';
}
@mysql_query('SET profiling = 0;', $this->db_connect_id);
}
}
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @mysql_query($query, $this->db_connect_id);
while ($void = @mysql_fetch_assoc($result))
{
// Take the time spent on parsing rows into account
}
@mysql_free_result($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,145 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Abstract MySQL Database Base Abstraction Layer
* @package dbal
*/
abstract class phpbb_db_driver_mysql_base extends phpbb_db_driver
{
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')';
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
// if $total is set to 0 we do not want to limit the number of rows
if ($total == 0)
{
// MySQL 4.1+ no longer supports -1 in limit queries
$total = '18446744073709551615';
}
$query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
return $this->sql_query($query, $cache_ttl);
}
/**
* Gets the estimated number of rows in a specified table.
*
* @param string $table_name Table name
*
* @return string Number of rows in $table_name.
* Prefixed with ~ if estimated (otherwise exact).
*
* @access public
*/
function get_estimated_row_count($table_name)
{
$table_status = $this->get_table_status($table_name);
if (isset($table_status['Engine']))
{
if ($table_status['Engine'] === 'MyISAM')
{
return $table_status['Rows'];
}
else if ($table_status['Engine'] === 'InnoDB' && $table_status['Rows'] > 100000)
{
return '~' . $table_status['Rows'];
}
}
return parent::get_row_count($table_name);
}
/**
* Gets the exact number of rows in a specified table.
*
* @param string $table_name Table name
*
* @return string Exact number of rows in $table_name.
*
* @access public
*/
function get_row_count($table_name)
{
$table_status = $this->get_table_status($table_name);
if (isset($table_status['Engine']) && $table_status['Engine'] === 'MyISAM')
{
return $table_status['Rows'];
}
return parent::get_row_count($table_name);
}
/**
* Gets some information about the specified table.
*
* @param string $table_name Table name
*
* @return array
*
* @access protected
*/
function get_table_status($table_name)
{
$sql = "SHOW TABLE STATUS
LIKE '" . $this->sql_escape($table_name) . "'";
$result = $this->sql_query($sql);
$table_status = $this->sql_fetchrow($result);
$this->sql_freeresult($result);
return $table_status;
}
/**
* Build LIKE expression
* @access private
*/
function _sql_like_expression($expression)
{
return $expression;
}
/**
* Build db-specific query data
* @access private
*/
function _sql_custom_build($stage, $data)
{
switch ($stage)
{
case 'FROM':
$data = '(' . $data . ')';
break;
}
return $data;
}
}

View File

@@ -1,463 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* MySQLi Database Abstraction Layer
* mysqli-extension has to be compiled with:
* MySQL 4.1+ or MySQL 5.0+
* @package dbal
*/
class phpbb_db_driver_mysqli extends phpbb_db_driver_mysql_base
{
var $multi_insert = true;
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false)
{
if (!function_exists('mysqli_connect'))
{
$this->connect_error = 'mysqli_connect function does not exist, is mysqli extension installed?';
return $this->sql_error('');
}
// Mysqli extension supports persistent connection since PHP 5.3.0
$this->persistency = (version_compare(PHP_VERSION, '5.3.0', '>=')) ? $persistency : false;
$this->user = $sqluser;
// If persistent connection, set dbhost to localhost when empty and prepend it with 'p:' prefix
$this->server = ($this->persistency) ? 'p:' . (($sqlserver) ? $sqlserver : 'localhost') : $sqlserver;
$this->dbname = $database;
$port = (!$port) ? NULL : $port;
// If port is set and it is not numeric, most likely mysqli socket is set.
// Try to map it to the $socket parameter.
$socket = NULL;
if ($port)
{
if (is_numeric($port))
{
$port = (int) $port;
}
else
{
$socket = $port;
$port = NULL;
}
}
$this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket);
if ($this->db_connect_id && $this->dbname != '')
{
@mysqli_query($this->db_connect_id, "SET NAMES 'utf8'");
// enforce strict mode on databases that support it
if (version_compare($this->sql_server_info(true), '5.0.2', '>='))
{
$result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode');
$row = @mysqli_fetch_assoc($result);
@mysqli_free_result($result);
$modes = array_map('trim', explode(',', $row['sql_mode']));
// TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES
if (!in_array('TRADITIONAL', $modes))
{
if (!in_array('STRICT_ALL_TABLES', $modes))
{
$modes[] = 'STRICT_ALL_TABLES';
}
if (!in_array('STRICT_TRANS_TABLES', $modes))
{
$modes[] = 'STRICT_TRANS_TABLES';
}
}
$mode = implode(',', $modes);
@mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'");
}
return $this->db_connect_id;
}
return $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache If true, it is safe to retrieve the value from the cache
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
global $cache;
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false)
{
$result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version');
$row = @mysqli_fetch_assoc($result);
@mysqli_free_result($result);
$this->sql_server_version = $row['version'];
if (!empty($cache) && $use_cache)
{
$cache->put('mysqli_version', $this->sql_server_version);
}
}
return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version;
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return @mysqli_autocommit($this->db_connect_id, false);
break;
case 'commit':
$result = @mysqli_commit($this->db_connect_id);
@mysqli_autocommit($this->db_connect_id, true);
return $result;
break;
case 'rollback':
$result = @mysqli_rollback($this->db_connect_id);
@mysqli_autocommit($this->db_connect_id, true);
return $result;
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->db_connect_id) ? @mysqli_affected_rows($this->db_connect_id) : false;
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
if ($query_id !== false)
{
$result = @mysqli_fetch_assoc($query_id);
return $result !== null ? $result : false;
}
return false;
}
/**
* Seek to given row number
* rownum is zero-based
*/
function sql_rowseek($rownum, &$query_id)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
return ($query_id !== false) ? @mysqli_data_seek($query_id, $rownum) : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
return ($this->db_connect_id) ? @mysqli_insert_id($this->db_connect_id) : false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
return @mysqli_free_result($query_id);
}
/**
* Escape string used in sql query
*/
function sql_escape($msg)
{
return @mysqli_real_escape_string($this->db_connect_id, $msg);
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
if ($this->db_connect_id)
{
$error = array(
'message' => @mysqli_error($this->db_connect_id),
'code' => @mysqli_errno($this->db_connect_id)
);
}
else if (function_exists('mysqli_connect_error'))
{
$error = array(
'message' => @mysqli_connect_error(),
'code' => @mysqli_connect_errno(),
);
}
else
{
$error = array(
'message' => $this->connect_error,
'code' => '',
);
}
return $error;
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @mysqli_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
static $test_prof;
// current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING
if ($test_prof === null)
{
$test_prof = false;
if (strpos(mysqli_get_server_info($this->db_connect_id), 'community') !== false)
{
$ver = mysqli_get_server_version($this->db_connect_id);
if ($ver >= 50037 && $ver < 50100)
{
$test_prof = true;
}
}
}
switch ($mode)
{
case 'start':
$explain_query = $query;
if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
{
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
}
else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
{
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
}
if (preg_match('/^SELECT/', $explain_query))
{
$html_table = false;
// begin profiling
if ($test_prof)
{
@mysqli_query($this->db_connect_id, 'SET profiling = 1;');
}
if ($result = @mysqli_query($this->db_connect_id, "EXPLAIN $explain_query"))
{
while ($row = @mysqli_fetch_assoc($result))
{
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
}
@mysqli_free_result($result);
if ($html_table)
{
$this->html_hold .= '</table>';
}
if ($test_prof)
{
$html_table = false;
// get the last profile
if ($result = @mysqli_query($this->db_connect_id, 'SHOW PROFILE ALL;'))
{
$this->html_hold .= '<br />';
while ($row = @mysqli_fetch_assoc($result))
{
// make <unknown> HTML safe
if (!empty($row['Source_function']))
{
$row['Source_function'] = str_replace(array('<', '>'), array('&lt;', '&gt;'), $row['Source_function']);
}
// remove unsupported features
foreach ($row as $key => $val)
{
if ($val === null)
{
unset($row[$key]);
}
}
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
}
@mysqli_free_result($result);
if ($html_table)
{
$this->html_hold .= '</table>';
}
@mysqli_query($this->db_connect_id, 'SET profiling = 0;');
}
}
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @mysqli_query($this->db_connect_id, $query);
while ($void = @mysqli_fetch_assoc($result))
{
// Take the time spent on parsing rows into account
}
@mysqli_free_result($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,803 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Oracle Database Abstraction Layer
* @package dbal
*/
class phpbb_db_driver_oracle extends phpbb_db_driver
{
var $last_query_text = '';
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->server = $sqlserver . (($port) ? ':' . $port : '');
$this->dbname = $database;
$connect = $database;
// support for "easy connect naming"
if ($sqlserver !== '' && $sqlserver !== '/')
{
if (substr($sqlserver, -1, 1) == '/')
{
$sqlserver == substr($sqlserver, 0, -1);
}
$connect = $sqlserver . (($port) ? ':' . $port : '') . '/' . $database;
}
if ($new_link)
{
if (!function_exists('ocinlogon'))
{
$this->connect_error = 'ocinlogon function does not exist, is oci extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ocinlogon($this->user, $sqlpassword, $connect, 'UTF8');
}
else if ($this->persistency)
{
if (!function_exists('ociplogon'))
{
$this->connect_error = 'ociplogon function does not exist, is oci extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ociplogon($this->user, $sqlpassword, $connect, 'UTF8');
}
else
{
if (!function_exists('ocilogon'))
{
$this->connect_error = 'ocilogon function does not exist, is oci extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ocilogon($this->user, $sqlpassword, $connect, 'UTF8');
}
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache forced to false for Oracle
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
/**
* force $use_cache false. I didn't research why the caching code below is commented out
* but I assume its because the Oracle extension provides a direct method to access it
* without a query.
*/
$use_cache = false;
/*
global $cache;
if (empty($cache) || ($this->sql_server_version = $cache->get('oracle_version')) === false)
{
$result = @ociparse($this->db_connect_id, 'SELECT * FROM v$version WHERE banner LIKE \'Oracle%\'');
@ociexecute($result, OCI_DEFAULT);
@ocicommit($this->db_connect_id);
$row = array();
@ocifetchinto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS);
@ocifreestatement($result);
$this->sql_server_version = trim($row['BANNER']);
$cache->put('oracle_version', $this->sql_server_version);
}
*/
$this->sql_server_version = @ociserverversion($this->db_connect_id);
return $this->sql_server_version;
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return true;
break;
case 'commit':
return @ocicommit($this->db_connect_id);
break;
case 'rollback':
return @ocirollback($this->db_connect_id);
break;
}
return true;
}
/**
* Oracle specific code to handle the fact that it does not compare columns properly
* @access private
*/
function _rewrite_col_compare($args)
{
if (sizeof($args) == 4)
{
if ($args[2] == '=')
{
return '(' . $args[0] . ' OR (' . $args[1] . ' is NULL AND ' . $args[3] . ' is NULL))';
}
else if ($args[2] == '<>')
{
// really just a fancy way of saying foo <> bar or (foo is NULL XOR bar is NULL) but SQL has no XOR :P
return '(' . $args[0] . ' OR ((' . $args[1] . ' is NULL AND ' . $args[3] . ' is NOT NULL) OR (' . $args[1] . ' is NOT NULL AND ' . $args[3] . ' is NULL)))';
}
}
else
{
return $this->_rewrite_where($args[0]);
}
}
/**
* Oracle specific code to handle it's lack of sanity
* @access private
*/
function _rewrite_where($where_clause)
{
preg_match_all('/\s*(AND|OR)?\s*([\w_.()]++)\s*(?:(=|<[=>]?|>=?|LIKE)\s*((?>\'(?>[^\']++|\'\')*+\'|[\d-.()]+))|((NOT )?IN\s*\((?>\'(?>[^\']++|\'\')*+\',? ?|[\d-.]+,? ?)*+\)))/', $where_clause, $result, PREG_SET_ORDER);
$out = '';
foreach ($result as $val)
{
if (!isset($val[5]))
{
if ($val[4] !== "''")
{
$out .= $val[0];
}
else
{
$out .= ' ' . $val[1] . ' ' . $val[2];
if ($val[3] == '=')
{
$out .= ' is NULL';
}
else if ($val[3] == '<>')
{
$out .= ' is NOT NULL';
}
}
}
else
{
$in_clause = array();
$sub_exp = substr($val[5], strpos($val[5], '(') + 1, -1);
$extra = false;
preg_match_all('/\'(?>[^\']++|\'\')*+\'|[\d-.]++/', $sub_exp, $sub_vals, PREG_PATTERN_ORDER);
$i = 0;
foreach ($sub_vals[0] as $sub_val)
{
// two things:
// 1) This determines if an empty string was in the IN clausing, making us turn it into a NULL comparison
// 2) This fixes the 1000 list limit that Oracle has (ORA-01795)
if ($sub_val !== "''")
{
$in_clause[(int) $i++/1000][] = $sub_val;
}
else
{
$extra = true;
}
}
if (!$extra && $i < 1000)
{
$out .= $val[0];
}
else
{
$out .= ' ' . $val[1] . '(';
$in_array = array();
// constuct each IN() clause
foreach ($in_clause as $in_values)
{
$in_array[] = $val[2] . ' ' . (isset($val[6]) ? $val[6] : '') . 'IN(' . implode(', ', $in_values) . ')';
}
// Join the IN() clauses against a few ORs (IN is just a nicer OR anyway)
$out .= implode(' OR ', $in_array);
// handle the empty string case
if ($extra)
{
$out .= ' OR ' . $val[2] . ' is ' . (isset($val[6]) ? $val[6] : '') . 'NULL';
}
$out .= ')';
unset($in_array, $in_clause);
}
}
}
return $out;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->last_query_text = $query;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
$in_transaction = false;
if (!$this->transaction)
{
$this->sql_transaction('begin');
}
else
{
$in_transaction = true;
}
$array = array();
// We overcome Oracle's 4000 char limit by binding vars
if (strlen($query) > 4000)
{
if (preg_match('/^(INSERT INTO[^(]++)\\(([^()]+)\\) VALUES[^(]++\\((.*?)\\)$/sU', $query, $regs))
{
if (strlen($regs[3]) > 4000)
{
$cols = explode(', ', $regs[2]);
preg_match_all('/\'(?:[^\']++|\'\')*+\'|[\d-.]+/', $regs[3], $vals, PREG_PATTERN_ORDER);
/* The code inside this comment block breaks clob handling, but does allow the
database restore script to work. If you want to allow no posts longer than 4KB
and/or need the db restore script, uncomment this.
if (sizeof($cols) !== sizeof($vals))
{
// Try to replace some common data we know is from our restore script or from other sources
$regs[3] = str_replace("'||chr(47)||'", '/', $regs[3]);
$_vals = explode(', ', $regs[3]);
$vals = array();
$is_in_val = false;
$i = 0;
$string = '';
foreach ($_vals as $value)
{
if (strpos($value, "'") === false && !$is_in_val)
{
$vals[$i++] = $value;
continue;
}
if (substr($value, -1) === "'")
{
$vals[$i] = $string . (($is_in_val) ? ', ' : '') . $value;
$string = '';
$is_in_val = false;
if ($vals[$i][0] !== "'")
{
$vals[$i] = "''" . $vals[$i];
}
$i++;
continue;
}
else
{
$string .= (($is_in_val) ? ', ' : '') . $value;
$is_in_val = true;
}
}
if ($string)
{
// New value if cols != value
$vals[(sizeof($cols) !== sizeof($vals)) ? $i : $i - 1] .= $string;
}
$vals = array(0 => $vals);
}
*/
$inserts = $vals[0];
unset($vals);
foreach ($inserts as $key => $value)
{
if (!empty($value) && $value[0] === "'" && strlen($value) > 4002) // check to see if this thing is greater than the max + 'x2
{
$inserts[$key] = ':' . strtoupper($cols[$key]);
$array[$inserts[$key]] = str_replace("''", "'", substr($value, 1, -1));
}
}
$query = $regs[1] . '(' . $regs[2] . ') VALUES (' . implode(', ', $inserts) . ')';
}
}
else if (preg_match_all('/^(UPDATE [\\w_]++\\s+SET )([\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+)(?:,\\s*[\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+))*+)\\s+(WHERE.*)$/s', $query, $data, PREG_SET_ORDER))
{
if (strlen($data[0][2]) > 4000)
{
$update = $data[0][1];
$where = $data[0][3];
preg_match_all('/([\\w_]++)\\s*=\\s*(\'(?:[^\']++|\'\')*+\'|[\d-.]++)/', $data[0][2], $temp, PREG_SET_ORDER);
unset($data);
$cols = array();
foreach ($temp as $value)
{
if (!empty($value[2]) && $value[2][0] === "'" && strlen($value[2]) > 4002) // check to see if this thing is greater than the max + 'x2
{
$cols[] = $value[1] . '=:' . strtoupper($value[1]);
$array[$value[1]] = str_replace("''", "'", substr($value[2], 1, -1));
}
else
{
$cols[] = $value[1] . '=' . $value[2];
}
}
$query = $update . implode(', ', $cols) . ' ' . $where;
unset($cols);
}
}
}
switch (substr($query, 0, 6))
{
case 'DELETE':
if (preg_match('/^(DELETE FROM [\w_]++ WHERE)((?:\s*(?:AND|OR)?\s*[\w_]+\s*(?:(?:=|<>)\s*(?>\'(?>[^\']++|\'\')*+\'|[\d-.]+)|(?:NOT )?IN\s*\((?>\'(?>[^\']++|\'\')*+\',? ?|[\d-.]+,? ?)*+\)))*+)$/', $query, $regs))
{
$query = $regs[1] . $this->_rewrite_where($regs[2]);
unset($regs);
}
break;
case 'UPDATE':
if (preg_match('/^(UPDATE [\\w_]++\\s+SET [\\w_]+\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]++|:\w++)(?:, [\\w_]+\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]++|:\w++))*+\\s+WHERE)(.*)$/s', $query, $regs))
{
$query = $regs[1] . $this->_rewrite_where($regs[2]);
unset($regs);
}
break;
case 'SELECT':
$query = preg_replace_callback('/([\w_.]++)\s*(?:(=|<>)\s*(?>\'(?>[^\']++|\'\')*+\'|[\d-.]++|([\w_.]++))|(?:NOT )?IN\s*\((?>\'(?>[^\']++|\'\')*+\',? ?|[\d-.]++,? ?)*+\))/', array($this, '_rewrite_col_compare'), $query);
break;
}
$this->query_result = @ociparse($this->db_connect_id, $query);
foreach ($array as $key => $value)
{
@ocibindbyname($this->query_result, $key, $array[$key], -1);
}
$success = @ociexecute($this->query_result, OCI_DEFAULT);
if (!$success)
{
$this->sql_error($query);
$this->query_result = false;
}
else
{
if (!$in_transaction)
{
$this->sql_transaction('commit');
}
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
$query = 'SELECT * FROM (SELECT /*+ FIRST_ROWS */ rownum AS xrownum, a.* FROM (' . $query . ') a WHERE rownum <= ' . ($offset + $total) . ') WHERE xrownum >= ' . $offset;
return $this->sql_query($query, $cache_ttl);
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->query_result) ? @ocirowcount($this->query_result) : false;
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
if ($query_id !== false)
{
$row = array();
$result = @ocifetchinto($query_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
if (!$result || !$row)
{
return false;
}
$result_row = array();
foreach ($row as $key => $value)
{
// Oracle treats empty strings as null
if (is_null($value))
{
$value = '';
}
// OCI->CLOB?
if (is_object($value))
{
$value = $value->load();
}
$result_row[strtolower($key)] = $value;
}
return $result_row;
}
return false;
}
/**
* Seek to given row number
* rownum is zero-based
*/
function sql_rowseek($rownum, &$query_id)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
if ($query_id === false)
{
return false;
}
// Reset internal pointer
@ociexecute($query_id, OCI_DEFAULT);
// We do not fetch the row for rownum == 0 because then the next resultset would be the second row
for ($i = 0; $i < $rownum; $i++)
{
if (!$this->sql_fetchrow($query_id))
{
return false;
}
}
return true;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
$query_id = $this->query_result;
if ($query_id !== false && $this->last_query_text != '')
{
if (preg_match('#^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)#is', $this->last_query_text, $tablename))
{
$query = 'SELECT ' . $tablename[1] . '_seq.currval FROM DUAL';
$stmt = @ociparse($this->db_connect_id, $query);
@ociexecute($stmt, OCI_DEFAULT);
$temp_result = @ocifetchinto($stmt, $temp_array, OCI_ASSOC + OCI_RETURN_NULLS);
@ocifreestatement($stmt);
if ($temp_result)
{
return $temp_array['CURRVAL'];
}
else
{
return false;
}
}
}
return false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
if (isset($this->open_queries[(int) $query_id]))
{
unset($this->open_queries[(int) $query_id]);
return @ocifreestatement($query_id);
}
return false;
}
/**
* Escape string used in sql query
*/
function sql_escape($msg)
{
return str_replace(array("'", "\0"), array("''", ''), $msg);
}
/**
* Build LIKE expression
* @access private
*/
function _sql_like_expression($expression)
{
return $expression . " ESCAPE '\\'";
}
function _sql_custom_build($stage, $data)
{
return $data;
}
function _sql_bit_and($column_name, $bit, $compare = '')
{
return 'BITAND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
}
function _sql_bit_or($column_name, $bit, $compare = '')
{
return 'BITOR(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
if (function_exists('ocierror'))
{
$error = @ocierror();
$error = (!$error) ? @ocierror($this->query_result) : $error;
$error = (!$error) ? @ocierror($this->db_connect_id) : $error;
if ($error)
{
$this->last_error_result = $error;
}
else
{
$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
}
}
else
{
$error = array(
'message' => $this->connect_error,
'code' => '',
);
}
return $error;
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @ocilogoff($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
switch ($mode)
{
case 'start':
$html_table = false;
// Grab a plan table, any will do
$sql = "SELECT table_name
FROM USER_TABLES
WHERE table_name LIKE '%PLAN_TABLE%'";
$stmt = ociparse($this->db_connect_id, $sql);
ociexecute($stmt);
$result = array();
if (ocifetchinto($stmt, $result, OCI_ASSOC + OCI_RETURN_NULLS))
{
$table = $result['TABLE_NAME'];
// This is the statement_id that will allow us to track the plan
$statement_id = substr(md5($query), 0, 30);
// Remove any stale plans
$stmt2 = ociparse($this->db_connect_id, "DELETE FROM $table WHERE statement_id='$statement_id'");
ociexecute($stmt2);
ocifreestatement($stmt2);
// Explain the plan
$sql = "EXPLAIN PLAN
SET STATEMENT_ID = '$statement_id'
FOR $query";
$stmt2 = ociparse($this->db_connect_id, $sql);
ociexecute($stmt2);
ocifreestatement($stmt2);
// Get the data from the plan
$sql = "SELECT operation, options, object_name, object_type, cardinality, cost
FROM plan_table
START WITH id = 0 AND statement_id = '$statement_id'
CONNECT BY PRIOR id = parent_id
AND statement_id = '$statement_id'";
$stmt2 = ociparse($this->db_connect_id, $sql);
ociexecute($stmt2);
$row = array();
while (ocifetchinto($stmt2, $row, OCI_ASSOC + OCI_RETURN_NULLS))
{
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
ocifreestatement($stmt2);
// Remove the plan we just made, we delete them on request anyway
$stmt2 = ociparse($this->db_connect_id, "DELETE FROM $table WHERE statement_id='$statement_id'");
ociexecute($stmt2);
ocifreestatement($stmt2);
}
ocifreestatement($stmt);
if ($html_table)
{
$this->html_hold .= '</table>';
}
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @ociparse($this->db_connect_id, $query);
$success = @ociexecute($result, OCI_DEFAULT);
$row = array();
while (@ocifetchinto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS))
{
// Take the time spent on parsing rows into account
}
@ocifreestatement($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,491 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* PostgreSQL Database Abstraction Layer
* Minimum Requirement is Version 7.3+
* @package dbal
*/
class phpbb_db_driver_postgres extends phpbb_db_driver
{
var $last_query_text = '';
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
$connect_string = '';
if ($sqluser)
{
$connect_string .= "user=$sqluser ";
}
if ($sqlpassword)
{
$connect_string .= "password=$sqlpassword ";
}
if ($sqlserver)
{
// $sqlserver can carry a port separated by : for compatibility reasons
// If $sqlserver has more than one : it's probably an IPv6 address.
// In this case we only allow passing a port via the $port variable.
if (substr_count($sqlserver, ':') === 1)
{
list($sqlserver, $port) = explode(':', $sqlserver);
}
if ($sqlserver !== 'localhost')
{
$connect_string .= "host=$sqlserver ";
}
if ($port)
{
$connect_string .= "port=$port ";
}
}
$schema = '';
if ($database)
{
$this->dbname = $database;
if (strpos($database, '.') !== false)
{
list($database, $schema) = explode('.', $database);
}
$connect_string .= "dbname=$database";
}
$this->persistency = $persistency;
if ($this->persistency)
{
if (!function_exists('pg_pconnect'))
{
$this->connect_error = 'pg_pconnect function does not exist, is pgsql extension installed?';
return $this->sql_error('');
}
$collector = new phpbb_error_collector;
$collector->install();
$this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);
}
else
{
if (!function_exists('pg_connect'))
{
$this->connect_error = 'pg_connect function does not exist, is pgsql extension installed?';
return $this->sql_error('');
}
$collector = new phpbb_error_collector;
$collector->install();
$this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);
}
$collector->uninstall();
if ($this->db_connect_id)
{
if (version_compare($this->sql_server_info(true), '8.2', '>='))
{
$this->multi_insert = true;
}
if ($schema !== '')
{
@pg_query($this->db_connect_id, 'SET search_path TO ' . $schema);
}
return $this->db_connect_id;
}
$this->connect_error = $collector->format_errors();
return $this->sql_error('');
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache If true, it is safe to retrieve the value from the cache
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
global $cache;
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false)
{
$query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version');
$row = @pg_fetch_assoc($query_id, null);
@pg_free_result($query_id);
$this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0;
if (!empty($cache) && $use_cache)
{
$cache->put('pgsql_version', $this->sql_server_version);
}
}
return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version;
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return @pg_query($this->db_connect_id, 'BEGIN');
break;
case 'commit':
return @pg_query($this->db_connect_id, 'COMMIT');
break;
case 'rollback':
return @pg_query($this->db_connect_id, 'ROLLBACK');
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->last_query_text = $query;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Build db-specific query data
* @access private
*/
function _sql_custom_build($stage, $data)
{
return $data;
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
// if $total is set to 0 we do not want to limit the number of rows
if ($total == 0)
{
$total = 'ALL';
}
$query .= "\n LIMIT $total OFFSET $offset";
return $this->sql_query($query, $cache_ttl);
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->query_result) ? @pg_affected_rows($this->query_result) : false;
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
return ($query_id !== false) ? @pg_fetch_assoc($query_id, null) : false;
}
/**
* Seek to given row number
* rownum is zero-based
*/
function sql_rowseek($rownum, &$query_id)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
return ($query_id !== false) ? @pg_result_seek($query_id, $rownum) : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
$query_id = $this->query_result;
if ($query_id !== false && $this->last_query_text != '')
{
if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text, $tablename))
{
$query = "SELECT currval('" . $tablename[1] . "_seq') AS last_value";
$temp_q_id = @pg_query($this->db_connect_id, $query);
if (!$temp_q_id)
{
return false;
}
$temp_result = @pg_fetch_assoc($temp_q_id, NULL);
@pg_free_result($query_id);
return ($temp_result) ? $temp_result['last_value'] : false;
}
}
return false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
if (isset($this->open_queries[(int) $query_id]))
{
unset($this->open_queries[(int) $query_id]);
return @pg_free_result($query_id);
}
return false;
}
/**
* Escape string used in sql query
* Note: Do not use for bytea values if we may use them at a later stage
*/
function sql_escape($msg)
{
return @pg_escape_string($msg);
}
/**
* Build LIKE expression
* @access private
*/
function _sql_like_expression($expression)
{
return $expression;
}
/**
* @inheritdoc
*/
function cast_expr_to_bigint($expression)
{
return 'CAST(' . $expression . ' as DECIMAL(255, 0))';
}
/**
* @inheritdoc
*/
function cast_expr_to_string($expression)
{
return 'CAST(' . $expression . ' as VARCHAR(255))';
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
// pg_last_error only works when there is an established connection.
// Connection errors have to be tracked by us manually.
if ($this->db_connect_id)
{
$message = @pg_last_error($this->db_connect_id);
}
else
{
$message = $this->connect_error;
}
return array(
'message' => $message,
'code' => ''
);
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @pg_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
switch ($mode)
{
case 'start':
$explain_query = $query;
if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
{
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
}
else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
{
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
}
if (preg_match('/^SELECT/', $explain_query))
{
$html_table = false;
if ($result = @pg_query($this->db_connect_id, "EXPLAIN $explain_query"))
{
while ($row = @pg_fetch_assoc($result, NULL))
{
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
}
@pg_free_result($result);
if ($html_table)
{
$this->html_hold .= '</table>';
}
}
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @pg_query($this->db_connect_id, $query);
while ($void = @pg_fetch_assoc($result, NULL))
{
// Take the time spent on parsing rows into account
}
@pg_free_result($result);
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,365 +0,0 @@
<?php
/**
*
* @package dbal
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Sqlite Database Abstraction Layer
* Minimum Requirement: 2.8.2+
* @package dbal
*/
class phpbb_db_driver_sqlite extends phpbb_db_driver
{
var $connect_error = '';
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->server = $sqlserver . (($port) ? ':' . $port : '');
$this->dbname = $database;
$error = '';
if ($this->persistency)
{
if (!function_exists('sqlite_popen'))
{
$this->connect_error = 'sqlite_popen function does not exist, is sqlite extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @sqlite_popen($this->server, 0666, $error);
}
else
{
if (!function_exists('sqlite_open'))
{
$this->connect_error = 'sqlite_open function does not exist, is sqlite extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @sqlite_open($this->server, 0666, $error);
}
if ($this->db_connect_id)
{
@sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id);
// @sqlite_query('PRAGMA encoding = "UTF-8"', $this->db_connect_id);
}
return ($this->db_connect_id) ? true : array('message' => $error);
}
/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version
* @param bool $use_cache if true, it is safe to retrieve the stored value from the cache
* @return string sql server version
*/
function sql_server_info($raw = false, $use_cache = true)
{
global $cache;
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('sqlite_version')) === false)
{
$result = @sqlite_query('SELECT sqlite_version() AS version', $this->db_connect_id);
$row = @sqlite_fetch_array($result, SQLITE_ASSOC);
$this->sql_server_version = (!empty($row['version'])) ? $row['version'] : 0;
if (!empty($cache) && $use_cache)
{
$cache->put('sqlite_version', $this->sql_server_version);
}
}
return ($raw) ? $this->sql_server_version : 'SQLite ' . $this->sql_server_version;
}
/**
* SQL Transaction
* @access private
*/
function _sql_transaction($status = 'begin')
{
switch ($status)
{
case 'begin':
return @sqlite_query('BEGIN', $this->db_connect_id);
break;
case 'commit':
return @sqlite_query('COMMIT', $this->db_connect_id);
break;
case 'rollback':
return @sqlite_query('ROLLBACK', $this->db_connect_id);
break;
}
return true;
}
/**
* Base query method
*
* @param string $query Contains the SQL query which shall be executed
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
* @return mixed When casted to bool the returned value returns true on success and false on failure
*
* @access public
*/
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
{
global $cache;
// EXPLAIN only in extra debug mode
if (defined('DEBUG'))
{
$this->sql_report('start', $query);
}
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if ($this->query_result === false)
{
if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false)
{
$this->sql_error($query);
}
if (defined('DEBUG'))
{
$this->sql_report('stop', $query);
}
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
else if (defined('DEBUG'))
{
$this->sql_report('fromcache', $query);
}
}
else
{
return false;
}
return $this->query_result;
}
/**
* Build LIMIT query
*/
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
// if $total is set to 0 we do not want to limit the number of rows
if ($total == 0)
{
$total = -1;
}
$query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
return $this->sql_query($query, $cache_ttl);
}
/**
* Return number of affected rows
*/
function sql_affectedrows()
{
return ($this->db_connect_id) ? @sqlite_changes($this->db_connect_id) : false;
}
/**
* Fetch current row
*/
function sql_fetchrow($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
return ($query_id !== false) ? @sqlite_fetch_array($query_id, SQLITE_ASSOC) : false;
}
/**
* Seek to given row number
* rownum is zero-based
*/
function sql_rowseek($rownum, &$query_id)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
return ($query_id !== false) ? @sqlite_seek($query_id, $rownum) : false;
}
/**
* Get last inserted id after insert statement
*/
function sql_nextid()
{
return ($this->db_connect_id) ? @sqlite_last_insert_rowid($this->db_connect_id) : false;
}
/**
* Free sql result
*/
function sql_freeresult($query_id = false)
{
global $cache;
if ($query_id === false)
{
$query_id = $this->query_result;
}
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
return true;
}
/**
* Escape string used in sql query
*/
function sql_escape($msg)
{
return @sqlite_escape_string($msg);
}
/**
* Correctly adjust LIKE expression for special characters
* For SQLite an underscore is a not-known character... this may change with SQLite3
*/
function sql_like_expression($expression)
{
// Unlike LIKE, GLOB is case sensitive (unfortunatly). SQLite users need to live with it!
// We only catch * and ? here, not the character map possible on file globbing.
$expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression);
$expression = str_replace(array('?', '*'), array("\?", "\*"), $expression);
$expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression);
return 'GLOB \'' . $this->sql_escape($expression) . '\'';
}
/**
* return sql error array
* @access private
*/
function _sql_error()
{
if (function_exists('sqlite_error_string'))
{
$error = array(
'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)),
'code' => @sqlite_last_error($this->db_connect_id),
);
}
else
{
$error = array(
'message' => $this->connect_error,
'code' => '',
);
}
return $error;
}
/**
* Build db-specific query data
* @access private
*/
function _sql_custom_build($stage, $data)
{
return $data;
}
/**
* Close sql connection
* @access private
*/
function _sql_close()
{
return @sqlite_close($this->db_connect_id);
}
/**
* Build db-specific report
* @access private
*/
function _sql_report($mode, $query = '')
{
switch ($mode)
{
case 'start':
break;
case 'fromcache':
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @sqlite_query($query, $this->db_connect_id);
while ($void = @sqlite_fetch_array($result, SQLITE_ASSOC))
{
// Take the time spent on parsing rows into account
}
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
break;
}
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_1_rc1');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.1')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_10 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.10', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_10_rc3');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.10')),
);
}
}

View File

@@ -1,30 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_10_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.10-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_9');
}
public function update_data()
{
return array(
array('config.add', array('email_max_chunk_size', 50)),
array('config.update', array('version', '3.0.10-rc1')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_10_rc2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.10-rc2', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_10_rc1');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.10-rc2')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_10_rc3 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.10-rc3', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_10_rc2');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.10-rc3')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_11 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.11', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_11_rc2');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.11')),
);
}
}

View File

@@ -1,95 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_11_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.11-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_10');
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'cleanup_deactivated_styles'))),
array('custom', array(array(&$this, 'delete_orphan_private_messages'))),
array('config.update', array('version', '3.0.11-rc1')),
);
}
public function cleanup_deactivated_styles()
{
// Updates users having current style a deactivated one
$sql = 'SELECT style_id
FROM ' . STYLES_TABLE . '
WHERE style_active = 0';
$result = $this->sql_query($sql);
$deactivated_style_ids = array();
while ($style_id = $this->db->sql_fetchfield('style_id', false, $result))
{
$deactivated_style_ids[] = (int) $style_id;
}
$this->db->sql_freeresult($result);
if (!empty($deactivated_style_ids))
{
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_style = ' . (int) $this->config['default_style'] .'
WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids);
$this->sql_query($sql);
}
}
public function delete_orphan_private_messages()
{
// Delete orphan private messages
$batch_size = 500;
$sql_array = array(
'SELECT' => 'p.msg_id',
'FROM' => array(
PRIVMSGS_TABLE => 'p',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(PRIVMSGS_TO_TABLE => 't'),
'ON' => 'p.msg_id = t.msg_id',
),
),
'WHERE' => 't.user_id IS NULL',
);
$sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query_limit($sql, $batch_size);
$delete_pms = array();
while ($row = $this->db->sql_fetchrow($result))
{
$delete_pms[] = (int) $row['msg_id'];
}
$this->db->sql_freeresult($result);
if (!empty($delete_pms))
{
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms);
$this->sql_query($sql);
// Return false to have the Migrator call this function again
return false;
}
}
}

View File

@@ -1,50 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_11_rc2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.11-rc2', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_11_rc1');
}
public function update_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_show_novalue' => array('BOOL', 0),
),
),
);
}
public function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_show_novalue',
),
),
);
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.11-rc2')),
);
}
}

View File

@@ -1,123 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
/** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 **/
class phpbb_db_migration_data_30x_3_0_12_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.12-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_11');
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'update_module_auth'))),
array('custom', array(array(&$this, 'update_bots'))),
array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))),
array('config.update', array('version', '3.0.12-rc1')),
);
}
public function disable_bots_from_receiving_pms()
{
// Disable receiving pms for bots
$sql = 'SELECT user_id
FROM ' . BOTS_TABLE;
$result = $this->db->sql_query($sql);
$bot_user_ids = array();
while ($row = $this->db->sql_fetchrow($result))
{
$bot_user_ids[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
if (!empty($bot_user_ids))
{
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_allow_pm = 0
WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids);
$this->sql_query($sql);
}
}
public function update_module_auth()
{
$sql = 'UPDATE ' . MODULES_TABLE . '
SET module_auth = \'acl_u_sig\'
WHERE module_class = \'ucp\'
AND module_basename = \'profile\'
AND module_mode = \'signature\'';
$this->sql_query($sql);
}
public function update_bots()
{
// Update bots
if (!function_exists('user_delete'))
{
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
$bots_updates = array(
// Bot Deletions
'NG-Search [Bot]' => false,
'Nutch/CVS [Bot]' => false,
'OmniExplorer [Bot]' => false,
'Seekport [Bot]' => false,
'Synoo [Bot]' => false,
'WiseNut [Bot]' => false,
// Bot Updates
// Bot name to bot user agent map
'Baidu [Spider]' => 'Baiduspider',
'Exabot [Bot]' => 'Exabot',
'Voyager [Bot]' => 'voyager/',
'W3C [Validator]' => 'W3C_Validator',
);
foreach ($bots_updates as $bot_name => $bot_agent)
{
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . '
WHERE user_type = ' . USER_IGNORE . "
AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'";
$result = $this->db->sql_query($sql);
$bot_user_id = (int) $this->db->sql_fetchfield('user_id');
$this->db->sql_freeresult($result);
if ($bot_user_id)
{
if ($bot_agent === false)
{
$sql = 'DELETE FROM ' . BOTS_TABLE . "
WHERE user_id = $bot_user_id";
$this->sql_query($sql);
user_delete('remove', $bot_user_id);
}
else
{
$sql = 'UPDATE ' . BOTS_TABLE . "
SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "'
WHERE user_id = $bot_user_id";
$this->sql_query($sql);
}
}
}
}
}

View File

@@ -1,108 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_1_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.1-rc1', '>=');
}
public function update_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'forums' => array(
'display_subforum_list' => array('BOOL', 1),
),
$this->table_prefix . 'sessions' => array(
'session_forum_id' => array('UINT', 0),
),
),
'drop_keys' => array(
$this->table_prefix . 'groups' => array(
'group_legend',
),
),
'add_index' => array(
$this->table_prefix . 'sessions' => array(
'session_forum_id' => array('session_forum_id'),
),
$this->table_prefix . 'groups' => array(
'group_legend_name' => array('group_legend', 'group_name'),
),
),
);
}
public function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'forums' => array(
'display_subforum_list',
),
$this->table_prefix . 'sessions' => array(
'session_forum_id',
),
),
'add_index' => array(
$this->table_prefix . 'groups' => array(
'group_legend' => array('group_legend'),
),
),
'drop_keys' => array(
$this->table_prefix . 'sessions' => array(
'session_forum_id',
),
$this->table_prefix . 'groups' => array(
'group_legend_name',
),
),
);
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'fix_unset_last_view_time'))),
array('custom', array(array(&$this, 'reset_smiley_size'))),
array('config.update', array('version', '3.0.1-rc1')),
);
}
public function fix_unset_last_view_time()
{
$sql = 'UPDATE ' . $this->table_prefix . "topics
SET topic_last_view_time = topic_last_post_time
WHERE topic_last_view_time = 0";
$this->sql_query($sql);
}
public function reset_smiley_size()
{
// Update smiley sizes
$smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');
foreach ($smileys as $smiley)
{
if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley))
{
list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley);
$sql = 'UPDATE ' . SMILIES_TABLE . '
SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'";
$this->sql_query($sql);
}
}
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.2', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_2_rc2');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.2')),
);
}
}

View File

@@ -1,32 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_2_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.2-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_1');
}
public function update_data()
{
return array(
array('config.add', array('referer_validation', '1')),
array('config.add', array('check_attachment_content', '1')),
array('config.add', array('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title')),
array('config.update', array('version', '3.0.2-rc1')),
);
}
}

View File

@@ -1,80 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_2_rc2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.2-rc2', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_2_rc1');
}
public function update_schema()
{
return array(
'change_columns' => array(
$this->table_prefix . 'drafts' => array(
'draft_subject' => array('STEXT_UNI', ''),
),
$this->table_prefix . 'forums' => array(
'forum_last_post_subject' => array('STEXT_UNI', ''),
),
$this->table_prefix . 'posts' => array(
'post_subject' => array('STEXT_UNI', '', 'true_sort'),
),
$this->table_prefix . 'privmsgs' => array(
'message_subject' => array('STEXT_UNI', ''),
),
$this->table_prefix . 'topics' => array(
'topic_title' => array('STEXT_UNI', '', 'true_sort'),
'topic_last_post_subject' => array('STEXT_UNI', ''),
),
),
'drop_keys' => array(
$this->table_prefix . 'sessions' => array(
'session_forum_id',
),
),
'add_index' => array(
$this->table_prefix . 'sessions' => array(
'session_fid' => array('session_forum_id'),
),
),
);
}
public function revert_schema()
{
return array(
'add_index' => array(
$this->table_prefix . 'sessions' => array(
'session_forum_id' => array(
'session_forum_id',
),
),
),
'drop_keys' => array(
$this->table_prefix . 'sessions' => array(
'session_fid',
),
),
);
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.2-rc2')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_3 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.3', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_3_rc1');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.3')),
);
}
}

View File

@@ -1,83 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_3_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.3-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_2');
}
public function update_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'styles_template' => array(
'template_inherits_id' => array('UINT:4', 0),
'template_inherit_path' => array('VCHAR', ''),
),
$this->table_prefix . 'groups' => array(
'group_max_recipients' => array('UINT', 0),
),
),
);
}
public function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'styles_template' => array(
'template_inherits_id',
'template_inherit_path',
),
$this->table_prefix . 'groups' => array(
'group_max_recipients',
),
),
);
}
public function update_data()
{
return array(
array('config.add', array('enable_queue_trigger', '0')),
array('config.add', array('queue_trigger_posts', '3')),
array('config.add', array('pm_max_recipients', '0')),
array('custom', array(array(&$this, 'set_group_default_max_recipients'))),
array('config.add', array('dbms_version', $this->db->sql_server_info(true))),
array('permission.add', array('u_masspm_group', true, 'u_masspm')),
array('custom', array(array(&$this, 'correct_acp_email_permissions'))),
array('config.update', array('version', '3.0.3-rc1')),
);
}
public function correct_acp_email_permissions()
{
$sql = 'UPDATE ' . $this->table_prefix . 'modules
SET module_auth = \'acl_a_email && cfg_email_enable\'
WHERE module_class = \'acp\'
AND module_basename = \'email\'';
$this->sql_query($sql);
}
public function set_group_default_max_recipients()
{
// Set maximum number of recipients for the registered users, bots, guests group
$sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
$this->sql_query($sql);
}
}

View File

@@ -1,49 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_4 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.4', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_4_rc1');
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'rename_log_delete_topic'))),
array('config.update', array('version', '3.0.4')),
);
}
public function rename_log_delete_topic()
{
if ($this->db->sql_layer == 'oracle')
{
// log_operation is CLOB - but we can change this later
$sql = 'UPDATE ' . $this->table_prefix . "log
SET log_operation = 'LOG_DELETE_TOPIC'
WHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
$this->sql_query($sql);
}
else
{
$sql = 'UPDATE ' . $this->table_prefix . "log
SET log_operation = 'LOG_DELETE_TOPIC'
WHERE log_operation = 'LOG_TOPIC_DELETED'";
$this->sql_query($sql);
}
}
}

View File

@@ -1,123 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_4_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.4-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_3');
}
public function update_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_show_profile' => array('BOOL', 0),
),
),
'change_columns' => array(
$this->table_prefix . 'styles' => array(
'style_id' => array('UINT', NULL, 'auto_increment'),
'template_id' => array('UINT', 0),
'theme_id' => array('UINT', 0),
'imageset_id' => array('UINT', 0),
),
$this->table_prefix . 'styles_imageset' => array(
'imageset_id' => array('UINT', NULL, 'auto_increment'),
),
$this->table_prefix . 'styles_imageset_data' => array(
'image_id' => array('UINT', NULL, 'auto_increment'),
'imageset_id' => array('UINT', 0),
),
$this->table_prefix . 'styles_theme' => array(
'theme_id' => array('UINT', NULL, 'auto_increment'),
),
$this->table_prefix . 'styles_template' => array(
'template_id' => array('UINT', NULL, 'auto_increment'),
),
$this->table_prefix . 'styles_template_data' => array(
'template_id' => array('UINT', 0),
),
$this->table_prefix . 'forums' => array(
'forum_style' => array('UINT', 0),
),
$this->table_prefix . 'users' => array(
'user_style' => array('UINT', 0),
),
),
);
}
public function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_show_profile',
),
),
);
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'update_custom_profile_fields'))),
array('config.update', array('version', '3.0.4-rc1')),
);
}
public function update_custom_profile_fields()
{
// Update the Custom Profile Fields based on previous settings to the new format
$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
FROM ' . PROFILE_FIELDS_TABLE;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql_ary = array(
'field_required' => 0,
'field_show_on_reg' => 0,
'field_hide' => 0,
'field_show_profile'=> 0,
);
if ($row['field_required'])
{
$sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
}
else if ($row['field_show_on_reg'])
{
$sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
}
else if ($row['field_hide'])
{
// Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
$sql_ary['field_hide'] = 1;
}
else
{
// equivelant to "none", which is the "Display in user control panel" option
$sql_ary['field_show_profile'] = 1;
}
$this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
}
$this->db->sql_freeresult($result);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_5 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.5', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_5_rc1part2');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.5')),
);
}
}

View File

@@ -1,124 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_5_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.5-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_4');
}
public function update_schema()
{
return array(
'change_columns' => array(
$this->table_prefix . 'forums' => array(
'forum_style' => array('UINT', 0),
),
),
);
}
public function update_data()
{
$search_indexing_state = $this->config['search_indexing_state'];
return array(
array('config.add', array('captcha_gd_wave', 0)),
array('config.add', array('captcha_gd_3d_noise', 1)),
array('config.add', array('captcha_gd_fonts', 1)),
array('config.add', array('confirm_refresh', 1)),
array('config.add', array('max_num_search_keywords', 10)),
array('config.remove', array('search_indexing_state')),
array('config.add', array('search_indexing_state', $search_indexing_state, true)),
array('custom', array(array(&$this, 'hash_old_passwords'))),
array('custom', array(array(&$this, 'update_ichiro_bot'))),
);
}
public function hash_old_passwords()
{
$sql = 'SELECT user_id, user_password
FROM ' . $this->table_prefix . 'users
WHERE user_pass_convert = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if (strlen($row['user_password']) == 32)
{
$sql_ary = array(
'user_password' => phpbb_hash($row['user_password']),
);
$this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']);
}
}
$this->db->sql_freeresult($result);
}
public function update_ichiro_bot()
{
// Adjust bot entry
$sql = 'UPDATE ' . $this->table_prefix . "bots
SET bot_agent = 'ichiro/'
WHERE bot_agent = 'ichiro/2'";
$this->sql_query($sql);
}
public function remove_duplicate_auth_options()
{
// Before we are able to add a unique key to auth_option, we need to remove duplicate entries
$sql = 'SELECT auth_option
FROM ' . $this->table_prefix . 'acl_options
GROUP BY auth_option
HAVING COUNT(*) >= 2';
$result = $this->db->sql_query($sql);
$auth_options = array();
while ($row = $this->db->sql_fetchrow($result))
{
$auth_options[] = $row['auth_option'];
}
$this->db->sql_freeresult($result);
// Remove specific auth options
if (!empty($auth_options))
{
foreach ($auth_options as $option)
{
// Select auth_option_ids... the largest id will be preserved
$sql = 'SELECT auth_option_id
FROM ' . ACL_OPTIONS_TABLE . "
WHERE auth_option = '" . $db->sql_escape($option) . "'
ORDER BY auth_option_id DESC";
// sql_query_limit not possible here, due to bug in postgresql layer
$result = $this->db->sql_query($sql);
// Skip first row, this is our original auth option we want to preserve
$row = $this->db->sql_fetchrow($result);
while ($row = $this->db->sql_fetchrow($result))
{
// Ok, remove this auth option...
$this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
$this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
$this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
$this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
}
$this->db->sql_freeresult($result);
}
}
}
}

View File

@@ -1,42 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_5_rc1part2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.5-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_5_rc1');
}
public function update_schema()
{
return array(
'drop_keys' => array(
$this->table_prefix . 'acl_options' => array('auth_option'),
),
'add_unique_index' => array(
$this->table_prefix . 'acl_options' => array(
'auth_option' => array('auth_option'),
),
),
);
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.5-rc1')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_6 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.6', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_6_rc4');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.6')),
);
}
}

View File

@@ -1,324 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_6_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.6-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_5');
}
public function update_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'confirm' => array(
'attempts' => array('UINT', 0),
),
$this->table_prefix . 'users' => array(
'user_new' => array('BOOL', 1),
'user_reminded' => array('TINT:4', 0),
'user_reminded_time' => array('TIMESTAMP', 0),
),
$this->table_prefix . 'groups' => array(
'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'),
),
$this->table_prefix . 'privmsgs' => array(
'message_reported' => array('BOOL', 0),
),
$this->table_prefix . 'reports' => array(
'pm_id' => array('UINT', 0),
),
$this->table_prefix . 'profile_fields' => array(
'field_show_on_vt' => array('BOOL', 0),
),
$this->table_prefix . 'forums' => array(
'forum_options' => array('UINT:20', 0),
),
),
'change_columns' => array(
$this->table_prefix . 'users' => array(
'user_options' => array('UINT:11', 230271),
),
),
'add_index' => array(
$this->table_prefix . 'reports' => array(
'post_id' => array('post_id'),
'pm_id' => array('pm_id'),
),
$this->table_prefix . 'posts' => array(
'post_username' => array('post_username:255'),
),
),
);
}
public function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'confirm' => array(
'attempts',
),
$this->table_prefix . 'users' => array(
'user_new',
'user_reminded',
'user_reminded_time',
),
$this->table_prefix . 'groups' => array(
'group_skip_auth',
),
$this->table_prefix . 'privmsgs' => array(
'message_reported',
),
$this->table_prefix . 'reports' => array(
'pm_id',
),
$this->table_prefix . 'profile_fields' => array(
'field_show_on_vt',
),
$this->table_prefix . 'forums' => array(
'forum_options',
),
),
'drop_keys' => array(
$this->table_prefix . 'reports' => array(
'post_id',
'pm_id',
),
$this->table_prefix . 'posts' => array(
'post_username',
),
),
);
}
public function update_data()
{
return array(
array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')),
array('if', array(
($this->config['captcha_gd']),
array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')),
)),
array('config.add', array('feed_enable', 0)),
array('config.add', array('feed_limit', 10)),
array('config.add', array('feed_overall_forums', 1)),
array('config.add', array('feed_overall_forums_limit', 15)),
array('config.add', array('feed_overall_topics', 0)),
array('config.add', array('feed_overall_topics_limit', 15)),
array('config.add', array('feed_forum', 1)),
array('config.add', array('feed_topic', 1)),
array('config.add', array('feed_item_statistics', 1)),
array('config.add', array('smilies_per_page', 50)),
array('config.add', array('allow_pm_report', 1)),
array('config.add', array('min_post_chars', 1)),
array('config.add', array('allow_quick_reply', 1)),
array('config.add', array('new_member_post_limit', 0)),
array('config.add', array('new_member_group_default', 0)),
array('config.add', array('delete_time', $this->config['edit_time'])),
array('config.add', array('allow_avatar', 0)),
array('if', array(
($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']),
array('config.update', array('allow_avatar', 1)),
)),
array('config.add', array('allow_avatar_remote_upload', 0)),
array('if', array(
($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']),
array('config.update', array('allow_avatar_remote_upload', 1)),
)),
array('module.add', array(
'acp',
'ACP_BOARD_CONFIGURATION',
array(
'module_basename' => 'acp_board',
'modes' => array('feed'),
),
)),
array('module.add', array(
'acp',
'ACP_CAT_USERS',
array(
'module_basename' => 'acp_users',
'modes' => array('warnings'),
),
)),
array('module.add', array(
'acp',
'ACP_SERVER_CONFIGURATION',
array(
'module_basename' => 'acp_send_statistics',
'modes' => array('send_statistics'),
),
)),
array('module.add', array(
'acp',
'ACP_FORUM_BASED_PERMISSIONS',
array(
'module_basename' => 'acp_permissions',
'modes' => array('setting_forum_copy'),
),
)),
array('module.add', array(
'mcp',
'MCP_REPORTS',
array(
'module_basename' => 'mcp_pm_reports',
'modes' => array('pm_reports','pm_reports_closed','pm_report_details'),
),
)),
array('custom', array(array(&$this, 'add_newly_registered_group'))),
array('custom', array(array(&$this, 'set_user_options_default'))),
array('config.update', array('version', '3.0.6-rc1')),
);
}
public function set_user_options_default()
{
// 229376 is the added value to enable all three signature options
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
$this->sql_query($sql);
}
public function add_newly_registered_group()
{
// Add newly_registered group... but check if it already exists (we always supported running the updater on any schema)
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = 'NEWLY_REGISTERED'";
$result = $this->db->sql_query($sql);
$group_id = (int) $this->db->sql_fetchfield('group_id');
$this->db->sql_freeresult($result);
if (!$group_id)
{
$sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)";
$this->sql_query($sql);
$group_id = $this->db->sql_nextid();
}
// Insert new user role... at the end of the chain
$sql = 'SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = 'ROLE_USER_NEW_MEMBER'
AND role_type = 'u_'";
$result = $this->db->sql_query($sql);
$u_role = (int) $this->db->sql_fetchfield('role_id');
$this->db->sql_freeresult($result);
if (!$u_role)
{
$sql = 'SELECT MAX(role_order) as max_order_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_type = 'u_'";
$result = $this->db->sql_query($sql);
$next_order_id = (int) $this->db->sql_fetchfield('max_order_id');
$this->db->sql_freeresult($result);
$next_order_id++;
$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)";
$this->sql_query($sql);
$u_role = $this->db->sql_nextid();
// Now add the correct data to the roles...
// The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')";
$this->sql_query($sql);
// Add user role to group
$sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)";
$this->sql_query($sql);
}
// Insert new forum role
$sql = 'SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = 'ROLE_FORUM_NEW_MEMBER'
AND role_type = 'f_'";
$result = $this->db->sql_query($sql);
$f_role = (int) $this->db->sql_fetchfield('role_id');
$this->db->sql_freeresult($result);
if (!$f_role)
{
$sql = 'SELECT MAX(role_order) as max_order_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_type = 'f_'";
$result = $this->db->sql_query($sql);
$next_order_id = (int) $this->db->sql_fetchfield('max_order_id');
$this->db->sql_freeresult($result);
$next_order_id++;
$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)";
$this->sql_query($sql);
$f_role = $this->db->sql_nextid();
$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')";
$this->sql_query($sql);
}
// Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once)
$sql = 'SELECT 1
FROM ' . USERS_TABLE . '
WHERE user_new = 0';
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row)
{
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0';
$this->sql_query($sql);
}
// To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts...
// Check if the role is already assigned...
$sql = 'SELECT forum_id
FROM ' . ACL_GROUPS_TABLE . '
WHERE group_id = ' . $group_id . '
AND auth_role_id = ' . $f_role;
$result = $this->db->sql_query($sql);
$is_options = (int) $this->db->sql_fetchfield('forum_id');
$this->db->sql_freeresult($result);
// Not assigned at all... :/
if (!$is_options)
{
// Get postable forums
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
WHERE forum_type != ' . FORUM_LINK;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)');
}
$this->db->sql_freeresult($result);
}
// Clear permissions...
include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext);
$auth_admin = new auth_admin();
$auth_admin->acl_clear_prefetch();
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_6_rc2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.6-rc2', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_6_rc1');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.6-rc2')),
);
}
}

View File

@@ -1,40 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_6_rc3 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.6-rc3', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_6_rc2');
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'update_cp_fields'))),
array('config.update', array('version', '3.0.6-rc3')),
);
}
public function update_cp_fields()
{
// Update the Custom Profile Fields based on previous settings to the new format
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
SET field_show_on_vt = 1
WHERE field_hide = 0
AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)';
$this->sql_query($sql);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_6_rc4 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.6-rc4', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_6_rc3');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.6-rc4')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_7 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.7', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_7_rc2');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.7')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_7_pl1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.7-pl1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_7');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.7-pl1')),
);
}
}

View File

@@ -1,76 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_7_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.7-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_6');
}
public function update_schema()
{
return array(
'drop_keys' => array(
$this->table_prefix . 'log' => array(
'log_time',
),
),
'add_index' => array(
$this->table_prefix . 'topics_track' => array(
'topic_id' => array('topic_id'),
),
),
);
}
public function revert_schema()
{
return array(
'add_index' => array(
$this->table_prefix . 'log' => array(
'log_time' => array('log_time'),
),
),
'drop_keys' => array(
$this->table_prefix . 'topics_track' => array(
'topic_id',
),
),
);
}
public function update_data()
{
return array(
array('config.add', array('feed_overall', 1)),
array('config.add', array('feed_http_auth', 0)),
array('config.add', array('feed_limit_post', $this->config['feed_limit'])),
array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])),
array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])),
array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])),
array('custom', array(array(&$this, 'delete_text_templates'))),
array('config.update', array('version', '3.0.7-rc1')),
);
}
public function delete_text_templates()
{
// Delete all text-templates from the template_data
$sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt');
$this->sql_query($sql);
}
}

View File

@@ -1,73 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_7_rc2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.7-rc2', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_7_rc1');
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'update_email_hash'))),
array('config.update', array('version', '3.0.7-rc2')),
);
}
public function update_email_hash($start = 0)
{
$limit = 1000;
$sql = 'SELECT user_id, user_email, user_email_hash
FROM ' . USERS_TABLE . '
WHERE user_type <> ' . USER_IGNORE . "
AND user_email <> ''";
$result = $this->db->sql_query_limit($sql, $limit, $start);
$i = 0;
while ($row = $this->db->sql_fetchrow($result))
{
$i++;
// Snapshot of the phpbb_email_hash() function
// We cannot call it directly because the auto updater updates the DB first. :/
$user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']);
if ($user_email_hash != $row['user_email_hash'])
{
$sql_ary = array(
'user_email_hash' => $user_email_hash,
);
$sql = 'UPDATE ' . USERS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . (int) $row['user_id'];
$this->sql_query($sql);
}
}
$this->db->sql_freeresult($result);
if ($i < $limit)
{
// Completed
return;
}
// Return the next start, will be sent to $start when this function is called again
return $start + $limit;
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_8 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.8', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_8_rc1');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.8')),
);
}
}

View File

@@ -1,221 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_8_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.8-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_7_pl1');
}
public function update_data()
{
return array(
array('custom', array(array(&$this, 'update_file_extension_group_names'))),
array('custom', array(array(&$this, 'update_module_auth'))),
array('custom', array(array(&$this, 'update_bots'))),
array('custom', array(array(&$this, 'delete_orphan_shadow_topics'))),
array('module.add', array(
'acp',
'ACP_MESSAGES',
array(
'module_basename' => 'acp_board',
'modes' => array('post'),
),
)),
array('config.add', array('load_unreads_search', 1)),
array('config.update_if_equals', array(600, 'queue_interval', 60)),
array('config.update_if_equals', array(50, 'email_package_size', 20)),
array('config.update', array('version', '3.0.8-rc1')),
);
}
public function update_file_extension_group_names()
{
// Update file extension group names to use language strings.
$sql = 'SELECT lang_dir
FROM ' . LANG_TABLE;
$result = $this->db->sql_query($sql);
$extension_groups_updated = array();
while ($lang_dir = $this->db->sql_fetchfield('lang_dir'))
{
$lang_dir = basename($lang_dir);
// The language strings we need are either in language/.../acp/attachments.php
// in the update package if we're updating to 3.0.8-RC1 or later,
// or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier.
// On an already updated board, they can also already be in language/.../acp/attachments.php
// in the board root.
$lang_files = array(
"{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}",
"{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}",
"{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}",
);
foreach ($lang_files as $lang_file)
{
if (!file_exists($lang_file))
{
continue;
}
$lang = array();
include($lang_file);
foreach($lang as $lang_key => $lang_val)
{
if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0)
{
continue;
}
$sql_ary = array(
'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_'
);
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "
WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'";
$this->sql_query($sql);
$extension_groups_updated[$lang_key] = true;
}
}
}
$this->db->sql_freeresult($result);
}
public function update_module_auth()
{
$sql = 'UPDATE ' . MODULES_TABLE . '
SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\'
WHERE module_class = \'ucp\'
AND module_basename = \'profile\'
AND module_mode = \'avatar\'';
$this->sql_query($sql);
}
public function update_bots()
{
$bot_name = 'Bing [Bot]';
$bot_name_clean = utf8_clean_string($bot_name);
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . "
WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'";
$result = $this->db->sql_query($sql);
$bing_already_added = (bool) $this->db->sql_fetchfield('user_id');
$this->db->sql_freeresult($result);
if (!$bing_already_added)
{
$bot_agent = 'bingbot/';
$bot_ip = '';
$sql = 'SELECT group_id, group_colour
FROM ' . GROUPS_TABLE . "
WHERE group_name = 'BOTS'";
$result = $this->db->sql_query($sql);
$group_row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$group_row)
{
// default fallback, should never get here
$group_row['group_id'] = 6;
$group_row['group_colour'] = '9E8DA7';
}
if (!function_exists('user_add'))
{
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
$user_row = array(
'user_type' => USER_IGNORE,
'group_id' => $group_row['group_id'],
'username' => $bot_name,
'user_regdate' => time(),
'user_password' => '',
'user_colour' => $group_row['group_colour'],
'user_email' => '',
'user_lang' => $this->config['default_lang'],
'user_style' => $this->config['default_style'],
'user_timezone' => 0,
'user_dateformat' => $this->config['default_dateformat'],
'user_allow_massemail' => 0,
);
$user_id = user_add($user_row);
$sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
'bot_active' => 1,
'bot_name' => (string) $bot_name,
'user_id' => (int) $user_id,
'bot_agent' => (string) $bot_agent,
'bot_ip' => (string) $bot_ip,
));
$this->sql_query($sql);
}
}
public function delete_orphan_shadow_topics()
{
// Delete shadow topics pointing to not existing topics
$batch_size = 500;
// Set of affected forums we have to resync
$sync_forum_ids = array();
$sql_array = array(
'SELECT' => 't1.topic_id, t1.forum_id',
'FROM' => array(
TOPICS_TABLE => 't1',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(TOPICS_TABLE => 't2'),
'ON' => 't1.topic_moved_id = t2.topic_id',
),
),
'WHERE' => 't1.topic_moved_id <> 0
AND t2.topic_id IS NULL',
);
$sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query_limit($sql, $batch_size);
$topic_ids = array();
while ($row = $this->db->sql_fetchrow($result))
{
$topic_ids[] = (int) $row['topic_id'];
$sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id'];
}
$this->db->sql_freeresult($result);
if (!empty($topic_ids))
{
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids);
$this->db->sql_query($sql);
// Sync the forums we have deleted shadow topics from.
sync('forum', 'forum_id', $sync_forum_ids, true, true);
return false;
}
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_9 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.9', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_9_rc4');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.9')),
);
}
}

View File

@@ -1,124 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_9_rc1 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.9-rc1', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_8');
}
public function update_schema()
{
return array(
'add_tables' => array(
$this->table_prefix . 'login_attempts' => array(
'COLUMNS' => array(
// this column was removed from the database updater
// after 3.0.9-RC3 was released. It might still exist
// in 3.0.9-RCX installations and has to be dropped as
// soon as the db_tools class is capable of properly
// removing a primary key.
// 'attempt_id' => array('UINT', NULL, 'auto_increment'),
'attempt_ip' => array('VCHAR:40', ''),
'attempt_browser' => array('VCHAR:150', ''),
'attempt_forwarded_for' => array('VCHAR:255', ''),
'attempt_time' => array('TIMESTAMP', 0),
'user_id' => array('UINT', 0),
'username' => array('VCHAR_UNI:255', 0),
'username_clean' => array('VCHAR_CI', 0),
),
//'PRIMARY_KEY' => 'attempt_id',
'KEYS' => array(
'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')),
'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')),
'att_time' => array('INDEX', array('attempt_time')),
'user_id' => array('INDEX', 'user_id'),
),
),
),
'change_columns' => array(
$this->table_prefix . 'bbcodes' => array(
'bbcode_id' => array('USINT', 0),
),
),
);
}
public function revert_schema()
{
return array(
'drop_tables' => array(
$this->table_prefix . 'login_attempts',
),
);
}
public function update_data()
{
return array(
array('config.add', array('ip_login_limit_max', 50)),
array('config.add', array('ip_login_limit_time', 21600)),
array('config.add', array('ip_login_limit_use_forwarded', 0)),
array('custom', array(array(&$this, 'update_file_extension_group_names'))),
array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))),
array('config.update', array('version', '3.0.9-rc1')),
);
}
public function update_file_extension_group_names()
{
// Update file extension group names to use language strings, again.
$sql = 'SELECT group_id, group_name
FROM ' . EXTENSION_GROUPS_TABLE . '
WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char);
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql_ary = array(
'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_'
);
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE group_id = ' . $row['group_id'];
$this->sql_query($sql);
}
$this->db->sql_freeresult($result);
}
public function fix_firebird_qa_captcha()
{
// Recover from potentially broken Q&A CAPTCHA table on firebird
// Q&A CAPTCHA was uninstallable, so it's safe to remove these
// without data loss
if ($this->db_tools->sql_layer == 'firebird')
{
$tables = array(
$this->table_prefix . 'captcha_questions',
$this->table_prefix . 'captcha_answers',
$this->table_prefix . 'qa_confirm',
);
foreach ($tables as $table)
{
if ($this->db_tools->sql_table_exists($table))
{
$this->db_tools->sql_table_drop($table);
}
}
}
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_9_rc2 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.9-rc2', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_9_rc1');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.9-rc2')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_9_rc3 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.9-rc3', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_9_rc2');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.9-rc3')),
);
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_db_migration_data_30x_3_0_9_rc4 extends phpbb_db_migration
{
public function effectively_installed()
{
return version_compare($this->config['version'], '3.0.9-rc4', '>=');
}
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_9_rc3');
}
public function update_data()
{
return array(
array('config.update', array('version', '3.0.9-rc4')),
);
}
}

View File

@@ -1,57 +0,0 @@
<?php
/**
*
* @package migration
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_db_migration_data_30x_local_url_bbcode extends phpbb_db_migration
{
static public function depends_on()
{
return array('phpbb_db_migration_data_30x_3_0_12_rc1');
}
public function update_data()
{
return array(
array('custom', array(array($this, 'update_local_url_bbcode'))),
);
}
/**
* Update BBCodes that currently use the LOCAL_URL tag
*
* To fix http://tracker.phpbb.com/browse/PHPBB3-8319 we changed
* the second_pass_replace value, so that needs updating for existing ones
*/
public function update_local_url_bbcode()
{
$sql = 'SELECT *
FROM ' . BBCODES_TABLE . '
WHERE bbcode_match ' . $this->db->sql_like_expression($this->db->any_char . 'LOCAL_URL' . $this->db->any_char);
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if (!class_exists('acp_bbcodes'))
{
global $phpEx;
phpbb_require_updated('includes/acp/acp_bbcodes.' . $phpEx);
}
$bbcode_match = $row['bbcode_match'];
$bbcode_tpl = $row['bbcode_tpl'];
$acp_bbcodes = new acp_bbcodes();
$sql_ary = $acp_bbcodes->build_regexp($bbcode_match, $bbcode_tpl);
$sql = 'UPDATE ' . BBCODES_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE bbcode_id = ' . (int) $row['bbcode_id'];
$this->sql_query($sql);
}
$this->db->sql_freeresult($result);
}
}

Some files were not shown because too many files have changed in this diff Show More