|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
*
|
|
|
f2e824 |
* @package phpBB3
|
|
|
f2e824 |
* @version $Id: style.php 8780 2008-08-22 12:52:48Z acydburn $
|
|
|
f2e824 |
* @copyright (c) 2005 phpBB Group
|
|
|
f2e824 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
f2e824 |
*
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* @ignore
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
define('IN_PHPBB', true);
|
|
|
f2e824 |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
|
|
f2e824 |
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Report all errors, except notices
|
|
|
f2e824 |
error_reporting(E_ALL ^ E_NOTICE);
|
|
|
f2e824 |
|
|
|
f2e824 |
require($phpbb_root_path . 'config.' . $phpEx);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
exit;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (version_compare(PHP_VERSION, '6.0.0-dev', '<'))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
@set_magic_quotes_runtime(0);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Load Extensions
|
|
|
f2e824 |
if (!empty($load_extensions))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$load_extensions = explode(',', $load_extensions);
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($load_extensions as $extension)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
@dl(trim($extension));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
|
|
|
f2e824 |
$sid = (isset($_GET['sid']) && !is_array($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : '';
|
|
|
f2e824 |
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
|
|
|
f2e824 |
|
|
|
f2e824 |
if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sid = '';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// This is a simple script to grab and output the requested CSS data stored in the DB
|
|
|
f2e824 |
// We include a session_id check to try and limit 3rd party linking ... unless they
|
|
|
f2e824 |
// happen to have a current session it will output nothing. We will also cache the
|
|
|
f2e824 |
// resulting CSS data for five minutes ... anything to reduce the load on the SQL
|
|
|
f2e824 |
// server a little
|
|
|
f2e824 |
if ($id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Include files
|
|
|
f2e824 |
require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
|
|
|
f2e824 |
require($phpbb_root_path . 'includes/cache.' . $phpEx);
|
|
|
f2e824 |
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
|
|
|
f2e824 |
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
|
|
f2e824 |
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
|
|
f2e824 |
|
|
|
f2e824 |
$db = new $sql_db();
|
|
|
f2e824 |
$cache = new cache();
|
|
|
f2e824 |
|
|
|
f2e824 |
// Connect to DB
|
|
|
f2e824 |
if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
exit;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($dbpasswd);
|
|
|
f2e824 |
|
|
|
f2e824 |
$config = $cache->obtain_config();
|
|
|
f2e824 |
$user = false;
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($sid)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT u.user_id, u.user_lang
|
|
|
f2e824 |
FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u
|
|
|
f2e824 |
WHERE s.session_id = '" . $db->sql_escape($sid) . "'
|
|
|
f2e824 |
AND s.session_user_id = u.user_id";
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
$user = $db->sql_fetchrow($result);
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$recompile = $config['load_tplcompile'];
|
|
|
f2e824 |
if (!$user)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$id = $config['default_style'];
|
|
|
f2e824 |
$recompile = false;
|
|
|
f2e824 |
$user = array('user_id' => ANONYMOUS);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT s.style_id, c.theme_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
|
|
|
f2e824 |
FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . ' i
|
|
|
f2e824 |
WHERE s.style_id = ' . $id . '
|
|
|
f2e824 |
AND t.template_id = s.template_id
|
|
|
f2e824 |
AND c.theme_id = s.theme_id
|
|
|
f2e824 |
AND i.imageset_id = s.imageset_id';
|
|
|
f2e824 |
$result = $db->sql_query($sql, 300);
|
|
|
f2e824 |
$theme = $db->sql_fetchrow($result);
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$theme)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
exit;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($user['user_id'] == ANONYMOUS)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$user['user_lang'] = $config['default_lang'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$user_image_lang = (file_exists($phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user['user_lang'])) ? $user['user_lang'] : $config['default_lang'];
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT *
|
|
|
f2e824 |
FROM ' . STYLES_IMAGESET_DATA_TABLE . '
|
|
|
f2e824 |
WHERE imageset_id = ' . $theme['imageset_id'] . "
|
|
|
f2e824 |
AND image_filename <> ''
|
|
|
f2e824 |
AND image_lang IN ('" . $db->sql_escape($user_image_lang) . "', '')";
|
|
|
f2e824 |
$result = $db->sql_query($sql, 3600);
|
|
|
f2e824 |
|
|
|
f2e824 |
$img_array = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$img_array[$row['image_name']] = $row;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// gzip_compression
|
|
|
f2e824 |
if ($config['gzip_compress'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// IE6 is not able to compress the style (do not ask us why!)
|
|
|
f2e824 |
$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? strtolower(htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT'])) : '';
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent())
|
|
|
f2e824 |
{
|
|
|
f2e824 |
ob_start('ob_gzhandler');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Expire time of seven days if not recached
|
|
|
f2e824 |
$expire_time = 7*86400;
|
|
|
f2e824 |
$recache = false;
|
|
|
f2e824 |
|
|
|
f2e824 |
// Re-cache stylesheet data if necessary
|
|
|
f2e824 |
if ($recompile || empty($theme['theme_data']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$recache = (empty($theme['theme_data'])) ? true : false;
|
|
|
f2e824 |
$update_time = time();
|
|
|
f2e824 |
|
|
|
f2e824 |
// We test for stylesheet.css because it is faster and most likely the only file changed on common themes
|
|
|
f2e824 |
if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$recache = true;
|
|
|
f2e824 |
$update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else if (!$recache)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$last_change = $theme['theme_mtime'];
|
|
|
f2e824 |
$dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme");
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($dir)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
while (($entry = readdir($dir)) !== false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}"))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$recache = true;
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
closedir($dir);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($recache)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx);
|
|
|
f2e824 |
|
|
|
f2e824 |
$theme['theme_data'] = acp_styles::db_theme_data($theme);
|
|
|
f2e824 |
$theme['theme_mtime'] = $update_time;
|
|
|
f2e824 |
|
|
|
f2e824 |
// Save CSS contents
|
|
|
f2e824 |
$sql_ary = array(
|
|
|
f2e824 |
'theme_mtime' => $theme['theme_mtime'],
|
|
|
f2e824 |
'theme_data' => $theme['theme_data']
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
|
|
|
f2e824 |
WHERE theme_id = {$theme['theme_id']}";
|
|
|
f2e824 |
$db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$cache->destroy('sql', STYLES_THEME_TABLE);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Only set the expire time if the theme changed data is older than 30 minutes - to cope with changes from the ACP
|
|
|
f2e824 |
if ($recache || $theme['theme_mtime'] > (time() - 1800))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
header('Expires: 0');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
header('Content-type: text/css; charset=UTF-8');
|
|
|
f2e824 |
|
|
|
f2e824 |
// Parse Theme Data
|
|
|
f2e824 |
$replace = array(
|
|
|
f2e824 |
'{T_THEME_PATH}' => "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme',
|
|
|
f2e824 |
'{T_TEMPLATE_PATH}' => "{$phpbb_root_path}styles/" . $theme['template_path'] . '/template',
|
|
|
f2e824 |
'{T_IMAGESET_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset',
|
|
|
f2e824 |
'{T_IMAGESET_LANG_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset/' . $user_image_lang,
|
|
|
f2e824 |
'{T_STYLESHEET_NAME}' => $theme['theme_name'],
|
|
|
f2e824 |
'{S_USER_LANG}' => $user['user_lang']
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
$theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$matches = array();
|
|
|
f2e824 |
preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches);
|
|
|
f2e824 |
|
|
|
f2e824 |
$imgs = $find = $replace = array();
|
|
|
f2e824 |
if (isset($matches[0]) && sizeof($matches[0]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($matches[1] as $i => $img)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$img = strtolower($img);
|
|
|
f2e824 |
$find[] = $matches[0][$i];
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!isset($img_array[$img]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$replace[] = '';
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!isset($imgs[$img]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$img_data = &$img_array[$img];
|
|
|
f2e824 |
$imgsrc = ($img_data['image_lang'] ? $img_data['image_lang'] . '/' : '') . $img_data['image_filename'];
|
|
|
f2e824 |
$imgs[$img] = array(
|
|
|
f2e824 |
'src' => $phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $imgsrc,
|
|
|
f2e824 |
'width' => $img_data['image_width'],
|
|
|
f2e824 |
'height' => $img_data['image_height'],
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
switch ($matches[2][$i])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
case 'SRC':
|
|
|
f2e824 |
$replace[] = $imgs[$img]['src'];
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
case 'WIDTH':
|
|
|
f2e824 |
$replace[] = $imgs[$img]['width'];
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
case 'HEIGHT':
|
|
|
f2e824 |
$replace[] = $imgs[$img]['height'];
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
default:
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (sizeof($find))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$theme['theme_data'] = str_replace($find, $replace, $theme['theme_data']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
echo $theme['theme_data'];
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!empty($cache))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$cache->unload();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_close();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
exit;
|
|
|
f2e824 |
|
|
|
f2e824 |
?>
|