Source for file CMS_PHPINC_PAGE.phpclass

Documentation is available at CMS_PHPINC_PAGE.phpclass

  1. <?php
  2. /**
  3.   * Class file CMS_PHPINC_PAGE.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.   ***/
  12.  
  13. require_once __OCSP_DEFAULTCONFPATH__."cms.conf.phpinc";
  14. require_once dirname(__FILE__)._OCSP_DIRSEP_."CMS_PAGE_V2.phpclass";
  15.  
  16.  
  17. /**
  18.   * class to handel PAGES with php code included
  19.   *
  20.   * NOTE: if you use a $PREPEND_INC make sure
  21.   * it is included by your index.php script by either
  22.   * calling inc_prepInc or by calling getHead which
  23.   * includes the file if not done before
  24.   *
  25.   * @project    Open CSP-Management
  26.   * @package    cms
  27.   *
  28.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  29.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   * @version    pk-04-11-17
  32.   * @since      pk-04-08-10
  33.   * @version pk-05-06-17 GLOBAL_VALUES added
  34.   * @version pk-07-08-25 $pageIncludeOutput Added
  35.   *
  36.   * @todo APPEND_INC
  37.   *
  38.   ***/
  39. class CMS_PHPINC_PAGE extends CMS_PAGE_V2 
  40. {
  41.     // ---------------------------------------------------------------------------
  42.     // constants
  43.     // ---------------------------------------------------------------------------
  44.     
  45.     /**
  46.      * @constant string CLASS_SRC_FILE
  47.      *
  48.      * @abstract
  49.      */
  50.     const CLASS_SRC_FILE = __FILE__;
  51.     
  52.     // ---------------------------------------------------------------------------
  53.     // class (static)
  54.     // ---------------------------------------------------------------------------
  55.     
  56.     /*** class vars ------------------------------------------------------ */
  57.     
  58.     /*** class methods --------------------------------------------------- */
  59.     
  60.     // ---------------------------------------------------------------------------
  61.     // object vars
  62.     // ---------------------------------------------------------------------------
  63.     
  64.     
  65.     
  66.  
  67.  
  68.     /**
  69.       * @var string $includeRoot 
  70.       */
  71.     protected $includeRoot="templates/";
  72.  
  73.     /**
  74.       * @var string $GLOBAL_VALUES 
  75.       * @since pk-05-06-17
  76.       */
  77.     protected $GLOBAL_VALUES = "";
  78.  
  79.     /**
  80.       * @var array $PAGVAR 
  81.       */
  82.     protected $PAGVAR=array();
  83.  
  84.     /**
  85.       * @var string $PREPEND_INC 
  86.       ***/
  87.     protected $PREPEND_INC = "";
  88.  
  89.      /**
  90.        * @var string $PROGRAMM_INC 
  91.        */
  92.     protected $PROGRAMM_INC = "";
  93.  
  94.      /**
  95.        * @var string $APPEND_INC 
  96.        */
  97.     protected $APPEND_INC = "";
  98.  
  99.     /**
  100.       * @var boolean $prepIncDone 
  101.       * @since pk-06-07-28 (was used but not defined)
  102.       ***/
  103.     protected $prepIncDone=FALSE;
  104.  
  105.     /**
  106.       * buffer for the include output
  107.       * @var string $pageIncludeOutput 
  108.       * @since pk-07-08-25
  109.       * @access protected
  110.       */
  111.     protected $pageIncludeOutput;
  112.  
  113.  
  114.     /** -----------------------------------------------------
  115.       * getter & setter methods
  116.       */
  117.  
  118.  
  119.     /**
  120.       * returns a array of variables used by the page object
  121.       *
  122.       * array[varName]=array(
  123.       *     [TYPE]          datatype
  124.       *     [FLDCLASS]      name of DBMS_FIELD* class
  125.       *     [CLASSVALS]     array of values of [FLDCLASS]
  126.       *
  127.       * @global array $OCSP_CONF 
  128.       *
  129.       * @returns array
  130.       *
  131.       * @since pk-04-08-10
  132.       * @version pk-05-06-17
  133.       *
  134.       ***/
  135.     protected function getObjVarDef({
  136.         $retArr=parent::getObjVarDef();
  137.  
  138.         global $OCSP_CONF;
  139.  
  140.         // <pk-05-06-17>
  141.         $retArr["GLOBAL_VALUES"]array(
  142.                 "TYPE"      => "string",
  143.                 "FLDCLASS"  => "DBMS_FIELD_TEXTAREA",
  144.                 "CLASSVALS" =>array(
  145.                     "label"         => "Globale Variablen",
  146.                     "allowNull"     => TRUE,
  147.                     "isSearchable"  => FALSE,
  148.                     "showInList"    => FALSE,
  149.                     "toolTip"       => "Liste von Variablen und Werten werden in \$this->PAGVAR gespeichert",
  150.                     "cols"          => 45,
  151.                     "rows"          => 5,
  152.                     "addTag"        => "<br /><span style=\"font-size: 0.8em\">NAME=Wert je Zeile</span>",
  153.                     "wrap"          => "off",
  154.                     "nlToBr"        => TRUE,
  155.                     "myROShowMode"  => // <pre>
  156.                 )
  157.             );
  158.         // </pk-05-06-17>
  159.  
  160.         $retArr["PREPEND_INC"]array(
  161.                 "TYPE"      => "string",
  162.                 "FLDCLASS"  => "DBMS_FIELD_FILESELECTLIST",
  163.                 "CLASSVALS" =>array(
  164.                     "label"         => "Prepend Include",
  165.                     "allowNull"     => TRUE,
  166.                     "isSearchable"  => TRUE,
  167.                     "showInList"    => FALSE,
  168.                     "toolTip"       => "Include File vor der ersten Ausgabe",
  169.                     "rootDir"       => $this->includeRoot,
  170.                     "defaultDir"    => $this->includeRoot."pages/",
  171.                     "allow_mkdir"   => TRUE,
  172.                     "allow_upload"  => TRUE
  173.                 )
  174.             );
  175.         $retArr["PROGRAMM_INC"]array(
  176.                 "TYPE"      => "string",
  177.                 "FLDCLASS"  => "DBMS_FIELD_FILESELECTLIST",
  178.                 "CLASSVALS" =>array(
  179.                     "label"         => "Programm Include",
  180.                     "allowNull"     => TRUE,
  181.                     "isSearchable"  => TRUE,
  182.                     "showInList"    => FALSE,
  183.                     "toolTip"       => "Include File im Content Bereich",
  184.                     "rootDir"       => $this->includeRoot,
  185.                     "defaultDir"    => $this->includeRoot."pages/",
  186.                     "allow_mkdir"   => TRUE,
  187.                     "allow_upload"  => TRUE,
  188.                     "editorUrl"     => $OCSP_CONF['SYSTEMURL']."editors/PHPWebEdit/editor.php"
  189.                 )
  190.             );
  191. /* not implemented
  192.         $retArr["APPEND_INC"]= array(
  193.                 "TYPE"      => "string",
  194.                 "FLDCLASS"  => "DBMS_FIELD_FILESELECTLIST",
  195.                 "CLASSVALS" =>array(
  196.                     "label"         => "Append Include",
  197.                     "allowNull"     => TRUE,
  198.                     "isSearchable"  => TRUE,
  199.                     "showInList"    => FALSE,
  200.                     "toolTip"       => "Include File nach </html>",
  201.                     "rootDir"       => $this->includeRoot,
  202.                     "defaultDir"    => $this->includeRoot."pages/",
  203.                     "allow_mkdir"   => TRUE,
  204.                     "allow_upload"  => TRUE
  205.                 )
  206.             );
  207. */
  208.         return $retArr;
  209.     }
  210.  
  211.  
  212.     /**
  213.       * @param string $aOutput 
  214.       * @param string $prepend 
  215.       * @param boolean $debug 
  216.       */
  217.     function addIncOutput($aOutput,$prepend=FALSE,$debug=FALSE)
  218.     {
  219.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PHPINC_PAGE::addIncOutput()",htmlspecialchars(substr($aOutput,0,40)));
  220.         if ($prepend$this->pageIncludeOutput=$aOutput.$this->pageIncludeOutput;
  221.         else          $this->pageIncludeOutput.=$aOutput;
  222.     }
  223.  
  224.     /** -----------------------------------------------------
  225.       * database methods
  226.       */
  227.  
  228.     /**
  229.       * unset some object vars to not store to the database
  230.       * and then calls the parent function
  231.       *
  232.       * @param string $gDBIDX GLOBAL ARRAY INDEX OF DB OBJECT
  233.       * @param bool   $debug  SHOW DEBUG INFO
  234.       *
  235.       * @return mixed 
  236.       *
  237.       * @since pk-04-11-17
  238.       *
  239.       ***/
  240.     function dbSave($debug=FALSE{
  241.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PHPINC_PAGE::dbSave()","Page: ".$this->getId());
  242.         unset($this->prepIncDone);
  243.         return parent::dbSave($debug);
  244.     }
  245.  
  246.     // #########################################
  247.  
  248.  
  249.     /**
  250.       * shows the page in preview mode
  251.       *
  252.       * @param int  $mdoe 
  253.       * @param bool $debug 
  254.       *
  255.       * @version pk-04-11-17
  256.       *
  257.       ***/
  258.     function preview($mode=0,$debug=FALSE{
  259.         $debug=TRUE;
  260.         if ($debugecho "<p><b>CMS_PHPINC_PAGE::preview($mode,$debug)</b> (".get_class($this).")</p>";
  261. /*        
  262.         if (!is_object($this->myTmpl)) {
  263.             if (!($this->loadTemplate($debug))) {
  264.                 $ERR="TEMPLATE_NOT_FOUND ".$query;
  265.                 include __OCSP_PHPINCPATH__."io/errors.phpinc";
  266.                 die();
  267.             }
  268.         }
  269.         $this->inc_prepInc($debug); // <pk-04-11-17 />
  270.  
  271.         echo $this->myTmpl->getBodyTag();
  272.         echo $this->myTmpl->getHeadLineTag();
  273.  
  274.         echo $this->{$this->colPrevix."HEADER"};
  275.  
  276.             echo $this->getChapter(CHAPTER_SHOWMODE_ALLWAYS_TOP,$debug);
  277.             if (!empty($this->PROGRAMM_INC)) {
  278.                 if (file_exists(__OCSP_PROJECTPATH__.$this->includeRoot.$this->PROGRAMM_INC)) {
  279.                     if ($debug) echo "<p>Programm Include:</p>";
  280.                     include __OCSP_PROJECTPATH__.$this->includeRoot.$this->PROGRAMM_INC;
  281.                 } else if (file_exists(__OCSP_PROJECTPATH__.$this->PROGRAMM_INC)) {
  282.                     if ($debug) echo "<p>Programm Include:</p>";
  283.                     include __OCSP_PROJECTPATH__.$this->PROGRAMM_INC;
  284.                 } else {
  285.                     if ($debug) echo "<p>Programm Include: <b>not found</b></b>";
  286.                 }
  287.             }
  288.             echo $this->getChapter(CHAPTER_SHOWMODE_ALLWAYS_BOTTOM,$debug);
  289.  
  290.             
  291.             if ($debug) echo "<p>Chapter Query: ".$this->getChapQuery(TRUE,FALSE,TRUE,FALSE,"",$debug)."</p>";
  292.         if ($cursor=$GLOBALS[$this->get_gDBIDX()]->query($this->getChapQuery())) {
  293.             while($row=$cursor->fetchArray()) {
  294.                 if (!is_object($this->chaTmplArr[$row[$this->ctmplFldPrevix."ID"]])) {
  295.                     $idx=$row[$this->ctmplFldPrevix."ID"];
  296.                     $cmd="\$this->chaTmplArr[".$idx."] = new ".$this->ctmplClass."();";
  297.                     eval ($cmd);
  298.  
  299.                     $this->chaTmplArr[$idx]->setProjId($this->getProjId());
  300.                     $this->chaTmplArr[$idx]->setPTMPId($this->getPTMPId());
  301.                     $this->chaTmplArr[$idx]->setId($idx);
  302.                     $this->chaTmplArr[$idx]->dbPopulate($debug);
  303.                 }
  304.  
  305.                 echo $this->chaTmplArr[$row[$this->ctmplFldPrevix."ID"]]->getTag(unserialize($row[$this->chapPrevix.'FIELDS']));
  306.  
  307.             }
  308.         }
  309.         echo $this->{$this->colPrevix."FEETER"};
  310.         echo $this->myTmpl->getFeeterTag();
  311. */
  312.         echo "todo";
  313.     }
  314.  
  315.     /**
  316.       * checks if we have a prepend inc file
  317.       * and includes it if exists
  318.       *
  319.       * @param boolean $debug 
  320.       *
  321.       * @returns boolean
  322.       *
  323.       * @since pk-04-11-17
  324.       * @version pk-05-06-17
  325.       *
  326.       ***/
  327.     function inc_prepInc($debug=FALSE{
  328.         if ($debugecho "<p><b>CMS_PHPINC_PAGE::inc_prepInc(...)</b> (".get_class($this).")</p>";
  329.  
  330.         // <pk-05-06-17>
  331.         if (!empty($this->GLOBAL_VALUES)) {
  332.             if ($debugecho "<pre>--".$this->GLOBAL_VALUES."--</pre>";
  333.             if ($keyVals=explode("\n",$this->GLOBAL_VALUES."\n")) {
  334.                 foreach($keyVals as $kv{
  335.                     if (strstr($kv,'=')) {
  336.                         if ($debugecho "<pre>KV: ".$kv."</pre>";
  337.                         list($k,$v)=explode("=",$kv,2);
  338.                         if ($debugecho "<pre>Setting \$GLOBALS['PAGVAR'][".$k."] to ".$v."</pre>";
  339.                         $GLOBALS['PAGVAR'][$k]=$v;
  340.                         $this->PAGVAR[$k]=$v;
  341.                     }
  342.                 }
  343.             }
  344.         }
  345.         // </pk-05-06-17>
  346.  
  347.         if (!empty($this->PREPEND_INC)) {
  348.             if (file_exists(__OCSP_PROJECTPATH__.$this->includeRoot.$this->PREPEND_INC)) {
  349.                 if ($debugecho "<p>Prepend Include:</p>";
  350.                 include __OCSP_PROJECTPATH__.$this->includeRoot.$this->PREPEND_INC;
  351.                 $this->prepIncDone=TRUE;
  352.             else if (file_exists(__OCSP_PROJECTPATH__.$this->PREPEND_INC)) {
  353.                 if ($debugecho "<p>Prepend Include:</p>";
  354.                 include __OCSP_PROJECTPATH__.$this->PREPEND_INC;
  355.                 $this->prepIncDone=TRUE;
  356.             else {
  357.                 if ($debugecho "<p>Prepend Include: <b>not found</b></b>";
  358.             }
  359.         }
  360.  
  361.         return $this->prepIncDone;
  362.     }
  363.  
  364.     /**
  365.       * executes a prepend script before the page output starts
  366.       *
  367.       * @param boolean $debug 
  368.       * @since pk-07-10-04
  369.       */
  370.     function execPrependCmds($debug=FALSE)
  371.     {
  372.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PHPINC_PAGE::execPrependCmds()");
  373.         $this->inc_prepInc($debug);
  374.     }
  375.  
  376.     /**
  377.       * returns the html head
  378.       * and includes $this->PREPEND_INC if file exists
  379.       *
  380.       *
  381.       * @param boolean $withMenu 
  382.       * @param boolean $debug 
  383.       *
  384.       * @returns string
  385.       *
  386.       * @version pk-04-11-17
  387.       *
  388.       ***/
  389.     function getHead($withMenu=TRUE,$debug=FALSE{
  390.         if ($debugecho "<p><b>CMS_PHPINC_PAGE::getHead($withMenu,...)</b> (".get_class($this).")</p>";
  391.         /* <pk-04-11-17> */
  392.         if (!$this->prepIncDone{
  393.             $this->inc_prepInc($debug);
  394.         }
  395.         /* </pk-04-11-17> */
  396.         return parent::getHead($withMenu,$debug);
  397.     }
  398.  
  399.  
  400.     /**
  401.       * returns the content of the page
  402.       *
  403.       * @param int $chaShowMode 
  404.       * @param boolean $debug 
  405.       *
  406.       * @return string 
  407.       * @since pk-07-08-25
  408.       * @version pk-07-10-04
  409.       * @version pk-08-07-25
  410.       */
  411.     function getContent($chaShowMode=0,$debug=False
  412.     {           
  413.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PHPINC_PAGE::getContent($chaShowMode)","<pre>" print_r($this->getDBVal(),True"</pre>");
  414.  
  415.         if (($chaShowMode == 0))
  416.         {
  417.             if ($this->getContentCalled())
  418.             {
  419.                 throw new Exception('content called twice');
  420.             else {
  421.                 $this->setContentCalled(True);
  422.             }
  423.         }        
  424.         
  425.         // <pk-07-10-15>
  426.         if (!empty($this->GLOBAL_VALUES)) {
  427.             if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>--".$this->GLOBAL_VALUES."--</pre>");
  428.             if ($keyVals=explode("\n",$this->GLOBAL_VALUES."\n")) {
  429.                 foreach($keyVals as $kv{
  430.                     if (strstr($kv,'=')) {
  431.                         if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>KV: ".$kv."</pre>");
  432.                         list($k,$v)=explode("=",$kv,2);
  433.                         if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>Setting PAGVAR[".$k."] to ".$v."</pre>");
  434.                         $this->PAGVAR[$k]=$v;
  435.                     }
  436.                 }
  437.             }
  438.         }
  439.         // </pk-07-10-15 />        
  440.         
  441.         if (($chaShowMode != CHAPTER_SHOWMODE_PROGRAMM&& ($chaShowMode != 0))
  442.         {
  443.             return parent::getContent($chaShowMode,$debug);
  444.         else if(empty($this->PROGRAMM_INC)) {
  445.             return parent::getContent($chaShowMode,$debug);            
  446.         else {
  447.  
  448.             $str_ret="";
  449.             if ($chaShowMode != CHAPTER_SHOWMODE_PROGRAMM)
  450.             {
  451.                 $str_ret .= $this->getContent(CHAPTER_SHOWMODE_ALLWAYS_TOP,$debug)
  452.             }
  453.             
  454.                if (file_exists(__OCSP_PROJECTPATH__.$this->includeRoot.$this->PROGRAMM_INC)) 
  455.                {                  
  456.                    if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Programm Include: "__OCSP_PROJECTPATH__ $this->includeRoot . $this->PROGRAMM_INC."</p>");
  457.                 ob_start();
  458.                    @include __OCSP_PROJECTPATH__ $this->includeRoot . $this->PROGRAMM_INC;
  459.                 $this->pageIncludeOutput.=ob_get_contents();
  460.                 ob_end_clean();                      
  461.                    
  462.                else if (file_exists(__OCSP_PROJECTPATH__.$this->PROGRAMM_INC)) {
  463.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Programm Include: " __OCSP_PROJECTPATH__ $this->PROGRAMM_INC."</p>");
  464.                 ob_start();
  465.                 @include __OCSP_PROJECTPATH__ $this->PROGRAMM_INC;
  466.                 $this->pageIncludeOutput.=ob_get_contents();
  467.                 ob_end_clean();                                      
  468.             else {
  469.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Programm Include: <b>not found</b></b>");
  470.             }  
  471.             $str_ret.=$this->pageIncludeOutput;
  472.             if ($debugechoDebugLine(__FILE__,__LINE__,"Include: " htmlspecialchars($this->pageIncludeOutput));
  473.             
  474.             if ($chaShowMode != CHAPTER_SHOWMODE_PROGRAMM)
  475.             {
  476.                 $str_ret.=$this->getContent(CHAPTER_SHOWMODE_ALLWAYS_BOTTOM)
  477.             }            
  478.             
  479.             return $str_ret;            
  480.         }
  481.     }
  482. }
  483.  
  484.  
  485. ?>

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