diff options
-rw-r--r-- | phpBB/adm/style/acp_styles.html | 55 | ||||
-rw-r--r-- | phpBB/adm/style/admin.css | 36 | ||||
-rw-r--r-- | phpBB/adm/style/viewsource.html | 19 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_styles.php | 455 | ||||
-rw-r--r-- | phpBB/includes/db/dbal.php | 2 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_queue.php | 5 | ||||
-rw-r--r-- | phpBB/includes/message_parser.php | 5 | ||||
-rwxr-xr-x | phpBB/includes/search/search.php | 4 | ||||
-rw-r--r-- | phpBB/language/en/acp/common.php | 16 | ||||
-rw-r--r-- | phpBB/language/en/acp/styles.php | 47 | ||||
-rw-r--r-- | phpBB/language/en/common.php | 1 | ||||
-rw-r--r-- | phpBB/style.php | 32 |
12 files changed, 510 insertions, 167 deletions
diff --git a/phpBB/adm/style/acp_styles.html b/phpBB/adm/style/acp_styles.html index b38a35702d..3a5b6330db 100644 --- a/phpBB/adm/style/acp_styles.html +++ b/phpBB/adm/style/acp_styles.html @@ -244,6 +244,8 @@ //--> </script> + <a href="{U_BACK}" style="float: right">« {L_BACK}</a> + <h1>{L_EDIT_THEME}</h1> <p>{L_EDIT_THEME_EXPLAIN}</p> @@ -374,6 +376,59 @@ </form> <!-- ENDIF --> +<!-- ELSEIF S_CACHE --> + <script language="Javascript" type="text/javascript"> + <!-- + + function viewsource(url) + { + window.open(url, '_source', 'HEIGHT=550,resizable=yes,scrollbars=yes,WIDTH=750'); + return false; + } + + //--> + </script> + + <a href="{U_BACK}" style="float: right">« {L_BACK}</a> + + <h1>{L_TEMPLATE_CACHE}</h1> + + <p>{L_TEMPLATE_CACHE_EXPLAIN}</p> + + <form name="acp_styles" method="post" action="{U_ACTION}"> + + <table cellspacing="1"> + <thead> + <tr> + <th>{L_CACHE_FILENAME}</th> + <th>{L_CACHE_FILESIZE}</th> + <th>{L_CACHE_CACHED}</th> + <th>{L_CACHE_MODIFIED}</th> + <th>{L_MARK}</th> + </tr> + </thead> + <tbody> + <!-- BEGIN file --> + <!-- IF file.S_ROW_COUNT is even --><tr class="row1"><!-- ELSE --><tr class="row2"><!-- ENDIF --> + <td><a href="{file.U_VIEWSOURCE}" onclick="viewsource('{file.UA_VIEWSOURCE}');return false">{file.FILENAME}</a></td> + <td>{file.FILESIZE}</td> + <td>{file.CACHED}</td> + <td>{file.MODIFIED}</td> + <td><input type="checkbox" name="delete[]" value="{file.FILENAME}" /></td> + </tr> + <!-- BEGINELSE --> + <tr class="row1"> + <td colspan="5">{L_TEMPLATE_CACHE_EMPTY}</td> + </tr> + <!-- END file --> + </table> + + <fieldset class="quick"> + <span class="small"><a href="javascript:marklist('acp_styles', 'delete', true);">Mark all</a> :: <a href="javascript:marklist('acp_styles', 'delete', false);">Unmark all</a></span><br /> + + <input class="button1" type="submit" id="submit" name="submit" value="{L_DELETE_MARKED}" /> + </fieldset> + </form> <!-- ELSEIF S_EXPORT --> <a href="{U_BACK}" style="float: right">« {L_BACK}</a> diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index dc57c98962..67cd36ae16 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -915,3 +915,39 @@ table.pmask td.name { height: 1%; } /* End hide */ + +/* Syntax Highlighting +---------------------------------------- */ +.sourcenum { + color: gray; + font-family: 'Courier New', monospace; + font-size: 125%; + font-weight: bold; + line-height: 120%; + text-align: right; + padding: 0px; +} +.source { + font-family: 'Courier New', monospace; + font-size: 125%; + line-height: 120%; + padding: 0px; +} +.syntaxbg { + color: #FFFFFF; + } +.syntaxcomment { + color: #FF8000; + } +.syntaxdefault { + color: #0000BB; + } +.syntaxhtml { + color: #000000; + } +.syntaxkeyword { + color: #007700; + } +.syntaxstring { + color: #DD0000; + }
\ No newline at end of file diff --git a/phpBB/adm/style/viewsource.html b/phpBB/adm/style/viewsource.html new file mode 100644 index 0000000000..44b1ad6be4 --- /dev/null +++ b/phpBB/adm/style/viewsource.html @@ -0,0 +1,19 @@ +<!-- INCLUDE simple_header.html --> + +<div class="panel" style="padding:10px"> + + <h1>{FILENAME}</h1> + + <table> + <tbody> + <!-- BEGIN source --> + <tr valign="top"> + <td class="sourcenum">{source.LINENUM} </td> + <td class="source">{source.LINE}</td> + </tr> + <!-- END source --> + </tbody> + </table> +</div> + +<!-- INCLUDE simple_footer.html -->
\ No newline at end of file diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 4145b1f479..d0257dfed7 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -9,12 +9,6 @@ */ /** -* @todo see /includes/acp/acp_styles.php -* templates/themes->cache (show template files in cache, ability to remove all) -* templates/themes->refresh (give explanation of what this is doing [confirm_box?] and printing out success message -*/ - -/** * @package acp */ class acp_styles @@ -29,7 +23,7 @@ class acp_styles function main($id, $mode) { - global $db, $user, $auth, $template; + global $db, $user, $auth, $template, $cache; global $config, $SID, $phpbb_root_path, $phpbb_admin_path, $phpEx; // Hardcoded template bitfield to add for new templates @@ -141,6 +135,17 @@ pagination_sep = \'{PAGINATION_SEP}\' } } break; + + case 'cache': + if ($style_id) + { + switch ($mode) + { + case 'template': + return $this->template_cache($style_id); + } + } + break; } switch ($mode) @@ -185,7 +190,7 @@ pagination_sep = \'{PAGINATION_SEP}\' switch ($action) { - // Refresh/Renew template cache + // Refresh template data stored in db and clear cache case 'refresh': $sql = 'SELECT * @@ -200,34 +205,56 @@ pagination_sep = \'{PAGINATION_SEP}\' trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action)); } - if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) + if (confirm_box(true)) { - $filelist = array('' => array()); + $template_refreshed = ''; - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TPLDATA_TABLE . " - WHERE template_id = $style_id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) + // Only refresh database if the template is stored in the database + if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) { - if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) + $filelist = array('' => array()); + + $sql = 'SELECT template_filename, template_mtime + FROM ' . STYLES_TPLDATA_TABLE . " + WHERE template_id = $style_id"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) { - // get folder info from the filename - if (($slash_pos = strrpos($row['template_filename'], '/')) === false) - { - $filelist[''][] = $row['template_filename']; - } - else + if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) { - $filelist[substr($row['template_filename'], 0, $slash_pos + 1)] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slashpos - 1); + // get folder info from the filename + if (($slash_pos = strrpos($row['template_filename'], '/')) === false) + { + $filelist[''][] = $row['template_filename']; + } + else + { + $filelist[substr($row['template_filename'], 0, $slash_pos + 1)] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slashpos - 1); + } } } + $db->sql_freeresult($result); + + $this->store_templates('update', $style_id, $template_row['template_path'], $filelist); + unset($filelist); + + $template_refreshed = $user->lang['TEMPLATE_REFRESHED'] . '<br />'; + add_log('admin', 'LOG_TEMPLATE_REFRESHED', $template_row['template_name']); } - $db->sql_freeresult($result); - $this->store_templates('update', $style_id, $template_row['template_path'], $filelist); - unset($filelist); + $this->clear_template_cache($template_row); + + trigger_error($template_refreshed . $user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action)); + } + else + { + confirm_box(false, ($template_row['template_storedb']) ? $user->lang['CONFIRM_TEMPLATE_REFRESH'] : $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'action' => $action, + 'id' => $style_id + ))); } break; @@ -240,7 +267,7 @@ pagination_sep = \'{PAGINATION_SEP}\' switch ($action) { - // Refresh/Renew theme cache + // Refresh theme data stored in the database case 'refresh': $sql = 'SELECT * @@ -255,31 +282,38 @@ pagination_sep = \'{PAGINATION_SEP}\' trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action)); } - if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) + if (!$theme_row['theme_storedb']) { - $theme_data = file_get_contents("{$phpbb_root_path}styles/" . $theme_row['theme_path'] . '/theme/stylesheet.css'); - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(\"(.*)\"\);/i', $theme_data, $matches); + trigger_error($user->lang['THEME_ERR_REFRESH_FS'] . adm_back_link($this->u_action)); + } - if (sizeof($matches)) + if (confirm_box(true)) + { + if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) { - foreach ($matches[0] as $idx => $match) - { - $theme_data = str_replace($match, $this->load_css_file($theme_row['theme_path'], $matches[1][$idx]), $theme_data); - } - } + // Save CSS contents + $sql_ary = array( + 'theme_mtime' => @filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), + 'theme_data' => $this->db_theme_data($theme_row) + ); + + $sql = 'UPDATE ' . STYLES_CSS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE theme_id = $style_id"; + $db->sql_query($sql); - // Save CSS contents - $sql_ary = array( - 'theme_mtime' => @filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), - 'theme_data' => str_replace('./', 'styles/' . $theme_info['theme_path'] . '/theme/', $theme_data) - ); + $cache->destroy('sql', STYLES_CSS_TABLE); - $sql = 'UPDATE ' . STYLES_CSS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = $style_id"; - $db->sql_query($sql); + trigger_error($user->lang['THEME_REFRESHED'] . adm_back_link($this->u_action)); + } + } + else + { + confirm_box(false, $user->lang['CONFIRM_THEME_REFRESH'], build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'action' => $action, + 'id' => $style_id + ))); } break; } @@ -392,9 +426,6 @@ pagination_sep = \'{PAGINATION_SEP}\' // Grab uninstalled items $new_ary = $cfg = array(); - /** - * @todo grab templates/themes/imagesets from style directories - */ $dp = opendir("{$phpbb_root_path}styles"); while (($file = readdir($dp)) !== false) { @@ -446,7 +477,7 @@ pagination_sep = \'{PAGINATION_SEP}\' */ function edit_template($template_id) { - global $phpbb_root_path, $phpEx, $SID, $config, $db, $cache, $user, $template; + global $phpbb_root_path, $phpEx, $SID, $config, $db, $cache, $user, $template, $safe_mode; $this->page_title = 'EDIT_TEMPLATE'; @@ -482,7 +513,7 @@ pagination_sep = \'{PAGINATION_SEP}\' $additional = ''; // If the template is stored on the filesystem try to write the file else store it in the database - if (!$template_info['template_storedb'] && file_exists($file) && is_writeable($file)) + if (!$safe_mode && !$template_info['template_storedb'] && file_exists($file) && is_writeable($file)) { if (!($fp = fopen($file, 'wb'))) { @@ -520,8 +551,8 @@ pagination_sep = \'{PAGINATION_SEP}\' $db->sql_transaction('commit'); } - // destroy the cached version of the template - @unlink("{$phpbb_root_path}cache/tpl_{$template_info['template_name']}_" . str_replace('/', '.', $template_file) . ".$phpEx"); + // destroy the cached version of the template (filename without extension) + $this->clear_template_cache($template_info, array(substr($template_file, 0, -5))); add_log('admin', 'LOG_TEMPLATE_EDIT', $template_info['template_name'], $template_file); trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . $additional . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file")); @@ -650,13 +681,137 @@ pagination_sep = \'{PAGINATION_SEP}\' } /** + * Allows the admin to view cached versions of template files and clear single template cache files + * + * @param int $template_id specifies which template's cache is shown + */ + function template_cache($template_id) + { + global $phpbb_root_path, $phpEx, $SID, $config, $db, $cache, $user, $template; + + $source = str_replace('/', '.', request_var('source', '')); + $file_ary = array_diff(request_var('delete', array('')), array('')); + $submit = isset($_POST['submit']) ? true : false; + + $sql = 'SELECT * + FROM ' . STYLES_TPL_TABLE . " + WHERE template_id = $template_id"; + $result = $db->sql_query($sql); + + if (!($template_row = $db->sql_fetchrow($result))) + { + trigger_error($user->lang['NO_TEMPLATE']); + } + $db->sql_freeresult($result); + + // User wants to delete one or more files ... + if ($submit && $file_ary) + { + $this->clear_template_cache($template_row, $file_ary); + trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action . "&action=cache&id=$template_id")); + } + + $cache_prefix = 'tpl_' . $template_row['template_path']; + + // Someone wants to see the cached source ... so we'll highlight it, + // add line numbers and indent it appropriately. This could be nasty + // on larger source files ... + if ($source && file_exists("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx")) + { + adm_page_header($user->lang['TEMPLATE_CACHE']); + + $template->set_filenames(array( + 'body' => 'viewsource.html') + ); + + $template->assign_vars(array( + 'FILENAME' => str_replace('.', '/', $source) . '.html') + ); + + $code = str_replace(array("\n\r", "\r"), array("\n", "\n"), file_get_contents("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx")); + + $conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string'); + foreach ($conf as $ini_var) + { + @ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var)); + } + + $marker = 'MARKER' . time(); + $code = highlight_string(str_replace("\n", $marker, $code), true); + $code = str_replace($marker, "\n", $code); + + $str_from = array('<font color="syntax', '</font>', '<code>', '</code>','[', ']', '.', ':'); + $str_to = array('<span class="syntax', '</span>', '', '', '[', ']', '.', ':'); + + $code = str_replace($str_from, $str_to, $code); + $code = preg_replace('#^(<span class="[a-z_]+">)\n?(.*?)\n?(</span>)$#is', '$1$2$3', $code); + + $code = explode("\n", $code); + + foreach ($code as $key => $line) + { + $template->assign_block_vars('source', array( + 'LINENUM' => $key + 1, + 'LINE' => preg_replace('#([^ ;]) ([^ &])#', '$1 $2', $line)) + ); + unset($code[$key]); + } + + adm_page_footer(); + } + + $filemtime = array(); + if ($template_row['template_storedb']) + { + $sql = 'SELECT template_filename, template_mtime + FROM ' . STYLES_TPLDATA_TABLE . " + WHERE template_id = $template_id"; + $result = $db->sql_query($sql); + + $filemtime = array(); + while ($row = $db->sql_fetchrow($result)) + { + $filemtime[$row['template_filename']] = $row['template_mtime']; + } + $db->sql_freeresult($result); + } + + // Get a list of cached template files and then retrieve additional information about them + $file_ary = $this->template_cache_filelist($template_row['template_path']); + + foreach ($file_ary as $file) + { + $filename = "{$cache_prefix}_$file.html.$phpEx"; + + $template->assign_block_vars('file', array( + 'U_VIEWSOURCE' => $this->u_action . "&action=cache&id=$template_id&source=$file", + 'UA_VIEWSOURCE' => str_replace('&', '&', $this->u_action) . "&action=cache&id=$template_id&source=$file", + + 'CACHED' => $user->format_date(filemtime("{$phpbb_root_path}cache/$filename")), + 'FILENAME' => $file, + 'FILESIZE' => sprintf('%.1f KB', filesize("{$phpbb_root_path}cache/$filename") / 1024), + 'MODIFIED' => $user->format_date((!$template_row['template_storedb']) ? filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/$file.html") : $filemtime[$file . '.html'])) + ); + } + unset($filemtime); + + $template->assign_vars(array( + 'S_CACHE' => true, + 'S_TEMPLATE' => true, + + 'U_ACTION' => $this->u_action . "&action=cache&id=$template_id", + 'U_BACK' => $this->u_action) + ); + } + + /** * Provides a css editor and a basic easier to use stylesheet editing tool for less experienced (or lazy) users * * @param int $theme_id specifies which theme is being edited */ function edit_theme($theme_id) { - global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $config, $db, $cache, $user, $template; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $config, $db, $cache, $user, $template, $safe_mode; $this->page_title = 'EDIT_THEME'; @@ -947,7 +1102,7 @@ pagination_sep = \'{PAGINATION_SEP}\' case 'colors': $value = request_var($var, ''); - if (preg_match('#^(?:[A-Z0-9]{6}|[A-Z]{3})$#', $value)) + if (preg_match('#^(?:[A-F0-9]{6}|[A-F0-9]{3})$#', $value)) { $value = '#' . $value; } @@ -1014,7 +1169,7 @@ pagination_sep = \'{PAGINATION_SEP}\' } // where should we store the CSS? - if (!$theme_info['theme_storedb'] && file_exists($stylesheet_path) && is_writeable($stylesheet_path)) + if (!$safe_mode && !$theme_info['theme_storedb'] && file_exists($stylesheet_path) && is_writeable($stylesheet_path)) { // write stylesheet to file if (!($fp = fopen($stylesheet_path, 'wb'))) @@ -1026,29 +1181,20 @@ pagination_sep = \'{PAGINATION_SEP}\' } else { - // match CSS imports - preg_match_all('/@import url\(\"(.*)\"\);/i', $stylesheet, $matches); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - $stylesheet = str_replace($match, $this->load_css_file($style_row['theme_path'], $matches[1][$idx]), $stylesheet); - } - } - // Write stylesheet to db $sql_ary = array( 'theme_mtime' => time(), 'theme_storedb' => 1, - 'theme_data' => str_replace('./', 'styles/' . $theme_info['theme_path'] . '/theme/', $stylesheet), + 'theme_data' => $this->db_theme_data($theme_info, $stylesheet), ); $sql = 'UPDATE ' . STYLES_CSS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE theme_id = ' . $theme_id; $db->sql_query($sql); - // notify the user if the template was not stored in the db before the mofication + $cache->destroy('sql', STYLES_CSS_TABLE); + + // notify the user if the template was not stored in the db before his modification if (!$theme_info['theme_storedb']) { add_log('admin', 'LOG_THEME_EDIT_DETAILS', $theme_info['theme_name']); @@ -1862,24 +2008,12 @@ pagination_sep = \'{PAGINATION_SEP}\' if (!$style_row['theme_storedb']) { - $theme_data = file_get_contents("{$phpbb_root_path}styles/" . $style_row['theme_path'] . '/theme/stylesheet.css'); - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(\"(.*)\"\);/i', $theme_data, $matches); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - $theme_data = str_replace($match, $this->load_css_file($style_row['theme_path'], $matches[1][$idx]), $theme_data); - } - } + $theme_data = $this->db_theme_data($style_row); } - - if (!$store_db && !$safe_mode && is_writeable("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css")) + else if (!$store_db && !$safe_mode && is_writeable("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css")) { $store_db = 1; + $theme_data = $style_row['theme_data']; if ($fp = @fopen("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css", 'wb')) { @@ -1887,7 +2021,6 @@ pagination_sep = \'{PAGINATION_SEP}\' } fclose($fp); } - $theme_data = str_replace('./', "styles/{$style_row['theme_path']}/theme/", $theme_data); $sql_ary += array( 'theme_mtime' => ($store_db) ? filemtime("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css") : 0, @@ -1901,8 +2034,6 @@ pagination_sep = \'{PAGINATION_SEP}\' if ($style_row['template_storedb'] != $store_db) { - $filelist = filelist("{$phpbb_root_path}styles/{$style_row['template_path']}/template", '', 'html'); - if (!$store_db && !$safe_mode && is_writeable("{$phpbb_root_path}styles/{$style_row['template_path']}/template")) { $sql = 'SELECT * @@ -1930,6 +2061,11 @@ pagination_sep = \'{PAGINATION_SEP}\' $db->sql_query($sql); } } + else if ($store_db) + { + $filelist = filelist("{$phpbb_root_path}styles/{$style_row['template_path']}/template", '', 'html'); + $this->store_templates('insert', $style_id, $style_row['template_path'], $filelist); + } $sql_ary += array( 'template_storedb' => $store_db, @@ -2032,6 +2168,50 @@ pagination_sep = \'{PAGINATION_SEP}\' } /** + * Returns a string containing the value that should be used for the theme_data column in the theme database table. + * Includes contents of files loaded via @import + * + * @param array $theme_row is an associative array containing the theme's current database entry + * @param mixed $stylesheet can either be the new content for the stylesheet or false to load from the standard file + * @param string $root_path should only be used in case you want to use a different root path than "{$phpbb_root_path}styles/{$theme_row['theme_path']}" + * + * @return string Stylesheet data for theme_data column in the theme table + */ + function db_theme_data($theme_row, $stylesheet = false, $root_path = '') + { + global $phpbb_root_path; + + if (!$root_path) + { + $root_path = $phpbb_root_path . 'styles/' . $theme_row['theme_path']; + } + + if (!$stylesheet) + { + $stylesheet = ''; + if (file_exists($root_path . '/theme/stylesheet.css')) + { + $stylesheet = file_get_contents($root_path . '/theme/stylesheet.css'); + } + } + + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + + if (sizeof($matches)) + { + foreach ($matches[0] as $idx => $match) + { + $stylesheet = str_replace($match, $this->load_css_file($theme_row['theme_path'], $matches[1][$idx]), $stylesheet); + } + } + + // adjust paths + return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); + } + + /** * Store template files into db */ function store_templates($mode, $style_id, $name, $filelist) @@ -2097,6 +2277,75 @@ pagination_sep = \'{PAGINATION_SEP}\' } /** + * Returns an array containing all template filenames for one template that are currently cached. + * + * @param string $template_path contains the name of the template's folder in /styles/ + * + * @return array of filenames that exist in /styles/$template_path/template/ (without extension!) + */ + function template_cache_filelist($template_path) + { + global $phpbb_root_path, $phpEx, $user; + + $cache_prefix = 'tpl_' . $template_path; + + if (!($dp = @opendir("{$phpbb_root_path}cache"))) + { + trigger_error($user->lang['TEMPLATE_ERR_CACHE_READ']); + } + + $file_ary = array(); + while ($file = readdir($dp)) + { + if (is_file($phpbb_root_path . 'cache/' . $file) && (strpos($file, $cache_prefix) === 0)) + { + $file_ary[] = str_replace('.', '/', preg_replace('#^' . preg_quote($cache_prefix, '#') . '_(.*?)\.html\.' . $phpEx . '$#i', '\1', $file)); + } + } + closedir($dp); + + return $file_ary; + } + + /** + * Destroys cached versions of template files + * + * @param array $template_row contains the template's row in the STYLES_TPL_TABLE database table + * @param mixed $file_ary is optional and may contain an array of template file names which should be refreshed in the cache. + * The file names should be the original template file names and not the cache file names. + */ + function clear_template_cache($template_row, $file_ary = false) + { + global $phpbb_root_path, $phpEx, $user; + + $cache_prefix = 'tpl_' . $template_row['template_path']; + + if (!$file_ary || !is_array($file_ary)) + { + $file_ary = $this->template_cache_filelist($template_row['template_path']); + $log_file_list = $user->lang['ALL_FILES']; + } + else + { + $log_file_list = implode(', ', $file_ary); + } + + foreach ($file_ary as $file) + { + $file = str_replace('/', '.', $file); + + $file = "{$phpbb_root_path}cache/{$cache_prefix}_$file.html.$phpEx"; + if (file_exists($file) && is_file($file)) + { + @unlink($file); + } + } + unset($file_ary); + + add_log('admin', 'LOG_TEMPLATE_CACHE_CLEARED', $template_row['template_name'], $log_file_list); + } + + /** * Install Style/Template/Theme/Imageset */ function install($mode) @@ -2200,7 +2449,7 @@ pagination_sep = \'{PAGINATION_SEP}\' } else { - $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $style_row[$mode . '_copyright'], $style_row['store_db']); + $style_row['store_db'] = $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $style_row[$mode . '_copyright'], $style_row['store_db']); } if (!sizeof($error)) @@ -2625,18 +2874,7 @@ pagination_sep = \'{PAGINATION_SEP}\' { return false; } -/* - if ($action != 'install') - { - @mkdir("{$phpbb_root_path}styles/$path", 0777); - @chmod("{$phpbb_root_path}styles/$path", 0777); - if ($root_path) - { - $this->copy_files("$root_path$type", filelist("$root_path$type", '', '*'), "$path/$type"); - } - } -*/ $sql_ary = array( $mode . '_name' => $name, $mode . '_copyright' => $copyright, @@ -2648,18 +2886,22 @@ pagination_sep = \'{PAGINATION_SEP}\' switch ($mode) { case 'template': + $store_db = (!is_writeable("{$phpbb_root_path}styles/$path/template")) ? 1 : $store_db; + // We set a pre-defined bitfield here which we may use further in 3.2 $sql_ary += array( 'bbcode_bitfield' => TEMPLATE_BITFIELD, - $mode . '_storedb' => (!is_writeable("{$phpbb_root_path}styles/$path/$mode")) ? 1 : 0 + 'template_storedb' => $store_db ); break; case 'theme': + $store_db = (!is_writeable("{$phpbb_root_path}styles/$path/theme/stylesheet.css")) ? 1 : $store_db; + $sql_ary += array( - 'theme_storedb' => (!is_writeable("{$phpbb_root_path}styles/$path/theme/stylesheet.css")) ? 1 : $store_db, - 'theme_data' => ($store_db) ? (($root_path) ? str_replace('./', "styles/$path/theme/", file_get_contents("$root_path/$mode/stylesheet.css")) : '') : '', - 'theme_mtime' => ($store_db) ? filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") : 0 + 'theme_storedb' => $store_db, + 'theme_data' => ($store_db) ? (($root_path) ? $this->db_theme_data($sql_ary, false, $root_path) : '') : '', + 'theme_mtime' => filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") ); break; } @@ -2697,6 +2939,9 @@ pagination_sep = \'{PAGINATION_SEP}\' $log = ($store_db) ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS'; add_log('admin', $log, $name); + + // Return store_db in case it had to be altered + return $store_db; } } diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 02072c1c60..4900486a9e 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -280,7 +280,7 @@ class dbal // Show complete SQL error and path to administrators only // Additionally show complete error on installation or if extended debug mode is enabled // The DEBUG_EXTRA constant is for development only! - if ($auth->acl_get('a_') || defined('IN_INSTALL') || defined('DEBUG_EXTRA')) + if (isset($auth) && ($auth->acl_get('a_') || defined('IN_INSTALL') || defined('DEBUG_EXTRA'))) { // Print out a nice backtrace... $backtrace = get_backtrace(); diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index c202637092..94f6ffe35a 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -367,10 +367,7 @@ function approve_post($post_id_list, $mode) $topic_id_list[$post_data['topic_id']] = 1; // Topic or Post. ;) - /** - * @todo What happens if a user posts a new topic which is not approved, then a second user replies and the post is automatically approved ;) - */ - if ($post_data['topic_first_post_id'] == $post_id/* && $post_data['topic_last_post_id'] == $post_id*/) + if ($post_data['topic_first_post_id'] == $post_id) { if ($post_data['forum_id']) { diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index c961062ac8..344fdff8a6 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -338,10 +338,7 @@ class bbcode_firstpass extends bbcode // Because highlight_string is specialcharing the text (but we already did this before), we have to reverse this in order to get correct results $code = html_entity_decode($code); - ob_start(); - highlight_string($code); - $code = ob_get_contents(); - ob_end_clean(); + $code = highlight_string($code, true); $str_from = array('<font color="syntax', '</font>', '<code>', '</code>','[', ']', '.', ':'); $str_to = array('<span class="syntax', '</span>', '', '', '[', ']', '.', ':'); diff --git a/phpBB/includes/search/search.php b/phpBB/includes/search/search.php index ddf5ca9796..fc9cf2bf02 100755 --- a/phpBB/includes/search/search.php +++ b/phpBB/includes/search/search.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @ignore */ -define('SEARCH_RESULT_NOT_IN_CACHE', 2); +define('SEARCH_RESULT_NOT_IN_CACHE', 0); define('SEARCH_RESULT_IN_CACHE', 1); define('SEARCH_RESULT_INCOMPLETE', 2); @@ -94,7 +94,7 @@ class search_backend * @param int result_count will contain the number of all results for the search (not only for the current page) * @param array id_ary is filled with the ids belonging to the requested page that are stored in the cache * - * @return SEARCH_RESULT_NOT_IN_CACHE or SEARCH_RESULT_IN_CACHE or SEARCH_RESULT_INCOMPLETE + * @return int SEARCH_RESULT_NOT_IN_CACHE or SEARCH_RESULT_IN_CACHE or SEARCH_RESULT_INCOMPLETE */ function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) { diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index a73967d001..5045fab807 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -536,13 +536,15 @@ $lang = array_merge($lang, array( 'LOG_STYLE_EDIT_DETAILS' => '<b>Edited style</b><br />» %s', 'LOG_STYLE_EXPORT' => '<b>Exported style</b><br />» %s', - 'LOG_TEMPLATE_ADD_DB' => '<b>Added new template set to database</b><br />» %s', - 'LOG_TEMPLATE_ADD_FS' => '<b>Add new template set on filesystem</b><br />» %s', - 'LOG_TEMPLATE_DELETE' => '<b>Deleted template set</b><br />» %s', - 'LOG_TEMPLATE_EDIT' => '<b>Edited template set <i>%s</i></b><br />» %s', - 'LOG_TEMPLATE_EDIT_DETAILS' => '<b>Edited template details</b><br />» %s', - 'LOG_TEMPLATE_EXPORT' => '<b>Exported template set</b><br />» %s', - + 'LOG_TEMPLATE_ADD_DB' => '<b>Added new template set to database</b><br />» %s', + 'LOG_TEMPLATE_ADD_FS' => '<b>Add new template set on filesystem</b><br />» %s', + 'LOG_TEMPLATE_CACHE_CLEARED' => '<b>Deleted cached versions of template files in template set <i>%s</i></b><br />» %s', + 'LOG_TEMPLATE_DELETE' => '<b>Deleted template set</b><br />» %s', + 'LOG_TEMPLATE_EDIT' => '<b>Edited template set <i>%s</i></b><br />» %s', + 'LOG_TEMPLATE_EDIT_DETAILS' => '<b>Edited template details</b><br />» %s', + 'LOG_TEMPLATE_EXPORT' => '<b>Exported template set</b><br />» %s', + 'LOG_TEMPLATE_REFRESHED' => '<b>Refreshed template set</b><br />» %s', + 'LOG_THEME_ADD_DB' => '<b>Added new theme to database</b><br />» %s', 'LOG_THEME_ADD_FS' => '<b>Add new theme on filesystem</b><br />» %s', 'LOG_THEME_DELETE' => '<b>Theme deleted</b><br />» %s', diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index 27918011ee..8c102a23f8 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -49,17 +49,24 @@ $lang = array_merge($lang, array( 'BACKGROUND_REPEAT' => 'Background repeat', 'BOLD' => 'Bold', - 'CACHE' => 'Cache', - 'COPYRIGHT' => 'Copyright', - 'CREATE_IMAGESET' => 'Create new imageset', - 'CREATE_STYLE' => 'Create new style', - 'CREATE_TEMPLATE' => 'Create new template set', - 'CREATE_THEME' => 'Create new theme', - 'CSS_CLASS_NAME' => 'CSS class name', - 'CSS_COLOUR_EXPLAIN' => 'You can either enter a hex number for the colour or use the web safe colour swatch to select one.', - 'CURRENT_IMAGE' => 'Current Image', - 'CUSTOM_CLASS' => 'Custom class', - 'CUSTOM_CLASS_EXPLAIN' => 'You can add additional classes to this theme if you wish. You must provide the actual CSS class name below, it must be the same as that you have or will use in your template. Please remember that class names may contain only alphanumeric characters, periods (.), colons (:), dash (-) and number/hash/pound (#). The new class will be added to class selection above.', + 'CACHE' => 'Cache', + 'CACHE_CACHED' => 'Cached', + 'CACHE_FILENAME' => 'Template file', + 'CACHE_FILESIZE' => 'Filesize', + 'CACHE_MODIFIED' => 'Modified', + 'CONFIRM_TEMPLATE_CLEAR_CACHE' => 'Are you sure you wish to clear all cached versions of your template files?', + 'CONFIRM_TEMPLATE_REFRESH' => 'Are you sure you wish to refresh all template data in the database with the contents of the template files on the filesystem? This will overwrite all modifications which have been carried out with the template editor while the template was stored in the database.', + 'CONFIRM_THEME_REFRESH' => 'Are you sure you wish to refresh the theme data stored in the database with the contents of the theme on the filesystem? This will overwrite all modifications which have been carried out with the theme editor while the theme was stored in the database.', + 'COPYRIGHT' => 'Copyright', + 'CREATE_IMAGESET' => 'Create new imageset', + 'CREATE_STYLE' => 'Create new style', + 'CREATE_TEMPLATE' => 'Create new template set', + 'CREATE_THEME' => 'Create new theme', + 'CSS_CLASS_NAME' => 'CSS class name', + 'CSS_COLOUR_EXPLAIN' => 'You can either enter a hex number for the colour or use the web safe colour swatch to select one.', + 'CURRENT_IMAGE' => 'Current Image', + 'CUSTOM_CLASS' => 'Custom class', + 'CUSTOM_CLASS_EXPLAIN' => 'You can add additional classes to this theme if you wish. You must provide the actual CSS class name below, it must be the same as that you have or will use in your template. Please remember that class names may contain only alphanumeric characters, periods (.), colons (:), dash (-) and number/hash/pound (#). The new class will be added to class selection above.', 'DEACTIVATE_DEFAULT' => 'You cannot deactivate the default style.', 'DELETE_FROM_FS' => 'Delete from filesystem', @@ -301,16 +308,19 @@ $lang = array_merge($lang, array( 'STYLE_THEME' => 'Theme', 'STYLE_USED_BY' => 'Used by', - 'TEMPLATE_EDITOR' => 'Raw HTML template editor', - 'TEMPLATE_EDITOR_HEIGHT' => 'Template editor height', - 'TEMPLATE_FILE' => 'Template file', - 'TEMPLATE_FILE_UPDATED' => 'Template file updated successfully', 'TEMPLATE_ADDED' => 'Template set added and stored on filesystem', 'TEMPLATE_ADDED_DB' => 'Template set added and stored in database', + 'TEMPLATE_CACHE' => 'Template cache', + 'TEMPLATE_CACHE_EXPLAIN' => 'By default phpBB caches the compiled version of its templates. This decreases the load on the server each time a page is viewed and thus may reduce the page generation time. Here you can view the cache status of each file and delete individual files or the entire cache.', + 'TEMPLATE_CACHE_CLEARED' => 'Template cache cleared successfully', + 'TEMPLATE_CACHE_EMPTY' => 'There are no cached templates.', 'TEMPLATE_DELETED' => 'Template set deleted successfully', 'TEMPLATE_DELETED_FS' => 'Template set removed from database but some files may remain on the filesystem', 'TEMPLATE_DETAILS_UPDATED' => 'Template details successfully updated', + 'TEMPLATE_EDITOR' => 'Raw HTML template editor', + 'TEMPLATE_EDITOR_HEIGHT' => 'Template editor height', 'TEMPLATE_ERR_ARCHIVE' => 'Please select an archive method', + 'TEMPLATE_ERR_CACHE_READ' => 'The cache directory used to store cached versions of template files could not be opened.', 'TEMPLATE_ERR_COPY_LONG' => 'The copyright can be no longer than 60 characters', 'TEMPLATE_ERR_NAME_CHARS' => 'The template name can only contain alphanumeric characters, -, +, _ and space', 'TEMPLATE_ERR_NAME_EXIST' => 'A template set with that name already exists', @@ -320,12 +330,16 @@ $lang = array_merge($lang, array( 'TEMPLATE_EXPORT' => 'Export Templates', 'TEMPLATE_EXPORT_EXPLAIN' => 'Here you can export a template set in the form of an archive. This archive will contain all the files necessary to install the templates on another board. You may select whether to download the file directly or to place it in your store folder for download later or via FTP.', 'TEMPLATE_EXPORTED' => 'Templates exported succesfully and stored in %s', + 'TEMPLATE_FILE' => 'Template file', + 'TEMPLATE_FILE_UPDATED' => 'Template file updated successfully', 'TEMPLATE_LOCATION' => 'Store templates in', 'TEMPLATE_LOCATION_EXPLAIN' => 'Images are always stored on the filesystem.', 'TEMPLATE_NAME' => 'Template name', + 'TEMPLATE_REFRESHED' => 'Template refreshed successfully', 'THEME_ADDED' => 'New theme added on filesystem', 'THEME_ADDED_DB' => 'New theme added to database', + 'THEME_CLASS_ADDED' => 'Custom class added successfully', 'THEME_DELETED' => 'Theme deleted successfully', 'THEME_DELETED_FS' => 'Theme removed from database but files remain on the filesystem', 'THEME_DETAILS_UPDATED' => 'Theme details successfully updated', @@ -338,6 +352,7 @@ $lang = array_merge($lang, array( 'THEME_ERR_NAME_EXIST' => 'A theme with that name already exists', 'THEME_ERR_NAME_LONG' => 'The theme name can be no longer than 30 characters', 'THEME_ERR_NOT_THEME' => 'The archive you specified does not contain a valid theme.', + 'THEME_ERR_REFRESH_FS' => 'This theme is stored on the filesystem so there is no need to refresh it.', 'THEME_ERR_STYLE_NAME' => 'You must supply a name for this theme', 'THEME_EXPORT' => 'Export Theme', 'THEME_EXPORT_EXPLAIN' => 'Here you can export a theme in the form of an archive. This archive will contain all the data necessary to install the theme on another board. You may select whether to download the file directly or to place it in your store folder for download later or via FTP.', @@ -345,7 +360,7 @@ $lang = array_merge($lang, array( 'THEME_LOCATION' => 'Store stylesheet in', 'THEME_LOCATION_EXPLAIN' => 'Images are always stored on the filesystem.', 'THEME_NAME' => 'Theme Name', - 'THEME_CLASS_ADDED' => 'Custom class added successfully', + 'THEME_REFRESHED' => 'Theme refreshed successfully', 'THEME_UPDATED' => 'Class updated successfully', 'UNDERLINE' => 'Underline', diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 0a9c41631b..1a33fe956a 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -51,6 +51,7 @@ $lang = array_merge($lang, array( 'ADMINISTRATOR' => 'Administrator', 'ADMINISTRATORS' => 'Administrators', 'ALLOWED' => 'Allowed', + 'ALL_FILES' => 'All files', 'ALL_FORUMS' => 'All forums', 'ALL_MESSAGES' => 'All messages', 'ALL_POSTS' => 'All posts', diff --git a/phpBB/style.php b/phpBB/style.php index e1bc5ef375..341fea13c5 100644 --- a/phpBB/style.php +++ b/phpBB/style.php @@ -33,7 +33,7 @@ if (!empty($load_extensions)) $sid = (isset($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : ''; $id = (isset($_GET['id'])) ? intval($_GET['id']) : 0; -if (!preg_match('/^[A-Za-z0-9]*$/', $sid)) +if (!preg_match('/^[A-Za-z0-9]*$/', $sid)) { $sid = ''; } @@ -52,7 +52,7 @@ if ($id && $sid) $db = new $sql_db(); $cache = new cache(); - + // Connect to DB if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false)) { @@ -66,7 +66,7 @@ if ($id && $sid) $result = $db->sql_query($sql); $user = $db->sql_fetchrow($result); $db->sql_freeresult($result); - + if ($user) { $sql = "SELECT s.style_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.imageset_path, t.template_path @@ -84,33 +84,9 @@ if ($id && $sid) exit; } - /*$force_load = true; // Ideally this needs to be based on $config['load_tplcompile'] - - if ($theme['theme_mtime'] < filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css') || $force_load) - { - $theme['theme_data'] = file_get_contents("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'); - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(\"(.*)\"\);/i', $theme['theme_data'], $matches); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - $theme['theme_data'] = str_replace($match, file_get_contents("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/' . $matches[1][$idx]), $theme['theme_data']); - } - } - - $sql = "UPDATE {$table_prefix}styles_theme - SET theme_data = '" . $db->sql_escape(str_replace('./', "styles/{$theme['theme_path']}/theme/", $theme['theme_data'])) . "', theme_mtime = " . time() . " - WHERE theme_id = $id"; - $db->sql_query($sql); - }*/ - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 3600)); header('Content-type: text/css'); - + // Parse Theme Data $replace = array( '{T_THEME_PATH}' => "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme', |