diff options
| author | Igor Wiedler <igor@wiedler.ch> | 2012-04-08 23:03:17 +0200 |
|---|---|---|
| committer | Igor Wiedler <igor@wiedler.ch> | 2012-04-08 23:03:17 +0200 |
| commit | 9165a045c5dee06bb5c163281bb817369a1733a3 (patch) | |
| tree | 7e27a3e6720eb9943e0d344d92dc443cd5be77a9 /phpBB/includes | |
| parent | e78fbfef9c6aac1349d18454a4292781d661795c (diff) | |
| parent | 26e7dd98b71655c7e09be02ebd3ef84765ce27b8 (diff) | |
| download | forums-9165a045c5dee06bb5c163281bb817369a1733a3.tar forums-9165a045c5dee06bb5c163281bb817369a1733a3.tar.gz forums-9165a045c5dee06bb5c163281bb817369a1733a3.tar.bz2 forums-9165a045c5dee06bb5c163281bb817369a1733a3.tar.xz forums-9165a045c5dee06bb5c163281bb817369a1733a3.zip | |
Merge remote-tracking branch 'upstream/develop' into feature/dic
* upstream/develop: (76 commits)
[ticket/10561] Removed extra tabs, changes made to $db->sql_query()
[ticket/10561] Changed $temp_style_id to $style_id
[ticket/10561] Added function desc for phpbb_style_is_active()
[ticket/10561] Casted $config['default_style'] to int
[ticket/10561] Reverted to phpbb_style_is_active()
[ticket/10561] Added to database_update:database_update_info()
[ticket/10561] Added section in database_update.php
[ticket/10764] FAQ now mentions Area51 instead of SourceForge
[ticket/10764] FAQ now mentions GitHub instead of SourceForge
[ticket/10455] Removed NOTE from prosilver overall_header.html.
[ticket/10561] Moved and renamed the funtion validate_style().
[ticket/10575] Adding public visibility to the methods.
[ticket/10575] Fixing non-static access to static functions get_instance
[ticket/10547] User is not logged in as admin after installation
[ticket/10650] Revert merge of 'rahulr92/ticket/10650' into develop
[ticket/10650] Added checking for empty subjects
[ticket/10650] Corrected intendation
[ticket/10650]Added permission checking and utf8 functions
[ticket/10650] Cropped subject and inserted newline
[ticket/10650] Corrected space before true
...
Diffstat (limited to 'phpBB/includes')
22 files changed, 619 insertions, 388 deletions
diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 2772fb2217..d33be274b4 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -20,31 +20,53 @@ if (!defined('IN_PHPBB')) */ class acp_styles { - var $u_action; - var $u_base_action; - var $s_hidden_fields; - var $mode; - var $styles_path; - var $styles_path_absolute = 'styles'; - - function main($id, $mode) + public $u_action; + + protected $u_base_action; + protected $s_hidden_fields; + protected $mode; + protected $styles_path; + protected $styles_path_absolute = 'styles'; + protected $default_style = 0; + + protected $db; + protected $user; + protected $template; + protected $request; + protected $cache; + protected $auth; + protected $phpbb_root_path; + protected $phpEx; + + public function main($id, $mode) { - global $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request; + global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config; + + $this->db = $db; + $this->user = $user; + $this->template = $template; + $this->request = $request; + $this->cache = $cache; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; - $this->styles_path = $phpbb_root_path . $this->styles_path_absolute . '/'; + $this->default_style = $config['default_style']; + $this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/'; $this->u_base_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}"); $this->s_hidden_fields = array( 'mode' => $mode, ); - $user->add_lang('acp/styles'); + $this->user->add_lang('acp/styles'); $this->tpl_name = 'acp_styles'; $this->page_title = 'ACP_CAT_STYLES'; $this->mode = $mode; - $action = $request->variable('action', ''); + $action = $this->request->variable('action', ''); $post_actions = array('install', 'activate', 'deactivate', 'uninstall'); foreach ($post_actions as $key) { @@ -58,12 +80,12 @@ class acp_styles $this->s_hidden_fields['action'] = $action; } - $template->assign_vars(array( + $this->template->assign_vars(array( 'U_ACTION' => $this->u_base_action, 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields) ) ); - + // Execute actions switch ($action) { @@ -86,11 +108,11 @@ class acp_styles $this->frontend(); } } - + /** * Main page */ - function frontend() + protected function frontend() { // Check mode switch ($this->mode) @@ -107,41 +129,36 @@ class acp_styles $this->action_cache(); return; } - global $user; - trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } - + /** * Purge cache */ - function action_cache() + protected function action_cache() { - global $cache, $auth, $user; - - $cache->purge(); + $this->cache->purge(); // Clear permissions - $auth->acl_clear_prefetch(); + $this->auth->acl_clear_prefetch(); cache_moderators(); add_log('admin', 'LOG_PURGE_CACHE'); - - trigger_error($user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); + + trigger_error($this->user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } - + /** * Install style(s) */ - function action_install() + protected function action_install() { - global $user; - // Get list of styles to install $dirs = $this->request_vars('dir', '', true); - + // Get list of styles that can be installed $styles = $this->find_available(false); - + // Install each style $messages = array(); $installed_names = array(); @@ -166,52 +183,50 @@ class acp_styles $last_installed = $style['style_id']; $installed_names[] = $style['style_name']; $installed_dirs[] = $style['style_path']; - $messages[] = sprintf($user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name'])); + $messages[] = sprintf($this->user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name'])); } } if (!$found) { - $messages[] = sprintf($user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); + $messages[] = sprintf($this->user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); } } - + // Show message if (!count($messages)) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } $message = implode('<br />', $messages); - $message .= '<br /><br />' . sprintf($user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); - $message .= '<br /><br />' . sprintf($user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); + $message .= '<br /><br />' . sprintf($this->user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); + $message .= '<br /><br />' . sprintf($this->user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); trigger_error($message, E_USER_NOTICE); } - + /** * Confirm styles removal */ - function action_uninstall() + protected function action_uninstall() { - global $user, $config, $template, $request; - // Get list of styles to uninstall $ids = $this->request_vars('id', 0, true); - + // Check if confirmation box was submitted if (confirm_box(true)) { // Uninstall - $this->action_uninstall_confirmed($ids, $request->variable('confirm_delete_files', false)); + $this->action_uninstall_confirmed($ids, $this->request->variable('confirm_delete_files', false)); return; } - + // Confirm box $s_hidden = build_hidden_fields(array( 'action' => 'uninstall', 'ids' => $ids )); - $template->assign_var('S_CONFIRM_DELETE', true); - confirm_box(false, $user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); - + $this->template->assign_var('S_CONFIRM_DELETE', true); + confirm_box(false, $this->user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); + // Canceled - show styles list $this->frontend(); } @@ -222,11 +237,9 @@ class acp_styles * @param array $ids List of style IDs * @param bool $delete_files If true, script will attempt to remove files for selected styles */ - function action_uninstall_confirmed($ids, $delete_files) + protected function action_uninstall_confirmed($ids, $delete_files) { - global $db, $user, $cache, $config; - - $default = $config['default_style']; + $default = $this->default_style; $uninstalled = array(); $messages = array(); @@ -235,11 +248,11 @@ class acp_styles { if (!$id) { - trigger_error($user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($id == $default) { - trigger_error($user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); } $uninstalled[$id] = false; } @@ -250,10 +263,10 @@ class acp_styles FROM ' . STYLES_TABLE . ' WHERE style_id IN (' . implode(', ', $ids) . ') ORDER BY style_id DESC'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); // Uinstall each style $uninstalled = array(); @@ -266,20 +279,20 @@ class acp_styles $messages[] = $result; continue; } - $messages[] = sprintf($user->lang['STYLE_UNINSTALLED'], $style['style_name']); + $messages[] = sprintf($this->user->lang['STYLE_UNINSTALLED'], $style['style_name']); $uninstalled[] = $style['style_name']; // Attempt to delete files if ($delete_files) { - $messages[] = sprintf($user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']); + $messages[] = sprintf($this->user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']); } } if (empty($messages)) { // Nothing to uninstall? - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } // Log action @@ -289,7 +302,7 @@ class acp_styles } // Clear cache - $cache->purge(); + $this->cache->purge(); // Show message trigger_error(implode('<br />', $messages) . adm_back_link($this->u_action), E_USER_NOTICE); @@ -298,22 +311,20 @@ class acp_styles /** * Activate styles */ - function action_activate() + protected function action_activate() { - global $user, $config, $cache, $db; - // Get list of styles to activate $ids = $this->request_vars('id', 0, true); - + // Activate styles $sql = 'UPDATE ' . STYLES_TABLE . ' SET style_active = 1 WHERE style_id IN (' . implode(', ', $ids) . ')'; - $db->sql_query($sql); + $this->db->sql_query($sql); // Purge cache - $cache->destroy('sql', STYLES_TABLE); - + $this->cache->destroy('sql', STYLES_TABLE); + // Show styles list $this->frontend(); } @@ -321,19 +332,17 @@ class acp_styles /** * Deactivate styles */ - function action_deactivate() + protected function action_deactivate() { - global $user, $config, $cache, $db; - // Get list of styles to deactivate $ids = $this->request_vars('id', 0, true); // Check for default style foreach ($ids as $id) { - if ($id == $config['default_style']) + if ($id == $this->default_style) { - trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); } } @@ -341,38 +350,36 @@ class acp_styles $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE user_style IN (' . implode(', ', $ids) . ')'; - $db->sql_query($sql); + $this->db->sql_query($sql); // Deactivate styles $sql = 'UPDATE ' . STYLES_TABLE . ' SET style_active = 0 WHERE style_id IN (' . implode(', ', $ids) . ')'; - $db->sql_query($sql); + $this->db->sql_query($sql); // Purge cache - $cache->destroy('sql', STYLES_TABLE); + $this->cache->destroy('sql', STYLES_TABLE); // Show styles list $this->frontend(); } - + /** * Show style details */ - function action_details() + protected function action_details() { - global $user, $config, $db, $request, $template, $cache; - - $id = $request->variable('id', 0); + $id = $this->request->variable('id', 0); if (!$id) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - + // Get all styles $styles = $this->get_styles(); - usort($styles, 'acp_styles::sort_styles'); - + usort($styles, array($this, 'sort_styles')); + // Find current style $style = false; foreach ($styles as $row) @@ -386,34 +393,43 @@ class acp_styles if ($style === false) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - + // Find all available parent styles $list = $this->find_possible_parents($styles, $id); - + + // Add form key + $form_key = 'acp_styles'; + add_form_key($form_key); + // Change data - if ($request->variable('update', false)) + if ($this->request->variable('update', false)) { + if (!check_form_key($form_key)) + { + trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $update = array( - 'style_name' => trim($request->variable('style_name', $style['style_name'])), - 'style_parent_id' => $request->variable('style_parent', (int) $style['style_parent_id']), - 'style_active' => $request->variable('style_active', (int) $style['style_active']), + 'style_name' => trim($this->request->variable('style_name', $style['style_name'])), + 'style_parent_id' => $this->request->variable('style_parent', (int) $style['style_parent_id']), + 'style_active' => $this->request->variable('style_active', (int) $style['style_active']), ); $update_action = $this->u_action . '&action=details&id=' . $id; - + // Check style name if ($update['style_name'] != $style['style_name']) { if (!strlen($update['style_name'])) { - trigger_error($user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING); } foreach ($styles as $row) { if ($row['style_name'] == $update['style_name']) { - trigger_error($user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING); } } } @@ -421,7 +437,7 @@ class acp_styles { unset($update['style_name']); } - + // Check parent style id if ($update['style_parent_id'] != $style['style_parent_id']) { @@ -439,7 +455,7 @@ class acp_styles } if (!$found) { - trigger_error($user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING); } } else @@ -451,64 +467,64 @@ class acp_styles { unset($update['style_parent_id']); } - + // Check style_active if ($update['style_active'] != $style['style_active']) { - if (!$update['style_active'] && $config['default_style'] == $style['style_id']) + if (!$update['style_active'] && $this->default_style == $style['style_id']) { - trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING); } } else { unset($update['style_active']); } - + // Update data if (count($update)) { $sql = 'UPDATE ' . STYLES_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $update) . " + SET ' . $this->db->sql_build_array('UPDATE', $update) . " WHERE style_id = $id"; - $db->sql_query($sql); - + $this->db->sql_query($sql); + $style = array_merge($style, $update); - + if (isset($update['style_parent_id'])) { // Update styles tree $styles = $this->get_styles(); - if ($this->update_styles_tree(&$styles, $style)) + if ($this->update_styles_tree($styles, $style)) { // Something was changed in styles tree, purge all cache - $cache->purge(); + $this->cache->purge(); } } add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']); } - + // Update default style - $default = $request->variable('style_default', 0); + $default = $this->request->variable('style_default', 0); if ($default) { if (!$style['style_active']) { - trigger_error($user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING); } set_config('default_style', $id); - $cache->purge(); + $this->cache->purge(); } - + // Show styles list $this->frontend(); return; } - + // Show parent styles foreach ($list as $row) { - $template->assign_block_vars('parent_styles', array( + $this->template->assign_block_vars('parent_styles', array( 'STYLE_ID' => $row['style_id'], 'STYLE_NAME' => htmlspecialchars($row['style_name']), 'LEVEL' => $row['level'], @@ -516,9 +532,9 @@ class acp_styles ) ); } - + // Show style details - $template->assign_vars(array( + $this->template->assign_vars(array( 'S_STYLE_DETAILS' => true, 'STYLE_ID' => $style['style_id'], 'STYLE_NAME' => htmlspecialchars($style['style_name']), @@ -526,7 +542,7 @@ class acp_styles 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), 'STYLE_PARENT' => $style['style_parent_id'], 'S_STYLE_ACTIVE' => $style['style_active'], - 'S_STYLE_DEFAULT' => ($style['style_id'] == $config['default_style']) + 'S_STYLE_DEFAULT' => ($style['style_id'] == $this->default_style) ) ); } @@ -534,65 +550,63 @@ class acp_styles /** * List installed styles */ - function show_installed() + protected function show_installed() { - global $user, $template; - // Get all installed styles $styles = $this->get_styles(); if (!count($styles)) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - - usort($styles, 'acp_styles::sort_styles'); + + usort($styles, array($this, 'sort_styles')); // Get users $users = $this->get_users(); - + // Add users counter to rows foreach ($styles as &$style) { $style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0; } - + // Set up styles list variables // Addons should increase this number and update template variable $this->styles_list_cols = 4; - $template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); + $this->template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); // Show styles list - $this->show_styles_list(&$styles, 0, 0); - + $this->show_styles_list($styles, 0, 0); + // Show styles with invalid inherits_id foreach ($styles as $style) { if (empty($style['_shown'])) { - $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree'])); + $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree'])); $this->list_style($style, 0); } } // Add buttons - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'activate', - 'L_ACTION' => $user->lang['STYLE_ACTIVATE'], + 'L_ACTION' => $this->user->lang['STYLE_ACTIVATE'], ) ); - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'deactivate', - 'L_ACTION' => $user->lang['STYLE_DEACTIVATE'], + 'L_ACTION' => $this->user->lang['STYLE_DEACTIVATE'], ) ); if (isset($this->style_counters) && $this->style_counters['total'] > 1) { - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'uninstall', - 'L_ACTION' => $user->lang['STYLE_UNINSTALL'], + 'L_ACTION' => $this->user->lang['STYLE_UNINSTALL'], ) ); } @@ -601,28 +615,26 @@ class acp_styles /** * Show list of styles that can be installed */ - function show_available() + protected function show_available() { - global $user, $template; - // Get list of styles $styles = $this->find_available(true); - + // Show styles if (empty($styles)) { - trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); + trigger_error($this->user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } - - usort($styles, 'acp_styles::sort_styles'); + + usort($styles, array($this, 'sort_styles')); $this->styles_list_cols = 3; - $template->assign_vars(array( + $this->template->assign_vars(array( 'STYLES_LIST_COLS' => $this->styles_list_cols, 'STYLES_LIST_HIDE_COUNT' => true ) ); - + // Show styles foreach ($styles as &$style) { @@ -641,41 +653,39 @@ class acp_styles } if (!$has_parent) { - $this->list_style(&$style, 0); - $this->show_available_child_styles(&$styles, $style['style_name'], 1); + $this->list_style($style, 0); + $this->show_available_child_styles($styles, $style['style_name'], 1); } } - + // Show styles that do not have parent style in styles list foreach ($styles as $style) { if (empty($style['_shown'])) { - $this->list_style(&$style, 0); + $this->list_style($style, 0); } } - + // Add button if (isset($this->style_counters) && $this->style_counters['caninstall'] > 0) { - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'install', - 'L_ACTION' => $user->lang['INSTALL_STYLES'], + 'L_ACTION' => $this->user->lang['INSTALL_STYLES'], ) ); } } - + /** * Find styles available for installation * * @param bool $all if true, function will return all installable styles. if false, function will return only styles that can be installed - * @returns array list of styles + * @return array List of styles */ - function find_available($all) + protected function find_available($all) { - global $user; - // Get list of installed styles $installed = $this->get_styles(); @@ -691,10 +701,10 @@ class acp_styles 'tree' => (strlen($style['style_parent_tree']) ? $style['style_parent_tree'] . '/' : '') . $style['style_path'], ); } - + // Get list of directories $dirs = $this->find_style_dirs(); - + // Find styles that can be installed $styles = array(); foreach ($dirs as $dir) @@ -743,10 +753,10 @@ class acp_styles { // Parent style is not installed yet $style['_available'] = false; - $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); + $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); } } - + if ($all || $style['_available']) { $styles[] = $style; @@ -755,7 +765,7 @@ class acp_styles return $styles; } - + /** * Show styles list * @@ -763,18 +773,18 @@ class acp_styles * @param int $parent parent style id * @param int $level style inheritance level */ - function show_styles_list($styles, $parent, $level) + protected function show_styles_list(&$styles, $parent, $level) { foreach ($styles as &$style) { if (empty($style['_shown']) && $style['style_parent_id'] == $parent) { - $this->list_style(&$style, $level); - $this->show_styles_list(&$styles, $style['style_id'], $level + 1); + $this->list_style($style, $level); + $this->show_styles_list($styles, $style['style_id'], $level + 1); } } } - + /** * Show available styles tree * @@ -782,26 +792,26 @@ class acp_styles * @param string $name Name of parent style * @param string $level Styles tree level */ - function show_available_child_styles($styles, $name, $level) + protected function show_available_child_styles(&$styles, $name, $level) { foreach ($styles as &$style) { if (empty($style['_shown']) && $style['_inherit_name'] == $name) { - $this->list_style(&$style, $level); - $this->show_available_child_styles(&$styles, $style['style_name'], $level + 1); + $this->list_style($style, $level); + $this->show_available_child_styles($styles, $style['style_name'], $level + 1); } } } - + /** * Update styles tree * * @param array $styles Styles list, passed as reference * @param array $style Current style, false if root - * @returns true if something was updated, false if not + * @return bool True if something was updated, false if not */ - function update_styles_tree($styles, $style = false) + protected function update_styles_tree(&$styles, $style = false) { $parent_id = ($style === false) ? 0 : $style['style_id']; $parent_tree = ($style === false) ? '' : ($style['style_parent_tree'] == '' ? '' : $style['style_parent_tree']) . $style['style_path']; @@ -816,21 +826,20 @@ class acp_styles $row['style_parent_tree'] = $parent_tree; $update = true; } - $updated |= $this->update_styles_tree(&$styles, $row); + $updated |= $this->update_styles_tree($styles, $row); } } if ($update) { - global $db; $sql = 'UPDATE ' . STYLES_TABLE . " - SET style_parent_tree = '" . $db->sql_escape($parent_tree) . "' + SET style_parent_tree = '" . $this->db->sql_escape($parent_tree) . "' WHERE style_parent_id = {$parent_id}"; - $db->sql_query($sql); + $this->db->sql_query($sql); $updated = true; } return $updated; } - + /** * Find all possible parent styles for style * @@ -838,9 +847,9 @@ class acp_styles * @param int $id id of style * @param int $parent current parent style id * @param int $level current tree level - * @returns array of style ids, names and levels + * @return array Style ids, names and levels */ - function find_possible_parents($styles, $id = -1, $parent = 0, $level = 0) + protected function find_possible_parents($styles, $id = -1, $parent = 0, $level = 0) { $results = array(); foreach ($styles as $style) @@ -860,21 +869,19 @@ class acp_styles } return $results; } - + /** * Show item in styles list * * @param array $style style row * @param array $level style inheritance level */ - function list_style($style, $level) + protected function list_style(&$style, $level) { - global $template, $config, $db, $user, $phpbb_root_path, $phpEx; - // Mark row as shown if (!empty($style['_shown'])) return; $style['_shown'] = true; - + // Generate template variables $actions = array(); $row = array( @@ -884,56 +891,56 @@ class acp_styles 'STYLE_PATH' => htmlspecialchars($style['style_path']), 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), 'STYLE_ACTIVE' => $style['style_active'], - + // Additional data - 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $config['default_style']), + 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $this->default_style), 'USERS' => (isset($style['_users'])) ? $style['_users'] : '', 'LEVEL' => $level, 'PADDING' => (4 + 16 * $level), 'SHOW_COPYRIGHT' => ($style['style_id']) ? false : true, 'STYLE_PATH_FULL' => htmlspecialchars($this->styles_path_absolute . '/' . $style['style_path']) . '/', - + // Comment to show below style 'COMMENT' => (isset($style['_note'])) ? $style['_note'] : '', - + // The following variables should be used by hooks to add custom HTML code 'EXTRA' => '', 'EXTRA_OPTIONS' => '' ); - + // Status specific data if ($style['style_id']) { // Style is installed - + // Details $actions[] = array( 'U_ACTION' => $this->u_action . '&action=details&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['DETAILS'] + 'L_ACTION' => $this->user->lang['DETAILS'] ); // Activate $actions[] = array( 'U_ACTION' => $this->u_action . '&action=' . ($style['style_active'] ? 'de' : '') . 'activate&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE'] + 'L_ACTION' => $this->user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE'] ); /* // Export $actions[] = array( 'U_ACTION' => $this->u_action . '&action=export&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['EXPORT'] + 'L_ACTION' => $this->user->lang['EXPORT'] ); */ // Uninstall $actions[] = array( 'U_ACTION' => $this->u_action . '&action=uninstall&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['STYLE_UNINSTALL'] + 'L_ACTION' => $this->user->lang['STYLE_UNINSTALL'] ); - + // Preview $actions[] = array( - 'U_ACTION' => append_sid("{$phpbb_root_path}index.$phpEx", 'style=' . $style['style_id']), - 'L_ACTION' => $user->lang['PREVIEW'] + 'U_ACTION' => append_sid($this->phpbb_root_path . 'index.' . $this->phpEx, 'style=' . $style['style_id']), + 'L_ACTION' => $this->user->lang['PREVIEW'] ); } else @@ -942,27 +949,27 @@ class acp_styles if (empty($style['_available'])) { $actions[] = array( - 'HTML' => $user->lang['CANNOT_BE_INSTALLED'] + 'HTML' => $this->user->lang['CANNOT_BE_INSTALLED'] ); } else { $actions[] = array( 'U_ACTION' => $this->u_action . '&action=install&dir=' . urlencode($style['style_path']), - 'L_ACTION' => $user->lang['INSTALL_STYLE'] + 'L_ACTION' => $this->user->lang['INSTALL_STYLE'] ); } } - + // todo: add hook - + // Assign template variables - $template->assign_block_vars('styles_list', $row); + $this->template->assign_block_vars('styles_list', $row); foreach($actions as $action) { - $template->assign_block_vars('styles_list.actions', $action); + $this->template->assign_block_vars('styles_list.actions', $action); } - + // Increase counters $counter = ($style['style_id']) ? ($style['style_active'] ? 'active' : 'inactive') : (empty($style['_available']) ? 'cannotinstall' : 'caninstall'); if (!isset($this->style_counters)) @@ -975,32 +982,31 @@ class acp_styles 'cannotinstall' => 0 ); } - $this->style_counters[$counter] ++; - $this->style_counters['total'] ++; + $this->style_counters[$counter]++; + $this->style_counters['total']++; } - + /** * Show welcome message * * @param string $title main title * @param string $description page description */ - function welcome_message($title, $description) + protected function welcome_message($title, $description) { - global $user, $template; - $template->assign_vars(array( - 'L_TITLE' => (isset($user->lang[$title])) ? $user->lang[$title] : $title, - 'L_EXPLAIN' => (isset($user->lang[$description])) ? $user->lang[$description] : $description + $this->template->assign_vars(array( + 'L_TITLE' => $this->user->lang[$title], + 'L_EXPLAIN' => (isset($this->user->lang[$description])) ? $this->user->lang[$description] : '' ) ); } - + /** * Find all directories that have styles * - * @returns array of directory names + * @return array Directory names */ - function find_style_dirs() + protected function find_style_dirs() { $styles = array(); @@ -1025,11 +1031,11 @@ class acp_styles return $styles; } - + /** * Sort styles */ - function sort_styles($style1, $style2) + public function sort_styles($style1, $style2) { if ($style1['style_active'] != $style2['style_active']) { @@ -1041,19 +1047,18 @@ class acp_styles } return strcasecmp(isset($style1['style_name']) ? $style1['style_name'] : $style1['name'], isset($style2['style_name']) ? $style2['style_name'] : $style2['name']); } - + /** * Read style configuration file * * @param string $dir style directory - * @returns array of style data - * @returns false on error + * @return array|bool Style data, false on error */ - function read_style_cfg($dir) + protected function read_style_cfg($dir) { static $required = array('name', 'version', 'copyright'); $cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg'); - + // Check if it is a valid file foreach ($required as $key) { @@ -1062,7 +1067,7 @@ class acp_styles return false; } } - + // Check data if (!isset($cfg['parent']) || !is_string($cfg['parent']) || $cfg['parent'] == $cfg['name']) { @@ -1072,20 +1077,18 @@ class acp_styles { $cfg['template_bitfield'] = $this->default_bitfield(); } - + return $cfg; } - + /** * Install style * * @param $style style data - * @returns int style id + * @return int Style id */ - function install_style($style) + protected function install_style($style) { - global $db; - // Generate row $sql_ary = array(); foreach ($style as $key => $value) @@ -1095,38 +1098,36 @@ class acp_styles $sql_ary[$key] = $value; } } - + // Add to database - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); $sql = 'INSERT INTO ' . STYLES_TABLE . ' - ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); + ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); - $id = $db->sql_nextid(); + $id = $this->db->sql_nextid(); - $db->sql_transaction('commit'); + $this->db->sql_transaction('commit'); add_log('admin', 'LOG_STYLE_ADD', $sql_ary['style_name']); - + return $id; } /** * Lists all styles * - * @returns array of rows with styles data + * @return array Rows with styles data */ - function get_styles() + protected function get_styles() { - global $db; - - $sql = 'SELECT * + $sql = 'SELECT * FROM ' . STYLES_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); return $rows; } @@ -1134,64 +1135,60 @@ class acp_styles /** * Count users for each style * - * @returns array of styles in following format: [style_id] = number of users + * @return array Styles in following format: [style_id] = number of users */ - function get_users() + protected function get_users() { - global $db; - $sql = 'SELECT user_style, COUNT(user_style) AS style_count FROM ' . USERS_TABLE . ' GROUP BY user_style'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - $style_count = array(); - while ($row = $db->sql_fetchrow($result)) + $style_count = array(); + while ($row = $this->db->sql_fetchrow($result)) { $style_count[$row['user_style']] = $row['style_count']; } - $db->sql_freeresult($result); - + $this->db->sql_freeresult($result); + return $style_count; } - + /** * Uninstall style * * @param array $style Style data - * @returns true on success, error message on error + * @return bool|string True on success, error message on error */ - function uninstall_style($style) + protected function uninstall_style($style) { - global $db, $user; - $id = $style['style_id']; $path = $style['style_path']; - + // Check if style has child styles - $sql = 'SELECT style_id + $sql = 'SELECT style_id FROM ' . STYLES_TABLE . ' - WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $db->sql_escape($path) . "'"; - $result = $db->sql_query($sql); - - $conflict = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + WHERE style_parent_id = ' . (int) $id . " OR style_parent_tree = '" . $this->db->sql_escape($path) . "'"; + $result = $this->db->sql_query($sql); + + $conflict = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if ($conflict !== false) { - return sprintf($user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); + return sprintf($this->user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); } - + // Change default style for users $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE user_style = ' . $id; - $db->sql_query($sql); - + $this->db->sql_query($sql); + // Uninstall style $sql = 'DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $id; - $db->sql_query($sql); + $this->db->sql_query($sql); return true; } @@ -1200,13 +1197,13 @@ class acp_styles * * @param string $path Style directory * @param string $dir Directory to remove inside style's directory - * @returns true on success, false on error + * @return bool True on success, false on error */ - function delete_style_files($path, $dir = '') + protected function delete_style_files($path, $dir = '') { $dirname = $this->styles_path . $path . $dir; $result = true; - + $dp = @opendir($dirname); if ($dp) @@ -1239,24 +1236,22 @@ class acp_styles { return false; } - + return $result; } - + /** * Get list of items from posted data * * @param string $name Variable name - * @param $default Default value for array: string or number + * @param string|int $default Default value for array * @param bool $error If true, error will be triggered if list is empty - * @returns array of items + * @return array Items */ - function request_vars($name, $default, $error = false) + protected function request_vars($name, $default, $error = false) { - global $request, $user; - - $item = $request->variable($name, $default); - $items = $request->variable($name . 's', array($default)); + $item = $this->request->variable($name, $default); + $items = $this->request->variable($name . 's', array($default)); if (count($items) == 1 && $items[0] == $default) { @@ -1267,28 +1262,30 @@ class acp_styles { $items[] = $item; } - + if ($error && !count($items)) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } return $items; } /** - * Generates hardcoded bitfield + * Generates default bitfield + * + * This bitfield decides which bbcodes are defined in a template. * - * @returns bitfield string + * @return string Bitfield */ - function default_bitfield() + protected function default_bitfield() { static $value; if (isset($value)) { return $value; } - + // Hardcoded template bitfield to add for new templates $bitfield = new bitfield(); $bitfield->set(0); diff --git a/phpBB/includes/captcha/captcha_factory.php b/phpBB/includes/captcha/captcha_factory.php index 62fb90d3c5..d57b333c69 100644 --- a/phpBB/includes/captcha/captcha_factory.php +++ b/phpBB/includes/captcha/captcha_factory.php @@ -25,7 +25,7 @@ class phpbb_captcha_factory /** * return an instance of class $name in file $name_plugin.php */ - function get_instance($name) + public static function get_instance($name) { global $phpbb_root_path, $phpEx; diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php index a63b0e448f..6c1f3bf00b 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php @@ -49,7 +49,7 @@ class phpbb_captcha_gd extends phpbb_default_captcha } } - function get_instance() + public static function get_instance() { $instance = new phpbb_captcha_gd(); return $instance; diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php index f523cae191..a5588178bb 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php @@ -39,7 +39,7 @@ class phpbb_captcha_gd_wave extends phpbb_default_captcha } } - function get_instance() + public static function get_instance() { return new phpbb_captcha_gd_wave(); } diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php index 4a0418146d..96f13fbe1b 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php @@ -39,7 +39,7 @@ class phpbb_captcha_nogd extends phpbb_default_captcha } } - function get_instance() + public static function get_instance() { $instance = new phpbb_captcha_nogd(); return $instance; diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index e12ad00d25..99813189d7 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -98,7 +98,7 @@ class phpbb_captcha_qa /** * API function */ - function get_instance() + public static function get_instance() { $instance = new phpbb_captcha_qa(); diff --git a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php index 0ea8b9c6e7..70c24a8c30 100644 --- a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php @@ -54,7 +54,7 @@ class phpbb_recaptcha extends phpbb_default_captcha $this->response = request_var('recaptcha_response_field', ''); } - function get_instance() + public static function get_instance() { $instance = new phpbb_recaptcha(); return $instance; diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 23b9f1c658..87ca40917d 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -270,11 +270,12 @@ class phpbb_extension_finder * Finds all directories matching the configured options * * @param bool $cache Whether the result should be cached + * @param bool $extension_keys Whether the result should have extension name as array key * @return array An array of paths to found directories */ - public function get_directories($cache = true) + public function get_directories($cache = true, $extension_keys = false) { - return $this->find_with_root_path($cache, true); + return $this->find_with_root_path($cache, true, $extension_keys); } /** @@ -294,16 +295,25 @@ class phpbb_extension_finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise + * @param bool $extension_keys If true, result will be associative array + * with extension name as key * @return array An array of paths to found items */ - protected function find_with_root_path($cache = true, $is_dir = false) + protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) { $items = $this->find($cache, $is_dir); $result = array(); foreach ($items as $item => $ext_name) { - $result[] = $this->phpbb_root_path . $item; + if ($extension_keys) + { + $result[$ext_name] = $this->phpbb_root_path . $item; + } + else + { + $result[] = $this->phpbb_root_path . $item; + } } return $result; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 74db8cb8fd..9a6af29d69 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4770,7 +4770,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'T_ASSETS_PATH' => "{$web_path}assets", 'T_THEME_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/theme', 'T_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', - 'T_SUPER_TEMPLATE_PATH' => ($user->theme['style_parent_id']) ? "{$web_path}styles/" . rawurlencode($user->theme['style_parent_tree']) . '/template' : "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', + 'T_SUPER_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', 'T_IMAGES_PATH' => "{$web_path}images/", 'T_SMILIES_PATH' => "{$web_path}{$config['smilies_path']}/", 'T_AVATAR_PATH' => "{$web_path}{$config['avatar_path']}/", @@ -4860,6 +4860,7 @@ function page_footer($run_cron = true) $template->assign_vars(array( 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '', 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '', + 'CREDIT_LINE' => $user->lang('POWERED_BY', '<a href="http://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Group'), 'U_ACP' => ($auth->acl_get('a_') && !empty($user->data['is_registered'])) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", false, true, $user->session_id) : '') ); diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 03dec1787a..dc61859363 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -131,6 +131,7 @@ function adm_page_footer($copyright_html = true) 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '', 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '', 'S_COPYRIGHT_HTML' => $copyright_html, + 'CREDIT_LINE' => $user->lang('POWERED_BY', '<a href="http://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Group'), 'T_JQUERY_LINK' => ($config['load_jquery_cdn'] && !empty($config['load_jquery_url'])) ? $config['load_jquery_url'] : "{$phpbb_root_path}assets/javascript/jquery.js", 'S_JQUERY_FALLBACK' => ($config['load_jquery_cdn']) ? true : false, 'VERSION' => $config['version']) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index f2faf20f43..6b2ee98d7a 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -739,7 +739,7 @@ function smiley_text($text, $force_option = false) else { $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; - return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $root_path . $config['smilies_path'] . '/\2 />', $text); + return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img class="smilies" src="' . $root_path . $config['smilies_path'] . '/\2 />', $text); } } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b3816baedd..f77f54679f 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -496,7 +496,14 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage { if ($free_space <= $file->get('filesize')) { - $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED']; + if ($auth->acl_get('a_')) + { + $filedata['error'][] = $user->lang['ATTACH_DISK_FULL']; + } + else + { + $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED']; + } $filedata['post_attach'] = false; $file->remove(); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 18452c27e9..5b05c3a78d 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1948,6 +1948,27 @@ function validate_jabber($jid) } /** +* Verifies whether a style ID corresponds to an active style. +* +* @param int $style_id The style_id of a style which should be checked if activated or not. +* @return boolean +*/ +function phpbb_style_is_active($style_id) +{ + global $db; + + $sql = 'SELECT style_active + FROM ' . STYLES_TABLE . ' + WHERE style_id = '. (int) $style_id; + $result = $db->sql_query($sql); + + $style_is_active = (bool) $db->sql_fetchfield('style_active'); + $db->sql_freeresult($result); + + return $style_is_active; +} + +/** * Remove avatar */ function avatar_delete($mode, $row, $clean_db = false) diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php index 1fb6580ce1..4eac300424 100644 --- a/phpBB/includes/style/extension_path_provider.php +++ b/phpBB/includes/style/extension_path_provider.php @@ -82,22 +82,26 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple $directories = array(); $finder = $this->extension_manager->get_finder(); - foreach ($this->base_path_provider as $path) + foreach ($this->base_path_provider as $key => $paths) { - if ($path && !phpbb_is_absolute($path)) + if ($key == 'style') { - $directories = array_merge($directories, $finder - ->directory('/' . $this->ext_dir_prefix . $path) - ->get_directories() - ); + foreach ($paths as $path) + { + $directories['style'][] = $path; + if ($path && !phpbb_is_absolute($path)) + { + $result = $finder->directory('/' . $this->ext_dir_prefix . $path) + ->get_directories(true, true); + foreach ($result as $ext => $ext_path) + { + $directories[$ext][] = $ext_path; + } + } + } } } - foreach ($this->base_path_provider as $path) - { - $directories[] = $path; - } - return $directories; } @@ -112,14 +116,4 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple $this->base_path_provider->set_styles($styles); $this->items = null; } - - /** - * Retrieves the path to the main style passed into set_styles() - * - * @return string Main style path - */ - public function get_main_style_path() - { - return $this->base_path_provider->get_main_style_path(); - } } diff --git a/phpBB/includes/style/path_provider.php b/phpBB/includes/style/path_provider.php index c229af92ba..731d682e88 100644 --- a/phpBB/includes/style/path_provider.php +++ b/phpBB/includes/style/path_provider.php @@ -24,7 +24,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_provider_interface { - protected $main_style_name = ''; protected $paths = array(); /** @@ -41,25 +40,14 @@ class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_p * Overwrites the current style paths * * The first element of the passed styles map, is considered the main - * style and can be retrieved through get_main_style_path(). + * style. * * @param array $styles An array of style paths. The first element is the main style. * @return null */ public function set_styles(array $styles) { - $this->paths = $styles; - $this->main_style_path = $this->paths[0]; - } - - /** - * Retrieves the path to the main style passed into set_styles() - * - * @return string Main style path - */ - public function get_main_style_path() - { - return $this->main_style_path; + $this->paths = array('style' => $styles); } /** diff --git a/phpBB/includes/style/path_provider_interface.php b/phpBB/includes/style/path_provider_interface.php index 7ae94e17f4..1a6153a4d3 100644 --- a/phpBB/includes/style/path_provider_interface.php +++ b/phpBB/includes/style/path_provider_interface.php @@ -39,11 +39,4 @@ interface phpbb_style_path_provider_interface extends Traversable * @return null */ public function set_styles(array $styles); - - /** - * Retrieves the path to the main style passed into set_styles() - * - * @return string Main style path - */ - public function get_main_style_path(); } diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index af261534c3..3e6dd5d6aa 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -39,12 +39,6 @@ class phpbb_style_resource_locator private $roots = array(); /** - * Index of the main style in the roots array. - * @var int - */ - private $main_root_id = 0; - - /** * Location of templates directory within style directories. * Must have trailing slash. Empty if templates are stored in root * style directory, such as admin control panel templates. @@ -70,17 +64,6 @@ class phpbb_style_resource_locator private $filenames = array(); /** - * Set main style location (must have been added through set_paths first). - * - * @param string $style_path Path to style directory - * @return null - */ - public function set_main_style($style_path) - { - $this->main_root_id = array_search($style_path, $this->roots, true); - } - - /** * Sets the list of style paths * * These paths will be searched for style files in the provided order. @@ -95,16 +78,18 @@ class phpbb_style_resource_locator $this->roots = array(); $this->files = array(); $this->filenames = array(); - $this->main_root_id = 0; - foreach ($style_paths as $path) + foreach ($style_paths as $key => $paths) { - // Make sure $path has no ending slash - if (substr($path, -1) === '/') + foreach ($paths as $path) { - $path = substr($path, 0, -1); + // Make sure $path has no ending slash + if (substr($path, -1) === '/') + { + $path = substr($path, 0, -1); + } + $this->roots[$key][] = $path; } - $this->roots[] = $path; } } @@ -125,9 +110,12 @@ class phpbb_style_resource_locator $this->filename[$handle] = $filename; - foreach ($this->roots as $root_index => $root) + foreach ($this->roots as $root_key => $root_paths) { - $this->files[$root_index][$handle] = $root . '/' . $this->template_path . $filename; + foreach ($root_paths as $root_index => $root) + { + $this->files[$root_key][$root_index][$handle] = $root . '/' . $this->template_path . $filename; + } } } } @@ -174,12 +162,12 @@ class phpbb_style_resource_locator public function get_virtual_source_file_for_handle($handle) { // If we don't have a file assigned to this handle, die. - if (!isset($this->files[$this->main_root_id][$handle])) + if (!isset($this->files['style'][0][$handle])) { trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); } - $source_file = $this->files[$this->main_root_id][$handle]; + $source_file = $this->files['style'][0][$handle]; return $source_file; } @@ -197,31 +185,107 @@ class phpbb_style_resource_locator * handle to a path without any filesystem or styles tree checks. * * @param string $handle Template handle (i.e. "friendly" template name) + * @param bool $find_all If true, each root path will be checked and function + * will return array of files instead of string and will not + * trigger a error if template does not exist * @return string Source file path */ - public function get_source_file_for_handle($handle) + public function get_source_file_for_handle($handle, $find_all = false) { // If we don't have a file assigned to this handle, die. - if (!isset($this->files[$this->main_root_id][$handle])) + if (!isset($this->files['style'][0][$handle])) { trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); } // locate a source file that exists - $source_file = $this->files[0][$handle]; + $source_file = $this->files['style'][0][$handle]; $tried = $source_file; - for ($i = 1, $n = count($this->roots); $i < $n && !file_exists($source_file); $i++) + $found = false; + $found_all = array(); + foreach ($this->roots as $root_key => $root_paths) { - $source_file = $this->files[$i][$handle]; - $tried .= ', ' . $source_file; + foreach ($root_paths as $root_index => $root) + { + $source_file = $this->files[$root_key][$root_index][$handle]; + $tried .= ', ' . $source_file; + if (file_exists($source_file)) + { + $found = true; + break; + } + } + if ($found) + { + if ($find_all) + { + $found_all[] = $source_file; + $found = false; + } + else + { + break; + } + } } // search failed - if (!file_exists($source_file)) + if (!$found && !$find_all) { trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); } - return $source_file; + return ($find_all) ? $found_all : $source_file; + } + + /** + * Locates source file path, accounting for styles tree and verifying that + * the path exists. + * + * Unlike previous functions, this function works without template handle + * and it can search for more than one file. If more than one file name is + * specified, it will return location of file that it finds first. + * + * @param array $files List of files to locate. + * @param bool $return_default Determines what to return if file does not + * exist. If true, function will return location where file is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to file. If false, function will return file name. This + * parameter can be used to check which one of set of files + * is available. + * @return string or boolean Source file path if file exists or $return_default is + * true. False if file does not exist and $return_default is false + */ + public function get_first_file_location($files, $return_default = false, $return_full_path = true) + { + // set default value + $default_result = false; + + // check all available paths + foreach ($this->roots as $root_paths) + { + foreach ($root_paths as $path) + { + // check all files + foreach ($files as $filename) + { + $source_file = $path . '/' . $filename; + if (file_exists($source_file)) + { + return ($return_full_path) ? $source_file : $filename; + } + + // assign first file as result if $return_default is true + if ($return_default && $default_result === false) + { + $default_result = $source_file; + } + } + } + } + + // search failed + return $default_result; } } diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 539a2642ee..5ac61c9f10 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -92,6 +92,9 @@ class phpbb_style $paths[] = $this->get_style_path($dir); } + // Add 'all' path, used as last fallback path by hooks and extensions + $paths[] = $this->get_style_path('all'); + return $this->set_custom_style($style_name, $paths); } @@ -113,7 +116,6 @@ class phpbb_style $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) . '_'; @@ -148,4 +150,32 @@ class phpbb_style { $this->provider->set_ext_dir_prefix($ext_dir_prefix); } + + /** + * Locates source file path, accounting for styles tree and verifying that + * the path exists. + * + * @param string or array $files List of files to locate. If there is only + * one file, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if file does not + * exist. If true, function will return location where file is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to file. If false, function will return file name. This + * parameter can be used to check which one of set of files + * is available. + * @return string or boolean Source file path if file exists or $return_default is + * true. False if file does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // convert string to array + if (is_string($files)) + { + $files = array($files); + } + + // use resource locator to find files + return $this->locator->get_first_file_location($files, $return_default, $return_full_path); + } } diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index 21a2e821dd..3f15355f7a 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -288,7 +288,7 @@ class phpbb_style_template return new phpbb_style_template_renderer_include($output_file, $this); } - $compile = new phpbb_style_template_compile($this->config['tpl_allow_php']); + $compile = new phpbb_style_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { @@ -456,4 +456,59 @@ class phpbb_style_template } include($file); } + + /** + * Locates source template path, accounting for styles tree and verifying that + * the path exists. + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // add tempalte path prefix + $templates = array(); + if (is_string($files)) + { + $templates[] = $this->template_path . $files; + } + else + { + foreach ($files as $file) + { + $templates[] = $this->template_path . $file; + } + } + + // use resource locator to find files + return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); + } + + /** + * Include JS file + * + * @param string $file file name + * @param bool $locate True if file needs to be located + */ + public function _js_include($file, $locate = false) + { + // Locate file + if ($locate) + { + $file = $this->locator->get_first_file_location(array($file), true, true); + } + + // Add HTML code + $code = '<script src="' . htmlspecialchars($file) . '"></script>'; + $this->context->append_var('SCRIPTS', $code); + } } diff --git a/phpBB/includes/style/template_compile.php b/phpBB/includes/style/template_compile.php index 3ef3fffc00..fa0928f424 100644 --- a/phpBB/includes/style/template_compile.php +++ b/phpBB/includes/style/template_compile.php @@ -26,20 +26,26 @@ stream_filter_register('phpbb_template', 'phpbb_style_template_filter'); class phpbb_style_template_compile { /** - * Whether <!-- PHP --> tags are allowed + * Array of parameters to forward to template filter * - * @var bool + * @var array */ - private $allow_php; + private $filter_params; /** * Constructor. * * @param bool @allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) + * @param phpbb_style_resource_locator $locator Resource locator + * @param string $phpbb_root_path Path to phpBB root directory */ - public function __construct($allow_php) + public function __construct($allow_php, $locator, $phpbb_root_path) { - $this->allow_php = $allow_php; + $this->filter_params = array( + 'allow_php' => $allow_php, + 'locator' => $locator, + 'phpbb_root_path' => $phpbb_root_path + ); } /** @@ -116,7 +122,7 @@ class phpbb_style_template_compile */ private function compile_stream_to_stream($source_stream, $dest_stream) { - stream_filter_append($source_stream, 'phpbb_template', null, array('allow_php' => $this->allow_php)); + stream_filter_append($source_stream, 'phpbb_template', null, $this->filter_params); stream_copy_to_stream($source_stream, $dest_stream); } } diff --git a/phpBB/includes/style/template_filter.php b/phpBB/includes/style/template_filter.php index 04fe85e07f..d62ad0ba1e 100644 --- a/phpBB/includes/style/template_filter.php +++ b/phpBB/includes/style/template_filter.php @@ -76,6 +76,18 @@ class phpbb_style_template_filter extends php_user_filter private $allow_php; /** + * Resource locator. + * + * @var phpbb_template_locator + */ + private $locator; + + /** + * @var string phpBB root path + */ + private $phpbb_root_path; + + /** * Stream filter * * Is invoked for evey chunk of the stream, allowing us @@ -126,14 +138,16 @@ class phpbb_style_template_filter extends php_user_filter /** * Initializer, called on creation. * - * Get the allow_php option from params, which is passed - * to stream_filter_append. + * Get the allow_php option, root directory and locator from params, + * which are passed to stream_filter_append. */ public function onCreate() { $this->chunk = ''; $this->in_php = false; $this->allow_php = $this->params['allow_php']; + $this->locator = $this->params['locator']; + $this->phpbb_root_path = $this->params['phpbb_root_path']; return true; } @@ -281,6 +295,10 @@ class phpbb_style_template_filter extends php_user_filter return ($this->allow_php) ? '<?php ' . $this->compile_tag_include_php($matches[2]) . ' ?>' : ''; break; + case 'INCLUDEJS': + return '<?php ' . $this->compile_tag_include_js($matches[2]) . ' ?>'; + break; + case 'PHP': if ($this->allow_php) { @@ -857,6 +875,45 @@ class phpbb_style_template_filter extends php_user_filter } /** + * Compile INCLUDEJS tag + * + * @param string $tag_args Expression given with INCLUDEJS in source template + * @return string compiled template code + */ + private function compile_tag_include_js($tag_args) + { + // Process dynamic includes + if ($tag_args[0] == '{') + { + $var = $this->get_varref($tag_args, $is_expr); + if (!$is_expr) + { + return " \$_template->_js_include($var, true);"; + } + return ''; + } + + // Locate file + $filename = $this->locator->get_first_file_location(array($tag_args), false, true); + + if ($filename === false) + { + // File does not exist, find it during run time + return ' $_template->_js_include(\'' . addslashes($tag_args) . '\', true); '; + } + + if (substr($filename, 0, strlen($this->phpbb_root_path)) != $this->phpbb_root_path) + { + // Absolute path, include as is + return ' $_template->_js_include(\'' . addslashes($filename) . '\', false); '; + } + + // Relative path, remove root path from it + $filename = substr($filename, strlen($this->phpbb_root_path)); + return ' global $phpbb_root_path; $_template->_js_include($phpbb_root_path . \'' . addslashes($filename) . '\', false); '; + } + + /** * Generates a reference to the given variable inside the given (possibly nested) * block namespace. This is a string of the form: * ' . $_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 11f2d231fe..0c9f20f266 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -60,7 +60,14 @@ class ucp_prefs if ($submit) { - $data['style'] = ($config['override_user_style']) ? $config['default_style'] : $data['style']; + if ($config['override_user_style']) + { + $data['style'] = (int) $config['default_style']; + } + else if (!phpbb_style_is_active($data['style'])) + { + $data['style'] = (int) $user->data['user_style']; + } $error = validate_data($data, array( 'dateformat' => array('string', false, 1, 30), |
