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;
 }
Пример #2
0
 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();
         }
     }
 }