diff options
Diffstat (limited to 'phpBB/includes')
25 files changed, 610 insertions, 169 deletions
diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 92971c6cb2..e0771ab1d3 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))  * ACM Abstract Memory Class  * @package acm  */ -class phpbb_cache_driver_memory extends phpbb_cache_driver_base +abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base  {  	var $key_prefix; diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php index a768885962..a768885962 100755..100644 --- a/phpBB/includes/cache/driver/redis.php +++ b/phpBB/includes/cache/driver/redis.php diff --git a/phpBB/includes/cache/factory.php b/phpBB/includes/cache/factory.php deleted file mode 100644 index 01c4d0b901..0000000000 --- a/phpBB/includes/cache/factory.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -/** -* -* @package acm -* @copyright (c) 2010 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - -/** -* @package acm -*/ -class phpbb_cache_factory -{ -	private $acm_type; - -	public function __construct($acm_type) -	{ -		$this->acm_type = $acm_type; -	} - -	public function get_driver() -	{ -		$class_name = 'phpbb_cache_driver_' . $this->acm_type; -		return new $class_name(); -	} - -	public function get_service() -	{ -		$driver = $this->get_driver(); -		$service = new phpbb_cache_service($driver); -		return $service; -	} -} diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 7a78a1b054..ccaa4f3764 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -32,31 +32,35 @@ class phpbb_cron_manager  	*/  	protected $tasks = array(); +	protected $phpbb_root_path; +	protected $php_ext; +  	/**  	* Constructor. Loads all available tasks.  	* -	* @param array|Traversable $task_names Provides an iterable set of task names +	* @param array|Traversable $tasks Provides an iterable set of task names  	*/ -	public function __construct($task_names) +	public function __construct($tasks, $phpbb_root_path, $php_ext)  	{ -		$this->load_tasks($task_names); +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; + +		$this->load_tasks($tasks);  	}  	/**  	* Loads tasks given by name, wraps them  	* and puts them into $this->tasks.  	* -	* @param array|Traversable $task_names		Array of strings +	* @param array|Traversable $tasks		Array of instances of phpbb_cron_task  	*  	* @return void  	*/ -	public function load_tasks($task_names) +	public function load_tasks($tasks)  	{ -		foreach ($task_names as $task_name) +		foreach ($tasks as $task)  		{ -			$task = new $task_name(); -			$wrapper = new phpbb_cron_task_wrapper($task); -			$this->tasks[] = $wrapper; +			$this->tasks[] = $this->wrap_task($task);  		}  	} @@ -122,25 +126,13 @@ class phpbb_cron_manager  	}  	/** -	* Creates an instance of parametrized cron task $name with args $args. -	* The constructed task is wrapped with cron task wrapper before being returned. -	* -	* @param string $name		The task name, which is the same as cron task class name. -	* @param array $args		Will be passed to the task class's constructor. +	* Wraps a task inside an instance of phpbb_cron_task_wrapper.  	* -	* @return phpbb_cron_task_wrapper|null +	* @param  phpbb_cron_task 			$task The task. +	* @return phpbb_cron_task_wrapper	The wrapped task.  	*/ -	public function instantiate_task($name, array $args) +	public function wrap_task(phpbb_cron_task $task)  	{ -		$task = $this->find_task($name); -		if ($task) -		{ -			// task here is actually an instance of cron task wrapper -			$class = $task->get_name(); -			$task = new $class($args); -			// need to wrap the new task too -			$task = new phpbb_cron_task_wrapper($task); -		} -		return $task; +		return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->php_ext);  	}  } diff --git a/phpBB/includes/cron/task/base.php b/phpBB/includes/cron/task/base.php index c05fb9a87c..94a2f267b4 100644 --- a/phpBB/includes/cron/task/base.php +++ b/phpBB/includes/cron/task/base.php @@ -28,6 +28,28 @@ if (!defined('IN_PHPBB'))  */  abstract class phpbb_cron_task_base implements phpbb_cron_task  { +	private $name; + +	/** +	* Returns the name of the task. +	* +	* @return string		Name of wrapped task. +	*/ +	public function get_name() +	{ +		return $this->name; +	} + +	/** +	* Sets the name of the task. +	* +	* @param string	$name The task name +	*/ +	public function set_name($name) +	{ +		$this->name = $name; +	} +  	/**  	* Returns whether this cron task can run, given current board configuration.  	* diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 15b93a9ca6..252e16e57d 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -26,6 +26,27 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base  { +	protected $phpbb_root_path; +	protected $php_ext; +	protected $config; +	protected $db; + +	/** +	* Constructor. +	* +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	* @param phpbb_config $config The config +	* @param dbal $db The db connection +	*/ +	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->config = $config; +		$this->db = $db; +	} +  	/**  	* Runs this cron task.  	* @@ -33,19 +54,17 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base  	*/  	public function run()  	{ -		global $phpbb_root_path, $phpEx, $db; -  		if (!function_exists('auto_prune'))  		{ -			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); +			include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);  		}  		$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq  			FROM ' . FORUMS_TABLE . " -			WHERE enable_prune = 1  +			WHERE enable_prune = 1  				AND prune_next < " . time(); -		$result = $db->sql_query($sql); -		while ($row = $db->sql_fetchrow($result)) +		$result = $this->db->sql_query($sql); +		while ($row = $this->db->sql_fetchrow($result))  		{  			if ($row['prune_days'])  			{ @@ -57,7 +76,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base  				auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);  			}  		} -		$db->sql_freeresult($result); +		$this->db->sql_freeresult($result);  	}  	/** @@ -69,7 +88,6 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base  	*/  	public function is_runnable()  	{ -		global $config; -		return (bool) $config['use_system_cron']; +		return (bool) $this->config['use_system_cron'];  	}  } diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 7686fd4281..41d60af921 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -26,31 +26,45 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized  { -	private $forum_data; +	protected $phpbb_root_path; +	protected $php_ext; +	protected $config; +	protected $db;  	/** -	* Constructor. -	*  	* If $forum_data is given, it is assumed to contain necessary information  	* about a single forum that is to be pruned.  	*  	* If $forum_data is not given, forum id will be retrieved via request_var  	* and a database query will be performed to load the necessary information  	* about the forum. +	*/ +	protected $forum_data; + +	/** +	* Constructor. +	* +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	* @param phpbb_config $config The config +	* @param dbal $db The db connection +	*/ +	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->config = $config; +		$this->db = $db; +	} + +	/** +	* Manually set forum data.  	*  	* @param array $forum_data Information about a forum to be pruned.  	*/ -	public function __construct($forum_data = null) +	public function set_forum_data($forum_data)  	{ -		global $db; -		if ($forum_data) -		{ -			$this->forum_data = $forum_data; -		} -		else -		{ -			$this->forum_data = null; -		} +		$this->forum_data = $forum_data;  	}  	/** @@ -60,10 +74,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p  	*/  	public function run()  	{ -		global $phpbb_root_path, $phpEx;  		if (!function_exists('auto_prune'))  		{ -			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); +			include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);  		}  		if ($this->forum_data['prune_days']) @@ -90,8 +103,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p  	*/  	public function is_runnable()  	{ -		global $config; -		return !$config['use_system_cron'] && $this->forum_data; +		return !$this->config['use_system_cron'] && $this->forum_data;  	}  	/** @@ -130,8 +142,6 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p  	*/  	public function parse_parameters(phpbb_request_interface $request)  	{ -		global $db; -  		$this->forum_data = null;  		if ($request->is_set('f'))  		{ @@ -140,9 +150,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p  			$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq  				FROM ' . FORUMS_TABLE . "  				WHERE forum_id = $forum_id"; -			$result = $db->sql_query($sql); -			$row = $db->sql_fetchrow($result); -			$db->sql_freeresult($result); +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result);  			if ($row)  			{ diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 1c72eec7c7..c765660906 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -22,6 +22,24 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_queue extends phpbb_cron_task_base  { +	protected $phpbb_root_path; +	protected $php_ext; +	protected $config; + +	/** +	* Constructor. +	* +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	* @param phpbb_config $config The config +	*/ +	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->config = $config; +	} +  	/**  	* Runs this cron task.  	* @@ -29,10 +47,9 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base  	*/  	public function run()  	{ -		global $phpbb_root_path, $phpEx;  		if (!class_exists('queue'))  		{ -			include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); +			include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);  		}  		$queue = new queue();  		$queue->process(); @@ -47,8 +64,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base  	*/  	public function is_runnable()  	{ -		global $phpbb_root_path, $phpEx; -		return file_exists($phpbb_root_path . 'cache/queue.' . $phpEx); +		return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->php_ext);  	}  	/** @@ -61,7 +77,6 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base  	*/  	public function should_run()  	{ -		global $config; -		return $config['last_queue_run'] < time() - $config['queue_interval_config']; +		return $this->config['last_queue_run'] < time() - $this->config['queue_interval_config'];  	}  } diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index f6cf77d01d..6017eea561 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -22,6 +22,21 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base  { +	protected $config; +	protected $cache; + +	/** +	* Constructor. +	* +	* @param phpbb_config $config The config +	* @param phpbb_cache_driver_interface $cache The cache driver +	*/ +	public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) +	{ +		$this->config = $config; +		$this->cache = $cache; +	} +  	/**  	* Runs this cron task.  	* @@ -29,8 +44,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base  	*/  	public function run()  	{ -		global $cache; -		$cache->tidy(); +		$this->cache->tidy();  	}  	/** @@ -57,7 +71,6 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base  	*/  	public function should_run()  	{ -		global $config; -		return $config['cache_last_gc'] < time() - $config['cache_gc']; +		return $this->config['cache_last_gc'] < time() - $this->config['cache_gc'];  	}  } diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 80a1901b1e..1d256f964f 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -22,6 +22,24 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base  { +	protected $phpbb_root_path; +	protected $php_ext; +	protected $config; + +	/** +	* Constructor. +	* +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	* @param phpbb_config $config The config +	*/ +	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->config = $config; +	} +  	/**  	* Runs this cron task.  	* @@ -29,10 +47,9 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base  	*/  	public function run()  	{ -		global $phpbb_root_path, $phpEx;  		if (!function_exists('tidy_database'))  		{ -			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); +			include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);  		}  		tidy_database();  	} @@ -48,7 +65,6 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base  	*/  	public function should_run()  	{ -		global $config; -		return $config['database_last_gc'] < time() - $config['database_gc']; +		return $this->config['database_last_gc'] < time() - $this->config['database_gc'];  	}  } diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 7855c3760a..2e5f3d79d5 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -24,6 +24,33 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base  { +	protected $phpbb_root_path; +	protected $php_ext; +	protected $auth; +	protected $config; +	protected $db; +	protected $user; + +	/** +	* Constructor. +	* +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	* @param phpbb_auth $auth The auth +	* @param phpbb_config $config The config +	* @param dbal $db The db connection +	* @param phpbb_user $user The user +	*/ +	public function __construct($phpbb_root_path, $php_ext, phpbb_auth $auth, phpbb_config $config, dbal $db, phpbb_user $user) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->auth = $auth; +		$this->config = $config; +		$this->db = $db; +		$this->user = $user; +	} +  	/**  	* Runs this cron task.  	* @@ -31,19 +58,17 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base  	*/  	public function run()  	{ -		global $phpbb_root_path, $phpEx, $config, $error, $auth, $db, $user; -  		// Select the search method -		$search_type = basename($config['search_type']); +		$search_type = basename($this->config['search_type']);  		if (!class_exists($search_type))  		{ -			include("{$phpbb_root_path}includes/search/$search_type.$phpEx"); +			include($this->phpbb_root_path . "includes/search/$search_type." . $this->php_ext);  		}  		// We do some additional checks in the module to ensure it can actually be utilised  		$error = false; -		$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); +		$search = new $search_type($error, $this->phpbb_root_path, $this->php_ext, $this->auth, $this->config, $this->db, $this->user);  		if (!$error)  		{ @@ -62,12 +87,10 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base  	*/  	public function is_runnable()  	{ -		global $phpbb_root_path, $phpEx, $config; -  		// Select the search method -		$search_type = basename($config['search_type']); +		$search_type = basename($this->config['search_type']); -		return file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx); +		return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->php_ext);  	}  	/** @@ -81,7 +104,6 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base  	*/  	public function should_run()  	{ -		global $config; -		return $config['search_last_gc'] < time() - $config['search_gc']; +		return $this->config['search_last_gc'] < time() - $this->config['search_gc'];  	}  } diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index ae7bb242b8..13531aa30b 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -22,6 +22,21 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base  { +	protected $config; +	protected $user; + +	/** +	* Constructor. +	* +	* @param phpbb_config $config The config +	* @param phpbb_user $user The user +	*/ +	public function __construct(phpbb_config $config, phpbb_user $user) +	{ +		$this->config = $config; +		$this->user = $user; +	} +  	/**  	* Runs this cron task.  	* @@ -29,8 +44,7 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base  	*/  	public function run()  	{ -		global $user; -		$user->session_gc(); +		$this->user->session_gc();  	}  	/** @@ -44,7 +58,6 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base  	*/  	public function should_run()  	{ -		global $config; -		return $config['session_last_gc'] < time() - $config['session_gc']; +		return $this->config['session_last_gc'] < time() - $this->config['session_gc'];  	}  } diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index e1434e7087..8dd0674fe5 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -24,6 +24,24 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base  { +	protected $phpbb_root_path; +	protected $php_ext; +	protected $config; + +	/** +	* Constructor. +	* +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	* @param phpbb_config $config The config +	*/ +	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->config = $config; +	} +  	/**  	* Runs this cron task.  	* @@ -31,10 +49,9 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base  	*/  	public function run()  	{ -		global $phpbb_root_path, $phpEx;  		if (!function_exists('tidy_warnings'))  		{ -			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); +			include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);  		}  		tidy_warnings();  	} @@ -48,8 +65,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base  	*/  	public function is_runnable()  	{ -		global $config; -		return (bool) $config['warnings_expire_days']; +		return (bool) $this->config['warnings_expire_days'];  	}  	/** @@ -63,7 +79,6 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base  	*/  	public function should_run()  	{ -		global $config; -		return $config['warnings_last_gc'] < time() - $config['warnings_gc']; +		return $this->config['warnings_last_gc'] < time() - $this->config['warnings_gc'];  	}  } diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 1482051699..134723ebd1 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB'))  	exit;  } +use Symfony\Component\DependencyInjection\TaggedContainerInterface; +  /**  * Provides cron manager with tasks  * @@ -22,27 +24,36 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_provider extends phpbb_extension_provider +class phpbb_cron_task_provider implements IteratorAggregate  { +	private $container; + +	public function __construct(TaggedContainerInterface $container) +	{ +		$this->container = $container; +	} +  	/** -	* Finds cron task names using the extension manager. -	* -	* All PHP files in includes/cron/task/core/ are considered tasks. Tasks -	* in extensions have to be located in a directory called cron or a subdir -	* of a directory called cron. The class and filename must end in a _task -	* suffix. Additionally all PHP files in includes/cron/task/core/ are -	* tasks. +	* Retrieve an iterator over all items  	* -	* @return array     List of task names +	* @return ArrayIterator An iterator for the array of cron tasks  	*/ -	protected function find() +	public function getIterator()  	{ -		$finder = $this->extension_manager->get_finder(); +		$definitions = $this->container->findTaggedServiceIds('cron.task'); + +		$tasks = array(); +		foreach ($definitions as $name => $definition) +		{ +			$task = $this->container->get($name); +			if ($task instanceof phpbb_cron_task_base) +			{ +				$task->set_name($name); +			} + +			$tasks[] = $task; +		} -		return $finder -			->extension_suffix('_task') -			->extension_directory('/cron') -			->core_path('includes/cron/task/core/') -			->get_classes(); +		return new ArrayIterator($tasks);  	}  } diff --git a/phpBB/includes/cron/task/task.php b/phpBB/includes/cron/task/task.php index 2f2a9e51f9..7b08fed413 100644 --- a/phpBB/includes/cron/task/task.php +++ b/phpBB/includes/cron/task/task.php @@ -22,6 +22,13 @@ if (!defined('IN_PHPBB'))  interface phpbb_cron_task  {  	/** +	* Returns the name of the task. +	* +	* @return string		Name of wrapped task. +	*/ +	public function get_name(); + +	/**  	* Runs this cron task.  	*  	* @return void diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/includes/cron/task/wrapper.php index 66c45189e5..386fb5b383 100644 --- a/phpBB/includes/cron/task/wrapper.php +++ b/phpBB/includes/cron/task/wrapper.php @@ -23,6 +23,10 @@ if (!defined('IN_PHPBB'))  */  class phpbb_cron_task_wrapper  { +	protected $task; +	protected $phpbb_root_path; +	protected $php_ext; +  	/**  	* Constructor.  	* @@ -30,9 +34,11 @@ class phpbb_cron_task_wrapper  	*  	* @param phpbb_cron_task $task The cron task to wrap.  	*/ -	public function __construct(phpbb_cron_task $task) +	public function __construct(phpbb_cron_task $task, $phpbb_root_path, $php_ext)  	{  		$this->task = $task; +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext;  	}  	/** @@ -62,16 +68,6 @@ class phpbb_cron_task_wrapper  	}  	/** -	* Returns the name of wrapped task. It is the same as the wrapped class's class name. -	* -	* @return string		Class name of wrapped task. -	*/ -	public function get_name() -	{ -		return get_class($this->task); -	} - -	/**  	* Returns a url through which this task may be invoked via web.  	*  	* When system cron is not in use, running a cron task is accomplished @@ -82,8 +78,6 @@ class phpbb_cron_task_wrapper  	*/  	public function get_url()  	{ -		global $phpbb_root_path, $phpEx; -  		$name = $this->get_name();  		if ($this->is_parametrized())  		{ @@ -98,7 +92,7 @@ class phpbb_cron_task_wrapper  		{  			$extra = '';  		} -		$url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $name . $extra); +		$url = append_sid($this->phpbb_root_path . 'cron.' . $this->php_ext, 'cron_type=' . $name . $extra);  		return $url;  	} diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 36ff461a29..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, diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/processor/config.php new file mode 100644 index 0000000000..22b6252a6d --- /dev/null +++ b/phpBB/includes/di/processor/config.php @@ -0,0 +1,76 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** +* Configure the container for phpBB's services though +* user-defined parameters defined in the config.php file. +*/ +class phpbb_di_processor_config implements phpbb_di_processor_interface +{ +	private $config_file; +	private $phpbb_root_path; +	private $php_ext; + +	/** +	* Constructor. +	* +	* @param string $config_file The config file +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	*/ +	public function __construct($config_file, $phpbb_root_path, $php_ext) +	{ +		$this->config_file = $config_file; +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +	} + +	/** +	* @inheritdoc +	*/ +	public function process(ContainerBuilder $container) +	{ +		require $this->config_file; + +		$container->setParameter('core.root_path', $this->phpbb_root_path); +		$container->setParameter('core.php_ext', $this->php_ext); + +		$container->setParameter('core.table_prefix', $table_prefix); +		$container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); +		$container->setParameter('dbal.driver.class', 'dbal_'.$dbms); +		$container->setParameter('dbal.dbhost', $dbhost); +		$container->setParameter('dbal.dbuser', $dbuser); +		$container->setParameter('dbal.dbpasswd', $dbpasswd); +		$container->setParameter('dbal.dbname', $dbname); +		$container->setParameter('dbal.dbport', $dbport); +		$container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); + +		$container->set('container', $container); +	} + +	protected function fix_acm_type($acm_type) +	{ +		if (preg_match('#^[a-z]+$#', $acm_type)) +		{ +			return 'phpbb_cache_driver_'.$acm_type; +		} + +		return $acm_type; +	} +} diff --git a/phpBB/includes/di/processor/ext.php b/phpBB/includes/di/processor/ext.php new file mode 100644 index 0000000000..e69a3d73b3 --- /dev/null +++ b/phpBB/includes/di/processor/ext.php @@ -0,0 +1,54 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + +/** +* Load the service configurations from all extensions into the container. +*/ +class phpbb_di_processor_ext implements phpbb_di_processor_interface +{ +	private $extension_manager; + +	/** +	* Constructor. +	* +	* @param string $extension_manager The extension manager +	*/ +	public function __construct($extension_manager) +	{ +		$this->extension_manager = $extension_manager; +	} + +	/** +	* @inheritdoc +	*/ +	public function process(ContainerBuilder $container) +	{ +		$enabled_exts = $this->extension_manager->all_enabled(); +		foreach ($enabled_exts as $name => $path) +		{ +			if (file_exists($path . '/config/services.yml')) +			{ +				$loader = new YamlFileLoader($container, new FileLocator($path . '/config')); +				$loader->load('services.yml'); +			} +		} +	} +} diff --git a/phpBB/includes/di/processor/interface.php b/phpBB/includes/di/processor/interface.php new file mode 100644 index 0000000000..b8563791cc --- /dev/null +++ b/phpBB/includes/di/processor/interface.php @@ -0,0 +1,28 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +use Symfony\Component\DependencyInjection\ContainerBuilder; + +interface phpbb_di_processor_interface +{ +	/** +	* Mutate the container. +	* +	* @param ContainerBuilder $container The container +	*/ +	public function process(ContainerBuilder $container); +} diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9f1172e61e..834f57a38b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2855,7 +2855,7 @@ function check_form_key($form_name, $timespan = false, $return_page = '', $trigg  		$diff = time() - $creation_time;  		// If creation_time and the time() now is zero we can assume it was not a human doing this (the check for if ($diff)... -		if ($diff && ($diff <= $timespan || $timespan === -1)) +		if (defined('DEBUG_TEST') || $diff && ($diff <= $timespan || $timespan === -1))  		{  			$token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : '';  			$key = sha1($creation_time . $user->data['user_form_salt'] . $form_name . $token_sid); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 66e8459c18..881c95907b 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1387,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_install.php b/phpBB/includes/functions_install.php index 46541acd44..10ec13669b 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -522,10 +522,12 @@ function adjust_language_keys_callback($matches)  * @param	string	$dbms The name of the DBAL class to use  * @param	array	$load_extensions Array of additional extensions that should be loaded  * @param	bool	$debug If the debug constants should be enabled by default or not +* @param	bool	$debug_test If the DEBUG_TEST constant should be added +*					NOTE: Only for use within the testing framework  *  * @return	string	The output to write to the file  */ -function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false) +function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false, $debug_test = false)  {  	$load_extensions = implode(',', $load_extensions); @@ -540,7 +542,7 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug =  		'dbuser'		=> $data['dbuser'],  		'dbpasswd'		=> htmlspecialchars_decode($data['dbpasswd']),  		'table_prefix'	=> $data['table_prefix'], -		'acm_type'		=> 'file', +		'acm_type'		=> 'phpbb_cache_driver_file',  		'load_extensions'	=> $load_extensions,  	); @@ -562,5 +564,10 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug =  		$config_data .= "// @define('DEBUG_EXTRA', true);\n";  	} +	if ($debug_test) +	{ +		$config_data .= "@define('DEBUG_TEST', true);\n"; +	} +  	return $config_data;  } diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index 569232d878..c85b05f144 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -257,6 +257,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)  		'U_PM_ACTION'		=> $url . '&mode=compose&f=' . $folder_id . '&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)), @@ -301,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(  | 
