[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/ -> style.php (source)

   1  <?php 
   2  /** 
   3  *
   4  * @package phpBB3
   5  * @version $Id: style.php,v 1.24 2006/10/06 18:43:54 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  define('IN_PHPBB', true);
  15  $phpbb_root_path = './';
  16  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17  require($phpbb_root_path . 'config.' . $phpEx);
  18  
  19  set_magic_quotes_runtime(0);
  20  
  21  // Load Extensions
  22  if (!empty($load_extensions))
  23  {
  24      $load_extensions = explode(',', $load_extensions);
  25  
  26      foreach ($load_extensions as $extension)
  27      {
  28          @dl(trim($extension));
  29      }
  30  }
  31  
  32  
  33  $sid = (isset($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : '';
  34  $id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
  35  
  36  if (!preg_match('/^[A-Za-z0-9]*$/', $sid))
  37  {
  38      $sid = '';
  39  }
  40  
  41  // This is a simple script to grab and output the requested CSS data stored in the DB
  42  // We include a session_id check to try and limit 3rd party linking ... unless they
  43  // happen to have a current session it will output nothing. We will also cache the
  44  // resulting CSS data for five minutes ... anything to reduce the load on the SQL
  45  // server a little
  46  if ($id && $sid)
  47  {
  48      if (empty($acm_type) || empty($dbms))
  49      {
  50          die('Hacking attempt');
  51      }
  52  
  53      // Include files
  54      require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
  55      require($phpbb_root_path . 'includes/cache.' . $phpEx);
  56      require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  57      require($phpbb_root_path . 'includes/constants.' . $phpEx);
  58  
  59      $db = new $sql_db();
  60      $cache = new cache();
  61  
  62      // Connect to DB
  63      if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false))
  64      {
  65          exit;
  66      }
  67  
  68      $config = $cache->obtain_config();
  69  
  70      $sql = "SELECT s.session_id, u.user_lang
  71          FROM {$table_prefix}sessions s, {$table_prefix}users u
  72          WHERE s.session_id = '" . $db->sql_escape($sid) . "'
  73              AND s.session_user_id = u.user_id";
  74      $result = $db->sql_query($sql);
  75      $user = $db->sql_fetchrow($result);
  76      $db->sql_freeresult($result);
  77  
  78      if ($user)
  79      {
  80          $sql = "SELECT s.style_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
  81              FROM {$table_prefix}styles s, {$table_prefix}styles_template t, {$table_prefix}styles_theme c, {$table_prefix}styles_imageset i
  82              WHERE s.style_id = $id
  83                  AND t.template_id = s.template_id
  84                  AND c.theme_id = s.theme_id
  85                  AND i.imageset_id = s.imageset_id";
  86          $result = $db->sql_query($sql, 300);
  87          $theme = $db->sql_fetchrow($result);
  88          $db->sql_freeresult($result);
  89  
  90          if (!$theme)
  91          {
  92              exit;
  93          }
  94  
  95          // Re-cache stylesheet data if necessary
  96          if ($config['load_tplcompile'] && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'))
  97          {
  98              include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx);
  99  
 100              $theme['theme_data'] = acp_styles::db_theme_data($theme);
 101              $theme['theme_mtime'] = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css');
 102  
 103              // Save CSS contents
 104              $sql_ary = array(
 105                  'theme_mtime'    => $theme['theme_mtime'],
 106                  'theme_data'    => $theme['theme_data']
 107              );
 108  
 109              $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
 110                  WHERE theme_id = $id";
 111              $db->sql_query($sql);
 112  
 113              $cache->destroy('sql', STYLES_THEME_TABLE);
 114          }
 115  
 116          header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
 117          header('Content-type: text/css');
 118  
 119          // Parse Theme Data
 120          $replace = array(
 121              '{T_THEME_PATH}'            => "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme',
 122              '{T_TEMPLATE_PATH}'            => "{$phpbb_root_path}styles/" . $theme['template_path'] . '/template',
 123              '{T_IMAGESET_PATH}'            => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset',
 124              '{T_IMAGESET_LANG_PATH}'    => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset/' . $user['user_lang'],
 125              '{T_STYLESHEET_NAME}'        => $theme['theme_name'],
 126              '{S_USER_LANG}'                => $user['user_lang']
 127          );
 128  
 129          $theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']);
 130  
 131          $matches = array();
 132          preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches);
 133  
 134          $imgs = $find = $replace = array();
 135          if (isset($matches[0]) && sizeof($matches[0]))
 136          {
 137              foreach ($matches[1] as $i => $img)
 138              {
 139                  $img = strtolower($img);
 140                  if (!isset($theme[$img]))
 141                  {
 142                      continue;
 143                  }
 144  
 145                  if (!isset($imgs[$img]))
 146                  {
 147                      // Do not include dimensions?
 148                      if (strpos($theme[$img], '*') === false)
 149                      {
 150                          $imgsrc = trim($theme[$img]);
 151                          $width = $height = null;
 152                      }
 153                      else
 154                      {
 155                          list($imgsrc, $height, $width) = explode('*', $theme[$img]);
 156                      }
 157          
 158                      $imgs[$img] = array(
 159                          'src'        => $phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . str_replace('{LANG}', $user['user_lang'], $imgsrc),
 160                          'width'        => $width,
 161                          'height'    => $height,
 162                      );
 163                  }
 164  
 165                  switch ($matches[2][$i])
 166                  {
 167                      case 'SRC':
 168                          $replace = $imgs[$img]['src'];
 169                      break;
 170                      
 171                      case 'WIDTH':
 172                          $replace = $imgs[$img]['width'];
 173                      break;
 174          
 175                      case 'HEIGHT':
 176                          $replace = $imgs[$img]['height'];
 177                      break;
 178  
 179                      default:
 180                          continue;
 181                  }
 182                  $find = $matches[0][$i];
 183              }
 184  
 185              if (sizeof($find))
 186              {
 187                  $theme['theme_data'] = str_replace($find, $replace, $theme['theme_data']);
 188              }
 189          }
 190  
 191          echo $theme['theme_data'];
 192      }
 193  
 194      if (!empty($cache))
 195      {
 196          $cache->unload();
 197      }
 198      $db->sql_close();
 199  }
 200  
 201  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6