Page 1 of 1

Speed Version of stylesheet.php

Posted: Sat Apr 29, 2006 9:03 am
by Piratos
This is a speed version of stylesheet.php.

The original need ca. 3,5 MB , this script only 50 KB.

Code: Select all

<?php
if (isset($_GET["templateid"])) $templateid = $_GET["templateid"]; else return "";
require_once('config.php');
if ($config['default_encoding'] =='') $encoding=$config['admin_encoding']; else $encoding=$config['default_encoding'];
if ($encoding=='') $encoding='UTF-8';
$sql="SELECT c.css_text,c.css_id 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";
$out="";
if ($config['dbms'] == 'mysqli' OR $config['dbms'] == 'mysql')
{
$db = mysql_connect($config['db_hostname'],$config['db_username'],$config['db_password']);
mysql_select_db($config['db_name']);
$result=mysql_query($sql);
while ($result && $row = mysql_fetch_assoc($result)){$out .=$row['css_text'];}
}
else
{
  $db=pg_connect("host=".$config['db_hostname']." dbname=".$config['db_name']." user=".$config['db_username']." password=".$config['db_password']);
  $result=pg_query($db,$sql);
  while ($result && $row = pg_fetch_array($result, null, PGSQL_ASSOC)){$out .=$row['css_text'];}
}
header("Content-Type: text/css; charset=" .$encoding);
echo $out;
?>

Re: Speed Version of stylesheet.php

Posted: Sat Apr 29, 2006 9:44 am
by tsw
And as it doesnt use adodb it wont work with postgresql

Re: Speed Version of stylesheet.php

Posted: Sat Apr 29, 2006 10:29 am
by Piratos
  $db=pg_connect("host=".$config['db_hostname']." dbname=".$config['db_name']." user=".$config['db_username']." password=".$config['db_password']);
  $result=pg_query($db,$sql);
  while ($result && $row = pg_fetch_array($result, null, PGSQL_ASSOC)){$out .=$row['css_text'];}
Please take a look in the script and than write something about it.

Code: Select all

doesnt use adodb
Why i should use Adodb , there is only 1 query ?

Re: Speed Version of stylesheet.php

Posted: Sat Apr 29, 2006 10:55 am
by tsw
Sorry, didnt read that closely ;)

Re: Speed Version of stylesheet.php

Posted: Sat Apr 29, 2006 12:03 pm
by Piratos
Ok.

It works with mysql, mysqli and with postgresql (i use 8.1 for windows xp).

Re: Speed Version of stylesheet.php

Posted: Sun Apr 30, 2006 9:59 am
by Piratos
From Ted:
I do like this idea (and it's on the cmsmadesimple site now).

Re: Speed Version of stylesheet.php

Posted: Sun Apr 30, 2006 2:58 pm
by Russ
Works for me and is on our test site:
http://www.cms.shoesforindustry.net

Nice one Piratos :)

Russ

Re: Speed Version of stylesheet.php

Posted: Mon May 01, 2006 11:19 am
by Piratos
The same problem is in the admin style.php - because userdata are loaded to get his admin theme, but we have only the default.
So admin get 3,5 MB only with this style.php and if you make a preview, you habe another callll to style.php  and additional 3,5 mb

This script helps and needed without data ca. 5KB.

Code: Select all

<?php

if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']))
{
	@ini_set( 'zlib.output_compression','Off' );
}
header("Content-type: text/css");
$theme="default";
$style="style";
if (isset($_GET['ie']))
    {
    $style.="_ie";
    }
$style .= ".css";
if (file_exists(dirname(__FILE__)."/themes/".$theme."/css/".$style))
	{
	readfile(dirname(__FILE__)."/themes/".$theme."/css/".$style);
	}
else if (file_exists(dirname(__FILE__)."/themes/default/css/".$style))
	{
	readfile(dirname(__FILE__)."/themes/default/css/".$style);
}
# vim:ts=4 sw=4 noet
?>