Augmentation vers version 3.3.0
This commit is contained in:
1732
install/update/old/includes/acp/acp_attachments.php
Normal file
1732
install/update/old/includes/acp/acp_attachments.php
Normal file
File diff suppressed because it is too large
Load Diff
620
install/update/old/includes/acp/acp_bbcodes.php
Normal file
620
install/update/old/includes/acp/acp_bbcodes.php
Normal file
@@ -0,0 +1,620 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_bbcodes
|
||||
{
|
||||
var $u_action;
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $db, $user, $template, $cache, $request, $phpbb_dispatcher, $phpbb_container;
|
||||
global $phpbb_log;
|
||||
|
||||
$user->add_lang('acp/posting');
|
||||
|
||||
// Set up general vars
|
||||
$action = $request->variable('action', '');
|
||||
$bbcode_id = $request->variable('bbcode', 0);
|
||||
$submit = $request->is_set_post('submit');
|
||||
|
||||
$this->tpl_name = 'acp_bbcodes';
|
||||
$this->page_title = 'ACP_BBCODES';
|
||||
$form_key = 'acp_bbcodes';
|
||||
|
||||
add_form_key($form_key);
|
||||
|
||||
if ($submit && !check_form_key($form_key))
|
||||
{
|
||||
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
// Set up mode-specific vars
|
||||
switch ($action)
|
||||
{
|
||||
case 'add':
|
||||
$bbcode_match = $bbcode_tpl = $bbcode_helpline = '';
|
||||
$display_on_posting = 0;
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$sql = 'SELECT bbcode_match, bbcode_tpl, display_on_posting, bbcode_helpline
|
||||
FROM ' . BBCODES_TABLE . '
|
||||
WHERE bbcode_id = ' . $bbcode_id;
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (!$row)
|
||||
{
|
||||
trigger_error($user->lang['BBCODE_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$bbcode_match = $row['bbcode_match'];
|
||||
$bbcode_tpl = htmlspecialchars($row['bbcode_tpl']);
|
||||
$display_on_posting = $row['display_on_posting'];
|
||||
$bbcode_helpline = $row['bbcode_helpline'];
|
||||
break;
|
||||
|
||||
case 'modify':
|
||||
$sql = 'SELECT bbcode_id, bbcode_tag
|
||||
FROM ' . BBCODES_TABLE . '
|
||||
WHERE bbcode_id = ' . $bbcode_id;
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (!$row)
|
||||
{
|
||||
trigger_error($user->lang['BBCODE_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
// No break here
|
||||
|
||||
case 'create':
|
||||
$display_on_posting = $request->variable('display_on_posting', 0);
|
||||
|
||||
$bbcode_match = $request->variable('bbcode_match', '');
|
||||
$bbcode_tpl = htmlspecialchars_decode($request->variable('bbcode_tpl', '', true));
|
||||
$bbcode_helpline = $request->variable('bbcode_helpline', '', true);
|
||||
break;
|
||||
}
|
||||
|
||||
// Do major work
|
||||
switch ($action)
|
||||
{
|
||||
case 'edit':
|
||||
case 'add':
|
||||
|
||||
$tpl_ary = array(
|
||||
'S_EDIT_BBCODE' => true,
|
||||
'U_BACK' => $this->u_action,
|
||||
'U_ACTION' => $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify') . (($bbcode_id) ? "&bbcode=$bbcode_id" : ''),
|
||||
|
||||
'L_BBCODE_USAGE_EXPLAIN'=> sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '<a href="#down">', '</a>'),
|
||||
'BBCODE_MATCH' => $bbcode_match,
|
||||
'BBCODE_TPL' => $bbcode_tpl,
|
||||
'BBCODE_HELPLINE' => $bbcode_helpline,
|
||||
'DISPLAY_ON_POSTING' => $display_on_posting,
|
||||
);
|
||||
|
||||
$bbcode_tokens = array('TEXT', 'SIMPLETEXT', 'INTTEXT', 'IDENTIFIER', 'NUMBER', 'EMAIL', 'URL', 'LOCAL_URL', 'RELATIVE_URL', 'COLOR');
|
||||
|
||||
/**
|
||||
* Modify custom bbcode template data before we display the add/edit form
|
||||
*
|
||||
* @event core.acp_bbcodes_edit_add
|
||||
* @var string action Type of the action: add|edit
|
||||
* @var array tpl_ary Array with custom bbcode add/edit data
|
||||
* @var int bbcode_id When editing: the bbcode id,
|
||||
* when creating: 0
|
||||
* @var array bbcode_tokens Array of bbcode tokens
|
||||
* @since 3.1.0-a3
|
||||
*/
|
||||
$vars = array('action', 'tpl_ary', 'bbcode_id', 'bbcode_tokens');
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_edit_add', compact($vars)));
|
||||
|
||||
$template->assign_vars($tpl_ary);
|
||||
|
||||
foreach ($bbcode_tokens as $token)
|
||||
{
|
||||
$template->assign_block_vars('token', array(
|
||||
'TOKEN' => '{' . $token . '}',
|
||||
'EXPLAIN' => ($token === 'LOCAL_URL') ? $user->lang(array('tokens', $token), generate_board_url() . '/') : $user->lang(array('tokens', $token)),
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
break;
|
||||
|
||||
case 'modify':
|
||||
case 'create':
|
||||
|
||||
$sql_ary = $hidden_fields = array();
|
||||
|
||||
/**
|
||||
* Modify custom bbcode data before the modify/create action
|
||||
*
|
||||
* @event core.acp_bbcodes_modify_create
|
||||
* @var string action Type of the action: modify|create
|
||||
* @var array sql_ary Array with new bbcode data
|
||||
* @var int bbcode_id When editing: the bbcode id,
|
||||
* when creating: 0
|
||||
* @var bool display_on_posting Display bbcode on posting form
|
||||
* @var string bbcode_match The bbcode usage string to match
|
||||
* @var string bbcode_tpl The bbcode HTML replacement string
|
||||
* @var string bbcode_helpline The bbcode help line string
|
||||
* @var array hidden_fields Array of hidden fields for use when
|
||||
* submitting form when $warn_text is true
|
||||
* @since 3.1.0-a3
|
||||
*/
|
||||
$vars = array(
|
||||
'action',
|
||||
'sql_ary',
|
||||
'bbcode_id',
|
||||
'display_on_posting',
|
||||
'bbcode_match',
|
||||
'bbcode_tpl',
|
||||
'bbcode_helpline',
|
||||
'hidden_fields',
|
||||
);
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create', compact($vars)));
|
||||
|
||||
$warn_text = preg_match('%<[^>]*\{text[\d]*\}[^>]*>%i', $bbcode_tpl);
|
||||
if (!$warn_text || confirm_box(true))
|
||||
{
|
||||
$data = $this->build_regexp($bbcode_match, $bbcode_tpl);
|
||||
|
||||
// Make sure the user didn't pick a "bad" name for the BBCode tag.
|
||||
$hard_coded = array('code', 'quote', 'quote=', 'attachment', 'attachment=', 'b', 'i', 'url', 'url=', 'img', 'size', 'size=', 'color', 'color=', 'u', 'list', 'list=', 'email', 'email=', 'flash', 'flash=');
|
||||
|
||||
if (($action == 'modify' && strtolower($data['bbcode_tag']) !== strtolower($row['bbcode_tag'])) || ($action == 'create'))
|
||||
{
|
||||
$sql = 'SELECT 1 as test
|
||||
FROM ' . BBCODES_TABLE . "
|
||||
WHERE LOWER(bbcode_tag) = '" . $db->sql_escape(strtolower($data['bbcode_tag'])) . "'";
|
||||
$result = $db->sql_query($sql);
|
||||
$info = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// Grab the end, interrogate the last closing tag
|
||||
if ($info['test'] === '1' || in_array(strtolower($data['bbcode_tag']), $hard_coded) || (preg_match('#\[/([^[]*)]$#', $bbcode_match, $regs) && in_array(strtolower($regs[1]), $hard_coded)))
|
||||
{
|
||||
trigger_error($user->lang['BBCODE_INVALID_TAG_NAME'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
if (substr($data['bbcode_tag'], -1) === '=')
|
||||
{
|
||||
$test = substr($data['bbcode_tag'], 0, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$test = $data['bbcode_tag'];
|
||||
}
|
||||
|
||||
if (!preg_match('%\\[' . $test . '[^]]*].*?\\[/' . $test . ']%s', $bbcode_match))
|
||||
{
|
||||
trigger_error($user->lang['BBCODE_OPEN_ENDED_TAG'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if (strlen($data['bbcode_tag']) > 16)
|
||||
{
|
||||
trigger_error($user->lang['BBCODE_TAG_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if (strlen($bbcode_match) > 4000)
|
||||
{
|
||||
trigger_error($user->lang['BBCODE_TAG_DEF_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if (strlen($bbcode_helpline) > 255)
|
||||
{
|
||||
trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$sql_ary = array_merge($sql_ary, array(
|
||||
'bbcode_tag' => $data['bbcode_tag'],
|
||||
'bbcode_match' => $bbcode_match,
|
||||
'bbcode_tpl' => $bbcode_tpl,
|
||||
'display_on_posting' => $display_on_posting,
|
||||
'bbcode_helpline' => $bbcode_helpline,
|
||||
'first_pass_match' => $data['first_pass_match'],
|
||||
'first_pass_replace' => $data['first_pass_replace'],
|
||||
'second_pass_match' => $data['second_pass_match'],
|
||||
'second_pass_replace' => $data['second_pass_replace']
|
||||
));
|
||||
|
||||
if ($action == 'create')
|
||||
{
|
||||
$sql = 'SELECT MAX(bbcode_id) as max_bbcode_id
|
||||
FROM ' . BBCODES_TABLE;
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$bbcode_id = (int) $row['max_bbcode_id'] + 1;
|
||||
|
||||
// Make sure it is greater than the core bbcode ids...
|
||||
if ($bbcode_id <= NUM_CORE_BBCODES)
|
||||
{
|
||||
$bbcode_id = NUM_CORE_BBCODES + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bbcode_id = NUM_CORE_BBCODES + 1;
|
||||
}
|
||||
|
||||
if ($bbcode_id > BBCODE_LIMIT)
|
||||
{
|
||||
trigger_error($user->lang['TOO_MANY_BBCODES'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$sql_ary['bbcode_id'] = (int) $bbcode_id;
|
||||
|
||||
$db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary));
|
||||
$cache->destroy('sql', BBCODES_TABLE);
|
||||
$phpbb_container->get('text_formatter.cache')->invalidate();
|
||||
|
||||
$lang = 'BBCODE_ADDED';
|
||||
$log_action = 'LOG_BBCODE_ADD';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'UPDATE ' . BBCODES_TABLE . '
|
||||
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
|
||||
WHERE bbcode_id = ' . $bbcode_id;
|
||||
$db->sql_query($sql);
|
||||
$cache->destroy('sql', BBCODES_TABLE);
|
||||
$phpbb_container->get('text_formatter.cache')->invalidate();
|
||||
|
||||
$lang = 'BBCODE_EDITED';
|
||||
$log_action = 'LOG_BBCODE_EDIT';
|
||||
}
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log_action, false, array($data['bbcode_tag']));
|
||||
|
||||
/**
|
||||
* Event after a BBCode has been added or updated
|
||||
*
|
||||
* @event core.acp_bbcodes_modify_create_after
|
||||
* @var string action Type of the action: modify|create
|
||||
* @var int bbcode_id The id of the added or updated bbcode
|
||||
* @var array sql_ary Array with bbcode data (read only)
|
||||
* @since 3.2.4-RC1
|
||||
*/
|
||||
$vars = array(
|
||||
'action',
|
||||
'bbcode_id',
|
||||
'sql_ary',
|
||||
);
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create_after', compact($vars)));
|
||||
|
||||
trigger_error($user->lang[$lang] . adm_back_link($this->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $user->lang['BBCODE_DANGER'], build_hidden_fields(array_merge($hidden_fields, array(
|
||||
'action' => $action,
|
||||
'bbcode' => $bbcode_id,
|
||||
'bbcode_match' => $bbcode_match,
|
||||
'bbcode_tpl' => htmlspecialchars($bbcode_tpl),
|
||||
'bbcode_helpline' => $bbcode_helpline,
|
||||
'display_on_posting' => $display_on_posting,
|
||||
)))
|
||||
, 'confirm_bbcode.html');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
|
||||
$sql = 'SELECT bbcode_tag
|
||||
FROM ' . BBCODES_TABLE . "
|
||||
WHERE bbcode_id = $bbcode_id";
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if ($row)
|
||||
{
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$bbcode_tag = $row['bbcode_tag'];
|
||||
|
||||
$db->sql_query('DELETE FROM ' . BBCODES_TABLE . " WHERE bbcode_id = $bbcode_id");
|
||||
$cache->destroy('sql', BBCODES_TABLE);
|
||||
$phpbb_container->get('text_formatter.cache')->invalidate();
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_BBCODE_DELETE', false, array($bbcode_tag));
|
||||
|
||||
/**
|
||||
* Event after a BBCode has been deleted
|
||||
*
|
||||
* @event core.acp_bbcodes_delete_after
|
||||
* @var string action Type of the action: delete
|
||||
* @var int bbcode_id The id of the deleted bbcode
|
||||
* @var string bbcode_tag The tag of the deleted bbcode
|
||||
* @since 3.2.4-RC1
|
||||
*/
|
||||
$vars = array(
|
||||
'action',
|
||||
'bbcode_id',
|
||||
'bbcode_tag',
|
||||
);
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_delete_after', compact($vars)));
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
$json_response = new \phpbb\json_response;
|
||||
$json_response->send(array(
|
||||
'MESSAGE_TITLE' => $user->lang['INFORMATION'],
|
||||
'MESSAGE_TEXT' => $user->lang['BBCODE_DELETED'],
|
||||
'REFRESH_DATA' => array(
|
||||
'time' => 3
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
|
||||
'bbcode' => $bbcode_id,
|
||||
'i' => $id,
|
||||
'mode' => $mode,
|
||||
'action' => $action))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$u_action = $this->u_action;
|
||||
|
||||
$template_data = array(
|
||||
'U_ACTION' => $this->u_action . '&action=add',
|
||||
);
|
||||
|
||||
$sql_ary = array(
|
||||
'SELECT' => 'b.*',
|
||||
'FROM' => array(BBCODES_TABLE => 'b'),
|
||||
'ORDER_BY' => 'b.bbcode_tag',
|
||||
);
|
||||
|
||||
/**
|
||||
* Modify custom bbcode template data before we display the form
|
||||
*
|
||||
* @event core.acp_bbcodes_display_form
|
||||
* @var string action Type of the action: modify|create
|
||||
* @var array sql_ary The SQL array to get custom bbcode data
|
||||
* @var array template_data Array with form template data
|
||||
* @var string u_action The u_action link
|
||||
* @since 3.1.0-a3
|
||||
*/
|
||||
$vars = array('action', 'sql_ary', 'template_data', 'u_action');
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_display_form', compact($vars)));
|
||||
|
||||
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
|
||||
|
||||
$template->assign_vars($template_data);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$bbcodes_array = array(
|
||||
'BBCODE_TAG' => $row['bbcode_tag'],
|
||||
'U_EDIT' => $u_action . '&action=edit&bbcode=' . $row['bbcode_id'],
|
||||
'U_DELETE' => $u_action . '&action=delete&bbcode=' . $row['bbcode_id'],
|
||||
);
|
||||
|
||||
/**
|
||||
* Modify display of custom bbcodes in the form
|
||||
*
|
||||
* @event core.acp_bbcodes_display_bbcodes
|
||||
* @var array row Array with current bbcode data
|
||||
* @var array bbcodes_array Array of bbcodes template data
|
||||
* @var string u_action The u_action link
|
||||
* @since 3.1.0-a3
|
||||
*/
|
||||
$vars = array('bbcodes_array', 'row', 'u_action');
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_display_bbcodes', compact($vars)));
|
||||
|
||||
$template->assign_block_vars('bbcodes', $bbcodes_array);
|
||||
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Build regular expression for custom bbcode
|
||||
*/
|
||||
function build_regexp(&$bbcode_match, &$bbcode_tpl)
|
||||
{
|
||||
$bbcode_match = trim($bbcode_match);
|
||||
$bbcode_tpl = trim($bbcode_tpl);
|
||||
|
||||
// Allow unicode characters for URL|LOCAL_URL|RELATIVE_URL|INTTEXT tokens
|
||||
$utf8 = preg_match('/(URL|LOCAL_URL|RELATIVE_URL|INTTEXT)/', $bbcode_match);
|
||||
|
||||
$fp_match = preg_quote($bbcode_match, '!');
|
||||
$fp_replace = preg_replace('#^\[(.*?)\]#', '[$1:$uid]', $bbcode_match);
|
||||
$fp_replace = preg_replace('#\[/(.*?)\]$#', '[/$1:$uid]', $fp_replace);
|
||||
|
||||
$sp_match = preg_quote($bbcode_match, '!');
|
||||
$sp_match = preg_replace('#^\\\\\[(.*?)\\\\\]#', '\[$1:$uid\]', $sp_match);
|
||||
$sp_match = preg_replace('#\\\\\[/(.*?)\\\\\]$#', '\[/$1:$uid\]', $sp_match);
|
||||
$sp_replace = $bbcode_tpl;
|
||||
|
||||
// @todo Make sure to change this too if something changed in message parsing
|
||||
$tokens = array(
|
||||
'URL' => array(
|
||||
'!(?:(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))!ie' => "\$this->bbcode_specialchars(('\$1') ? '\$1' : 'http://\$2')"
|
||||
),
|
||||
'LOCAL_URL' => array(
|
||||
'!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')"
|
||||
),
|
||||
'RELATIVE_URL' => array(
|
||||
'!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')"
|
||||
),
|
||||
'EMAIL' => array(
|
||||
'!(' . get_preg_expression('email') . ')!ie' => "\$this->bbcode_specialchars('$1')"
|
||||
),
|
||||
'TEXT' => array(
|
||||
'!(.*?)!es' => "str_replace(array(\"\\r\\n\", '\\\"', '\\'', '(', ')'), array(\"\\n\", '\"', ''', '(', ')'), trim('\$1'))"
|
||||
),
|
||||
'SIMPLETEXT' => array(
|
||||
'!([a-zA-Z0-9-+.,_ ]+)!' => "$1"
|
||||
),
|
||||
'INTTEXT' => array(
|
||||
'!([\p{L}\p{N}\-+,_. ]+)!u' => "$1"
|
||||
),
|
||||
'IDENTIFIER' => array(
|
||||
'!([a-zA-Z0-9-_]+)!' => "$1"
|
||||
),
|
||||
'COLOR' => array(
|
||||
'!([a-z]+|#[0-9abcdef]+)!i' => '$1'
|
||||
),
|
||||
'NUMBER' => array(
|
||||
'!([0-9]+)!' => '$1'
|
||||
)
|
||||
);
|
||||
|
||||
$sp_tokens = array(
|
||||
'URL' => '(?i)((?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))(?-i)',
|
||||
'LOCAL_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)',
|
||||
'RELATIVE_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)',
|
||||
'EMAIL' => '(' . get_preg_expression('email') . ')',
|
||||
'TEXT' => '(.*?)',
|
||||
'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)',
|
||||
'INTTEXT' => '([\p{L}\p{N}\-+,_. ]+)',
|
||||
'IDENTIFIER' => '([a-zA-Z0-9-_]+)',
|
||||
'COLOR' => '([a-zA-Z]+|#[0-9abcdefABCDEF]+)',
|
||||
'NUMBER' => '([0-9]+)',
|
||||
);
|
||||
|
||||
$pad = 0;
|
||||
$modifiers = 'i';
|
||||
$modifiers .= ($utf8) ? 'u' : '';
|
||||
|
||||
if (preg_match_all('/\{(' . implode('|', array_keys($tokens)) . ')[0-9]*\}/i', $bbcode_match, $m))
|
||||
{
|
||||
foreach ($m[0] as $n => $token)
|
||||
{
|
||||
$token_type = $m[1][$n];
|
||||
|
||||
reset($tokens[strtoupper($token_type)]);
|
||||
list($match, $replace) = each($tokens[strtoupper($token_type)]);
|
||||
|
||||
// Pad backreference numbers from tokens
|
||||
if (preg_match_all('/(?<!\\\\)\$([0-9]+)/', $replace, $repad))
|
||||
{
|
||||
$repad = $pad + count(array_unique($repad[0]));
|
||||
$replace = preg_replace_callback('/(?<!\\\\)\$([0-9]+)/', function ($match) use ($pad) {
|
||||
return '${' . ($match[1] + $pad) . '}';
|
||||
}, $replace);
|
||||
$pad = $repad;
|
||||
}
|
||||
|
||||
// Obtain pattern modifiers to use and alter the regex accordingly
|
||||
$regex = preg_replace('/!(.*)!([a-z]*)/', '$1', $match);
|
||||
$regex_modifiers = preg_replace('/!(.*)!([a-z]*)/', '$2', $match);
|
||||
|
||||
for ($i = 0, $size = strlen($regex_modifiers); $i < $size; ++$i)
|
||||
{
|
||||
if (strpos($modifiers, $regex_modifiers[$i]) === false)
|
||||
{
|
||||
$modifiers .= $regex_modifiers[$i];
|
||||
|
||||
if ($regex_modifiers[$i] == 'e')
|
||||
{
|
||||
$fp_replace = "'" . str_replace("'", "\\'", $fp_replace) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
if ($regex_modifiers[$i] == 'e')
|
||||
{
|
||||
$replace = "'.$replace.'";
|
||||
}
|
||||
}
|
||||
|
||||
$fp_match = str_replace(preg_quote($token, '!'), $regex, $fp_match);
|
||||
$fp_replace = str_replace($token, $replace, $fp_replace);
|
||||
|
||||
$sp_match = str_replace(preg_quote($token, '!'), $sp_tokens[$token_type], $sp_match);
|
||||
|
||||
// Prepend the board url to local relative links
|
||||
$replace_prepend = ($token_type === 'LOCAL_URL') ? generate_board_url() . '/' : '';
|
||||
|
||||
$sp_replace = str_replace($token, $replace_prepend . '${' . ($n + 1) . '}', $sp_replace);
|
||||
}
|
||||
|
||||
$fp_match = '!' . $fp_match . '!' . $modifiers;
|
||||
$sp_match = '!' . $sp_match . '!s' . (($utf8) ? 'u' : '');
|
||||
|
||||
if (strpos($fp_match, 'e') !== false)
|
||||
{
|
||||
$fp_replace = str_replace("'.'", '', $fp_replace);
|
||||
$fp_replace = str_replace(".''.", '.', $fp_replace);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No replacement is present, no need for a second-pass pattern replacement
|
||||
// A simple str_replace will suffice
|
||||
$fp_match = '!' . $fp_match . '!' . $modifiers;
|
||||
$sp_match = $fp_replace;
|
||||
$sp_replace = '';
|
||||
}
|
||||
|
||||
// Lowercase tags
|
||||
$bbcode_tag = preg_replace('/.*?\[([a-z0-9_-]+).*/i', '$1', $bbcode_match);
|
||||
$bbcode_search = preg_replace('/.*?\[([a-z0-9_-]+).*/i', '$1', $bbcode_match);
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $bbcode_tag))
|
||||
{
|
||||
global $user;
|
||||
trigger_error($user->lang['BBCODE_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$fp_match = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
|
||||
return strtolower($match[0]);
|
||||
}, $fp_match);
|
||||
$fp_replace = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
|
||||
return strtolower($match[0]);
|
||||
}, $fp_replace);
|
||||
$sp_match = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
|
||||
return strtolower($match[0]);
|
||||
}, $sp_match);
|
||||
$sp_replace = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
|
||||
return strtolower($match[0]);
|
||||
}, $sp_replace);
|
||||
|
||||
return array(
|
||||
'bbcode_tag' => $bbcode_tag,
|
||||
'first_pass_match' => $fp_match,
|
||||
'first_pass_replace' => $fp_replace,
|
||||
'second_pass_match' => $sp_match,
|
||||
'second_pass_replace' => $sp_replace
|
||||
);
|
||||
}
|
||||
}
|
||||
1178
install/update/old/includes/acp/acp_board.php
Normal file
1178
install/update/old/includes/acp/acp_board.php
Normal file
File diff suppressed because it is too large
Load Diff
622
install/update/old/includes/acp/acp_database.php
Normal file
622
install/update/old/includes/acp/acp_database.php
Normal file
@@ -0,0 +1,622 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_database
|
||||
{
|
||||
var $db_tools;
|
||||
var $u_action;
|
||||
public $page_title;
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $cache, $db, $user, $template, $table_prefix, $request;
|
||||
global $phpbb_root_path, $phpbb_container, $phpbb_log;
|
||||
|
||||
$this->db_tools = $phpbb_container->get('dbal.tools');
|
||||
|
||||
$user->add_lang('acp/database');
|
||||
|
||||
$this->tpl_name = 'acp_database';
|
||||
$this->page_title = 'ACP_DATABASE';
|
||||
|
||||
$action = $request->variable('action', '');
|
||||
|
||||
$form_key = 'acp_database';
|
||||
add_form_key($form_key);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'MODE' => $mode
|
||||
));
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 'backup':
|
||||
|
||||
$this->page_title = 'ACP_BACKUP';
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case 'download':
|
||||
$type = $request->variable('type', '');
|
||||
$table = array_intersect($this->db_tools->sql_list_tables(), $request->variable('table', array('')));
|
||||
$format = $request->variable('method', '');
|
||||
$where = $request->variable('where', '');
|
||||
|
||||
if (!count($table))
|
||||
{
|
||||
trigger_error($user->lang['TABLE_SELECT_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if (!check_form_key($form_key))
|
||||
{
|
||||
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$store = $structure = $schema_data = false;
|
||||
|
||||
if ($where == 'store')
|
||||
{
|
||||
$store = true;
|
||||
}
|
||||
|
||||
if ($type == 'full' || $type == 'structure')
|
||||
{
|
||||
$structure = true;
|
||||
}
|
||||
|
||||
if ($type == 'full' || $type == 'data')
|
||||
{
|
||||
$schema_data = true;
|
||||
}
|
||||
|
||||
@set_time_limit(1200);
|
||||
@set_time_limit(0);
|
||||
|
||||
$time = time();
|
||||
|
||||
$filename = 'backup_' . $time . '_' . unique_id();
|
||||
|
||||
/** @var phpbb\db\extractor\extractor_interface $extractor Database extractor */
|
||||
$extractor = $phpbb_container->get('dbal.extractor');
|
||||
$extractor->init_extractor($format, $filename, $time, false, $store);
|
||||
|
||||
$extractor->write_start($table_prefix);
|
||||
|
||||
foreach ($table as $table_name)
|
||||
{
|
||||
// Get the table structure
|
||||
if ($structure)
|
||||
{
|
||||
$extractor->write_table($table_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We might wanna empty out all that junk :D
|
||||
switch ($db->get_sql_layer())
|
||||
{
|
||||
case 'sqlite3':
|
||||
$extractor->flush('DELETE FROM ' . $table_name . ";\n");
|
||||
break;
|
||||
|
||||
case 'mssql_odbc':
|
||||
case 'mssqlnative':
|
||||
$extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n");
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
$extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
$extractor->flush('TRUNCATE TABLE ' . $table_name . ";\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Data
|
||||
if ($schema_data)
|
||||
{
|
||||
$extractor->write_data($table_name);
|
||||
}
|
||||
}
|
||||
|
||||
$extractor->write_end();
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_BACKUP');
|
||||
|
||||
trigger_error($user->lang['BACKUP_SUCCESS'] . adm_back_link($this->u_action));
|
||||
break;
|
||||
|
||||
default:
|
||||
$tables = $this->db_tools->sql_list_tables();
|
||||
asort($tables);
|
||||
foreach ($tables as $table_name)
|
||||
{
|
||||
if (strlen($table_prefix) === 0 || stripos($table_name, $table_prefix) === 0)
|
||||
{
|
||||
$template->assign_block_vars('tables', array(
|
||||
'TABLE' => $table_name
|
||||
));
|
||||
}
|
||||
}
|
||||
unset($tables);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_ACTION' => $this->u_action . '&action=download'
|
||||
));
|
||||
|
||||
$available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2');
|
||||
|
||||
foreach ($available_methods as $type => $module)
|
||||
{
|
||||
if (!@extension_loaded($module))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$template->assign_block_vars('methods', array(
|
||||
'TYPE' => $type
|
||||
));
|
||||
}
|
||||
|
||||
$template->assign_block_vars('methods', array(
|
||||
'TYPE' => 'text'
|
||||
));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'restore':
|
||||
|
||||
$this->page_title = 'ACP_RESTORE';
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case 'submit':
|
||||
$delete = $request->variable('delete', '');
|
||||
$file = $request->variable('file', '');
|
||||
|
||||
$backup_info = $this->get_backup_file($phpbb_root_path . 'store/', $file);
|
||||
|
||||
if (empty($backup_info) || !is_readable($backup_info['file_name']))
|
||||
{
|
||||
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if ($delete)
|
||||
{
|
||||
if (confirm_box(true))
|
||||
{
|
||||
unlink($backup_info['file_name']);
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_DELETE');
|
||||
trigger_error($user->lang['BACKUP_DELETE'] . adm_back_link($this->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $user->lang['DELETE_SELECTED_BACKUP'], build_hidden_fields(array('delete' => $delete, 'file' => $file)));
|
||||
}
|
||||
}
|
||||
else if (confirm_box(true))
|
||||
{
|
||||
switch ($backup_info['extensions'])
|
||||
{
|
||||
case 'sql':
|
||||
$fp = fopen($backup_info['file_name'], 'rb');
|
||||
$read = 'fread';
|
||||
$seek = 'fseek';
|
||||
$eof = 'feof';
|
||||
$close = 'fclose';
|
||||
$fgetd = 'fgetd';
|
||||
break;
|
||||
|
||||
case 'sql.bz2':
|
||||
$fp = bzopen($backup_info['file_name'], 'r');
|
||||
$read = 'bzread';
|
||||
$seek = '';
|
||||
$eof = 'feof';
|
||||
$close = 'bzclose';
|
||||
$fgetd = 'fgetd_seekless';
|
||||
break;
|
||||
|
||||
case 'sql.gz':
|
||||
$fp = gzopen($backup_info['file_name'], 'rb');
|
||||
$read = 'gzread';
|
||||
$seek = 'gzseek';
|
||||
$eof = 'gzeof';
|
||||
$close = 'gzclose';
|
||||
$fgetd = 'fgetd';
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($db->get_sql_layer())
|
||||
{
|
||||
case 'mysql':
|
||||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'sqlite3':
|
||||
while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false)
|
||||
{
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'postgres':
|
||||
$delim = ";\n";
|
||||
while (($sql = $fgetd($fp, $delim, $read, $seek, $eof)) !== false)
|
||||
{
|
||||
$query = trim($sql);
|
||||
|
||||
if (substr($query, 0, 13) == 'CREATE DOMAIN')
|
||||
{
|
||||
list(, , $domain) = explode(' ', $query);
|
||||
$sql = "SELECT domain_name
|
||||
FROM information_schema.domains
|
||||
WHERE domain_name = '$domain';";
|
||||
$result = $db->sql_query($sql);
|
||||
if (!$db->sql_fetchrow($result))
|
||||
{
|
||||
$db->sql_query($query);
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->sql_query($query);
|
||||
}
|
||||
|
||||
if (substr($query, 0, 4) == 'COPY')
|
||||
{
|
||||
while (($sub = $fgetd($fp, "\n", $read, $seek, $eof)) !== '\.')
|
||||
{
|
||||
if ($sub === false)
|
||||
{
|
||||
trigger_error($user->lang['RESTORE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
pg_put_line($db->get_db_connect_id(), $sub . "\n");
|
||||
}
|
||||
pg_put_line($db->get_db_connect_id(), "\\.\n");
|
||||
pg_end_copy($db->get_db_connect_id());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
while (($sql = $fgetd($fp, "/\n", $read, $seek, $eof)) !== false)
|
||||
{
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mssql_odbc':
|
||||
case 'mssqlnative':
|
||||
while (($sql = $fgetd($fp, "GO\n", $read, $seek, $eof)) !== false)
|
||||
{
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$close($fp);
|
||||
|
||||
// Purge the cache due to updated data
|
||||
$cache->purge();
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_RESTORE');
|
||||
trigger_error($user->lang['RESTORE_SUCCESS'] . adm_back_link($this->u_action));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $user->lang['RESTORE_SELECTED_BACKUP'], build_hidden_fields(array('file' => $file)));
|
||||
}
|
||||
|
||||
default:
|
||||
$backup_files = $this->get_file_list($phpbb_root_path . 'store/');
|
||||
|
||||
if (!empty($backup_files))
|
||||
{
|
||||
krsort($backup_files);
|
||||
|
||||
foreach ($backup_files as $name => $file)
|
||||
{
|
||||
$template->assign_block_vars('files', array(
|
||||
'FILE' => sha1($file),
|
||||
'NAME' => $user->format_date($name, 'd-m-Y H:i', true),
|
||||
'SUPPORTED' => true,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_ACTION' => $this->u_action . '&action=submit'
|
||||
));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup file from file hash
|
||||
*
|
||||
* @param string $directory Relative path to directory
|
||||
* @param string $file_hash Hash of selected file
|
||||
*
|
||||
* @return array Backup file data or empty array if unable to find file
|
||||
*/
|
||||
protected function get_backup_file($directory, $file_hash)
|
||||
{
|
||||
$backup_data = [];
|
||||
|
||||
$file_list = $this->get_file_list($directory);
|
||||
$supported_extensions = $this->get_supported_extensions();
|
||||
|
||||
foreach ($file_list as $file)
|
||||
{
|
||||
preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches);
|
||||
if (sha1($file) === $file_hash && in_array($matches[2], $supported_extensions))
|
||||
{
|
||||
$backup_data = [
|
||||
'file_name' => $directory . $file,
|
||||
'extension' => $matches[2],
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $backup_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup file list for directory
|
||||
*
|
||||
* @param string $directory Relative path to backup directory
|
||||
*
|
||||
* @return array List of backup files in specified directory
|
||||
*/
|
||||
protected function get_file_list($directory)
|
||||
{
|
||||
$supported_extensions = $this->get_supported_extensions();
|
||||
|
||||
$dh = @opendir($directory);
|
||||
|
||||
$backup_files = [];
|
||||
|
||||
if ($dh)
|
||||
{
|
||||
while (($file = readdir($dh)) !== false)
|
||||
{
|
||||
if (preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
|
||||
{
|
||||
if (in_array($matches[2], $supported_extensions))
|
||||
{
|
||||
$backup_files[(int) $matches[1]] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
|
||||
return $backup_files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported extensions for backup
|
||||
*
|
||||
* @return array List of supported extensions
|
||||
*/
|
||||
protected function get_supported_extensions()
|
||||
{
|
||||
$extensions = ['sql'];
|
||||
$available_methods = ['sql.gz' => 'zlib', 'sql.bz2' => 'bz2'];
|
||||
|
||||
foreach ($available_methods as $type => $module)
|
||||
{
|
||||
if (!@extension_loaded($module))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$extensions[] = $type;
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
}
|
||||
|
||||
// get how much space we allow for a chunk of data, very similar to phpMyAdmin's way of doing things ;-) (hey, we only do this for MySQL anyway :P)
|
||||
function get_usable_memory()
|
||||
{
|
||||
$val = trim(@ini_get('memory_limit'));
|
||||
|
||||
if (preg_match('/(\\d+)([mkg]?)/i', $val, $regs))
|
||||
{
|
||||
$memory_limit = (int) $regs[1];
|
||||
switch ($regs[2])
|
||||
{
|
||||
|
||||
case 'k':
|
||||
case 'K':
|
||||
$memory_limit *= 1024;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
case 'M':
|
||||
$memory_limit *= 1048576;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
case 'G':
|
||||
$memory_limit *= 1073741824;
|
||||
break;
|
||||
}
|
||||
|
||||
// how much memory PHP requires at the start of export (it is really a little less)
|
||||
if ($memory_limit > 6100000)
|
||||
{
|
||||
$memory_limit -= 6100000;
|
||||
}
|
||||
|
||||
// allow us to consume half of the total memory available
|
||||
$memory_limit /= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the buffer to 1M if we have no clue how much memory PHP will give us :P
|
||||
$memory_limit = 1048576;
|
||||
}
|
||||
|
||||
return $memory_limit;
|
||||
}
|
||||
|
||||
function sanitize_data_mssql($text)
|
||||
{
|
||||
$data = preg_split('/[\n\t\r\b\f]/', $text);
|
||||
preg_match_all('/[\n\t\r\b\f]/', $text, $matches);
|
||||
|
||||
$val = array();
|
||||
|
||||
foreach ($data as $value)
|
||||
{
|
||||
if (strlen($value))
|
||||
{
|
||||
$val[] = "'" . $value . "'";
|
||||
}
|
||||
if (count($matches[0]))
|
||||
{
|
||||
$val[] = 'char(' . ord(array_shift($matches[0])) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return implode('+', $val);
|
||||
}
|
||||
|
||||
function sanitize_data_oracle($text)
|
||||
{
|
||||
// $data = preg_split('/[\0\n\t\r\b\f\'"\/\\\]/', $text);
|
||||
// preg_match_all('/[\0\n\t\r\b\f\'"\/\\\]/', $text, $matches);
|
||||
$data = preg_split('/[\0\b\f\'\/]/', $text);
|
||||
preg_match_all('/[\0\r\b\f\'\/]/', $text, $matches);
|
||||
|
||||
$val = array();
|
||||
|
||||
foreach ($data as $value)
|
||||
{
|
||||
if (strlen($value))
|
||||
{
|
||||
$val[] = "'" . $value . "'";
|
||||
}
|
||||
if (count($matches[0]))
|
||||
{
|
||||
$val[] = 'chr(' . ord(array_shift($matches[0])) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return implode('||', $val);
|
||||
}
|
||||
|
||||
function sanitize_data_generic($text)
|
||||
{
|
||||
$data = preg_split('/[\n\t\r\b\f]/', $text);
|
||||
preg_match_all('/[\n\t\r\b\f]/', $text, $matches);
|
||||
|
||||
$val = array();
|
||||
|
||||
foreach ($data as $value)
|
||||
{
|
||||
if (strlen($value))
|
||||
{
|
||||
$val[] = "'" . $value . "'";
|
||||
}
|
||||
if (count($matches[0]))
|
||||
{
|
||||
$val[] = "'" . array_shift($matches[0]) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
return implode('||', $val);
|
||||
}
|
||||
|
||||
// modified from PHP.net
|
||||
function fgetd(&$fp, $delim, $read, $seek, $eof, $buffer = 8192)
|
||||
{
|
||||
$record = '';
|
||||
$delim_len = strlen($delim);
|
||||
|
||||
while (!$eof($fp))
|
||||
{
|
||||
$pos = strpos($record, $delim);
|
||||
if ($pos === false)
|
||||
{
|
||||
$record .= $read($fp, $buffer);
|
||||
if ($eof($fp) && ($pos = strpos($record, $delim)) !== false)
|
||||
{
|
||||
$seek($fp, $pos + $delim_len - strlen($record), SEEK_CUR);
|
||||
return substr($record, 0, $pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$seek($fp, $pos + $delim_len - strlen($record), SEEK_CUR);
|
||||
return substr($record, 0, $pos);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function fgetd_seekless(&$fp, $delim, $read, $seek, $eof, $buffer = 8192)
|
||||
{
|
||||
static $array = array();
|
||||
static $record = '';
|
||||
|
||||
if (!count($array))
|
||||
{
|
||||
while (!$eof($fp))
|
||||
{
|
||||
if (strpos($record, $delim) !== false)
|
||||
{
|
||||
$array = explode($delim, $record);
|
||||
$record = array_pop($array);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
$record .= $read($fp, $buffer);
|
||||
}
|
||||
}
|
||||
if ($eof($fp) && strpos($record, $delim) !== false)
|
||||
{
|
||||
$array = explode($delim, $record);
|
||||
$record = array_pop($array);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($array))
|
||||
{
|
||||
return array_shift($array);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
665
install/update/old/includes/acp/acp_extensions.php
Normal file
665
install/update/old/includes/acp/acp_extensions.php
Normal file
@@ -0,0 +1,665 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
use phpbb\exception\exception_interface;
|
||||
use phpbb\exception\version_check_exception;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_extensions
|
||||
{
|
||||
var $u_action;
|
||||
var $tpl_name;
|
||||
var $page_title;
|
||||
|
||||
private $config;
|
||||
private $template;
|
||||
private $user;
|
||||
private $log;
|
||||
private $request;
|
||||
private $phpbb_dispatcher;
|
||||
private $ext_manager;
|
||||
private $phpbb_container;
|
||||
private $php_ini;
|
||||
|
||||
function main()
|
||||
{
|
||||
// Start the page
|
||||
global $config, $user, $template, $request, $phpbb_extension_manager, $phpbb_root_path, $phpbb_log, $phpbb_dispatcher, $phpbb_container;
|
||||
|
||||
$this->config = $config;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->request = $request;
|
||||
$this->log = $phpbb_log;
|
||||
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||
$this->ext_manager = $phpbb_extension_manager;
|
||||
$this->phpbb_container = $phpbb_container;
|
||||
$this->php_ini = $this->phpbb_container->get('php_ini');
|
||||
|
||||
$this->user->add_lang(array('install', 'acp/extensions', 'migrator'));
|
||||
|
||||
$this->page_title = 'ACP_EXTENSIONS';
|
||||
|
||||
$action = $this->request->variable('action', 'list');
|
||||
$ext_name = $this->request->variable('ext_name', '');
|
||||
|
||||
// What is a safe limit of execution time? Half the max execution time should be safe.
|
||||
$safe_time_limit = ($this->php_ini->getNumeric('max_execution_time') / 2);
|
||||
$start_time = time();
|
||||
|
||||
// Cancel action
|
||||
if ($this->request->is_set_post('cancel'))
|
||||
{
|
||||
$action = 'list';
|
||||
$ext_name = '';
|
||||
}
|
||||
|
||||
if (in_array($action, array('enable', 'disable', 'delete_data')) && !check_link_hash($this->request->variable('hash', ''), $action . '.' . $ext_name))
|
||||
{
|
||||
trigger_error('FORM_INVALID', E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to run a specific action on extension
|
||||
*
|
||||
* @event core.acp_extensions_run_action_before
|
||||
* @var string action Action to run; if the event completes execution of the action, should be set to 'none'
|
||||
* @var string u_action Url we are at
|
||||
* @var string ext_name Extension name from request
|
||||
* @var int safe_time_limit Safe limit of execution time
|
||||
* @var int start_time Start time
|
||||
* @var string tpl_name Template file to load
|
||||
* @since 3.1.11-RC1
|
||||
* @changed 3.2.1-RC1 Renamed to core.acp_extensions_run_action_before, added tpl_name, added action 'none'
|
||||
*/
|
||||
$u_action = $this->u_action;
|
||||
$tpl_name = '';
|
||||
$vars = array('action', 'u_action', 'ext_name', 'safe_time_limit', 'start_time', 'tpl_name');
|
||||
extract($this->phpbb_dispatcher->trigger_event('core.acp_extensions_run_action_before', compact($vars)));
|
||||
|
||||
// In case they have been updated by the event
|
||||
$this->u_action = $u_action;
|
||||
$this->tpl_name = $tpl_name;
|
||||
|
||||
// If they've specified an extension, let's load the metadata manager and validate it.
|
||||
if ($ext_name)
|
||||
{
|
||||
$md_manager = $this->ext_manager->create_extension_metadata_manager($ext_name);
|
||||
|
||||
try
|
||||
{
|
||||
$md_manager->get_metadata('all');
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
// What are we doing?
|
||||
switch ($action)
|
||||
{
|
||||
case 'none':
|
||||
// Intentionally empty, used by extensions that execute additional actions in the prior event
|
||||
break;
|
||||
|
||||
case 'set_config_version_check_force_unstable':
|
||||
$force_unstable = $this->request->variable('force_unstable', false);
|
||||
|
||||
if ($force_unstable)
|
||||
{
|
||||
$s_hidden_fields = build_hidden_fields(array(
|
||||
'force_unstable' => $force_unstable,
|
||||
));
|
||||
|
||||
confirm_box(false, $this->user->lang('EXTENSION_FORCE_UNSTABLE_CONFIRM'), $s_hidden_fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config->set('extension_force_unstable', false);
|
||||
trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
default:
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$this->config->set('extension_force_unstable', true);
|
||||
trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
|
||||
}
|
||||
|
||||
$this->list_enabled_exts();
|
||||
$this->list_disabled_exts();
|
||||
$this->list_available_exts();
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'U_VERSIONCHECK_FORCE' => $this->u_action . '&action=list&versioncheck_force=1',
|
||||
'FORCE_UNSTABLE' => $this->config['extension_force_unstable'],
|
||||
'U_ACTION' => $this->u_action,
|
||||
));
|
||||
|
||||
$this->tpl_name = 'acp_ext_list';
|
||||
break;
|
||||
|
||||
case 'enable_pre':
|
||||
try
|
||||
{
|
||||
$md_manager->validate_enable();
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$extension = $this->ext_manager->get_extension($ext_name);
|
||||
if (!$extension->is_enableable())
|
||||
{
|
||||
trigger_error($this->user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if ($this->ext_manager->is_enabled($ext_name))
|
||||
{
|
||||
redirect($this->u_action);
|
||||
}
|
||||
|
||||
$this->tpl_name = 'acp_ext_enable';
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'PRE' => true,
|
||||
'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_ENABLE_CONFIRM', $md_manager->get_metadata('display-name')),
|
||||
'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name),
|
||||
));
|
||||
break;
|
||||
|
||||
case 'enable':
|
||||
try
|
||||
{
|
||||
$md_manager->validate_enable();
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$extension = $this->ext_manager->get_extension($ext_name);
|
||||
if (!$extension->is_enableable())
|
||||
{
|
||||
trigger_error($this->user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
while ($this->ext_manager->enable_step($ext_name))
|
||||
{
|
||||
// Are we approaching the time limit? If so we want to pause the update and continue after refreshing
|
||||
if ((time() - $start_time) >= $safe_time_limit)
|
||||
{
|
||||
$this->template->assign_var('S_NEXT_STEP', true);
|
||||
|
||||
meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name));
|
||||
}
|
||||
}
|
||||
|
||||
// Update custom style for admin area
|
||||
$this->template->set_custom_style(array(
|
||||
array(
|
||||
'name' => 'adm',
|
||||
'ext_path' => 'adm/style/',
|
||||
),
|
||||
), array($phpbb_root_path . 'adm/style'));
|
||||
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name));
|
||||
}
|
||||
catch (\phpbb\db\migration\exception $e)
|
||||
{
|
||||
$this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
|
||||
}
|
||||
|
||||
$this->tpl_name = 'acp_ext_enable';
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'U_RETURN' => $this->u_action . '&action=list',
|
||||
));
|
||||
break;
|
||||
|
||||
case 'disable_pre':
|
||||
if (!$this->ext_manager->is_enabled($ext_name))
|
||||
{
|
||||
redirect($this->u_action);
|
||||
}
|
||||
|
||||
$this->tpl_name = 'acp_ext_disable';
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'PRE' => true,
|
||||
'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DISABLE_CONFIRM', $md_manager->get_metadata('display-name')),
|
||||
'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name),
|
||||
));
|
||||
break;
|
||||
|
||||
case 'disable':
|
||||
if (!$this->ext_manager->is_enabled($ext_name))
|
||||
{
|
||||
redirect($this->u_action);
|
||||
}
|
||||
|
||||
while ($this->ext_manager->disable_step($ext_name))
|
||||
{
|
||||
// Are we approaching the time limit? If so we want to pause the update and continue after refreshing
|
||||
if ((time() - $start_time) >= $safe_time_limit)
|
||||
{
|
||||
$this->template->assign_var('S_NEXT_STEP', true);
|
||||
|
||||
meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name));
|
||||
}
|
||||
}
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name));
|
||||
|
||||
$this->tpl_name = 'acp_ext_disable';
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'U_RETURN' => $this->u_action . '&action=list',
|
||||
));
|
||||
break;
|
||||
|
||||
case 'delete_data_pre':
|
||||
if ($this->ext_manager->is_enabled($ext_name))
|
||||
{
|
||||
redirect($this->u_action);
|
||||
}
|
||||
$this->tpl_name = 'acp_ext_delete_data';
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'PRE' => true,
|
||||
'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DELETE_DATA_CONFIRM', $md_manager->get_metadata('display-name')),
|
||||
'U_PURGE' => $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name),
|
||||
));
|
||||
break;
|
||||
|
||||
case 'delete_data':
|
||||
if ($this->ext_manager->is_enabled($ext_name))
|
||||
{
|
||||
redirect($this->u_action);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
while ($this->ext_manager->purge_step($ext_name))
|
||||
{
|
||||
// Are we approaching the time limit? If so we want to pause the update and continue after refreshing
|
||||
if ((time() - $start_time) >= $safe_time_limit)
|
||||
{
|
||||
$this->template->assign_var('S_NEXT_STEP', true);
|
||||
|
||||
meta_refresh(0, $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name));
|
||||
}
|
||||
}
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_PURGE', time(), array($ext_name));
|
||||
}
|
||||
catch (\phpbb\db\migration\exception $e)
|
||||
{
|
||||
$this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
|
||||
}
|
||||
|
||||
$this->tpl_name = 'acp_ext_delete_data';
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'U_RETURN' => $this->u_action . '&action=list',
|
||||
));
|
||||
break;
|
||||
|
||||
case 'details':
|
||||
// Output it to the template
|
||||
$meta = $md_manager->get_metadata('all');
|
||||
$this->output_metadata_to_template($meta);
|
||||
|
||||
if (isset($meta['extra']['version-check']))
|
||||
{
|
||||
try
|
||||
{
|
||||
$updates_available = $this->ext_manager->version_check($md_manager, $this->request->variable('versioncheck_force', false), false, $this->config['extension_force_unstable'] ? 'unstable' : null);
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'S_UP_TO_DATE' => empty($updates_available),
|
||||
'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')),
|
||||
));
|
||||
|
||||
$this->template->assign_block_vars('updates_available', $updates_available);
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'S_VERSIONCHECK_FAIL' => true,
|
||||
'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '',
|
||||
));
|
||||
}
|
||||
$this->template->assign_var('S_VERSIONCHECK', true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->template->assign_var('S_VERSIONCHECK', false);
|
||||
}
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'U_BACK' => $this->u_action . '&action=list',
|
||||
'U_VERSIONCHECK_FORCE' => $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')),
|
||||
));
|
||||
|
||||
$this->tpl_name = 'acp_ext_details';
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to run after a specific action on extension has completed
|
||||
*
|
||||
* @event core.acp_extensions_run_action_after
|
||||
* @var string action Action that has run
|
||||
* @var string u_action Url we are at
|
||||
* @var string ext_name Extension name from request
|
||||
* @var int safe_time_limit Safe limit of execution time
|
||||
* @var int start_time Start time
|
||||
* @var string tpl_name Template file to load
|
||||
* @since 3.1.11-RC1
|
||||
*/
|
||||
$u_action = $this->u_action;
|
||||
$tpl_name = $this->tpl_name;
|
||||
$vars = array('action', 'u_action', 'ext_name', 'safe_time_limit', 'start_time', 'tpl_name');
|
||||
extract($this->phpbb_dispatcher->trigger_event('core.acp_extensions_run_action_after', compact($vars)));
|
||||
|
||||
// In case they have been updated by the event
|
||||
$this->u_action = $u_action;
|
||||
$this->tpl_name = $tpl_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the enabled extensions and dumps to the template
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function list_enabled_exts()
|
||||
{
|
||||
$enabled_extension_meta_data = array();
|
||||
|
||||
foreach ($this->ext_manager->all_enabled() as $name => $location)
|
||||
{
|
||||
$md_manager = $this->ext_manager->create_extension_metadata_manager($name);
|
||||
|
||||
try
|
||||
{
|
||||
$meta = $md_manager->get_metadata('all');
|
||||
$enabled_extension_meta_data[$name] = array(
|
||||
'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
|
||||
'META_VERSION' => $meta['version'],
|
||||
);
|
||||
|
||||
if (isset($meta['extra']['version-check']))
|
||||
{
|
||||
try
|
||||
{
|
||||
$force_update = $this->request->variable('versioncheck_force', false);
|
||||
$updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
|
||||
|
||||
$enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
|
||||
$enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
|
||||
$enabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name'));
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
// Ignore exceptions due to the version check
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
|
||||
}
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
$this->template->assign_block_vars('disabled', array(
|
||||
'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
|
||||
'S_VERSIONCHECK' => false,
|
||||
));
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
$enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
uasort($enabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
|
||||
|
||||
foreach ($enabled_extension_meta_data as $name => $block_vars)
|
||||
{
|
||||
$block_vars['NAME'] = $name;
|
||||
$block_vars['U_DETAILS'] = $this->u_action . '&action=details&ext_name=' . urlencode($name);
|
||||
|
||||
$this->template->assign_block_vars('enabled', $block_vars);
|
||||
|
||||
$this->output_actions('enabled', array(
|
||||
'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . urlencode($name),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the disabled extensions and dumps to the template
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function list_disabled_exts()
|
||||
{
|
||||
$disabled_extension_meta_data = array();
|
||||
|
||||
foreach ($this->ext_manager->all_disabled() as $name => $location)
|
||||
{
|
||||
$md_manager = $this->ext_manager->create_extension_metadata_manager($name);
|
||||
|
||||
try
|
||||
{
|
||||
$meta = $md_manager->get_metadata('all');
|
||||
$disabled_extension_meta_data[$name] = array(
|
||||
'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
|
||||
'META_VERSION' => $meta['version'],
|
||||
);
|
||||
|
||||
if (isset($meta['extra']['version-check']))
|
||||
{
|
||||
$force_update = $this->request->variable('versioncheck_force', false);
|
||||
$updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
|
||||
|
||||
$disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
|
||||
$disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
|
||||
$disabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
|
||||
}
|
||||
}
|
||||
catch (version_check_exception $e)
|
||||
{
|
||||
$disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
$this->template->assign_block_vars('disabled', array(
|
||||
'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
|
||||
'S_VERSIONCHECK' => false,
|
||||
));
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
$disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
uasort($disabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
|
||||
|
||||
foreach ($disabled_extension_meta_data as $name => $block_vars)
|
||||
{
|
||||
$block_vars['NAME'] = $name;
|
||||
$block_vars['U_DETAILS'] = $this->u_action . '&action=details&ext_name=' . urlencode($name);
|
||||
|
||||
$this->template->assign_block_vars('disabled', $block_vars);
|
||||
|
||||
$this->output_actions('disabled', array(
|
||||
'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name),
|
||||
'DELETE_DATA' => $this->u_action . '&action=delete_data_pre&ext_name=' . urlencode($name),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the available extensions and dumps to the template
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function list_available_exts()
|
||||
{
|
||||
$uninstalled = array_diff_key($this->ext_manager->all_available(), $this->ext_manager->all_configured());
|
||||
|
||||
$available_extension_meta_data = array();
|
||||
|
||||
foreach ($uninstalled as $name => $location)
|
||||
{
|
||||
$md_manager = $this->ext_manager->create_extension_metadata_manager($name);
|
||||
|
||||
try
|
||||
{
|
||||
$meta = $md_manager->get_metadata('all');
|
||||
$available_extension_meta_data[$name] = array(
|
||||
'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
|
||||
'META_VERSION' => $meta['version'],
|
||||
);
|
||||
|
||||
if (isset($meta['extra']['version-check']))
|
||||
{
|
||||
$force_update = $this->request->variable('versioncheck_force', false);
|
||||
$updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
|
||||
|
||||
$available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
|
||||
$available_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
|
||||
$available_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$available_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
|
||||
}
|
||||
}
|
||||
catch (version_check_exception $e)
|
||||
{
|
||||
$available_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
|
||||
}
|
||||
catch (exception_interface $e)
|
||||
{
|
||||
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
$this->template->assign_block_vars('disabled', array(
|
||||
'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
|
||||
'S_VERSIONCHECK' => false,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
uasort($available_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
|
||||
|
||||
foreach ($available_extension_meta_data as $name => $block_vars)
|
||||
{
|
||||
$block_vars['NAME'] = $name;
|
||||
$block_vars['U_DETAILS'] = $this->u_action . '&action=details&ext_name=' . urlencode($name);
|
||||
|
||||
$this->template->assign_block_vars('disabled', $block_vars);
|
||||
|
||||
$this->output_actions('disabled', array(
|
||||
'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output actions to a block
|
||||
*
|
||||
* @param string $block
|
||||
* @param array $actions
|
||||
*/
|
||||
private function output_actions($block, $actions)
|
||||
{
|
||||
foreach ($actions as $lang => $url)
|
||||
{
|
||||
$this->template->assign_block_vars($block . '.actions', array(
|
||||
'L_ACTION' => $this->user->lang('EXTENSION_' . $lang),
|
||||
'L_ACTION_EXPLAIN' => (isset($this->user->lang['EXTENSION_' . $lang . '_EXPLAIN'])) ? $this->user->lang('EXTENSION_' . $lang . '_EXPLAIN') : '',
|
||||
'U_ACTION' => $url,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort helper for the table containing the metadata about the extensions.
|
||||
*/
|
||||
protected function sort_extension_meta_data_table($val1, $val2)
|
||||
{
|
||||
return strnatcasecmp($val1['META_DISPLAY_NAME'], $val2['META_DISPLAY_NAME']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs extension metadata into the template
|
||||
*
|
||||
* @param array $metadata Array with all metadata for the extension
|
||||
* @return null
|
||||
*/
|
||||
public function output_metadata_to_template($metadata)
|
||||
{
|
||||
$this->template->assign_vars(array(
|
||||
'META_NAME' => $metadata['name'],
|
||||
'META_TYPE' => $metadata['type'],
|
||||
'META_DESCRIPTION' => (isset($metadata['description'])) ? $metadata['description'] : '',
|
||||
'META_HOMEPAGE' => (isset($metadata['homepage'])) ? $metadata['homepage'] : '',
|
||||
'META_VERSION' => $metadata['version'],
|
||||
'META_TIME' => (isset($metadata['time'])) ? $metadata['time'] : '',
|
||||
'META_LICENSE' => $metadata['license'],
|
||||
|
||||
'META_REQUIRE_PHP' => (isset($metadata['require']['php'])) ? $metadata['require']['php'] : '',
|
||||
'META_REQUIRE_PHP_FAIL' => (isset($metadata['require']['php'])) ? false : true,
|
||||
|
||||
'META_REQUIRE_PHPBB' => (isset($metadata['extra']['soft-require']['phpbb/phpbb'])) ? $metadata['extra']['soft-require']['phpbb/phpbb'] : '',
|
||||
'META_REQUIRE_PHPBB_FAIL' => (isset($metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true,
|
||||
|
||||
'META_DISPLAY_NAME' => (isset($metadata['extra']['display-name'])) ? $metadata['extra']['display-name'] : '',
|
||||
));
|
||||
|
||||
foreach ($metadata['authors'] as $author)
|
||||
{
|
||||
$this->template->assign_block_vars('meta_authors', array(
|
||||
'AUTHOR_NAME' => $author['name'],
|
||||
'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '',
|
||||
'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '',
|
||||
'AUTHOR_ROLE' => (isset($author['role'])) ? $author['role'] : '',
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
2179
install/update/old/includes/acp/acp_forums.php
Normal file
2179
install/update/old/includes/acp/acp_forums.php
Normal file
File diff suppressed because it is too large
Load Diff
143
install/update/old/includes/acp/acp_help_phpbb.php
Normal file
143
install/update/old/includes/acp/acp_help_phpbb.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_help_phpbb
|
||||
{
|
||||
var $u_action;
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $config, $request, $template, $user, $phpbb_dispatcher, $phpbb_admin_path, $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!class_exists('phpbb_questionnaire_data_collector'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/questionnaire/questionnaire.' . $phpEx);
|
||||
}
|
||||
|
||||
$collect_url = "https://www.phpbb.com/stats/receive_stats.php";
|
||||
|
||||
$this->tpl_name = 'acp_help_phpbb';
|
||||
$this->page_title = 'ACP_HELP_PHPBB';
|
||||
|
||||
$submit = ($request->is_set_post('submit')) ? true : false;
|
||||
|
||||
$form_key = 'acp_help_phpbb';
|
||||
add_form_key($form_key);
|
||||
$error = array();
|
||||
|
||||
if ($submit && !check_form_key($form_key))
|
||||
{
|
||||
$error[] = $user->lang['FORM_INVALID'];
|
||||
}
|
||||
// Do not write values if there is an error
|
||||
if (count($error))
|
||||
{
|
||||
$submit = false;
|
||||
}
|
||||
|
||||
// generate a unique id if necessary
|
||||
if (!isset($config['questionnaire_unique_id']))
|
||||
{
|
||||
$install_id = unique_id();
|
||||
$config->set('questionnaire_unique_id', $install_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$install_id = $config['questionnaire_unique_id'];
|
||||
}
|
||||
|
||||
$collector = new phpbb_questionnaire_data_collector($install_id);
|
||||
|
||||
// Add data provider
|
||||
$collector->add_data_provider(new phpbb_questionnaire_php_data_provider());
|
||||
$collector->add_data_provider(new phpbb_questionnaire_system_data_provider());
|
||||
$collector->add_data_provider(new phpbb_questionnaire_phpbb_data_provider($config));
|
||||
|
||||
/**
|
||||
* Event to modify ACP help phpBB page and/or listen to submit
|
||||
*
|
||||
* @event core.acp_help_phpbb_submit_before
|
||||
* @var boolean submit Do we display the form or process the submission
|
||||
* @since 3.2.0-RC2
|
||||
*/
|
||||
$vars = array('submit');
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_help_phpbb_submit_before', compact($vars)));
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
$config->set('help_send_statistics', $request->variable('help_send_statistics', false));
|
||||
$response = $request->variable('send_statistics_response', '');
|
||||
|
||||
$config->set('help_send_statistics_time', time());
|
||||
|
||||
if (!empty($response))
|
||||
{
|
||||
if ((strpos($response, 'Thank you') !== false || strpos($response, 'Flood protection') !== false))
|
||||
{
|
||||
trigger_error($user->lang('THANKS_SEND_STATISTICS') . adm_back_link($this->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error($user->lang('FAIL_SEND_STATISTICS') . adm_back_link($this->u_action));
|
||||
}
|
||||
}
|
||||
|
||||
trigger_error($user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action));
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_COLLECT_STATS' => $collect_url,
|
||||
'S_COLLECT_STATS' => (!empty($config['help_send_statistics'])) ? true : false,
|
||||
'RAW_DATA' => $collector->get_data_for_form(),
|
||||
'U_ACP_MAIN' => append_sid("{$phpbb_admin_path}index.$phpEx"),
|
||||
'U_ACTION' => $this->u_action,
|
||||
// Pass earliest time we should try to send stats again
|
||||
'COLLECT_STATS_TIME' => intval($config['help_send_statistics_time']) + 86400,
|
||||
));
|
||||
|
||||
$raw = $collector->get_data_raw();
|
||||
|
||||
foreach ($raw as $provider => $data)
|
||||
{
|
||||
if ($provider == 'install_id')
|
||||
{
|
||||
$data = array($provider => $data);
|
||||
}
|
||||
|
||||
$template->assign_block_vars('providers', array(
|
||||
'NAME' => htmlspecialchars($provider),
|
||||
));
|
||||
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
if (is_array($value))
|
||||
{
|
||||
$value = utf8_wordwrap(serialize($value), 75, "\n", true);
|
||||
}
|
||||
|
||||
$template->assign_block_vars('providers.values', array(
|
||||
'KEY' => utf8_htmlspecialchars($key),
|
||||
'VALUE' => utf8_htmlspecialchars($value),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
707
install/update/old/includes/acp/acp_main.php
Normal file
707
install/update/old/includes/acp/acp_main.php
Normal file
@@ -0,0 +1,707 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_main
|
||||
{
|
||||
var $u_action;
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $config, $db, $cache, $user, $auth, $template, $request, $phpbb_log;
|
||||
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container, $phpbb_dispatcher, $phpbb_filesystem;
|
||||
|
||||
// Show restore permissions notice
|
||||
if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
|
||||
{
|
||||
$this->tpl_name = 'acp_main';
|
||||
$this->page_title = 'ACP_MAIN';
|
||||
|
||||
$sql = 'SELECT user_id, username, user_colour
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_id = ' . $user->data['user_perm_from'];
|
||||
$result = $db->sql_query($sql);
|
||||
$user_row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$perm_from = get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_RESTORE_PERMISSIONS' => true,
|
||||
'U_RESTORE_PERMISSIONS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm'),
|
||||
'PERM_FROM' => $perm_from,
|
||||
'L_PERMISSIONS_TRANSFERRED_EXPLAIN' => sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm')),
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$action = $request->variable('action', '');
|
||||
|
||||
if ($action)
|
||||
{
|
||||
if ($action === 'admlogout')
|
||||
{
|
||||
$user->unset_admin();
|
||||
redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
|
||||
}
|
||||
|
||||
if (!confirm_box(true))
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
case 'online':
|
||||
$confirm = true;
|
||||
$confirm_lang = 'RESET_ONLINE_CONFIRM';
|
||||
break;
|
||||
case 'stats':
|
||||
$confirm = true;
|
||||
$confirm_lang = 'RESYNC_STATS_CONFIRM';
|
||||
break;
|
||||
case 'user':
|
||||
$confirm = true;
|
||||
$confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
|
||||
break;
|
||||
case 'date':
|
||||
$confirm = true;
|
||||
$confirm_lang = 'RESET_DATE_CONFIRM';
|
||||
break;
|
||||
case 'db_track':
|
||||
$confirm = true;
|
||||
$confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
|
||||
break;
|
||||
case 'purge_cache':
|
||||
$confirm = true;
|
||||
$confirm_lang = 'PURGE_CACHE_CONFIRM';
|
||||
break;
|
||||
case 'purge_sessions':
|
||||
$confirm = true;
|
||||
$confirm_lang = 'PURGE_SESSIONS_CONFIRM';
|
||||
break;
|
||||
|
||||
default:
|
||||
$confirm = true;
|
||||
$confirm_lang = 'CONFIRM_OPERATION';
|
||||
}
|
||||
|
||||
if ($confirm)
|
||||
{
|
||||
confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array(
|
||||
'i' => $id,
|
||||
'mode' => $mode,
|
||||
'action' => $action,
|
||||
)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
|
||||
case 'online':
|
||||
if (!$auth->acl_get('a_board'))
|
||||
{
|
||||
send_status_line(403, 'Forbidden');
|
||||
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$config->set('record_online_users', 1, false);
|
||||
$config->set('record_online_date', time(), false);
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESET_ONLINE');
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
trigger_error('RESET_ONLINE_SUCCESS');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'stats':
|
||||
if (!$auth->acl_get('a_board'))
|
||||
{
|
||||
send_status_line(403, 'Forbidden');
|
||||
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$sql = 'SELECT COUNT(post_id) AS stat
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_visibility = ' . ITEM_APPROVED;
|
||||
$result = $db->sql_query($sql);
|
||||
$config->set('num_posts', (int) $db->sql_fetchfield('stat'), false);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql = 'SELECT COUNT(topic_id) AS stat
|
||||
FROM ' . TOPICS_TABLE . '
|
||||
WHERE topic_visibility = ' . ITEM_APPROVED;
|
||||
$result = $db->sql_query($sql);
|
||||
$config->set('num_topics', (int) $db->sql_fetchfield('stat'), false);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql = 'SELECT COUNT(user_id) AS stat
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
|
||||
$result = $db->sql_query($sql);
|
||||
$config->set('num_users', (int) $db->sql_fetchfield('stat'), false);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql = 'SELECT COUNT(attach_id) as stat
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE is_orphan = 0';
|
||||
$result = $db->sql_query($sql);
|
||||
$config->set('num_files', (int) $db->sql_fetchfield('stat'), false);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql = 'SELECT SUM(filesize) as stat
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE is_orphan = 0';
|
||||
$result = $db->sql_query($sql);
|
||||
$config->set('upload_dir_size', (float) $db->sql_fetchfield('stat'), false);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (!function_exists('update_last_username'))
|
||||
{
|
||||
include($phpbb_root_path . "includes/functions_user.$phpEx");
|
||||
}
|
||||
update_last_username();
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_STATS');
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
trigger_error('RESYNC_STATS_SUCCESS');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
if (!$auth->acl_get('a_board'))
|
||||
{
|
||||
send_status_line(403, 'Forbidden');
|
||||
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
// Resync post counts
|
||||
$start = $max_post_id = 0;
|
||||
|
||||
// Find the maximum post ID, we can only stop the cycle when we've reached it
|
||||
$sql = 'SELECT MAX(forum_last_post_id) as max_post_id
|
||||
FROM ' . FORUMS_TABLE;
|
||||
$result = $db->sql_query($sql);
|
||||
$max_post_id = (int) $db->sql_fetchfield('max_post_id');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// No maximum post id? :o
|
||||
if (!$max_post_id)
|
||||
{
|
||||
$sql = 'SELECT MAX(post_id) as max_post_id
|
||||
FROM ' . POSTS_TABLE;
|
||||
$result = $db->sql_query($sql);
|
||||
$max_post_id = (int) $db->sql_fetchfield('max_post_id');
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
// Still no maximum post id? Then we are finished
|
||||
if (!$max_post_id)
|
||||
{
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POSTCOUNTS');
|
||||
break;
|
||||
}
|
||||
|
||||
$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
|
||||
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
|
||||
|
||||
while ($start < $max_post_id)
|
||||
{
|
||||
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
|
||||
AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . '
|
||||
GROUP BY poster_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
do
|
||||
{
|
||||
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$start += $step;
|
||||
}
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POSTCOUNTS');
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
trigger_error('RESYNC_POSTCOUNTS_SUCCESS');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
if (!$auth->acl_get('a_board'))
|
||||
{
|
||||
send_status_line(403, 'Forbidden');
|
||||
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$config->set('board_startdate', time() - 1);
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESET_DATE');
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
trigger_error('RESET_DATE_SUCCESS');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'db_track':
|
||||
switch ($db->get_sql_layer())
|
||||
{
|
||||
case 'sqlite3':
|
||||
$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
|
||||
break;
|
||||
|
||||
default:
|
||||
$db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
|
||||
break;
|
||||
}
|
||||
|
||||
// This can get really nasty... therefore we only do the last six months
|
||||
$get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
|
||||
|
||||
// Select forum ids, do not include categories
|
||||
$sql = 'SELECT forum_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_type <> ' . FORUM_CAT;
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$forum_ids = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$forum_ids[] = $row['forum_id'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// Any global announcements? ;)
|
||||
$forum_ids[] = 0;
|
||||
|
||||
// Now go through the forums and get us some topics...
|
||||
foreach ($forum_ids as $forum_id)
|
||||
{
|
||||
$sql = 'SELECT p.poster_id, p.topic_id
|
||||
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
|
||||
WHERE t.forum_id = ' . $forum_id . '
|
||||
AND t.topic_moved_id = 0
|
||||
AND t.topic_last_post_time > ' . $get_from_time . '
|
||||
AND t.topic_id = p.topic_id
|
||||
AND p.poster_id <> ' . ANONYMOUS . '
|
||||
GROUP BY p.poster_id, p.topic_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$posted = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$posted[$row['poster_id']][] = $row['topic_id'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql_ary = array();
|
||||
foreach ($posted as $user_id => $topic_row)
|
||||
{
|
||||
foreach ($topic_row as $topic_id)
|
||||
{
|
||||
$sql_ary[] = array(
|
||||
'user_id' => (int) $user_id,
|
||||
'topic_id' => (int) $topic_id,
|
||||
'topic_posted' => 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
unset($posted);
|
||||
|
||||
if (count($sql_ary))
|
||||
{
|
||||
$db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
|
||||
}
|
||||
}
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POST_MARKING');
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
trigger_error('RESYNC_POST_MARKING_SUCCESS');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'purge_cache':
|
||||
$config->increment('assets_version', 1);
|
||||
$cache->purge();
|
||||
|
||||
// Remove old renderers from the text_formatter service. Since this
|
||||
// operation is performed after the cache is purged, there is not "current"
|
||||
// renderer and in effect all renderers will be purged
|
||||
$phpbb_container->get('text_formatter.cache')->tidy();
|
||||
|
||||
// Clear permissions
|
||||
$auth->acl_clear_prefetch();
|
||||
phpbb_cache_moderators($db, $cache, $auth);
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PURGE_CACHE');
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
trigger_error('PURGE_CACHE_SUCCESS');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'purge_sessions':
|
||||
if ((int) $user->data['user_type'] !== USER_FOUNDER)
|
||||
{
|
||||
send_status_line(403, 'Forbidden');
|
||||
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$tables = array(CONFIRM_TABLE, SESSIONS_TABLE);
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
switch ($db->get_sql_layer())
|
||||
{
|
||||
case 'sqlite3':
|
||||
$db->sql_query("DELETE FROM $table");
|
||||
break;
|
||||
|
||||
default:
|
||||
$db->sql_query("TRUNCATE TABLE $table");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// let's restore the admin session
|
||||
$reinsert_ary = array(
|
||||
'session_id' => (string) $user->session_id,
|
||||
'session_page' => (string) substr($user->page['page'], 0, 199),
|
||||
'session_forum_id' => $user->page['forum'],
|
||||
'session_user_id' => (int) $user->data['user_id'],
|
||||
'session_start' => (int) $user->data['session_start'],
|
||||
'session_last_visit' => (int) $user->data['session_last_visit'],
|
||||
'session_time' => (int) $user->time_now,
|
||||
'session_browser' => (string) trim(substr($user->browser, 0, 149)),
|
||||
'session_forwarded_for' => (string) $user->forwarded_for,
|
||||
'session_ip' => (string) $user->ip,
|
||||
'session_autologin' => (int) $user->data['session_autologin'],
|
||||
'session_admin' => 1,
|
||||
'session_viewonline' => (int) $user->data['session_viewonline'],
|
||||
);
|
||||
|
||||
$sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $reinsert_ary);
|
||||
$db->sql_query($sql);
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PURGE_SESSIONS');
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
trigger_error('PURGE_SESSIONS_SUCCESS');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Version check
|
||||
$user->add_lang('install');
|
||||
|
||||
if ($auth->acl_get('a_server') && version_compare(PHP_VERSION, '5.4.0', '<'))
|
||||
{
|
||||
$template->assign_vars(array(
|
||||
'S_PHP_VERSION_OLD' => true,
|
||||
'L_PHP_VERSION_OLD' => sprintf($user->lang['PHP_VERSION_OLD'], PHP_VERSION, '5.4.0', '<a href="https://www.phpbb.com/support/docs/en/3.2/ug/quickstart/requirements">', '</a>'),
|
||||
));
|
||||
}
|
||||
|
||||
if ($auth->acl_get('a_board'))
|
||||
{
|
||||
$version_helper = $phpbb_container->get('version_helper');
|
||||
try
|
||||
{
|
||||
$recheck = $request->variable('versioncheck_force', false);
|
||||
$updates_available = $version_helper->get_update_on_branch($recheck);
|
||||
$upgrades_available = $version_helper->get_suggested_updates();
|
||||
if (!empty($upgrades_available))
|
||||
{
|
||||
$upgrades_available = array_pop($upgrades_available);
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_VERSION_UP_TO_DATE' => empty($updates_available),
|
||||
'S_VERSION_UPGRADEABLE' => !empty($upgrades_available),
|
||||
'UPGRADE_INSTRUCTIONS' => !empty($upgrades_available) ? $user->lang('UPGRADE_INSTRUCTIONS', $upgrades_available['current'], $upgrades_available['announcement']) : false,
|
||||
));
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
$message = call_user_func_array(array($user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
|
||||
$template->assign_vars(array(
|
||||
'S_VERSIONCHECK_FAIL' => true,
|
||||
'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '',
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We set this template var to true, to not display an outdated version notice.
|
||||
$template->assign_var('S_VERSION_UP_TO_DATE', true);
|
||||
}
|
||||
|
||||
// Incomplete update?
|
||||
if (phpbb_version_compare($config['version'], PHPBB_VERSION, '<'))
|
||||
{
|
||||
$template->assign_var('S_UPDATE_INCOMPLETE', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice admin
|
||||
*
|
||||
* @event core.acp_main_notice
|
||||
* @since 3.1.0-RC3
|
||||
*/
|
||||
$phpbb_dispatcher->dispatch('core.acp_main_notice');
|
||||
|
||||
// Get forum statistics
|
||||
$total_posts = $config['num_posts'];
|
||||
$total_topics = $config['num_topics'];
|
||||
$total_users = $config['num_users'];
|
||||
$total_files = $config['num_files'];
|
||||
|
||||
$start_date = $user->format_date($config['board_startdate']);
|
||||
|
||||
$boarddays = (time() - $config['board_startdate']) / 86400;
|
||||
|
||||
$posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
|
||||
$topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
|
||||
$users_per_day = sprintf('%.2f', $total_users / $boarddays);
|
||||
$files_per_day = sprintf('%.2f', $total_files / $boarddays);
|
||||
|
||||
$upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
|
||||
|
||||
$avatar_dir_size = 0;
|
||||
|
||||
if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
|
||||
{
|
||||
while (($file = readdir($avatar_dir)) !== false)
|
||||
{
|
||||
if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
|
||||
{
|
||||
$avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
|
||||
}
|
||||
}
|
||||
closedir($avatar_dir);
|
||||
|
||||
$avatar_dir_size = get_formatted_filesize($avatar_dir_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Couldn't open Avatar dir.
|
||||
$avatar_dir_size = $user->lang['NOT_AVAILABLE'];
|
||||
}
|
||||
|
||||
if ($posts_per_day > $total_posts)
|
||||
{
|
||||
$posts_per_day = $total_posts;
|
||||
}
|
||||
|
||||
if ($topics_per_day > $total_topics)
|
||||
{
|
||||
$topics_per_day = $total_topics;
|
||||
}
|
||||
|
||||
if ($users_per_day > $total_users)
|
||||
{
|
||||
$users_per_day = $total_users;
|
||||
}
|
||||
|
||||
if ($files_per_day > $total_files)
|
||||
{
|
||||
$files_per_day = $total_files;
|
||||
}
|
||||
|
||||
if ($config['allow_attachments'] || $config['allow_pm_attach'])
|
||||
{
|
||||
$sql = 'SELECT COUNT(attach_id) AS total_orphan
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE is_orphan = 1
|
||||
AND filetime < ' . (time() - 3*60*60);
|
||||
$result = $db->sql_query($sql);
|
||||
$total_orphan = (int) $db->sql_fetchfield('total_orphan');
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
$total_orphan = false;
|
||||
}
|
||||
|
||||
$dbsize = get_database_size();
|
||||
|
||||
$template->assign_vars(array(
|
||||
'TOTAL_POSTS' => $total_posts,
|
||||
'POSTS_PER_DAY' => $posts_per_day,
|
||||
'TOTAL_TOPICS' => $total_topics,
|
||||
'TOPICS_PER_DAY' => $topics_per_day,
|
||||
'TOTAL_USERS' => $total_users,
|
||||
'USERS_PER_DAY' => $users_per_day,
|
||||
'TOTAL_FILES' => $total_files,
|
||||
'FILES_PER_DAY' => $files_per_day,
|
||||
'START_DATE' => $start_date,
|
||||
'AVATAR_DIR_SIZE' => $avatar_dir_size,
|
||||
'DBSIZE' => $dbsize,
|
||||
'UPLOAD_DIR_SIZE' => $upload_dir_size,
|
||||
'TOTAL_ORPHAN' => $total_orphan,
|
||||
'S_TOTAL_ORPHAN' => ($total_orphan === false) ? false : true,
|
||||
'GZIP_COMPRESSION' => ($config['gzip_compress'] && @extension_loaded('zlib')) ? $user->lang['ON'] : $user->lang['OFF'],
|
||||
'DATABASE_INFO' => $db->sql_server_info(),
|
||||
'PHP_VERSION_INFO' => PHP_VERSION,
|
||||
'BOARD_VERSION' => $config['version'],
|
||||
|
||||
'U_ACTION' => $this->u_action,
|
||||
'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&mode=admin'),
|
||||
'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&mode=list'),
|
||||
'U_VERSIONCHECK' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=update&mode=version_check'),
|
||||
'U_VERSIONCHECK_FORCE' => append_sid("{$phpbb_admin_path}index.$phpEx", 'versioncheck_force=1'),
|
||||
'U_ATTACH_ORPHAN' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=acp_attachments&mode=orphan'),
|
||||
|
||||
'S_VERSIONCHECK' => ($auth->acl_get('a_board')) ? true : false,
|
||||
'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ? true : false,
|
||||
'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
|
||||
)
|
||||
);
|
||||
|
||||
$log_data = array();
|
||||
$log_count = false;
|
||||
|
||||
if ($auth->acl_get('a_viewlogs'))
|
||||
{
|
||||
view_log('admin', $log_data, $log_count, 5);
|
||||
|
||||
foreach ($log_data as $row)
|
||||
{
|
||||
$template->assign_block_vars('log', array(
|
||||
'USERNAME' => $row['username_full'],
|
||||
'IP' => $row['ip'],
|
||||
'DATE' => $user->format_date($row['time']),
|
||||
'ACTION' => $row['action'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($auth->acl_get('a_user'))
|
||||
{
|
||||
$user->add_lang('memberlist');
|
||||
|
||||
$inactive = array();
|
||||
$inactive_count = 0;
|
||||
|
||||
view_inactive_users($inactive, $inactive_count, 10);
|
||||
|
||||
foreach ($inactive as $row)
|
||||
{
|
||||
$template->assign_block_vars('inactive', array(
|
||||
'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
|
||||
'REMINDED_DATE' => $user->format_date($row['user_reminded_time']),
|
||||
'JOINED' => $user->format_date($row['user_regdate']),
|
||||
'LAST_VISIT' => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
|
||||
|
||||
'REASON' => $row['inactive_reason'],
|
||||
'USER_ID' => $row['user_id'],
|
||||
'POSTS' => ($row['user_posts']) ? $row['user_posts'] : 0,
|
||||
'REMINDED' => $row['user_reminded'],
|
||||
|
||||
'REMINDED_EXPLAIN' => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
|
||||
|
||||
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview')),
|
||||
'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
|
||||
'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
|
||||
|
||||
'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&mode=overview&u={$row['user_id']}"),
|
||||
'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&sr=posts") : '',
|
||||
));
|
||||
}
|
||||
|
||||
$option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
|
||||
if ($config['email_enable'])
|
||||
{
|
||||
$option_ary += array('remind' => 'REMIND');
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_INACTIVE_USERS' => true,
|
||||
'S_INACTIVE_OPTIONS' => build_select($option_ary))
|
||||
);
|
||||
}
|
||||
|
||||
// Warn if install is still present
|
||||
if (file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
|
||||
{
|
||||
$template->assign_var('S_REMOVE_INSTALL', true);
|
||||
}
|
||||
|
||||
// Warn if no search index is created
|
||||
if ($config['num_posts'] && class_exists($config['search_type']))
|
||||
{
|
||||
$error = false;
|
||||
$search_type = $config['search_type'];
|
||||
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
|
||||
if (!$search->index_created())
|
||||
{
|
||||
$template->assign_vars(array(
|
||||
'S_SEARCH_INDEX_MISSING' => true,
|
||||
'L_NO_SEARCH_INDEX' => $user->lang('NO_SEARCH_INDEX', $search->get_name(), '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=acp_search&mode=index') . '">', '</a>'),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && $phpbb_filesystem->is_writable($phpbb_root_path . 'config.' . $phpEx))
|
||||
{
|
||||
// World-Writable? (000x)
|
||||
$template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002));
|
||||
}
|
||||
|
||||
if (extension_loaded('mbstring'))
|
||||
{
|
||||
$template->assign_vars(array(
|
||||
'S_MBSTRING_LOADED' => true,
|
||||
'S_MBSTRING_FUNC_OVERLOAD_FAIL' => (intval(@ini_get('mbstring.func_overload')) & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING)),
|
||||
'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => (@ini_get('mbstring.encoding_translation') != 0),
|
||||
'S_MBSTRING_HTTP_INPUT_FAIL' => !in_array(@ini_get('mbstring.http_input'), array('pass', '')),
|
||||
'S_MBSTRING_HTTP_OUTPUT_FAIL' => !in_array(@ini_get('mbstring.http_output'), array('pass', '')),
|
||||
));
|
||||
}
|
||||
|
||||
// Fill dbms version if not yet filled
|
||||
if (empty($config['dbms_version']))
|
||||
{
|
||||
$config->set('dbms_version', $db->sql_server_info(true));
|
||||
}
|
||||
|
||||
$this->tpl_name = 'acp_main';
|
||||
$this->page_title = 'ACP_MAIN';
|
||||
}
|
||||
}
|
||||
1346
install/update/old/includes/acp/acp_permissions.php
Normal file
1346
install/update/old/includes/acp/acp_permissions.php
Normal file
File diff suppressed because it is too large
Load Diff
587
install/update/old/includes/acp/acp_prune.php
Normal file
587
install/update/old/includes/acp/acp_prune.php
Normal file
@@ -0,0 +1,587 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_prune
|
||||
{
|
||||
var $u_action;
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $user, $phpEx, $phpbb_root_path;
|
||||
|
||||
$user->add_lang('acp/prune');
|
||||
|
||||
if (!function_exists('user_active_flip'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
||||
}
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 'forums':
|
||||
$this->tpl_name = 'acp_prune_forums';
|
||||
$this->page_title = 'ACP_PRUNE_FORUMS';
|
||||
$this->prune_forums($id, $mode);
|
||||
break;
|
||||
|
||||
case 'users':
|
||||
$this->tpl_name = 'acp_prune_users';
|
||||
$this->page_title = 'ACP_PRUNE_USERS';
|
||||
$this->prune_users($id, $mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune forums
|
||||
*/
|
||||
function prune_forums($id, $mode)
|
||||
{
|
||||
global $db, $user, $auth, $template, $phpbb_log, $request, $phpbb_dispatcher;
|
||||
|
||||
$all_forums = $request->variable('all_forums', 0);
|
||||
$forum_id = $request->variable('f', array(0));
|
||||
$submit = (isset($_POST['submit'])) ? true : false;
|
||||
|
||||
if ($all_forums)
|
||||
{
|
||||
$sql = 'SELECT forum_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
ORDER BY left_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$forum_id = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$forum_id[] = $row['forum_id'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$prune_posted = $request->variable('prune_days', 0);
|
||||
$prune_viewed = $request->variable('prune_vieweddays', 0);
|
||||
$prune_all = (!$prune_posted && !$prune_viewed) ? true : false;
|
||||
|
||||
$prune_flags = 0;
|
||||
$prune_flags += ($request->variable('prune_old_polls', 0)) ? 2 : 0;
|
||||
$prune_flags += ($request->variable('prune_announce', 0)) ? 4 : 0;
|
||||
$prune_flags += ($request->variable('prune_sticky', 0)) ? 8 : 0;
|
||||
|
||||
// Convert days to seconds for timestamp functions...
|
||||
$prunedate_posted = time() - ($prune_posted * 86400);
|
||||
$prunedate_viewed = time() - ($prune_viewed * 86400);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_PRUNED' => true)
|
||||
);
|
||||
|
||||
$sql_forum = (count($forum_id)) ? ' AND ' . $db->sql_in_set('forum_id', $forum_id) : '';
|
||||
|
||||
// Get a list of forum's or the data for the forum that we are pruning.
|
||||
$sql = 'SELECT forum_id, forum_name
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_type = ' . FORUM_POST . "
|
||||
$sql_forum
|
||||
ORDER BY left_id ASC";
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$prune_ids = array();
|
||||
$p_result['topics'] = 0;
|
||||
$p_result['posts'] = 0;
|
||||
$log_data = '';
|
||||
|
||||
do
|
||||
{
|
||||
if (!$auth->acl_get('f_list', $row['forum_id']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($prune_all)
|
||||
{
|
||||
$p_result = prune($row['forum_id'], 'posted', time(), $prune_flags, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($prune_posted)
|
||||
{
|
||||
$return = prune($row['forum_id'], 'posted', $prunedate_posted, $prune_flags, false);
|
||||
$p_result['topics'] += $return['topics'];
|
||||
$p_result['posts'] += $return['posts'];
|
||||
}
|
||||
|
||||
if ($prune_viewed)
|
||||
{
|
||||
$return = prune($row['forum_id'], 'viewed', $prunedate_viewed, $prune_flags, false);
|
||||
$p_result['topics'] += $return['topics'];
|
||||
$p_result['posts'] += $return['posts'];
|
||||
}
|
||||
}
|
||||
|
||||
$prune_ids[] = $row['forum_id'];
|
||||
|
||||
$template->assign_block_vars('pruned', array(
|
||||
'FORUM_NAME' => $row['forum_name'],
|
||||
'NUM_TOPICS' => $p_result['topics'],
|
||||
'NUM_POSTS' => $p_result['posts'])
|
||||
);
|
||||
|
||||
$log_data .= (($log_data != '') ? ', ' : '') . $row['forum_name'];
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
|
||||
// Sync all pruned forums at once
|
||||
sync('forum', 'forum_id', $prune_ids, true, true);
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PRUNE', false, array($log_data));
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hidden_fields = array(
|
||||
'i' => $id,
|
||||
'mode' => $mode,
|
||||
'submit' => 1,
|
||||
'all_forums' => $all_forums,
|
||||
'f' => $forum_id,
|
||||
|
||||
'prune_days' => $request->variable('prune_days', 0),
|
||||
'prune_vieweddays' => $request->variable('prune_vieweddays', 0),
|
||||
'prune_old_polls' => $request->variable('prune_old_polls', 0),
|
||||
'prune_announce' => $request->variable('prune_announce', 0),
|
||||
'prune_sticky' => $request->variable('prune_sticky', 0),
|
||||
);
|
||||
|
||||
/**
|
||||
* Use this event to pass data from the prune form to the confirmation screen
|
||||
*
|
||||
* @event core.prune_forums_settings_confirm
|
||||
* @var array hidden_fields Hidden fields that are passed through the confirm screen
|
||||
* @since 3.2.2-RC1
|
||||
*/
|
||||
$vars = array('hidden_fields');
|
||||
extract($phpbb_dispatcher->trigger_event('core.prune_forums_settings_confirm', compact($vars)));
|
||||
|
||||
confirm_box(false, $user->lang['PRUNE_FORUM_CONFIRM'], build_hidden_fields($hidden_fields));
|
||||
}
|
||||
}
|
||||
|
||||
// If they haven't selected a forum for pruning yet then
|
||||
// display a select box to use for pruning.
|
||||
if (!count($forum_id))
|
||||
{
|
||||
$template->assign_vars(array(
|
||||
'U_ACTION' => $this->u_action,
|
||||
'S_SELECT_FORUM' => true,
|
||||
'S_FORUM_OPTIONS' => make_forum_select(false, false, false))
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT forum_id, forum_name
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE ' . $db->sql_in_set('forum_id', $forum_id);
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
|
||||
if (!$row)
|
||||
{
|
||||
$db->sql_freeresult($result);
|
||||
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$forum_list = $s_hidden_fields = '';
|
||||
do
|
||||
{
|
||||
$forum_list .= (($forum_list != '') ? ', ' : '') . '<b>' . $row['forum_name'] . '</b>';
|
||||
$s_hidden_fields .= '<input type="hidden" name="f[]" value="' . $row['forum_id'] . '" />';
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$l_selected_forums = (count($forum_id) == 1) ? 'SELECTED_FORUM' : 'SELECTED_FORUMS';
|
||||
|
||||
$template_data = array(
|
||||
'L_SELECTED_FORUMS' => $user->lang[$l_selected_forums],
|
||||
'U_ACTION' => $this->u_action,
|
||||
'U_BACK' => $this->u_action,
|
||||
'FORUM_LIST' => $forum_list,
|
||||
'S_HIDDEN_FIELDS' => $s_hidden_fields,
|
||||
);
|
||||
|
||||
/**
|
||||
* Event to add/modify prune forums settings template data
|
||||
*
|
||||
* @event core.prune_forums_settings_template_data
|
||||
* @var array template_data Array with form template data
|
||||
* @since 3.2.2-RC1
|
||||
*/
|
||||
$vars = array('template_data');
|
||||
extract($phpbb_dispatcher->trigger_event('core.prune_forums_settings_template_data', compact($vars)));
|
||||
|
||||
$template->assign_vars($template_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune users
|
||||
*/
|
||||
function prune_users($id, $mode)
|
||||
{
|
||||
global $db, $user, $auth, $template, $phpbb_log, $request;
|
||||
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
|
||||
|
||||
/** @var \phpbb\group\helper $group_helper */
|
||||
$group_helper = $phpbb_container->get('group_helper');
|
||||
|
||||
$user->add_lang('memberlist');
|
||||
|
||||
$prune = (isset($_POST['prune'])) ? true : false;
|
||||
|
||||
if ($prune)
|
||||
{
|
||||
$action = $request->variable('action', 'deactivate');
|
||||
$deleteposts = $request->variable('deleteposts', 0);
|
||||
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$user_ids = $usernames = array();
|
||||
|
||||
$this->get_prune_users($user_ids, $usernames);
|
||||
if (count($user_ids))
|
||||
{
|
||||
if ($action == 'deactivate')
|
||||
{
|
||||
user_active_flip('deactivate', $user_ids);
|
||||
$l_log = 'LOG_PRUNE_USER_DEAC';
|
||||
}
|
||||
else if ($action == 'delete')
|
||||
{
|
||||
if ($deleteposts)
|
||||
{
|
||||
user_delete('remove', $user_ids);
|
||||
|
||||
$l_log = 'LOG_PRUNE_USER_DEL_DEL';
|
||||
}
|
||||
else
|
||||
{
|
||||
user_delete('retain', $user_ids, true);
|
||||
|
||||
$l_log = 'LOG_PRUNE_USER_DEL_ANON';
|
||||
}
|
||||
}
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, $l_log, false, array(implode(', ', $usernames)));
|
||||
$msg = $user->lang['USER_' . strtoupper($action) . '_SUCCESS'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = $user->lang['USER_PRUNE_FAILURE'];
|
||||
}
|
||||
|
||||
trigger_error($msg . adm_back_link($this->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
// We list the users which will be pruned...
|
||||
$user_ids = $usernames = array();
|
||||
$this->get_prune_users($user_ids, $usernames);
|
||||
|
||||
if (!count($user_ids))
|
||||
{
|
||||
trigger_error($user->lang['USER_PRUNE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
// Assign to template
|
||||
foreach ($user_ids as $user_id)
|
||||
{
|
||||
$template->assign_block_vars('users', array(
|
||||
'USERNAME' => $usernames[$user_id],
|
||||
'USER_ID' => $user_id,
|
||||
'U_PROFILE' => get_username_string('profile', $user_id, $usernames[$user_id]),
|
||||
'U_USER_ADMIN' => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview&u=' . $user_id, true, $user->session_id) : '',
|
||||
));
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_DEACTIVATE' => ($action == 'deactivate') ? true : false,
|
||||
'S_DELETE' => ($action == 'delete') ? true : false,
|
||||
));
|
||||
|
||||
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
|
||||
'i' => $id,
|
||||
'mode' => $mode,
|
||||
'prune' => 1,
|
||||
|
||||
'deleteposts' => $request->variable('deleteposts', 0),
|
||||
'action' => $request->variable('action', ''),
|
||||
)), 'confirm_body_prune.html');
|
||||
}
|
||||
}
|
||||
|
||||
$find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
|
||||
$s_find_count = '';
|
||||
|
||||
foreach ($find_count as $key => $value)
|
||||
{
|
||||
$selected = ($key == 'eq') ? ' selected="selected"' : '';
|
||||
$s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
|
||||
}
|
||||
|
||||
$find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
|
||||
$s_find_active_time = '';
|
||||
foreach ($find_time as $key => $value)
|
||||
{
|
||||
$s_find_active_time .= '<option value="' . $key . '">' . $value . '</option>';
|
||||
}
|
||||
|
||||
$sql = 'SELECT group_id, group_name
|
||||
FROM ' . GROUPS_TABLE . '
|
||||
WHERE group_type <> ' . GROUP_SPECIAL . '
|
||||
ORDER BY group_name ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$s_group_list = '';
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$s_group_list .= '<option value="' . $row['group_id'] . '">' . $group_helper->get_name($row['group_name']) . '</option>';
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if ($s_group_list)
|
||||
{
|
||||
// Only prepend the "All groups" option if there are groups,
|
||||
// otherwise we don't want to display this option at all.
|
||||
$s_group_list = '<option value="0">' . $user->lang['PRUNE_USERS_GROUP_NONE'] . '</option>' . $s_group_list;
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_ACTION' => $this->u_action,
|
||||
'S_ACTIVE_OPTIONS' => $s_find_active_time,
|
||||
'S_GROUP_LIST' => $s_group_list,
|
||||
'S_COUNT_OPTIONS' => $s_find_count,
|
||||
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_prune&field=users'),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user_ids/usernames from those being pruned
|
||||
*/
|
||||
function get_prune_users(&$user_ids, &$usernames)
|
||||
{
|
||||
global $user, $db, $request;
|
||||
|
||||
$users_by_name = $request->variable('users', '', true);
|
||||
$users_by_id = $request->variable('user_ids', array(0));
|
||||
$group_id = $request->variable('group_id', 0);
|
||||
$posts_on_queue = (trim($request->variable('posts_on_queue', '')) === '') ? false : $request->variable('posts_on_queue', 0);
|
||||
|
||||
if ($users_by_name)
|
||||
{
|
||||
$users = explode("\n", $users_by_name);
|
||||
$where_sql = ' AND ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', $users));
|
||||
}
|
||||
else if (!empty($users_by_id))
|
||||
{
|
||||
$user_ids = $users_by_id;
|
||||
user_get_id_name($user_ids, $usernames);
|
||||
|
||||
$where_sql = ' AND ' . $db->sql_in_set('user_id', $user_ids);
|
||||
}
|
||||
else
|
||||
{
|
||||
$username = $request->variable('username', '', true);
|
||||
$email = $request->variable('email', '');
|
||||
|
||||
$active_select = $request->variable('active_select', 'lt');
|
||||
$count_select = $request->variable('count_select', 'eq');
|
||||
$queue_select = $request->variable('queue_select', 'gt');
|
||||
$joined_before = $request->variable('joined_before', '');
|
||||
$joined_after = $request->variable('joined_after', '');
|
||||
$active = $request->variable('active', '');
|
||||
|
||||
$count = ($request->variable('count', '') === '') ? false : $request->variable('count', 0);
|
||||
|
||||
$active = ($active) ? explode('-', $active) : array();
|
||||
$joined_before = ($joined_before) ? explode('-', $joined_before) : array();
|
||||
$joined_after = ($joined_after) ? explode('-', $joined_after) : array();
|
||||
|
||||
// calculate the conditions required by the join time criteria
|
||||
$joined_sql = '';
|
||||
if (!empty($joined_before) && !empty($joined_after))
|
||||
{
|
||||
// if the two entered dates are equal, we need to adjust
|
||||
// so that our time range is a full day instead of 1 second
|
||||
if ($joined_after == $joined_before)
|
||||
{
|
||||
$joined_after[2] += 1;
|
||||
}
|
||||
|
||||
$joined_sql = ' AND user_regdate BETWEEN ' . gmmktime(0, 0, 0, (int) $joined_after[1], (int) $joined_after[2], (int) $joined_after[0]) .
|
||||
' AND ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]);
|
||||
}
|
||||
else if (empty($joined_before) && !empty($joined_after))
|
||||
{
|
||||
$joined_sql = ' AND user_regdate > ' . gmmktime(0, 0, 0, (int) $joined_after[1], (int) $joined_after[2], (int) $joined_after[0]);
|
||||
}
|
||||
else if (empty($joined_after) && !empty($joined_before))
|
||||
{
|
||||
$joined_sql = ' AND user_regdate < ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]);
|
||||
}
|
||||
// implicit else when both arrays are empty do nothing
|
||||
|
||||
if ((count($active) && count($active) != 3) || (count($joined_before) && count($joined_before) != 3) || (count($joined_after) && count($joined_after) != 3))
|
||||
{
|
||||
trigger_error($user->lang['WRONG_ACTIVE_JOINED_DATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
|
||||
|
||||
$where_sql = '';
|
||||
$where_sql .= ($username) ? ' AND username_clean ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), utf8_clean_string($username))) : '';
|
||||
$where_sql .= ($email) ? ' AND user_email ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), $email)) . ' ' : '';
|
||||
$where_sql .= $joined_sql;
|
||||
$where_sql .= ($count !== false) ? " AND user_posts " . $key_match[$count_select] . ' ' . (int) $count . ' ' : '';
|
||||
|
||||
// First handle pruning of users who never logged in, last active date is 0000-00-00
|
||||
if (count($active) && (int) $active[0] == 0 && (int) $active[1] == 0 && (int) $active[2] == 0)
|
||||
{
|
||||
$where_sql .= ' AND user_lastvisit = 0';
|
||||
}
|
||||
else if (count($active) && $active_select != 'lt')
|
||||
{
|
||||
$where_sql .= ' AND user_lastvisit ' . $key_match[$active_select] . ' ' . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
|
||||
}
|
||||
else if (count($active))
|
||||
{
|
||||
$where_sql .= ' AND (user_lastvisit > 0 AND user_lastvisit < ' . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
// If no search criteria were provided, go no further.
|
||||
if (!$where_sql && !$group_id && $posts_on_queue === false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get bot ids
|
||||
$sql = 'SELECT user_id
|
||||
FROM ' . BOTS_TABLE;
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$bot_ids = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$bot_ids[] = $row['user_id'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// Protect the admin, do not prune if no options are given...
|
||||
if ($where_sql)
|
||||
{
|
||||
// Do not prune founder members
|
||||
$sql = 'SELECT user_id, username
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_id <> ' . ANONYMOUS . '
|
||||
AND user_type <> ' . USER_FOUNDER . "
|
||||
$where_sql";
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$user_ids = $usernames = array();
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
// Do not prune bots and the user currently pruning.
|
||||
if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids))
|
||||
{
|
||||
$user_ids[] = $row['user_id'];
|
||||
$usernames[$row['user_id']] = $row['username'];
|
||||
}
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if ($group_id)
|
||||
{
|
||||
$sql = 'SELECT u.user_id, u.username
|
||||
FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
|
||||
WHERE ug.group_id = ' . (int) $group_id . '
|
||||
AND ug.user_id <> ' . ANONYMOUS . '
|
||||
AND u.user_type <> ' . USER_FOUNDER . '
|
||||
AND ug.user_pending = 0
|
||||
AND u.user_id = ug.user_id
|
||||
' . (!empty($user_ids) ? ' AND ' . $db->sql_in_set('ug.user_id', $user_ids) : '');
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
// we're performing an intersection operation, so all the relevant users
|
||||
// come from this most recent query (which was limited to the results of the
|
||||
// previous query)
|
||||
$user_ids = $usernames = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
// Do not prune bots and the user currently pruning.
|
||||
if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids))
|
||||
{
|
||||
$user_ids[] = $row['user_id'];
|
||||
$usernames[$row['user_id']] = $row['username'];
|
||||
}
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if ($posts_on_queue !== false)
|
||||
{
|
||||
$sql = 'SELECT u.user_id, u.username, COUNT(p.post_id) AS queue_posts
|
||||
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
|
||||
WHERE u.user_id <> ' . ANONYMOUS . '
|
||||
AND u.user_type <> ' . USER_FOUNDER . '
|
||||
AND ' . $db->sql_in_set('p.post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)) . '
|
||||
AND u.user_id = p.poster_id
|
||||
' . (!empty($user_ids) ? ' AND ' . $db->sql_in_set('p.poster_id', $user_ids) : '') . '
|
||||
GROUP BY p.poster_id
|
||||
HAVING queue_posts ' . $key_match[$queue_select] . ' ' . $posts_on_queue;
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
// same intersection logic as the above group ID portion
|
||||
$user_ids = $usernames = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
// Do not prune bots and the user currently pruning.
|
||||
if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids))
|
||||
{
|
||||
$user_ids[] = $row['user_id'];
|
||||
$usernames[$row['user_id']] = $row['username'];
|
||||
}
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
394
install/update/old/includes/acp/acp_reasons.php
Normal file
394
install/update/old/includes/acp/acp_reasons.php
Normal file
@@ -0,0 +1,394 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_reasons
|
||||
{
|
||||
var $u_action;
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $db, $user, $template;
|
||||
global $request, $phpbb_log;
|
||||
|
||||
$user->add_lang(array('mcp', 'acp/posting'));
|
||||
|
||||
// Set up general vars
|
||||
$action = $request->variable('action', '');
|
||||
$submit = (isset($_POST['submit'])) ? true : false;
|
||||
$reason_id = $request->variable('id', 0);
|
||||
|
||||
$this->tpl_name = 'acp_reasons';
|
||||
$this->page_title = 'ACP_REASONS';
|
||||
|
||||
$form_name = 'acp_reason';
|
||||
add_form_key('acp_reason');
|
||||
|
||||
$error = array();
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case 'add':
|
||||
case 'edit':
|
||||
|
||||
$reason_row = array(
|
||||
'reason_title' => $request->variable('reason_title', '', true),
|
||||
'reason_description' => $request->variable('reason_description', '', true),
|
||||
);
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
if (!check_form_key($form_name))
|
||||
{
|
||||
$error[] = $user->lang['FORM_INVALID'];
|
||||
}
|
||||
// Reason specified?
|
||||
if (!$reason_row['reason_title'] || !$reason_row['reason_description'])
|
||||
{
|
||||
$error[] = $user->lang['NO_REASON_INFO'];
|
||||
}
|
||||
|
||||
$check_double = ($action == 'add') ? true : false;
|
||||
|
||||
if ($action == 'edit')
|
||||
{
|
||||
$sql = 'SELECT reason_title
|
||||
FROM ' . REPORTS_REASONS_TABLE . "
|
||||
WHERE reason_id = $reason_id";
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (strtolower($row['reason_title']) == 'other' || strtolower($reason_row['reason_title']) == 'other')
|
||||
{
|
||||
$reason_row['reason_title'] = 'other';
|
||||
}
|
||||
|
||||
if ($row['reason_title'] != $reason_row['reason_title'])
|
||||
{
|
||||
$check_double = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for same reason if adding it...
|
||||
if ($check_double)
|
||||
{
|
||||
$sql = 'SELECT reason_id
|
||||
FROM ' . REPORTS_REASONS_TABLE . "
|
||||
WHERE reason_title = '" . $db->sql_escape($reason_row['reason_title']) . "'";
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if ($row || ($action == 'add' && strtolower($reason_row['reason_title']) == 'other'))
|
||||
{
|
||||
$error[] = $user->lang['REASON_ALREADY_EXIST'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!count($error))
|
||||
{
|
||||
// New reason?
|
||||
if ($action == 'add')
|
||||
{
|
||||
// Get new order...
|
||||
$sql = 'SELECT MAX(reason_order) as max_reason_order
|
||||
FROM ' . REPORTS_REASONS_TABLE;
|
||||
$result = $db->sql_query($sql);
|
||||
$max_order = (int) $db->sql_fetchfield('max_reason_order');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql_ary = array(
|
||||
'reason_title' => (string) $reason_row['reason_title'],
|
||||
'reason_description' => (string) $reason_row['reason_description'],
|
||||
'reason_order' => $max_order + 1
|
||||
);
|
||||
|
||||
$db->sql_query('INSERT INTO ' . REPORTS_REASONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
||||
|
||||
$log = 'ADDED';
|
||||
}
|
||||
else if ($reason_id)
|
||||
{
|
||||
$sql_ary = array(
|
||||
'reason_title' => (string) $reason_row['reason_title'],
|
||||
'reason_description' => (string) $reason_row['reason_description'],
|
||||
);
|
||||
|
||||
$db->sql_query('UPDATE ' . REPORTS_REASONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
|
||||
WHERE reason_id = ' . $reason_id);
|
||||
|
||||
$log = 'UPDATED';
|
||||
}
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_REASON_' . $log, false, array($reason_row['reason_title']));
|
||||
trigger_error($user->lang['REASON_' . $log] . adm_back_link($this->u_action));
|
||||
}
|
||||
}
|
||||
else if ($reason_id)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . REPORTS_REASONS_TABLE . '
|
||||
WHERE reason_id = ' . $reason_id;
|
||||
$result = $db->sql_query($sql);
|
||||
$reason_row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (!$reason_row)
|
||||
{
|
||||
trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
$l_title = ($action == 'edit') ? 'EDIT' : 'ADD';
|
||||
|
||||
$translated = false;
|
||||
|
||||
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
|
||||
if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])]))
|
||||
{
|
||||
$translated = true;
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'L_TITLE' => $user->lang['REASON_' . $l_title],
|
||||
'U_ACTION' => $this->u_action . "&id=$reason_id&action=$action",
|
||||
'U_BACK' => $this->u_action,
|
||||
'ERROR_MSG' => (count($error)) ? implode('<br />', $error) : '',
|
||||
|
||||
'REASON_TITLE' => $reason_row['reason_title'],
|
||||
'REASON_DESCRIPTION' => $reason_row['reason_description'],
|
||||
|
||||
'TRANSLATED_TITLE' => ($translated) ? $user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])] : '',
|
||||
'TRANSLATED_DESCRIPTION'=> ($translated) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])] : '',
|
||||
|
||||
'S_AVAILABLE_TITLES' => implode($user->lang['COMMA_SEPARATOR'], array_map('htmlspecialchars', array_keys($user->lang['report_reasons']['TITLE']))),
|
||||
'S_EDIT_REASON' => true,
|
||||
'S_TRANSLATED' => $translated,
|
||||
'S_ERROR' => (count($error)) ? true : false,
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
|
||||
$sql = 'SELECT *
|
||||
FROM ' . REPORTS_REASONS_TABLE . '
|
||||
WHERE reason_id = ' . $reason_id;
|
||||
$result = $db->sql_query($sql);
|
||||
$reason_row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (!$reason_row)
|
||||
{
|
||||
trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if (strtolower($reason_row['reason_title']) == 'other')
|
||||
{
|
||||
trigger_error($user->lang['NO_REMOVE_DEFAULT_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
// Let the deletion be confirmed...
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$sql = 'SELECT reason_id
|
||||
FROM ' . REPORTS_REASONS_TABLE . "
|
||||
WHERE LOWER(reason_title) = 'other'";
|
||||
$result = $db->sql_query($sql);
|
||||
$other_reason_id = (int) $db->sql_fetchfield('reason_id');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
switch ($db->get_sql_layer())
|
||||
{
|
||||
// The ugly one!
|
||||
case 'mysqli':
|
||||
case 'mysql4':
|
||||
case 'mysql':
|
||||
// Change the reports using this reason to 'other'
|
||||
$sql = 'UPDATE ' . REPORTS_TABLE . '
|
||||
SET reason_id = ' . $other_reason_id . ", report_text = CONCAT('" . $db->sql_escape($reason_row['reason_description']) . "\n\n', report_text)
|
||||
WHERE reason_id = $reason_id";
|
||||
break;
|
||||
|
||||
// Standard? What's that?
|
||||
case 'mssql_odbc':
|
||||
case 'mssqlnative':
|
||||
// Change the reports using this reason to 'other'
|
||||
$sql = "DECLARE @ptrval binary(16)
|
||||
|
||||
SELECT @ptrval = TEXTPTR(report_text)
|
||||
FROM " . REPORTS_TABLE . "
|
||||
WHERE reason_id = " . $reason_id . "
|
||||
|
||||
UPDATETEXT " . REPORTS_TABLE . ".report_text @ptrval 0 0 '" . $db->sql_escape($reason_row['reason_description']) . "\n\n'
|
||||
|
||||
UPDATE " . REPORTS_TABLE . '
|
||||
SET reason_id = ' . $other_reason_id . "
|
||||
WHERE reason_id = $reason_id";
|
||||
break;
|
||||
|
||||
// Teh standard
|
||||
case 'postgres':
|
||||
case 'oracle':
|
||||
case 'sqlite3':
|
||||
// Change the reports using this reason to 'other'
|
||||
$sql = 'UPDATE ' . REPORTS_TABLE . '
|
||||
SET reason_id = ' . $other_reason_id . ", report_text = '" . $db->sql_escape($reason_row['reason_description']) . "\n\n' || report_text
|
||||
WHERE reason_id = $reason_id";
|
||||
break;
|
||||
}
|
||||
$db->sql_query($sql);
|
||||
|
||||
$db->sql_query('DELETE FROM ' . REPORTS_REASONS_TABLE . ' WHERE reason_id = ' . $reason_id);
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_REASON_REMOVED', false, array($reason_row['reason_title']));
|
||||
trigger_error($user->lang['REASON_REMOVED'] . adm_back_link($this->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
|
||||
'i' => $id,
|
||||
'mode' => $mode,
|
||||
'action' => $action,
|
||||
'id' => $reason_id))
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'move_up':
|
||||
case 'move_down':
|
||||
|
||||
if (!check_link_hash($request->variable('hash', ''), 'acp_reasons'))
|
||||
{
|
||||
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$sql = 'SELECT reason_order
|
||||
FROM ' . REPORTS_REASONS_TABLE . "
|
||||
WHERE reason_id = $reason_id";
|
||||
$result = $db->sql_query($sql);
|
||||
$order = $db->sql_fetchfield('reason_order');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if ($order === false || ($order == 0 && $action == 'move_up'))
|
||||
{
|
||||
break;
|
||||
}
|
||||
$order = (int) $order;
|
||||
$order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
|
||||
|
||||
$sql = 'UPDATE ' . REPORTS_REASONS_TABLE . '
|
||||
SET reason_order = ' . $order_total . ' - reason_order
|
||||
WHERE reason_order IN (' . $order . ', ' . (($action == 'move_up') ? $order - 1 : $order + 1) . ')';
|
||||
$db->sql_query($sql);
|
||||
|
||||
if ($request->is_ajax())
|
||||
{
|
||||
$json_response = new \phpbb\json_response;
|
||||
$json_response->send(array(
|
||||
'success' => (bool) $db->sql_affectedrows(),
|
||||
));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// By default, check that order is valid and fix it if necessary
|
||||
$sql = 'SELECT reason_id, reason_order
|
||||
FROM ' . REPORTS_REASONS_TABLE . '
|
||||
ORDER BY reason_order';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$order = 0;
|
||||
do
|
||||
{
|
||||
++$order;
|
||||
|
||||
if ($row['reason_order'] != $order)
|
||||
{
|
||||
$sql = 'UPDATE ' . REPORTS_REASONS_TABLE . "
|
||||
SET reason_order = $order
|
||||
WHERE reason_id = {$row['reason_id']}";
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_ACTION' => $this->u_action,
|
||||
)
|
||||
);
|
||||
|
||||
// Reason count
|
||||
$sql = 'SELECT reason_id, COUNT(reason_id) AS reason_count
|
||||
FROM ' . REPORTS_TABLE . '
|
||||
GROUP BY reason_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$reason_count = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$reason_count[$row['reason_id']] = $row['reason_count'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql = 'SELECT *
|
||||
FROM ' . REPORTS_REASONS_TABLE . '
|
||||
ORDER BY reason_order ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$translated = false;
|
||||
$other_reason = ($row['reason_title'] == 'other') ? true : false;
|
||||
|
||||
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
|
||||
if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
|
||||
{
|
||||
$row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
|
||||
$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
|
||||
|
||||
$translated = true;
|
||||
}
|
||||
|
||||
$template->assign_block_vars('reasons', array(
|
||||
'REASON_TITLE' => $row['reason_title'],
|
||||
'REASON_DESCRIPTION' => $row['reason_description'],
|
||||
'REASON_COUNT' => (isset($reason_count[$row['reason_id']])) ? $reason_count[$row['reason_id']] : 0,
|
||||
|
||||
'S_TRANSLATED' => $translated,
|
||||
'S_OTHER_REASON' => $other_reason,
|
||||
|
||||
'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['reason_id'],
|
||||
'U_DELETE' => (!$other_reason) ? $this->u_action . '&action=delete&id=' . $row['reason_id'] : '',
|
||||
'U_MOVE_UP' => $this->u_action . '&action=move_up&id=' . $row['reason_id'] . '&hash=' . generate_link_hash('acp_reasons'),
|
||||
'U_MOVE_DOWN' => $this->u_action . '&action=move_down&id=' . $row['reason_id'] . '&hash=' . generate_link_hash('acp_reasons'))
|
||||
);
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
1373
install/update/old/includes/acp/acp_styles.php
Normal file
1373
install/update/old/includes/acp/acp_styles.php
Normal file
File diff suppressed because it is too large
Load Diff
86
install/update/old/includes/acp/acp_update.php
Normal file
86
install/update/old/includes/acp/acp_update.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class acp_update
|
||||
{
|
||||
var $u_action;
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $config, $user, $template, $request;
|
||||
global $phpbb_root_path, $phpEx, $phpbb_container;
|
||||
|
||||
$user->add_lang('install');
|
||||
|
||||
$this->tpl_name = 'acp_update';
|
||||
$this->page_title = 'ACP_VERSION_CHECK';
|
||||
|
||||
/* @var $version_helper \phpbb\version_helper */
|
||||
$version_helper = $phpbb_container->get('version_helper');
|
||||
try
|
||||
{
|
||||
$recheck = $request->variable('versioncheck_force', false);
|
||||
$updates_available = $version_helper->get_update_on_branch($recheck);
|
||||
$upgrades_available = $version_helper->get_suggested_updates();
|
||||
if (!empty($upgrades_available))
|
||||
{
|
||||
$upgrades_available = array_pop($upgrades_available);
|
||||
}
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
$template->assign_var('S_VERSIONCHECK_FAIL', true);
|
||||
|
||||
$updates_available = array();
|
||||
}
|
||||
|
||||
if (!empty($updates_available))
|
||||
{
|
||||
$template->assign_block_vars('updates_available', $updates_available);
|
||||
}
|
||||
|
||||
$update_link = $phpbb_root_path . 'install/app.' . $phpEx;
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_UP_TO_DATE' => empty($updates_available),
|
||||
'U_ACTION' => $this->u_action,
|
||||
'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&versioncheck_force=1'),
|
||||
|
||||
'CURRENT_VERSION' => $config['version'],
|
||||
|
||||
'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $update_link),
|
||||
'S_VERSION_UPGRADEABLE' => !empty($upgrades_available),
|
||||
'UPGRADE_INSTRUCTIONS' => !empty($upgrades_available) ? $user->lang('UPGRADE_INSTRUCTIONS', $upgrades_available['current'], $upgrades_available['announcement']) : false,
|
||||
));
|
||||
|
||||
// Incomplete update?
|
||||
if (phpbb_version_compare($config['version'], PHPBB_VERSION, '<'))
|
||||
{
|
||||
$database_update_link = $phpbb_root_path . 'install/app.php/update';
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_UPDATE_INCOMPLETE' => true,
|
||||
'FILES_VERSION' => PHPBB_VERSION,
|
||||
'INCOMPLETE_INSTRUCTIONS' => $user->lang('UPDATE_INCOMPLETE_EXPLAIN', $database_update_link),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
2692
install/update/old/includes/acp/acp_users.php
Normal file
2692
install/update/old/includes/acp/acp_users.php
Normal file
File diff suppressed because it is too large
Load Diff
1323
install/update/old/includes/acp/auth.php
Normal file
1323
install/update/old/includes/acp/auth.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user