mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
The MCP strikes back.... :-)
git-svn-id: file:///svn/phpbb/trunk@5300 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
2b96a90d44
commit
ed8edf3b8f
2 changed files with 161 additions and 246 deletions
|
@ -310,7 +310,7 @@ class p_master
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$u_title = $module_url . '&i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&mode=' . $itep_ary['mode']);
|
$u_title = $module_url . '&i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&mode=' . $itep_ary['mode'] . $itep_ary['url_extra']);
|
||||||
|
|
||||||
// Only output a categories items if it's currently selected
|
// Only output a categories items if it's currently selected
|
||||||
if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($this->module_cache['parents'])) || $itep_ary['parent'] == $this->p_parent)))
|
if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($this->module_cache['parents'])) || $itep_ary['parent'] == $this->p_parent)))
|
||||||
|
|
367
phpBB/mcp.php
367
phpBB/mcp.php
|
@ -16,267 +16,168 @@ $phpbb_root_path = './';
|
||||||
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
||||||
include($phpbb_root_path . 'common.'.$phpEx);
|
include($phpbb_root_path . 'common.'.$phpEx);
|
||||||
include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
|
include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
|
||||||
|
require($phpbb_root_path . 'includes/functions_module.'.$phpEx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package mcp
|
* @package mcp
|
||||||
* MCP Module
|
* MCP Module
|
||||||
*/
|
*/
|
||||||
class module
|
class mcp extends p_master
|
||||||
{
|
{
|
||||||
var $id = 0;
|
/**
|
||||||
var $type;
|
* List modules
|
||||||
var $name;
|
*
|
||||||
var $mode;
|
* This creates a list, stored in $this->module_ary of all available
|
||||||
var $url;
|
* modules for the given class (ucp, mcp and acp). Additionally
|
||||||
|
* $this->module_y_ary is created with indentation information for
|
||||||
// Private methods, should not be overwritten
|
* displaying the module list appropriately. Only modules for which
|
||||||
function create($module_type, $module_url, $post_id, $topic_id, $forum_id, $selected_mod = false, $selected_submod = false)
|
* the user has access rights are included in these lists.
|
||||||
|
*
|
||||||
|
* The mcp performs additional checks on the modules loaded to ensure
|
||||||
|
* that only relevant links are presented
|
||||||
|
*
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
function list_modules($p_class, $forum_id = 0, $topic_id = 0, $post_id = 0)
|
||||||
{
|
{
|
||||||
global $template, $auth, $db, $user, $config;
|
global $auth, $db, $user;
|
||||||
global $phpbb_root_path, $phpEx;
|
global $config, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
$sql = 'SELECT module_id, module_title, module_filename, module_subs, module_acl
|
$get_cache_data = true;
|
||||||
|
|
||||||
|
// Empty cached contents
|
||||||
|
$this->module_cache = array();
|
||||||
|
|
||||||
|
// Sanitise for future path use, it's escaped as appropriate for queries
|
||||||
|
$this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class));
|
||||||
|
|
||||||
|
if (file_exists($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx))
|
||||||
|
{
|
||||||
|
include($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx);
|
||||||
|
$get_cache_data = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($get_cache_data)
|
||||||
|
{
|
||||||
|
global $cache;
|
||||||
|
|
||||||
|
// Get active modules
|
||||||
|
$sql = 'SELECT *
|
||||||
FROM ' . MODULES_TABLE . "
|
FROM ' . MODULES_TABLE . "
|
||||||
WHERE module_type = '{$module_type}'
|
WHERE module_class = '" . $db->sql_escape($p_class) . "'
|
||||||
AND module_enabled = 1
|
AND module_enabled = 1
|
||||||
ORDER BY module_order ASC";
|
ORDER BY left_id ASC";
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
$i = 0;
|
$this->module_cache['modules'] = array();
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
// Authorisation is required for the basic module
|
$this->module_cache['modules'][] = $row;
|
||||||
if ($row['module_acl'])
|
|
||||||
{
|
|
||||||
$is_auth = false;
|
|
||||||
eval('$is_auth = (' . preg_replace(array('#acl_([a-z_]+)#e', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1", ' . $forum_id . ')', '(int) $config["\\1"]'), trim($row['module_acl'])) . ');');
|
|
||||||
|
|
||||||
// The user is not authorised to use this module, skip it
|
|
||||||
if (!$is_auth)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$selected = ($row['module_filename'] == $selected_mod || $row['module_id'] == $selected_mod || (!$selected_mod && !$i)) ? true : false;
|
|
||||||
|
|
||||||
// Get the localised lang string if available, or make up our own otherwise
|
|
||||||
$module_lang = strtoupper($module_type) . '_' . $row['module_title'];
|
|
||||||
$template->assign_block_vars($module_type . '_section', array(
|
|
||||||
'L_TITLE' => (isset($user->lang[$module_lang])) ? $user->lang[$module_lang] : ucfirst(str_replace('_', ' ', strtolower($row['module_title']))),
|
|
||||||
'S_SELECTED' => $selected,
|
|
||||||
'U_TITLE' => $module_url . '&i=' . $row['module_id'])
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($selected)
|
|
||||||
{
|
|
||||||
$module_id = $row['module_id'];
|
|
||||||
$module_name = $row['module_filename'];
|
|
||||||
|
|
||||||
if ($row['module_subs'])
|
|
||||||
{
|
|
||||||
$j = 0;
|
|
||||||
$submodules_ary = explode("\n", $row['module_subs']);
|
|
||||||
foreach ($submodules_ary as $submodule)
|
|
||||||
{
|
|
||||||
if (!trim($submodule))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$submodule = explode(',', trim($submodule));
|
|
||||||
$submodule_title = array_shift($submodule);
|
|
||||||
|
|
||||||
$is_auth = true;
|
|
||||||
foreach ($submodule as $auth_option)
|
|
||||||
{
|
|
||||||
eval('$is_auth = (' . preg_replace(array('#acl_([a-z_]+)#e', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1", ' . $forum_id . ')', '(int) $config["\\1"]'), trim($auth_option)) . ');');
|
|
||||||
|
|
||||||
if (!$is_auth)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$is_auth)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only show those rows we are able to access
|
|
||||||
if (($submodule_title == 'post_details' && !$post_id) ||
|
|
||||||
($submodule_title == 'topic_view' && !$topic_id) ||
|
|
||||||
($submodule_title == 'forum_view' && !$forum_id))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$suffix = ($post_id) ? "&p=$post_id" : '';
|
|
||||||
$suffix .= ($topic_id) ? "&t=$topic_id" : '';
|
|
||||||
$suffix .= ($forum_id) ? "&f=$forum_id" : '';
|
|
||||||
|
|
||||||
$selected = ($submodule_title == $selected_submod || (!$selected_submod && !$j)) ? true : false;
|
|
||||||
|
|
||||||
// Get the localised lang string if available, or make up our own otherwise
|
|
||||||
$module_lang = strtoupper($module_type . '_' . $module_name . '_' . $submodule_title);
|
|
||||||
|
|
||||||
$template->assign_block_vars("{$module_type}_section.{$module_type}_subsection", array(
|
|
||||||
'L_TITLE' => (isset($user->lang[$module_lang])) ? $user->lang[$module_lang] : ucfirst(str_replace('_', ' ', strtolower($module_lang))),
|
|
||||||
'S_SELECTED' => $selected,
|
|
||||||
'ADD_ITEM' => $this->add_menu_item($row['module_filename'], $submodule_title),
|
|
||||||
'U_TITLE' => $module_url . '&i=' . $module_id . '&mode=' . $submodule_title . $suffix)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($selected)
|
|
||||||
{
|
|
||||||
$this->mode = $submodule_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
$j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
if (!$module_id)
|
// Get module parents
|
||||||
|
$this->module_cache['parents'] = array();
|
||||||
|
foreach ($this->module_cache['modules'] as $row)
|
||||||
{
|
{
|
||||||
trigger_error('MODULE_NOT_EXIST');
|
$this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->type = $module_type;
|
$file = '<?php $this->module_cache=' . $cache->format_array($this->module_cache) . "; ?>";
|
||||||
$this->id = $module_id;
|
|
||||||
$this->name = $module_name;
|
if ($fp = @fopen($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx, 'wb'))
|
||||||
$this->url = "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}";
|
{
|
||||||
$this->url .= ($post_id) ? "&p=$post_id" : '';
|
@flock($fp, LOCK_EX);
|
||||||
$this->url .= ($topic_id) ? "&t=$topic_id" : '';
|
fwrite($fp, $file);
|
||||||
$this->url .= ($forum_id) ? "&f=$forum_id" : '';
|
@flock($fp, LOCK_UN);
|
||||||
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
function load($type = false, $name = false, $mode = false, $run = true)
|
unset($file);
|
||||||
{
|
|
||||||
global $phpbb_root_path, $phpEx;
|
|
||||||
|
|
||||||
if ($type)
|
|
||||||
{
|
|
||||||
$this->type = $type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($name)
|
$right = $depth = $i = 0;
|
||||||
{
|
$depth_ary = array();
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!class_exists($this->type . '_' . $this->name))
|
foreach ($this->module_cache['modules'] as $row)
|
||||||
{
|
{
|
||||||
require_once($phpbb_root_path . "includes/{$this->type}/{$this->type}_{$this->name}.$phpEx");
|
/**
|
||||||
|
* Authorisation is required ... not authed, skip
|
||||||
if ($run)
|
* @todo implement $this->is_module_id
|
||||||
|
* @todo put in seperate method for authentication
|
||||||
|
*/
|
||||||
|
if ($row['module_auth'])
|
||||||
{
|
{
|
||||||
if (!isset($this->mode))
|
$is_auth = false;
|
||||||
|
eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z_]+)(,\$id)?#e', '#\$id#', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1"\\2)', '$this->acl_forup_id', '(int) $config["\\1"]'), trim($row['module_auth'])) . ');');
|
||||||
|
if (!$is_auth)
|
||||||
{
|
{
|
||||||
$this->mode = $mode;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
eval("\$this->module = new {$this->type}_{$this->name}(\$this->id, \$this->mode, \$this->url);");
|
|
||||||
if (method_exists($this->module, 'init'))
|
|
||||||
{
|
|
||||||
$this->module->init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Displays the appropriate template with the given title
|
// Category with no members, ignore
|
||||||
function display($page_title, $tpl_name)
|
if (!$row['module_name'] && ($row['left_id'] + 1 == $row['right_id']))
|
||||||
{
|
{
|
||||||
global $template;
|
continue;
|
||||||
|
|
||||||
page_header($page_title);
|
|
||||||
|
|
||||||
$template->set_filenames(array(
|
|
||||||
'body' => $tpl_name)
|
|
||||||
);
|
|
||||||
|
|
||||||
page_footer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Item to Submodule Title
|
// Ignore those rows we don't have enough information to access
|
||||||
function add_menu_item($module_name, $mode)
|
if (($row['module_mode'] == 'post_details' && !$post_id) ||
|
||||||
|
($row['module_mode'] == 'topic_view' && !$topic_id) ||
|
||||||
|
($row['module_mode'] == 'forum_view' && !$forum_id))
|
||||||
{
|
{
|
||||||
global $db, $user, $auth;
|
continue;
|
||||||
|
|
||||||
if ($module_name != 'queue')
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$forum_id = request_var('f', 0);
|
$url_extra = '';
|
||||||
if ($forum_id && $auth->acl_get('m_approve', $forum_id))
|
$url_extra .= ($forum_id) ? "&f=$forum_id" : '';
|
||||||
|
$url_extra .= ($topic_id) ? "&t=$topic_id" : '';
|
||||||
|
$url_extra .= ($post_id) ? "&p=$post_id" : '';
|
||||||
|
|
||||||
|
if ($row['left_id'] < $right)
|
||||||
{
|
{
|
||||||
$forum_list = array($forum_id);
|
$depth++;
|
||||||
|
$depth_ary[$row['parent_id']] = $depth;
|
||||||
|
}
|
||||||
|
else if ($row['left_id'] > $right + 1)
|
||||||
|
{
|
||||||
|
if (!isset($depth_ary[$row['parent_id']]))
|
||||||
|
{
|
||||||
|
$depth = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$forum_list = get_forum_list('m_approve');
|
$depth = $depth_ary[$row['parent_id']];
|
||||||
}
|
|
||||||
|
|
||||||
switch ($mode)
|
|
||||||
{
|
|
||||||
case 'unapproved_topics':
|
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*) AS total
|
|
||||||
FROM ' . TOPICS_TABLE . '
|
|
||||||
WHERE forum_id IN (' . implode(', ', $forum_list) . ')
|
|
||||||
AND topic_approved = 0';
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
$total_topics = $db->sql_fetchfield('total', 0, $result);
|
|
||||||
|
|
||||||
return ($total_topics) ? $total_topics : $user->lang['NONE'];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'unapproved_posts':
|
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*) AS total
|
|
||||||
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
|
|
||||||
WHERE p.forum_id IN (' . implode(', ', $forum_list) . ')
|
|
||||||
AND p.post_approved = 0
|
|
||||||
AND t.topic_id = p.topic_id
|
|
||||||
AND t.topic_first_post_id <> p.post_id';
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
$total_posts = $db->sql_fetchfield('total', 0, $result);
|
|
||||||
|
|
||||||
return ($total_posts) ? $total_posts : $user->lang['NONE'];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public methods to be overwritten by modules
|
$right = $row['right_id'];
|
||||||
function module()
|
|
||||||
{
|
$this->module_ary[$i] = array(
|
||||||
// Module name
|
'depth' => $depth,
|
||||||
// Module filename
|
|
||||||
// Module description
|
'id' => (int) $row['module_id'],
|
||||||
// Module version
|
'parent' => (int) $row['parent_id'],
|
||||||
// Module compatibility
|
'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false,
|
||||||
return false;
|
|
||||||
|
'name' => (string) $row['module_name'],
|
||||||
|
'mode' => (string) $row['module_mode'],
|
||||||
|
'display' => (int) $row['module_display'],
|
||||||
|
|
||||||
|
'lang' => (function_exists($row['module_name'])) ? $row['module_name']($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']),
|
||||||
|
'langname' => $row['module_langname'],
|
||||||
|
|
||||||
|
'url_extra' => $url_extra,
|
||||||
|
|
||||||
|
'left' => $row['left_id'],
|
||||||
|
'right' => $row['right_id'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init()
|
unset($this->module_cache['modules']);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function uninstall()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,12 +189,12 @@ $user->session_begin();
|
||||||
$auth->acl($user->data);
|
$auth->acl($user->data);
|
||||||
$user->setup('mcp');
|
$user->setup('mcp');
|
||||||
|
|
||||||
$mcp = new module();
|
$module = new mcp();
|
||||||
|
|
||||||
// Basic parameter data
|
// Basic parameter data
|
||||||
$mode = request_var('mode', '');
|
$mode = request_var('mode', '');
|
||||||
$mode2 = (isset($_REQUEST['quick'])) ? request_var('mode2', '') : '';
|
$mode2 = (isset($_REQUEST['quick'])) ? request_var('mode2', '') : '';
|
||||||
$module = request_var('i', '');
|
$id = request_var('i', '');
|
||||||
|
|
||||||
if (is_array($mode))
|
if (is_array($mode))
|
||||||
{
|
{
|
||||||
|
@ -310,7 +211,7 @@ if ($mode2)
|
||||||
// Make sure we are using the correct module
|
// Make sure we are using the correct module
|
||||||
if ($mode == 'approve' || $mode == 'disapprove')
|
if ($mode == 'approve' || $mode == 'disapprove')
|
||||||
{
|
{
|
||||||
$module = 'queue';
|
$id = 'queue';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only Moderators can go beyond this point
|
// Only Moderators can go beyond this point
|
||||||
|
@ -402,11 +303,26 @@ if (!$quickmod)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate module system and generate list of available modules
|
// Instantiate module system and generate list of available modules
|
||||||
$mcp->create('mcp', "mcp.$phpEx$SID", $post_id, $topic_id, $forum_id, $module, $mode);
|
$module->list_modules('mcp', $forum_id, $topic_id, $post_id);
|
||||||
|
|
||||||
|
// Select the active module
|
||||||
|
$module->set_active($id, $mode);
|
||||||
|
|
||||||
// Load and execute the relevant module
|
// Load and execute the relevant module
|
||||||
$mcp->load('mcp', false, $mode);
|
$module->load_active();
|
||||||
exit;
|
|
||||||
|
// Assign data to the template engine for the list of modules
|
||||||
|
$module->assign_tpl_vars("mcp.$phpEx$SID");
|
||||||
|
|
||||||
|
// Generate the page
|
||||||
|
page_header($user->lang['MCP_MAIN']);
|
||||||
|
|
||||||
|
$template->set_filenames(array(
|
||||||
|
'body' => $module->get_tpl_name())
|
||||||
|
);
|
||||||
|
|
||||||
|
page_footer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($mode)
|
switch ($mode)
|
||||||
|
@ -415,28 +331,27 @@ switch ($mode)
|
||||||
case 'unlock':
|
case 'unlock':
|
||||||
case 'lock_post':
|
case 'lock_post':
|
||||||
case 'unlock_post':
|
case 'unlock_post':
|
||||||
$mcp->load('mcp', 'main', $mode);
|
$module->load('mcp', 'main', $mode);
|
||||||
break;
|
break;
|
||||||
case 'make_sticky':
|
case 'make_sticky':
|
||||||
case 'make_announce':
|
case 'make_announce':
|
||||||
case 'make_global':
|
case 'make_global':
|
||||||
case 'make_normal':
|
case 'make_normal':
|
||||||
$mcp->load('mcp', 'main', $mode);
|
$module->load('mcp', 'main', $mode);
|
||||||
break;
|
break;
|
||||||
case 'fork':
|
case 'fork':
|
||||||
case 'move':
|
case 'move':
|
||||||
$mcp->load('mcp', 'main', $mode);
|
$module->load('mcp', 'main', $mode);
|
||||||
break;
|
break;
|
||||||
case 'delete_post':
|
case 'delete_post':
|
||||||
case 'delete_topic':
|
case 'delete_topic':
|
||||||
$mcp->load('mcp', 'main', $mode);
|
$module->load('mcp', 'main', $mode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
trigger_error("$mode not allowed as quickmod");
|
trigger_error("$mode not allowed as quickmod");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// LITTLE HELPER
|
// LITTLE HELPER
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue