aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2005-10-09 17:59:27 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2005-10-09 17:59:27 +0000
commit0513ef4d17e32c8be1fec6615918e6d694667738 (patch)
treef7aad03713f11023643d7c6fb7192b5b96a1ffe2 /phpBB/includes
parent9732b0deb29ed149c4e9b602fc7d16ac721389a6 (diff)
downloadforums-0513ef4d17e32c8be1fec6615918e6d694667738.tar
forums-0513ef4d17e32c8be1fec6615918e6d694667738.tar.gz
forums-0513ef4d17e32c8be1fec6615918e6d694667738.tar.bz2
forums-0513ef4d17e32c8be1fec6615918e6d694667738.tar.xz
forums-0513ef4d17e32c8be1fec6615918e6d694667738.zip
- 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
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/db/dbal.php12
-rw-r--r--phpBB/includes/functions.php1
-rw-r--r--phpBB/includes/functions_admin.php5
-rw-r--r--phpBB/includes/functions_module.php138
-rw-r--r--phpBB/includes/functions_user.php2
-rw-r--r--phpBB/includes/message_parser.php1
-rw-r--r--phpBB/includes/template.php13
-rw-r--r--phpBB/includes/ucp/ucp_zebra.php1
8 files changed, 138 insertions, 35 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index caa6f70a00..4aaaa62790 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -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')
{
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index d4bc58aa16..4daab71c90 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -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;
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 9668b9f44a..7fb8148726 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -892,7 +892,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
$db->sql_query($sql);
unset($topic_id_ary);
}
- $db->sql_freeresult($result);
+ $db->sql_freeresult($result);
}
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;
diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php
index 78b6ea04c8..f40feb9415 100644
--- a/phpBB/includes/functions_module.php
+++ b/phpBB/includes/functions_module.php
@@ -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. ;)
- */
- $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);
+ 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);
+
+ $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,
+
+ 'id' => (int) $row['module_id'],
+ 'parent' => (int) $row['parent_id'],
+ 'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false,
- $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;
+ 'name' => (string) $row['module_name'],
+ 'mode' => (string) $row['module_mode'],
+
+ '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'],
- $this->module_ary[$i]['name'] = (string) $row['module_name'];
- $this->module_ary[$i]['mode'] = (string) $row['module_mode'];
+ 'left' => $row['left_id'],
+ 'right' => $row['right_id'],
+ );
- $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'];
+ $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 . '&amp;i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&amp;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 . '&amp;i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&amp;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;
}
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php
index 150a37b6b8..d868235319 100644
--- a/phpBB/includes/functions_user.php
+++ b/phpBB/includes/functions_user.php
@@ -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));
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index d97f2b731d..71cff5ce0c 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -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);
diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php
index ebd5655e6b..64994cb3cf 100644
--- a/phpBB/includes/template.php
+++ b/phpBB/includes/template.php
@@ -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)
diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php
index 908ebaff5a..ca39afc86a 100644
--- a/phpBB/includes/ucp/ucp_zebra.php
+++ b/phpBB/includes/ucp/ucp_zebra.php
@@ -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));