public function componentWithMaster(array $componentWithMaster) { $last = array_pop($componentWithMaster); $component = $last['data']; if ($last['type'] == 'master') { $innerComponent = $componentWithMaster[0]['data']; $vars = $component->getComponent()->getMasterTemplateVars($innerComponent, $this->_getRenderer()); $vars['componentWithMaster'] = $componentWithMaster; $masterTemplate = $this->_getRenderer()->getTemplate($component, 'Master'); if (substr($masterTemplate, -4) == '.tpl') { $view = new Kwf_Component_View($this->_getRenderer()); $view->assign($vars); $ret = $view->render($masterTemplate); } else { $twig = new Kwf_Component_Renderer_Twig_Environment($this->_getRenderer()); $ret = $twig->render($masterTemplate, $vars); } $ret = $this->_replaceKwfUp($ret); return $ret; } else { if ($last['type'] == 'component') { $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($this->_getRenderer()); return '<div class="kwfMainContent">' . "\n " . $helper->component($component) . "\n" . '</div><!--/kwfMainContent-->' . "\n"; } else { throw new Kwf_Exception("invalid type"); } } }
public function processOutput($output, $renderer) { // append data of child-component to view-cache $loggedIn = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_componentId, array('ignoreVisible' => true))->getChildComponent('-loggedIn'); $h = new Kwf_Component_View_Helper_Component(); $h->setRenderer($renderer); return $output . '{kwfappendboxdata}' . $h->component($loggedIn); }
/** * Renders a single component without master */ public function renderComponent($component, &$hasDynamicParts = false) { $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($this); $content = $helper->component($component); $ret = $this->_renderPass2($content, $hasDynamicParts); Kwf_Component_Cache::getInstance()->writeBuffer(); return $ret; }
public function processOutput($output, $renderer) { $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_componentId, array('ignoreVisible' => true))->getComponent(); $itemPage = $component->getDefaultItemPage(); if ($itemPage) { $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($renderer); $html = $helper->component($component->getLargeComponent($itemPage)); $output = str_replace('<div class="listSwitchLargeContent"></div>', '<div class="listSwitchLargeContent">%largeContentBegin%' . $html . '%largeContentEnd%</div>', $output); $preview = $component->getPreviewComponent($itemPage); $output = str_replace('<div id="' . $preview->componentId . '" class="listSwitchItem', '<div id="' . $preview->componentId . '" class="listSwitchItem defaultActive', $output); } return $output; }
public function processOutput($output, $renderer) { if (is_null($this->_currentItem)) { $output = str_replace(array('%largeContentBegin%', '%largeContentEnd%'), '', $output); } else { $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($renderer); $html = $helper->component($this->_currentItem); $output = preg_replace('/%largeContentBegin%.*?%largeContentEnd%/s', $html, $output); $output = preg_replace('/class="listSwitchItem(.*)defaultActive/', 'class="listSwitchItem', $output); $output = str_replace('<div id="' . $this->_currentPreview->componentId . '" class="listSwitchItem', '<div id="' . $this->_currentPreview->componentId . '" class="listSwitchItem defaultActive', $output); } return $output; }
public function renderComponent($component, &$hasDynamicParts = false) { static $benchmarkEnabled; if (!isset($benchmarkEnabled)) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); } $content = false; if ($this->_enableCache && $component->isPage) { //use fullPage cache only for pages $content = Kwf_Component_Cache::getInstance()->load($component->componentId, $this->_getRendererName(), 'fullPage'); $this->_minLifetime = null; } Kwf_Benchmark::checkpoint('load fullPage cache'); $statType = null; if (!$content) { $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($this); $content = $helper->component($component); $pass1Cacheable = true; $content = $this->_renderPass1($content, $pass1Cacheable); Kwf_Benchmark::checkpoint('render pass 1'); if (strpos($content, '<kwc2 ') === false) { //if there are no components that need second render cycle start HtmlParser now //and cache result in fullPage cache if ($this->_renderFormat == self::RENDER_HTML && $this->_htmlStyles) { $p = new Kwc_Mail_HtmlParser($this->_htmlStyles); $content = $p->parse($content); Kwf_Benchmark::checkpoint('html parser (in fullPage)'); } } if ($this->_enableCache && $pass1Cacheable && $component->isPage) { Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'fullPage', '', '', $this->_minLifetime); } } $hasPass2Placeholders = strpos($content, '<kwc2 ') !== false; $content = $this->_renderPass2($content); Kwf_Benchmark::checkpoint('render pass 2'); //if there where components that needed second render cycle the HtmlParser wasn't started yet //do that now (should be avoided as it's slow) if ((!$component->isPage || $hasPass2Placeholders) && $this->_renderFormat == self::RENDER_HTML && $this->_htmlStyles) { $p = new Kwc_Mail_HtmlParser($this->_htmlStyles); $content = $p->parse($content); Kwf_Benchmark::checkpoint('html parser'); } Kwf_Component_Cache::getInstance()->writeBuffer(); return $content; }
private function _getContent($renderer) { $childComponents = array(); foreach ($this->getData()->getChildComponents(array('generator' => 'child')) as $c) { $childComponents[$c->id] = $c; } $c = $this->_getRow()->content; preg_match_all('#{([a-z0-9]+)}#', $c, $m); if ($m[0]) { $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($renderer); foreach ($m[1] as $i) { if (isset($childComponents[$i]) && $childComponents[$i] instanceof Kwf_Component_Data) { $c = str_replace('{' . $i . '}', $helper->component($childComponents[$i]), $c); } } } return $c; }
public function componentWithMaster(array $componentWithMaster) { $last = array_pop($componentWithMaster); $component = $last['data']; if ($last['type'] == 'master') { $innerComponent = $componentWithMaster[0]['data']; $vars = $component->getComponent()->getMasterTemplateVars($innerComponent, $this->_getRenderer()); $vars['componentWithMaster'] = $componentWithMaster; if (isset($vars['template'])) { $masterTemplate = $vars['template']; } else { $masterTemplate = $this->_getRenderer()->getTemplate($component, 'Master'); } if (substr($masterTemplate, -4) == '.tpl') { $view = new Kwf_Component_View($this->_getRenderer()); $view->assign($vars); $ret = $view->render($masterTemplate); } else { $twig = new Kwf_Component_Renderer_Twig_Environment($this->_getRenderer()); $ret = $twig->render($masterTemplate, $vars); } $ret = $this->_replaceKwfUp($ret); return $ret; } else { if ($last['type'] == 'component') { $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($this->_getRenderer()); $kwfUniquePrefix = Kwf_Config::getValue('application.uniquePrefix'); if ($kwfUniquePrefix) { $kwfUniquePrefix = $kwfUniquePrefix . '-'; } return '<main class="' . $kwfUniquePrefix . 'kwfMainContent">' . "\n " . $helper->component($component) . "\n" . '</main><!--/' . $kwfUniquePrefix . 'kwfMainContent-->' . "\n"; } else { throw new Kwf_Exception("invalid type"); } } }
public function includeCode($position) { $data = $this->_getView()->component; $ret = ''; if ($position == 'header') { $helper = new Kwf_View_Helper_DebugData(); $ret .= $helper->debugData(); } $flag = $position == 'header' ? 'hasHeaderIncludeCode' : 'hasFooterIncludeCode'; $cmps = $data->getPage()->getRecursiveChildComponents(array('flags' => array($flag => true))); if (Kwc_Abstract::getFlag($data->componentClass, $flag)) { $cmps[] = $data; } $statisticsBoxUsed = false; $assetsBoxUsed = false; foreach ($cmps as $c) { $includeCode = $c->getComponent()->getIncludeCode($position); if (is_string($includeCode)) { $ret .= $includeCode; } else { if (is_object($includeCode) && $includeCode instanceof Kwf_Component_Data) { $componentHelper = new Kwf_Component_View_Helper_Component(); $componentHelper->setRenderer($this->_getRenderer()); $componentHelper->setView($this->_getView()); $ret .= $componentHelper->component($includeCode); if (is_instance_of($includeCode->componentClass, 'Kwc_Statistics_Analytics_Component') || is_instance_of($includeCode->componentClass, 'Kwc_Statistics_Piwik_Component')) { $statisticsBoxUsed = true; } if (is_instance_of($includeCode->componentClass, 'Kwc_Box_Assets_Component')) { $assetsBoxUsed = true; } } else { if (is_null($includeCode)) { } else { throw new Kwf_Exception("invalid getIncludeCode return type"); } } } } if ($position == 'header') { if ($v = Kwf_Config::getValue('kwc.favicon')) { $ret .= "<link rel=\"shortcut icon\" href=\"{$v}\" />\n"; } if (!$assetsBoxUsed) { //add default assets if there was no box $a = new Kwf_View_Helper_Assets(); $ret .= $a->assets(Kwf_Assets_Package_Default::getInstance('Frontend'), null); } $helper = new Kwf_Component_View_Helper_Dynamic(); $helper->setRenderer($this->_getRenderer()); $helper->setView($this->_getView()); $ret .= $helper->dynamic('SessionToken'); } else { if ($position == 'footer') { if (!$statisticsBoxUsed) { //if there was no statistics box output default code //box is required for eg. multidomains $cfg = Kwf_Config::getValueArray('statistics'); if (isset($cfg['analytics']['code']) && $cfg['analytics']['code']) { throw new Kwf_Exception('To support analytics add Kwc_Statistics_Analytics_Component as a box.'); } if (isset($cfg['piwik']['id']) && $cfg['piwik']['id']) { throw new Kwf_Exception('To support piwik add Kwc_Statistics_Piwik_Component as a box.'); } } //see http://nexxar.wordpress.com/2010/10/07/speeding-up-jquery-ready-on-ie/ $ret .= "\n"; $ret .= "<!--[if lt IE 9]>\n"; $ret .= "<script type=\"text/javascript\">\n"; $ret .= " jQuery.ready();\n"; $ret .= "</script>\n"; $ret .= "<![endif]-->\n"; } } return $ret; }
public function includeCode($position) { $data = $this->_getView()->component; $ret = ''; if ($position == 'header') { if (Kwf_Config::getValue('application.kwf.name') == 'Koala Framework') { $ret .= "<!--\n"; $ret .= " This website is powered by Koala Web Framework CMS Version " . Kwf_Config::getValue('application.kwf.version') . ".\n"; $ret .= " Koala Framework is a free open source Content Management Framework licensed under BSD.\n"; $ret .= " http://www.koala-framework.org\n"; $ret .= "-->\n"; } $helper = new Kwf_View_Helper_DebugData(); $ret .= $helper->debugData(); } $flag = $position == 'header' ? 'hasHeaderIncludeCode' : 'hasFooterIncludeCode'; $cmps = $data->getPage()->getRecursiveChildComponents(array('flags' => array($flag => true))); if (Kwc_Abstract::getFlag($data->componentClass, $flag)) { $cmps[] = $data; } $statisticsBoxUsed = false; $assetsBoxUsed = false; foreach ($cmps as $c) { $includeCode = $c->getComponent()->getIncludeCode($position); if (is_string($includeCode)) { $ret .= $includeCode; } else { if (is_object($includeCode) && $includeCode instanceof Kwf_Component_Data) { $componentHelper = new Kwf_Component_View_Helper_Component(); $componentHelper->setRenderer($this->_getRenderer()); $componentHelper->setView($this->_getView()); $ret .= $componentHelper->component($includeCode); if (is_instance_of($includeCode->componentClass, 'Kwc_Statistics_Analytics_Component') || is_instance_of($includeCode->componentClass, 'Kwc_Statistics_Piwik_Component')) { $statisticsBoxUsed = true; } if (is_instance_of($includeCode->componentClass, 'Kwc_Box_Assets_Component')) { $assetsBoxUsed = true; } } else { if (is_null($includeCode)) { } else { throw new Kwf_Exception("invalid getIncludeCode return type"); } } } } if ($position == 'header') { if ($v = Kwf_Config::getValue('kwc.favicon')) { $v = Kwf_Setup::getBaseUrl() . $v; $ret .= "<link rel=\"shortcut icon\" href=\"{$v}\" />\n"; } if (!$assetsBoxUsed) { //add default assets if there was no box $a = new Kwf_View_Helper_Assets(); $ret .= $a->assets(Kwf_Assets_Package_Default::getInstance('Frontend'), null); } $helper = new Kwf_Component_View_Helper_Dynamic(); $helper->setRenderer($this->_getRenderer()); $helper->setView($this->_getView()); $ret .= $helper->dynamic('SessionToken'); } else { if ($position == 'footer') { if (!$statisticsBoxUsed) { //if there was no statistics box output default code //box is required for eg. multidomains $cfg = Kwf_Config::getValueArray('statistics'); if (isset($cfg['analytics']['code']) && $cfg['analytics']['code']) { throw new Kwf_Exception('To support analytics add Kwc_Statistics_Analytics_Component as a box.'); } if (isset($cfg['piwik']['id']) && $cfg['piwik']['id']) { throw new Kwf_Exception('To support piwik add Kwc_Statistics_Piwik_Component as a box.'); } } } } return $ret; }