* Author: Aart-Jan Boor * Wemag Advisering * Website: http://www.ktplugins.com * */ /** * KTPage child class that is designed to allow interception of page rendering * to adjust page output as provided by KT */ class KTPFwPage extends KTPage{ var $ktp_type; private $triggers; private $initialPortletsProcessed = false; /** * Constructor, runs the init_* methods of the registered triggers * @param object $type [optional] * @return */ function KTPFwPage($type = 'admin'){ $this->KTPage(); //run parent constructor $this->ktp_type = $type; $plugins = array(); $oRegistry =& KTPluginRegistry::getSingleton(); $pluginsList = $oRegistry->getPlugins(); foreach($pluginsList as $plugin){ $plugins[$plugin->sNamespace] = true; } //collect active triggers $res = DBUtil::getResultArray("SELECT * FROM ktp_fw_triggers"); if(PEAR::isError($res)){ KTPUtil::displayError("Can't read triggers: ".$res->message); } foreach($res as $trigger){ if(isset($plugins[$trigger['plugin']])){ if(!isset($this->triggers[$trigger['type']])){ $this->triggers[$trigger['type']] = array(); } $this->triggers[$trigger['type']][] = $trigger; } } //run required triggers if($type == 'admin'){ $this->runTriggers("admin_render"); }else{ $this->runTriggers("render"); } } function processInitialPortlets(){ //run portlet triggers $pTemp = $this->portlets; $this->portlets = array(); foreach($pTemp as $oPortlet){ $this->addPortlet($oPortlet); } $this->initialPortletsProcessed = true; } /** * KTPage class override. This method is called for adding a portlet * to the sidebar. By intercepting this method we can change some * aspects of the portlet layout, and refuse to add some portlets. * Again, this method is called by KT internal (blackbox) code. * * @param KTPortlet $oPortlet portlet to add */ function addPortlet($oPortlet){ if(!$this->initialPortletsProcessed){ $this->processInitialPortlets(); } if(count($this->triggers['add_portlet']) > 0){ $this->runTriggers("add_portlet",$oPortlet); }else{ parent::addPortlet($oPortlet); } } function runTriggers($type, $html = null){ foreach($this->triggers[$type] as $trigger){ require_once(KT_DIR.$trigger['file']); if($type=="add_portlet"){ $oTrig = new $trigger['class']; $this->portlets = $oTrig->runTrigger($html,$this->portlets); }else{ if(substr($type,-6) == 'output'){ $html = call_user_func(array($trigger['class'], 'runTrigger'), $html); }else{ call_user_func(array($trigger['class'], 'runTrigger')); } } } return $html; } /** * Renders page content and allows interceptions by KTplugins.com * interceptor methods prefixed by render_ * @return */ function render(){ ob_start(); parent::render(); $data = ob_get_contents(); ob_end_clean(); //run required triggers if($this->ktp_type == 'admin'){ $data = $this->runTriggers("admin_output",$data); }else{ $data = $this->runTriggers("output",$data); } echo $data; } } ?>