plugins:css:css_code

NP_CSS.php Source Code

<?php
 
/*
  CSS style switcher, version 0.0.1
  This plugin allows users to select their preffered CSS style sheet, 
  and stores this info in a cookie.
 
  Modify your skin in a following way:
 
  STEP 1:
  in skin body, e.g. in menu div, add following call to allow user select 
  a new CSS style, this will display available styles and button for change:
    <%CSS(SELECT)%>
    --------------- recommended on main page only
 
  STEP 2:
  on EVERY page, in a page header, instead of:
  <link rel="stylesheet" type="text/css" href="<%skinfile(default.css)%>" >
  use on **every page** you want users to see a custom style sheet, not a 
  default one:
    <%CSS(META)%>
    --------------- on all pages
  added> you can call it with one *optional* parameter - a default style sheet,
  but this just duplicates an option found in plugin configuration
 
  This plugin uses one new CSS style, for its selection box position:
  .cssselect{}
 
  Styles used common all Nucleus:
  .formbutton{}
  .formfield{}
*/
 
class NP_CSS extends NucleusPlugin {
 
 function getNAME() { return 'CSS';  }
 function getAuthor()  { return 'Radek HULAN';  }
 function getURL() {  return 'http://hulan.info/blog/'; }
 function getVersion() { return '0.0.1'; }
 function getDescription() { 
  return 'CSS style switcher. Usage: <%CSS(META)%> in *every* page header, supplies complete meta css style info, and <%CSS(SELECT)%> to select a new style.';
 }
 
 function install() {
   $this->createOption('CSSStyles','CSS filenames, comma separated list (without .css!):','text','extreme,czechia,france,choco,blue,simple,techno,green');
   $this->createOption('CSSNames','CSS style names as shown to user:','text','eXtreme!,Czechia,France,Chocolate,Blue Dot,Simpleton,Techno,Green Eye');
   $this->createOption('CSSDefaultFile','Default style filename (without .css!):','text','extreme');
   $this->createOption('CSSText1','Text for current style (can be blank):','text','');
   $this->createOption('CSSText2','Text for select style (can be blank):','text','');
   $this->createOption('CSSText3','Text for select style button:','text','Apply Skin!');
   $this->createOption('menu','Text for menu:','text','Skin');
   $this->createOption('version','CSS version:','text','');
   $this->createOption('cookie','Cookie name:','text','BLOGCMS32');
 }
 
 function supportsFeature($feature) {
		switch($feature) {
			case 'SqlTablePrefix':
				return 1;
			default:
				return 0;
		}
 }
 
 function browserAgent(){
	$xagent = strtolower($_SERVER["HTTP_USER_AGENT"]);
  if(!(strpos(strtolower($xagent),"opera")===false)){$xagent=substr($xagent,strpos(strtolower($xagent),"opera"),10);};
  if(!(strpos(strtolower($xagent),"msie")===false)){$xagent=substr($xagent,strpos(strtolower($xagent),"msie"),8);};
  if(!(strpos(strtolower($xagent),"mozilla")===false)){$xagent="Gecko";};
  $xagent=substr($xagent,0,20);
  return $xagent;
 }
 
 function getEventList() { return array('PreSkinParse'); 	}	
 
 function event_PreSkinParse(&$data) {
  /* ------------------------------------------ */
  /* -------------- set a cookie -------------- */
  if ( !empty($_POST['CSSVOLBA']) ) {
   $cookie=$this->getOption('cookie'); 
   setCookie($cookie,$_POST['CSSVOLBA'], time()+36002430);
   setCookie($cookie,$_POST['CSSVOLBA'], time()+36002430,'/',$_SERVER['HTTP_HOST']);
   $url = str_replace('&','&amp;',str_replace('&amp;','&',"http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
	 header('Expires: 0');
	 header('Pragma: no-cache');
   header("Location: $url");
   $url = htmlspecialchars($url);
   die("Redirected: <a href=\"$url\">$url</a>");
  }
 }
 
 function doSkinVar($skinType, $whattodo = 'META', $defaultsheet = '' ) {
  $cookie=$this->getOption('cookie');
  $version=$this->getOption('version');
 
  /* ---------------------------------------------------- */
  /* query a style formerly saved or supply a default one */
  if ( ($whattodo=='META') || ($whattodo=='SELECT')){
    if (isset($_COOKIE[$cookie])){
      $mycookie=$_COOKIE[$cookie];
      /* style still exists? */
      $found=false;
      $mystyles = explode(",",$this->getOption('CSSStyles'));
      foreach ($mystyles as $mystyle){
        if($mystyle==$mycookie){$found=true;};
      }
      if (!$found) {$mycookie="";}
    } else {
      if($defaultsheet==''){$mycookie=$this->getOption('CSSDefaultFile');} else {$mycookie=$defaultsheet;};
    }
    if ($mycookie==""){
      if($defaultsheet==''){$mycookie=$this->getOption('CSSDefaultFile');} else {$mycookie=$defaultsheet;};
    }
  }
 
  /* ------------------------------------------- */
  /* whattodo = META -- echo selected stylesheet */
  if ($whattodo=='META'){
    global $CONF;
    $CONF['NUCLEUSSTYLE']=$mycookie;
 
    /* echo stylesheet into a header */
    $url=$CONF['SkinsURL'].PARSER::getProperty('IncludePrefix').$mycookie.$version.'.css';
    echo "<link rel='stylesheet' type='text/css' href='".$url."' media='screen,projection' />\n";
    $CONF['NUCLEUSCSS']=$url;
 
    /* print stylesheet */
    if ($skinType=='item'){
      $url=$CONF['SkinsURL'].PARSER::getProperty('IncludePrefix').'print.css';
      echo "<link rel='stylesheet' type='text/css' href='".$url."' media='print' />\n";
    }
  }
 
  /* ------------------------------------------------------------------- */
  /* whattodo = SELECT -- display current style and form for changing it */
  if ($whattodo=='SELECT'){
    /* echo current style */
    if ($this->getOption('CSSText1')!=""){
      echo $this->getOption('CSSText1').$mycookie;
    }
    /* echo style select form */
    echo $this->getOption('CSSText2');
    $url=str_replace('&','&amp;',str_replace('&amp;','&',"http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
    echo "<form id='CSSSwitch' method='post' action='$url'>\n";
    echo "<div class='centrovani'><fieldset><legend>".$this->getOption('menu')."</legend>";
    echo "<select name='CSSVOLBA' class='formfield'>\n";
     $mystyles = explode(",",$this->getOption('CSSStyles'));
     $mynames = explode(",",$this->getOption('CSSNames'));
     $i=0;
     foreach ($mystyles as $mystyle){
      if($mystyle==$mycookie){$deff=" selected='selected' ";} else {$deff="";};
      echo "<option value='$mystyle' $deff id='opt".strval($i)."'>".$mynames[$i]."</option>\n";
      $i++;
     }
    echo "</select>\n";
    echo "<input name='submitcss' type='image' src='".$CONF['SkinsURL']."skins/moose/applyskin.png' alt='".$this->getOption('CSSText3')."' title='".$this->getOption('CSSText3')."' />\n";
    echo "</fieldset></div>\n";
    echo "</form>\n";
  }
 
 }
}
 
?>
 
plugins/css/css_code.txt · 最終更新: 2011/03/23 21:28 (外部編集)