[Cs-content-commits] SF.net SVN: cs-content:[435] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-08-13 18:57:39
|
Revision: 435 http://cs-content.svn.sourceforge.net/cs-content/?rev=435&view=rev Author: crazedsanity Date: 2009-08-13 18:57:31 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Fix cs_tabs{} so it doesn't require the page object. /contentSystem.class.php: * initialize_locals(): -- TODO about making the tabs object useable. -- don't pass any arguments to cs_tabs::__construct() /cs_tabs.class.php: * MAIN::: -- remove csPageObj -- add gfObj * __construct(): -- ARG CHANGE: ARG DELETED: #1 (cs_genericPage $csPageObj) -- ARG CHANGE: ARG SHIFTED: #2 ($templateVar="tabs" now #1) -- special check so calling code knows not to try to pass cs_genericPage as the first argument (the old code caused an error about an inability to convert the object to a string). -- create cs_globalFunctions object. * load_tabs_template() [DELETED]: -- no longer needed * display_tabs(): -- ARG CHANGE: NEW ARG: #1 (array $blockRows) -- Need to pass an array of block rows (i.e. using $page->templateRows) so the tabs can be built. -- remove call to non-existent function load_tabs_template() -- fix exception -- returns parsed tabs instead of trying to use cs_genericPage::add_template_var()... Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/cs_tabs.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-08-13 18:40:21 UTC (rev 434) +++ trunk/1.0/contentSystem.class.php 2009-08-13 18:57:31 UTC (rev 435) @@ -180,7 +180,8 @@ //create a tabs object, in case they want to load tabs on the page. - $this->tabs = new cs_tabs($this->templateObj); + //TODO: make the tabs object usable to included code! + $this->tabs = new cs_tabs(); //check versions, make sure they're all the same. $myVersion = $this->get_version(); Modified: trunk/1.0/cs_tabs.class.php =================================================================== --- trunk/1.0/cs_tabs.class.php 2009-08-13 18:40:21 UTC (rev 434) +++ trunk/1.0/cs_tabs.class.php 2009-08-13 18:57:31 UTC (rev 435) @@ -11,8 +11,8 @@ private $tabsArr=array(); private $selectedTab; - private $csPageObj; private $templateVar; + private $gfObj; /** This is the default suffix to use when none is given during the add_tab() call. */ private $defaultSuffix='tab'; @@ -24,19 +24,14 @@ * @param $csPageObj (object) Instance of the class "cs_genericPage". * @param $templateVar (str,optional) What template var to find the tab blockrows in. */ - public function __construct(cs_genericPage $csPageObj, $templateVar="tabs") { + public function __construct($templateVar="tabs") { parent::__construct(false); - if(is_null($csPageObj) || !is_object($csPageObj) || get_class($csPageObj) !== 'cs_genericPage') { - //can't continue without that! - throw new exception("cs_tabs::__construct(): cannot load without cs_genericPage{} object (". get_class($csPageObj) .")"); - } - else { - //set it as a member. - $this->csPageObj = $csPageObj; - } - - if(is_null($templateVar) || strlen($templateVar) < 3) { + if(is_object($templateVar)) { + //trying to pass cs_genericPage{}... tell 'em we don't like that anymore. + throw new exception(__METHOD__ .": got an object (". get_class($templateVar) .") instead of template var name"); + } + elseif(is_string($templateVar) && is_null($templateVar) || strlen($templateVar) < 3) { //no template name? AHH!!! throw new exception("cs_tabs::__construct(): failed to specify proper template file"); } @@ -44,33 +39,14 @@ //set the internal var. $this->templateVar = $templateVar; } + + $this->gfObj = new cs_globalFunctions; }//end __construct() //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- - /** - * Loads & parses the given tabs template. Requires that the given template has "selected_tab" - * and "unselected_tab" block row definitions. - * - * @param (void) - * @return (void) - */ - private function load_tabs_template() { - //now let's parse it for the proper block rows. - $blockRows = $this->csPageObj->rip_all_block_rows($this->templateVar); - - #if(count($blockRows) < 2) { - # //not enough blocks, or they're not properly named. - # throw new exception("cs_tabs::load_tabs_template(): failed to retrieve the required block rows"); - #} - }//end load_tabs_template() - //--------------------------------------------------------------------------------------------- - - - - //--------------------------------------------------------------------------------------------- public function add_tab_array(array $tabs, $useSuffix=null) { $retval = 0; foreach($tabs as $name=>$url) { @@ -120,7 +96,7 @@ /** * Call this to add the parsed tabs into the page. */ - public function display_tabs() { + public function display_tabs(array $blockRows) { if(!strlen($this->selectedTab)) { $keys = array_keys($this->tabsArr); @@ -128,7 +104,6 @@ } if(is_array($this->tabsArr) && count($this->tabsArr)) { - $this->load_tabs_template(); $finalString = ""; //loop through the array. foreach($this->tabsArr as $tabName=>$tabData) { @@ -141,11 +116,13 @@ $blockRowName = 'selected_'. $suffix; } - if(isset($this->csPageObj->templateRows[$blockRowName])) { - $useTabContent = $this->csPageObj->templateRows[$blockRowName]; + if(isset($blockRows[$blockRowName])) { + $useTabContent = $blockRows[$blockRowName]; } else { - throw new exception(__METHOD__ ."(): failed to load block row (". $blockRowName .") for tab (". $tabName .")". $this->csPageObj->gfObj->debug_print($this->csPageObj->templateRows,0)); + throw new exception(__METHOD__ ."(): failed to load block row " . + "(". $blockRowName .") for tab (". $tabName .")". + $this->gfObj->debug_print($blockRows,0)); } $parseThis = array( @@ -153,17 +130,15 @@ 'url' => $url, 'cleanTitle' => preg_replace('/[^a-zA-Z0-9]/', '_', $tabName) ); - $finalString .= $this->csPageObj->mini_parser($useTabContent, $parseThis, '%%', '%%'); + $finalString .= $this->gfObj->mini_parser($useTabContent, $parseThis, '%%', '%%'); } - - //now parse it onto the page. - $this->csPageObj->add_template_var($this->templateVar, $finalString); } else { //something bombed. throw new exception(__METHOD__ ."(): no tabs to add"); } + return($finalString); }//end display_tabs() //--------------------------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |