/** * Returns if the given component requests https * * Return value is cached. */ public static function doesComponentRequestHttps(Kwf_Component_Data $data) { $showInvisible = Kwf_Component_Data_Root::getShowInvisible(); $foundRequestHttps = false; if (!$showInvisible) { //don't cache in preview $cacheId = 'reqHttps-' . $data->componentId; $foundRequestHttps = Kwf_Cache_Simple::fetch($cacheId); } if ($foundRequestHttps === false) { $foundRequestHttps = 0; //don't use false, false means not-cached if (Kwf_Component_Abstract::getFlag($data->componentClass, 'requestHttps')) { $foundRequestHttps = true; } if (!$foundRequestHttps && $data->getRecursiveChildComponents(array('page' => false, 'flags' => array('requestHttps' => true)))) { $foundRequestHttps = true; } if (!$showInvisible) { //don't cache in preview Kwf_Cache_Simple::add($cacheId, $foundRequestHttps); } } return $foundRequestHttps; }
public function __construct() { $this->_enableCache = true; if (Kwf_Component_Data_Root::getShowInvisible()) { $this->_enableCache = false; } }
public function getChildData($parentData, $select = array()) { if (is_array($select)) { $select = new Kwf_Component_Select($select); } if (($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) && substr($id, 0, 1) == '_') { $select->whereId(substr($id, 1)); } if ($parentData) { if ($parentData->generator != $this && $parentData->componentClass != $this->getClass()) { return array(); } } $filename = null; $limit = null; $ignoreVisible = $select->hasPart(Kwf_Component_Select::IGNORE_VISIBLE) ? $select->getPart(Kwf_Component_Select::IGNORE_VISIBLE) : false; if (Kwf_Component_Data_Root::getShowInvisible()) { $ignoreVisible = true; } $select = clone $select; // Nach Filename selbst suchen, da ja andere Sprache if ($select->hasPart(Kwf_Component_Select::WHERE_FILENAME)) { $filename = $select->getPart(Kwf_Component_Select::WHERE_FILENAME); $select->unsetPart(Kwf_Component_Select::WHERE_FILENAME); } // Limit auch selbst beachten, da in slave eigenes visible gesetzt ist if ($select->hasPart(Kwf_Component_Select::LIMIT_COUNT)) { $limit = $select->getPart(Kwf_Component_Select::LIMIT_COUNT); $select->unsetPart(Kwf_Component_Select::LIMIT_COUNT); } $select->ignoreVisible(); $ret = array(); $components = parent::getChildData($parentData, $select); foreach ($components as $key => $c) { if (($ignoreVisible || $c->visible || $c->isHome) && (!$filename || $c->filename == $filename)) { $ret[$key] = $c; } if ($limit && count($ret) == $limit) { return $ret; } } if ($filename) { $componentIds = array(); foreach ($components as $key => $c) { $componentIds[$c->dbId] = $key; } $model = $this->getHistoryModel(); $select = $model->select()->whereEquals('component_id', array_keys($componentIds))->whereEquals('filename', $filename)->order('date', 'DESC'); $rows = $model->export(Kwf_Model_Interface::FORMAT_ARRAY, $select, array('columns' => array('component_id'))); foreach ($rows as $row) { $key = $componentIds[$row['component_id']]; $ret[$key] = $components[$key]; if ($limit && count($ret) == $limit) { return $ret; } } } return $ret; }
public function sendContent($includeMaster) { //show content only in preview, else a 404 if (!Kwf_Component_Data_Root::getShowInvisible()) { throw new Kwf_Exception_NotFound(); } parent::sendContent($includeMaster); }
public static function __getProcessInputComponents($data) { $showInvisible = Kwf_Component_Data_Root::getShowInvisible(); $cacheId = 'procI-' . $data->componentId; $success = false; if (!$showInvisible) { //don't cache in preview $cacheContents = Kwf_Cache_Simple::fetch($cacheId, $success); //cache is cleared in Kwf_Component_Events_ProcessInputCache } if (!$success) { $datas = array(); foreach (self::_findProcessInputComponents($data) as $p) { $plugins = array(); $c = $p; do { foreach ($c->getPlugins('Kwf_Component_Plugin_Interface_SkipProcessInput') as $i) { $plugins[] = array('pluginClass' => $i, 'componentId' => $c->componentId); } $isPage = $c->isPage; $c = $c->parent; } while ($c && !$isPage); $datas[] = array('data' => $p, 'plugins' => $plugins); } if (!$showInvisible) { $cacheContents = array(); foreach ($datas as $p) { $cacheContents[] = array('data' => $p['data']->kwfSerialize(), 'plugins' => $p['plugins']); } Kwf_Cache_Simple::add($cacheId, $cacheContents); } } else { $datas = array(); foreach ($cacheContents as $d) { $datas[] = array('data' => Kwf_Component_Data::kwfUnserialize($d['data']), 'plugins' => $d['plugins']); } } //ask SkipProcessInput plugins if it should be skipped //evaluated every time $process = array(); foreach ($datas as $d) { foreach ($d['plugins'] as $p) { $plugin = Kwf_Component_Plugin_Abstract::getInstance($p['pluginClass'], $p['componentId']); $result = $plugin->skipProcessInput(); if ($result === Kwf_Component_Plugin_Interface_SkipProcessInput::SKIP_SELF_AND_CHILDREN) { continue 2; } if ($result === Kwf_Component_Plugin_Interface_SkipProcessInput::SKIP_SELF && $p['componentId'] == $d['data']->componentId) { continue 2; } } $process[] = $d['data']; } return $process; }
protected function _formatSelect($parentData, $select) { $ret = parent::_formatSelect($parentData, $select); if (!$ret) { return $ret; } $ignoreVisible = $select && $select->getPart(Kwf_Component_Select::IGNORE_VISIBLE); if (!$ignoreVisible) { $ignoreVisible = Kwf_Component_Data_Root::getShowInvisible(); $ret->where('date <= CURDATE()'); } $ret->whereEquals('deleted', 0); return $ret; }
public function getChildData($parentData, $select = array()) { if (is_array($select)) { $select = new Kwf_Component_Select($select); } if (($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) && substr($id, 0, 1) == '_') { $select->whereId(substr($id, 1)); } if ($parentData) { if ($parentData->generator != $this && $parentData->componentClass != $this->getClass()) { return array(); } } $filename = null; $limit = null; $ignoreVisible = $select->hasPart(Kwf_Component_Select::IGNORE_VISIBLE) ? $select->getPart(Kwf_Component_Select::IGNORE_VISIBLE) : false; if (Kwf_Component_Data_Root::getShowInvisible()) { $ignoreVisible = true; } $select = clone $select; // Nach Filename selbst suchen, da ja andere Sprache if ($select->hasPart(Kwf_Component_Select::WHERE_FILENAME)) { $filename = $select->getPart(Kwf_Component_Select::WHERE_FILENAME); $select->unsetPart(Kwf_Component_Select::WHERE_FILENAME); } // Limit auch selbst beachten, da in slave eigenes visible gesetzt ist if ($select->hasPart(Kwf_Component_Select::LIMIT_COUNT)) { $limit = $select->getPart(Kwf_Component_Select::LIMIT_COUNT); $select->unsetPart(Kwf_Component_Select::LIMIT_COUNT); } $select->ignoreVisible(); $ret = array(); foreach (parent::getChildData($parentData, $select) as $key => $c) { if (($ignoreVisible || $c->visible || $c->isHome) && (!$filename || $c->filename == $filename)) { $ret[$key] = $c; } if ($limit && count($ret) == $limit) { return $ret; } } return $ret; }
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer) { $ret = parent::getTemplateVars($renderer); $ret['test'] = Kwf_Component_Data_Root::getShowInvisible() ? 'foo' : 'bar'; return $ret; }
protected function _formatSelect($parentData, $select) { $select = parent::_formatSelect($parentData, $select); if (is_null($select)) { return null; } if ($this->_getUseComponentId()) { if ($parentData) { $select->whereEquals('component_id', $parentData->dbId); } else { if ($p = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF)) { $ors = array(new Kwf_Model_Select_Expr_StartsWith('component_id', $p->dbId . '-'), new Kwf_Model_Select_Expr_Equal('component_id', $p->dbId)); foreach ($this->_getPossibleIndirectDbIdShortcuts($p->componentClass) as $dbIdShortcut) { $ors[] = new Kwf_Model_Select_Expr_StartsWith('component_id', $dbIdShortcut); } $select->where(new Kwf_Model_Select_Expr_Or($ors)); } } } $select = $this->_formatSelectId($select); if (is_null($select)) { return null; } if (in_array('pos', $this->_getModel()->getOwnColumns()) && !$select->hasPart(Kwf_Component_Select::ORDER)) { $select->order("pos"); } $showInvisible = Kwf_Component_Data_Root::getShowInvisible(); if (!$select->getPart(Kwf_Component_Select::IGNORE_VISIBLE) && $this->_getModel()->hasColumn('visible') && !$showInvisible) { $select->whereEquals("visible", 1); } if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) { $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES); if (!$selectClasses) { return null; } $childClasses = $this->_settings['component']; $keys = array(); foreach ($selectClasses as $selectClass) { $keys = array_merge($keys, array_keys($childClasses, $selectClass)); } if (!$keys) { return null; } if (count($childClasses) == 1) { if (!in_array(key($childClasses), $keys)) { return null; } } else { if (!$this->_getModel()->hasColumn('component')) { throw new Kwf_Exception("Column component does not exist for a generator '{$this->getGeneratorKey()}' in '{$this->_class}'"); } $select->whereEquals('component', $keys); } } return $select; }
public function getChildData($parentData, $select = array()) { Kwf_Benchmark::count('GenPage::getChildData'); $select = $this->_formatSelect($parentData, $select); if (is_null($select)) { return array(); } $pageIds = $this->_getPageIds($parentData, $select); $ret = array(); foreach ($pageIds as $pageId) { $page = $this->_getPageData($pageId); if (!$page) { continue; } //can happen for floating page (without valid parent) if ($select->hasPart(Kwf_Component_Select::WHERE_SHOW_IN_MENU)) { $menu = $select->getPart(Kwf_Component_Select::WHERE_SHOW_IN_MENU); if ($menu == $page['hide']) { continue; } } if ($select->getPart(Kwf_Component_Select::IGNORE_VISIBLE)) { } else { if (!Kwf_Component_Data_Root::getShowInvisible()) { if (!$page['parent_visible']) { continue; } } } $d = $this->_createData($parentData, $pageId, $select); if ($d) { $ret[] = $d; } if ($select->hasPart(Kwf_Model_Select::LIMIT_COUNT)) { if (count($ret) >= $select->getPart(Kwf_Model_Select::LIMIT_COUNT)) { break; } } } return $ret; }
/** * Helper function that can be used in Component implementing Kwf_Media_Output_IsValidInterface * to check if the component is visible to the current user */ public static function isValid($id) { $writeCache = false; $cacheId = 'media-isvalid-component-' . $id; $plugins = Kwf_Cache_Simple::fetch($cacheId, $success); if ($success) { //success means it's VALID and we successfully fetched the $plugins $ret = Kwf_Media_Output_IsValidInterface::VALID; } else { $ret = Kwf_Media_Output_IsValidInterface::VALID; $c = Kwf_Component_Data_Root::getInstance()->getComponentById($id); if (!$c) { $c = Kwf_Component_Data_Root::getInstance()->getComponentById($id, array('ignoreVisible' => true)); if (!$c) { return Kwf_Media_Output_IsValidInterface::INVALID; } if (Kwf_Component_Data_Root::getShowInvisible()) { //preview im frontend $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE; } else { if (Kwf_Registry::get('acl')->isAllowedComponentById($id, $c->componentClass, Kwf_Registry::get('userModel')->getAuthedUser())) { //paragraphs preview in backend $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE; } else { if (Kwf_Registry::get('acl')->isAllowedUser(Kwf_Registry::get('userModel')->getAuthedUser(), 'kwf_component_preview', 'view')) { //perview user in frontend $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE; } else { return Kwf_Media_Output_IsValidInterface::ACCESS_DENIED; } } } } //$ret can be VALID or VALID_DONT_CACHE at this point $plugins = array(); $onlyInherit = false; while ($c) { $p = Kwc_Abstract::getSetting($c->componentClass, 'pluginsInherit'); if (!$onlyInherit) { $p = array_merge($p, Kwc_Abstract::getSetting($c->componentClass, 'plugins')); } foreach ($p as $plugin) { if (is_instance_of($plugin, 'Kwf_Component_Plugin_Interface_Login')) { $plugins[] = array('plugin' => $plugin, 'id' => $c->componentId); } } if ($c->isPage) { $onlyInherit = true; } $c = $c->parent; } if ($ret == Kwf_Media_Output_IsValidInterface::VALID) { //only cache VALID, VALID_DONT_CACHE can't be cached $writeCache = true; } } foreach ($plugins as $p) { $plugin = $p['plugin']; $plugin = new $plugin($p['id']); if ($plugin->isLoggedIn()) { $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE; } else { $c = Kwf_Component_Data_Root::getInstance()->getComponentById($id); $userModel = Kwf_Registry::get('userModel'); if (Kwf_Registry::get('acl')->isAllowedComponentById($id, $c->componentClass, $userModel ? $userModel->getAuthedUser() : null)) { //allow preview in backend always $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE; } else { $ret = Kwf_Media_Output_IsValidInterface::ACCESS_DENIED; break; } } } if ($writeCache && $ret == Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE) { //only cache VALID_DONT_CACHE, not VALID as it will be cached in Kwf_Media::getOutput //this cache doesn't need to be cleared, because of it's lifetime Kwf_Cache_Simple::add($cacheId, $plugins, 60 * 60 - 1); //one second less than isValid cache in Kwf_Media } return $ret; }
public function renderMaster($component, &$hasDynamicParts = false) { static $benchmarkEnabled; if (!isset($benchmarkEnabled)) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); } if (Kwf_Component_Data_Root::getShowInvisible()) { $hasDynamicParts = true; } $content = false; if ($this->_enableCache) { $content = Kwf_Component_Cache::getInstance()->load($component->componentId, $this->_getRendererName(), 'fullPage'); $this->_minLifetime = null; } Kwf_Benchmark::checkpoint('load fullPage cache'); $statType = null; if (!$content) { if ($benchmarkEnabled) { $startTime = microtime(true); } if (!$this->_enableCache || ($content = Kwf_Component_Cache::getInstance()->load($component, $this->_getRendererName(), 'page')) === null) { $masterHelper = new Kwf_Component_View_Helper_Master(); $masterHelper->setRenderer($this); $content = $masterHelper->master($component); if ($this->_enableCache) { Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'page', '', '', null); $statType = 'miss'; } else { $statType = 'noviewcache'; } } else { $statType = 'hit'; } if ($statType) { Kwf_Benchmark::count("rendered {$statType}", $component->componentId . ': page'); } Kwf_Benchmark::countLog('render-' . $statType); if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint($component->componentId . ' page', microtime(true) - $startTime); } Kwf_Benchmark::checkpoint('render page'); $pass1Cacheable = true; $content = $this->_renderPass1($content, $pass1Cacheable); if (!$pass1Cacheable) { $hasDynamicParts = true; } Kwf_Benchmark::checkpoint('render pass 1'); if ($this->_enableCache && $pass1Cacheable) { Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'fullPage', '', '', $this->_minLifetime); } Kwf_Benchmark::count("rendered miss", $component->componentId . ': fullPage'); Kwf_Benchmark::countLog('fullpage-miss'); } else { Kwf_Benchmark::count("rendered hit", $component->componentId . ': fullPage'); Kwf_Benchmark::countLog('fullpage-hit'); } $content = $this->_renderPass2($content, $hasDynamicParts); Kwf_Benchmark::checkpoint('render pass 2'); Kwf_Component_Cache::getInstance()->writeBuffer(); foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) { $content = $plugin->processOutput($content, $component); } return $content; }
public function getTemplateVars() { $ret = parent::getTemplateVars(); $ret['test'] = Kwf_Component_Data_Root::getShowInvisible() ? 'foo' : 'bar'; return $ret; }