aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/style/style.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/style/style.php')
-rw-r--r--phpBB/includes/style/style.php154
1 files changed, 154 insertions, 0 deletions
diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php
new file mode 100644
index 0000000000..5dee0a138c
--- /dev/null
+++ b/phpBB/includes/style/style.php
@@ -0,0 +1,154 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Base Style class.
+* @package phpBB3
+*/
+class phpbb_style
+{
+ /**
+ * @var phpbb_style_template Template class.
+ * Handles everything related to templates.
+ */
+ public $template;
+
+ /**
+ * @var string phpBB root path
+ */
+ private $phpbb_root_path;
+
+ /**
+ * @var phpEx PHP file extension
+ */
+ private $phpEx;
+
+ /**
+ * @var phpbb_config phpBB config instance
+ */
+ private $config;
+
+ /**
+ * @var user current user
+ */
+ private $user;
+
+ /**
+ * Style resource locator
+ * @var phpbb_style_resource_locator
+ * This item is temporary public, until locate() function is implemented
+ */
+ public $locator;
+
+ /**
+ * Style path provider
+ * @var phpbb_style_path_provider
+ */
+ private $provider;
+
+ /**
+ * Constructor.
+ *
+ * @param string $phpbb_root_path phpBB root path
+ * @param user $user current user
+ * @param phpbb_extension_manager $phpbb_extension_manager extension manager. Set it to false if extension manager should not be used.
+ */
+ public function __construct($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager = false)
+ {
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->phpEx = $phpEx;
+ $this->config = $config;
+ $this->user = $user;
+ $this->locator = new phpbb_style_resource_locator();
+ $this->provider = new phpbb_style_path_provider();
+ if ($phpbb_extension_manager !== false)
+ {
+ $this->provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, $this->provider);
+ }
+ $this->template = new phpbb_style_template($this->phpbb_root_path, $this->phpEx, $this->config, $this->user, $this->locator, $this->provider);
+ }
+
+ /**
+ * Set style location based on (current) user's chosen style.
+ */
+ public function set_style()
+ {
+ $style_name = $this->user->theme['style_path'];
+ $style_dirs = ($this->user->theme['style_parent_id']) ? array_reverse(explode('/', $this->user->theme['style_parent_tree'])) : array();
+ $paths = array($this->get_style_path($style_name));
+ foreach ($style_dirs as $dir)
+ {
+ $paths[] = $this->get_style_path($dir);
+ }
+
+ return $this->set_custom_style($style_name, $paths);
+ }
+
+ /**
+ * Set custom style location (able to use directory outside of phpBB).
+ *
+ * Note: Templates are still compiled to phpBB's cache directory.
+ *
+ * @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver"
+ * @param array or string $paths Array of style paths, relative to current root directory
+ * @param string $template_path Path to templates, relative to style directory. False if path should not be changed.
+ */
+ public function set_custom_style($name, $paths, $template_path = false)
+ {
+ if (is_string($paths))
+ {
+ $paths = array($paths);
+ }
+
+ $this->provider->set_styles($paths);
+ $this->locator->set_paths($this->provider);
+ $this->locator->set_main_style($this->provider->get_main_style_path());
+
+ $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
+
+ $this->template->context = new phpbb_style_template_context();
+
+ if ($template_path !== false)
+ {
+ $this->template->template_path = $this->locator->template_path = $template_path;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get location of style directory for specific style_path
+ *
+ * @param string $path Style path, such as "prosilver"
+ * @return string Path to style directory, relative to current path
+ */
+ public function get_style_path($path)
+ {
+ return $this->phpbb_root_path . 'styles/' . $path;
+ }
+
+ /**
+ * Defines a prefix to use for style paths in extensions
+ *
+ * @param string $ext_dir_prefix The prefix including trailing slash
+ * @return null
+ */
+ public function set_ext_dir_prefix($ext_dir_prefix)
+ {
+ $this->provider->set_ext_dir_prefix($ext_dir_prefix);
+ }
+}