do not display ban link for own profile
[phpbb.git] / phpBB / style.php
blob9f8d8ff4d3827172280f5c7a4f13639af73a93ef
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 define('IN_PHPBB', true);
15 if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './');
16 if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
18 $sid = (isset($_GET['sid']) && !is_array($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : '';
19 $id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
21 if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid))
23 $sid = '';
26 // This is a simple script to grab and output the requested CSS data stored in the DB
27 // We include a session_id check to try and limit 3rd party linking ... unless they
28 // happen to have a current session it will output nothing. We will also cache the
29 // resulting CSS data for five minutes ... anything to reduce the load on the SQL
30 // server a little
31 if (!$id)
33 exit;
36 include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
38 $user = false;
40 if ($sid)
42 $sql = 'SELECT u.user_id, u.user_lang
43 FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u
44 WHERE s.session_id = '" . $db->sql_escape($sid) . "'
45 AND s.session_user_id = u.user_id";
46 $result = $db->sql_query($sql);
47 $user = $db->sql_fetchrow($result);
48 $db->sql_freeresult($result);
51 $recompile = $config['load_tplcompile'];
52 if (!$user)
54 $id = $config['default_style'];
55 $recompile = false;
56 $user = array('user_id' => ANONYMOUS);
59 $sql = 'SELECT s.style_id, c.theme_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
60 FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . ' i
61 WHERE s.style_id = ' . $id . '
62 AND t.template_id = s.template_id
63 AND c.theme_id = s.theme_id
64 AND i.imageset_id = s.imageset_id';
65 $result = $db->sql_query($sql, 300);
66 $theme = $db->sql_fetchrow($result);
67 $db->sql_freeresult($result);
69 if (!$theme)
71 garbage_collection();
72 exit_handler();
75 if ($user['user_id'] == ANONYMOUS)
77 $user['user_lang'] = $config['default_lang'];
80 $user_image_lang = (file_exists(PHPBB_ROOT_PATH . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user['user_lang'])) ? $user['user_lang'] : $config['default_lang'];
82 $sql = 'SELECT *
83 FROM ' . STYLES_IMAGESET_DATA_TABLE . '
84 WHERE imageset_id = ' . $theme['imageset_id'] . "
85 AND image_filename <> ''
86 AND image_lang IN ('" . $db->sql_escape($user_image_lang) . "', '')";
87 $result = $db->sql_query($sql, 3600);
89 $img_array = array();
90 while ($row = $db->sql_fetchrow($result))
92 $img_array[$row['image_name']] = $row;
94 $db->sql_freeresult($result);
96 // gzip_compression
97 if ($config['gzip_compress'])
99 // IE6 is not able to compress the style (do not ask us why!)
100 $browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? strtolower(htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT'])) : '';
102 if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent())
104 ob_start('ob_gzhandler');
108 // Expire time of seven days if not recached
109 $expire_time = 7 * 86400;
110 $recache = false;
112 // Re-cache stylesheet data if necessary
113 if ($recompile || empty($theme['theme_data']))
115 $recache = (empty($theme['theme_data'])) ? true : false;
116 $update_time = time();
118 // We test for stylesheet.css because it is faster and most likely the only file changed on common themes
119 if (!$recache && $theme['theme_mtime'] < @filemtime(PHPBB_ROOT_PATH . 'styles/' . $theme['theme_path'] . '/theme/stylesheet.css'))
121 $recache = true;
122 $update_time = @filemtime(PHPBB_ROOT_PATH . 'styles/' . $theme['theme_path'] . '/theme/stylesheet.css');
124 else if (!$recache)
126 $last_change = $theme['theme_mtime'];
127 $dir = @opendir(PHPBB_ROOT_PATH . "styles/{$theme['theme_path']}/theme");
129 if ($dir)
131 while (($entry = readdir($dir)) !== false)
133 if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime(PHPBB_ROOT_PATH . "styles/{$theme['theme_path']}/theme/{$entry}"))
135 $recache = true;
136 break;
139 closedir($dir);
144 if ($recache)
146 if (!class_exists('acp_styles'))
148 include(PHPBB_ROOT_PATH . 'includes/acp/acp_styles.' . PHP_EXT);
151 $theme['theme_data'] = acp_styles::db_theme_data($theme);
152 $theme['theme_mtime'] = $update_time;
154 // Save CSS contents
155 $sql_ary = array(
156 'theme_mtime' => $theme['theme_mtime'],
157 'theme_data' => $theme['theme_data']
160 // @TODO: rewrite with the new param db functions
161 $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
162 WHERE theme_id = {$theme['theme_id']}";
163 $db->sql_query($sql);
165 $cache->destroy('sql', STYLES_THEME_TABLE);
168 // Only set the expire time if the theme changed data is older than 30 minutes - to cope with changes from the ACP
169 if ($recache || $theme['theme_mtime'] > (time() - 1800))
171 header('Expires: 0');
173 else
175 header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time));
178 header('Content-type: text/css; charset=UTF-8');
180 // Parse Theme Data
181 $replace = array(
182 '{T_THEME_PATH}' => PHPBB_ROOT_PATH . 'styles/' . $theme['theme_path'] . '/theme',
183 '{T_TEMPLATE_PATH}' => PHPBB_ROOT_PATH . 'styles/' . $theme['template_path'] . '/template',
184 '{T_IMAGESET_PATH}' => PHPBB_ROOT_PATH . 'styles/' . $theme['imageset_path'] . '/imageset',
185 '{T_IMAGESET_LANG_PATH}' => PHPBB_ROOT_PATH . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user_image_lang,
186 '{T_STYLESHEET_NAME}' => $theme['theme_name'],
187 '{S_USER_LANG}' => $user['user_lang']
190 $theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']);
192 $matches = array();
193 preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches);
195 $imgs = $find = $replace = array();
196 if (isset($matches[0]) && sizeof($matches[0]))
198 foreach ($matches[1] as $i => $img)
200 $img = strtolower($img);
201 $find[] = $matches[0][$i];
203 if (!isset($img_array[$img]))
205 $replace[] = '';
206 continue;
209 if (!isset($imgs[$img]))
211 $img_data = &$img_array[$img];
212 $imgsrc = ($img_data['image_lang'] ? $img_data['image_lang'] . '/' : '') . $img_data['image_filename'];
213 $imgs[$img] = array(
214 'src' => PHPBB_ROOT_PATH . 'styles/' . $theme['imageset_path'] . '/imageset/' . $imgsrc,
215 'width' => $img_data['image_width'],
216 'height' => $img_data['image_height'],
220 switch ($matches[2][$i])
222 case 'SRC':
223 $replace[] = $imgs[$img]['src'];
224 break;
226 case 'WIDTH':
227 $replace[] = $imgs[$img]['width'];
228 break;
230 case 'HEIGHT':
231 $replace[] = $imgs[$img]['height'];
232 break;
234 default:
235 continue;
239 if (sizeof($find))
241 $theme['theme_data'] = str_replace($find, $replace, $theme['theme_data']);
245 echo $theme['theme_data'];
247 garbage_collection();
248 exit_handler();