public static function getSessionToken() { if (!Kwf_Setup::hasAuthedUser()) { return null; } $ns = new Kwf_Session_Namespace('sessionToken'); if (!$ns->token) { $ns->token = md5(microtime() . mt_rand()); } return $ns->token; }
public function isLoggedIn() { if (Kwf_Setup::hasAuthedUser()) { $user = Zend_Registry::get('userModel')->getAuthedUser(); if (!$user) { return false; } if (!$this->_getSetting('validUserRoles')) { return true; } if (in_array($user->role, $this->_getSetting('validUserRoles'))) { return true; } } return false; }
public function getTargetLanguage() { if (PHP_SAPI == 'cli' || !$this->_useUserLanguage) { return $this->getWebCodeLanguage(); } //shortcut if (count($this->getLanguages()) == 1) { return $this->getWebCodeLanguage(); } if (!Kwf_Setup::hasAuthedUser()) { return $this->getWebCodeLanguage(); } else { if ($this->_authedUserTargetLanguageCache) { return $this->_authedUserTargetLanguageCache; } //TODO: this ALWAYS requires a db connection, should be saved in session $userModel = Kwf_Registry::get('userModel'); $authedUser = $userModel->getAuthedUser(); if (!isset($userModel->getAuthedUser()->language) || !($userLanguage = $userModel->getAuthedUser()->language) || !in_array($userLanguage, $this->getLanguages())) { $this->_authedUserTargetLanguageCache = $this->getWebCodeLanguage(); return $this->_authedUserTargetLanguageCache; } $this->_authedUserTargetLanguageCache = $userLanguage; return $this->_authedUserTargetLanguageCache; } }
protected function _isLoggedIn() { return Kwf_Setup::hasAuthedUser(); }
/** * 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; }