[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> stylesheet.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program is distributed in the hope that it will be useful,
  12  #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #GNU General Public License for more details.
  15  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  #
  19  #$Id: stylesheet.php 3747 2007-01-14 11:59:02Z dittmann $
  20  
  21  if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']))
  22  {
  23      @ini_set( 'zlib.output_compression','Off' );
  24  }
  25  
  26  $templateid = '';
  27  if (isset($_GET["templateid"])) $templateid = $_GET["templateid"];
  28  
  29  $mediatype = '';
  30  if (isset($_GET["mediatype"])) $mediatype = $_GET["mediatype"];
  31  
  32  $name = '';
  33  if (isset($_GET['name'])) $name = $_GET['name'];
  34  
  35  $stripbackground = false;
  36  if (isset($_GET["stripbackground"])) $stripbackground = true;
  37  
  38  if ($templateid == '' && $name == '') return '';
  39  
  40  require_once('config.php');
  41  
  42  $css='';
  43  
  44  if (isset($config['old_stylesheet']) && $config['old_stylesheet'] == false)
  45  {
  46      // connect to the database
  47      require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'misc.functions.php');
  48      require_once(cms_join_path(dirname(__FILE__),'lib','adodb.functions.php'));
  49      load_adodb();
  50      $db =& adodb_connect();
  51      
  52      // select the stylesheet(s)
  53      if ($name != '')
  54          $sql="SELECT css_text, css_name FROM ".$config['db_prefix']."css WHERE css_name = " . $db->qstr($name);
  55      else
  56          $sql="SELECT c.css_text, c.css_id, c.css_name FROM ".$config['db_prefix']."css c,".$config['db_prefix']."css_assoc ac WHERE ac.assoc_type='template' AND ac.assoc_to_id = $templateid AND ac.assoc_css_id = c.css_id AND c.media_type = " . $db->qstr($mediatype) . " ORDER BY ac.create_date";
  57      $result = $db->Execute($sql);
  58      
  59      // add a comment at the start
  60      while ($result && $row = $result->FetchRow())
  61      {
  62          $css .= "/* Start of CMSMS style sheet '{$row['css_name']}' */\n{$row['css_text']}\n/* End of '{$row['css_name']}' */\n\n";
  63      }
  64      
  65      // set encoding
  66      if ($config['admin_encoding'] != '')
  67          $encoding = $config['admin_encoding'];
  68      elseif ($config['default_encoding'] != '')
  69          $encoding = $config['default_encoding'];
  70      else
  71          $encoding = 'UTF-8';
  72  }
  73  else
  74  {
  75      require_once(dirname(__FILE__)."/include.php");
  76      
  77      if ($name != '')
  78      {
  79          //TODO: Make stylesheet handling OOP
  80          global $gCms;
  81          $db =& $gCms->GetDb();
  82          $cssquery = "SELECT css_text, css_name FROM ".cms_db_prefix()."css WHERE css_name = ?";
  83          $cssresult = &$db->Execute($cssquery, array($name));
  84  
  85          while ($cssresult && !$cssresult->EOF)
  86          {
  87              $css .= "/* Start of CMSMS style sheet '{$cssresult->fields['css_name']}' */\n{$cssresult->fields['css_text']}\n/* End of '{$cssresult->fields['css_name']}' */\n";
  88              $cssresult->MoveNext();
  89          }
  90      }
  91      else
  92      {
  93          $result = get_stylesheet($templateid, $mediatype);
  94          $css = $result['stylesheet']; 
  95          if (!isset($result['nostylesheet']))
  96          {
  97              #$nostylesheet = true;
  98              #Perform the content stylesheet callback
  99              #if ($nostylesheet == false)
 100              #{
 101                  reset($gCms->modules);
 102                  while (list($key) = each($gCms->modules))
 103                  {
 104                      $value =& $gCms->modules[$key];
 105                      if ($gCms->modules[$key]['installed'] == true &&
 106                          $gCms->modules[$key]['active'] == true)
 107                      {
 108                          $gCms->modules[$key]['object']->ContentStylesheet($css);
 109                      }
 110                  }
 111                  
 112                  Events::SendEvent('Core', 'ContentStylesheet', array('stylesheet' => &$stylesheet));
 113              #}
 114          }
 115      }
 116      // set encoding
 117      $encoding = isset($result['encoding']) ? $result['encoding'] : 'UTF-8';
 118  }
 119      
 120  
 121  // send HTTP header
 122  header("Content-Type: text/css; charset=$encoding");
 123  
 124  #sending content length allows HTTP/1.0 persistent connections
 125  #(and also breaks if gzip is on)
 126  #header("Content-Length: ".strlen($css));
 127  
 128  if ($stripbackground)
 129  {
 130      #$css = preg_replace('/(\w*?background-color.*?\:\w*?).*?(;.*?)/', '', $css);
 131      $css = preg_replace('/(\w*?background-color.*?\:\w*?).*?(;.*?)/', '\\1transparent\\2', $css);
 132      $css = preg_replace('/(\w*?background-image.*?\:\w*?).*?(;.*?)/', '', $css);
 133  }
 134  
 135  #Do cache-control stuff but only if we are running Apache
 136  if(function_exists('getallheaders'))
 137  {
 138      $headers = getallheaders();
 139      $hash = md5($css);
 140  
 141      #if browser sent etag and it is the same then reply with 304
 142      if (isset($headers['If-None-Match']) && $headers['If-None-Match'] == '"'.$hash.'"')
 143      {
 144          header('HTTP/1.1 304 Not Modified');
 145          exit;
 146      }
 147      else {
 148          header('ETag: "'.$hash.'"');
 149      }
 150  }
 151  
 152  echo $css;
 153  
 154  # vim:ts=4 sw=4 noet
 155  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7