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 testUrl() { $url = Kwf_Media::getUrl('Kwc_Basic_Image_TestComponent', 1600, 'foo', 'test.jpg'); $url = explode('/', trim($url, '/')); $this->assertEquals('Kwc_Basic_Image_TestComponent', $url[1]); $this->assertEquals(1600, $url[2]); $this->assertEquals('foo', $url[3]); $this->assertEquals('test.jpg', $url[6]); $c1 = Kwf_Media::getChecksum('Kwc_Basic_Image_TestComponent', 1600, 'foo', 'test.jpg'); $c2 = Kwf_Media::getChecksum($url[1], $url[2], $url[3], $url[6]); $this->assertEquals($c1, $c2); }
public static function dispatchMedia() { $requestPath = self::getRequestPath(); if ($requestPath === false) { return; } $baseUrl = Kwf_Setup::getBaseUrl(); if ($baseUrl) { if (substr($requestPath, 0, strlen($baseUrl)) != $baseUrl) { throw new Kwf_Exception_NotFound(); } $requestPath = substr($requestPath, strlen($baseUrl)); } $urlParts = explode('/', substr($requestPath, 1)); 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 = urlencode($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_NotFound(); } $class = rawurldecode($class); Kwf_Media_Output::output(Kwf_Media::getOutput($class, $id, $type)); } }
public function setBodyHtml($html, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE) { while (preg_match('/(img src|background)=\\"\\/(.*?)\\"/i', $html, $matches)) { $path = '/' . $matches[2]; if ($this->_attachImages) { if (substr($path, 0, 6) == '/media') { $parts = explode('/', substr($path, 1)); $class = $parts[1]; $id = $parts[2]; $type = $parts[3]; $checksum = $parts[4]; $filename = $parts[6]; if ($checksum != Kwf_Media::getChecksum($class, $id, $type, $filename)) { throw new Kwf_Exception_AccessDenied('Access to file not allowed.'); } $output = Kwf_Media::getOutputWithoutCheckingIsValid($class, $id, $type); } else { try { $f = new Kwf_Assets_Loader(); $output = $f->getFileContents(substr($path, 8)); } catch (Kwf_Exception_NotFound $e) { throw new Kwf_Exception('Asset not found: ' . $path); } } if (isset($output['contents'])) { $contents = $output['contents']; } else { if (isset($output['file'])) { $contents = file_get_contents($output['file']); } else { throw new Kwf_Exception("didn't get image contents"); } } $image = new Zend_Mime_Part($contents); $image->type = $output['mimeType']; $image->disposition = Zend_Mime::DISPOSITION_INLINE; $image->encoding = Zend_Mime::ENCODING_BASE64; $filename = rawurldecode(substr(strrchr($path, '/'), 1)); $filename = preg_replace('/([^a-z0-9\\-\\.]+)/i', '_', $filename); $image->filename = $filename; $image->id = md5($path); $this->setType(Zend_Mime::MULTIPART_RELATED); $this->addAttachment($image); $replace = "cid:{$image->id}"; } else { $replace = "http://" . $this->getDomain() . $path; } $html = str_replace($matches[0], "{$matches[1]}=\"{$replace}\"", $html); } parent::setBodyHtml($html, $charset, $encoding); }