public function preDispatch() { if ($this->_getParam('applicationAssetsVersion') && $this->getHelper('ViewRenderer')->isJson()) { if (Kwf_Assets_Dispatcher::getInstance()->getAssetsVersion() != $this->_getParam('applicationAssetsVersion')) { $this->_forward('json-wrong-version', 'error', 'kwf_controller_action_error'); return; } } $this->_validateSessionToken(); $t = microtime(true); $allowed = $this->_isAllowedResource(); if ($allowed) { $allowed = $this->_isAllowed($this->_getAuthData()); } if (!$allowed) { $params = array('role' => $this->_getUserRole()); if ($this->getHelper('ViewRenderer')->isJson()) { $this->_forward('json-login', 'login', 'kwf_controller_action_user', $params); } else { $params = array('location' => $this->getRequest()->getBaseUrl() . '/' . ltrim($this->getRequest()->getPathInfo(), '/')); $this->_forward('index', 'login', 'kwf_controller_action_user', $params); } } Kwf_Benchmark::subCheckpoint('check acl', microtime(true) - $t); }
public function sendContent($includeMaster) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); if ($benchmarkEnabled) { $startTime = microtime(true); } $process = $this->_getProcessInputComponents($includeMaster); if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime); } self::_callProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('processInput'); } $hasDynamicParts = false; $out = $this->_render($includeMaster, $hasDynamicParts); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('render'); } header('Content-Type: text/html; charset=utf-8'); if (!$hasDynamicParts) { $lifetime = 60 * 60; header('Cache-Control: public, max-age=' . $lifetime); header('Expires: ' . gmdate("D, d M Y H:i:s \\G\\M\\T", time() + $lifetime)); header('Pragma: public'); } echo $out; self::_callPostProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('postProcessInput'); } }
public function renderMaster($component) { static $benchmarkEnabled; if (!isset($benchmarkEnabled)) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); } $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); 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); Kwf_Benchmark::checkpoint('render pass 2'); Kwf_Component_Cache::getInstance()->writeBuffer(); return $content; }
public function preDispatch() { $t = microtime(true); if (!isset($this->_form)) { if (isset($this->_formName)) { $this->_form = new $this->_formName(null, $this->_getParam('class')); } else { $this->_form = Kwc_Abstract_Form::createComponentForm($this->_getParam('class'), 'component'); } } Kwf_Benchmark::subCheckpoint('create component form', microtime(true) - $t); $this->_form->setBodyStyle('padding: 10px'); $this->_form->setId($this->_getParam('componentId')); parent::preDispatch(); }
/** * Lädt Resourcen die von Komponenten kommen. * Muss extra aufgerufen werden wenn diese Resourcen benötigt werden, aus * performance gründen */ public function loadKwcResources() { if (!Kwf_Registry::get('db')) { return; } //if we don't have a db configured yet skip kwc resources. required to be able to build assets without db if ($this->_kwcResourcesLoaded) { return; } $this->_kwcResourcesLoaded = true; $t = microtime(true); $menuConfigs = array(); foreach (Kwc_Abstract::getComponentClasses() as $c) { if (Kwc_Abstract::getFlag($c, 'hasResources')) { Kwc_Admin::getInstance($c)->addResources($this); } if (Kwc_Abstract::hasSetting($c, 'menuConfig') && Kwc_Abstract::getSetting($c, 'menuConfig')) { $menuConfigs[] = Kwf_Component_Abstract_MenuConfig_Abstract::getInstance($c); } } usort($menuConfigs, array(get_class($this), '_compareMenuConfig')); foreach ($menuConfigs as $cfg) { $cfg->addResources($this); } Kwf_Benchmark::subCheckpoint('kwc resources', microtime(true) - $t); }
public function sendContent($includeMaster) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); if (Kwf_Util_Https::supportsHttps()) { $foundRequestHttps = Kwf_Util_Https::doesComponentRequestHttps($this->_data); if (isset($_SERVER['HTTPS'])) { //we are on https if (!$foundRequestHttps && isset($_COOKIE['kwcAutoHttps']) && !Zend_Session::sessionExists() && !Zend_Session::isStarted()) { //we where auto-redirected to https but don't need https anymore setcookie('kwcAutoHttps', '', 0, '/'); //delete cookie Kwf_Util_Https::ensureHttp(); } } else { //we are on http if ($foundRequestHttps) { setcookie('kwcAutoHttps', '1', 0, '/'); Kwf_Util_Https::ensureHttps(); } } if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('check requestHttps'); } } if ($benchmarkEnabled) { $startTime = microtime(true); } $process = $this->_getProcessInputComponents($includeMaster); if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime); } self::_callProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('processInput'); } $hasDynamicParts = false; $out = $this->_render($includeMaster, $hasDynamicParts); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('render'); } header('Content-Type: text/html; charset=utf-8'); if (!$hasDynamicParts) { $lifetime = 60 * 60; header('Cache-Control: public, max-age=' . $lifetime); header('Expires: ' . gmdate("D, d M Y H:i:s \\G\\M\\T", time() + $lifetime)); header('Pragma: public'); } echo $out; self::_callPostProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('postProcessInput'); } }
/** * Check if user is logged in (faster than directly calling user model) * * Only asks user model (expensive) when there is something stored in the session * * @return boolean if user is logged in */ public static function hasAuthedUser() { static $benchmarkEnabled; if (!isset($benchmarkEnabled)) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); } if ($benchmarkEnabled) { $t = microtime(true); } if (!Zend_Session::isStarted() && !Zend_Session::sessionExists() && !Kwf_Config::getValue('autologin')) { if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint('hasAuthedUser: no session', microtime(true) - $t); } return false; } if (!Kwf_Auth::getInstance()->getStorage()->read()) { if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint('hasAuthedUser: storage empty', microtime(true) - $t); } return false; } $m = Kwf_Registry::get('userModel'); if (!$m) { return false; } $ret = $m->hasAuthedUser(); if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint('hasAuthedUser: asked model', microtime(true) - $t); } return $ret; }
public function preDispatch() { parent::preDispatch(); $t = microtime(true); if (!isset($this->_form)) { if (isset($this->_formName)) { $this->_form = new $this->_formName(); } else { $this->_form = new Kwf_Form(); } } foreach ($this->_fields as $k => $field) { if (!isset($field['type'])) { throw new Kwf_Exception("no type for field no {$k} specified"); } $cls = 'Kwf_Form_Field_' . $field['type']; if (!class_exists($cls)) { throw new Kwf_Exception("Invalid type: Form-Field-Class {$cls} does not exist."); } $fieldObject = new $cls(); unset($field['type']); foreach ($field as $propName => $propValue) { $fieldObject->setProperty($propName, $propValue); } $this->_form->fields[] = $fieldObject; } if (!$this->_form->getModel()) { if (isset($this->_table)) { $this->_form->setTable($this->_table); } else { if (isset($this->_tableName)) { $this->_form->setTable(new $this->_tableName()); } else { if (isset($this->_modelName)) { $this->_form->setModel(new $this->_modelName()); } else { if (isset($this->_model)) { if (is_string($this->_model)) { $this->_form->setModel(Kwf_Model_Abstract::getInstance($this->_model)); } else { $this->_form->setModel($this->_model); } } } } } } $this->_initFields(); $this->_form->initFields(); $this->_form->trlStaticExecute(); if (!$this->_form->fields->first() instanceof Kwf_Form_Container_Tabs) { $this->_form->setBodyStyle('padding: 10px;'); } if (!$this->_form->getId()) { if (is_array($this->_form->getPrimaryKey())) { foreach ($this->_form->getPrimaryKey() as $key) { $id[$key] = $this->_getParam($key); } $this->_form->setId($id); } else { $this->_form->setId($this->_getParam($this->_form->getPrimaryKey())); } } Kwf_Benchmark::subCheckpoint('init form', microtime(true) - $t); }
/** * Render components (ie. expand <kwc ...>) * * Pass 1 for content that can be stored in fullPage cache, * 2 for everything else. 2 includes 1, so calling just with 2 also works * @param string render content */ protected function _renderPass2($ret, &$hasDynamicParts = false) { //execute all plugins that where added in pass 1 $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_USECACHE, $hasDynamicParts); $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_BEFORE, $hasDynamicParts); $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_REPLACE, $hasDynamicParts); $ret = $this->_findAndExecuteUseCacheDynamic($ret, $hasDynamicParts); static $benchmarkEnabled; if (!isset($benchmarkEnabled)) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); } $offset = 0; while ($target = $this->_getNextRenderTarget($ret, 2, $offset)) { if ($benchmarkEnabled) { $startTime = microtime(true); } if ($target['type'] == 'dynamic' && $target['config']['class'] == 'Kwf_Component_Dynamic_SessionToken' && !Kwf_Setup::hasAuthedUser()) { $hasDynamicParts = true; //yes, this is cheating, but a very common case that's worth optimizing using this hack $ret = substr($ret, 0, $target['start']) . '' . substr($ret, $target['end'] + 1); continue; } $helper = $this->_getHelper($target['type']); $statType = null; $content = null; if ($this->_enableCache && $target['isCacheable']) { $content = $this->_cacheLoad($target['componentId'], $target['type'], $target['value']); } if (!is_null($content)) { //cache hit $statType = 'hit'; //look for UseViewCache plugin in $content if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_USECACHE, $content)) { $hasDynamicParts = true; if (!$p['plugin']->useViewCache($this)) { //re-render, without <pluginC $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } else { //continue with content $content = $p['content']; } } else { //execute replace and before plugin if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_REPLACE, $content)) { $hasDynamicParts = true; $r = $p['plugin']->replaceOutput($this); if ($r !== false) { $content = $r; } else { $content = $p['content']; } } $content = $this->_findAndExecutePlugins($content, self::PLUGIN_TYPE_BEFORE, $hasDynamicParts); } $content = $this->_findAndExecuteUseCacheDynamic($content, $hasDynamicParts); } else { if ($this->_enableCache && $target['isCacheable']) { //cache miss $statType = 'miss'; $content = $this->_renderAndCache($target['componentId'], $target['type'], $target['value'], $target['config'], false); } else { $hasDynamicParts = true; //view cache disabled $statType = 'noviewcache'; $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } } $content = $helper->renderCached($content, $target['componentId'], $target['config']); $ret = substr($ret, 0, $target['start']) . $content . substr($ret, $target['end'] + 1); if ($statType) { if ($benchmarkEnabled) { Kwf_Benchmark::count("rendered {$statType}", $target['statId']); } Kwf_Benchmark::countLog('render-' . $statType); } if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint($target['componentId'] . ' ' . $target['type'], microtime(true) - $startTime); } } //execute Render Cached Dynamic, used eg for callback link modifier in componentLink while (($start = strpos($ret, '<rcd ')) !== false) { $hasDynamicParts = true; $startEnd = strpos($ret, '>', $start); $args = explode(' ', substr($ret, $start + 5, $startEnd - $start - 5)); $end = strpos($ret, '</rcd ' . $args[0] . '>'); $content = substr($ret, $startEnd + 1, $end - $startEnd - 1); if ($benchmarkEnabled) { $startTime = microtime(true); } $componentId = $args[0]; $type = $args[1]; $settings = json_decode($args[2], true); $content = $this->_getHelper($type)->renderCachedDynamic($content, $componentId, $settings); if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint("renderCachedDynamic {$type} {$componentId}", microtime(true) - $startTime); } $ret = substr($ret, 0, $start) . $content . substr($ret, $end + 7 + strlen($args[0])); } $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_AFTER, $hasDynamicParts); return $ret; }
public function getContent($includeMaster) { if ($this->_data->getBaseProperty('preLogin')) { $ignore = false; foreach (Kwf_Config::getValueArray('preLoginIgnoreIp') as $i) { $ip = $_SERVER['REMOTE_ADDR']; if ($ip == $i) { $ignore = true; } if (!$ignore && substr($i, -1) == '*') { $i = substr($i, 0, -1); if (substr($ip, 0, strlen($i)) == $i) { $ignore = true; } } if (!$ignore && substr($i, 0, 1) == '*') { $i = substr($i, 1); if (substr($ip, -strlen($i)) == $i) { $ignore = true; } } } Kwf_Setup::checkPreLogin($this->_data->getBaseProperty('preLoginUser'), $this->_data->getBaseProperty('preLoginPassword')); } $benchmarkEnabled = Kwf_Benchmark::isEnabled(); if ($benchmarkEnabled) { $startTime = microtime(true); } $process = $this->_getProcessInputComponents($includeMaster); if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime); } self::_callProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('processInput'); } $ret = array(); $hasDynamicParts = false; $ret['content'] = $this->_render($includeMaster, $hasDynamicParts); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('render'); } $ret['mimeType'] = 'text/html; charset=utf-8'; if (!$includeMaster) { $assetsBox = $this->_data->getChildComponent('-assets'); if ($assetsBox) { $ret['assets'] = $assetsBox->render(null, false, $hasDynamicParts); } else { $ret['assets'] = ''; } } if (!$hasDynamicParts) { $ret['lifetime'] = 60 * 60; } self::_callPostProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('postProcessInput'); } return $ret; }