aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r--phpBB/phpbb/console/command/config/command.php22
-rw-r--r--phpBB/phpbb/console/command/config/delete.php46
-rw-r--r--phpBB/phpbb/console/command/config/get.php54
-rw-r--r--phpBB/phpbb/console/command/config/increment.php52
-rw-r--r--phpBB/phpbb/console/command/config/set.php52
-rw-r--r--phpBB/phpbb/console/command/config/set_atomic.php65
-rw-r--r--phpBB/phpbb/extension/manager.php15
-rw-r--r--phpBB/phpbb/extension/metadata_manager.php14
-rw-r--r--phpBB/phpbb/log/log.php4
-rw-r--r--phpBB/phpbb/notification/type/approve_post.php7
-rw-r--r--phpBB/phpbb/notification/type/approve_topic.php7
-rw-r--r--phpBB/phpbb/notification/type/base.php6
-rw-r--r--phpBB/phpbb/notification/type/disapprove_post.php7
-rw-r--r--phpBB/phpbb/notification/type/disapprove_topic.php7
-rw-r--r--phpBB/phpbb/notification/type/post.php11
-rw-r--r--phpBB/phpbb/notification/type/report_post.php7
-rw-r--r--phpBB/phpbb/notification/type/report_post_closed.php7
-rw-r--r--phpBB/phpbb/notification/type/topic.php11
-rw-r--r--phpBB/phpbb/pagination.php306
-rw-r--r--phpBB/phpbb/path_helper.php44
-rw-r--r--phpBB/phpbb/request/request.php2
-rw-r--r--phpBB/phpbb/search/fulltext_mysql.php2
-rw-r--r--phpBB/phpbb/search/fulltext_native.php2
23 files changed, 737 insertions, 13 deletions
diff --git a/phpBB/phpbb/console/command/config/command.php b/phpBB/phpbb/console/command/config/command.php
new file mode 100644
index 0000000000..b105bc826d
--- /dev/null
+++ b/phpBB/phpbb/console/command/config/command.php
@@ -0,0 +1,22 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+namespace phpbb\console\command\config;
+
+abstract class command extends \phpbb\console\command\command
+{
+ /** @var \phpbb\config\config */
+ protected $config;
+
+ function __construct(\phpbb\config\config $config)
+ {
+ $this->config = $config;
+
+ parent::__construct();
+ }
+}
diff --git a/phpBB/phpbb/console/command/config/delete.php b/phpBB/phpbb/console/command/config/delete.php
new file mode 100644
index 0000000000..9a2d00561d
--- /dev/null
+++ b/phpBB/phpbb/console/command/config/delete.php
@@ -0,0 +1,46 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+namespace phpbb\console\command\config;
+
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class delete extends command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('config:delete')
+ ->setDescription('Deletes a configuration option')
+ ->addArgument(
+ 'key',
+ InputArgument::REQUIRED,
+ "The configuration option's name"
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $key = $input->getArgument('key');
+
+ if (isset($this->config[$key]))
+ {
+ $this->config->delete($key);
+
+ $output->writeln("<info>Successfully deleted config $key</info>");
+ }
+ else
+ {
+ $output->writeln("<error>Config $key does not exist</error>");
+ }
+ }
+}
diff --git a/phpBB/phpbb/console/command/config/get.php b/phpBB/phpbb/console/command/config/get.php
new file mode 100644
index 0000000000..275c82b53f
--- /dev/null
+++ b/phpBB/phpbb/console/command/config/get.php
@@ -0,0 +1,54 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+namespace phpbb\console\command\config;
+
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class get extends command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('config:get')
+ ->setDescription("Gets a configuration option's value")
+ ->addArgument(
+ 'key',
+ InputArgument::REQUIRED,
+ "The configuration option's name"
+ )
+ ->addOption(
+ 'no-newline',
+ null,
+ InputOption::VALUE_NONE,
+ 'Set this option if the value should be printed without a new line at the end.'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $key = $input->getArgument('key');
+
+ if (isset($this->config[$key]) && $input->getOption('no-newline'))
+ {
+ $output->write($this->config[$key]);
+ }
+ elseif (isset($this->config[$key]))
+ {
+ $output->writeln($this->config[$key]);
+ }
+ else
+ {
+ $output->writeln("<error>Could not get config $key</error>");
+ }
+ }
+}
diff --git a/phpBB/phpbb/console/command/config/increment.php b/phpBB/phpbb/console/command/config/increment.php
new file mode 100644
index 0000000000..bc6b63c6ff
--- /dev/null
+++ b/phpBB/phpbb/console/command/config/increment.php
@@ -0,0 +1,52 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+namespace phpbb\console\command\config;
+
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class increment extends command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('config:increment')
+ ->setDescription("Increments a configuration option's value")
+ ->addArgument(
+ 'key',
+ InputArgument::REQUIRED,
+ "The configuration option's name"
+ )
+ ->addArgument(
+ 'increment',
+ InputArgument::REQUIRED,
+ 'Amount to increment by'
+ )
+ ->addOption(
+ 'dynamic',
+ 'd',
+ InputOption::VALUE_NONE,
+ 'Set this option if the configuration option changes too frequently to be efficiently cached.'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $key = $input->getArgument('key');
+ $increment = $input->getArgument('increment');
+ $use_cache = !$input->getOption('dynamic');
+
+ $this->config->increment($key, $increment, $use_cache);
+
+ $output->writeln("<info>Successfully incremented config $key</info>");
+ }
+}
diff --git a/phpBB/phpbb/console/command/config/set.php b/phpBB/phpbb/console/command/config/set.php
new file mode 100644
index 0000000000..9d471a96ad
--- /dev/null
+++ b/phpBB/phpbb/console/command/config/set.php
@@ -0,0 +1,52 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+namespace phpbb\console\command\config;
+
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class set extends command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('config:set')
+ ->setDescription("Sets a configuration option's value")
+ ->addArgument(
+ 'key',
+ InputArgument::REQUIRED,
+ "The configuration option's name"
+ )
+ ->addArgument(
+ 'value',
+ InputArgument::REQUIRED,
+ 'New configuration value, use 0 and 1 to specify boolean values'
+ )
+ ->addOption(
+ 'dynamic',
+ 'd',
+ InputOption::VALUE_NONE,
+ 'Set this option if the configuration option changes too frequently to be efficiently cached.'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $key = $input->getArgument('key');
+ $value = $input->getArgument('value');
+ $use_cache = !$input->getOption('dynamic');
+
+ $this->config->set($key, $value, $use_cache);
+
+ $output->writeln("<info>Successfully set config $key</info>");
+ }
+}
diff --git a/phpBB/phpbb/console/command/config/set_atomic.php b/phpBB/phpbb/console/command/config/set_atomic.php
new file mode 100644
index 0000000000..03e7a60210
--- /dev/null
+++ b/phpBB/phpbb/console/command/config/set_atomic.php
@@ -0,0 +1,65 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+namespace phpbb\console\command\config;
+
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class set_atomic extends command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('config:set-atomic')
+ ->setDescription("Sets a configuration option's value only if the old matches the current value.")
+ ->addArgument(
+ 'key',
+ InputArgument::REQUIRED,
+ "The configuration option's name"
+ )
+ ->addArgument(
+ 'old',
+ InputArgument::REQUIRED,
+ 'Current configuration value, use 0 and 1 to specify boolean values'
+ )
+ ->addArgument(
+ 'new',
+ InputArgument::REQUIRED,
+ 'New configuration value, use 0 and 1 to specify boolean values'
+ )
+ ->addOption(
+ 'dynamic',
+ 'd',
+ InputOption::VALUE_NONE,
+ 'Set this option if the configuration option changes too frequently to be efficiently cached.'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $key = $input->getArgument('key');
+ $old_value = $input->getArgument('old');
+ $new_value = $input->getArgument('new');
+ $use_cache = !$input->getOption('dynamic');
+
+ if ($this->config->set_atomic($key, $old_value, $new_value, $use_cache))
+ {
+ $output->writeln("<info>Successfully set config $key</info>");
+ return 0;
+ }
+ else
+ {
+ $output->writeln("<error>Could not set config $key</error>");
+ return 1;
+ }
+ }
+}
diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php
index 7f009867c9..23b281deaa 100644
--- a/phpBB/phpbb/extension/manager.php
+++ b/phpBB/phpbb/extension/manager.php
@@ -411,9 +411,24 @@ class manager
if ($file_info->isFile() && $file_info->getFilename() == 'ext.' . $this->php_ext)
{
$ext_name = $iterator->getInnerIterator()->getSubPath();
+ $composer_file = $iterator->getPath() . '/composer.json';
+ // Ignore the extension if there is no composer.json.
+ if (!is_readable($composer_file) || !($ext_info = file_get_contents($composer_file)))
+ {
+ continue;
+ }
+
+ $ext_info = json_decode($ext_info, true);
$ext_name = str_replace(DIRECTORY_SEPARATOR, '/', $ext_name);
+ // Ignore the extension if directory depth is not correct or if the directory structure
+ // does not match the name value specified in composer.json.
+ if (substr_count($ext_name, '/') !== 1 || !isset($ext_info['name']) || $ext_name != $ext_info['name'])
+ {
+ continue;
+ }
+
$available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/';
}
}
diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php
index d0323120d8..66cdb86513 100644
--- a/phpBB/phpbb/extension/metadata_manager.php
+++ b/phpBB/phpbb/extension/metadata_manager.php
@@ -266,8 +266,8 @@ class metadata_manager
*/
public function validate_enable()
{
- // Check for phpBB, PHP versions
- if (!$this->validate_require_phpbb() || !$this->validate_require_php())
+ // Check for valid directory & phpBB, PHP versions
+ if (!$this->validate_dir() || !$this->validate_require_phpbb() || !$this->validate_require_php())
{
return false;
}
@@ -275,6 +275,16 @@ class metadata_manager
return true;
}
+ /**
+ * Validates the most basic directory structure to ensure it follows <vendor>/<ext> convention.
+ *
+ * @return boolean True when passes validation
+ */
+ public function validate_dir()
+ {
+ return (substr_count($this->ext_name, '/') === 1 && $this->ext_name == $this->get_metadata('name'));
+ }
+
/**
* Validates the contents of the phpbb requirement field
diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php
index a6ee06ebf2..62edc6a77f 100644
--- a/phpBB/phpbb/log/log.php
+++ b/phpBB/phpbb/log/log.php
@@ -424,7 +424,7 @@ class log implements \phpbb\log\log_interface
if ($count_logs)
{
$sql = 'SELECT COUNT(l.log_id) AS total_entries
- FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . ' u
+ FROM ' . $this->log_table . ' l, ' . USERS_TABLE . ' u
WHERE l.log_type = ' . (int) $log_type . '
AND l.user_id = u.user_id
AND l.log_time >= ' . (int) $log_time . "
@@ -449,7 +449,7 @@ class log implements \phpbb\log\log_interface
}
$sql = 'SELECT l.*, u.username, u.username_clean, u.user_colour
- FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . ' u
+ FROM ' . $this->log_table . ' l, ' . USERS_TABLE . ' u
WHERE l.log_type = ' . (int) $log_type . '
AND u.user_id = l.user_id
' . (($log_time) ? 'AND l.log_time >= ' . (int) $log_time : '') . "
diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php
index 51a9a704b0..e51ff12b3e 100644
--- a/phpBB/phpbb/notification/type/approve_post.php
+++ b/phpBB/phpbb/notification/type/approve_post.php
@@ -35,6 +35,13 @@ class approve_post extends \phpbb\notification\type\post
protected $language_key = 'NOTIFICATION_POST_APPROVED';
/**
+ * Inherit notification read status from post.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = false;
+
+ /**
* Notification option data (for outputting to the user)
*
* @var bool|array False if the service should use it's default data
diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php
index 6229800c68..11a240e03d 100644
--- a/phpBB/phpbb/notification/type/approve_topic.php
+++ b/phpBB/phpbb/notification/type/approve_topic.php
@@ -35,6 +35,13 @@ class approve_topic extends \phpbb\notification\type\topic
protected $language_key = 'NOTIFICATION_TOPIC_APPROVED';
/**
+ * Inherit notification read status from topic.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = false;
+
+ /**
* Notification option data (for outputting to the user)
*
* @var bool|array False if the service should use it's default data
diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php
index 951585853f..10c876b286 100644
--- a/phpBB/phpbb/notification/type/base.php
+++ b/phpBB/phpbb/notification/type/base.php
@@ -282,15 +282,17 @@ abstract class base implements \phpbb\notification\type\type_interface
*/
public function prepare_for_display()
{
+ $mark_hash = generate_link_hash('mark_notification_read');
+
if ($this->get_url())
{
- $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id);
+ $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&amp;hash=' . $mark_hash);
}
else
{
$redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : '');
- $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&amp;redirect=' . urlencode($redirect));
+ $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&amp;hash=' . $mark_hash . '&amp;redirect=' . urlencode($redirect));
}
return array(
diff --git a/phpBB/phpbb/notification/type/disapprove_post.php b/phpBB/phpbb/notification/type/disapprove_post.php
index 411d4195c7..70de2a3e10 100644
--- a/phpBB/phpbb/notification/type/disapprove_post.php
+++ b/phpBB/phpbb/notification/type/disapprove_post.php
@@ -35,6 +35,13 @@ class disapprove_post extends \phpbb\notification\type\approve_post
protected $language_key = 'NOTIFICATION_POST_DISAPPROVED';
/**
+ * Inherit notification read status from post.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = false;
+
+ /**
* Notification option data (for outputting to the user)
*
* @var bool|array False if the service should use it's default data
diff --git a/phpBB/phpbb/notification/type/disapprove_topic.php b/phpBB/phpbb/notification/type/disapprove_topic.php
index 19e9d468ce..d39201d928 100644
--- a/phpBB/phpbb/notification/type/disapprove_topic.php
+++ b/phpBB/phpbb/notification/type/disapprove_topic.php
@@ -35,6 +35,13 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic
protected $language_key = 'NOTIFICATION_TOPIC_DISAPPROVED';
/**
+ * Inherit notification read status from topic.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = false;
+
+ /**
* Notification option data (for outputting to the user)
*
* @var bool|array False if the service should use it's default data
diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php
index c2854c17af..bc42c4422b 100644
--- a/phpBB/phpbb/notification/type/post.php
+++ b/phpBB/phpbb/notification/type/post.php
@@ -35,6 +35,13 @@ class post extends \phpbb\notification\type\base
protected $language_key = 'NOTIFICATION_POST';
/**
+ * Inherit notification read status from post.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = true;
+
+ /**
* Notification option data (for outputting to the user)
*
* @var bool|array False if the service should use it's default data
@@ -315,7 +322,7 @@ class post extends \phpbb\notification\type\base
*/
public function pre_create_insert_array($post, $notify_users)
{
- if (!sizeof($notify_users))
+ if (!sizeof($notify_users) || !$this->inherit_read_status)
{
return array();
}
@@ -360,7 +367,7 @@ class post extends \phpbb\notification\type\base
// Topics can be "read" before they are public (while awaiting approval).
// Make sure that if the user has read the topic, it's marked as read in the notification
- if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
+ if ($this->inherit_read_status && isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
{
$this->notification_read = true;
}
diff --git a/phpBB/phpbb/notification/type/report_post.php b/phpBB/phpbb/notification/type/report_post.php
index 89b497efa6..9bf035b91e 100644
--- a/phpBB/phpbb/notification/type/report_post.php
+++ b/phpBB/phpbb/notification/type/report_post.php
@@ -35,6 +35,13 @@ class report_post extends \phpbb\notification\type\post_in_queue
protected $language_key = 'NOTIFICATION_REPORT_POST';
/**
+ * Inherit notification read status from post.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = false;
+
+ /**
* Permission to check for (in find_users_for_notification)
*
* @var string Permission name
diff --git a/phpBB/phpbb/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php
index 5874d48e31..fff45612b3 100644
--- a/phpBB/phpbb/notification/type/report_post_closed.php
+++ b/phpBB/phpbb/notification/type/report_post_closed.php
@@ -41,6 +41,13 @@ class report_post_closed extends \phpbb\notification\type\post
*/
protected $language_key = 'NOTIFICATION_REPORT_CLOSED';
+ /**
+ * Inherit notification read status from post.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = false;
+
public function is_available()
{
return false;
diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php
index 6198881d8d..98f086a50b 100644
--- a/phpBB/phpbb/notification/type/topic.php
+++ b/phpBB/phpbb/notification/type/topic.php
@@ -35,6 +35,13 @@ class topic extends \phpbb\notification\type\base
protected $language_key = 'NOTIFICATION_TOPIC';
/**
+ * Inherit notification read status from topic.
+ *
+ * @var bool
+ */
+ protected $inherit_read_status = true;
+
+ /**
* Notification option data (for outputting to the user)
*
* @var bool|array False if the service should use it's default data
@@ -220,7 +227,7 @@ class topic extends \phpbb\notification\type\base
*/
public function pre_create_insert_array($post, $notify_users)
{
- if (!sizeof($notify_users))
+ if (!sizeof($notify_users) || !$this->inherit_read_status)
{
return array();
}
@@ -261,7 +268,7 @@ class topic extends \phpbb\notification\type\base
// Topics can be "read" before they are public (while awaiting approval).
// Make sure that if the user has read the topic, it's marked as read in the notification
- if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
+ if ($this->inherit_read_status && isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
{
$this->notification_read = true;
}
diff --git a/phpBB/phpbb/pagination.php b/phpBB/phpbb/pagination.php
new file mode 100644
index 0000000000..467dc2157f
--- /dev/null
+++ b/phpBB/phpbb/pagination.php
@@ -0,0 +1,306 @@
+<?php
+/**
+*
+* @package phpbb
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+namespace phpbb;
+
+class pagination
+{
+ /** @var \phpbb\template\template */
+ protected $template;
+
+ /** @var \phpbb\user */
+ protected $user;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\template\template $template
+ * @param \phpbb\user $user
+ */
+ public function __construct(\phpbb\template\template $template, \phpbb\user $user)
+ {
+ $this->template = $template;
+ $this->user = $user;
+ }
+
+ /**
+ * Generate a pagination link based on the url and the page information
+ *
+ * @param string $base_url is url prepended to all links generated within the function
+ * If you use page numbers inside your controller route, base_url should contains a placeholder (%d)
+ * for the page. Also be sure to specify the pagination path information into the start_name argument
+ * @param string $on_page is the page for which we want to generate the link
+ * @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20)
+ * If you use page numbers inside your controller route, start name should be the string
+ * that should be removed for the first page (example: /page/%d)
+ * @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce
+ * @return URL for the requested page
+ */
+ protected function generate_page_link($base_url, $on_page, $start_name, $per_page)
+ {
+ if (strpos($start_name, '%d') !== false)
+ {
+ return ($on_page > 1) ? sprintf($base_url, (int) $on_page) : str_replace($start_name, '', $base_url);
+ }
+ else
+ {
+ $url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&amp;');
+ return ($on_page > 1) ? $base_url . $url_delim . $start_name . '=' . (($on_page - 1) * $per_page) : $base_url;
+ }
+ }
+
+ /**
+ * Generate template rendered pagination
+ * Allows full control of rendering of pagination with the template
+ *
+ * @param string $base_url is url prepended to all links generated within the function
+ * If you use page numbers inside your controller route, base_url should contains a placeholder (%d)
+ * for the page. Also be sure to specify the pagination path information into the start_name argument
+ * @param string $block_var_name is the name assigned to the pagination data block within the template (example: <!-- BEGIN pagination -->)
+ * @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20)
+ * If you use page numbers inside your controller route, start name should be the string
+ * that should be removed for the first page (example: /page/%d)
+ * @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce
+ * @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @param bool $reverse_count determines whether we weight display of the list towards the start (false) or end (true) of the list
+ * @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists
+ * @return null
+ */
+ public function generate_template_pagination($base_url, $block_var_name, $start_name, $num_items, $per_page, $start = 1, $reverse_count = false, $ignore_on_page = false)
+ {
+ $total_pages = ceil($num_items / $per_page);
+
+ if ($total_pages == 1 || !$num_items)
+ {
+ return;
+ }
+
+ $on_page = $this->get_on_page($per_page, $start);
+
+ if ($reverse_count)
+ {
+ $start_page = ($total_pages > 5) ? $total_pages - 4 : 1;
+ $end_page = $total_pages;
+ }
+ else
+ {
+ // What we're doing here is calculating what the "start" and "end" pages should be. We
+ // do this by assuming pagination is "centered" around the currently active page with
+ // the three previous and three next page links displayed. Anything more than that and
+ // we display the ellipsis, likewise anything less.
+ //
+ // $start_page is the page at which we start creating the list. When we have five or less
+ // pages we start at page 1 since there will be no ellipsis displayed. Anymore than that
+ // and we calculate the start based on the active page. This is the min/max calculation.
+ // First (max) would we end up starting on a page less than 1? Next (min) would we end
+ // up starting so close to the end that we'd not display our minimum number of pages.
+ //
+ // $end_page is the last page in the list to display. Like $start_page we use a min/max to
+ // determine this number. Again at most five pages? Then just display them all. More than
+ // five and we first (min) determine whether we'd end up listing more pages than exist.
+ // We then (max) ensure we're displaying the minimum number of pages.
+ $start_page = ($total_pages > 5) ? min(max(1, $on_page - 3), $total_pages - 4) : 1;
+ $end_page = ($total_pages > 5) ? max(min($total_pages, $on_page + 3), 5) : $total_pages;
+ }
+
+ $u_previous_page = $u_next_page = '';
+ if ($on_page != 1)
+ {
+ $u_previous_page = $this->generate_page_link($base_url, $on_page - 1, $start_name, $per_page);
+
+ $this->template->assign_block_vars($block_var_name, array(
+ 'PAGE_NUMBER' => '',
+ 'PAGE_URL' => $u_previous_page,
+ 'S_IS_CURRENT' => false,
+ 'S_IS_PREV' => true,
+ 'S_IS_NEXT' => false,
+ 'S_IS_ELLIPSIS' => false,
+ ));
+ }
+
+ // This do...while exists purely to negate the need for start and end assign_block_vars, i.e.
+ // to display the first and last page in the list plus any ellipsis. We use this loop to jump
+ // around a little within the list depending on where we're starting (and ending).
+ $at_page = 1;
+ do
+ {
+ // We decide whether to display the ellipsis during the loop. The ellipsis is always
+ // displayed as either the second or penultimate item in the list. So are we at either
+ // of those points and of course do we even need to display it, i.e. is the list starting
+ // on at least page 3 and ending three pages before the final item.
+ $this->template->assign_block_vars($block_var_name, array(
+ 'PAGE_NUMBER' => $at_page,
+ 'PAGE_URL' => $this->generate_page_link($base_url, $at_page, $start_name, $per_page),
+ 'S_IS_CURRENT' => (!$ignore_on_page && $at_page == $on_page),
+ 'S_IS_NEXT' => false,
+ 'S_IS_PREV' => false,
+ 'S_IS_ELLIPSIS' => ($at_page == 2 && $start_page > 2) || ($at_page == $total_pages - 1 && $end_page < $total_pages - 1),
+ ));
+
+ // We may need to jump around in the list depending on whether we have or need to display
+ // the ellipsis. Are we on page 2 and are we more than one page away from the start
+ // of the list? Yes? Then we jump to the start of the list. Likewise are we at the end of
+ // the list and are there more than two pages left in total? Yes? Then jump to the penultimate
+ // page (so we can display the ellipsis next pass). Else, increment the counter and keep
+ // going
+ if ($at_page == 2 && $at_page < $start_page - 1)
+ {
+ $at_page = $start_page;
+ }
+ else if ($at_page == $end_page && $end_page < $total_pages - 1)
+ {
+ $at_page = $total_pages - 1;
+ }
+ else
+ {
+ $at_page++;
+ }
+ }
+ while ($at_page <= $total_pages);
+
+ if ($on_page != $total_pages)
+ {
+ $u_next_page = $this->generate_page_link($base_url, $on_page + 1, $start_name, $per_page);
+
+ $this->template->assign_block_vars($block_var_name, array(
+ 'PAGE_NUMBER' => '',
+ 'PAGE_URL' => $u_next_page,
+ 'S_IS_CURRENT' => false,
+ 'S_IS_PREV' => false,
+ 'S_IS_NEXT' => true,
+ 'S_IS_ELLIPSIS' => false,
+ ));
+ }
+
+ // If the block_var_name is a nested block, we will use the last (most
+ // inner) block as a prefix for the template variables. If the last block
+ // name is pagination, the prefix is empty. If the rest of the
+ // block_var_name is not empty, we will modify the last row of that block
+ // and add our pagination items.
+ $tpl_block_name = $tpl_prefix = '';
+ if (strrpos($block_var_name, '.') !== false)
+ {
+ $tpl_block_name = substr($block_var_name, 0, strrpos($block_var_name, '.'));
+ $tpl_prefix = strtoupper(substr($block_var_name, strrpos($block_var_name, '.') + 1));
+ }
+ else
+ {
+ $tpl_prefix = strtoupper($block_var_name);
+ }
+ $tpl_prefix = ($tpl_prefix == 'PAGINATION') ? '' : $tpl_prefix . '_';
+
+ $template_array = array(
+ $tpl_prefix . 'BASE_URL' => $base_url,
+ $tpl_prefix . 'PER_PAGE' => $per_page,
+ 'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page != 1) ? $u_previous_page : '',
+ 'U_' . $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $u_next_page : '',
+ $tpl_prefix . 'TOTAL_PAGES' => $total_pages,
+ $tpl_prefix . 'CURRENT_PAGE' => $on_page,
+ );
+
+ if ($tpl_block_name)
+ {
+ $this->template->alter_block_array($tpl_block_name, $template_array, true, 'change');
+ }
+ else
+ {
+ $this->template->assign_vars($template_array);
+ }
+ }
+
+ /**
+ * Get current page number
+ *
+ * @param int $per_page the number of items, posts, etc. per page
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @return int Current page number
+ */
+ public function get_on_page($per_page, $start)
+ {
+ return floor($start / $per_page) + 1;
+ }
+
+ /**
+ * Return current page
+ * This function also sets certain specific template variables
+ *
+ * @param string $base_url the base url used to call this page, used by Javascript for popup jump to page
+ * @param int $num_items the total number of items, posts, topics, etc.
+ * @param int $per_page the number of items, posts, etc. per page
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @return string Descriptive pagination string (e.g. "page 1 of 10")
+ */
+ public function on_page($base_url, $num_items, $per_page, $start)
+ {
+ $on_page = $this->get_on_page($per_page, $start);
+
+ $this->template->assign_vars(array(
+ 'PER_PAGE' => $per_page,
+ 'ON_PAGE' => $on_page,
+ 'BASE_URL' => $base_url,
+ ));
+
+ return $this->user->lang('PAGE_OF', $on_page, max(ceil($num_items / $per_page), 1));
+ }
+
+ /**
+ * Get current page number
+ *
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @param int $per_page the number of items, posts, etc. per page
+ * @param int $num_items the total number of items, posts, topics, etc.
+ * @return int Current page number
+ */
+ public function validate_start($start, $per_page, $num_items)
+ {
+ if ($start < 0 || $start >= $num_items)
+ {
+ return ($start < 0) ? 0 : floor(($num_items - 1) / $per_page) * $per_page;
+ }
+
+ return $start;
+ }
+
+ /**
+ * Get new start when searching from the end
+ *
+ * If the user is trying to reach late pages, start searching from the end.
+ *
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @param int $limit the number of items, posts, etc. to display
+ * @param int $num_items the total number of items, posts, topics, etc.
+ * @return int Current page number
+ */
+ public function reverse_start($start, $limit, $num_items)
+ {
+ return max(0, $num_items - $limit - $start);
+ }
+
+ /**
+ * Get new item limit when searching from the end
+ *
+ * If the user is trying to reach late pages, start searching from the end.
+ * In this case the items to display might be lower then the actual per_page setting.
+ *
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @param int $per_page the number of items, posts, etc. per page
+ * @param int $num_items the total number of items, posts, topics, etc.
+ * @return int Current page number
+ */
+ public function reverse_limit($start, $per_page, $num_items)
+ {
+ if ($start + $per_page > $num_items)
+ {
+ return min($per_page, max(1, $num_items - $start));
+ }
+
+ return $per_page;
+ }
+}
diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php
index 8cd8808261..a8e12c4063 100644
--- a/phpBB/phpbb/path_helper.php
+++ b/phpBB/phpbb/path_helper.php
@@ -102,6 +102,27 @@ class path_helper
}
/**
+ * Strips away the web root path and prepends the normal root path
+ *
+ * This replaces get_web_root_path() . some_url with
+ * $phpbb_root_path . some_url
+ *
+ * @param string $path The path to be updated
+ * @return string
+ */
+ public function remove_web_root_path($path)
+ {
+ if (strpos($path, $this->get_web_root_path()) === 0)
+ {
+ $path = substr($path, strlen($this->get_web_root_path()));
+
+ return $this->phpbb_root_path . $path;
+ }
+
+ return $path;
+ }
+
+ /**
* Get a relative root path from the current URL
*
* @return string
@@ -162,4 +183,27 @@ class path_helper
*/
return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1);
}
+
+ /**
+ * Eliminates useless . and .. components from specified URL
+ *
+ * @param string $url URL to clean
+ *
+ * @return string Cleaned URL
+ */
+ public function clean_url($url)
+ {
+ $delimiter_position = strpos($url, '://');
+ // URL should contain :// but it shouldn't start with it.
+ // Do not clean URLs that do not fit these constraints.
+ if (empty($delimiter_position))
+ {
+ return $url;
+ }
+ $scheme = substr($url, 0, $delimiter_position) . '://';
+ // Add length of URL delimiter to position
+ $path = substr($url, $delimiter_position + 3);
+
+ return $scheme . $this->filesystem->clean_path($path);
+ }
}
diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php
index e158d33c01..3171a6edb7 100644
--- a/phpBB/phpbb/request/request.php
+++ b/phpBB/phpbb/request/request.php
@@ -217,7 +217,7 @@ class request implements \phpbb\request\request_interface
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
- public function untrimmed_variable($var_name, $default, $multibyte, $super_global = \phpbb\request\request_interface::REQUEST)
+ public function untrimmed_variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST)
{
return $this->_variable($var_name, $default, $multibyte, $super_global, false);
}
diff --git a/phpBB/phpbb/search/fulltext_mysql.php b/phpBB/phpbb/search/fulltext_mysql.php
index cdd2da222f..509b73e26e 100644
--- a/phpBB/phpbb/search/fulltext_mysql.php
+++ b/phpBB/phpbb/search/fulltext_mysql.php
@@ -216,7 +216,7 @@ class fulltext_mysql extends \phpbb\search\base
// We limit the number of allowed keywords to minimize load on the database
if ($this->config['max_num_search_keywords'] && sizeof($this->split_words) > $this->config['max_num_search_keywords'])
{
- trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], sizeof($this->split_words)));
+ trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], sizeof($this->split_words)));
}
// to allow phrase search, we need to concatenate quoted words
diff --git a/phpBB/phpbb/search/fulltext_native.php b/phpBB/phpbb/search/fulltext_native.php
index 1b314a24d3..1a89182978 100644
--- a/phpBB/phpbb/search/fulltext_native.php
+++ b/phpBB/phpbb/search/fulltext_native.php
@@ -277,7 +277,7 @@ class fulltext_native extends \phpbb\search\base
// We limit the number of allowed keywords to minimize load on the database
if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords'])
{
- trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], $num_keywords));
+ trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], $num_keywords));
}
// $keywords input format: each word separated by a space, words in a bracket are not separated