Source for file CMS_CSSSTYLE.phpclass

Documentation is available at CMS_CSSSTYLE.phpclass

  1. <?php
  2. /**
  3.   * Class file CMS_CSSSTYLE.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   * @categorie  css
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. pcf_require_class('CMS_TABLEOBJ',__OCSP_PHPINCPATH__ "cms/CMS_TABLEOBJ.phpclass");
  16.  
  17.  
  18. /**
  19.   * handels CSS Style Files
  20.   *
  21.   * @project    Open CSP-Management
  22.   * @package    cms
  23.   * @categorie  css
  24.   *
  25.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  26.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  27.   *
  28.   * @since      pk-03-12-16
  29.   * @verision   pk-03-12-16
  30.   *
  31.   *
  32.   ***/
  33. class CMS_CSSSTYLE  extends CMS_TABLEOBJ{
  34.     /**
  35.       * @staticvar string $myTable name of the db table
  36.       ***/
  37.     var $myTable="T_CMS_CSSSTYLES";
  38.  
  39.     /**
  40.       * @staticvar string $myClassSrcFile if is set the DBMS_FORM get the class object
  41.       * @since pk-06-09-08
  42.       ***/
  43.     var $myClassSrcFile=__FILE__;
  44.  
  45.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  46.     /**
  47.       * @staticvar string $myCSSClassTbl 
  48.       * @since pk-06-09-08
  49.       ***/
  50.     var $myCSSClassTbl="T_CMS_CSSCLASS";
  51.  
  52.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  53.     /*      cunstructor methods                                                     */
  54.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  55.  
  56.     /**
  57.       * init the object and populates the object if aId
  58.       *
  59.       * if $aId is set the object is populated with the id
  60.       * if $name is set and $aId is not set the object is populated
  61.       *     by calling $this::populateFromName()
  62.       *
  63.       * returns if populate found a row in the database
  64.       *
  65.       * @param int      $aId id of an existing template
  66.       * @param string   $name 
  67.       * @param int      $projId 
  68.       * @param string   $gDBIDX   GLOBALS database Object index
  69.       * @param bool     $debug 
  70.       *
  71.       ***/
  72.     function CMS_CSSSTYLE($id=0,$name="",$projId=0,$debug=FALSE)
  73.     {
  74.         if ($debugechoDebugMethod(__FILE__,get_class($this)."CMS_CSSSTYLE::CMS_CSSSTYLE()");
  75.         $this->init($debug);
  76.         if (intval($projId))
  77.         {
  78.             $this->setProjId(intval($projId));
  79.         }
  80.         if (intval($id))
  81.         {
  82.             $this->STY_ID $id;
  83.             $this->dbPopulate();
  84.         else if (!empty($name)) {
  85.             $this->STY_NAME=$name;
  86.             $this->populateFromName($name,$gDBIDX,$debug);
  87.         }
  88.     }
  89.  
  90.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  91.     /*      object var methods                                                      */
  92.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  93.  
  94.     /**
  95.       * returns the id
  96.       *
  97.       * @return int 
  98.       *
  99.       * @since pk-06-09-08
  100.       *
  101.       ***/
  102.     function getId()
  103.     {
  104.         return intval($this->getDBField('STY_ID'));
  105.     }
  106.  
  107.     /**
  108.       * returns the name of the style
  109.       *
  110.       * @return string 
  111.       *
  112.       * @since pk-06-09-08
  113.       *
  114.       ***/
  115.     function getName()
  116.     {
  117.         return $this->getDBField('STY_NAME');
  118.     }
  119.  
  120.     /**
  121.       * @return string 
  122.       * @access public
  123.       *
  124.       * @since pk-07-06-08
  125.       */
  126.     function getIncludeFile()
  127.     {
  128.         return $this->getDBField('STY_INCLUDEFILE');
  129.     }
  130.  
  131.     /**
  132.       * returns the javascript code for the style
  133.       *
  134.       * @param boolean $debug 
  135.       *
  136.       * @returns string
  137.       * @since pk-07-03-27
  138.       *
  139.       * @access public
  140.       */
  141.     function getJSCode($debug=FALSE)
  142.     {
  143.         if ($debugechoDebugMethod(__FILE__,get_class($this),__CLASS__."::getJSCode()");
  144.         return $this->getDBField('STY_JAVACODE');
  145.     }
  146.  
  147.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  148.     /*      Database methods                                                        */
  149.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  150.  
  151.     /**
  152.       * populates the object form the unique key STY_NAME
  153.       *
  154.       * @param string   $name 
  155.       * @param string   $gDBIDX   GLOBALS database Object index
  156.       * @param bool     $debug 
  157.       *
  158.       * @return mixed (int) $this->getId() or FALSE
  159.       *
  160.       * @version pk-07-08-18
  161.       *
  162.       ***/
  163.     function populateFromName($name,$debug=FALSE)
  164.     {
  165.         if ($debugechoDebugMethod(__FILE__,pcf_object_id($this),"CMS_CSSSTYLE::populateFromName($name");
  166.         
  167.         if (empty($name))
  168.         {
  169.             ocsp_logError(__FILE__,__LINE__,"no name submitted",E_WARNING);
  170.             return FALSE;
  171.         }
  172.         
  173.         if (!$this->isConnected(TRUE,$debug))
  174.         {
  175.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  176.             die();
  177.         }
  178.         
  179.         $str_query=$query="SELECT * FROM ".$this->myTable." WHERE STY_NAME=".$this->myDBObj->qs_getSlashedValue($name);
  180.         
  181.         if ($arr_row=$this->myDBObj->quickQuery($str_query))
  182.         {
  183.             $this->setDBRow($arr_row,TRUE,$debug);
  184.             return $this->getId();
  185.         }
  186.         return FALSE;
  187.     }
  188.     
  189.     /**
  190.       * updates the database and clears the cache
  191.       *
  192.       * @param boolean $debug 
  193.       * @param boolean $ignorPopulated (if false the table MUST have been populated)
  194.       *
  195.       * @return int 
  196.       *
  197.       * @since pk-07-08-18
  198.       */
  199.     function dbReplace($debug=FALSE,$ignorPopulated=FALSE)
  200.     {
  201.         if ($debugechoDebugMethod(__FILE__,pcf_object_id($this),"CMS_CSSSTYLE::dbReplace()");
  202.         $this->clearStyleCache($this->getId(),$debug);
  203.         return parent::dbReplace($debug,$ignorPopulated);
  204.     }
  205.     
  206.  
  207.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  208.     /*      cache methods                                                       */
  209.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  210.  
  211.     /**
  212.       * clears the style cache
  213.       *
  214.       * @param int $aId (to enable static cals if not called static $this->getId() is used)
  215.       * @param boolean $debug 
  216.       *
  217.       * @since pk-06-09-08
  218.       * @version pk-07-08-18
  219.       *
  220.       ***/
  221.     function clearStyleCache($aId=0,$debug)
  222.     {
  223.         if ($debugechoDebugMethod(__FILE__,pcf_object_id($this),"CMS_CSSSTYLE::clearStyleCache($aId)");
  224.         
  225.         if (pcf_is_instance_of($this,'CMS_CSSSTYLE')) // no static call
  226.         {
  227.             $aId=$this->getId();
  228.         }
  229.         
  230.         if (method_exists($this,'getProjId'))
  231.         {
  232.             $int_projId=$this->getProjId();
  233.         else {
  234.             $int_projId=0;
  235.         }
  236.     
  237.         if (isset($GLOBALS['PROJECT']['WEBCACHEPATH'])) {
  238.             $cachFile=$GLOBALS['PROJECT']['WEBCACHEPATH']."styles/0-default.css"// default
  239.             @unlink($cachFile);
  240.             $cachFile=$GLOBALS['PROJECT']['WEBCACHEPATH']."styles/".$aId."-default.css"// project default
  241.             @unlink($cachFile);
  242.             $cachFile=$GLOBALS['PROJECT']['WEBCACHEPATH']."styles/".$int_projId."-id-".$aId.".css";
  243.             @unlink($cachFile);
  244.         }
  245.     }
  246.  
  247.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  248.     /*      class methods                                                       */
  249.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  250.  
  251.     /**
  252.       * resorts the classes of the style
  253.       *
  254.       * @param boolean $debug 
  255.       *
  256.       * @since pk-06-09-08
  257.       * @version pk-07-08-09
  258.       *
  259.       ***/
  260.     function resortClasses($debug=FALSE)
  261.     {
  262.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSSTYLE::resortClasses()");
  263.  
  264.         if (!$this->isConnected(TRUE,$debug))
  265.         {
  266.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  267.             die();
  268.         }
  269.  
  270.         $i_projId=0;$i_ordNr =1;
  271.         $s_query ="SELECT * FROM ".$this->myCSSClassTbl." WHERE STY_ID=".$this->getId();
  272.         $s_query.=" ORDER BY PROJ_ID,CSS_ORDERNR";
  273.         if ($o_cursor=$this->myDBObj->query($s_query)) {
  274.             $b_changed=FALSE;
  275.             while($a_row=$o_cursor->fetchArrayFld()) {
  276.                 if (intval($a_row['PROJ_ID']!= $i_projId{
  277.                     $i_ordNr=1;$i_projId=intval($a_row['PROJ_ID']);
  278.                 }
  279.                 if (intval($a_row['CSS_ORDERNR']!= $i_ordNr)
  280.                 {
  281.                     $a_row['CSS_ORDERNR']       =$i_ordNr;
  282.                     $a_row['CSS_LASTCHANGE']    =$this->myDBObj->qs_getNowStmt();
  283.                     $this->myDBObj->replaceArray($this->myCSSClassTbl,$a_row);
  284.                     $b_changed=TRUE;
  285.                 }
  286.                 $i_ordNr++;
  287.             }
  288.             if ($b_changed$this->clearStyleCache();
  289.         else {
  290.             if ($debugechoDebug(__FILE__,"ERROR in Query$s_query");
  291.         }
  292.     }
  293.  
  294.     /**
  295.       * returns the css code for the style
  296.       *
  297.       * @param string $media 
  298.       * @param int $projId 
  299.       * @param boolean $debug 
  300.       *
  301.       * @since pk-07-01-09
  302.       * @version pk-07-03-28
  303.       *
  304.       ***/
  305.     function getCSSCode($media="",$projId=-1,$debug=FALSE)
  306.     {
  307.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSSTYLE::getCSSCode()");
  308.  
  309.         if (!$this->isConnected(TRUE,$debug))
  310.         {
  311.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  312.             die();
  313.         }
  314.  
  315.         $s_ret="";
  316.  
  317.         $s_cssTxtCode=$this->getDBField('STY_TEXT');
  318.         if (!empty($s_cssTxtCode))
  319.         {
  320.             $s_ret.="/* __STY_TEXT__START__ */\n".$s_cssTxtCode."\n/* __STY_TEXT__END__ */\n";
  321.         }
  322.  
  323.         $s_query ="SELECT * FROM ".$this->myCSSClassTbl;
  324.         $s_query.=" WHERE STY_ID=".$this->getId();
  325.         if (!empty($media&& (strtoupper($media!= "ALL"))
  326.         {
  327.              $s_query.=" AND CSS_MEDIA=".$this->myDBObj->qs_getSlashedValue($media);
  328.         }
  329.  
  330.         if ($projId > -1)
  331.         {
  332.             $s_query.=" AND PROJ_ID=".intval($projId);
  333.         }
  334.  
  335.         $s_query.=" ORDER BY CSS_ORDERNR,CSS_MEDIA";
  336.         if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Query$s_query</p>");
  337.  
  338.         if ($o_cssCursor=$this->myDBObj->query($s_query))
  339.         {
  340.             $s_aktMedia="";$b_mediaOpen=FALSE;
  341.             while($a_css=$o_cssCursor->fetchArrayFld())
  342.             {
  343.                 if (empty($a_css['CSS_MEDIA'])) $a_css['CSS_MEDIA']="all"// ensure all is set
  344.                 if ($a_css['CSS_MEDIA'!= $s_aktMedia)
  345.                 {
  346.                     if ($b_mediaOpen)  // close it
  347.                     {
  348.                         $s_ret.="}\n";
  349.                     }
  350.  
  351.                     $s_aktMedia=$a_css['CSS_MEDIA'];
  352.                     $s_ret.="@media ".$s_aktMedia." {\n";
  353.                     $b_mediaOpen=TRUE;
  354.                 }
  355.                 $s_ret.="\t".trim($a_css['CSS_NAME'])." {\n";
  356.                 $s_def=str_replace("\n","",str_replace("\r","",$a_css['CSS_DEFINITION']));
  357.                 $a_defLines=explode(";",$s_def);
  358.                 foreach($a_defLines as $s_line)
  359.                 {
  360.                     $s_line=trim($s_line);
  361.                     if (!empty($s_line)) $s_ret.="\t\t".trim($s_line).";\n";
  362.                 }
  363.                 $s_ret.="\t}\n";
  364.             }
  365.             if ($b_mediaOpen)
  366.             {
  367.                 $s_ret.="}\n";
  368.             }
  369.         }
  370.  
  371.  
  372.         return $s_ret;
  373.     }
  374.  
  375.     /**
  376.       * returns an array with the css definitinons
  377.       *
  378.       * @param boolean $debug 
  379.       *
  380.       * @return array 
  381.       * @access public
  382.       *
  383.       * @since pk-07-06-08
  384.       */
  385.     function getCssClassArray($debug=FALSE)
  386.     {
  387.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSSTYLE::getCssClassArray()");
  388.  
  389.         if (!$this->isConnected(TRUE,$debug))
  390.         {
  391.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  392.             die();
  393.         }
  394.  
  395.         $arr_ret=array();
  396.  
  397.         $s_query ="SELECT * FROM ".$this->myCSSClassTbl;
  398.         $s_query.=" WHERE STY_ID=".$this->getId();
  399.         $s_query.=" ORDER BY CSS_ORDERNR,CSS_MEDIA";
  400.  
  401.         if ($obj_cursor=$this->myDBObj->query($s_query))
  402.         {
  403.             while($arr_Row=$obj_cursor->fetchArrayFld())
  404.             {
  405.                 if ($arr_tmp=explode(";",$arr_Row['CSS_DEFINITION']))
  406.                 {
  407.                     $str_def="";$c_sep="";
  408.                     foreach($arr_tmp as $str_line)
  409.                     {
  410.                         $str_def.=$c_sep.trim($str_line);
  411.                         $c_sep=";";
  412.                     }
  413.                     $arr_ret[]=array(
  414.                         'CSS_NAME'      => $arr_Row['CSS_NAME'],
  415.                         'CSS_BROWSER'   => $arr_Row['CSS_BROWSER'],
  416.                         'CSS_MEDIA'     => $arr_Row['CSS_MEDIA'],
  417.                         'PROJ_ID'       => $arr_Row['PROJ_ID'],
  418.                         'CSS_DEFINITION'=> $str_def
  419.                     );
  420.  
  421.                 }
  422.             }
  423.         }
  424.         return $arr_ret;
  425.     }
  426. }
  427. ?>

Documentation generated on Thu, 08 Jan 2009 17:38:48 +0100 by phpDocumentor 1.4.0a2