html
[ class tree: html ] [ index: html ] [ all elements ]

Source for file Stylesheet.class.php

Documentation is available at Stylesheet.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package html
  9.  */
  10.  
  11. if!defined"CLASSPATH" ) )
  12. {
  13.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  14.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  15.   exit();
  16. }
  17.  
  18. /**
  19.  *
  20.  */
  21. include_onceCLASSPATH."core/PlainTextFormatter.class.php" );
  22.  
  23. /**
  24.  * @package html
  25.  * @version   1.25
  26.  * @author    Daniel Plücken <daniel@debakel.net>
  27.  * @license   http://www.gnu.org/copyleft/lesser.html
  28.  *             GNU Lesser General Public License
  29.  * @copyright Copyright (c) 2005 Daniel Plücken <daniel@debakel.net>
  30.  *
  31.  *  This library is free software; you can redistribute it and/or
  32.  *  modify it under the terms of the GNU Lesser General Public
  33.  *  License as published by the Free Software Foundation; either
  34.  *  version 2.1 of the License.
  35.  *
  36.  *  This library is distributed in the hope that it will be useful,
  37.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  38.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39.  *  GNU Lesser General Public License for more details.
  40.  *
  41.  *  You should have received a copy of the GNU Lesser General
  42.  *  Public License along with this library; if not, write to the
  43.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  44.  *  Boston, MA 02111-1307 USA
  45.  */
  46. class Stylesheet
  47. {
  48.   /**
  49.    * @var    array 
  50.    * @access public
  51.    */
  52.   var $cls_arr = array();
  53.   /**
  54.    * @var    array 
  55.    * @access public
  56.    */
  57.   var $id_arr = array();
  58.   /**
  59.    * @var    array 
  60.    * @access public
  61.    */
  62.   var $tag_arr = array();
  63.   /**
  64.    * Stores the type of media ...
  65.    *
  66.    * @var    string 
  67.    * @access public
  68.    */
  69.   var $str_media = "";
  70.  
  71.  
  72.  
  73.   /**
  74.    * The constructor can be used to set the first stylesheet-class.
  75.    *
  76.    * @version 1.1
  77.    * @since   1.0
  78.    * @author  Daniel Plücken <daniel@debakel.net>
  79.    * @access  public
  80.    * @param   string  $classname 
  81.    * @param   string  $content 
  82.    * @return  void 
  83.    */
  84.   function Stylesheet$classname ""$content "" )
  85.   {
  86.     if !empty$classname ) )
  87.        $this->addClass$classname$content );
  88.   }
  89.  
  90.  
  91.  
  92.   /**
  93.    * Sets the type of media to the stylesheet.
  94.    *
  95.    * @version 1.0
  96.    * @since   1.25
  97.    * @author  Daniel Plücken <daniel@debakel.net>
  98.    * @access  public
  99.    * @param   string  $str_type The type of media can be comma seperated!
  100.    *                              Possible values are:
  101.    *
  102.    *                                  - screen
  103.    *                                  - tty
  104.    *                                  - tv
  105.    *                                  - projection
  106.    *                                  - handheld
  107.    *                                  - print
  108.    *                                  - braille
  109.    *                                  - aural
  110.    *                                  - all
  111.    *
  112.    * @return  void 
  113.    */
  114.   function setMedia$str_type )
  115.   $this->str_media = $str_type}
  116.  
  117.  
  118.  
  119.   /**
  120.    * Adds a stylesheet-class to this object.
  121.    *
  122.    * @version 1.0
  123.    * @since   1.0
  124.    * @author  Daniel Plücken <daniel@debakel.net>
  125.    * @access  public
  126.    * @param   string  $name 
  127.    * @param   string  $content 
  128.    * @return  void 
  129.    */
  130.   function addClass$name$content )
  131.   {
  132.     $cnt count$this->cls_arr );
  133.     $this->cls_arr[$cnt][0$name;
  134.     $this->cls_arr[$cnt][1$content;
  135.   }
  136.  
  137.  
  138.  
  139.   /**
  140.    * Adds a stylesheet of a html-tag to this object.
  141.    *
  142.    * @version 1.0
  143.    * @since   1.2
  144.    * @author  Daniel Plücken <daniel@debakel.net>
  145.    * @access  public
  146.    * @param   string  $name 
  147.    * @param   string  $content 
  148.    * @return  void 
  149.    */
  150.   function addTag$name$content )
  151.   {
  152.     $cnt count$this->tag_arr );
  153.     $this->tag_arr[$cnt][0$name;
  154.     $this->tag_arr[$cnt][1$content;
  155.   }
  156.  
  157.  
  158.  
  159.   /**
  160.    * Adds a stylesheet-id to this object.
  161.    *
  162.    * @version 1.0
  163.    * @since   1.1
  164.    * @author  Daniel Plücken <daniel@debakel.net>
  165.    * @access  public
  166.    * @param   string  $classname* 
  167.    * @param   string  $content* 
  168.    * @return  void 
  169.    */
  170.   function addId$name$content )
  171.   {
  172.     $cnt count$this->id_arr );
  173.     $this->id_arr[$cnt][0$name;
  174.     $this->id_arr[$cnt][1$content;
  175.   }
  176.  
  177.  
  178.  
  179.   /**
  180.     * Returns a generated string based on the attributes of this HTML-Object.
  181.     *
  182.     * @version 1.0
  183.     * @since   1.0
  184.     * @author  Daniel Plücken <daniel@debakel.net>
  185.     * @access  public
  186.     * @return  string 
  187.     */
  188.   function get()
  189.   {
  190.     $out  "<style type=\"text/css\"".(
  191.                 !empty$this->str_media )
  192.                 ? " media=\"{$this->str_media}\""
  193.                 : ""
  194.                                        ).">\r\n";
  195.  
  196.     for( $i = 0; $i < count( $this->cls_arr )$i++ )
  197.     {
  198.       $out .= "\r\n.".$this->cls_arr[$i][0]."\r\n";
  199.       $out .= "{\r\n";
  200.       $out .= PlainTextFormatter::indentText$this->cls_arr[$i][1])."\r\n";
  201.       $out .= "}\r\n";
  202.     }
  203.  
  204.     for( $i = 0; $i < count( $this->id_arr )$i++ )
  205.     {
  206.       $out .= "\r\n#".$this->id_arr[$i][0]."\r\n";
  207.       $out .= "{\r\n";
  208.       $out .= PlainTextFormatter::indentText$this->id_arr[$i][1])."\r\n";
  209.       $out .= "}\r\n";
  210.     }
  211.  
  212.     for( $i = 0; $i < count( $this->tag_arr )$i++ )
  213.     {
  214.       $out .= "\r\n".$this->tag_arr[$i][0]."\r\n";
  215.       $out .= "{\r\n";
  216.       $out .= PlainTextFormatter::indentText$this->tag_arr[$i][1])
  217.              ."\r\n";
  218.       $out .= "}\r\n";
  219.     }
  220.  
  221.     $out .= "</style>\r\n";
  222.  
  223.     return $out;
  224.   }
  225. } // END of Stylesheet

Documentation generated on Thu, 05 Jun 2008 19:15:10 +0200 by phpDocumentor 1.4.1