mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
- added new query type to dbal's sql_build_array
- allow setting custom template path - adjusted module class to correctly parse trees with more than one category - added caching to module class git-svn-id: file:///svn/phpbb/trunk@5268 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
9732b0deb2
commit
0513ef4d17
11 changed files with 142 additions and 47 deletions
|
@ -28,6 +28,7 @@ class dbal
|
|||
var $sql_report = '';
|
||||
var $cache_num_queries = 0;
|
||||
|
||||
var $dbname = '';
|
||||
|
||||
/**
|
||||
* return on error or display error message
|
||||
|
@ -99,6 +100,7 @@ class dbal
|
|||
* Build sql statement from array for insert/update/select statements
|
||||
*
|
||||
* Idea for this from Ikonboard
|
||||
* Possible query values: INSERT, INSERT_SELECT, MULTI_INSERT, UPDATE, SELECT
|
||||
*/
|
||||
function sql_build_array($query, $assoc_ary = false)
|
||||
{
|
||||
|
@ -109,7 +111,7 @@ class dbal
|
|||
|
||||
$fields = array();
|
||||
$values = array();
|
||||
if ($query == 'INSERT')
|
||||
if ($query == 'INSERT' || $query == 'INSERT_SELECT')
|
||||
{
|
||||
foreach ($assoc_ary as $key => $var)
|
||||
{
|
||||
|
@ -119,17 +121,21 @@ class dbal
|
|||
{
|
||||
$values[] = 'NULL';
|
||||
}
|
||||
elseif (is_string($var))
|
||||
else if (is_string($var))
|
||||
{
|
||||
$values[] = "'" . $this->sql_escape($var) . "'";
|
||||
}
|
||||
else if (is_array($var) && is_string($var[0]))
|
||||
{
|
||||
$values[] = $var[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$values[] = (is_bool($var)) ? intval($var) : $var;
|
||||
}
|
||||
}
|
||||
|
||||
$query = ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')';
|
||||
$query = ($query == 'INSERT') ? ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')' : ' (' . implode(', ', $fields) . ') SELECT ' . implode(', ', $values) . ' ';
|
||||
}
|
||||
else if ($query == 'MULTI_INSERT')
|
||||
{
|
||||
|
|
|
@ -542,6 +542,7 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql .= (($sql != '') ? ' UNION ALL ' : '') . ' SELECT ' . $user->data['user_id'] . ", $forum_id, $current_time";
|
||||
break;
|
||||
|
|
|
@ -1764,6 +1764,7 @@ function cache_moderators()
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql = 'INSERT INTO ' . MODERATOR_TABLE . ' (forum_id, user_id, username, group_id, groupname)
|
||||
' . implode(' UNION ALL ', preg_replace('#^(.*)$#', 'SELECT \1', $m_sql));
|
||||
|
@ -2081,6 +2082,7 @@ if (class_exists('auth'))
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql = implode(' UNION ALL ', preg_replace('#^(.*?)$#', 'SELECT \1', $sql_subary));
|
||||
break;
|
||||
|
@ -2224,6 +2226,7 @@ if (class_exists('auth'))
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql .= (($sql != '') ? ' UNION ALL ' : '') . " SELECT '$option', " . $type_sql[$type];
|
||||
break;
|
||||
|
|
|
@ -47,7 +47,10 @@ class p_master
|
|||
global $auth, $db, $user;
|
||||
global $config, $phpbb_root_path, $phpEx;
|
||||
|
||||
$active = $category = false;
|
||||
$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));
|
||||
|
@ -55,22 +58,52 @@ class p_master
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo cache, see above. ;)
|
||||
*/
|
||||
if ($get_cache_data)
|
||||
{
|
||||
global $cache;
|
||||
|
||||
// Get active modules
|
||||
$sql = 'SELECT *
|
||||
FROM ' . MODULES_TABLE . "
|
||||
WHERE module_class = '" . $db->sql_escape($p_class) . "'
|
||||
AND module_enabled = 1
|
||||
ORDER BY left_id ASC";
|
||||
$result = $db->sql_query($sql, 3600);
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$this->module_cache['modules'] = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$this->module_cache['modules'][] = $row;
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// Get module parents
|
||||
$this->module_cache['parents'] = array();
|
||||
foreach ($this->module_cache['modules'] as $row)
|
||||
{
|
||||
$this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id']);
|
||||
}
|
||||
|
||||
$file = '<?php $this->module_cache=' . $cache->format_array($this->module_cache) . "; ?>";
|
||||
|
||||
if ($fp = @fopen($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx, 'wb'))
|
||||
{
|
||||
@flock($fp, LOCK_EX);
|
||||
fwrite($fp, $file);
|
||||
@flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
unset($file);
|
||||
}
|
||||
|
||||
$right = $depth = $i = 0;
|
||||
$depth_ary = array();
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
foreach ($this->module_cache['modules'] as $row)
|
||||
{
|
||||
// Authorisation is required ... not authed, skip
|
||||
if ($row['module_auth'])
|
||||
|
@ -108,21 +141,29 @@ class p_master
|
|||
|
||||
$right = $row['right_id'];
|
||||
|
||||
$this->module_ary[$i]['depth'] = $depth;
|
||||
$module_data = array(
|
||||
'depth' => $depth,
|
||||
|
||||
$this->module_ary[$i]['id'] = (int) $row['module_id'];
|
||||
$this->module_ary[$i]['parent'] = (int) $row['parent_id'];
|
||||
$this->module_ary[$i]['cat'] = ($row['right_id'] > $row['left_id'] + 1) ? true : false;
|
||||
'id' => (int) $row['module_id'],
|
||||
'parent' => (int) $row['parent_id'],
|
||||
'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false,
|
||||
|
||||
$this->module_ary[$i]['name'] = (string) $row['module_name'];
|
||||
$this->module_ary[$i]['mode'] = (string) $row['module_mode'];
|
||||
'name' => (string) $row['module_name'],
|
||||
'mode' => (string) $row['module_mode'],
|
||||
|
||||
$this->module_ary[$i]['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']] : ucfirst(str_replace('_', ' ', strtolower($row['module_langname']))));
|
||||
$this->module_ary[$i]['langname'] = $row['module_langname'];
|
||||
'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']] : ucfirst(str_replace('_', ' ', strtolower($row['module_langname'])))),
|
||||
'langname' => $row['module_langname'],
|
||||
|
||||
'left' => $row['left_id'],
|
||||
'right' => $row['right_id'],
|
||||
);
|
||||
|
||||
$this->module_ary[$i] = $module_data;
|
||||
|
||||
$i++;
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
unset($this->module_cache['modules']);
|
||||
}
|
||||
|
||||
function set_active($id = false, $mode = false)
|
||||
|
@ -145,15 +186,18 @@ class p_master
|
|||
$this->p_parent = $itep_ary['parent'];
|
||||
$this->p_name = $itep_ary['name'];
|
||||
$this->p_mode = $itep_ary['mode'];
|
||||
$this->p_left = $itep_ary['left'];
|
||||
$this->p_right = $itep_ary['right'];
|
||||
|
||||
$this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id];
|
||||
|
||||
break;
|
||||
}
|
||||
else if ($itep_ary['cat'] && $itep_ary['id'] == $id)
|
||||
else if (($itep_ary['cat'] && $itep_ary['id'] == $id) || ($itep_ary['parent'] === $category && $itep_ary['cat']))
|
||||
{
|
||||
$category = $itep_ary['id'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,9 +246,37 @@ class p_master
|
|||
}
|
||||
}
|
||||
|
||||
function get_parents($parent_id, $left_id, $right_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$parents = array();
|
||||
|
||||
if ($parent_id > 0)
|
||||
{
|
||||
$sql = 'SELECT module_id, parent_id
|
||||
FROM ' . MODULES_TABLE . '
|
||||
WHERE left_id < ' . $left_id . '
|
||||
AND right_id > ' . $right_id . '
|
||||
ORDER BY left_id ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$parents = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$parents[$row['module_id']] = $row['parent_id'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
return $parents;
|
||||
}
|
||||
|
||||
function assign_tpl_vars($module_url)
|
||||
{
|
||||
global $template;
|
||||
global $template, $db;
|
||||
|
||||
$parents = $this->module_cache['parents'];
|
||||
|
||||
$current_padding = $current_depth = 0;
|
||||
$linear_offset = 'l_block1';
|
||||
|
@ -233,22 +305,26 @@ class p_master
|
|||
}
|
||||
|
||||
// Only output a categories items if it's currently selected
|
||||
if (!$depth || ($depth && $itep_ary['parent'] == $this->p_parent))
|
||||
if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($parents)) || $itep_ary['parent'] == $this->p_parent)))
|
||||
{
|
||||
$use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset;
|
||||
|
||||
$template->assign_block_vars($use_tabular_offset, array(
|
||||
$tpl_ary = array(
|
||||
'L_TITLE' => $itep_ary['lang'],
|
||||
'S_SELECTED' => ($itep_ary['id'] == $this->p_parent || $itep_ary['id'] == $this->p_id) ? true : false,
|
||||
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($parents)) || $itep_ary['id'] == $this->p_id) ? true : false,
|
||||
'U_TITLE' => $module_url . '&i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&mode=' . $itep_ary['mode'])
|
||||
));
|
||||
);
|
||||
|
||||
$template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($itep_ary, CASE_UPPER)));
|
||||
}
|
||||
|
||||
$template->assign_block_vars($linear_offset, array(
|
||||
$tpl_ary = array(
|
||||
'L_TITLE' => $itep_ary['lang'],
|
||||
'S_SELECTED' => ($itep_ary['id'] == $this->p_parent || $itep_ary['id'] == $this->p_id) ? true : false,
|
||||
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($parents)) || $itep_ary['id'] == $this->p_id) ? true : false,
|
||||
'U_TITLE' => $module_url . '&i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&mode=' . $itep_ary['mode'])
|
||||
));
|
||||
);
|
||||
|
||||
$template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($itep_ary, CASE_UPPER)));
|
||||
|
||||
$current_depth = $depth;
|
||||
}
|
||||
|
|
|
@ -504,6 +504,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql .= (($sql != '') ? ' UNION ALL ' : '') . " SELECT $ban_entry, $current_time, $ban_end, $ban_exclude, '" . $db->sql_escape($ban_reason) . "'";
|
||||
break;
|
||||
|
@ -1266,6 +1267,7 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false,
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader, user_pending)
|
||||
VALUES " . implode(', ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id, $leader, $pending)", $add_id_ary));
|
||||
|
|
|
@ -1389,6 +1389,7 @@ class fulltext_search
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql = 'INSERT INTO ' . SEARCH_WORD_TABLE . ' (word_text) ' . implode(' UNION ALL ', preg_replace('#^(.*)$#', "SELECT '\$1'", $new_words));
|
||||
$db->sql_query($sql);
|
||||
|
|
|
@ -75,6 +75,19 @@ class template
|
|||
return true;
|
||||
}
|
||||
|
||||
function set_custom_template($template_path, $template_name, $static_lang = false)
|
||||
{
|
||||
global $phpbb_root_path;
|
||||
|
||||
$this->tpl = 'primary';
|
||||
$this->root = $template_path;
|
||||
$this->cachepath = $phpbb_root_path . 'cache/ctpl_' . $template_name . '_';
|
||||
|
||||
$this->static_lang = $static_lang;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sets the template filenames for handles. $filename_array
|
||||
// should be a hash of handle => filename pairs.
|
||||
function set_filenames($filename_array)
|
||||
|
|
|
@ -123,6 +123,7 @@ class ucp_zebra
|
|||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'sqlite':
|
||||
$sql = 'INSERT INTO ' . ZEBRA_TABLE . " (user_id, zebra_id, $sql_mode)
|
||||
VALUES " . implode(' UNION ALL ', preg_replace('#^([0-9]+)$#', '(' . $user->data['user_id'] . ", \\1, 1)", $user_id_ary));
|
||||
|
|
|
@ -35,13 +35,14 @@ $lang += array(
|
|||
'NO_ADMIN' => 'You are not authorised to administer this board.',
|
||||
'NO_FRAMES' => 'Sorry, your browser does not support frames.',
|
||||
|
||||
'ADMIN_TITLE' => 'Administration Panel',
|
||||
'ADMIN_PANEL' => 'Administration Control Panel',
|
||||
'ADMIN' => 'Administration',
|
||||
|
||||
'RETURN_TO' => 'Return to ...',
|
||||
'FORUM_INDEX' => 'Forum Index',
|
||||
'ADMIN_INDEX' => 'Admin Index',
|
||||
|
||||
'ACP_MAIN' => 'Admin index',
|
||||
'ACP_INDEX' => 'Admin index',
|
||||
|
||||
'ACP_CAT_GENERAL' => 'General',
|
||||
|
@ -54,7 +55,7 @@ $lang += array(
|
|||
'ACP_CAT_USERGROUP' => 'Users & Groups',
|
||||
'ACP_USERS_MANAGE' => 'Edit user data',
|
||||
|
||||
|
||||
'LOGGED_IN_AS' => 'You are logged in as:',
|
||||
|
||||
'DB_CAT' => 'Database',
|
||||
'DB_BACKUP' => 'Backup Database',
|
||||
|
|
|
@ -201,6 +201,7 @@ $lang += array(
|
|||
'LOGIN_FORUM' => 'To view or post in this forum you must enter a password.',
|
||||
'LOGIN_INFO' => 'In order to login you must be registered. Registering takes only a few seconds but gives you increased capabilies. The board administrator may also grant additional permissions to registered users. Before you login please ensure you are familiar with our terms of use and related policies. Please ensure you read any forum rules as you navigate around the board.',
|
||||
'LOGIN_VIEWFORUM' => 'The board administrator requires you to be registered and logged in to view this forum.',
|
||||
'LOGOUT' => 'Logout',
|
||||
'LOGOUT_USER' => 'Logout [ %s ]',
|
||||
'LOG_ADMIN_AUTH_FAIL' => '<b>Failed administration login attempt</b>',
|
||||
'LOG_ADMIN_AUTH_SUCCESS'=> '<b>Sucessful administration login</b>',
|
||||
|
|
|
@ -214,14 +214,4 @@ $template->set_filenames(array(
|
|||
|
||||
page_footer();
|
||||
|
||||
/* Language override function for 'main' module
|
||||
function main($mode, $langname)
|
||||
{
|
||||
if ($mode == 'front')
|
||||
{
|
||||
return 'Frontpanel';
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue