Source for file OCSP_CMS_HTMLPAGE.phpclass

Documentation is available at OCSP_CMS_HTMLPAGE.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_CMS_HTMLPAGE.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 __OCSP_PHPINCPATH__."common/OCSP_HTMLPAGE.phpclass";
  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_CMS_PHPINCPATH__'))
  28.     {
  29.         require_once __OCSP_DEFAULTCONFPATH__."cms.conf.phpinc";    
  30.     }
  31.  
  32.     pcf_require_class('OCSP_HTMLPAGE',"common/");
  33.     pcf_require_class('CMS_TABLEOBJ',"cms/");
  34.     pcf_require_class('CMS_PROJECT',"cms/");
  35.     pcf_require_class('CMS_PAGE',"cms/page/");
  36.     
  37.  
  38. /**
  39.   * Class OCSP_CMS_PEARCACHE.phpclass
  40.   *
  41.   * @project    Open CSP-Management
  42.   * @package    cms
  43.   *
  44.   * @author     Peter Krebs <p.krebs@amicas.at>
  45.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  46.   *
  47.   * @since pk-07-06-07
  48.   *
  49.   */
  50. class OCSP_CMS_HTMLPAGE extends OCSP_HTMLPAGE 
  51. {
  52.     // ---------------------------------------------------------------------------
  53.     // constants
  54.     // ---------------------------------------------------------------------------
  55.     
  56.     /**
  57.       * @constant string CLASS_SRC_FILE
  58.       */
  59.     const CLASS_SRC_FILE = __FILE__;    
  60.     
  61.     // ---------------------------------------------------------------------------
  62.     // class (static)
  63.     // ---------------------------------------------------------------------------
  64.     
  65.     /**
  66.      * unit of work array of instances
  67.      *
  68.      * @staticvar array $myCMSPageInstances 
  69.      */
  70.        protected static $loaded_CMS_HTML_Pages array();
  71.     
  72.     /*** class methods ------------------------------------------------ */
  73.     
  74.     /**
  75.      * returns the current html page object
  76.      *
  77.      * @return CMS_PAGE 
  78.      */
  79.     public static function &getCurrentPage($debug)
  80.     {
  81.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_CMS_HTMLPAGE::getCurrentPage()");
  82.         
  83.         if (!$obj_page CMS_TABLEOBJ::get_currentPage())
  84.         {
  85.             if (!$obj_menu CMS_TABLEOBJ::get_currentMenu())
  86.             {
  87.                 if (!$obj_project CMS_TABLEOBJ::get_currentProj())
  88.                 {
  89.                     throw new Exception("COULD NOT FIND SOMETHING TO SHOW");
  90.                 }
  91.                 $obj_menu $obj_project->getCurrentMenuNode();            
  92.             }
  93.             $obj_page $obj_menu->getCurrentPage(False,True);
  94.             CMS_TABLEOBJ::set_currentPage($obj_page);
  95.         }
  96.         return $obj_page;
  97.     }
  98.  
  99.     /**
  100.      * returns if a page is already instanced
  101.      *
  102.      * @param int $aPageId 
  103.      * @return boolean 
  104.      */
  105.     public static function isInstanced($aPageId)
  106.     {
  107.         return isset(self::$loaded_CMS_HTML_Pages[intval($aPageId)]);
  108.     }
  109.     
  110.     /**
  111.      * returns the instance for $aPage
  112.      * 
  113.      * NOTE you can pass either the pageId or the page object
  114.      *
  115.      * @param mixed $aPage 
  116.      * @param boolean $debug 
  117.      * 
  118.      * @return OCSP_CMS_HTMLPAGE 
  119.      */
  120.     public static function &getInstance($aPage,$debug=False)
  121.     {
  122.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_CMS_HTMLPAGE::getInstance()");
  123.         
  124.         if (!pcf_class_implements($aPage,'INFA_CMS_PAGE'))
  125.         {
  126.             if ($int_pagId intval($aPage))
  127.             {
  128.                 if (isset(self::$loaded_CMS_HTML_Pages[$int_pagId]&& pcf_is_instance_of(self::$loaded_CMS_HTML_Pages[$int_pagId],'OCSP_CMS_HTMLPAGE')) 
  129.                 {
  130.                     return self::$loaded_CMS_HTML_Pages[$int_pagId];
  131.                 else {
  132.                     if (!($aPage CMS_PAGE::getInstance($int_pagId)))
  133.                     {
  134.                         $obj_ret Null;
  135.                         return $obj_ret;
  136.                     }
  137.                 }
  138.             else {
  139.                 $obj_ret Null;
  140.                 return $obj_ret;
  141.             }            
  142.         }
  143.         
  144.         $int_pagId $aPage->getId();
  145.         if (isset(self::$loaded_CMS_HTML_Pages[$int_pagId]&& pcf_is_instance_of(self::$loaded_CMS_HTML_Pages[$int_pagId],'OCSP_CMS_HTMLPAGE')) 
  146.         {
  147.             return self::$loaded_CMS_HTML_Pages[$int_pagId];
  148.         else {
  149.             self::$loaded_CMS_HTML_Pages[$int_pagIdnew OCSP_CMS_HTMLPAGE($aPage,$debug);
  150.             return self::$loaded_CMS_HTML_Pages[$int_pagId];
  151.         }
  152.     }
  153.     
  154.     // ---------------------------------------------------------------------------
  155.     // object vars
  156.     // ---------------------------------------------------------------------------
  157.     
  158.     /*** compostion --------------------------------------------------- */
  159.    
  160.     /**
  161.       * @var CMS_PAGE $myPageObj 
  162.       * @access protected
  163.       */
  164.     protected $myPageObj=Null;
  165.  
  166.     /**
  167.       * @var CMS_MENU_NODE $myPageObj 
  168.       * @access protected
  169.       */
  170.     protected $myMenuNode=Null;
  171.  
  172.     /**
  173.      * @var CMS_PROJECT $myProject 
  174.      */
  175.     protected $myProject=Null;
  176.  
  177.     /*** attributes  -------------------------------------------------- */
  178.     
  179.     /**
  180.       * @var string $myJsOnError 
  181.       * @access protectd
  182.       */
  183.     protected $myJsOnError="
  184.         window.onerror=ocsp_handleErr;
  185.         var ocsp_handleErrDebug=true;
  186.  
  187.         function ocsp_handleErr(msg,url,l)
  188.         {
  189.             var txt=\"\";
  190.             txt =\"There was an error on this page.\\n\\n\";
  191.             txt+=\"Error: \" + msg + \"\\n\";
  192.             txt+=\"URL: \" + url + \"\\n\";
  193.             txt+=\"Line: \" + l + \"\\n\\n\";
  194.             txt+=\"Click OK to continue.\\n\\n\";
  195.             if (ocsp_handleErrDebug) alert(txt);
  196.             return true;
  197.         }
  198.       ";
  199.  
  200.     /**
  201.      * preview mode
  202.      *
  203.      * @var boolean 
  204.      */
  205.     protected $previewMode = False;
  206.     
  207.  
  208.     // ---------------------------------------------------------------------------
  209.     // factory / construct
  210.     // ---------------------------------------------------------------------------
  211.     
  212.     /**
  213.      * factories the html page from the environment
  214.      *
  215.      * @param boolean $debug 
  216.      * 
  217.      * @return OCSP_CMS_HTMLPAGE 
  218.      * 
  219.      * @since pk-08-11-30
  220.      */
  221.     public static function &factoryFromEnv($debug=False)
  222.     {
  223.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_CMS_HTMLPAGE::factoryFromEnv");
  224.         
  225.            if (CMS_TABLEOBJ::factoryCurrentElements($debug))
  226.            {
  227.             try {
  228.                 $obj_page self::getCurrentPage($debug);
  229.             catch(Exception $e{                
  230.                 if ($debug{
  231.                     ob_start();
  232.                     var_dump($e);
  233.                     $str_debug ob_get_contents();
  234.                     ob_end_clean();
  235.                     echoDebugLine(__FILE__,__LINE__,$str_debug);
  236.                 }
  237.                 $obj_page new CMS_PAGE();
  238.                 $obj_page->setMyProject(CMS_TABLEOBJ::get_currentProj());
  239.                 $obj_page->setMyMenuNode(CMS_TABLEOBJ::get_currentMenu());
  240.             }
  241.             
  242.             $obj_ret self::getInstance($obj_page);
  243.         else {   
  244.             $obj_page=Null;         
  245.             $obj_ret new OCSP_CMS_HTMLPAGE($obj_page,$debug);
  246.         }        
  247.         
  248.         if (isset($_GET['PREVIEW']&& intval($_GET['PREVIEW']))
  249.         {
  250.             $obj_ret->setPreviewMode(True);
  251.         }
  252.         return $obj_ret;
  253.     }    
  254.     
  255.     /**
  256.      * factories a html page from a cms page object
  257.      *
  258.      * @param CMS_PAGE $aPage 
  259.      * @param boolean $debug 
  260.      * 
  261.      * @return OCSP_CMS_HTMLPAGE 
  262.      */
  263.     public static function factoryFromPage(&$aPage,$debug=False)
  264.     {
  265.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_CMS_HTMLPAGE::factoryFromPage()");
  266.         if (!pcf_class_implements($aPage,'INFA_CMS_PAGE'))
  267.         {
  268.             return Null;
  269.         }
  270.         return new OCSP_CMS_HTMLPAGE($aPage,$debug);        
  271.     }
  272.     
  273.     /**
  274.       * @param CMS_PAGE_V2 $aPage 
  275.       * @param boolean $debug 
  276.       */
  277.     function OCSP_CMS_HTMLPAGE(&$aPage,$debug=False)
  278.     {
  279.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_HTMLPAGE");
  280.         
  281.         parent::OCSP_HTMLPAGE($debug);
  282.         
  283.         if (pcf_class_implements($aPage,"INFA_CMS_PAGE"))
  284.         {
  285.             $this->myPageObj    =$aPage;
  286.             $this->myMenuNode   =$aPage->getMyMenuNode($debug);
  287.             $this->myProject    =$aPage->getMyProject($debug);
  288.     
  289.             if (intval($this->myPageObj->getId()))
  290.             {
  291.                 $this->populateHTML_Head($debug);
  292.             }
  293.             
  294.             $this->myPageObj->setMyHTMLPage($this);
  295.         else {
  296.             if ($debugechoDebugLine(__FILE__,__LINE__,"<h1>WARNING: no page set</h1><p>" get_class($aPage"</p>");
  297.         }
  298.     }
  299.      
  300.     // ---------------------------------------------------------------------------
  301.     // factory / construct
  302.     // ---------------------------------------------------------------------------
  303.  
  304.  
  305.     /**
  306.      * returns the page object
  307.      * 
  308.      * @return CMS_PAGE 
  309.      */
  310.     public function getPageObj()
  311.     {
  312.         return $this->myPageObj;
  313.     }
  314.  
  315.     /**
  316.      * returns if preview is on
  317.      *
  318.      * @return boolean 
  319.      */
  320.     public function getPreviewMode()
  321.     {
  322.         return $this->previewMode;
  323.     }
  324.     
  325.     /**
  326.      * sets preview mode
  327.      *
  328.      * @param boolean $on 
  329.      */
  330.     public function setPreviewMode($on=True)
  331.     {
  332.         $this->previewMode = $on;
  333.     }
  334.     
  335.     /** -----------------------------------------------------
  336.       * body content
  337.       */
  338.  
  339.     /**
  340.       * adds a body content (to a block)
  341.       *
  342.       * if the blockname ends with [] the content is treaten as array
  343.       *     in this case prepend is disabled
  344.       *
  345.       * @param CMS_PAGE_V2 $aPage 
  346.       * @param int $chapterMode 
  347.       * @param boolean $prepend 
  348.       * @param string $blockName 
  349.       * @param boolean $debug 
  350.       * @access public
  351.       *
  352.       * @todo OCSP_HTMLPAGE::prepend in array mode
  353.       *
  354.       */
  355.     function addBodyContentPage($aPage,$chapterMode=0,$prepend=False,$blockName='DEFAULT',$debug=False)
  356.     {
  357.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_HTMLPAGE::addPageContent()");
  358.  
  359.         if (!pcf_class_implements($aPage,"INFA_CMS_PAGE"))
  360.         {
  361.             ocsp_logError(__FILE__,__LINE__,"addPageContent(): \$aPage (".get_class($aPage).") is not an instance of CMS_PAGE_V2",E_WARNING);
  362.  
  363.         else {
  364.             $aPage->execPrependCmds($debug);
  365.             $aPage->setMyHTMLPage($this);
  366.             $str_content=$aPage->getContent($chapterMode,$debug);
  367.             if ($debugechoDebugLine(__FILE__,__LINE__,"<h1>OCSP_CMS_HTMLPAGE::pageContent: </h1><pre>".htmlspecialchars($str_content)."</pre>");
  368.             $this->addBodyContent($str_content,$prepend,$blockName);
  369.         }
  370.     }
  371.  
  372.     /** -----------------------------------------------------
  373.       * cache methods
  374.       */
  375.  
  376.     /**
  377.       * returns if the cms cache is usable
  378.       *
  379.       * if (_OCSP_USEPEARCACHE_) it's ensured that
  380.       * $GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE'] is an object
  381.       *
  382.       * @return boolean 
  383.       */
  384.     function cmsCacheIsUsable()
  385.     {
  386.         if (_OCSP_USEPEARCACHE_{
  387.             if (!pcf_is_instance_of($GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE'],'OCSP_CMS_PEARCACHE'))
  388.             {
  389.                 require_once $GLOBALS['OCSP_CMS']['PHPINCPATH']."OCSP_CMS_PEARCACHE.phpclass";
  390.                 $GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE']=new OCSP_CMS_PEARCACHE();
  391.             }
  392.             $this->myCmsCache=&$GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE'];
  393.  
  394.             return TRUE;
  395.         }
  396.         return False;
  397.     }
  398.  
  399.     /**
  400.       * HTML head ----------------------------------------------------------------------------------
  401.       */
  402.  
  403.     /**
  404.       * sets the html header form the page
  405.       * note clears all previous settings
  406.       *
  407.       * @param boolean $debug 
  408.       *
  409.       * @return boolean 
  410.       * @access public
  411.       *
  412.       */
  413.     function populateHTML_Head($debug=False)
  414.     {
  415.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_HTMLPAGE::populateHTML_Head()");
  416.  
  417.         if (!pcf_is_instance_of($this->myPageObj,'CMS_PAGE_V2')) {
  418.             if ($debugechoDebugLine(__FILE__,__LINE__,"No page object set");
  419.             return False;
  420.         }
  421.  
  422.         $this->setTitle($this->myPageObj->getTitle());
  423.  
  424.         // css
  425.         if (!isset($GLOBALS['OCSP_VAL']['CMS_CSS_STY_INCLUDED']))
  426.         {
  427.             $GLOBALS['OCSP_VAL']['CMS_CSS_STY_INCLUDED']=array();
  428.         }
  429.  
  430.         if (pcf_is_instance_of($this->myProject,'CMS_PROJECT'))
  431.         {
  432.             $this->myProject->addCssToHTMLPage($this,$debug);
  433.         }
  434.  
  435.     }
  436.     
  437.     // ------------------------------------------------
  438.     // output
  439.     // ------------------------------------------------
  440.     
  441.     /**
  442.      * loads the required templates and sets the template vars
  443.      *
  444.      * @param unknown_type $debug 
  445.      */
  446.     public function prepare($debug=False)
  447.     {          
  448.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_HTMLPAGE::prepare");
  449.         
  450.                 
  451.         if ($str_idxTmpl=CMS_TABLEOBJ::get_currentProj()->getIndexPHP_inc($debug))
  452.         {
  453.             if ($debugechoDebugLine(__FILE__,__LINE__,"index template: ".$str_idxTmpl);
  454.             if (!$debug{
  455.                 ob_start();
  456.                 include $str_idxTmpl;
  457.                 $this->addBodyContent(ob_get_contents());
  458.                 ob_end_clean();                                        
  459.             else {
  460.                 include $str_idxTmpl;
  461.             }
  462.         }
  463.         
  464.         
  465.     
  466.     
  467.      /**
  468.       * outputs the page
  469.       *
  470.       * @param boolean $closeBody 
  471.       * @param string $convertCharSet 
  472.       * 
  473.       * @version pk-07-12-14 gzip return
  474.       */
  475.     function display($closeBody=true,$convertCharSet="UTF-8",$debug=False)
  476.     {            
  477.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_HTMLPAGE::display();");
  478.         
  479.         if (pcf_class_implements($this->myPageObj,'INFA_CMS_PAGE'))
  480.         {
  481.             if (!is_array($this->myTemplateVars['ALL'])) $this->myTemplateVars['ALL']=array();
  482.             $this->myTemplateVars['ALL'array_merge($this->myPageObj->getDBVal(),$this->myTemplateVars['ALL']);
  483.             $this->myTemplateVars['ALL'array_merge($this->myPageObj->getMyMenuNode()->getDBVal(),$this->myTemplateVars['ALL']);
  484.             $this->myTemplateVars['ALL'array_merge($this->myPageObj->getMyProject()->getDBVal(),$this->myTemplateVars['ALL']);                
  485.                         
  486.             if (!$this->myPageObj->getContentCalled())
  487.             {
  488.                 $this->setTemplateVar('PAGECONTENT',$this->myPageObj->getContent(0,$debug));    
  489.             }
  490.         }
  491.  
  492.         if ($debug{
  493.             echoDebugLine(__FILE__,__LINE__,"<h2>Content:</h2><pre>" htmlspecialchars(print_r($this->myBodyContent,True)) "</pre>");
  494.             echoDebugLine(__FILE__,__LINE__,"<h2>myTemplateVars:</h2><pre>" htmlspecialchars(print_r($this->myTemplateVars,True)) "</pre>");
  495.         }
  496.         
  497.         parent::display($closeBody,$convertCharSet);
  498.     }
  499.     
  500.     /**
  501.      * outputs an error page
  502.      * 
  503.      * @param string $errorMsg 
  504.      * 
  505.      * @todo make layout
  506.      */
  507.     public function displayErrorPage($errorMsg)
  508.     {
  509.         echo "
  510.             <html>
  511.                 <head>
  512.                     <title>" t_admin("Fehler""</title>
  513.                 </head>
  514.                 <body>
  515.                     <h1>" t_admin("Fehler""</h1>
  516.                     <p>{$errorMsg}</p>
  517.                 </body>
  518.             </html>
  519.             ";
  520.     }
  521.     
  522.     // ------------------------------------------------
  523.     // view / rights
  524.     // ------------------------------------------------
  525.         
  526.     /**
  527.      * returns if the current user can open the page
  528.      *
  529.      * @param boolean $debug 
  530.      * 
  531.      * @return boolean 
  532.      */
  533.     public function curUserCanOpen($debug=False)
  534.     {
  535.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_HTMLPAGE::curUserCanOpen()");
  536.         
  537.         if (pcf_class_implements($this->getPageObj(),"INFA_CMS_PAGE"))
  538.         {
  539.             if (!$this->getPreviewMode())
  540.             {
  541.                 if (!$this->getPageObj()->isOnline())
  542.                 {
  543.                     return False;    
  544.                 }
  545.             }             
  546.             return $this->getPageObj()->curUserCanOpen();
  547.         else {
  548.             return False;
  549.         }
  550.     }
  551.     
  552. // end class OCSP_CMS_HTMLPAGE

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