Source for file OCSP_CMS_PEARCACHE.phpclass

Documentation is available at OCSP_CMS_PEARCACHE.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_CMS_PEARCACHE.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   *
  8.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-07-06-07
  12.   *
  13.   * @requires Cache/Lite.php           [PEAR]
  14.   *
  15.   * @uses _OCSP_PEARPATH_
  16.   *
  17.   * @see http://pear.php.net/manual/en/package.caching.cache-lite.php
  18.   ***/
  19.  
  20. /**
  21.   * ---------------------------------------------------
  22.   *
  23.   * common settings and requirements
  24.   *
  25.   */
  26.  
  27.     if (!defined('_OCSP_PEARPATH_'))
  28.     {
  29.         define('_OCSP_PEARPATH_','')// pear is in the include path
  30.     }
  31.  
  32.     require_once _OCSP_PEARPATH_."Cache/Lite.php";
  33.  
  34. /**
  35.   * Class OCSP_CMS_PEARCACHE.phpclass
  36.   *
  37.   * @project    Open CSP-Management
  38.   * @package    cms
  39.   *
  40.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  41.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  42.   *
  43.   * @since pk-07-06-07
  44.   *
  45.   * @requires Cache/Lite.php           [PEAR]
  46.   *
  47.   * @uses $GLOBALS['OCSP']['OBJCACHEPATH']
  48.   *
  49.   * @see http://pear.php.net/manual/en/package.caching.cache-lite.php
  50.   *
  51.   *
  52.   */
  53.     /** -----------------------------------------------------
  54.       * Aggregations:
  55.       */
  56.  
  57.  
  58.     /** -----------------------------------------------------
  59.       * Compositions:
  60.       */
  61.  
  62.     /**
  63.       * @var array $projCachArr 
  64.       * @access protected
  65.       */
  66.     protected $projCachArr = array();
  67.  
  68.     /**
  69.       * @var Cache_Lite $myMenuCache 
  70.       * @access protected
  71.       */
  72.     protected $myMenuCache=NULL;
  73.  
  74.     /**
  75.       * @var Cache_Lite $myPageCache 
  76.       * @acces protected
  77.       */
  78.     protected $myPageCache=NULL;
  79.  
  80.     /** -----------------------------------------------------
  81.       * Attributes:
  82.       */
  83.  
  84.     /**
  85.       * @var string $rootPath 
  86.       * @access protected
  87.       */
  88.     protected $rootPath = "";
  89.  
  90.     /**
  91.       * @var int $ttl 
  92.       * @access protectd
  93.       */
  94.     protected $ttl = 604800// one week
  95.  
  96.  
  97.  
  98.  
  99.     /**
  100.       * index of the menu tree in $GLOBALS['OCSP_VAL']['DBMS_TREE']
  101.       * @var string $menuTreeIndex 
  102.       * @access protected
  103.       */
  104.     protected $menuTreeIndex="";
  105.  
  106.     /**
  107.       * @var array $menNodeValsLoaded ([$menuTreeIndex]=TRUE/FALSE)
  108.       * @access protected
  109.       */
  110.     protected $menNodeValsLoaded=array();
  111.  
  112.     /**
  113.       *
  114.       * METHODS _____________________________________________
  115.       *
  116.       */
  117.  
  118.     /** -----------------------------------------------------
  119.       * Constructors
  120.       */
  121.     function OCSP_CMS_PEARCACHE()
  122.     {
  123.         $this->rootPath=$GLOBALS['OCSP']['CACHEPATH']."cms"._OCSP_DIRSEP_;
  124.         if (!isset($GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE']))
  125.         {
  126.             $GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE']=&$this;
  127.         }
  128.     }
  129.  
  130.     /** -----------------------------------------------------
  131.       * getter & setter methods
  132.       */
  133.  
  134.     /**
  135.       * @return string 
  136.       */
  137.     function getRootPath()
  138.     {
  139.         if (pcf_is_instance_of($this,'OCSP_CMS_PEARCACHE'&& !empty($this->rootPath))
  140.         {
  141.             return $this->rootPath;
  142.         }
  143.  
  144.         return $GLOBALS['OCSP']['CACHEPATH']."cms"._OCSP_DIRSEP_;
  145.     }
  146.  
  147.     /**
  148.       *
  149.       * project cache methods
  150.       *
  151.       */
  152.  
  153.     /**
  154.       * @param int $projId 
  155.       * @param boolean $chkDir 
  156.       * @param boolean $debug 
  157.       *
  158.       * @return Cache_Lite 
  159.       * @access public
  160.       *
  161.       * @requires $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_directory.phpinc";
  162.       *
  163.       */
  164.     function &getProjCacheObj($projId,$chkDir=FALSE,$debug=FALSE)
  165.     {
  166.         //if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getProjCacheObj($projId)");
  167.  
  168.         if (isset($this->projCachArr[$projId]&& pcf_is_instance_of($this->projCachArr[$projId],'Cache_Lite'))
  169.         {
  170.             return $this->projCachArr[$projId];
  171.         }
  172.  
  173.         $arr_option=array(
  174.             'cacheDir'                  => $this->getRootPath()."PROJ_".$projId."/",
  175.             'automaticSerialization'    => TRUE,
  176.             'lifeTime'                  => $this->ttl,
  177.             'fileNameProtection'        => FALSE
  178.         );
  179.         if ($chkDir)
  180.         {
  181.             require_once $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_directory.phpinc";
  182.             if (!pcf_checkDir($arr_option['cacheDir'],TRUE,0700,$debug))
  183.             {
  184.                 $null_ret=NULL;
  185.                 return $null_ret;
  186.             }
  187.         }
  188.         $this->projCachArr[$projId]=new Cache_Lite($arr_option);
  189.         return $this->projCachArr[$projId];
  190.     }
  191.  
  192.     /**
  193.       * gets a projects database values from the cache
  194.       *
  195.       * @param int $projId 
  196.       * @param boolean $debug 
  197.       *
  198.       * @return array 
  199.       */
  200.     function getProjDBValues($projId,$debug=FALSE)
  201.     {
  202.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getProjDBValues($projId)");
  203.         $obj_cache=$this->getProjCacheObj($projId,TRUE,$debug);
  204.         return $obj_cache->get('PROJDBVAL');
  205.     }
  206.  
  207.     /**
  208.       * stores a projects database values to the cache
  209.       *
  210.       * @param CMS_PROJECT $aProj 
  211.       * @param boolean $debug 
  212.       */
  213.     function setProjDBValues($aProj,$debug=FALSE)
  214.     {
  215.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setProjDBValues(".$aProj->getId().")");
  216.         if ($obj_cache=$this->getProjCacheObj($aProj->getId(),TRUE,$debug))
  217.         {
  218.             $arr_projVals=$aProj->getDBVal();
  219.             $arr_projVals['PEARCACHE_TS']=time();
  220.             if (!$obj_cache->save($arr_projVals,'PROJDBVAL'))
  221.             {
  222.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Error Saving Cache</p><pre>".print_r($obj_cache,TRUE)."</pre>");
  223.             }
  224.         }
  225.     }
  226.  
  227.     /**
  228.       * clears the cache by removing the cache directory
  229.       *
  230.       * @param CMS_PROJECT $aProject 
  231.       * @param boolean $debug 
  232.       * @access public
  233.       */
  234.     function cleanProject($aProject,$debug=FALSE)
  235.     {
  236.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::cleanProject(".$aProject->getId().")");
  237.         $obj_cache=$this->getProjCacheObj($aProject->getId(),FALSE,$debug);
  238.         $obj_cache->clean();
  239.     }
  240.  
  241.     /**
  242.       *
  243.       * menu cache methods
  244.       *
  245.       */
  246.  
  247.     /**
  248.       * @param boolean $chkDir (if true the existens of page cache dir is checked)
  249.       * @param boolean $debug 
  250.       *
  251.       * @return array 
  252.       */
  253.     function getMenuCacheOptions($chkDir=FALSE,$debug=FALSE)
  254.     {
  255.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getMenuCacheOptions()");
  256.  
  257.  
  258.         $arr_option=array(
  259.             'cacheDir'                  => $this->getRootPath()."menu"._OCSP_DIRSEP_,
  260.             'automaticSerialization'    => TRUE,
  261.             'lifeTime'                  => $this->ttl,
  262.             'fileNameProtection'        => FALSE
  263.         );
  264.  
  265.         if ($chkDir)
  266.         {
  267.             require_once $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_directory.phpinc";
  268.             if (!pcf_checkDir($arr_option['cacheDir'],TRUE,0700,$debug))
  269.             {
  270.                 ocsp_logError(__FILE__,__LINE__,"check dir ".$arr_option['cacheDir']." failed");
  271.             }
  272.         }
  273.         return $arr_option;
  274.     }
  275.  
  276.     /**
  277.       * @param boolean $chkDir 
  278.       * @param boolean $debug 
  279.       */
  280.     function &getMenuCacheObj($chkDir=FALSE,$debug=FALSE)
  281.     {
  282.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getMenuCacheObj()");
  283.  
  284.         if (!pcf_is_instance_of($this->myMenuCache,'Cache_Lite'))
  285.         {
  286.             $this->myMenuCache=new Cache_Lite($this->getMenuCacheOptions($chkDir,$debug));
  287.         else if ($chkDir{
  288.             $this->getMenuCacheOptions($chkDir,$debug);
  289.         }
  290.         return $this->myMenuCache;
  291.     }
  292.  
  293.     /**
  294.       * returns an array with all data for a menu node
  295.       *
  296.       * <code>
  297.       * array(
  298.       *     'MENVAL' => CMS_MENU_NODE->getDBVal(),
  299.       *     'PROJVAL'=> CMS_PROJECT->getDBVal()
  300.       * )
  301.       * </code>
  302.       *
  303.       * @param int $pag_id 
  304.       * @param boolean $debug 
  305.       *
  306.       * @return mixed array or false if cache failed
  307.       */
  308.     function getMenuData($aId,$debug=FALSE)
  309.     {
  310.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getMenuData($aId)");
  311.  
  312.         if (!intval($aId)) {
  313.             if ($debugechoDebugLine(__FILE__,__LINE__,"no id set");
  314.             return FALSE;
  315.         }
  316.  
  317.         $this->getMenuCacheObj(FALSE,$debug)// ensure $this->myPageCache is set
  318.         return $this->myMenuCache->get('MENU_'.intval($aId));
  319.     }
  320.  
  321.     /**
  322.       * returns an array with page values
  323.       *
  324.       * @param int $aId 
  325.       * @param boolean $debug 
  326.       *
  327.       * @return mixed array of false if cache failed
  328.       */
  329.     function getMenuVal($aId,$debug=FALSE)
  330.     {
  331.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getMenuVal($aId)");
  332.         if ($arr_cache=$this->getMenuData($aId,$debug))
  333.         {
  334.             if (isset($arr_cache['MENVAL']&& is_array($arr_cache['MENVAL']))
  335.             {
  336.                 return $arr_cache['MENVAL'];
  337.             else {
  338.                 return FALSE;
  339.             }
  340.         else {
  341.             return FALSE;
  342.         }
  343.     }
  344.  
  345.     /**
  346.       * sets page cache values
  347.       *
  348.       * @param CMS_PAGE_V2 $aPage 
  349.       * @param boolean $debug 
  350.       *
  351.       * @return boolean 
  352.       *
  353.       */
  354.     function setMenuData(&$aNode,$debug=FALSE)
  355.     {
  356.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setMenuData()");
  357.  
  358.         if (!pcf_is_instance_of($aNode,'CMS_MENU_NODE')) return FALSE;
  359.  
  360.         $this->getMenuCacheObj(TRUE,$debug)// ensure $this->myMenuCache is set and the directory exists
  361.  
  362.         $arr_cache['MENVAL']=$aNode->getDBVal();
  363.         $arr_cache['MENVAL']['PEARCACHE_TS']=$aNode->getPopulateTs();
  364.         $arr_cache['MENVAL']['CMS_MENU_TREE_KEY']=$aNode->getGlobalTreeKey();
  365.  
  366.         if ($obj_proj=$aNode->getMyProject($debug))
  367.         {
  368.             $arr_cache['PROJVAL']=$obj_proj->getDBVal();
  369.             $arr_cache['PROJVAL']['PEARCACHE_TS']=$obj_proj->getPopulateTs();
  370.         }
  371.  
  372.         if (!$this->myMenuCache->save($arr_cache,'MENU_'.$aNode->getId()))
  373.         {
  374.             ocsp_logError(__FILE__,__LINE__,"error cacheing page data");
  375.         else {
  376.             return TRUE;
  377.         }
  378.     }
  379.  
  380.     /**
  381.       * @param mixed $aId (int) menu id or (string) PROJ_$*PROJ_ID$ for project root pages
  382.       * @param boolean $debug 
  383.       *
  384.       * @return array 
  385.       */
  386.     function getMenuPageListVal($aId,$debug=FALSE)
  387.     {
  388.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getMenuPageListVal($aId)");
  389.  
  390.         if (empty($aId)) {
  391.             if ($debugechoDebugLine(__FILE__,__LINE__,"no id set");
  392.             return FALSE;
  393.         }
  394.  
  395.         $this->getMenuCacheObj(FALSE,$debug)// ensure $this->myMenuCache is set
  396.         return $this->myMenuCache->get('PAGLSTVAL_'.$aId);
  397.     }
  398.  
  399.     /**
  400.       * @param mixed $aId (int) menu id or (string) PROJ_$*PROJ_ID$ for project root pages
  401.       * @param boolean $debug 
  402.       *
  403.       * @return array 
  404.       */
  405.     function setMenuPageListVal($aId,$arr_cache,$debug=FALSE)
  406.     {
  407.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setMenuPageListVal($aId)");
  408.  
  409.         if (empty($aId)) {
  410.             ocsp_logError(__FILE__,__LINE__,"error cacheing page data",E_WARNING);
  411.             return FALSE;
  412.         }
  413.  
  414.         $this->getMenuCacheObj(TRUE,$debug)// ensure $this->myMenuCache is set
  415.  
  416.         $arr_cache['PEARCACHE_TS']=time();
  417.  
  418.         if (!$this->myMenuCache->save($arr_cache,'PAGLSTVAL_'.$aId))
  419.         {
  420.             ocsp_logError(__FILE__,__LINE__,"error cacheing page data",E_WARNING);
  421.             return FALSE;
  422.         else {
  423.             return TRUE;
  424.         }
  425.     }
  426.  
  427.  
  428.     /**
  429.       *
  430.       * page cache methods
  431.       *
  432.       */
  433.  
  434.     /**
  435.       * @param boolean $chkDir (if true the existens of page cache dir is checked)
  436.       * @param boolean $debug 
  437.       *
  438.       * @return array 
  439.       */
  440.     function getPageCacheOptions($chkDir=FALSE,$debug=FALSE)
  441.     {
  442.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getPageCacheOptions()");
  443.  
  444.  
  445.         $arr_option=array(
  446.             'cacheDir'                  => $this->getRootPath()."page"._OCSP_DIRSEP_,
  447.             'automaticSerialization'    => TRUE,
  448.             'lifeTime'                  => $this->ttl,
  449.             'fileNameProtection'        => FALSE
  450.         );
  451.  
  452.         if ($chkDir)
  453.         {
  454.             require_once $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_directory.phpinc";
  455.             if (!pcf_checkDir($arr_option['cacheDir'],TRUE,0700,$debug))
  456.             {
  457.                 ocsp_logError(__FILE__,__LINE__,"check dir ".$arr_option['cacheDir']." failed");
  458.             }
  459.         }
  460.         return $arr_option;
  461.     }
  462.  
  463.     /**
  464.       * @param boolean $chkDir 
  465.       * @param boolean $debug 
  466.       */
  467.     function &getPageCacheObj($chkDir=FALSE,$debug=FALSE)
  468.     {
  469.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getPageCacheObj()");
  470.  
  471.         if (!pcf_is_instance_of($this->myPageCache,'Cache_Lite'))
  472.         {
  473.             $this->myPageCache=new Cache_Lite($this->getPageCacheOptions($chkDir,$debug));
  474.         else if ($chkDir{
  475.             $this->getPageCacheOptions($chkDir,$debug);
  476.         }
  477.         return $this->myPageCache;
  478.     }
  479.  
  480.     /**
  481.       * returns an array with all data for a page
  482.       *
  483.       * <code>
  484.       * array(
  485.       *     'PAGVAL' => CMS_PAGE_V2->getDBVal(),
  486.       *     'MENVAL' => CMS_MENU_NODE->getDBVal(),
  487.       *     'PROJVAL'=> CMS_PROJECT->getDBVal()
  488.       * )
  489.       * </code>
  490.       *
  491.       * @param int $pag_id 
  492.       * @param boolean $debug 
  493.       *
  494.       * @return mixed array or false if cache failed
  495.       */
  496.     function getPageData($aId,$debug=FALSE)
  497.     {
  498.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getPageData($aId)");
  499.  
  500.         if (!intval($aId)) {
  501.             if ($debugechoDebugLine(__FILE__,__LINE__,"no id set");
  502.             return FALSE;
  503.         }
  504.  
  505.         $this->getPageCacheObj(FALSE,$debug)// ensure $this->myPageCache is set
  506.         return $this->myPageCache->get('PAGE_'.intval($aId));
  507.     }
  508.  
  509.     /**
  510.       * returns an array with page values
  511.       *
  512.       * @param int $aId 
  513.       * @param boolean $debug 
  514.       *
  515.       * @return mixed array of false if cache failed
  516.       */
  517.     function getPageVal($aId,$debug=FALSE)
  518.     {
  519.         if ($debugechoDebugMethod(__FILE__,__LINE__,get_class($this),"OCSP_CMS_PEARCACHE::getPageVal($aId)");
  520.         if ($arr_cache=$this->getPageData($aId,$debug))
  521.         {
  522.             if (isset($arr_cache['PAGVAL']&& is_array($arr_cache['PAGVAL']))
  523.             {
  524.                 return $arr_cache['PAGVAL'];
  525.             else {
  526.                 return FALSE;
  527.             }
  528.         else {
  529.             return FALSE;
  530.         }
  531.     }
  532.  
  533.     /**
  534.       * sets page cache values
  535.       *
  536.       * @param CMS_PAGE_V2 $aPage 
  537.       * @param boolean $debug 
  538.       *
  539.       * @return boolean 
  540.       *
  541.       */
  542.     function setPageData(&$aPage,$debug=FALSE)
  543.     {
  544.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setPageDate()");
  545.  
  546.         if (!pcf_is_instance_of($aPage,'CMS_PAGE_V2')) return FALSE;
  547.         if (!intval($aPage->getId())) return FALSE;
  548.  
  549.         $this->getPageCacheObj(TRUE,$debug)// ensure $this->myPageCache is set and the directory exists
  550.  
  551.         $arr_cache['PAGVAL']=$aPage->getDBVal();
  552.         $arr_cache['PAGVAL']['PEARCACHE_TS']=$aPage->getPopulateTs();
  553.         if ($obj_menu=$aPage->getMyMenuNode($debug))
  554.         {
  555.             $arr_cache['MENVAL']=$obj_menu->getDBVal();
  556.             $arr_cache['MENVAL']['PEARCACHE_TS']=$obj_menu->getPopulateTs();
  557.         }
  558.         if ($obj_proj=$aPage->getMyProject($debug))
  559.         {
  560.             $arr_cache['PROJVAL']=$obj_proj->getDBVal();
  561.             $arr_cache['PROJVAL']['PEARCACHE_TS']=$obj_proj->getPopulateTs();
  562.         }
  563.  
  564.         if (!$this->myPageCache->save($arr_cache,'PAGE_'.$aPage->getId()))
  565.         {
  566.             ocsp_logError(__FILE__,__LINE__,"error cacheing page data");
  567.         else {
  568.             return TRUE;
  569.         }
  570.     }
  571.  
  572.  
  573.  
  574.  
  575.  
  576. // ----------------------------------------------------------------------------
  577. // ----------------------------------------------------------------------------
  578. // ----------------------------------------------------------------------------
  579. // ----------------------------------------------------------------------------
  580. // ----------------------------------------------------------------------------
  581. // ----------------------------------------------------------------------------
  582. // ----------------------------------------------------------------------------
  583. // ----------------------------------------------------------------------------
  584. // ----------------------------------------------------------------------------
  585. // ----------------------------------------------------------------------------
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.     /**
  596.       *
  597.       * project cache methods
  598.       *
  599.       */
  600.  
  601.     /** -----------------------------------------------------
  602.       * project object values
  603.       */
  604.  
  605.  
  606.  
  607.     /** -----------------------------------------------------
  608.       * ProjIdFromHTTP_HOST
  609.       */
  610.  
  611.     /**
  612.       * @param boolean $debug 
  613.       * @return int 
  614.       * @access public
  615.       */
  616.     function getProjIdFromHTTP_HOST($debug=FALSE)
  617.     {
  618.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getProjIdFromHTTP_HOST()",$_SERVER['HTTP_HOST']);
  619.         $arr_option=array(
  620.             'cacheDir'                  => $this->getRootPath(),
  621.             'automaticSerialization'    => TRUE,
  622.             'lifeTime'                  => $this->ttl,
  623.             'fileNameProtection'        => FALSE
  624.         );
  625.  
  626.         $obj_cache=new Cache_Lite($arr_option);
  627.         if ($arr_prjData=$obj_cache->get('PROJLST'))
  628.         {
  629.             if (isset($arr_prjData[strtoupper($_SERVER['HTTP_HOST'])]['PROJ_ID']))
  630.             {
  631.                 if ($debugechoDebugLine(__FILE__,__LINE__,"CacheHit: ".intval($arr_prjData[$_SERVER['HTTP_HOST']]['PROJ_ID']));
  632.                 return intval($arr_prjData[$_SERVER['HTTP_HOST']]['PROJ_ID']);
  633.             }
  634.             if (is_array($arr_prjData))
  635.             {
  636.                 foreach($arr_prjData as $host => $arr_vals)
  637.                 {
  638.                     if (!empty($arr_vals['PROJ_URLREGEX']&& ($a_regExpNames=explode("\n",str_replace("\r","",$arr_vals['PROJ_URLREGEX']))))
  639.                     {
  640.                         if ($arr_vals['PROJ_URL']==strtoupper($_SERVER['SERVER_NAME']))
  641.                         {
  642.                             if ($debugechoDebugLine(__FILE__,__LINE__,"CacheHit SERVER_NAME: ".intval($arr_vals['PROJ_ID']));
  643.                             return intval($arr_vals['PROJ_ID']);
  644.                         }
  645.                         // we have regular expressions to check
  646.                         foreach($a_regExpNames as $s_pattern)
  647.                         {
  648.                             $s_pattern=trim($s_pattern);
  649.                             if ((!empty($s_pattern)) && (@preg_match($s_pattern,$_SERVER['SERVER_NAME'])))
  650.                             {
  651.                                 if ($debugechoDebugLine(__FILE__,__LINE__,"CacheHit Regex ".htmlspecialchars($s_pattern).": ".intval($arr_vals['PROJ_ID']));
  652.                                 return intval($arr_vals['PROJ_ID']);
  653.                             }
  654.                         }
  655.                     }
  656.                 // foreach($arr_prjData as $host => $arr_vals)
  657.             // (is_array($arr_prjData))
  658.             if ($debugechoDebugLine(__FILE__,__LINE__,"no CacheHit");
  659.         else {
  660.             if ($debugechoDebugLine(__FILE__,__LINE__,"NO CACHE");
  661.             return 0;
  662.         }
  663.     }
  664.  
  665.     /**
  666.       * adds or replaces a host if $aId is 0 the host is removed from the cache
  667.       *
  668.       * @param int $aId (0 -> unset the cache object)
  669.       * @param string $aHost 
  670.       * @param string $urlRegex 
  671.       * @access public
  672.       *
  673.       */
  674.     function addProjIdFromHTTP_HOST($aId,$aHost="",$urlRegex="",$aServerName="")
  675.     {
  676.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::addProjIdFromHTTP_HOST()",$_SERVER['HTTP_HOST']);
  677.         $arr_option=array(
  678.             'cacheDir'                  => $this->getRootPath(),
  679.             'automaticSerialization'    => TRUE,
  680.             'lifeTime'                  => $this->ttl,
  681.             'fileNameProtection'        => FALSE
  682.         );
  683.         $obj_cache=new Cache_Lite($arr_option);
  684.  
  685.         $arr_prjData=$obj_cache->get('PROJLST');
  686.         if (!is_array($arr_prjData))
  687.         {
  688.             $arr_prjData=array();
  689.         }
  690.  
  691.         if (empty($aHost)) $aHost=$_SERVER['HTTP_HOST'];
  692.         $aHost=strtoupper($aHost);
  693.  
  694.         if (intval($aId)==0)
  695.         {
  696.             if (isset($arr_prjData[$aHost]))
  697.             {
  698.                 unset($arr_prjData[$aHost]);
  699.             }
  700.         else {
  701.             $arr_prjData[$aHost]=array(
  702.                     'PROJ_ID'       =>intval($aId),
  703.                     'PROJ_URLREGEX' =>$urlRegex,
  704.                     'PROJ_URL'      =>strtoupper(!empty($aServerName$aServerName $_SERVER['SERVER_NAME'])
  705.                 );
  706.         }
  707.  
  708.         $arr_prjData['PEARCACHE_TS']=time();
  709.         $obj_cache->save($arr_prjData,'PROJLST');
  710.     }
  711.  
  712.     /**
  713.       * @param boolean $debug 
  714.       * @access public
  715.       */
  716.     function clearProjIdFromHTTP_HOST($debug=FALSE)
  717.     {
  718.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::clearProjIdFromHTTP_HOST()",$_SERVER['HTTP_HOST']);
  719.         $arr_option=array(
  720.             'cacheDir'                  => $this->getRootPath(),
  721.             'automaticSerialization'    => TRUE,
  722.             'lifeTime'                  => $this->ttl,
  723.             'fileNameProtection'        => FALSE
  724.         );
  725.         $obj_cache=new Cache_Lite($arr_option);
  726.         $obj_cache->clear();
  727.     }
  728.  
  729.     /**
  730.       * @param int $projId 
  731.       * @param boolean $debug 
  732.       *
  733.       * @return array 
  734.       * @access public
  735.       *
  736.       */
  737.     function getProjCssArray($projId,$debug=FALSE)
  738.     {
  739.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getProjCssArray()");
  740.         $obj_cache=$this->getProjCacheObj($projId,FALSE,$debug);
  741.         return $obj_cache->get('CSS_PROJ');
  742.     }
  743.  
  744.  
  745.     /**
  746.       * @param int $projId 
  747.       * @param boolean $debug 
  748.       *
  749.       * @return array 
  750.       * @access public
  751.       *
  752.       */
  753.     function setProjCssArray($projId,$cssArr,$debug=FALSE)
  754.     {
  755.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setProjCssArray($projId)");
  756.         if ($obj_cache=$this->getProjCacheObj($projId,TRUE,$debug))
  757.         {
  758.             $cssArr['PEARCACHE_TS']=time();
  759.             if (!$obj_cache->save($cssArr,'CSS_PROJ'))
  760.             {
  761.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Error Saving Cache</p><pre>".print_r($obj_cache,TRUE)."</pre>");
  762.             }
  763.         }
  764.     }
  765.  
  766.  
  767.     /**
  768.       *
  769.       * page template cache methods
  770.       *
  771.       */
  772.     /**
  773.       * @param int $projId 
  774.       * @param int $pageId 
  775.       * @param boolean $debug 
  776.       *
  777.       * @return array 
  778.       * @access public
  779.       */
  780.     function getPageTmplRow($projId,$tmplId,$debug=FALSE)
  781.     {
  782.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getPageTmplRow($projId,$tmplId)");
  783.         $obj_cache=$this->getProjCacheObj($projId,FALSE,$debug);
  784.         return $obj_cache->get('PTMPLROW_'.$tmplId);
  785.     }
  786.  
  787.     /**
  788.       * @param int $projId 
  789.       * @param int $pageId 
  790.       * @param array $pageRow 
  791.       * @param boolean $debug 
  792.       *
  793.       * @return array 
  794.       * @access public
  795.       *
  796.       */
  797.     function setPageTmplRow($projId,$tmplId,$tmplRow,$debug=FALSE)
  798.     {
  799.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setPageTmplRow($projId,$tmplId)");
  800.         if ($obj_cache=$this->getProjCacheObj($projId,TRUE,$debug))
  801.         {
  802.             $tmplRow['PEARCACHE_TS']=time();
  803.             $obj_cache->save($tmplRow,'PTMPLROW_'.$tmplId);
  804.         }
  805.     }
  806.  
  807.     /**
  808.       *
  809.       * menu cache methods
  810.       *
  811.       */
  812.  
  813.     /**
  814.       * sets the menuTreeKey (index of $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex])
  815.       *
  816.       * @param string $treeName 
  817.       * @access public
  818.       */
  819.     function setMenuTreeIndex($treeName)
  820.     {
  821.         $this->menuTreeIndex=$treeName;
  822.     }
  823.  
  824.  
  825.     /**
  826.       * @param int $projId 
  827.       * @param string $treeKey 
  828.       *
  829.       * @return boolean 
  830.       */
  831.     function getMenuKeyTree($projId,$debug=FALSE)
  832.     {
  833.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getMenuKeyTree($projId)");
  834.         $obj_cache=$this->getProjCacheObj($projId,TRUE,$debug);
  835.         return $obj_cache->get('MENUKEYTREE');
  836.     }
  837.  
  838.     /**
  839.       * stores a projects database values to the cache
  840.       *
  841.       * @param CMS_PROJECT $aProj 
  842.       * @param boolean $debug 
  843.       */
  844.     function setMenuKeyTree($projId,$keyArr,$debug=FALSE)
  845.     {
  846.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setMenuKeyTree($projId)");
  847.         if ($obj_cache=$this->getProjCacheObj($projId,TRUE,$debug))
  848.         {
  849.             $keyArr['PEARCACHE_TS']=time();
  850.             if (!$obj_cache->save($keyArr,'MENUKEYTREE'))
  851.             {
  852.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Error Saving Cache</p><pre>".print_r($obj_cache,TRUE)."</pre>");
  853.             }
  854.         }
  855.     }
  856.  
  857.     /**
  858.       * returns if the global menu nodeval array has been loaded
  859.       *
  860.       * @param int $projId 
  861.       * @param string $menuTreeIndex 
  862.       *
  863.       * @return boolean 
  864.       * @access public
  865.       */
  866.     function menuNodesValLoaded($projId,$menuTreeIndex='T_CMS_MENU')
  867.     {
  868.         if (isset($this->menNodeValsLoaded[$projId][$menuTreeIndex]))
  869.         {
  870.             return $this->menNodeValsLoaded[$projId][$menuTreeIndex];
  871.         }
  872.         return FALSE;
  873.     }
  874.  
  875.     /**
  876.       * sets the global environment of the tree from the cache
  877.       *
  878.       * @param int $projId 
  879.       * @param string $treeKey 
  880.       *
  881.       * @return boolean 
  882.       */
  883.     function getMenuNodesVal($projId,$debug=FALSE)
  884.     {
  885.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getMenuNodesVal($projId)",$this->menuTreeIndex);
  886.         $obj_cache=$this->getProjCacheObj($projId,TRUE,$debug);
  887.  
  888.         if (empty($this->menuTreeIndex)) $this->menuTreeIndex='T_CMS_MENU'.$projId;
  889.  
  890.         $this->menNodeValsLoaded[$projId][$this->menuTreeIndex]=TRUE;
  891.         if (!$arr_cache=$obj_cache->get('MENUNODESVAL'.$this->menuTreeIndex))
  892.         {
  893.             if ($debugechoDebugLine(__FILE__,__LINE__,"MENUNODESVAL is empty");
  894.             return FALSE;
  895.         }
  896.  
  897.         $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODEVAL']=$arr_cache;
  898.  
  899.         if ($debugechoDebugLine(__FILE__,__LINE__,"cache values: <pre style=\"font-size: 60%\">".print_r($GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODEVAL'],TRUE)."</pre>");
  900.  
  901.         return TRUE;
  902.  
  903.     }
  904.  
  905.     /* *
  906.       * stores a projects database values to the cache
  907.       *
  908.       * @param CMS_PROJECT $aProj
  909.       * @param boolean $debug
  910.       *
  911.     function setMenuNodesVal($projId,$debug=FALSE)
  912.     {
  913.         if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setMenuNodesVal($projId)",$this->menuTreeIndex);
  914.  
  915.         if (empty($this->menuTreeIndex)) $this->menuTreeIndex='T_CMS_MENU'.$projId;
  916.  
  917.         if ($obj_cache=$this->getProjCacheObj($projId,TRUE,$debug))
  918.         {
  919.             $arr_Nodes = &$GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODEVAL'];
  920.  
  921.             if (isset($GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODES']))
  922.             {
  923.                 foreach($GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODES'] as $idx => &$o_node)
  924.                 {
  925.                     if (pcf_is_instance_of($o_node,'DBMS_TREE_NODE'))
  926.                     {
  927.                         if ($debug) echoDebugLine(__FILE__,__LINE__,"adding Node ".$o_node->getId());
  928.                         $arr_Nodes[$o_node->getId()]['DATA']        =$o_node->getDBVal();
  929.                         $arr_Nodes[$o_node->getId()]['PEARCACHE_TS']=$o_node->getPopulateTs();
  930.                     } else {
  931.                         if ($debug) echoDebugLine(__FILE__,__LINE__,"not instance of DBMS_TREE_NODE <pre>".print_r($o_node,TRUE)."</pre>");
  932.                     }
  933.                 }
  934.             }
  935.  
  936.             if (!$obj_cache->save($arr_Nodes,'MENUNODESVAL'.$this->menuTreeIndex))
  937.             {
  938.                 if ($debug) echoDebugLine(__FILE__,__LINE__,"<p>Error Saving Cache</p><pre>".print_r($obj_cache,TRUE)."</pre>");
  939.             }
  940.             $this->menNodeValsLoaded[$projId][$this->menuTreeIndex]=TRUE;
  941.         }
  942.     }
  943.     */
  944.  
  945.  
  946.     /** -----------------------------------------------------
  947.       * pageRow
  948.       */
  949.  
  950.  
  951.  
  952.     /** -----------------------------------------------------
  953.       * pageHeader
  954.       */
  955.  
  956.     /**
  957.       * @param CMS_PAGE_V2 $pageObj 
  958.       * @param boolean $debug 
  959.       *
  960.       * @return string 
  961.       * @access public
  962.       */
  963.     function getPageHeader($pageObj,$debug=FALSE)
  964.     {
  965.         $obj_cache=$this->getProjCacheObj($projId,FALSE,$debug);
  966.         return $obj_cache->get('PAGHEADER_'.$pageObj->getId());
  967.     }
  968.  
  969.  
  970.  
  971. // end class OCSP_CMS_PEARCACHE
  972. ?>

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