public function indexAction() { Zend_Registry::set('db', false); Kwf_Test_SeparateDb::setDbFromCookie(); // setzt es nur wenn es das cookie wirklich gibt //FnF models setzen damit tests nicht in echte tabellen schreiben Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF); Kwf_Component_Cache_Memory::setInstance(new Kwf_Component_Cache_MemoryBlackHole()); /* if (class_exists('APCIterator')) { $prefix = Kwf_Cache::getUniquePrefix(); apc_delete_file(new APCIterator('user', '#^'.$prefix.'#')); } else { apc_clear_cache('user'); } */ Kwf_Component_Data_Root::setComponentClass($this->_getParam('root')); Zend_Registry::set('testRootComponentClass', $this->_getParam('root')); $root = Kwf_Component_Data_Root::getInstance(); $root->setFilename('kwf/kwctest/' . $this->_getParam('root')); $url = $this->_getParam('url'); $urlParts = explode('/', $url); if (is_array($urlParts) && $urlParts[0] == 'media') { if (sizeof($urlParts) != 7) { throw new Kwf_Exception_NotFound(); } $class = $urlParts[1]; $id = $urlParts[2]; $type = $urlParts[3]; $checksum = $urlParts[4]; // time() wäre der 5er, wird aber nur wegen browsercache benötigt $filename = $urlParts[6]; if ($checksum != Kwf_Media::getChecksum($class, $id, $type, $filename)) { throw new Kwf_Exception_AccessDenied('Access to file not allowed.'); } Kwf_Media_Output::output(Kwf_Media::getOutput($class, $id, $type)); } if ($url == 'kwf/util/kwc/render') { if (isset($_REQUEST['url'])) { $_REQUEST['url'] = str_replace('/' . $root->filename, '', $_REQUEST['url']); } Kwf_Util_Component::dispatchRender(); } $domain = 'http://' . Zend_Registry::get('config')->server->domain; $data = $root->getPageByUrl($domain . Kwf_Setup::getBaseUrl() . '/' . $url, null); if (!$data) { throw new Kwf_Exception_NotFound(); } $root->setCurrentPage($data); $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender'); $contentSender = new $contentSender($data); $contentSender->sendContent(true); Kwf_Benchmark::shutDown(); Kwf_Benchmark::output(); exit; }
public function indexAction() { $id = $this->_getParam('id'); if (!$id) { throw new Kwf_ClientException("Missing Parameter: id"); } $c = Kwf_Component_Data_Root::getInstance()->getComponentById($id, array('ignoreVisible' => true)); if (!$c) { $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true)); } if (!$c) { throw new Kwf_ClientException("Component with id '{$id}' not found"); } $process = $c->getRecursiveChildComponents(array('page' => false, 'flags' => array('processInput' => true))); if (Kwf_Component_Abstract::getFlag($c->componentClass, 'processInput')) { $process[] = $c; } $postData = array(); foreach ($process as $i) { Kwf_Benchmark::count('processInput', $i->componentId); if (method_exists($i->getComponent(), 'preProcessInput')) { $i->getComponent()->preProcessInput($postData); } } foreach ($process as $i) { if (method_exists($i->getComponent(), 'processInput')) { $i->getComponent()->processInput($postData); } } /* //deaktivert: funktioniert nicht $c->getComponent()->sendContent('views/component-master.tpl', true); */ //zwischenlösung: //(unschön: keine assets, kein html-header usw) echo $c->render(); Kwf_Benchmark::output(); exit; }
public static function dispatchKwc() { $requestPath = self::getRequestPath(); if ($requestPath === false) { return; } $fullRequestPath = $requestPath; $data = null; $baseUrl = Kwf_Setup::getBaseUrl(); if ($baseUrl) { if (substr($requestPath, 0, strlen($baseUrl)) != $baseUrl) { throw new Kwf_Exception_NotFound(); } $requestPath = substr($requestPath, strlen($baseUrl)); } $uri = substr($requestPath, 1); $i = strpos($uri, '/'); if ($i) { $uri = substr($uri, 0, $i); } if ($uri == 'robots.txt') { Kwf_Util_RobotsTxt::output(); } if ($uri == 'sitemap.xml') { $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . Kwf_Setup::getBaseUrl() . '/', null); Kwf_Component_Sitemap::output($data->getDomainComponent()); } if (!in_array($uri, array('media', 'kwf', 'admin', 'assets', 'vkwf', 'api'))) { if (!isset($_SERVER['HTTP_HOST'])) { $requestUrl = 'http://' . Kwf_Config::getValue('server.domain') . $fullRequestPath; } else { $requestUrl = 'http://' . $_SERVER['HTTP_HOST'] . $fullRequestPath; } Kwf_Trl::getInstance()->setUseUserLanguage(false); $root = Kwf_Component_Data_Root::getInstance(); foreach ($root->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $p) { $p->preDispatch($requestUrl); } $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; $exactMatch = true; $data = $root->getPageByUrl($requestUrl, $acceptLanguage, $exactMatch); Kwf_Benchmark::checkpoint('getPageByUrl'); if (!$data) { throw new Kwf_Exception_NotFound(); } if (!$exactMatch) { if (rawurldecode($data->url) == $fullRequestPath) { throw new Kwf_Exception("getPageByUrl reported this isn't an exact match, but the urls are equal. wtf."); } $url = $data->url; if (!$url) { // e.g. firstChildPageData without child pages throw new Kwf_Exception_NotFound(); } foreach ($root->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $p) { $url = $p->processUrl($url); } if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) { $url .= '?' . $_SERVER['QUERY_STRING']; } header('Location: ' . $url, true, 301); exit; } $root->setCurrentPage($data); Kwf_User_Autologin::processCookies(); $contentSender = Kwf_Component_Settings::getSetting($data->componentClass, 'contentSender'); $contentSender = new $contentSender($data); $contentSender->sendContent(true); Kwf_Benchmark::shutDown(); //TODO: ein flag oder sowas ähnliches stattdessen verwenden if ($data instanceof Kwc_Abstract_Feed_Component || $data instanceof Kwc_Export_Xml_Component || $data instanceof Kwc_Export_Xml_Trl_Component) { echo "<!--"; } Kwf_Benchmark::output(); if ($data instanceof Kwc_Abstract_Feed_Component || $data instanceof Kwc_Export_Xml_Component || $data instanceof Kwc_Export_Xml_Trl_Component) { echo "-->"; } exit; } else { if ($requestPath == '/kwf/util/kwc/render') { Kwf_User_Autologin::processCookies(); Kwf_Util_Component::dispatchRender(); } } }
public static function handleException($exception) { if ($exception instanceof Zend_Controller_Exception && $exception->getPrevious()) { $exception = $exception->getPrevious(); } if (!$exception instanceof Kwf_Exception_Abstract) { $exception = new Kwf_Exception_Other($exception); } $exception->render(); Kwf_Benchmark::shutDown(); Kwf_Benchmark::output(); }
public function sendContent($includeMaster) { $content = $this->getContent($includeMaster); $content['contents'] = $content['content']; unset($content['content']); if (!isset($content['lifetime'])) { $content['lifetime'] = false; } if (Kwf_Benchmark::isEnabled()) { ob_start(); Kwf_Benchmark::output(); $content['contents'] .= ob_get_contents(); ob_end_clean(); } Kwf_Media_Output::outputWithoutShutdown($content); exit; }
public function render($ignoreCli = false) { try { $exception = $this->getException(); $msg = $exception->__toString(); if ($exception instanceof Zend_Db_Adapter_Exception) { try { foreach (Kwf_Registry::get('config')->database as $db) { $msg = str_replace($db->password, 'xxxxxx', $msg); } } catch (Exception $e) { } } if (!$ignoreCli && PHP_SAPI == 'cli') { $this->log(); file_put_contents('php://stderr', $msg . "\n"); exit(1); } $header = $this->getHeader(); $this->log(); $format = 'html'; if (isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json') { // Is mainly used for Exceptions in setup or bootstrap if called from native application $format = 'json'; } if ($format == 'json') { $output = $this->_renderJson($exception, $msg); } else { $output = $this->_renderHtml($exception, $msg); } if (!headers_sent()) { header($header); if ($format == 'json') { header('Content-Type: application/json; charset=utf-8'); } else { header('Content-Type: text/html; charset=utf-8'); } } echo $output; Kwf_Benchmark::output(); } catch (Exception $e) { if (Kwf_Exception::isDebug()) { echo '<pre>'; echo $this->getException()->__toString(); echo "\n\n\nError happened while handling exception:"; echo $e->__toString(); echo '</pre>'; } else { if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); header('Content-Type: text/html; charset=utf-8'); } echo '<h1>Error</h1>'; echo '<p>An Error ocurred. Please try again later.</p>'; } } }