public function __get($var) { if ($var == 'url') { $m = Kwc_Abstract::createModel($this->componentClass); $row = $m->getRow($this->dbId); if (!$row) { return null; } $fRow = $row->getParentRow('File'); if (!$fRow) { return null; } $filename = $row->filename; if (!$filename) { $filename = $fRow->filename; } $filename .= '.' . $fRow->extension; $ret = Kwf_Media::getUrl($this->componentClass, $this->componentId, 'default', $filename); $ev = new Kwf_Component_Event_CreateMediaUrl($this->componentClass, $this, $ret); Kwf_Events_Dispatcher::fireEvent($ev); return $ev->url; } else { return parent::__get($var); } }
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer) { $ret = parent::getTemplateVars($renderer); $ret['sources'] = null; //mp3 $url = Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, 'mp3', 'audio.mp3'); $ev = new Kwf_Component_Event_CreateMediaUrl($this->getData()->componentClass, $this->getData(), $url); Kwf_Events_Dispatcher::fireEvent($ev); $url = $ev->url; if ($url) { $ret['source'] = array('src' => $url, 'type' => 'audio/mp3', 'title' => 'mp3'); } $ret['config'] = Kwc_Abstract::getSetting($this->getData()->componentClass, 'audio'); $row = $this->getRow(); if ($row->audio_width) { $ret['config']['audioWidth'] = $row->audio_width; } if ($row->audio_height) { $ret['config']['audioHeight'] = $row->audio_height; } if ($row->auto_play) { $ret['config']['autoPlay'] = true; } if ($row->loop) { $ret['config']['loop'] = true; } return $ret; }
public function testImageCacheDeletedAfterDimensionsChange() { $html = $this->_root->getComponentById('root_imageabstract1')->render(); // Normal size $file200 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-200-ffa94c'); // Small size $file100 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-100-ffa94c'); $model = Kwf_Model_Abstract::getInstance('Kwc_ImageResponsive_MediaOutput_Image_TestModel'); $row = $model->getRow('root_imageabstract1'); $row->dimension = 'default2'; $row->kwf_upload_id = 2; $row->save(); $this->_process(); // cache for dh-100 and dh-200 must be deleted, dh-300 and dh-400 remain as zombie $html2 = $this->_root->getComponentById('root_imageabstract1')->render(); $this->assertNotEquals($html, $html2); // Dpr2 size $otherfile200 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-200-ffa94c'); // Normal size $otherfile100 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-100-ffa94c'); // SmallSize cache-id and normal-size cache-id could colide $this->assertNotEquals($file100, $otherfile100); // NormalSize cache-id and Dpr2-size cache-id could colide $this->assertNotEquals($file200, $otherfile200); }
public function getTemplateVars() { $ret = parent::getTemplateVars(); $ret['sources'] = null; //mp3 $url = Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, 'mp3', 'audio.mp3'); if ($url) { $ret['source'] = array('src' => $url, 'type' => 'audio/mp3', 'title' => 'mp3'); } $ret['config'] = Kwc_Abstract::getSetting($this->getData()->componentClass, 'audio'); $row = $this->getRow(); if ($row->audio_width) { $ret['config']['audioWidth'] = $row->audio_width; } if ($row->audio_height) { $ret['config']['audioHeight'] = $row->audio_height; } if ($row->auto_play) { $ret['config']['autoPlay'] = true; } if ($row->loop) { $ret['config']['loop'] = true; } return $ret; }
public function __get($var) { if ($var == 'url') { $m = Kwc_Abstract::createModel($this->componentClass); $row = $m->getRow($this->dbId); if (!$row || !$row->own_download) { //not own_download but still output thru own url to be ablte to call own isValidMediaOutput $row = $this->chained->getComponent()->getRow(); if (!$row) { return null; } $fRow = $row->getParentRow('File'); if (!$fRow) { return null; } $filename = $row->filename; if (!$filename) { $filename = $fRow->filename; } $filename .= '.' . $fRow->extension; return Kwf_Media::getUrl($this->componentClass, $this->componentId, 'default', $filename); } return $this->getChildComponent('-download')->url; } else { return parent::__get($var); } }
public function headerAction() { try { $t = new Kwf_Util_Model_Welcome(); $row = $t->getRow(1); } catch (Zend_Db_Statement_Exception $e) { //wenn tabelle nicht existiert fehler abfangen $row = null; } if ($row && $row->getParentRow('LoginImage')) { $this->view->image = Kwf_Media::getUrlByRow($row, 'LoginImage'); $this->view->imageSize = Kwf_Media::getDimensionsByRow($row, 'LoginImage'); } else { $this->view->image = false; } if (Kwf_Registry::get('config')->allowUntagged === true) { if (file_exists('.git') && Kwf_Util_Git::web()->getActiveBranch() != 'production') { $this->view->untagged = true; } if (file_exists(KWF_PATH . '/.git') && Kwf_Util_Git::kwf()->getActiveBranch() != 'production/' . Kwf_Registry::get('config')->application->id) { $this->view->untagged = true; } } $this->view->application = Zend_Registry::get('config')->application->toArray(); $this->_helper->viewRenderer->setRender('loginheader'); }
public function getBaseImageUrl() { $data = $this->getImageData(); if ($data) { return Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, $this->getBaseType(), $data['filename']); } return null; }
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer) { $ret = parent::getTemplateVars($renderer); $ret['src'] = false; if ($this->_getGraph()) { $ret['src'] = Kwf_Media::getUrl(get_class($this), $this->getData()->componentId, 'default', 'graph.png'); } return $ret; }
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 load($row) { $data = array('imageUrl' => false, 'previewUrl' => false); $uploadRow = $row->getParentRow($this->getRuleKey()); if ($uploadRow) { $data['imageUrl'] = Kwf_Media::getUrl(get_class($this), $uploadRow->id, 'original', $uploadRow); $data['previewUrl'] = Kwf_Media::getUrl(get_class($this), $uploadRow->id, 'preview', $uploadRow); } return array($this->getFieldName() => (object) $data); }
protected function _afterSave() { parent::_afterSave(); if ($this->isDirty('login_kwf_upload_id')) { Kwf_Media::clearCache('Kwf_Util_Model_Welcome', $this->id, 'LoginImage'); Kwf_Media::clearCache('Kwf_Util_Model_Welcome', $this->id, 'LoginImageLarge'); } if ($this->isDirty('kwf_upload_id')) { Kwf_Media::clearCache('Kwf_Util_Model_Welcome', $this->id, 'WelcomeImage'); } }
protected function _getUploadUrl() { $row = $this->_getRow(); $fRow = $row->getParentRow($this->_getSetting('uploadModelRule')); if (!$fRow) { return null; } $filename = $fRow->filename . '.' . $fRow->extension; $id = $this->getData()->componentId; return Kwf_Media::getUrl(get_class($this), $id, 'default', $filename); }
public function getBaseImageUrl() { if ($this->getRow()->own_image) { return $this->getData()->getChildComponent('-image')->getComponent()->getBaseImageUrl(); } else { $data = $this->getData()->chained->getComponent()->getImageDataOrEmptyImageData(); if ($data && $data['filename']) { return Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, $this->getBaseType(), $data['filename']); } } return null; }
private function _checkTheSizes($html, $smallImageNum, $smallWidth, $smallHeight) { // getMediaOutput aufrufen, damit Cache-Meta geschrieben wird (wegen d0cf3812b20fa19c40617ac5b08ed08a18ff808d) // muss so gemacht werden, weil der request über getimagesize weiter unten // nicht das FnF-Cache Model dieses Request schreiben kann preg_match('# src=".*/media/([^/]+)/([^/]+)/([^/]+)#', $html, $matches); Kwf_Media::getOutput($matches[1], $matches[2], $matches[3]); $this->assertRegExp('#<img.+?src=".+?' . $smallImageNum . '\\.jpg.+width="' . $smallWidth . '".+height="' . $smallHeight . '"#ms', $html); preg_match('# src="(.+?)"#ms', $html, $matches); $smallSrcSize = getimagesize('http://' . Kwf_Registry::get('testDomain') . $matches[1]); $this->assertEquals($smallWidth, $smallSrcSize[0]); $this->assertEquals($smallHeight, $smallSrcSize[1]); }
public function testClearOutputCacheWhenChangingCropOptions() { $this->assertEquals('dh-{width}-dc16b9', $this->_root->getComponentById('root_page')->getComponent()->getBaseType()); $dim = $this->_root->getComponentById('root_page')->getComponent()->getImageDimensions(); Kwf_Media::clearCache('Kwc_Basic_Image_Crop_ImageComponent', 'root_page', Kwf_Media::DONT_HASH_TYPE_PREFIX . $dim['width'] . '-dc16b9'); Kwc_Basic_Image_Crop_ImageComponent::$getMediaOutputCalled = 0; Kwf_Media::getOutput('Kwc_Basic_Image_Crop_ImageComponent', 'root_page', Kwf_Media::DONT_HASH_TYPE_PREFIX . $dim['width'] . '-dc16b9'); $this->assertEquals(1, Kwc_Basic_Image_Crop_ImageComponent::$getMediaOutputCalled); Kwf_Media::getOutput('Kwc_Basic_Image_Crop_ImageComponent', 'root_page', Kwf_Media::DONT_HASH_TYPE_PREFIX . $dim['width'] . '-dc16b9'); $this->assertEquals(1, Kwc_Basic_Image_Crop_ImageComponent::$getMediaOutputCalled); $c = $this->_root->getComponentById('root_page'); $row = Kwf_Model_Abstract::getInstance('Kwc_Basic_Image_Crop_TestModel')->getRow('root_page'); $row->crop_x = 20; $row->save(); Kwf_Events_ModelObserver::getInstance()->process(); Kwf_Media::getOutput('Kwc_Basic_Image_Crop_ImageComponent', 'root_page', Kwf_Media::DONT_HASH_TYPE_PREFIX . $dim['width'] . '-dc16b9'); $this->assertEquals(2, Kwc_Basic_Image_Crop_ImageComponent::$getMediaOutputCalled); }
public function load($row, $role, $info) { $ret = null; $uploadRow = $row->getParentRow($this->getRuleKey()); if ($uploadRow) { $width = $this->getWidth() - 10; $size = array('width' => $width, 'height' => $this->getMaxHeight(), 'cover' => false); $size = Kwf_Media_Image::calculateScaleDimensions($uploadRow->getFileSource(), $size); $ret = array('previewUrl' => Kwf_Media::getUrl(get_class($this), $uploadRow->id, 'preview-' . $width . '-' . $this->getMaxHeight(), $uploadRow), 'previewHeight' => $size['height'], 'previewWidth' => $size['width']); if ($this->getShowHoverImage()) { $size = array('width' => 250, 'height' => 250, 'cover' => false); $size = Kwf_Media_Image::calculateScaleDimensions($uploadRow->getFileSource(), $size); $ret['hoverUrl'] = Kwf_Media::getUrl(get_class($this), $uploadRow->id, 'hover', $uploadRow); $ret['hoverHeight'] = $size['height']; $ret['hoverWidth'] = $size['width']; } } return $ret; }
public function getBaseImageUrl() { if ($this->getRow()->own_image) { return $this->getData()->getChildComponent('-image')->getComponent()->getBaseImageUrl(); } else { $data = $this->getData()->chained->getComponent()->getImageDataOrEmptyImageData(); if ($data && $data['filename']) { if (Kwc_Abstract::getSetting($this->_getSetting('masterComponentClass'), 'editFilename') && $this->_getRow()->filename) { $fn = $this->_getRow()->filename; if ($fn) { $fileRow = $this->getData()->chained->getComponent()->getRow()->getParentRow('Image'); $data['filename'] = $fn . '.' . $fileRow->extension; } } return Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, $this->getBaseType(), $data['filename']); } } return null; }
public function indexAction() { $this->view->applicationName = Kwf_Config::getValue('application.name'); $this->view->brandingKoala = Kwf_Config::getValue('application.branding.koala'); $this->view->brandingVividPlanet = Kwf_Config::getValue('application.branding.vividPlanet'); $this->view->pages = Kwf_Registry::get('acl')->has('kwf_component_pages'); $this->view->baseUrl = Kwf_Setup::getBaseUrl(); $this->view->favicon = Kwf_View_Ext::getFavicon(); try { $t = new Kwf_Util_Model_Welcome(); $row = $t->getRow(1); } catch (Zend_Db_Statement_Exception $e) { //wenn tabelle nicht existiert fehler abfangen $row = null; } if ($row && ($fileRow = $row->getParentRow('LoginImage'))) { $this->view->image = Kwf_Media::getUrlByRow($row, 'LoginImageLarge', 'login'); $this->view->imageSize = Kwf_Media_Image::calculateScaleDimensions($fileRow->getImageDimensions(), Kwf_Util_Model_Welcome::getImageDimensions('LoginImageLarge')); } else { $this->view->image = false; } if (Kwf_Registry::get('config')->allowUntagged === true) { if (file_exists('.git') && Kwf_Util_Git::web()->getActiveBranch() != 'production') { $this->view->untagged = true; } if (file_exists(KWF_PATH . '/.git') && Kwf_Util_Git::kwf()->getActiveBranch() != 'production/' . Kwf_Registry::get('config')->application->id) { $this->view->untagged = true; } } $this->view->contentScript = $this->getHelper('viewRenderer')->getViewScript('login'); $this->view->lostPasswordLink = $this->getFrontController()->getRouter()->assemble(array('controller' => 'login', 'action' => 'lost-password'), 'kwf_user'); $this->view->redirects = array(); $users = Zend_Registry::get('userModel'); foreach ($users->getAuthMethods() as $k => $auth) { if ($auth instanceof Kwf_User_Auth_Interface_Redirect && $auth->showInBackend()) { $url = $this->getFrontController()->getRouter()->assemble(array('controller' => 'backend-login', 'action' => 'redirect'), 'kwf_user'); $label = $auth->getLoginRedirectLabel(); $this->view->redirects[] = array('url' => $url, 'authMethod' => $k, 'redirect' => $_SERVER['REQUEST_URI'], 'name' => Kwf_Trl::getInstance()->trlStaticExecute($label['name']), 'icon' => isset($label['icon']) ? '/assets/' . $label['icon'] : false, 'formOptions' => Kwf_User_Auth_Helper::getRedirectFormOptionsHtml($auth->getLoginRedirectFormOptions())); } } parent::indexAction(); }
public function __get($var) { if ($var == 'url') { $m = Kwc_Abstract::createModel($this->componentClass); $row = $m->getRow($this->dbId); if (!$row) { return null; } $fRow = $row->getParentRow('File'); if (!$fRow) { return null; } $filename = $row->filename; if (!$filename) { $filename = $fRow->filename; } $filename .= '.' . $fRow->extension; return Kwf_Media::getUrl($this->componentClass, $this->componentId, 'default', $filename); } else { return parent::__get($var); } }
public function testOutputCacheWithMtimeFiles() { Kwf_Media_TestMediaOutputClass::$called = 0; $f = tempnam('/tmp', 'outputTest'); Kwf_Media_TestMediaOutputClass::$mtimeFiles = array($f); $id = time() + rand(0, 10000); $o = Kwf_Media::getOutput('Kwf_Media_TestMediaOutputClass', $id, 'mtimeFiles'); unset($o['mtime']); $this->assertEquals(array('mimeType' => 'text/plain', 'contents' => 'foobar' . $id, 'mtimeFiles' => array($f)), $o); $this->assertEquals(1, Kwf_Media_TestMediaOutputClass::$called); $o = Kwf_Media::getOutput('Kwf_Media_TestMediaOutputClass', $id, 'mtimeFiles'); $this->assertEquals(1, Kwf_Media_TestMediaOutputClass::$called); $newTime = time() + 10; $this->assertTrue(touch($f, $newTime)); clearstatcache(); $this->assertEquals($newTime, filemtime($f)); $o = Kwf_Media::getOutput('Kwf_Media_TestMediaOutputClass', $id, 'mtimeFiles'); $this->assertEquals(array('mimeType' => 'text/plain', 'contents' => 'foobar' . $id, 'mtimeFiles' => array($f), 'mtime' => $newTime), $o); $this->assertEquals(2, Kwf_Media_TestMediaOutputClass::$called); $o = Kwf_Media::getOutput('Kwf_Media_TestMediaOutputClass', $id, 'mtimeFiles'); $this->assertEquals(2, Kwf_Media_TestMediaOutputClass::$called); }
public function indexAction() { $this->view->content = ''; try { $t = new Kwf_Util_Model_Welcome(); $row = $t->getRow(1); if ($row) { $this->view->content = $row->content; } } catch (Zend_Db_Statement_Exception $e) { //wenn tabelle nicht existiert fehler abfangen $row = null; } if ($row && $row->getParentRow('WelcomeImage')) { $this->view->image = Kwf_Media::getUrlByRow($row, 'WelcomeImage'); $this->view->imageSize = Kwf_Media::getDimensionsByRow($row, 'WelcomeImage'); } else { $this->view->image = false; } $this->view->application = Zend_Registry::get('config')->application; $this->_helper->viewRenderer->setRender('Welcome'); }
public function testParentImage() { $c = $this->_root->getComponentById('root_image-parentImage'); $html = $c->render(true, false); $this->assertTrue(!!preg_match('#<img src="([^"]+)" width="(\\d+)" height="(\\d+)"#', $html, $m)); $this->assertEquals($m[2], 20); $this->assertEquals($m[3], 20); $url = $m[1]; $this->assertTrue(!!preg_match('#/media/([^/]+)/([^/]+)/([^/]+)#', $url, $m)); $this->assertEquals($m[1], 'Kwc_Basic_Image_CacheParentImage_ParentImage_Component'); $this->assertEquals($m[2], 'root_image-parentImage'); $this->assertContains('dh-16-', $m[3]); $o = Kwf_Media::getOutput($m[1], $m[2], $m[3]); $im = new Imagick($o['file']); $this->assertEquals(16, $im->getImageWidth()); $this->assertEquals(16, $im->getImageHeight()); $model = Kwf_Model_Abstract::getInstance('Kwc_Basic_Image_CacheParentImage_Image_TestModel'); $row = $model->getRow('root_image'); $row->kwf_upload_id = 2; $row->save(); $this->_process(); $c = $this->_root->getComponentById('root_image-parentImage'); $html = $c->render(true, false); $this->assertTrue(!!preg_match('#<img src="([^"]+)" width="(\\d+)" height="(\\d+)"#', $html, $m)); $this->assertEquals($m[2], 20); $this->assertEquals($m[3], 7); $url = $m[1]; $this->assertTrue(!!preg_match('#/media/([^/]+)/([^/]+)/([^/]+)#', $url, $m)); $this->assertEquals($m[1], 'Kwc_Basic_Image_CacheParentImage_ParentImage_Component'); $this->assertEquals($m[2], 'root_image-parentImage'); $this->assertContains('dh-20-', $m[3]); $o = Kwf_Media::getOutput($m[1], $m[2], $m[3]); $im = new Imagick(); $im->readImageBlob($o['contents']); $this->assertEquals(20, $im->getImageWidth()); $this->assertEquals(7, $im->getImageHeight()); }
public function testClearCache() { $c = $this->_root->getComponentById('root_page1'); $html = $c->render(); $this->assertTrue(!!preg_match('# src="([^"]+)"#', $html, $m)); $url = str_replace('{width}', '', $m[1]); $url = explode('/', trim($url, '/')); $class = $url[4]; $id = $url[5]; $type = $url[6]; $o = Kwf_Media::getOutput($class, $id, $type); $this->assertNotNull($o); $this->assertEquals('image/jpg', $o['mimeType']); $im = new Imagick(); $im->readImageBlob($o['contents']); $this->assertEquals(26, $im->getImageWidth()); $this->assertEquals(32, $im->getImageHeight()); $row = Kwf_Model_Abstract::getInstance('Kwc_Basic_Image_DprImage_TestModel')->getRow('root_page1'); $row->kwf_upload_id = 3; $row->save(); $this->_process(); $c = $this->_root->getComponentById('root_page1'); $html = $c->render(); $this->assertTrue(!!preg_match('# src="([^"]+)"#', $html, $m)); $url = explode('/', trim($m[1], '/')); $class = $url[4]; $id = $url[5]; $type = $url[6]; $o = Kwf_Media::getOutput($class, $id, $type); $this->assertNotNull($o); $this->assertEquals('image/gif', $o['mimeType']); $im = new Imagick(); $im->readImageBlob($o['contents']); $this->assertEquals(32, $im->getImageWidth()); $this->assertEquals(11, $im->getImageHeight()); }
public function onMediaChanged(Kwf_Events_Event_Media_Changed $event) { Kwf_Media::clearCache($event->class, $event->component->componentId, $event->type); $log = Kwf_Events_Log::getInstance(); if ($log) { $log->log("media cache clear class={$event->class} id={$event->component->componentId} type={$event->type}", Zend_Log::INFO); } }
public function testEnlargeCacheDeletedOnBaseImageChanged() { // Image and Enlarge have to define different dimensions because else it // could happen that the parent has the same types as the child. // Get EnlargeComponent $component = $this->_root->getChildComponent('1804')->getChildComponent('-linkTag')->getChildComponent('_imagePage'); // Render EnlargeComponent. Request Enlarge-Image (image has to be big enough) preg_match_all('#/media/([^/]+)/([^/]+)/([^/]+)#', $component->render(), $matches); foreach ($matches[0] as $key => $m) { if (strpos($matches[3][$key], '{width}') !== false) { continue; } $fileWithGreaterHeight = Kwf_Media::getOutput($matches[1][$key], $matches[2][$key], $matches[3][$key]); } // Change basis-bild $row = $this->_root->getChildComponent('1804')->getComponent()->getRow(); $row->kwf_upload_id = 5; $row->save(); $this->_process(); // Assert if image cache was changed preg_match_all('#/media/([^/]+)/([^/]+)/([^/]+)#', $component->render(), $matches); foreach ($matches[0] as $key => $m) { if (strpos($matches[3][$key], '{width}') !== false) { continue; } $fileWithSmallerHeight = Kwf_Media::getOutput($matches[1][$key], $matches[2][$key], $matches[3][$key]); } $image1 = new Imagick($fileWithGreaterHeight['file']); $image2 = new Imagick($fileWithSmallerHeight['file']); $this->assertNotEquals($image1->getImageHeight(), $image2->getImageHeight()); }
public function getBaseImageUrl() { $data = $this->_getImageDataOrEmptyImageData(); if ($data) { $ret = Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, $this->getBaseType(), $data['filename']); $ev = new Kwf_Component_Event_CreateMediaUrl($this->getData()->componentClass, $this->getData(), $ret); Kwf_Events_Dispatcher::fireEvent($ev); return $ev->url; } return null; }
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]; $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); }
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer) { $ret = parent::getTemplateVars($renderer); $ret['downloadUrl'] = Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, 'list', 'all'); return $ret; }
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 load($row) { $pk = $row->getModel()->getPrimaryKey(); $url = Kwf_Media::getUrl(get_class($row->getModel()), $this->_componentId . '_' . $row->{$pk}, 'File', $row->getParentRow('File')); return '<a class="kwcAdvancedDownloadsTreeLink" href="' . $url . '" target="_blank">' . $row->text . '</a>'; }