phpBB
Statistics
| Revision:

root / tags / milestone_3 / phpBB / style.php

History | View | Annotate | Download (3.4 kB)

1
<?php 
2
/** 
3
*
4
* @package phpBB3
5
* @version $Id: style.php 5257 2005-10-04 21:47:20Z acydburn $
6
* @copyright (c) 2005 phpBB Group 
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
8
*
9
*/
10
11
/**
12
*/
13
define('IN_PHPBB', true);
14
$phpbb_root_path = './';
15
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16
require($phpbb_root_path . 'config.'.$phpEx);
17
18
set_magic_quotes_runtime(0);
19
20
// Load Extensions
21
if (!empty($load_extensions))
22
{
23
        $load_extensions = explode(',', $load_extensions);
24
25
        foreach ($load_extensions as $extension)
26
        {
27
                @dl(trim($extension));
28
        }
29
}
30
31
// This is a simple script to grab and output the requested CSS data stored in the DB
32
// We include a session_id check to try and limit 3rd party linking ... unless they
33
// happen to have a current session it will output nothing. We will also cache the
34
// resulting CSS data for five minutes ... anything to reduce the load on the SQL
35
// server a little
36
if (!empty($_GET['id']) && !empty($_GET['sid']))
37
{
38
        // Include files
39
        require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.'.$phpEx);
40
        require($phpbb_root_path . 'includes/acm/acm_main.' . $phpEx);
41
        require($phpbb_root_path . 'includes/db/' . $dbms . '.'.$phpEx);
42
43
        $db = new $sql_db();
44
        $cache = new cache();
45
46
        // Connect to DB
47
        if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false))
48
        {
49
                exit;
50
        }
51
52
        $sid = htmlspecialchars($_GET['sid']);
53
        $id = intval($_GET['id']);
54
55
        $sql = "SELECT s.session_id, u.user_lang
56
                FROM {$table_prefix}sessions s, {$table_prefix}users u
57
                WHERE s.session_id = '" . ((!get_magic_quotes_gpc()) ? $db->sql_escape($sid) : $sid) . "'
58
                        AND s.session_user_id = u.user_id";
59
        $result = $db->sql_query($sql);
60
61
        if ($user = $db->sql_fetchrow($result))
62
        {
63
                $sql = "SELECT s.style_id, c.theme_data, c.theme_path, c.theme_mtime, i.imageset_path, t.template_path
64
                        FROM {$table_prefix}styles s, {$table_prefix}styles_template t, {$table_prefix}styles_theme c, {$table_prefix}styles_imageset i
65
                        WHERE s.style_id = $id
66
                                AND t.template_id = s.template_id
67
                                AND c.theme_id = s.theme_id
68
                                AND i.imageset_id = s.imageset_id";
69
                $result2 = $db->sql_query($sql, 300);
70
71
                if (!($theme = $db->sql_fetchrow($result2)))
72
                {
73
                        exit;
74
                }
75
                $db->sql_freeresult($result2);
76
77
                if ($theme['theme_mtime'] < filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'))
78
                {
79
                        $theme['theme_data'] = implode('', file("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'));
80
81
                        $db->sql_query("UPDATE {$table_prefix}styles_theme SET theme_data = '" . $db->sql_escape($theme['theme_data']) . "', theme_mtime = " . time() . "
82
                                WHERE theme_id = $id");
83
                }
84
85
                header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
86
                header('Content-type: text/css');
87
88
                // Parse Theme Data
89
                $replace = array(
90
                        '{T_THEME_PATH}'                        => "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme',
91
                        '{T_TEMPLATE_PATH}'                        => "{$phpbb_root_path}styles/" . $theme['template_path'] . '/template',
92
                        '{T_IMAGESET_PATH}'                        => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset',
93
                        '{T_IMAGESET_LANG_PATH}'        => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset/' . $user['user_lang'],
94
                        '{T_STYLESHEET_NAME}'                => $theme['theme_name'],
95
                        '{S_USER_LANG}'                                => $user['user_lang']
96
                );
97
98
                $theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']);
99
100
                echo $theme['theme_data'];
101
        }
102
        $db->sql_freeresult($result);
103
104
        if (!empty($cache))
105
        {
106
                $cache->unload();
107
        }
108
        $db->sql_close();
109
}
110
111
?>