aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/common.php17
-rw-r--r--phpBB/develop/search_fill.php2
-rw-r--r--phpBB/download/file.php340
-rw-r--r--phpBB/includes/acp/acp_forums.php158
-rw-r--r--phpBB/includes/acp/acp_search.php4
-rw-r--r--phpBB/includes/acp/acp_users.php49
-rw-r--r--phpBB/includes/cache/driver/file.php4
-rw-r--r--phpBB/includes/cache/driver/interface.php2
-rw-r--r--phpBB/includes/cache/driver/memory.php4
-rw-r--r--phpBB/includes/cache/driver/null.php2
-rw-r--r--phpBB/includes/cron/task/core/tidy_search.php4
-rw-r--r--phpBB/includes/db/dbal.php4
-rw-r--r--phpBB/includes/db/firebird.php6
-rw-r--r--phpBB/includes/db/mssql.php8
-rw-r--r--phpBB/includes/db/mssql_odbc.php6
-rw-r--r--phpBB/includes/db/mssqlnative.php7
-rw-r--r--phpBB/includes/db/mysql.php8
-rw-r--r--phpBB/includes/db/mysqli.php8
-rw-r--r--phpBB/includes/db/oracle.php8
-rw-r--r--phpBB/includes/db/postgres.php8
-rw-r--r--phpBB/includes/db/sqlite.php8
-rw-r--r--phpBB/includes/extension/controller.php21
-rw-r--r--phpBB/includes/functions.php59
-rw-r--r--phpBB/includes/functions_acp.php84
-rw-r--r--phpBB/includes/functions_admin.php4
-rw-r--r--phpBB/includes/functions_display.php149
-rw-r--r--phpBB/includes/functions_download.php129
-rw-r--r--phpBB/includes/functions_posting.php16
-rw-r--r--phpBB/includes/functions_user.php83
-rw-r--r--phpBB/includes/mcp/mcp_forum.php13
-rw-r--r--phpBB/includes/mcp/mcp_main.php2
-rw-r--r--phpBB/includes/mcp/mcp_post.php4
-rw-r--r--phpBB/includes/search/fulltext_mysql.php202
-rw-r--r--phpBB/includes/search/fulltext_native.php320
-rw-r--r--phpBB/includes/search/fulltext_postgres.php206
-rw-r--r--phpBB/includes/search/fulltext_sphinx.php123
-rw-r--r--phpBB/includes/template/template.php11
-rw-r--r--phpBB/includes/ucp/ucp_pm_viewmessage.php32
-rw-r--r--phpBB/includes/ucp/ucp_zebra.php30
-rw-r--r--phpBB/includes/user.php36
-rw-r--r--phpBB/index.php14
-rw-r--r--phpBB/install/database_update.php6
-rw-r--r--phpBB/install/install_convert.php4
-rw-r--r--phpBB/install/install_install.php4
-rw-r--r--phpBB/install/install_update.php2
-rw-r--r--phpBB/language/en/acp/common.php1
-rw-r--r--phpBB/language/en/common.php2
-rw-r--r--phpBB/language/en/search.php2
-rw-r--r--phpBB/memberlist.php37
-rw-r--r--phpBB/search.php2
-rw-r--r--phpBB/styles/prosilver/template/ucp_pm_viewfolder.html2
-rw-r--r--phpBB/styles/prosilver/template/ucp_pm_viewmessage.html24
-rw-r--r--phpBB/styles/prosilver/template/viewtopic_body.html25
-rw-r--r--phpBB/styles/prosilver/theme/content.css23
-rw-r--r--phpBB/styles/prosilver/theme/cp.css3
-rw-r--r--phpBB/ucp.php12
-rw-r--r--phpBB/viewforum.php19
-rw-r--r--phpBB/viewonline.php42
-rw-r--r--phpBB/viewtopic.php97
59 files changed, 1755 insertions, 747 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index 81fe275008..c7c5859c25 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -132,7 +132,7 @@ $phpbb_subscriber_loader->load();
// Add own hook handler
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
-$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
+$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display')));
foreach ($cache->obtain_hooks() as $hook)
{
@@ -143,3 +143,18 @@ if (!$config['use_system_cron'])
{
$cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver());
}
+
+/**
+* Main event which is triggered on every page
+*
+* You can use this event to load function files and initiate objects
+*
+* NOTE: At this point the global session ($user) and permissions ($auth)
+* do NOT exist yet. If you need to use the user object
+* (f.e. to include language files) or need to check permissions,
+* please use the core.user_setup event instead!
+*
+* @event core.common
+* @since 3.1-A1
+*/
+$phpbb_dispatcher->dispatch('core.common');
diff --git a/phpBB/develop/search_fill.php b/phpBB/develop/search_fill.php
index 4c0b607778..2a4dfb212c 100644
--- a/phpBB/develop/search_fill.php
+++ b/phpBB/develop/search_fill.php
@@ -40,7 +40,7 @@ if (!class_exists($search_type))
}
$error = false;
-$search = new $search_type($error);
+$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if ($error)
{
diff --git a/phpBB/download/file.php b/phpBB/download/file.php
index c01b0789de..b56d729a7b 100644
--- a/phpBB/download/file.php
+++ b/phpBB/download/file.php
@@ -134,6 +134,9 @@ include($phpbb_root_path . 'common.' . $phpEx);
require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx);
$download_id = request_var('id', 0);
+$topic_id = $request->variable('topic_id', 0);
+$post_msg_id = $request->variable('post_msg_id', 0);
+$archive = $request->variable('archive', '.tar');
$mode = request_var('mode', '');
$thumbnail = request_var('t', false);
@@ -142,195 +145,268 @@ $user->session_begin(false);
$auth->acl($user->data);
$user->setup('viewtopic');
-if (!$download_id)
+if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
{
send_status_line(404, 'Not Found');
- trigger_error('NO_ATTACHMENT_SELECTED');
+ trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}
-if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
+if ($download_id)
+{
+ // Attachment id (only 1 attachment)
+ $sql_where = "attach_id = $download_id";
+}
+else if ($post_msg_id)
+{
+ // Post id or private message id (multiple attachments)
+ $sql_where = "post_msg_id = $post_msg_id AND is_orphan = 0";
+}
+else if ($topic_id)
+{
+ // Topic id (multiple attachments)
+ $sql_where = "topic_id = $topic_id AND is_orphan = 0";
+}
+else
{
send_status_line(404, 'Not Found');
- trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
+ trigger_error('NO_ATTACHMENT_SELECTED');
}
-$sql = 'SELECT attach_id, in_message, post_msg_id, extension, is_orphan, poster_id, filetime
+$sql = 'SELECT attach_id, post_msg_id, topic_id, in_message, is_orphan, physical_filename, real_filename, extension, mimetype, filesize, filetime
FROM ' . ATTACHMENTS_TABLE . "
- WHERE attach_id = $download_id";
-$result = $db->sql_query_limit($sql, 1);
-$attachment = $db->sql_fetchrow($result);
+ WHERE $sql_where";
+$result = $db->sql_query($sql);
+
+$attachments = $attachment_ids = array();
+while ($row = $db->sql_fetchrow($result))
+{
+ $attachment_id = (int) $row['attach_id'];
+
+ $row['physical_filename'] = utf8_basename($row['physical_filename']);
+
+ $attachment_ids[$attachment_id] = $attachment_id;
+ $attachments[$attachment_id] = $row;
+}
$db->sql_freeresult($result);
-if (!$attachment)
+// Make $attachment the first of the attachments we fetched.
+$attachment = current($attachments);
+
+if (empty($attachments))
{
send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
}
-
-if ((!$attachment['in_message'] && !$config['allow_attachments']) || ($attachment['in_message'] && !$config['allow_pm_attach']))
+else if (!download_allowed())
{
- send_status_line(404, 'Not Found');
- trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
+ send_status_line(403, 'Forbidden');
+ trigger_error($user->lang['LINKAGE_FORBIDDEN']);
}
-
-$row = array();
-
-if ($attachment['is_orphan'])
+else if ($download_id)
{
- // We allow admins having attachment permissions to see orphan attachments...
- $own_attachment = ($auth->acl_get('a_attach') || $attachment['poster_id'] == $user->data['user_id']) ? true : false;
+ // sizeof($attachments) == 1
- if (!$own_attachment || ($attachment['in_message'] && !$auth->acl_get('u_pm_download')) || (!$attachment['in_message'] && !$auth->acl_get('u_download')))
+ if (!$attachment['in_message'] && !$config['allow_attachments'] || $attachment['in_message'] && !$config['allow_pm_attach'])
{
send_status_line(404, 'Not Found');
- trigger_error('ERROR_NO_ATTACHMENT');
+ trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}
- // Obtain all extensions...
- $extensions = $cache->obtain_attach_extensions(true);
-}
-else
-{
- if (!$attachment['in_message'])
+ if ($attachment['is_orphan'])
{
- //
- $sql = 'SELECT p.forum_id, f.forum_password, f.parent_id
- FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . ' f
- WHERE p.post_id = ' . $attachment['post_msg_id'] . '
- AND p.forum_id = f.forum_id';
- $result = $db->sql_query_limit($sql, 1);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- $f_download = $auth->acl_get('f_download', $row['forum_id']);
-
- if ($auth->acl_get('u_download') && $f_download)
- {
- if ($row && $row['forum_password'])
- {
- // Do something else ... ?
- login_forum_box($row);
- }
- }
- else
+ // We allow admins having attachment permissions to see orphan attachments...
+ $own_attachment = ($auth->acl_get('a_attach') || $attachment['poster_id'] == $user->data['user_id']) ? true : false;
+
+ if (!$own_attachment || ($attachment['in_message'] && !$auth->acl_get('u_pm_download')) || (!$attachment['in_message'] && !$auth->acl_get('u_download')))
{
- send_status_line(403, 'Forbidden');
- trigger_error('SORRY_AUTH_VIEW_ATTACH');
+ send_status_line(404, 'Not Found');
+ trigger_error('ERROR_NO_ATTACHMENT');
}
+
+ // Obtain all extensions...
+ $extensions = $cache->obtain_attach_extensions(true);
}
else
{
- $row['forum_id'] = false;
- if (!$auth->acl_get('u_pm_download'))
+ if (!$attachment['in_message'])
{
- send_status_line(403, 'Forbidden');
- trigger_error('SORRY_AUTH_VIEW_ATTACH');
+ phpbb_download_handle_forum_auth($db, $auth, $attachment['topic_id']);
}
+ else
+ {
+ // Attachment is in a private message.
+ $row['forum_id'] = false;
+ phpbb_download_handle_pm_auth($db, $auth, $user->data['user_id'], $attachment['post_msg_id']);
+ }
+
+ $extensions = array();
+ if (!extension_allowed($row['forum_id'], $attachment['extension'], $extensions))
+ {
+ send_status_line(404, 'Forbidden');
+ trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
+ }
+ }
+
+ $download_mode = (int) $extensions[$attachment['extension']]['download_mode'];
+ $display_cat = $extensions[$attachment['extension']]['display_cat'];
+
+ if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg'))
+ {
+ $display_cat = ATTACHMENT_CATEGORY_NONE;
+ }
+
+ if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash'))
+ {
+ $display_cat = ATTACHMENT_CATEGORY_NONE;
+ }
- // Check if the attachment is within the users scope...
- $sql = 'SELECT user_id, author_id
- FROM ' . PRIVMSGS_TO_TABLE . '
- WHERE msg_id = ' . $attachment['post_msg_id'];
- $result = $db->sql_query($sql);
+ if ($thumbnail)
+ {
+ $attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
+ }
+ else if ($display_cat == ATTACHMENT_CATEGORY_NONE && !$attachment['is_orphan'] && !phpbb_http_byte_range($attachment['filesize']))
+ {
+ // Update download count
+ phpbb_increment_downloads($db, $attachment['attach_id']);
+ }
- $allowed = false;
- while ($user_row = $db->sql_fetchrow($result))
+ if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && ((strpos(strtolower($user->browser), 'msie') !== false) && (strpos(strtolower($user->browser), 'msie 8.0') === false)))
+ {
+ wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']);
+ file_gc();
+ }
+ else
+ {
+ // Determine the 'presenting'-method
+ if ($download_mode == PHYSICAL_LINK)
{
- if ($user->data['user_id'] == $user_row['user_id'] || $user->data['user_id'] == $user_row['author_id'])
+ // This presenting method should no longer be used
+ if (!@is_dir($phpbb_root_path . $config['upload_path']))
{
- $allowed = true;
- break;
+ send_status_line(500, 'Internal Server Error');
+ trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
}
- }
- $db->sql_freeresult($result);
- if (!$allowed)
+ redirect($phpbb_root_path . $config['upload_path'] . '/' . $attachment['physical_filename']);
+ file_gc();
+ }
+ else
{
- send_status_line(403, 'Forbidden');
- trigger_error('ERROR_NO_ATTACHMENT');
+ send_file_to_browser($attachment, $config['upload_path'], $display_cat);
+ file_gc();
}
}
+}
+else
+{
+ // sizeof($attachments) >= 1
+ if ($attachment['in_message'])
+ {
+ phpbb_download_handle_pm_auth($db, $auth, $user->data['user_id'], $attachment['post_msg_id']);
+ }
+ else
+ {
+ phpbb_download_handle_forum_auth($db, $auth, $attachment['topic_id']);
+ }
- // disallowed?
- $extensions = array();
- if (!extension_allowed($row['forum_id'], $attachment['extension'], $extensions))
+ if (!class_exists('compress'))
{
- send_status_line(404, 'Forbidden');
- trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
+ require $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
}
-}
-if (!download_allowed())
-{
- send_status_line(403, 'Forbidden');
- trigger_error($user->lang['LINKAGE_FORBIDDEN']);
-}
+ if (!in_array($archive, compress::methods()))
+ {
+ $archive = '.tar';
+ }
-$download_mode = (int) $extensions[$attachment['extension']]['download_mode'];
+ if ($post_msg_id)
+ {
+ if ($attachment['in_message'])
+ {
+ $sql = 'SELECT message_subject AS attach_subject
+ FROM ' . PRIVMSGS_TABLE . "
+ WHERE msg_id = $post_msg_id";
+ }
+ else
+ {
+ $sql = 'SELECT post_subject AS attach_subject, forum_id
+ FROM ' . POSTS_TABLE . "
+ WHERE post_id = $post_msg_id";
+ }
+ }
+ else
+ {
+ $sql = 'SELECT topic_title AS attach_subject, forum_id
+ FROM ' . TOPICS_TABLE . "
+ WHERE topic_id = $topic_id";
+ }
-// Fetching filename here to prevent sniffing of filename
-$sql = 'SELECT attach_id, is_orphan, in_message, post_msg_id, extension, physical_filename, real_filename, mimetype, filesize, filetime
- FROM ' . ATTACHMENTS_TABLE . "
- WHERE attach_id = $download_id";
-$result = $db->sql_query_limit($sql, 1);
-$attachment = $db->sql_fetchrow($result);
-$db->sql_freeresult($result);
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
-if (!$attachment)
-{
- send_status_line(404, 'Not Found');
- trigger_error('ERROR_NO_ATTACHMENT');
-}
+ if (empty($row))
+ {
+ send_status_line(404, 'Not Found');
+ trigger_error('ERROR_NO_ATTACHMENT');
+ }
-$attachment['physical_filename'] = utf8_basename($attachment['physical_filename']);
-$display_cat = $extensions[$attachment['extension']]['display_cat'];
+ $clean_name = phpbb_download_clean_filename($row['attach_subject']);
+ $suffix = '_' . (($post_msg_id) ? $post_msg_id : $topic_id) . '_' . $clean_name;
+ $archive_name = 'attachments' . $suffix;
-if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg'))
-{
- $display_cat = ATTACHMENT_CATEGORY_NONE;
-}
+ $store_name = 'att_' . time() . '_' . unique_id();
+ $archive_path = "{$phpbb_root_path}store/{$store_name}{$archive}";
-if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash'))
-{
- $display_cat = ATTACHMENT_CATEGORY_NONE;
-}
+ if ($archive === '.zip')
+ {
+ $compress = new compress_zip('w', $archive_path);
+ }
+ else
+ {
+ $compress = new compress_tar('w', $archive_path, $archive);
+ }
-if ($thumbnail)
-{
- $attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
-}
-else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHMENT_CATEGORY_IMAGE*/) && !$attachment['is_orphan'] && !phpbb_http_byte_range($attachment['filesize']))
-{
- // Update download count
- $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
- SET download_count = download_count + 1
- WHERE attach_id = ' . $attachment['attach_id'];
- $db->sql_query($sql);
-}
+ $extensions = array();
+ $files_added = 0;
+ $forum_id = ($attachment['in_message']) ? false : (int) $row['forum_id'];
+ $disallowed = array();
-if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && ((strpos(strtolower($user->browser), 'msie') !== false) && (strpos(strtolower($user->browser), 'msie 8.0') === false)))
-{
- wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']);
- file_gc();
-}
-else
-{
- // Determine the 'presenting'-method
- if ($download_mode == PHYSICAL_LINK)
+ foreach ($attachments as $attach)
{
- // This presenting method should no longer be used
- if (!@is_dir($phpbb_root_path . $config['upload_path']))
+ if (!extension_allowed($forum_id, $attach['extension'], $extensions))
+ {
+ $disallowed[$attach['extension']] = $attach['extension'];
+ continue;
+ }
+
+ $prefix = '';
+ if ($topic_id)
{
- send_status_line(500, 'Internal Server Error');
- trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
+ $prefix = $attach['post_msg_id'] . '_';
}
- redirect($phpbb_root_path . $config['upload_path'] . '/' . $attachment['physical_filename']);
- file_gc();
+ $compress->add_custom_file("{$phpbb_root_path}files/{$attach['physical_filename']}", "{$prefix}{$attach['real_filename']}");
+ $files_added++;
}
- else
+
+ $compress->close();
+
+ if ($files_added)
{
- send_file_to_browser($attachment, $config['upload_path'], $display_cat);
- file_gc();
+ phpbb_increment_downloads($db, $attachment_ids);
+ $compress->download($store_name, $archive_name);
+ }
+
+ unlink($archive_path);
+
+ if (!$files_added)
+ {
+ // None of the attachments had a valid extension
+ $disallowed = implode($user->lang['COMMA_SEPARATOR'], $disallowed);
+ send_status_line(404, 'Forbidden');
+ trigger_error($user->lang('EXTENSION_DISABLED_AFTER_POSTING', $disallowed));
}
+
+ file_gc();
}
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php
index 3a3b2021eb..c6dbf5eb9c 100644
--- a/phpBB/includes/acp/acp_forums.php
+++ b/phpBB/includes/acp/acp_forums.php
@@ -25,7 +25,7 @@ class acp_forums
function main($id, $mode)
{
- global $db, $user, $auth, $template, $cache, $request;
+ global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher;
global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
$user->add_lang('acp/forums');
@@ -150,6 +150,17 @@ class acp_forums
'forum_password_unset' => request_var('forum_password_unset', false),
);
+ /**
+ * Request forum data and operate on it (parse texts, etc.)
+ *
+ * @event core.acp_manage_forums_request_data
+ * @var string action Type of the action: add|edit
+ * @var array forum_data Array with new forum data
+ * @since 3.1-A1
+ */
+ $vars = array('action', 'forum_data');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_request_data', compact($vars)));
+
// On add, add empty forum_options... else do not consider it (not updating it)
if ($action == 'add')
{
@@ -386,6 +397,9 @@ class acp_forums
$forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
}
+ // Initialise $row, so we always have it in the event
+ $row = array();
+
// Show form to create/modify a forum
if ($action == 'edit')
{
@@ -453,6 +467,24 @@ class acp_forums
}
}
+ /**
+ * Initialise data before we display the add/edit form
+ *
+ * @event core.acp_manage_forums_initialise_data
+ * @var string action Type of the action: add|edit
+ * @var bool update Do we display the form only
+ * or did the user press submit
+ * @var int forum_id When editing: the forum id,
+ * when creating: the parent forum id
+ * @var array row Array with current forum data
+ * empty when creating new forum
+ * @var array forum_data Array with new forum data
+ * @var string parents_list List of parent options
+ * @since 3.1-A1
+ */
+ $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_initialise_data', compact($vars)));
+
$forum_rules_data = array(
'text' => $forum_data['forum_rules'],
'allow_bbcode' => true,
@@ -582,7 +614,7 @@ class acp_forums
$errors[] = $user->lang['FORUM_PASSWORD_OLD'];
}
- $template->assign_vars(array(
+ $template_data = array(
'S_EDIT_FORUM' => true,
'S_ERROR' => (sizeof($errors)) ? true : false,
'S_PARENT_ID' => $this->parent_id,
@@ -647,7 +679,31 @@ class acp_forums
'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
'S_CAN_COPY_PERMISSIONS' => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false,
- ));
+ );
+
+ /**
+ * Modify forum template data before we display the form
+ *
+ * @event core.acp_manage_forums_display_form
+ * @var string action Type of the action: add|edit
+ * @var bool update Do we display the form only
+ * or did the user press submit
+ * @var int forum_id When editing: the forum id,
+ * when creating: the parent forum id
+ * @var array row Array with current forum data
+ * empty when creating new forum
+ * @var array forum_data Array with new forum data
+ * @var string parents_list List of parent options
+ * @var array errors Array of errors, if you add errors
+ * ensure to update the template variables
+ * S_ERROR and ERROR_MSG to display it
+ * @var array template_data Array with new forum data
+ * @since 3.1-A1
+ */
+ $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list', 'errors', 'template_data');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_display_form', compact($vars)));
+
+ $template->assign_vars($template_data);
return;
@@ -872,10 +928,22 @@ class acp_forums
*/
function update_forum_data(&$forum_data)
{
- global $db, $user, $cache, $phpbb_root_path;
+ global $db, $user, $cache, $phpbb_root_path, $phpbb_dispatcher;
$errors = array();
+ /**
+ * Validate the forum data before we create/update the forum
+ *
+ * @event core.acp_manage_forums_validate_data
+ * @var array forum_data Array with new forum data
+ * @var array errors Array of errors, should be strings and not
+ * language key.
+ * @since 3.1-A1
+ */
+ $vars = array('forum_data', 'errors');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_validate_data', compact($vars)));
+
if ($forum_data['forum_name'] == '')
{
$errors[] = $user->lang['FORUM_NAME_EMPTY'];
@@ -968,7 +1036,22 @@ class acp_forums
}
unset($forum_data_sql['forum_password_unset']);
- if (!isset($forum_data_sql['forum_id']))
+ /**
+ * Remove invalid values from forum_data_sql that should not be updated
+ *
+ * @event core.acp_manage_forums_update_data_before
+ * @var array forum_data Array with forum data
+ * @var array forum_data_sql Array with data we are going to update
+ * If forum_data_sql[forum_id] is set, we update
+ * that forum, otherwise a new one is created.
+ * @since 3.1-A1
+ */
+ $vars = array('forum_data', 'forum_data_sql');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_before', compact($vars)));
+
+ $is_new_forum = !isset($forum_data_sql['forum_id']);
+
+ if ($is_new_forum)
{
// no forum_id means we're creating a new forum
unset($forum_data_sql['type_action']);
@@ -1239,6 +1322,22 @@ class acp_forums
add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
}
+ /**
+ * Event after a forum was updated or created
+ *
+ * @event core.acp_manage_forums_update_data_after
+ * @var array forum_data Array with forum data
+ * @var array forum_data_sql Array with data we updated
+ * @var bool is_new_forum Did we create a forum or update one
+ * If you want to overwrite this value,
+ * ensure to set forum_data_sql[forum_id]
+ * @var array errors Array of errors, should be strings and not
+ * language key.
+ * @since 3.1-A1
+ */
+ $vars = array('forum_data', 'forum_data_sql', 'is_new_forum', 'errors');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_after', compact($vars)));
+
return $errors;
}
@@ -1247,7 +1346,7 @@ class acp_forums
*/
function move_forum($from_id, $to_id)
{
- global $db, $user;
+ global $db, $user, $phpbb_dispatcher;
$to_data = $moved_ids = $errors = array();
@@ -1259,10 +1358,30 @@ class acp_forums
if ($to_data['forum_type'] == FORUM_LINK)
{
$errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
- return $errors;
}
}
+ /**
+ * Event when we move all children of one forum to another
+ *
+ * This event may be triggered, when a forum is deleted
+ *
+ * @event core.acp_manage_forums_move_children
+ * @var int from_id If of the current parent forum
+ * @var int to_id If of the new parent forum
+ * @var array errors Array of errors, should be strings and not
+ * language key.
+ * @since 3.1-A1
+ */
+ $vars = array('from_id', 'to_id', 'errors');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_children', compact($vars)));
+
+ // Return if there were errors
+ if (!empty($errors))
+ {
+ return $errors;
+ }
+
$moved_forums = get_forum_branch($from_id, 'children', 'descending');
$from_data = $moved_forums[0];
$diff = sizeof($moved_forums) * 2;
@@ -1342,7 +1461,30 @@ class acp_forums
*/
function move_forum_content($from_id, $to_id, $sync = true)
{
- global $db;
+ global $db, $phpbb_dispatcher;
+
+ $errors = array();
+
+ /**
+ * Event when we move content from one forum to another
+ *
+ * @event core.acp_manage_forums_move_children
+ * @var int from_id If of the current parent forum
+ * @var int to_id If of the new parent forum
+ * @var bool sync Shall we sync the "to"-forum's data
+ * @var array errors Array of errors, should be strings and not
+ * language key. If this array is not empty,
+ * The content will not be moved.
+ * @since 3.1-A1
+ */
+ $vars = array('from_id', 'to_id', 'sync', 'errors');
+ extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_content', compact($vars)));
+
+ // Return if there were errors
+ if (!empty($errors))
+ {
+ return $errors;
+ }
$table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php
index 82d9b021fe..6618e2c3f9 100644
--- a/phpBB/includes/acp/acp_search.php
+++ b/phpBB/includes/acp/acp_search.php
@@ -596,7 +596,7 @@ class acp_search
*/
function init_search($type, &$search, &$error)
{
- global $phpbb_root_path, $phpEx, $user;
+ global $phpbb_root_path, $phpEx, $user, $auth, $config, $db;
if (!class_exists($type) || !method_exists($type, 'keyword_search'))
{
@@ -605,7 +605,7 @@ class acp_search
}
$error = false;
- $search = new $type($error);
+ $search = new $type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
return $error;
}
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php
index 62968a17b7..b54257b04a 100644
--- a/phpBB/includes/acp/acp_users.php
+++ b/phpBB/includes/acp/acp_users.php
@@ -32,6 +32,7 @@ class acp_users
{
global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
+ global $phpbb_dispatcher;
$user->add_lang(array('posting', 'ucp', 'acp/users'));
$this->tpl_name = 'acp_users';
@@ -749,6 +750,19 @@ class acp_users
}
break;
+
+ default:
+ /**
+ * Run custom quicktool code
+ *
+ * @event core.acp_users_overview_run_quicktool
+ * @var array user_row Current user data
+ * @var string action Quick tool that should be run
+ * @since 3.1-A1
+ */
+ $vars = array('action', 'user_row');
+ extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars)));
+ break;
}
// Handle registration info updates
@@ -855,6 +869,18 @@ class acp_users
}
}
+ /**
+ * Modify user data before we update it
+ *
+ * @event core.acp_users_overview_modify_data
+ * @var array user_row Current user data
+ * @var array data Submitted user data
+ * @var array sql_ary User data we udpate
+ * @since 3.1-A1
+ */
+ $vars = array('user_row', 'data', 'sql_ary');
+ extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars)));
+
if ($update_username !== false)
{
$sql_ary['username'] = $update_username;
@@ -945,12 +971,6 @@ class acp_users
}
}
- $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
- foreach ($quick_tool_ary as $value => $lang)
- {
- $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
- }
-
if ($config['load_onlinetrack'])
{
$sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
@@ -965,6 +985,23 @@ class acp_users
unset($row);
}
+ /**
+ * Add additional quick tool options and overwrite user data
+ *
+ * @event core.acp_users_display_overview
+ * @var array user_row Array with user data
+ * @var array quick_tool_ary Ouick tool options
+ * @since 3.1-A1
+ */
+ $vars = array('user_row', 'quick_tool_ary');
+ extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars)));
+
+ $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
+ foreach ($quick_tool_ary as $value => $lang)
+ {
+ $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
+ }
+
$last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];
$inactive_reason = '';
diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php
index 0d3b06f621..f64a9e3ea8 100644
--- a/phpBB/includes/cache/driver/file.php
+++ b/phpBB/includes/cache/driver/file.php
@@ -364,7 +364,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
/**
* Save sql query
*/
- function sql_save($query, &$query_result, $ttl)
+ function sql_save($query, $query_result, $ttl)
{
global $db;
@@ -385,6 +385,8 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
{
$query_result = $query_id;
}
+
+ return $query_id;
}
/**
diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php
index 313a2d4b31..847ba97262 100644
--- a/phpBB/includes/cache/driver/interface.php
+++ b/phpBB/includes/cache/driver/interface.php
@@ -75,7 +75,7 @@ interface phpbb_cache_driver_interface
/**
* Save sql query
*/
- public function sql_save($query, &$query_result, $ttl);
+ public function sql_save($query, $query_result, $ttl);
/**
* Ceck if a given sql query exist in cache
diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php
index e25c9229a1..92971c6cb2 100644
--- a/phpBB/includes/cache/driver/memory.php
+++ b/phpBB/includes/cache/driver/memory.php
@@ -280,7 +280,7 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base
/**
* Save sql query
*/
- function sql_save($query, &$query_result, $ttl)
+ function sql_save($query, $query_result, $ttl)
{
global $db;
@@ -335,6 +335,8 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base
$this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl);
$query_result = $query_id;
+
+ return $query_id;
}
/**
diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php
index c143803d0e..df2c6c026f 100644
--- a/phpBB/includes/cache/driver/null.php
+++ b/phpBB/includes/cache/driver/null.php
@@ -107,7 +107,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base
/**
* Save sql query
*/
- function sql_save($query, &$query_result, $ttl)
+ function sql_save($query, $query_result, $ttl)
{
}
diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php
index 8a0b1b690a..7855c3760a 100644
--- a/phpBB/includes/cron/task/core/tidy_search.php
+++ b/phpBB/includes/cron/task/core/tidy_search.php
@@ -31,7 +31,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base
*/
public function run()
{
- global $phpbb_root_path, $phpEx, $config, $error;
+ global $phpbb_root_path, $phpEx, $config, $error, $auth, $db, $user;
// Select the search method
$search_type = basename($config['search_type']);
@@ -43,7 +43,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base
// We do some additional checks in the module to ensure it can actually be utilised
$error = false;
- $search = new $search_type($error);
+ $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if (!$error)
{
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index 159703d3be..1de236d3de 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -206,7 +206,7 @@ class dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@@ -256,7 +256,7 @@ class dbal
$this->sql_rowseek($rownum, $query_id);
}
- if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
+ if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_fetchfield($query_id, $field);
}
diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index 06c76fa94a..9f9b8a1abd 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -272,7 +272,7 @@ class dbal_firebird extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -332,7 +332,7 @@ class dbal_firebird extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -398,7 +398,7 @@ class dbal_firebird extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index e40510835a..bde283c3ea 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -162,7 +162,7 @@ class dbal_mssql extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -234,7 +234,7 @@ class dbal_mssql extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -271,7 +271,7 @@ class dbal_mssql extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@@ -310,7 +310,7 @@ class dbal_mssql extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 3c9a9599ec..687bc52abc 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -181,7 +181,7 @@ class dbal_mssql_odbc extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -254,7 +254,7 @@ class dbal_mssql_odbc extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -295,7 +295,7 @@ class dbal_mssql_odbc extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php
index d35337d05b..c31f7f6892 100644
--- a/phpBB/includes/db/mssqlnative.php
+++ b/phpBB/includes/db/mssqlnative.php
@@ -218,7 +218,6 @@ class dbal_mssqlnative extends dbal
$this->server = $sqlserver . (($port) ? $port_delimiter . $port : '');
//connect to database
- error_reporting(E_ALL);
$this->db_connect_id = sqlsrv_connect($this->server, array(
'Database' => $this->dbname,
'UID' => $this->user,
@@ -338,7 +337,7 @@ class dbal_mssqlnative extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -418,7 +417,7 @@ class dbal_mssqlnative extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -478,7 +477,7 @@ class dbal_mssqlnative extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index dbab1ec0b8..5b4ff86579 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -190,7 +190,7 @@ class dbal_mysql extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -249,7 +249,7 @@ class dbal_mysql extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -270,7 +270,7 @@ class dbal_mysql extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@@ -298,7 +298,7 @@ class dbal_mysql extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index fc98de31fb..1f13bd5459 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -196,7 +196,7 @@ class dbal_mysqli extends dbal
if ($cache_ttl)
{
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
}
else if (defined('DEBUG_EXTRA'))
@@ -251,7 +251,7 @@ class dbal_mysqli extends dbal
$query_id = $this->query_result;
}
- if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
+ if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -278,7 +278,7 @@ class dbal_mysqli extends dbal
$query_id = $this->query_result;
}
- if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
+ if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@@ -306,7 +306,7 @@ class dbal_mysqli extends dbal
$query_id = $this->query_result;
}
- if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
+ if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 4954f4d398..de2729e973 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -421,7 +421,7 @@ class dbal_oracle extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -473,7 +473,7 @@ class dbal_oracle extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -525,7 +525,7 @@ class dbal_oracle extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@@ -594,7 +594,7 @@ class dbal_oracle extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index 41838d2613..f0a4a7a7a2 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -218,7 +218,7 @@ class dbal_postgres extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -285,7 +285,7 @@ class dbal_postgres extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -306,7 +306,7 @@ class dbal_postgres extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@@ -355,7 +355,7 @@ class dbal_postgres extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index d930567773..2cf55b07e2 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -135,7 +135,7 @@ class dbal_sqlite extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@@ -193,7 +193,7 @@ class dbal_sqlite extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@@ -214,7 +214,7 @@ class dbal_sqlite extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@@ -242,7 +242,7 @@ class dbal_sqlite extends dbal
$query_id = $this->query_result;
}
- if (isset($cache->sql_rowset[$query_id]))
+ if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php
index 2b8c50aafb..f97b69c7ed 100644
--- a/phpBB/includes/extension/controller.php
+++ b/phpBB/includes/extension/controller.php
@@ -23,37 +23,44 @@ if (!defined('IN_PHPBB'))
abstract class phpbb_extension_controller implements phpbb_extension_controller_interface
{
/**
- * @var phpbb_request Request class object
+ * Request class object
+ * @var phpbb_request
*/
protected $request;
/**
- * @var dbal DBAL class object
+ * DBAL class object
+ * @var dbal
*/
protected $db;
/**
- * @var user User class object
+ * User class object
+ * @var phpbb_user
*/
protected $user;
/**
- * @var phpbb_template Template class object
+ * Template class object
+ * @var phpbb_template
*/
protected $template;
/**
- * @var array Config array
+ * Config object
+ * @var phpbb_config
*/
protected $config;
/**
- * @var string PHP Extension
+ * PHP Extension
+ * @var string
*/
protected $php_ext;
/**
- * @var string Relative path to board root
+ * Relative path to board root
+ * @var string
*/
protected $phpbb_root_path;
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index e5b721b1f5..ecec1e5e4a 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -4753,6 +4753,31 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
define('HEADER_INC', true);
+ // A listener can set this variable to `true` when it overrides this function
+ $page_header_override = false;
+
+ /**
+ * Execute code and/or overwrite page_header()
+ *
+ * @event core.page_header
+ * @var string page_title Page title
+ * @var bool display_online_list Do we display online users list
+ * @var string item Restrict online users to a certain
+ * session item, e.g. forum for
+ * session_forum_id
+ * @var int item_id Restrict online users to item id
+ * @var bool page_header_override Shall we return instead of running
+ * the rest of page_header()
+ * @since 3.1-A1
+ */
+ $vars = array('page_title', 'display_online_list', 'item_id', 'item', 'page_header_override');
+ extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars)));
+
+ if ($page_header_override)
+ {
+ return;
+ }
+
// gzip_compression
if ($config['gzip_compress'])
{
@@ -5033,9 +5058,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
));
- $vars = array('page_title', 'display_online_list', 'item_id', 'item');
- extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars)));
-
// application/xhtml+xml not used because of IE
header('Content-type: text/html; charset=UTF-8');
@@ -5058,7 +5080,27 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
function page_footer($run_cron = true)
{
global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx;
- global $request;
+ global $request, $phpbb_dispatcher;
+
+ // A listener can set this variable to `true` when it overrides this function
+ $page_footer_override = false;
+
+ /**
+ * Execute code and/or overwrite page_footer()
+ *
+ * @event core.page_footer
+ * @var bool run_cron Shall we run cron tasks
+ * @var bool page_footer_override Shall we return instead of running
+ * the rest of page_footer()
+ * @since 3.1-A1
+ */
+ $vars = array('run_cron', 'page_footer_override');
+ extract($phpbb_dispatcher->trigger_event('core.page_footer', compact($vars)));
+
+ if ($page_footer_override)
+ {
+ return;
+ }
// Output page creation time
if (defined('DEBUG'))
@@ -5143,6 +5185,15 @@ function page_footer($run_cron = true)
function garbage_collection()
{
global $cache, $db;
+ global $phpbb_dispatcher;
+
+ /**
+ * Unload some objects, to free some memory, before we finish our task
+ *
+ * @event core.garbage_collection
+ * @since 3.1-A1
+ */
+ $phpbb_dispatcher->dispatch('core.garbage_collection');
// Unload cache, must be done before the DB connection if closed
if (!empty($cache))
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index dc61859363..2f0188289b 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -22,6 +22,7 @@ function adm_page_header($page_title)
{
global $config, $db, $user, $template;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
+ global $phpbb_dispatcher;
if (defined('HEADER_INC'))
{
@@ -30,6 +31,26 @@ function adm_page_header($page_title)
define('HEADER_INC', true);
+ // A listener can set this variable to `true` when it overrides this function
+ $adm_page_header_override = false;
+
+ /**
+ * Execute code and/or overwrite adm_page_header()
+ *
+ * @event core.adm_page_header
+ * @var string page_title Page title
+ * @var bool adm_page_header_override Shall we return instead of
+ * running the rest of adm_page_header()
+ * @since 3.1-A1
+ */
+ $vars = array('page_title', 'adm_page_header_override');
+ extract($phpbb_dispatcher->trigger_event('core.adm_page_header', compact($vars)));
+
+ if ($adm_page_header_override)
+ {
+ return;
+ }
+
// gzip_compression
if ($config['gzip_compress'])
{
@@ -96,7 +117,27 @@ function adm_page_footer($copyright_html = true)
{
global $db, $config, $template, $user, $auth, $cache;
global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
- global $request;
+ global $request, $phpbb_dispatcher;
+
+ // A listener can set this variable to `true` when it overrides this function
+ $adm_page_footer_override = false;
+
+ /**
+ * Execute code and/or overwrite adm_page_footer()
+ *
+ * @event core.adm_page_footer
+ * @var bool copyright_html Shall we display the copyright?
+ * @var bool adm_page_footer_override Shall we return instead of
+ * running the rest of adm_page_footer()
+ * @since 3.1-A1
+ */
+ $vars = array('copyright_html', 'adm_page_footer_override');
+ extract($phpbb_dispatcher->trigger_event('core.adm_page_footer', compact($vars)));
+
+ if ($adm_page_footer_override)
+ {
+ return;
+ }
// Output page creation time
if (defined('DEBUG'))
@@ -193,7 +234,7 @@ function h_radio($name, $input_ary, $input_default = false, $id = false, $key =
*/
function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
{
- global $user, $module;
+ global $user, $module, $phpbb_dispatcher;
$tpl = '';
$name = 'config[' . $config_key . ']';
@@ -305,6 +346,24 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
$tpl .= $vars['append'];
}
+ /**
+ * Overwrite the html code we display for the config value
+ *
+ * @event core.build_config_template
+ * @var array tpl_type Config type array:
+ * 0 => data type
+ * 1 [optional] => string: size, int: minimum
+ * 2 [optional] => string: max. length, int: maximum
+ * @var string key Should be used for the id attribute in html
+ * @var array new Array with the config values we display
+ * @var string name Should be used for the name attribute
+ * @var array vars Array with the options for the config
+ * @var string tpl The resulting html code we display
+ * @since 3.1-A1
+ */
+ $vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl');
+ extract($phpbb_dispatcher->trigger_event('core.build_config_template', compact($vars)));
+
return $tpl;
}
@@ -314,7 +373,8 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
*/
function validate_config_vars($config_vars, &$cfg_array, &$error)
{
- global $phpbb_root_path, $user;
+ global $phpbb_root_path, $user, $phpbb_dispatcher;
+
$type = 0;
$min = 1;
$max = 2;
@@ -489,6 +549,24 @@ function validate_config_vars($config_vars, &$cfg_array, &$error)
}
break;
+
+ default:
+ /**
+ * Validate a config value
+ *
+ * @event core.validate_config_variable
+ * @var array cfg_array Array with config values
+ * @var string config_name Name of the config we validate
+ * @var array config_definition Array with the options for
+ * this config
+ * @var array error Array of errors, the errors should
+ * be strings only, language keys are
+ * not replaced afterwards
+ * @since 3.1-A1
+ */
+ $vars = array('cfg_array', 'config_name', 'config_definition', 'error');
+ extract($phpbb_dispatcher->trigger_event('core.validate_config_variable', compact($vars)));
+ break;
}
}
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 5d19cd7adb..5e2ee8c8f6 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -723,7 +723,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
*/
function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true)
{
- global $db, $config, $phpbb_root_path, $phpEx;
+ global $db, $config, $phpbb_root_path, $phpEx, $auth, $user;
if ($where_type === 'range')
{
@@ -855,7 +855,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
}
$error = false;
- $search = new $search_type($error);
+ $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if ($error)
{
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index a1ff7a1f99..881c95907b 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -22,7 +22,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
{
global $db, $auth, $user, $template;
global $phpbb_root_path, $phpEx, $config;
- global $request;
+ global $request, $phpbb_dispatcher;
$forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
$parent_id = $visible_forums = 0;
@@ -119,6 +119,16 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
'ORDER_BY' => 'f.left_id',
);
+ /**
+ * Event to modify the SQL query before the forum data is queried
+ *
+ * @event core.display_forums_modify_sql
+ * @var array sql_ary The SQL array to get the data of the forums
+ * @since 3.1-A1
+ */
+ $vars = array('sql_ary');
+ extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars)));
+
$sql = $db->sql_build_query('SELECT', $sql_ary);
$result = $db->sql_query($sql);
@@ -127,6 +137,19 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
while ($row = $db->sql_fetchrow($result))
{
+ /**
+ * Event to modify the data set of a forum
+ *
+ * This event is triggered once per forum
+ *
+ * @event core.display_forums_modify_row
+ * @var int branch_root_id Last top-level forum
+ * @var array row The data of the forum
+ * @since 3.1-A1
+ */
+ $vars = array('branch_root_id', 'row');
+ extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars)));
+
$forum_id = $row['forum_id'];
// Mark forums read?
@@ -260,6 +283,22 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
$forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
}
}
+
+ /**
+ * Event to modify the forum rows data set
+ *
+ * This event is triggered once per forum
+ *
+ * @event core.display_forums_modify_forum_rows
+ * @var array forum_rows Data array of all forums we display
+ * @var array subforums Data array of all subforums we display
+ * @var int branch_root_id Current top-level forum
+ * @var int parent_id Current parent forum
+ * @var array row The data of the forum
+ * @since 3.1-A1
+ */
+ $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row');
+ extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars)));
}
$db->sql_freeresult($result);
@@ -443,7 +482,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
}
}
- $template->assign_block_vars('forumrow', array(
+ $forum_row = array(
'S_IS_CAT' => false,
'S_NO_CAT' => $catless && !$last_catless,
'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
@@ -480,9 +519,24 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '',
'U_VIEWFORUM' => $u_viewforum,
'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
- 'U_LAST_POST' => $last_post_url)
+ 'U_LAST_POST' => $last_post_url,
);
+ /**
+ * Modify the template data block of the forum
+ *
+ * This event is triggered once per forum
+ *
+ * @event core.display_forums_modify_template_vars
+ * @var array forum_row Template data of the forum
+ * @var array row The data of the forum
+ * @since 3.1-A1
+ */
+ $vars = array('forum_row', 'row');
+ extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars)));
+
+ $template->assign_block_vars('forumrow', $forum_row);
+
// Assign subforums loop for style authors
foreach ($subforums_list as $subforum)
{
@@ -830,7 +884,7 @@ function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$fold
*/
function display_custom_bbcodes()
{
- global $db, $template, $user;
+ global $db, $template, $user, $phpbb_dispatcher;
// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
$num_predefined_bbcodes = 22;
@@ -850,17 +904,40 @@ function display_custom_bbcodes()
$row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
}
- $template->assign_block_vars('custom_tags', array(
+ $custom_tags = array(
'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
'BBCODE_TAG' => $row['bbcode_tag'],
'BBCODE_HELPLINE' => $row['bbcode_helpline'],
'A_BBCODE_HELPLINE' => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
- ));
+ );
+
+ /**
+ * Modify the template data block of a bbcode
+ *
+ * This event is triggered once per bbcode
+ *
+ * @event core.display_custom_bbcodes_modify_row
+ * @var array custom_tags Template data of the bbcode
+ * @var array row The data of the bbcode
+ * @since 3.1-A1
+ */
+ $vars = array('custom_tags', 'row');
+ extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars)));
+
+ $template->assign_block_vars('custom_tags', $custom_tags);
$i++;
}
$db->sql_freeresult($result);
+
+ /**
+ * Display custom bbcodes
+ *
+ * @event core.display_custom_bbcodes
+ * @since 3.1-A1
+ */
+ $phpbb_dispatcher->dispatch('core.display_custom_bbcodes');
}
/**
@@ -1248,6 +1325,31 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
{
global $user, $config, $phpbb_root_path, $phpEx;
+ global $phpbb_dispatcher;
+
+ $overwrite_avatar = '';
+
+ /**
+ * Overwrite users avatar
+ *
+ * @event core.display_custom_bbcodes_modify_row
+ * @var string avatar Users assigned avatar name
+ * @var int avatar_type Type of avatar
+ * @var string avatar_width Width of users avatar
+ * @var string avatar_height Height of users avatar
+ * @var string alt Language string for alt tag within image
+ * Can be a language key or text
+ * @var bool ignore_config Ignores config and force displaying avatar
+ * @var string overwrite_avatar If set, this string will be the avatar
+ * @since 3.1-A1
+ */
+ $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar');
+ extract($phpbb_dispatcher->trigger_event('core.user_get_avatar', compact($vars)));
+
+ if ($overwrite_avatar)
+ {
+ return $overwrite_avatar;
+ }
if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
{
@@ -1285,3 +1387,38 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $
$avatar_img .= $avatar;
return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
}
+
+/**
+* Generate a list of archive types available for compressing attachments
+*
+* @param string $param_key Either topic_id or post_id
+* @param string $param_val The value of the topic or post id
+* @param string $phpbb_root_path The root path of the phpBB installation
+* @param string $phpEx The PHP extension
+*
+* @return array Array containing the link and the type of compression
+*/
+function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $phpEx)
+{
+ if (!class_exists('compress'))
+ {
+ require $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
+ }
+
+ $methods = compress::methods();
+ $links = array();
+
+ foreach ($methods as $method)
+ {
+ $type = array_pop(explode('.', $method));
+ $params = array('archive' => $method);
+ $params[$param_key] = $param_val;
+
+ $links[] = array(
+ 'LINK' => append_sid("{$phpbb_root_path}download/file.$phpEx", $params),
+ 'TYPE' => $type,
+ );
+ }
+
+ return $links;
+}
diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php
index 1486113013..b6371dbecc 100644
--- a/phpBB/includes/functions_download.php
+++ b/phpBB/includes/functions_download.php
@@ -592,3 +592,132 @@ function phpbb_parse_range_request($request_array, $filesize)
);
}
}
+
+/**
+* Increments the download count of all provided attachments
+*
+* @param dbal $db The database object
+* @param array|int $ids The attach_id of each attachment
+*
+* @return null
+*/
+function phpbb_increment_downloads($db, $ids)
+{
+ if (!is_array($ids))
+ {
+ $ids = array($ids);
+ }
+
+ $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
+ SET download_count = download_count + 1
+ WHERE ' . $db->sql_in_set('attach_id', $ids);
+ $db->sql_query($sql);
+}
+
+/**
+* Handles authentication when downloading attachments from a post or topic
+*
+* @param dbal $db The database object
+* @param phpbb_auth $auth The authentication object
+* @param int $topic_id The id of the topic that we are downloading from
+*
+* @return null
+*/
+function phpbb_download_handle_forum_auth($db, $auth, $topic_id)
+{
+ $sql = 'SELECT t.forum_id, f.forum_password, f.parent_id
+ FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
+ WHERE t.topic_id = " . (int) $topic_id . "
+ AND t.forum_id = f.forum_id";
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']))
+ {
+ if ($row && $row['forum_password'])
+ {
+ // Do something else ... ?
+ login_forum_box($row);
+ }
+ }
+ else
+ {
+ send_status_line(403, 'Forbidden');
+ trigger_error('SORRY_AUTH_VIEW_ATTACH');
+ }
+}
+
+/**
+* Handles authentication when downloading attachments from PMs
+*
+* @param dbal $db The database object
+* @param phpbb_auth $auth The authentication object
+* @param int $user_id The user id
+* @param int $msg_id The id of the PM that we are downloading from
+*
+* @return null
+*/
+function phpbb_download_handle_pm_auth($db, $auth, $user_id, $msg_id)
+{
+ if (!$auth->acl_get('u_pm_download'))
+ {
+ send_status_line(403, 'Forbidden');
+ trigger_error('SORRY_AUTH_VIEW_ATTACH');
+ }
+
+ $allowed = phpbb_download_check_pm_auth($db, $user_id, $msg_id);
+
+ if (!$allowed)
+ {
+ send_status_line(403, 'Forbidden');
+ trigger_error('ERROR_NO_ATTACHMENT');
+ }
+}
+
+/**
+* Checks whether a user can download from a particular PM
+*
+* @param dbal $db The database object
+* @param int $user_id The user id
+* @param int $msg_id The id of the PM that we are downloading from
+*
+* @return bool Whether the user is allowed to download from that PM or not
+*/
+function phpbb_download_check_pm_auth($db, $user_id, $msg_id)
+{
+ // Check if the attachment is within the users scope...
+ $sql = 'SELECT msg_id
+ FROM ' . PRIVMSGS_TO_TABLE . '
+ WHERE msg_id = ' . (int) $msg_id . '
+ AND (
+ user_id = ' . (int) $user_id . '
+ OR author_id = ' . (int) $user_id . '
+ )';
+ $result = $db->sql_query_limit($sql, 1);
+ $allowed = (bool) $db->sql_fetchfield('msg_id');
+ $db->sql_freeresult($result);
+
+ return $allowed;
+}
+
+/**
+* Cleans a filename of any characters that could potentially cause a problem on
+* a user's filesystem.
+*
+* @param string $filename The filename to clean
+*
+* @return string The cleaned filename
+*/
+function phpbb_download_clean_filename($filename)
+{
+ $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
+
+ // rawurlencode to convert any potentially 'bad' characters that we missed
+ $filename = rawurlencode(str_replace($bad_chars, '_', $filename));
+
+ // Turn the %xx entities created by rawurlencode to _
+ $filename = preg_replace("/%(\w{2})/", '_', $filename);
+
+ return $filename;
+}
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 6c21b0f412..c50395a5df 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -20,7 +20,7 @@ if (!defined('IN_PHPBB'))
*/
function generate_smilies($mode, $forum_id)
{
- global $db, $user, $config, $template;
+ global $db, $user, $config, $template, $phpbb_dispatcher;
global $phpEx, $phpbb_root_path;
$start = request_var('start', 0);
@@ -123,6 +123,18 @@ function generate_smilies($mode, $forum_id)
}
}
+ /**
+ * This event is called after the smilies are populated
+ *
+ * @event core.generate_smilies_after
+ * @var string mode Mode of the smilies: window|inline
+ * @var int forum_id The forum ID we are currently in
+ * @var bool display_link Shall we display the "more smilies" link?
+ * @since 3.1-A1
+ */
+ $vars = array('mode', 'forum_id', 'display_link');
+ extract($phpbb_dispatcher->trigger_event('core.generate_smilies_after', compact($vars)));
+
if ($mode == 'inline' && $display_link)
{
$template->assign_vars(array(
@@ -2370,7 +2382,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
}
$error = false;
- $search = new $search_type($error);
+ $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if ($error)
{
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php
index 6e658b4ef4..9e33a5122e 100644
--- a/phpBB/includes/functions_user.php
+++ b/phpBB/includes/functions_user.php
@@ -112,7 +112,7 @@ function update_last_username()
*/
function user_update_name($old_name, $new_name)
{
- global $config, $db, $cache;
+ global $config, $db, $cache, $phpbb_dispatcher;
$update_ary = array(
FORUMS_TABLE => array('forum_last_poster_name'),
@@ -137,6 +137,17 @@ function user_update_name($old_name, $new_name)
set_config('newest_username', $new_name, true);
}
+ /**
+ * Update a username when it is changed
+ *
+ * @event core.update_username
+ * @var string old_name The old username that is replaced
+ * @var string new_name The new username
+ * @since 3.1-A1
+ */
+ $vars = array('old_name', 'new_name');
+ extract($phpbb_dispatcher->trigger_event('core.update_username', compact($vars)));
+
// Because some tables/caches use username-specific data we need to purge this here.
$cache->destroy('sql', MODERATOR_CACHE_TABLE);
}
@@ -331,7 +342,7 @@ function user_add($user_row, $cp_data = false)
*/
function user_delete($mode, $user_id, $post_username = false)
{
- global $cache, $config, $db, $user, $auth;
+ global $cache, $config, $db, $user, $auth, $phpbb_dispatcher;
global $phpbb_root_path, $phpEx;
$sql = 'SELECT *
@@ -346,6 +357,18 @@ function user_delete($mode, $user_id, $post_username = false)
return false;
}
+ /**
+ * Event before a user is deleted
+ *
+ * @event core.delete_user_before
+ * @var string mode Mode of deletion (retain/delete posts)
+ * @var int user_id ID of the deleted user
+ * @var mixed post_username Guest username that is being used or false
+ * @since 3.1-A1
+ */
+ $vars = array('mode', 'user_id', 'post_username');
+ extract($phpbb_dispatcher->trigger_event('core.delete_user_before', compact($vars)));
+
// Before we begin, we will remove the reports the user issued.
$sql = 'SELECT r.post_id, p.topic_id
FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
@@ -535,6 +558,18 @@ function user_delete($mode, $user_id, $post_username = false)
$db->sql_transaction('commit');
+ /**
+ * Event after a user is deleted
+ *
+ * @event core.delete_user_after
+ * @var string mode Mode of deletion (retain/delete posts)
+ * @var int user_id ID of the deleted user
+ * @var mixed post_username Guest username that is being used or false
+ * @since 3.1-A1
+ */
+ $vars = array('mode', 'user_id', 'post_username');
+ extract($phpbb_dispatcher->trigger_event('core.delete_user_after', compact($vars)));
+
// Reset newest user info if appropriate
if ($config['newest_user_id'] == $user_id)
{
@@ -2759,7 +2794,7 @@ function avatar_remove_db($avatar_name)
*/
function group_delete($group_id, $group_name = false)
{
- global $db, $phpbb_root_path, $phpEx;
+ global $db, $phpbb_root_path, $phpEx, $phpbb_dispatcher;
if (!$group_name)
{
@@ -2818,6 +2853,17 @@ function group_delete($group_id, $group_name = false)
WHERE group_id = $group_id";
$db->sql_query($sql);
+ /**
+ * Event after a group is deleted
+ *
+ * @event core.delete_group_after
+ * @var int group_id ID of the deleted group
+ * @var string group_name Name of the deleted group
+ * @since 3.1-A1
+ */
+ $vars = array('group_id', 'group_name');
+ extract($phpbb_dispatcher->trigger_event('core.delete_group_after', compact($vars)));
+
// Re-cache moderators
if (!function_exists('cache_moderators'))
{
@@ -2940,7 +2986,7 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false,
*/
function group_user_del($group_id, $user_id_ary = false, $username_ary = false, $group_name = false)
{
- global $db, $auth, $config;
+ global $db, $auth, $config, $phpbb_dispatcher;
if ($config['coppa_enable'])
{
@@ -3039,6 +3085,19 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false,
}
unset($special_group_data);
+ /**
+ * Event before users are removed from a group
+ *
+ * @event core.group_delete_user_before
+ * @var int group_id ID of the group from which users are deleted
+ * @var string group_name Name of the group
+ * @var array user_id_ary IDs of the users which are removed
+ * @var array username_ary names of the users which are removed
+ * @since 3.1-A1
+ */
+ $vars = array('group_id', 'group_name', 'user_id_ary', 'username_ary');
+ extract($phpbb_dispatcher->trigger_event('core.group_delete_user_before', compact($vars)));
+
$sql = 'DELETE FROM ' . USER_GROUP_TABLE . "
WHERE group_id = $group_id
AND " . $db->sql_in_set('user_id', $user_id_ary);
@@ -3356,7 +3415,7 @@ function group_validate_groupname($group_id, $group_name)
*/
function group_set_user_default($group_id, $user_id_ary, $group_attributes = false, $update_listing = false)
{
- global $cache, $db;
+ global $cache, $db, $phpbb_dispatcher;
if (empty($user_id_ary))
{
@@ -3452,6 +3511,20 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal
}
}
+ /**
+ * Event when the default group is set for an array of users
+ *
+ * @event core.user_set_default_group
+ * @var int group_id ID of the group
+ * @var array user_id_ary IDs of the users
+ * @var array group_attributes Group attributes which were changed
+ * @var array update_listing Update the list of moderators and foes
+ * @var array sql_ary User attributes which were changed
+ * @since 3.1-A1
+ */
+ $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary');
+ extract($phpbb_dispatcher->trigger_event('core.user_set_default_group', compact($vars)));
+
if ($update_listing)
{
group_update_listings($group_id);
diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php
index 4518e7b7cf..7b3bc82093 100644
--- a/phpBB/includes/mcp/mcp_forum.php
+++ b/phpBB/includes/mcp/mcp_forum.php
@@ -22,7 +22,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
{
global $template, $db, $user, $auth, $cache, $module;
global $phpEx, $phpbb_root_path, $config;
- global $request;
+ global $request, $phpbb_dispatcher;
$user->add_lang(array('viewtopic', 'viewforum'));
@@ -288,6 +288,17 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
));
}
+ /**
+ * Modify the topic data before it is assigned to the template in MCP
+ *
+ * @event core.mcp_view_forum_modify_topicrow
+ * @var array row Array with topic data
+ * @var array topic_row Template array with topic data
+ * @since 3.1-A1
+ */
+ $vars = array('row', 'topic_row');
+ extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_topicrow', compact($vars)));
+
$template->assign_block_vars('topicrow', $topic_row);
}
unset($topic_rows);
diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php
index a21c67924d..95ca7c2e1b 100644
--- a/phpBB/includes/mcp/mcp_main.php
+++ b/phpBB/includes/mcp/mcp_main.php
@@ -915,7 +915,7 @@ function mcp_fork_topic($topic_ids)
}
$error = false;
- $search = new $search_type($error);
+ $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
$search_mode = 'post';
if ($error)
diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php
index 2a52a858b3..520c964228 100644
--- a/phpBB/includes/mcp/mcp_post.php
+++ b/phpBB/includes/mcp/mcp_post.php
@@ -393,7 +393,7 @@ function mcp_post_details($id, $mode, $action)
*/
function change_poster(&$post_info, $userdata)
{
- global $auth, $db, $config, $phpbb_root_path, $phpEx;
+ global $auth, $db, $config, $phpbb_root_path, $phpEx, $user;
if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
{
@@ -470,7 +470,7 @@ function change_poster(&$post_info, $userdata)
{
// We do some additional checks in the module to ensure it can actually be utilised
$error = false;
- $search = new $search_type($error);
+ $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if (!$error && method_exists($search, 'destroy_cache'))
{
diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php
index 20dcb74c0d..cf89ab1c24 100644
--- a/phpBB/includes/search/fulltext_mysql.php
+++ b/phpBB/includes/search/fulltext_mysql.php
@@ -22,17 +22,28 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_search_fulltext_mysql extends phpbb_search_base
{
- var $stats = array();
- var $word_length = array();
- var $split_words = array();
- var $search_query;
- var $common_words = array();
+ protected $stats = array();
+ protected $split_words = array();
+ protected $config;
+ protected $db;
+ protected $user;
+ public $word_length = array();
+ public $search_query;
+ public $common_words = array();
- public function __construct(&$error)
+ /**
+ * Constructor
+ * Creates a new phpbb_search_fulltext_mysql, which is used as a search backend.
+ *
+ * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
+ */
+ public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
- global $config;
+ $this->config = $config;
+ $this->db = $db;
+ $this->user = $user;
- $this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']);
+ $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']);
$error = false;
}
@@ -49,19 +60,19 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Checks for correct MySQL version and stores min/max word length in the config
+ *
+ * @return string|bool Language key of the error/incompatiblity occured
*/
- function init()
+ public function init()
{
- global $db, $user;
-
- if ($db->sql_layer != 'mysql4' && $db->sql_layer != 'mysqli')
+ if ($this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli')
{
- return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE'];
+ return $this->user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE'];
}
- $result = $db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\'');
- $info = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
+ $result = $this->db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\'');
+ $info = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
$engine = '';
if (isset($info['Engine']))
@@ -75,19 +86,19 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if ($engine != 'MyISAM')
{
- return $user->lang['FULLTEXT_MYSQL_NOT_MYISAM'];
+ return $this->user->lang['FULLTEXT_MYSQL_NOT_MYISAM'];
}
$sql = 'SHOW VARIABLES
LIKE \'ft\_%\'';
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
$mysql_info = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$mysql_info[$row['Variable_name']] = $row['Value'];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
set_config('fulltext_mysql_max_word_len', $mysql_info['ft_max_word_len']);
set_config('fulltext_mysql_min_word_len', $mysql_info['ft_min_word_len']);
@@ -103,10 +114,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* @param string $terms is either 'all' or 'any'
* @return bool false if no valid keywords were found and otherwise true
*/
- function split_keywords(&$keywords, $terms)
+ public function split_keywords(&$keywords, $terms)
{
- global $config, $user;
-
if ($terms == 'all')
{
$match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#(^|\s)\+#', '#(^|\s)-#', '#(^|\s)\|#');
@@ -125,9 +134,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$this->split_words = $matches[1];
// We limit the number of allowed keywords to minimize load on the database
- if ($config['max_num_search_keywords'] && sizeof($this->split_words) > $config['max_num_search_keywords'])
+ if ($this->config['max_num_search_keywords'] && sizeof($this->split_words) > $this->config['max_num_search_keywords'])
{
- trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], sizeof($this->split_words)));
+ trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], sizeof($this->split_words)));
}
// to allow phrase search, we need to concatenate quoted words
@@ -169,7 +178,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
// check word length
$clean_len = utf8_strlen(str_replace('*', '', $clean_word));
- if (($clean_len < $config['fulltext_mysql_min_word_len']) || ($clean_len > $config['fulltext_mysql_max_word_len']))
+ if (($clean_len < $this->config['fulltext_mysql_min_word_len']) || ($clean_len > $this->config['fulltext_mysql_max_word_len']))
{
$this->common_words[] = $word;
unset($this->split_words[$i]);
@@ -221,11 +230,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Turns text into an array of words
+ * @param string $text contains post text/subject
*/
- function split_message($text)
+ public function split_message($text)
{
- global $config;
-
// Split words
$text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text)));
$matches = array();
@@ -237,7 +245,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
for ($i = 0, $n = sizeof($text); $i < $n; $i++)
{
$text[$i] = trim($text[$i]);
- if (utf8_strlen($text[$i]) < $config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_mysql_max_word_len'])
+ if (utf8_strlen($text[$i]) < $this->config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_mysql_max_word_len'])
{
unset($text[$i]);
}
@@ -265,13 +273,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
- global $config, $db;
-
// No keywords? No posts.
if (!$this->search_query)
{
@@ -360,7 +364,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
else
{
- $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
+ $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
$sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : '';
@@ -370,11 +374,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (sizeof($author_ary) && $author_name)
{
// first one matches post of registered users, second one guests and deleted users
- $sql_author = ' AND (' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
+ $sql_author = ' AND (' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else if (sizeof($author_ary))
{
- $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary);
+ $sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary);
}
else
{
@@ -384,7 +388,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sql_where_options = $sql_sort_join;
$sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : '';
$sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : '';
- $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
+ $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_where_options .= $m_approve_fid_sql;
$sql_where_options .= $sql_author;
$sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
@@ -392,16 +396,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sql = "SELECT $sql_select
FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p
- WHERE MATCH ($sql_match) AGAINST ('" . $db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE)
+ WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE)
$sql_where_options
ORDER BY $sql_sort";
- $result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
+ $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
$id_ary = array_unique($id_ary);
@@ -414,9 +418,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (!$result_count)
{
$sql = 'SELECT FOUND_ROWS() as result_count';
- $result = $db->sql_query($sql);
- $result_count = (int) $db->sql_fetchfield('result_count');
- $db->sql_freeresult($result);
+ $result = $this->db->sql_query($sql);
+ $result_count = (int) $this->db->sql_fetchfield('result_count');
+ $this->db->sql_freeresult($result);
if (!$result_count)
{
@@ -449,13 +453,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
- global $config, $db;
-
// No author? No posts.
if (!sizeof($author_ary))
{
@@ -491,13 +491,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
- $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
+ $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
- $sql_author = $db->sql_in_set('p.poster_id', $author_ary);
+ $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
- $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
+ $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';
@@ -533,7 +533,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
else
{
- $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
+ $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
// If the cache was completely empty count the results
@@ -572,21 +572,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
// Only read one block of posts from the db and then cache it
- $result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
+ $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
// retrieve the total result count if needed
if (!$result_count)
{
$sql = 'SELECT FOUND_ROWS() as result_count';
- $result = $db->sql_query($sql);
- $result_count = (int) $db->sql_fetchfield('result_count');
- $db->sql_freeresult($result);
+ $result = $this->db->sql_query($sql);
+ $result_count = (int) $this->db->sql_fetchfield('result_count');
+ $this->db->sql_freeresult($result);
if (!$result_count)
{
@@ -607,12 +607,15 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Destroys cached search results, that contained one of the new words in a post so the results won't be outdated.
*
- * @param string $mode contains the post mode: edit, post, reply, quote ...
+ * @param string $mode contains the post mode: edit, post, reply, quote ...
+ * @param int $post_id contains the post id of the post to index
+ * @param string $message contains the post text of the post
+ * @param string $subject contains the subject of the post to index
+ * @param int $poster_id contains the user id of the poster
+ * @param int $forum_id contains the forum id of parent forum of the post
*/
- function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
+ public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
- global $db;
-
// Split old and new post/subject to obtain array of words
$split_text = $this->split_message($message);
$split_title = ($subject) ? $this->split_message($subject) : array();
@@ -631,7 +634,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Destroy cached results, that might be outdated after deleting a post
*/
- function index_remove($post_ids, $author_ids, $forum_ids)
+ public function index_remove($post_ids, $author_ids, $forum_ids)
{
$this->destroy_cache(array(), array_unique($author_ids));
}
@@ -639,10 +642,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Destroy old cache entries
*/
- function tidy()
+ public function tidy()
{
- global $db, $config;
-
// destroy too old cached search results
$this->destroy_cache(array());
@@ -651,11 +652,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Create fulltext index
+ *
+ * @return string|bool error string is returned incase of errors otherwise false
*/
- function create_index($acp_module, $u_action)
+ public function create_index($acp_module, $u_action)
{
- global $db;
-
// Make sure we can actually use MySQL with fulltext indexes
if ($error = $this->init())
{
@@ -671,7 +672,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (!isset($this->stats['post_subject']))
{
- if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>='))
+ if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
{
$alter[] = 'MODIFY post_subject varchar(255) COLLATE utf8_unicode_ci DEFAULT \'\' NOT NULL';
}
@@ -684,7 +685,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (!isset($this->stats['post_text']))
{
- if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>='))
+ if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
{
$alter[] = 'MODIFY post_text mediumtext COLLATE utf8_unicode_ci NOT NULL';
}
@@ -702,21 +703,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (sizeof($alter))
{
- $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
+ $this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}
- $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
+ $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
/**
* Drop fulltext index
+ *
+ * @return string|bool error string is returned incase of errors otherwise false
*/
- function delete_index($acp_module, $u_action)
+ public function delete_index($acp_module, $u_action)
{
- global $db;
-
// Make sure we can actually use MySQL with fulltext indexes
if ($error = $this->init())
{
@@ -747,10 +748,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (sizeof($alter))
{
- $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
+ $this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}
- $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
+ $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
@@ -758,7 +759,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Returns true if both FULLTEXT indexes exist
*/
- function index_created()
+ public function index_created()
{
if (empty($this->stats))
{
@@ -771,25 +772,24 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Returns an associative array containing information about the indexes
*/
- function index_stats()
+ public function index_stats()
{
- global $user;
-
if (empty($this->stats))
{
$this->get_stats();
}
return array(
- $user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
+ $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
);
}
- function get_stats()
+ /**
+ * Computes the stats and store them in the $this->stats associative array
+ */
+ protected function get_stats()
{
- global $db;
-
- if (strpos($db->sql_layer, 'mysql') === false)
+ if (strpos($this->db->sql_layer, 'mysql') === false)
{
$this->stats = array();
return;
@@ -797,9 +797,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sql = 'SHOW INDEX
FROM ' . POSTS_TABLE;
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
// deal with older MySQL versions which didn't use Index_type
$index_type = (isset($row['Index_type'])) ? $row['Index_type'] : $row['Comment'];
@@ -820,26 +820,26 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
}
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
- $this->stats['total_posts'] = empty($this->stats) ? 0 : $db->get_estimated_row_count(POSTS_TABLE);
+ $this->stats['total_posts'] = empty($this->stats) ? 0 : $this->db->get_estimated_row_count(POSTS_TABLE);
}
/**
* Display a note, that UTF-8 support is not available with certain versions of PHP
+ *
+ * @return associative array containing template and config variables
*/
- function acp()
+ public function acp()
{
- global $user, $config;
-
$tpl = '
<dl>
- <dt><label>' . $user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
- <dd>' . $config['fulltext_mysql_min_word_len'] . '</dd>
+ <dt><label>' . $this->user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
+ <dd>' . $this->config['fulltext_mysql_min_word_len'] . '</dd>
</dl>
<dl>
- <dt><label>' . $user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
- <dd>' . $config['fulltext_mysql_max_word_len'] . '</dd>
+ <dt><label>' . $this->user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
+ <dd>' . $this->config['fulltext_mysql_max_word_len'] . '</dd>
</dl>
';
diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php
index 1e2074b1b1..96b3f02ec6 100644
--- a/phpBB/includes/search/fulltext_native.php
+++ b/phpBB/includes/search/fulltext_native.php
@@ -22,32 +22,42 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_search_fulltext_native extends phpbb_search_base
{
- var $stats = array();
- var $word_length = array();
- var $search_query;
- var $common_words = array();
+ protected $stats = array();
+ public $word_length = array();
+ public $search_query;
+ public $common_words = array();
- var $must_contain_ids = array();
- var $must_not_contain_ids = array();
- var $must_exclude_one_ids = array();
+ protected $must_contain_ids = array();
+ protected $must_not_contain_ids = array();
+ protected $must_exclude_one_ids = array();
+
+ protected $phpbb_root_path;
+ protected $php_ext;
+ protected $config;
+ protected $db;
+ protected $user;
/**
* Initialises the fulltext_native search backend with min/max word length and makes sure the UTF-8 normalizer is loaded.
*
* @param boolean|string &$error is passed by reference and should either be set to false on success or an error message on failure.
*/
- public function __construct(&$error)
+ public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
- global $phpbb_root_path, $phpEx, $config;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $phpEx;
+ $this->config = $config;
+ $this->db = $db;
+ $this->user = $user;
- $this->word_length = array('min' => $config['fulltext_native_min_chars'], 'max' => $config['fulltext_native_max_chars']);
+ $this->word_length = array('min' => $this->config['fulltext_native_min_chars'], 'max' => $this->config['fulltext_native_max_chars']);
/**
* Load the UTF tools
*/
if (!class_exists('utf_normalizer'))
{
- include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
+ include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->php_ext);
}
$error = false;
@@ -77,13 +87,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* @param string $terms is either 'all' (use search query as entered, default words to 'must be contained in post')
* or 'any' (find all posts containing at least one of the given words)
* @return boolean false if no valid keywords were found and otherwise true
- *
- * @access public
*/
- function split_keywords($keywords, $terms)
+ public function split_keywords($keywords, $terms)
{
- global $db, $user, $config;
-
$tokens = '+-|()*';
$keywords = trim($this->cleanup($keywords, $tokens));
@@ -182,9 +188,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$num_keywords = sizeof(explode(' ', $keywords));
// We limit the number of allowed keywords to minimize load on the database
- if ($config['max_num_search_keywords'] && $num_keywords > $config['max_num_search_keywords'])
+ if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords'])
{
- trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], $num_keywords));
+ trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], $num_keywords));
}
// $keywords input format: each word separated by a space, words in a bracket are not separated
@@ -214,12 +220,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql = 'SELECT word_id, word_text, word_common
FROM ' . SEARCH_WORDLIST_TABLE . '
- WHERE ' . $db->sql_in_set('word_text', $exact_words) . '
+ WHERE ' . $this->db->sql_in_set('word_text', $exact_words) . '
ORDER BY word_count ASC';
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
// store an array of words and ids, remove common words
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
if ($row['word_common'])
{
@@ -230,7 +236,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$words[$row['word_text']] = (int) $row['word_id'];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
}
unset($exact_words);
@@ -301,7 +307,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
if (strpos($word_part, '*') !== false)
{
- $id_words[] = '\'' . $db->sql_escape(str_replace('*', '%', $word_part)) . '\'';
+ $id_words[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word_part)) . '\'';
$non_common_words[] = $word_part;
}
else if (isset($words[$word_part]))
@@ -346,7 +352,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$len = utf8_strlen(str_replace('*', '', $word));
if ($len >= $this->word_length['min'] && $len <= $this->word_length['max'])
{
- $this->{$mode . '_ids'}[] = '\'' . $db->sql_escape(str_replace('*', '%', $word)) . '\'';
+ $this->{$mode . '_ids'}[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word)) . '\'';
}
else
{
@@ -366,7 +372,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$len = utf8_strlen($word);
if ($len >= $this->word_length['min'] && $len <= $this->word_length['max'])
{
- trigger_error(sprintf($user->lang['WORD_IN_NO_POST'], $word));
+ trigger_error(sprintf($this->user->lang['WORD_IN_NO_POST'], $word));
}
else
{
@@ -416,13 +422,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
- global $config, $db;
-
// No keywords? No posts.
if (empty($this->search_query))
{
@@ -537,7 +539,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
}
- $sql_where[] = $db->sql_in_set("m$m_num.word_id", $word_ids);
+ $sql_where[] = $this->db->sql_in_set("m$m_num.word_id", $word_ids);
unset($word_id_sql);
unset($word_ids);
@@ -591,7 +593,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num),
- 'ON' => $db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id"
+ 'ON' => $this->db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id"
);
$sql_where[] = "m$m_num.word_id IS NULL";
@@ -632,7 +634,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
else if ($m_approve_fid_ary !== array(-1))
{
- $sql_where[] = '(p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
+ $sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
if ($topic_id)
@@ -645,18 +647,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
- $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
+ $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
- $sql_author = $db->sql_in_set('p.poster_id', $author_ary);
+ $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
$sql_where[] = $sql_author;
}
if (sizeof($ex_fid_ary))
{
- $sql_where[] = $db->sql_in_set('p.forum_id', $ex_fid_ary, true);
+ $sql_where[] = $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true);
}
if ($sort_days)
@@ -681,7 +683,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
);
}
- switch ($db->sql_layer)
+ switch ($this->db->sql_layer)
{
case 'mysql4':
case 'mysqli':
@@ -695,17 +697,17 @@ class phpbb_search_fulltext_native extends phpbb_search_base
case 'sqlite':
$sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id';
$sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results
- FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')';
+ FROM (' . $this->db->sql_build_query('SELECT', $sql_array_count) . ')';
// no break
default:
$sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results';
- $sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql;
+ $sql = (!$sql) ? $this->db->sql_build_query('SELECT', $sql_array_count) : $sql;
- $result = $db->sql_query($sql);
- $total_results = (int) $db->sql_fetchfield('total_results');
- $db->sql_freeresult($result);
+ $result = $this->db->sql_query($sql);
+ $total_results = (int) $this->db->sql_fetchfield('total_results');
+ $this->db->sql_freeresult($result);
if (!$total_results)
{
@@ -751,14 +753,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base
unset($sql_where, $sql_sort, $group_by);
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
+ $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
if (!sizeof($id_ary))
{
@@ -772,16 +774,16 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sql_array_copy = $sql_array;
$sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id ';
- $sql = $db->sql_build_query('SELECT', $sql_array_copy);
+ $sql = $this->db->sql_build_query('SELECT', $sql_array_copy);
unset($sql_array_copy);
- $db->sql_query($sql);
- $db->sql_freeresult($result);
+ $this->db->sql_query($sql);
+ $this->db->sql_freeresult($result);
$sql = 'SELECT FOUND_ROWS() as total_results';
- $result = $db->sql_query($sql);
- $total_results = (int) $db->sql_fetchfield('total_results');
- $db->sql_freeresult($result);
+ $result = $this->db->sql_query($sql);
+ $total_results = (int) $this->db->sql_fetchfield('total_results');
+ $this->db->sql_freeresult($result);
if (!$total_results)
{
@@ -814,13 +816,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
- global $config, $db;
-
// No author? No posts.
if (!sizeof($author_ary))
{
@@ -856,13 +854,13 @@ class phpbb_search_fulltext_native extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
- $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
+ $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
- $sql_author = $db->sql_in_set('p.poster_id', $author_ary);
+ $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
- $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
+ $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';
@@ -898,7 +896,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
else
{
- $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
+ $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
$select = ($type == 'posts') ? 'p.post_id' : 't.topic_id';
@@ -907,7 +905,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
// If the cache was completely empty count the results
if (!$total_results)
{
- switch ($db->sql_layer)
+ switch ($this->db->sql_layer)
{
case 'mysql4':
case 'mysqli':
@@ -929,7 +927,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
else
{
- if ($db->sql_layer == 'sqlite')
+ if ($this->db->sql_layer == 'sqlite')
{
$sql = 'SELECT COUNT(topic_id) as total_results
FROM (SELECT DISTINCT t.topic_id';
@@ -946,12 +944,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$m_approve_fid_sql
$sql_fora
AND t.topic_id = p.topic_id
- $sql_time" . (($db->sql_layer == 'sqlite') ? ')' : '');
+ $sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : '');
}
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
- $total_results = (int) $db->sql_fetchfield('total_results');
- $db->sql_freeresult($result);
+ $total_results = (int) $this->db->sql_fetchfield('total_results');
+ $this->db->sql_freeresult($result);
if (!$total_results)
{
@@ -994,26 +992,26 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
// Only read one block of posts from the db and then cache it
- $result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
+ $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
if (!$total_results && $is_mysql)
{
// Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it.
$sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql);
- $db->sql_query($sql);
- $db->sql_freeresult($result);
+ $this->db->sql_query($sql);
+ $this->db->sql_freeresult($result);
$sql = 'SELECT FOUND_ROWS() as total_results';
- $result = $db->sql_query($sql);
- $total_results = (int) $db->sql_fetchfield('total_results');
- $db->sql_freeresult($result);
+ $result = $this->db->sql_query($sql);
+ $total_results = (int) $this->db->sql_fetchfield('total_results');
+ $this->db->sql_freeresult($result);
if (!$total_results)
{
@@ -1041,13 +1039,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*
* @param string $text Text to split, encoded in UTF-8
* @return array Array of UTF-8 words
- *
- * @access private
*/
- function split_message($text)
+ public function split_message($text)
{
- global $phpbb_root_path, $phpEx, $user;
-
$match = $words = array();
/**
@@ -1120,14 +1114,10 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* @param string &$subject New or updated post subject
* @param int $poster_id Post author's user id
* @param int $forum_id The id of the forum in which the post is located
- *
- * @access public
*/
- function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
+ public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
- global $config, $db, $user;
-
- if (!$config['fulltext_native_load_upd'])
+ if (!$this->config['fulltext_native_load_upd'])
{
/**
* The search indexer is disabled, return
@@ -1153,14 +1143,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base
FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m
WHERE m.post_id = $post_id
AND w.word_id = m.word_id";
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$which = ($row['title_match']) ? 'title' : 'post';
$cur_words[$which][$row['word_text']] = $row['word_id'];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
$words['add']['post'] = array_diff($split_text, array_keys($cur_words['post']));
$words['add']['title'] = array_diff($split_title, array_keys($cur_words['title']));
@@ -1188,18 +1178,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '
- WHERE ' . $db->sql_in_set('word_text', $unique_add_words);
- $result = $db->sql_query($sql);
+ WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words);
+ $result = $this->db->sql_query($sql);
$word_ids = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$word_ids[$row['word_text']] = $row['word_id'];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
$new_words = array_diff($unique_add_words, array_keys($word_ids));
- $db->sql_transaction('begin');
+ $this->db->sql_transaction('begin');
if (sizeof($new_words))
{
$sql_ary = array();
@@ -1208,15 +1198,15 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0);
}
- $db->sql_return_on_error(true);
- $db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
- $db->sql_return_on_error(false);
+ $this->db->sql_return_on_error(true);
+ $this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
+ $this->db->sql_return_on_error(false);
}
unset($new_words, $sql_ary);
}
else
{
- $db->sql_transaction('begin');
+ $this->db->sql_transaction('begin');
}
// now update the search match table, remove links to removed words and add links to new words
@@ -1233,22 +1223,22 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
- WHERE ' . $db->sql_in_set('word_id', $sql_in) . '
+ WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
AND post_id = ' . intval($post_id) . "
AND title_match = $title_match";
- $db->sql_query($sql);
+ $this->db->sql_query($sql);
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1
- WHERE ' . $db->sql_in_set('word_id', $sql_in) . '
+ WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
AND word_count > 0';
- $db->sql_query($sql);
+ $this->db->sql_query($sql);
unset($sql_in);
}
}
- $db->sql_return_on_error(true);
+ $this->db->sql_return_on_error(true);
foreach ($words['add'] as $word_in => $word_ary)
{
$title_match = ($word_in == 'title') ? 1 : 0;
@@ -1258,18 +1248,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match)
SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . '
FROM ' . SEARCH_WORDLIST_TABLE . '
- WHERE ' . $db->sql_in_set('word_text', $word_ary);
- $db->sql_query($sql);
+ WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
+ $this->db->sql_query($sql);
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count + 1
- WHERE ' . $db->sql_in_set('word_text', $word_ary);
- $db->sql_query($sql);
+ WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
+ $this->db->sql_query($sql);
}
}
- $db->sql_return_on_error(false);
+ $this->db->sql_return_on_error(false);
- $db->sql_transaction('commit');
+ $this->db->sql_transaction('commit');
// destroy cached search results containing any of the words removed or added
$this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id));
@@ -1282,20 +1272,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base
/**
* Removes entries from the wordmatch table for the specified post_ids
*/
- function index_remove($post_ids, $author_ids, $forum_ids)
+ public function index_remove($post_ids, $author_ids, $forum_ids)
{
- global $db;
-
if (sizeof($post_ids))
{
$sql = 'SELECT w.word_id, w.word_text, m.title_match
FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w
- WHERE ' . $db->sql_in_set('m.post_id', $post_ids) . '
+ WHERE ' . $this->db->sql_in_set('m.post_id', $post_ids) . '
AND w.word_id = m.word_id';
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
$message_word_ids = $title_word_ids = $word_texts = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
if ($row['title_match'])
{
@@ -1307,32 +1295,32 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
$word_texts[] = $row['word_text'];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
if (sizeof($title_word_ids))
{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1
- WHERE ' . $db->sql_in_set('word_id', $title_word_ids) . '
+ WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . '
AND word_count > 0';
- $db->sql_query($sql);
+ $this->db->sql_query($sql);
}
if (sizeof($message_word_ids))
{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1
- WHERE ' . $db->sql_in_set('word_id', $message_word_ids) . '
+ WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . '
AND word_count > 0';
- $db->sql_query($sql);
+ $this->db->sql_query($sql);
}
unset($title_word_ids);
unset($message_word_ids);
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
- WHERE ' . $db->sql_in_set('post_id', $post_ids);
- $db->sql_query($sql);
+ WHERE ' . $this->db->sql_in_set('post_id', $post_ids);
+ $this->db->sql_query($sql);
}
$this->destroy_cache(array_unique($word_texts), array_unique($author_ids));
@@ -1342,13 +1330,11 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* Tidy up indexes: Tag 'common words' and remove
* words no longer referenced in the match table
*/
- function tidy()
+ public function tidy()
{
- global $db, $config;
-
// Is the fulltext indexer disabled? If yes then we need not
// carry on ... it's okay ... I know when I'm not wanted boo hoo
- if (!$config['fulltext_native_load_upd'])
+ if (!$this->config['fulltext_native_load_upd'])
{
set_config('search_last_gc', time(), true);
return;
@@ -1357,31 +1343,31 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$destroy_cache_words = array();
// Remove common words
- if ($config['num_posts'] >= 100 && $config['fulltext_native_common_thres'])
+ if ($this->config['num_posts'] >= 100 && $this->config['fulltext_native_common_thres'])
{
- $common_threshold = ((double) $config['fulltext_native_common_thres']) / 100.0;
+ $common_threshold = ((double) $this->config['fulltext_native_common_thres']) / 100.0;
// First, get the IDs of common words
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '
- WHERE word_count > ' . floor($config['num_posts'] * $common_threshold) . '
+ WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . '
OR word_common = 1';
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
$sql_in = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$sql_in[] = $row['word_id'];
$destroy_cache_words[] = $row['word_text'];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
if (sizeof($sql_in))
{
// Flag the words
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_common = 1
- WHERE ' . $db->sql_in_set('word_id', $sql_in);
- $db->sql_query($sql);
+ WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
+ $this->db->sql_query($sql);
// by setting search_last_gc to the new time here we make sure that if a user reloads because the
// following query takes too long, he won't run into it again
@@ -1389,8 +1375,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base
// Delete the matches
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
- WHERE ' . $db->sql_in_set('word_id', $sql_in);
- $db->sql_query($sql);
+ WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
+ $this->db->sql_query($sql);
}
unset($sql_in);
}
@@ -1407,23 +1393,21 @@ class phpbb_search_fulltext_native extends phpbb_search_base
/**
* Deletes all words from the index
*/
- function delete_index($acp_module, $u_action)
+ public function delete_index($acp_module, $u_action)
{
- global $db;
-
- switch ($db->sql_layer)
+ switch ($this->db->sql_layer)
{
case 'sqlite':
case 'firebird':
- $db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE);
- $db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE);
- $db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE);
+ $this->db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE);
+ $this->db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE);
+ $this->db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE);
break;
default:
- $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE);
- $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
- $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
+ $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE);
+ $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
+ $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
break;
}
}
@@ -1431,7 +1415,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
/**
* Returns true if both FULLTEXT indexes exist
*/
- function index_created()
+ public function index_created()
{
if (!sizeof($this->stats))
{
@@ -1444,26 +1428,22 @@ class phpbb_search_fulltext_native extends phpbb_search_base
/**
* Returns an associative array containing information about the indexes
*/
- function index_stats()
+ public function index_stats()
{
- global $user;
-
if (!sizeof($this->stats))
{
$this->get_stats();
}
return array(
- $user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
- $user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
+ $this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
+ $this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
}
- function get_stats()
+ protected function get_stats()
{
- global $db;
-
- $this->stats['total_words'] = $db->get_estimated_row_count(SEARCH_WORDLIST_TABLE);
- $this->stats['total_matches'] = $db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE);
+ $this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE);
+ $this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE);
}
/**
@@ -1481,9 +1461,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*
* @todo normalizer::cleanup being able to be used?
*/
- function cleanup($text, $allowed_chars = null, $encoding = 'utf-8')
+ protected function cleanup($text, $allowed_chars = null, $encoding = 'utf-8')
{
- global $phpbb_root_path, $phpEx;
static $conv = array(), $conv_loaded = array();
$words = $allow = array();
@@ -1680,7 +1659,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
if (!isset($conv_loaded[$idx]))
{
$conv_loaded[$idx] = 1;
- $file = $phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $phpEx;
+ $file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->php_ext;
if (file_exists($file))
{
@@ -1711,31 +1690,28 @@ class phpbb_search_fulltext_native extends phpbb_search_base
/**
* Returns a list of options for the ACP to display
*/
- function acp()
+ public function acp()
{
- global $user, $config;
-
-
/**
* if we need any options, copied from fulltext_native for now, will have to be adjusted or removed
*/
$tpl = '
<dl>
- <dt><label for="fulltext_native_load_upd">' . $user->lang['YES_SEARCH_UPDATE'] . ':</label><br /><span>' . $user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '</span></dt>
- <dd><label><input type="radio" id="fulltext_native_load_upd" name="config[fulltext_native_load_upd]" value="1"' . (($config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $user->lang['YES'] . '</label><label><input type="radio" name="config[fulltext_native_load_upd]" value="0"' . ((!$config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $user->lang['NO'] . '</label></dd>
+ <dt><label for="fulltext_native_load_upd">' . $this->user->lang['YES_SEARCH_UPDATE'] . ':</label><br /><span>' . $this->user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '</span></dt>
+ <dd><label><input type="radio" id="fulltext_native_load_upd" name="config[fulltext_native_load_upd]" value="1"' . (($this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->user->lang['YES'] . '</label><label><input type="radio" name="config[fulltext_native_load_upd]" value="0"' . ((!$this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->user->lang['NO'] . '</label></dd>
</dl>
<dl>
- <dt><label for="fulltext_native_min_chars">' . $user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
- <dd><input id="fulltext_native_min_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_min_chars]" value="' . (int) $config['fulltext_native_min_chars'] . '" /></dd>
+ <dt><label for="fulltext_native_min_chars">' . $this->user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
+ <dd><input id="fulltext_native_min_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_min_chars]" value="' . (int) $this->config['fulltext_native_min_chars'] . '" /></dd>
</dl>
<dl>
- <dt><label for="fulltext_native_max_chars">' . $user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
- <dd><input id="fulltext_native_max_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_max_chars]" value="' . (int) $config['fulltext_native_max_chars'] . '" /></dd>
+ <dt><label for="fulltext_native_max_chars">' . $this->user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
+ <dd><input id="fulltext_native_max_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_max_chars]" value="' . (int) $this->config['fulltext_native_max_chars'] . '" /></dd>
</dl>
<dl>
- <dt><label for="fulltext_native_common_thres">' . $user->lang['COMMON_WORD_THRESHOLD'] . ':</label><br /><span>' . $user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '</span></dt>
- <dd><input id="fulltext_native_common_thres" type="text" size="3" maxlength="3" name="config[fulltext_native_common_thres]" value="' . (double) $config['fulltext_native_common_thres'] . '" /> %</dd>
+ <dt><label for="fulltext_native_common_thres">' . $this->user->lang['COMMON_WORD_THRESHOLD'] . ':</label><br /><span>' . $this->user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '</span></dt>
+ <dd><input id="fulltext_native_common_thres" type="text" size="3" maxlength="3" name="config[fulltext_native_common_thres]" value="' . (double) $this->config['fulltext_native_common_thres'] . '" /> %</dd>
</dl>
';
diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php
index 84ce674564..50ed785093 100644
--- a/phpBB/includes/search/fulltext_postgres.php
+++ b/phpBB/includes/search/fulltext_postgres.php
@@ -22,12 +22,15 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_search_fulltext_postgres extends phpbb_search_base
{
- private $stats = array();
- private $split_words = array();
- private $tsearch_usable = false;
- private $version;
- private $tsearch_query;
- private $phrase_search = false;
+ protected $stats = array();
+ protected $split_words = array();
+ protected $tsearch_usable = false;
+ protected $version;
+ protected $tsearch_query;
+ protected $phrase_search = false;
+ protected $config;
+ protected $db;
+ protected $user;
public $search_query;
public $common_words = array();
public $word_length = array();
@@ -38,16 +41,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*
* @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
*/
- public function __construct(&$error)
+ public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
- global $db, $config;
+ $this->config = $config;
+ $this->db = $db;
+ $this->user = $user;
- $this->word_length = array('min' => $config['fulltext_postgres_min_word_len'], 'max' => $config['fulltext_postgres_max_word_len']);
+ $this->word_length = array('min' => $this->config['fulltext_postgres_min_word_len'], 'max' => $this->config['fulltext_postgres_max_word_len']);
-
- if ($db->sql_layer == 'postgres')
+ if ($this->db->sql_layer == 'postgres')
{
- $pgsql_version = explode(',', substr($db->sql_server_info(), 10));
+ $pgsql_version = explode(',', substr($this->db->sql_server_info(), 10));
$this->version = trim($pgsql_version[0]);
if (version_compare($this->version, '8.3', '>='))
{
@@ -62,8 +66,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* Returns the name of this search backend to be displayed to administrators
*
* @return string Name
- *
- * @access public
*/
public function get_name()
{
@@ -74,8 +76,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* Returns if phrase search is supported or not
*
* @return bool
- *
- * @access public
*/
public function supports_phrase_search()
{
@@ -86,21 +86,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* Checks for correct PostgreSQL version and stores min/max word length in the config
*
* @return string|bool Language key of the error/incompatiblity occured
- *
- * @access public
*/
- function init()
+ public function init()
{
- global $db, $user;
-
- if ($db->sql_layer != 'postgres')
+ if ($this->db->sql_layer != 'postgres')
{
- return $user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE'];
+ return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE'];
}
if (!$this->tsearch_usable)
{
- return $user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE'];
+ return $this->user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE'];
}
return false;
@@ -113,13 +109,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* @param string &$keywords Contains the keyword as entered by the user
* @param string $terms is either 'all' or 'any'
* @return bool false if no valid keywords were found and otherwise true
- *
- * @access public
*/
- function split_keywords(&$keywords, $terms)
+ public function split_keywords(&$keywords, $terms)
{
- global $config;
-
if ($terms == 'all')
{
$match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#\+#', '#-#', '#\|#');
@@ -143,7 +135,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
// check word length
$clean_len = utf8_strlen(str_replace('*', '', $clean_word));
- if (($clean_len < $config['fulltext_postgres_min_word_len']) || ($clean_len > $config['fulltext_postgres_max_word_len']))
+ if (($clean_len < $this->config['fulltext_postgres_min_word_len']) || ($clean_len > $this->config['fulltext_postgres_max_word_len']))
{
$this->common_words[] = $word;
unset($this->split_words[$i]);
@@ -208,13 +200,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
/**
* Turns text into an array of words
* @param string $text contains post text/subject
- *
- * @access public
*/
- function split_message($text)
+ public function split_message($text)
{
- global $config;
-
// Split words
$text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text)));
$matches = array();
@@ -226,7 +214,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
for ($i = 0, $n = sizeof($text); $i < $n; $i++)
{
$text[$i] = trim($text[$i]);
- if (utf8_strlen($text[$i]) < $config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_postgres_max_word_len'])
+ if (utf8_strlen($text[$i]) < $this->config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_postgres_max_word_len'])
{
unset($text[$i]);
}
@@ -254,13 +242,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
- global $config, $db;
-
// No keywords? No posts.
if (!$this->search_query)
{
@@ -349,7 +333,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
}
else
{
- $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
+ $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
$sql_select = ($type == 'posts') ? 'p.post_id' : 'DISTINCT t.topic_id';
@@ -360,11 +344,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if (sizeof($author_ary) && $author_name)
{
// first one matches post of registered users, second one guests and deleted users
- $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
+ $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else if (sizeof($author_ary))
{
- $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary);
+ $sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary);
}
else
{
@@ -374,7 +358,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
$sql_where_options = $sql_sort_join;
$sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : '';
$sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : '';
- $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
+ $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_where_options .= $m_approve_fid_sql;
$sql_where_options .= $sql_author;
$sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
@@ -383,7 +367,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
$tmp_sql_match = array();
foreach (explode(',', $sql_match) as $sql_match_column)
{
- $tmp_sql_match[] = "to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', '" . $db->sql_escape($this->tsearch_query) . "')";
+ $tmp_sql_match[] = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')";
}
$sql = "SELECT $sql_select
@@ -391,13 +375,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
WHERE (" . implode(' OR ', $tmp_sql_match) . ")
$sql_where_options
ORDER BY $sql_sort";
- $result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
+ $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = $row[$field];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
$id_ary = array_unique($id_ary);
@@ -442,13 +426,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
- global $config, $db;
-
// No author? No posts.
if (!sizeof($author_ary))
{
@@ -484,13 +464,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
- $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
+ $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
- $sql_author = $db->sql_in_set('p.poster_id', $author_ary);
+ $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
- $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
+ $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';
@@ -526,7 +506,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
}
else
{
- $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
+ $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
// Build the query for really selecting the post_ids
@@ -562,13 +542,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
}
// Only read one block of posts from the db and then cache it
- $result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
+ $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = $row[$field];
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
// retrieve the total result count if needed
if (!$result_count)
@@ -600,13 +580,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* @param string $subject contains the subject of the post to index
* @param int $poster_id contains the user id of the poster
* @param int $forum_id contains the forum id of parent forum of the post
- *
- * @access public
*/
- function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
+ public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
- global $db;
-
// Split old and new post/subject to obtain array of words
$split_text = $this->split_message($message);
$split_title = ($subject) ? $this->split_message($subject) : array();
@@ -624,23 +600,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
/**
* Destroy cached results, that might be outdated after deleting a post
- *
- * @access public
*/
- function index_remove($post_ids, $author_ids, $forum_ids)
+ public function index_remove($post_ids, $author_ids, $forum_ids)
{
$this->destroy_cache(array(), $author_ids);
}
/**
* Destroy old cache entries
- *
- * @access public
*/
- function tidy()
+ public function tidy()
{
- global $db, $config;
-
// destroy too old cached search results
$this->destroy_cache(array());
@@ -651,13 +621,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* Create fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
- *
- * @access public
*/
- function create_index($acp_module, $u_action)
+ public function create_index($acp_module, $u_action)
{
- global $db, $config;
-
// Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init())
{
@@ -671,15 +637,15 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if (!isset($this->stats['post_subject']))
{
- $db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_subject))");
+ $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_subject))");
}
if (!isset($this->stats['post_text']))
{
- $db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_text))");
+ $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text))");
}
- $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
+ $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
@@ -688,13 +654,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
* Drop fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
- *
- * @access public
*/
- function delete_index($acp_module, $u_action)
+ public function delete_index($acp_module, $u_action)
{
- global $db;
-
// Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init())
{
@@ -708,25 +670,23 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if (isset($this->stats['post_subject']))
{
- $db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']);
+ $this->db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']);
}
if (isset($this->stats['post_text']))
{
- $db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']);
+ $this->db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']);
}
- $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
+ $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
/**
* Returns true if both FULLTEXT indexes exist
- *
- * @access public
*/
- function index_created()
+ public function index_created()
{
if (empty($this->stats))
{
@@ -738,33 +698,25 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
/**
* Returns an associative array containing information about the indexes
- *
- * @access public
*/
- function index_stats()
+ public function index_stats()
{
- global $user;
-
if (empty($this->stats))
{
$this->get_stats();
}
return array(
- $user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
+ $this->user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
);
}
/**
* Computes the stats and store them in the $this->stats associative array
- *
- * @access private
*/
- function get_stats()
+ protected function get_stats()
{
- global $db, $config;
-
- if ($db->sql_layer != 'postgres')
+ if ($this->db->sql_layer != 'postgres')
{
$this->stats = array();
return;
@@ -776,74 +728,70 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
AND pg_catalog.pg_table_is_visible(c1.oid)
AND c1.oid = i.indrelid
AND i.indexrelid = c2.oid";
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
// deal with older PostgreSQL versions which didn't use Index_type
if (strpos($row['indexdef'], 'to_tsvector') !== false)
{
- if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text')
+ if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text')
{
$this->stats['post_text'] = $row;
}
- else if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject')
+ else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject')
{
$this->stats['post_subject'] = $row;
}
}
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
- $this->stats['total_posts'] = $config['num_posts'];
+ $this->stats['total_posts'] = $this->config['num_posts'];
}
/**
* Display various options that can be configured for the backend from the acp
*
* @return associative array containing template and config variables
- *
- * @access public
*/
- function acp()
+ public function acp()
{
- global $user, $config, $db;
-
$tpl = '
<dl>
- <dt><label>' . $user->lang['FULLTEXT_POSTGRES_VERSION_CHECK'] . '</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '</span></dt>
- <dd>' . (($this->tsearch_usable) ? $user->lang['YES'] : $user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')</dd>
+ <dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '</span></dt>
+ <dd>' . (($this->tsearch_usable) ? $this->user->lang['YES'] : $this->user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')</dd>
</dl>
<dl>
- <dt><label>' . $user->lang['FULLTEXT_POSTGRES_TS_NAME'] . '</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '</span></dt>
+ <dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '</span></dt>
<dd><select name="config[fulltext_postgres_ts_name]">';
- if ($db->sql_layer == 'postgres' && $this->tsearch_usable)
+ if ($this->db->sql_layer == 'postgres' && $this->tsearch_usable)
{
$sql = 'SELECT cfgname AS ts_name
FROM pg_ts_config';
- $result = $db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = $this->db->sql_fetchrow($result))
{
- $tpl .= '<option value="' . $row['ts_name'] . '"' . ($row['ts_name'] === $config['fulltext_postgres_ts_name'] ? ' selected="selected"' : '') . '>' . $row['ts_name'] . '</option>';
+ $tpl .= '<option value="' . $row['ts_name'] . '"' . ($row['ts_name'] === $this->config['fulltext_postgres_ts_name'] ? ' selected="selected"' : '') . '>' . $row['ts_name'] . '</option>';
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
}
else
{
- $tpl .= '<option value="' . $config['fulltext_postgres_ts_name'] . '" selected="selected">' . $config['fulltext_postgres_ts_name'] . '</option>';
+ $tpl .= '<option value="' . $this->config['fulltext_postgres_ts_name'] . '" selected="selected">' . $this->config['fulltext_postgres_ts_name'] . '</option>';
}
$tpl .= '</select></dd>
</dl>
<dl>
- <dt><label for="fulltext_postgres_min_word_len">' . $user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN'] . ':</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '</span></dt>
- <dd><input id="fulltext_postgres_min_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_min_word_len]" value="' . (int) $config['fulltext_postgres_min_word_len'] . '" /></dd>
+ <dt><label for="fulltext_postgres_min_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '</span></dt>
+ <dd><input id="fulltext_postgres_min_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_min_word_len]" value="' . (int) $this->config['fulltext_postgres_min_word_len'] . '" /></dd>
</dl>
<dl>
- <dt><label for="fulltext_postgres_max_word_len">' . $user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN'] . ':</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '</span></dt>
- <dd><input id="fulltext_postgres_max_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_max_word_len]" value="' . (int) $config['fulltext_postgres_max_word_len'] . '" /></dd>
+ <dt><label for="fulltext_postgres_max_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '</span></dt>
+ <dd><input id="fulltext_postgres_max_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_max_word_len]" value="' . (int) $this->config['fulltext_postgres_max_word_len'] . '" /></dd>
</dl>
';
diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php
index 8371f6b377..288c0b5940 100644
--- a/phpBB/includes/search/fulltext_sphinx.php
+++ b/phpBB/includes/search/fulltext_sphinx.php
@@ -17,13 +17,6 @@ if (!defined('IN_PHPBB'))
/**
* @ignore
*/
-/**
-* This statement is necessary as this file is sometimes included from within a
-* function and the variables used are in global space.
-*/
-global $phpbb_root_path, $phpEx, $table_prefix;
-require($phpbb_root_path . 'includes/sphinxapi.' . $phpEx);
-
define('SPHINX_MAX_MATCHES', 20000);
define('SPHINX_CONNECT_RETRIES', 3);
define('SPHINX_CONNECT_WAIT_TIME', 300);
@@ -35,18 +28,20 @@ define('SPHINX_CONNECT_WAIT_TIME', 300);
*/
class phpbb_search_fulltext_sphinx
{
- private $stats = array();
- private $split_words = array();
- private $id;
- private $indexes;
- private $sphinx;
- private $auth;
- private $config;
- private $db;
- private $db_tools;
- private $dbtype;
- private $user;
- private $config_file_data = '';
+ protected $stats = array();
+ protected $split_words = array();
+ protected $id;
+ protected $indexes;
+ protected $sphinx;
+ protected $phpbb_root_path;
+ protected $php_ext;
+ protected $auth;
+ protected $config;
+ protected $db;
+ protected $db_tools;
+ protected $dbtype;
+ protected $user;
+ protected $config_file_data = '';
public $search_query;
public $common_words = array();
@@ -56,9 +51,10 @@ class phpbb_search_fulltext_sphinx
*
* @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
*/
- public function __construct(&$error)
+ public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
- global $config, $db, $user, $auth, $phpbb_root_path, $phpEx;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $phpEx;
$this->config = $config;
$this->user = $user;
$this->db = $db;
@@ -66,7 +62,7 @@ class phpbb_search_fulltext_sphinx
if (!class_exists('phpbb_db_tools'))
{
- require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
+ require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->php_ext);
}
// Initialize phpbb_db_tools object
@@ -79,6 +75,12 @@ class phpbb_search_fulltext_sphinx
$this->id = $this->config['fulltext_sphinx_id'];
$this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main';
+ if (!class_exists('SphinxClient'))
+ {
+ require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->php_ext);
+ }
+
+ // Initialize sphinx client
$this->sphinx = new SphinxClient();
$this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 9312));
@@ -90,8 +92,6 @@ class phpbb_search_fulltext_sphinx
* Returns the name of this search backend to be displayed to administrators
*
* @return string Name
- *
- * @access public
*/
public function get_name()
{
@@ -102,10 +102,8 @@ class phpbb_search_fulltext_sphinx
* Checks permissions and paths, if everything is correct it generates the config file
*
* @return string|bool Language key of the error/incompatiblity encountered, or false if successful
- *
- * @access public
*/
- function init()
+ public function init()
{
if ($this->db->sql_layer != 'mysql' && $this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli' && $this->db->sql_layer != 'postgres')
{
@@ -122,13 +120,9 @@ class phpbb_search_fulltext_sphinx
* Generates content of sphinx.conf
*
* @return bool True if sphinx.conf content is correctly generated, false otherwise
- *
- * @access private
*/
- function config_generate()
+ protected function config_generate()
{
- global $phpbb_root_path, $phpEx;
-
// Check if Database is supported by Sphinx
if ($this->db->sql_layer =='mysql' || $this->db->sql_layer == 'mysql4' || $this->db->sql_layer == 'mysqli')
{
@@ -151,7 +145,7 @@ class phpbb_search_fulltext_sphinx
return false;
}
- include($phpbb_root_path . 'config.' . $phpEx);
+ include($this->phpbb_root_path . 'config.' . $this->php_ext);
/* Now that we're sure everything was entered correctly,
generate a config for the index. We use a config value
@@ -306,10 +300,8 @@ class phpbb_search_fulltext_sphinx
* @param string $keywords Contains the keyword as entered by the user
* @param string $terms is either 'all' or 'any'
* @return false if no valid keywords were found and otherwise true
- *
- * @access public
*/
- function split_keywords(&$keywords, $terms)
+ public function split_keywords(&$keywords, $terms)
{
if ($terms == 'all')
{
@@ -356,10 +348,8 @@ class phpbb_search_fulltext_sphinx
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
// No keywords? No posts.
if (!strlen($this->search_query) && !sizeof($author_ary))
@@ -495,12 +485,25 @@ class phpbb_search_fulltext_sphinx
// Could be connection to localhost:9312 failed (errno=111,
// msg=Connection refused) during rotate, retry if so
$retries = SPHINX_CONNECT_RETRIES;
- while (!$result && (strpos($this->sphinx->_error, "errno=111,") !== false) && $retries--)
+ while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--)
{
usleep(SPHINX_CONNECT_WAIT_TIME);
$result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
}
+ if ($this->sphinx->GetLastError())
+ {
+ add_log('critical', 'LOG_SPHINX_ERROR', $this->sphinx->GetLastError());
+ if ($this->auth->acl_get('a_'))
+ {
+ trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError()));
+ }
+ else
+ {
+ trigger_error($this->user->lang('SPHINX_SEARCH_FAILED_LOG'));
+ }
+ }
+
$id_ary = array();
if (isset($result['matches']))
{
@@ -546,10 +549,8 @@ class phpbb_search_fulltext_sphinx
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
- *
- * @access public
*/
- function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
$this->search_query = '';
@@ -568,10 +569,8 @@ class phpbb_search_fulltext_sphinx
* @param string &$subject New or updated post subject
* @param int $poster_id Post author's user id
* @param int $forum_id The id of the forum in which the post is located
- *
- * @access public
*/
- function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
+ public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
if ($mode == 'edit')
{
@@ -613,10 +612,8 @@ class phpbb_search_fulltext_sphinx
/**
* Delete a post from the index after it was deleted
- *
- * @access public
*/
- function index_remove($post_ids, $author_ids, $forum_ids)
+ public function index_remove($post_ids, $author_ids, $forum_ids)
{
$values = array();
foreach ($post_ids as $post_id)
@@ -629,10 +626,8 @@ class phpbb_search_fulltext_sphinx
/**
* Nothing needs to be destroyed
- *
- * @access public
*/
- function tidy($create = false)
+ public function tidy($create = false)
{
set_config('search_last_gc', time(), true);
}
@@ -641,10 +636,8 @@ class phpbb_search_fulltext_sphinx
* Create sphinx table
*
* @return string|bool error string is returned incase of errors otherwise false
- *
- * @access public
*/
- function create_index($acp_module, $u_action)
+ public function create_index($acp_module, $u_action)
{
if (!$this->index_created())
{
@@ -675,10 +668,8 @@ class phpbb_search_fulltext_sphinx
* Drop sphinx table
*
* @return string|bool error string is returned incase of errors otherwise false
- *
- * @access public
*/
- function delete_index($acp_module, $u_action)
+ public function delete_index($acp_module, $u_action)
{
if (!$this->index_created())
{
@@ -694,10 +685,8 @@ class phpbb_search_fulltext_sphinx
* Returns true if the sphinx table was created
*
* @return bool true if sphinx table was created
- *
- * @access public
*/
- function index_created($allow_new_files = true)
+ public function index_created($allow_new_files = true)
{
$created = false;
@@ -713,10 +702,8 @@ class phpbb_search_fulltext_sphinx
* Returns an associative array containing information about the indexes
*
* @return string|bool Language string of error false otherwise
- *
- * @access public
*/
- function index_stats()
+ public function index_stats()
{
if (empty($this->stats))
{
@@ -732,10 +719,8 @@ class phpbb_search_fulltext_sphinx
/**
* Collects stats that can be displayed on the index maintenance page
- *
- * @access private
*/
- function get_stats()
+ protected function get_stats()
{
if ($this->index_created())
{
@@ -759,10 +744,8 @@ class phpbb_search_fulltext_sphinx
* Returns a list of options for the ACP to display
*
* @return associative array containing template and config variables
- *
- * @access public
*/
- function acp()
+ public function acp()
{
$config_vars = array(
'fulltext_sphinx_data_path' => 'string',
diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php
index 13fa845659..b7c3e00dee 100644
--- a/phpBB/includes/template/template.php
+++ b/phpBB/includes/template/template.php
@@ -139,7 +139,7 @@ class phpbb_template
*/
public function display($handle)
{
- $result = $this->call_hook($handle);
+ $result = $this->call_hook($handle, __FUNCTION__);
if ($result !== false)
{
return $result[0];
@@ -174,16 +174,17 @@ class phpbb_template
* Calls hook if any is defined.
*
* @param string $handle Template handle being displayed.
+ * @param string $method Method name of the caller.
*/
- private function call_hook($handle)
+ private function call_hook($handle, $method)
{
global $phpbb_hook;
- if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $this))
+ if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this))
{
- if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__)))
+ if ($phpbb_hook->hook_return(array(__CLASS__, $method)))
{
- $result = $phpbb_hook->hook_return_result(array(__CLASS__, __FUNCTION__));
+ $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method));
return array($result);
}
}
diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php
index c55e8850a6..c85b05f144 100644
--- a/phpBB/includes/ucp/ucp_pm_viewmessage.php
+++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php
@@ -21,7 +21,7 @@ if (!defined('IN_PHPBB'))
function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
{
global $user, $template, $auth, $db, $cache;
- global $phpbb_root_path, $request, $phpEx, $config;
+ global $phpbb_root_path, $request, $phpEx, $config, $phpbb_dispatcher;
$user->add_lang(array('viewtopic', 'memberlist'));
@@ -204,7 +204,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
}
}
- $template->assign_vars(array(
+ $msg_data = array(
'MESSAGE_AUTHOR_FULL' => get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
'MESSAGE_AUTHOR' => get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
@@ -257,6 +257,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
'U_PM_ACTION' => $url . '&amp;mode=compose&amp;f=' . $folder_id . '&amp;p=' . $message_row['msg_id'],
'S_HAS_ATTACHMENTS' => (sizeof($attachments)) ? true : false,
+ 'S_HAS_MULTIPLE_ATTACHMENTS' => (sizeof($attachments) > 1),
'S_DISPLAY_NOTICE' => $display_notice && $message_row['message_attachment'],
'S_AUTHOR_DELETED' => ($author_id == ANONYMOUS) ? true : false,
'S_SPECIAL_FOLDER' => in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
@@ -265,9 +266,28 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
'S_CUSTOM_FIELDS' => (!empty($cp_row['row'])) ? true : false,
'U_PRINT_PM' => ($config['print_pm'] && $auth->acl_get('u_pm_printpm')) ? "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=print" : '',
- 'U_FORWARD_PM' => ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&amp;mode=compose&amp;action=forward&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '')
+ 'U_FORWARD_PM' => ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&amp;mode=compose&amp;action=forward&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
);
+ /**
+ * Modify pm and sender data before it is assigned to the template
+ *
+ * @event core.ucp_pm_view_messsage
+ * @var mixed id Active module category (can be int or string)
+ * @var string mode Active module
+ * @var int folder_id ID of the folder the message is in
+ * @var int msg_id ID of the private message
+ * var array folder Array with data of user's message folders
+ * @var array message_row Array with message data
+ * @var array cp_row Array with senders custom profile field data
+ * @var array msg_data Template array with message data
+ * @since 3.1-A1
+ */
+ $vars = array('id', 'mode', 'folder_id', 'msg_id', 'folder', 'message_row', 'cp_row', 'msg_data');
+ extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_messsage', compact($vars)));
+
+ $template->assign_vars($msg_data);
+
// Display the custom profile fields
if (!empty($cp_row['row']))
{
@@ -282,6 +302,12 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
// Display not already displayed Attachments for this post, we already parsed them. ;)
if (isset($attachments) && sizeof($attachments))
{
+ $methods = phpbb_gen_download_links('post_msg_id', $msg_id, $phpbb_root_path, $phpEx);
+ foreach ($methods as $method)
+ {
+ $template->assign_block_vars('dl_method', $method);
+ }
+
foreach ($attachments as $attachment)
{
$template->assign_block_vars('attachment', array(
diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php
index efe928b387..a669c450a4 100644
--- a/phpBB/includes/ucp/ucp_zebra.php
+++ b/phpBB/includes/ucp/ucp_zebra.php
@@ -25,7 +25,7 @@ class ucp_zebra
function main($id, $mode)
{
- global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $request;
+ global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $request, $phpbb_dispatcher;
$submit = (isset($_POST['submit']) || isset($_GET['add']) || isset($_GET['remove'])) ? true : false;
$s_hidden_fields = '';
@@ -54,9 +54,22 @@ class ucp_zebra
// Remove users
if (!empty($data['usernames']))
{
+ $user_ids = $data['usernames'];
+
+ /**
+ * Remove users from friends/foes
+ *
+ * @event core.ucp_remove_zebra
+ * @var string mode Zebra type: friends|foes
+ * @var array user_ids User ids we remove
+ * @since 3.1-A1
+ */
+ $vars = array('user_ids');
+ extract($phpbb_dispatcher->trigger_event('core.ucp_remove_zebra', compact($vars)));
+
$sql = 'DELETE FROM ' . ZEBRA_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
- AND ' . $db->sql_in_set('zebra_id', $data['usernames']);
+ AND ' . $db->sql_in_set('zebra_id', $user_ids);
$db->sql_query($sql);
$updated = true;
@@ -186,6 +199,19 @@ class ucp_zebra
);
}
+ /**
+ * Add users to friends/foes
+ *
+ * @event core.ucp_add_zebra
+ * @var string mode Zebra type:
+ * friends|foes
+ * @var array sql_ary Array of
+ * entries we add
+ * @since 3.1-A1
+ */
+ $vars = array('mode', 'sql_ary');
+ extract($phpbb_dispatcher->trigger_event('core.ucp_add_zebra', compact($vars)));
+
$db->sql_multi_insert(ZEBRA_TABLE, $sql_ary);
$updated = true;
diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php
index fcbfaaddfa..93557f3558 100644
--- a/phpBB/includes/user.php
+++ b/phpBB/includes/user.php
@@ -76,18 +76,18 @@ class phpbb_user extends phpbb_session
function setup($lang_set = false, $style_id = false)
{
global $db, $phpbb_style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
+ global $phpbb_dispatcher;
if ($this->data['user_id'] != ANONYMOUS)
{
- $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
-
- $this->date_format = $this->data['user_dateformat'];
+ $user_lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
+ $user_date_format = $this->data['user_dateformat'];
$user_timezone = $this->data['user_timezone'];
}
else
{
- $this->lang_name = basename($config['default_lang']);
- $this->date_format = $config['default_dateformat'];
+ $user_lang_name = basename($config['default_lang']);
+ $user_date_format = $config['default_dateformat'];
$user_timezone = $config['board_timezone'];
/**
@@ -107,7 +107,7 @@ class phpbb_user extends phpbb_session
if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
{
- $this->lang_name = $config['default_lang'] = $accept_lang;
+ $user_lang_name = $config['default_lang'] = $accept_lang;
break;
}
else
@@ -118,7 +118,7 @@ class phpbb_user extends phpbb_session
if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
{
- $this->lang_name = $config['default_lang'] = $accept_lang;
+ $user_lang_name = $config['default_lang'] = $accept_lang;
break;
}
}
@@ -127,6 +127,28 @@ class phpbb_user extends phpbb_session
*/
}
+ $user_data = $this->data;
+
+ /**
+ * Event to load language files and modify user data on every page
+ *
+ * @event core.user_setup
+ * @var array user_data Array with user's data row
+ * @var string user_lang_name Basename of the user's langauge
+ * @var string user_date_format User's date/time format
+ * @var string user_timezone User's timezone, should be one of
+ * http://www.php.net/manual/en/timezones.php
+ * @var mixed lang_set String or array of language files
+ * @var mixed style_id Style we are going to display
+ * @since 3.1-A1
+ */
+ $vars = array('user_data', 'user_lang_name', 'user_date_format', 'user_timezone', 'lang_set', 'style_id');
+ extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars)));
+
+ $this->data = $user_data;
+ $this->lang_name = $user_lang_name;
+ $this->date_format = $user_date_format;
+
try
{
$this->timezone = new DateTimeZone($user_timezone);
diff --git a/phpBB/index.php b/phpBB/index.php
index c13f3c06ab..0ac8034d7f 100644
--- a/phpBB/index.php
+++ b/phpBB/index.php
@@ -171,8 +171,20 @@ $template->assign_vars(array(
'U_MCP' => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '')
);
+$page_title = $user->lang['INDEX'];
+
+/**
+* You can use this event to modify the page title and load data for the index
+*
+* @event core.index_modify_page_title
+* @var string page_title Title of the index page
+* @since 3.1-A1
+*/
+$vars = array('page_title');
+extract($phpbb_dispatcher->trigger_event('core.index_modify_page_title', compact($vars)));
+
// Output page
-page_header($user->lang['INDEX']);
+page_header($page_title);
$template->set_filenames(array(
'body' => 'index_body.html')
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 1408db27be..502b3bb1a4 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -1079,6 +1079,8 @@ function database_update_info()
),
),
),
+ // No changes from 3.0.11-RC2 to 3.0.11
+ '3.0.11-RC2' => array(),
/** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 */
@@ -2222,6 +2224,10 @@ function change_database_data(&$no_updates, $version)
case '3.0.11-RC1':
break;
+ // No changes from 3.0.11-RC2 to 3.0.11
+ case '3.0.11-RC2':
+ break;
+
// Changes from 3.1.0-dev to 3.1.0-A1
case '3.1.0-dev':
diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php
index ca3994d129..b8045cb98b 100644
--- a/phpBB/install/install_convert.php
+++ b/phpBB/install/install_convert.php
@@ -569,7 +569,7 @@ class install_convert extends module
*/
function convert_data($sub)
{
- global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache;
+ global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache, $auth;
global $convert, $convert_row, $message_parser, $skip_rows, $language;
global $request;
@@ -750,7 +750,7 @@ class install_convert extends module
}
$error = false;
- $convert->fulltext_search = new $search_type($error);
+ $convert->fulltext_search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if ($error)
{
diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php
index 40dee7b3d7..23593ee51f 100644
--- a/phpBB/install/install_install.php
+++ b/phpBB/install/install_install.php
@@ -1427,7 +1427,7 @@ class install_install extends module
*/
function build_search_index($mode, $sub)
{
- global $db, $lang, $phpbb_root_path, $phpEx, $config;
+ global $db, $lang, $phpbb_root_path, $phpEx, $config, $auth, $user;
// Obtain any submitted data
$data = $this->get_submitted_data();
@@ -1463,7 +1463,7 @@ class install_install extends module
set_config_count(null, null, null, $config);
$error = false;
- $search = new phpbb_search_fulltext_native($error);
+ $search = new phpbb_search_fulltext_native($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
$sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
FROM ' . POSTS_TABLE;
diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php
index c2feaa086a..88b00f1cf1 100644
--- a/phpBB/install/install_update.php
+++ b/phpBB/install/install_update.php
@@ -349,7 +349,7 @@ class install_update extends module
// We are directly within an update. To make sure our update list is correct we check its status.
$update_list = ($request->variable('check_again', false, false, phpbb_request_interface::POST)) ? false : $cache->get('_update_list');
- $modified = ($update_list !== false) ? @filemtime($cache->cache_dir . 'data_update_list.' . $phpEx) : 0;
+ $modified = ($update_list !== false) ? @filemtime($cache->get_driver()->cache_dir . 'data_update_list.' . $phpEx) : 0;
// Make sure the list is up-to-date
if ($update_list !== false)
diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php
index 5cebcc89d7..04df897dba 100644
--- a/phpBB/language/en/acp/common.php
+++ b/phpBB/language/en/acp/common.php
@@ -690,6 +690,7 @@ $lang = array_merge($lang, array(
'LOG_SEARCH_INDEX_CREATED' => '<strong>Created search index for</strong><br />» %s',
'LOG_SEARCH_INDEX_REMOVED' => '<strong>Removed search index for</strong><br />» %s',
+ 'LOG_SPHINX_ERROR' => '<strong>Sphinx Error</strong><br />» %s',
'LOG_STYLE_ADD' => '<strong>Added new style</strong><br />» %s',
'LOG_STYLE_DELETE' => '<strong>Deleted style</strong><br />» %s',
'LOG_STYLE_EDIT_DETAILS' => '<strong>Edited style</strong><br />» %s',
diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php
index 33d39c3e99..e6022e3b79 100644
--- a/phpBB/language/en/common.php
+++ b/phpBB/language/en/common.php
@@ -161,6 +161,8 @@ $lang = array_merge($lang, array(
'DISPLAY_MESSAGES' => 'Display messages from previous',
'DISPLAY_POSTS' => 'Display posts from previous',
'DISPLAY_TOPICS' => 'Display topics from previous',
+ 'DOWNLOAD_ALL' => 'Download all',
+ 'DOWNLOAD_ALL_ATTACHMENTS' => 'Download all attachments',
'DOWNLOADED' => 'Downloaded',
'DOWNLOADING_FILE' => 'Downloading file',
'DOWNLOAD_COUNTS' => array(
diff --git a/phpBB/language/en/search.php b/phpBB/language/en/search.php
index d09b4303cd..71cbec4b41 100644
--- a/phpBB/language/en/search.php
+++ b/phpBB/language/en/search.php
@@ -105,6 +105,8 @@ $lang = array_merge($lang, array(
'SORT_FORUM' => 'Forum',
'SORT_POST_SUBJECT' => 'Post subject',
'SORT_TIME' => 'Post time',
+ 'SPHINX_SEARCH_FAILED' => 'Search failed: %s',
+ 'SPHINX_SEARCH_FAILED_LOG' => 'Sorry, search could not be performed. More information about this failure has been logged in the error log.',
'TOO_FEW_AUTHOR_CHARS' => array(
1 => 'You must specify at least %d character of the authors name.',
diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php
index 4f9a8cdff3..f142d182bc 100644
--- a/phpBB/memberlist.php
+++ b/phpBB/memberlist.php
@@ -575,6 +575,26 @@ switch ($mode)
unset($module);
}
+ /**
+ * Modify user data before we display the profile
+ *
+ * @event core.memberlist_view_profile
+ * @var array member Title of the index page
+ * @var bool user_notes_enabled Is the mcp user notes module
+ * enabled?
+ * @var bool warn_user_enabled Is the mcp warnings module
+ * enabled?
+ * @var bool zebra_enabled Is the ucp zebra module
+ * enabled?
+ * @var bool friends_enabled Is the ucp friends module
+ * enabled?
+ * @var bool foes_enabled Is the ucp foes module
+ * enabled?
+ * @since 3.1-A1
+ */
+ $vars = array('member', 'user_notes_enabled', 'warn_user_enabled', 'zebra_enabled', 'friends_enabled', 'foes_enabled');
+ extract($phpbb_dispatcher->trigger_event('core.memberlist_view_profile', compact($vars)));
+
$template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled));
// Custom Profile Fields
@@ -1631,7 +1651,7 @@ page_footer();
*/
function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false)
{
- global $config, $auth, $template, $user, $phpEx, $phpbb_root_path;
+ global $config, $auth, $template, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher;
$username = $data['username'];
$user_id = $data['user_id'];
@@ -1693,7 +1713,7 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f
}
// Dump it out to the template
- return array(
+ $template_data = array(
'AGE' => $age,
'RANK_TITLE' => $rank_title,
'JOINED' => $user->format_date($data['user_regdate']),
@@ -1741,6 +1761,19 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f
'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $username),
);
+
+ /**
+ * Preparing a user's data before displaying it in profile and memberlist
+ *
+ * @event core.memberlist_prepare_profile_data
+ * @var array data Array with user's data
+ * @var array template_data Template array with user's data
+ * @since 3.1-A1
+ */
+ $vars = array('data', 'template_data');
+ extract($phpbb_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars)));
+
+ return $template_data;
}
function _sort_last_active($first, $second)
diff --git a/phpBB/search.php b/phpBB/search.php
index efbf2f4dfe..190da5247f 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -280,7 +280,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
}
// We do some additional checks in the module to ensure it can actually be utilised
$error = false;
- $search = new $search_type($error);
+ $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if ($error)
{
diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html
index 195b212da3..68df22c68e 100644
--- a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html
+++ b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html
@@ -103,7 +103,7 @@
<ul class="linklist">
<!-- IF TOTAL_MESSAGES or S_VIEW_MESSAGE -->
<li class="rightside pagination">
- <!-- IF TOTAL_MESSAGES -->{TOTAL_MESSAGES &bull; <!-- ENDIF -->
+ <!-- IF TOTAL_MESSAGES -->{TOTAL_MESSAGES} &bull; <!-- ENDIF -->
<!-- IF .pagination -->
<!-- INCLUDE pagination.html -->
<!-- ELSE -->
diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html b/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html
index 2e7a7c4ac9..b022bcd979 100644
--- a/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html
+++ b/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html
@@ -41,12 +41,24 @@
<div class="content">{MESSAGE}</div>
<!-- IF S_HAS_ATTACHMENTS -->
- <dl class="attachbox">
- <dt>{L_ATTACHMENTS}</dt>
- <!-- BEGIN attachment -->
- <dd>{attachment.DISPLAY_ATTACHMENT}</dd>
- <!-- END attachment -->
- </dl>
+ <dl class="attachbox">
+ <dt>
+ {L_ATTACHMENTS}
+ <!-- IF S_HAS_MULTIPLE_ATTACHMENTS -->
+ <div class="dl_links">
+ <strong>{L_DOWNLOAD_ALL}:</strong>
+ <ul>
+ <!-- BEGIN dl_method -->
+ <li>[ <a href="{dl_method.LINK}">{dl_method.TYPE}</a> ]</li>
+ <!-- END dl_method -->
+ </ul>
+ </div>
+ <!-- ENDIF -->
+ </dt>
+ <!-- BEGIN attachment -->
+ <dd>{attachment.DISPLAY_ATTACHMENT}</dd>
+ <!-- END attachment -->
+ </dl>
<!-- ENDIF -->
<!-- IF S_DISPLAY_NOTICE -->
diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html
index cfbf0969d9..4534dc5bcc 100644
--- a/phpBB/styles/prosilver/template/viewtopic_body.html
+++ b/phpBB/styles/prosilver/template/viewtopic_body.html
@@ -157,7 +157,19 @@
<!-- IF postrow.S_HAS_ATTACHMENTS -->
<dl class="attachbox">
- <dt>{L_ATTACHMENTS}</dt>
+ <dt>
+ {L_ATTACHMENTS}
+ <!-- IF postrow.S_MULTIPLE_ATTACHMENTS -->
+ <div class="dl_links">
+ <strong>{L_DOWNLOAD_ALL}:</strong>
+ <ul>
+ <!-- BEGIN dl_method -->
+ <li>[ <a href="{postrow.dl_method.LINK}">{postrow.dl_method.TYPE}</a> ]</li>
+ <!-- END dl_method -->
+ </ul>
+ </div>
+ <!-- ENDIF -->
+ </dt>
<!-- BEGIN attachment -->
<dd>{postrow.attachment.DISPLAY_ATTACHMENT}</dd>
<!-- END attachment -->
@@ -256,6 +268,17 @@
<!-- ENDIF -->
</div>
+ <!-- IF S_HAS_ATTACHMENTS -->
+ <div class="dl_links">
+ <strong>{L_DOWNLOAD_ALL_ATTACHMENTS}:</strong>
+ <ul>
+ <!-- BEGIN dl_method -->
+ <li>[ <a href="{dl_method.LINK}">{dl_method.TYPE}</a> ]</li>
+ <!-- END dl_method -->
+ </ul>
+ </div>
+ <!-- ENDIF -->
+
<!-- IF .pagination or TOTAL_POSTS -->
<div class="pagination">
{TOTAL_POSTS} &bull;
diff --git a/phpBB/styles/prosilver/theme/content.css b/phpBB/styles/prosilver/theme/content.css
index 60903911dd..b6012f8a63 100644
--- a/phpBB/styles/prosilver/theme/content.css
+++ b/phpBB/styles/prosilver/theme/content.css
@@ -702,3 +702,26 @@ dl.pmlist dd {
margin-left: 61% !important;
margin-bottom: 2px;
}
+
+.topic-actions div.dl_links {
+ padding: 10px 0 0 10px;
+}
+
+div.dl_links {
+ display: inline-block;
+ text-transform: none;
+}
+
+.dl_links strong {
+ font-weight: bold;
+}
+
+.dl_links ul {
+ list-style-type: none;
+ margin: 0;
+ display: inline-block;
+}
+
+.dl_links li {
+ display: inline-block;
+}
diff --git a/phpBB/styles/prosilver/theme/cp.css b/phpBB/styles/prosilver/theme/cp.css
index bf7d304ca4..da3ec1736e 100644
--- a/phpBB/styles/prosilver/theme/cp.css
+++ b/phpBB/styles/prosilver/theme/cp.css
@@ -260,8 +260,9 @@ ul.cplist {
/* Friends list */
.cp-mini {
- padding: 0 5px;
margin: 10px 15px 10px 5px;
+ padding: 5px 10px;
+ border-radius: 7px;
}
dl.mini dt {
diff --git a/phpBB/ucp.php b/phpBB/ucp.php
index 64afa0be67..9730591698 100644
--- a/phpBB/ucp.php
+++ b/phpBB/ucp.php
@@ -328,6 +328,18 @@ if (!$auth->acl_get('u_sig'))
$module->set_display('profile', 'signature', false);
}
+/**
+* Use this event to enable and disable additional UCP modules
+*
+* @event core.ucp_display_module_before
+* @var p_master module Object holding all modules and their status
+* @var mixed id Active module category (can be the int or string)
+* @var string mode Active module
+* @since 3.1-A1
+*/
+$vars = array('module', 'id', 'mode');
+extract($phpbb_dispatcher->trigger_event('core.ucp_display_module_before', compact($vars)));
+
// Select the active module
$module->set_active($id, $mode);
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index f4781a09ff..783c7181d2 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -690,7 +690,7 @@ if (sizeof($topic_list))
$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : '';
// Send vars to template
- $template->assign_block_vars('topicrow', array(
+ $topic_row = array(
'FORUM_ID' => $row['forum_id'],
'TOPIC_ID' => $topic_id,
'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
@@ -742,11 +742,24 @@ if (sizeof($topic_list))
'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;f=' . $row['forum_id'] . '&amp;t=' . $topic_id, true, $user->session_id),
'U_MCP_QUEUE' => $u_mcp_queue,
- 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
+ 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test,
);
+ /**
+ * Modify the topic data before it is assigned to the template
+ *
+ * @event core.viewforum_modify_topicrow
+ * @var array row Array with topic data
+ * @var array topic_row Template array with topic data
+ * @since 3.1-A1
+ */
+ $vars = array('row', 'topic_row');
+ extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_topicrow', compact($vars)));
+
+ $template->assign_block_vars('topicrow', $topic_row);
+
phpbb_generate_template_pagination($template, $view_topic_url, 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
-
+
$s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
if ($unread_topic)
diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php
index 48362a9d67..15884a41d8 100644
--- a/phpBB/viewonline.php
+++ b/phpBB/viewonline.php
@@ -121,13 +121,30 @@ if (!$show_guests)
}
// Get user list
-$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_type, u.user_colour, s.session_id, s.session_time, s.session_page, s.session_ip, s.session_browser, s.session_viewonline, s.session_forum_id
- FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . ' s
- WHERE u.user_id = s.session_user_id
+$sql_ary = array(
+ 'SELECT' => 'u.user_id, u.username, u.username_clean, u.user_type, u.user_colour, s.session_id, s.session_time, s.session_page, s.session_ip, s.session_browser, s.session_viewonline, s.session_forum_id',
+ 'FROM' => array(
+ USERS_TABLE => 'u',
+ SESSIONS_TABLE => 's',
+ ),
+ 'WHERE' => 'u.user_id = s.session_user_id
AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
- ((!$show_guests) ? ' AND s.session_user_id <> ' . ANONYMOUS : '') . '
- ORDER BY ' . $order_by;
-$result = $db->sql_query($sql);
+ ((!$show_guests) ? ' AND s.session_user_id <> ' . ANONYMOUS : ''),
+ 'ORDER_BY' => $order_by,
+);
+
+/**
+* Modify the SQL query for getting the user data to display viewonline list
+*
+* @event core.viewonline_modify_sql
+* @var array sql_ary The SQL array
+* @var bool show_guests Do we display guests in the list
+* @since 3.1-A1
+*/
+$vars = array('sql_ary', 'show_guests');
+extract($phpbb_dispatcher->trigger_event('core.viewonline_modify_sql', compact($vars)));
+
+$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
$prev_id = $prev_ip = $user_list = array();
$logged_visible_online = $logged_hidden_online = $counter = 0;
@@ -320,6 +337,19 @@ while ($row = $db->sql_fetchrow($result))
break;
}
+ /**
+ * Overwrite the location's name and URL, which are displayed in the list
+ *
+ * @event core.viewonline_overwrite_location
+ * @var array on_page File name and query string
+ * @var array row Array with the users sql row
+ * @var string location Page name to displayed in the list
+ * @var string location_url Page url to displayed in the list
+ * @since 3.1-A1
+ */
+ $vars = array('on_page', 'row', 'location', 'location_url');
+ extract($phpbb_dispatcher->trigger_event('core.viewonline_overwrite_location', compact($vars)));
+
$template->assign_block_vars('user_row', array(
'USERNAME' => $row['username'],
'USERNAME_COLOUR' => $row['user_colour'],
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index b6df14d42d..3fde5b5e03 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -987,6 +987,16 @@ $sql_ary = array(
AND u.user_id = p.poster_id',
);
+/**
+* Event to modify the SQL query before the post and poster data is retrieved
+*
+* @event core.viewtopic_get_post_data
+* @var array sql_ary The SQL array to get the data of posts and posters
+* @since 3.1-A1
+*/
+$vars = array('sql_ary');
+extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_post_data', compact($vars)));
+
$sql = $db->sql_build_query('SELECT', $sql_ary);
$result = $db->sql_query($sql);
@@ -1063,7 +1073,7 @@ while ($row = $db->sql_fetchrow($result))
{
if ($poster_id == ANONYMOUS)
{
- $user_cache[$poster_id] = array(
+ $user_cache_data = array(
'joined' => '',
'posts' => '',
'from' => '',
@@ -1098,6 +1108,20 @@ while ($row = $db->sql_fetchrow($result))
'allow_pm' => 0,
);
+ /**
+ * Modify the guest user's data displayed with the posts
+ *
+ * @event core.viewtopic_cache_guest_data
+ * @var array user_cache_data Array with the user's data
+ * @var int poster_id Poster's user id
+ * @var array row Array with original user and post data
+ * @since 3.1-A1
+ */
+ $vars = array('user_cache_data', 'poster_id', 'row');
+ extract($phpbb_dispatcher->trigger_event('core.viewtopic_cache_guest_data', compact($vars)));
+
+ $user_cache[$poster_id] = $user_cache_data;
+
get_user_rank($row['user_rank'], false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
}
else
@@ -1112,7 +1136,7 @@ while ($row = $db->sql_fetchrow($result))
$id_cache[] = $poster_id;
- $user_cache[$poster_id] = array(
+ $user_cache_data = array(
'joined' => $user->format_date($row['user_regdate']),
'posts' => $row['user_posts'],
'warnings' => (isset($row['user_warnings'])) ? $row['user_warnings'] : 0,
@@ -1150,6 +1174,20 @@ while ($row = $db->sql_fetchrow($result))
'author_profile' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour']),
);
+ /**
+ * Modify the users' data displayed with their posts
+ *
+ * @event core.viewtopic_cache_user_data
+ * @var array user_cache_data Array with the user's data
+ * @var int poster_id Poster's user id
+ * @var array row Array with original user and post data
+ * @since 3.1-A1
+ */
+ $vars = array('user_cache_data', 'poster_id', 'row');
+ extract($phpbb_dispatcher->trigger_event('core.viewtopic_cache_user_data', compact($vars)));
+
+ $user_cache[$poster_id] = $user_cache_data;
+
get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
if ((!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email'))
@@ -1314,6 +1352,16 @@ if (sizeof($attach_list))
}
}
+$template->assign_vars(array(
+ 'S_HAS_ATTACHMENTS' => !empty($attachments),
+));
+
+$methods = phpbb_gen_download_links('topic_id', $topic_id, $phpbb_root_path, $phpEx);
+foreach ($methods as $method)
+{
+ $template->assign_block_vars('dl_method', $method);
+}
+
// Instantiate BBCode if need be
if ($bbcode_bitfield !== '')
{
@@ -1493,7 +1541,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
)));
//
- $postrow = array(
+ $post_row = array(
'POST_AUTHOR_FULL' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_full'] : get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR_COLOUR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_colour'] : get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_username'] : get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
@@ -1556,6 +1604,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
'POSTER_ID' => $poster_id,
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
+ 'S_MULTIPLE_ATTACHMENTS' => !empty($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']]) > 1,
'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true,
'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'],
@@ -1569,13 +1618,28 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
'L_IGNORE_POST' => ($row['hide_post']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), '<a href="' . $viewtopic_url . "&amp;p={$row['post_id']}&amp;view=show#p{$row['post_id']}" . '">', '</a>') : '',
);
+ $user_poster_data = $user_cache[$poster_id];
+
+ /**
+ * Modify the posts template block
+ *
+ * @event core.viewtopic_modify_post_row
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @var array user_poster_data Poster's data from user cache
+ * @var array post_row Template block array of the post
+ * @since 3.1-A1
+ */
+ $vars = array('row', 'cp_row', 'user_poster_data', 'post_row');
+ extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_post_row', compact($vars)));
+
if (isset($cp_row['row']) && sizeof($cp_row['row']))
{
- $postrow = array_merge($postrow, $cp_row['row']);
+ $post_row = array_merge($post_row, $cp_row['row']);
}
// Dump vars into template
- $template->assign_block_vars('postrow', $postrow);
+ $template->assign_block_vars('postrow', $post_row);
if (!empty($cp_row['blockrow']))
{
@@ -1594,6 +1658,12 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
'DISPLAY_ATTACHMENT' => $attachment)
);
}
+
+ $methods = phpbb_gen_download_links('post_msg_id', $row['post_id'], $phpbb_root_path, $phpEx);
+ foreach ($methods as $method)
+ {
+ $template->assign_block_vars('postrow.dl_method', $method);
+ }
}
$prev_post_id = $row['post_id'];
@@ -1729,8 +1799,23 @@ if (!request_var('t', 0) && !empty($topic_id))
$request->overwrite('t', $topic_id);
}
+$page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : '');
+
+/**
+* You can use this event to modify the page title of the viewtopic page
+*
+* @event core.viewtopic_modify_page_title
+* @var string page_title Title of the index page
+* @var array topic_data Array with topic data
+* @var int forum_id Forum ID of the topic
+* @var int start Start offset used to calculate the page
+* @since 3.1-A1
+*/
+$vars = array('page_title', 'topic_data', 'forum_id', 'start');
+extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_page_title', compact($vars)));
+
// Output the page
-page_header($topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : ''), true, $forum_id);
+page_header($page_title, true, $forum_id);
$template->set_filenames(array(
'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html')