Page 1 of 1

Speed version of smarty plugin function.stylesheet.php

Posted: Mon Jun 09, 2008 8:59 am
by pb
Here  is it:

Code: Select all

<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function smarty_cms_function_stylesheet($params, &$smarty)
{
	global $gCms;
	$config = &$gCms->config;
	$pageinfo = &$gCms->variables['pageinfo'];
  $db =& $gCms->GetDB();
	$stylesheet = '';
	
	if (isset($params['name']) && $params['name'] != '')
	{
		$stylesheet .= '<link rel="stylesheet" type="text/css" ';
		if (isset($params['media']) && $params['media'] != '')
		{
			$stylesheet .= 'media="' . $params['media'] . '" ';
		}
		$stylesheet .= 'href="'.$config['root_url'].'/stylesheet.php?name='.$params['name'];
		$stylesheet .= "\" />\n"; 
	}
	else
	{
	
	  $cssquery = "SELECT DISTINCT media_type FROM ".cms_db_prefix()."css c, ".cms_db_prefix()."css_assoc
			WHERE	css_id		= assoc_css_id
			AND		assoc_type	= 'template'
			AND		assoc_to_id = ?";
		$cssresult = &$db->Execute($cssquery, array($pageinfo->template_id));
		$result=array();
    if ($cssresult)
    { 
		    while ($cssresult && !$cssresult->EOF)
		    {
			   if (!in_array($cssresult->fields['media_type'], $result))
         { 			   
				    $result[] =& $cssresult->fields['media_type'];
				    $media=$cssresult->fields['media_type'];
				    $stylesheet .= '<link rel="stylesheet" type="text/css" ';
			      if ($media != '')
			         $stylesheet .= 'media="'.$media.'" ';
			
			      $stylesheet .= 'href="'.$config['root_url'].'/stylesheet.php?templateid='.$pageinfo->template_id;
			     if ($media != '')
				        $stylesheet .= '&mediatype='.urlencode($media);
			     $stylesheet .= "\" />\n";
				 }   
				    
			   $cssresult->MoveNext();
		   }
		   $cssresult->Close();   
		}    
				
	if (!(isset($config["use_smarty_php_tags"]) && $config["use_smarty_php_tags"] == true))
		$stylesheet = ereg_replace("\{\/?php\}", "", $stylesheet);
 }
 return $stylesheet;
} 

function smarty_cms_help_function_stylesheet() {
  echo lang('help_function_stylesheet');
}

function smarty_cms_about_function_stylesheet() {
	?>
	<p>Author: Ted Kulp<tedkulp@users.sf.net></p>
	<p>Version: 1.0</p>
	<p>
	Change History:<br/>
	None
	</p>
	<?php
}
?>