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;
 }
Esempio n. 2
0
 public function assets(Kwf_Assets_Package $assetsPackage, $language = null, $subroot = null)
 {
     if (!$language) {
         $language = Kwf_Trl::getInstance()->getTargetLanguage();
     }
     $ev = new Kwf_Events_Event_CreateAssetsPackageUrls(get_class($assetsPackage), $assetsPackage, $subroot);
     Kwf_Events_Dispatcher::fireEvent($ev);
     $prefix = $ev->prefix;
     $indent = str_repeat(' ', 8);
     $ret = '';
     foreach ($assetsPackage->getPackageUrls('text/css', $language) as $file) {
         $ret .= "{$indent}<link rel=\"stylesheet\" type=\"text/css\" href=\"" . htmlspecialchars($prefix . $file) . "\" />\n";
     }
     foreach ($assetsPackage->getPackageUrls('text/css; ie8', $language) as $file) {
         $ret .= "{$indent}<!--[if lte IE 8]><link rel=\"stylesheet\" type=\"text/css\" href=\"" . htmlspecialchars($prefix . $file) . "\" /><![endif]-->\n";
     }
     foreach ($assetsPackage->getPackageUrls('text/javascript; ie8', $language) as $file) {
         $ret .= "{$indent}<!--[if lte IE 8]><script type=\"text/javascript\" src=\"" . htmlspecialchars($prefix . $file) . "\"></script><![endif]-->\n";
     }
     foreach ($assetsPackage->getPackageUrls('text/javascript', $language) as $file) {
         $ret .= "{$indent}<script type=\"text/javascript\" src=\"" . htmlspecialchars($prefix . $file) . "\"></script>\n";
     }
     foreach ($assetsPackage->getPackageUrls('text/javascript; defer', $language) as $file) {
         //single line to allow parsing
         $ret .= "<script type=\"text/javascript\">var se=document.createElement('script');se.type='text/javascript';se.async=true;se.src='" . $prefix . $file . "';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(se,s);</script>\n";
     }
     return $ret;
 }
Esempio n. 3
0
 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);
     }
 }
Esempio n. 4
0
 public function setUp()
 {
     parent::setUp();
     Kwf_Model_Events_UnionReFire_EventSubscriber::$onUnionRowUpdatedCalled = array();
     Kwf_Model_Events_UnionReFire_EventSubscriber::$onSourceRowUpdatedCalled = array();
     Kwf_Events_Dispatcher::addListeners('Kwf_Model_Events_UnionReFire_UnionModel');
     Kwf_Events_Dispatcher::addListeners(Kwf_Events_Subscriber::getInstance('Kwf_Model_Events_UnionReFire_EventSubscriber'));
 }
Esempio n. 5
0
 public function setUp()
 {
     parent::setUp();
     Kwf_Model_Events_ProxySourceNoClass_EventSubscriber::$onProxyRowInsertedCalled = 0;
     Kwf_Model_Events_ProxySourceNoClass_EventSubscriber::$onProxyModelUpdatedCalled = 0;
     Kwf_Events_Dispatcher::addListeners('Kwf_Model_Events_ProxySourceNoClass_Model');
     Kwf_Events_Dispatcher::addListeners(Kwf_Events_Subscriber::getInstance('Kwf_Model_Events_ProxySourceNoClass_EventSubscriber'));
 }
 public function mediaAction()
 {
     echo "clearing media cache, this can take some time...\n";
     Kwf_Media_MemoryCache::getInstance()->clean();
     echo "done\n";
     $ev = new Kwf_Events_Event_Media_ClearAll('Kwf_Media_MemoryCache');
     Kwf_Events_Dispatcher::fireEvent($ev);
     exit;
 }
Esempio n. 7
0
 public function setUp()
 {
     apc_clear_cache('user');
     Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean();
     Kwf_Cache_Simple::resetZendCache();
     parent::setUp();
     Kwf_Events_Dispatcher::addListeners('Kwf_Model_RowCache_RowCacheModel');
     Kwf_Model_Abstract::getInstance('Kwf_Model_RowCache_SourceModel')->setData(array(array('id' => 1, 'foo' => 1, 'bar' => 'x1'), array('id' => 2, 'foo' => 2, 'bar' => 'x2'), array('id' => 3, 'foo' => 3, 'bar' => 'x3'), array('id' => 4, 'foo' => 4, 'bar' => 'x4')));
 }
Esempio n. 8
0
 public function tearDown()
 {
     Kwf_Events_ModelObserver::getInstance()->setSkipFnF(true);
     Kwf_Component_Data_Root::reset();
     Kwf_Component_Cache::clearInstance();
     Kwf_Model_Abstract::clearInstances();
     Kwf_Events_Dispatcher::clearCache();
     Kwf_Events_Subscriber::clearInstances();
     Kwf_Component_PagesMetaModel::clearInstance();
     Kwf_Trl::getInstance()->unsetTrlElements();
 }
 public function jsonAddParagraphAction()
 {
     $class = $this->_getParam('component');
     if (array_search($class, $this->_components)) {
         $paragraphsData = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId'), array('ignoreVisible' => true, 'limit' => 1));
         $supportedMasterLayoutContexts = Kwf_Component_Layout_Abstract::getInstance($class)->getSupportedContexts();
         if ($supportedMasterLayoutContexts !== false) {
             $masterLayoutContexts = $paragraphsData->getComponent()->getMasterLayoutContexts();
             foreach ($masterLayoutContexts as $ctx) {
                 if (!in_array($ctx, $supportedMasterLayoutContexts)) {
                     throw new Kwf_Exception("Supported Content Spans doesn't match");
                     //button is hidden in JS
                 }
             }
         }
         $ev = new Kwf_Component_Event_Component_FilterAddComponentClass($class, $paragraphsData);
         Kwf_Events_Dispatcher::fireEvent($ev);
         if ($ev->deny) {
             throw new Kwf_Exception("Adding '{$class}' is denied for {$paragraphsData->componentId} by plugin");
         }
         $row = $this->_model->createRow();
         $this->_preforeAddParagraph($row);
         $generators = Kwc_Abstract::getSetting($this->_getParam('class'), 'generators');
         $classes = $generators['paragraphs']['component'];
         $row->component = array_search($class, $classes);
         if (is_null($row->visible)) {
             $row->visible = 0;
         }
         if (is_null($row->device_visible)) {
             $row->device_visible = 'all';
         }
         $row->pos = $this->_getParam('pos');
         $row->save();
         $id = $row->id;
         $where['component_id = ?'] = $this->_getParam('componentId');
         // Hack für weiterleiten auf Edit-Seite
         $name = Kwc_Abstract::getSetting($this->_getParam('class'), 'componentName');
         $name = str_replace('.', ' -> ', $name);
         $this->view->id = $row->id;
         //wird des braucht? $this->view->componentClass = $classes[$row->component];
         //wird des braucht? $this->view->componentName = $name;
         $this->view->componentConfigs = array();
         $this->view->editComponents = array();
         $extConfig = Kwf_Component_Abstract_ExtConfig_Abstract::getInstance($classes[$row->component]);
         $this->view->openConfigKey = $extConfig->getEditAfterCreateConfigKey();
         $cfg = $extConfig->getConfig(Kwf_Component_Abstract_ExtConfig_Abstract::TYPE_DEFAULT);
         foreach ($cfg as $k => $i) {
             $this->view->componentConfigs[$classes[$row->component] . '-' . $k] = $i;
             $this->view->editComponents[] = array('componentClass' => $classes[$row->component], 'type' => $k);
         }
     } else {
         throw new Kwf_Exception("Component {$class} not found");
     }
 }
Esempio n. 10
0
 protected function _build($options)
 {
     Kwf_Events_Dispatcher::clearCache();
     if (!file_exists('build/events')) {
         mkdir('build/events');
     }
     $fileName = 'build/events/listeners';
     if (file_exists($fileName)) {
         unlink($fileName);
     }
     $data = Kwf_Events_Dispatcher::getAllListeners();
     file_put_contents($fileName, serialize($data));
 }
Esempio n. 11
0
 public function image($image, $alt = '', $attributes = null)
 {
     if (!$image) {
         return '';
     }
     $url = $this->_getImageUrl($image);
     if ($url == '') {
         return '';
     }
     if (substr($url, 0, 8) == '/assets/') {
         if (Kwf_Setup::getBaseUrl()) {
             $url = Kwf_Setup::getBaseUrl() . $url;
         }
         $subroot = null;
         if ($this->_getView() && $this->_getView()->component) {
             $subroot = $this->_getView()->component->getSubroot();
         }
         $ev = new Kwf_Events_Event_CreateAssetUrl(get_class($this), $url, $subroot);
         Kwf_Events_Dispatcher::fireEvent($ev);
         $url = $ev->url;
     }
     $class = '';
     if (is_string($attributes)) {
         $class = $attributes;
     }
     if (is_string($image)) {
         if (file_exists(str_replace('/images/', '/images/dpr2/', $this->_getAssetPath($image)))) {
             $class .= ' kwfReplaceImageDpr2';
         }
     }
     $class = trim($class);
     if (!is_array($attributes)) {
         $attributes = array();
     }
     if ($class != '') {
         $attributes['class'] = $class;
     }
     $size = $this->_getImageSize($image);
     if (!isset($attributes['width'])) {
         $attributes['width'] = $size['width'];
     }
     if (!isset($attributes['height'])) {
         $attributes['height'] = $size['height'];
     }
     $attr = '';
     foreach ($attributes as $k => $i) {
         $attr .= ' ' . $k . '="' . $i . '"';
     }
     return "<img src=\"{$url}\"{$attr} alt=\"{$alt}\" />";
 }
Esempio n. 12
0
 public function testMove()
 {
     $root = $this->_init('Kwf_Component_Cache_PageMove_Root_Component');
     $c2 = $root->getComponentById('2');
     $c2->render();
     $model = Kwf_Model_Abstract::getInstance('Kwf_Component_Cache_PageMove_Root_PagesModel');
     $row = $model->getRow(2);
     $row->parent_id = 3;
     $row->save();
     $this->_process();
     Kwf_Events_Dispatcher::fireEvent(new Kwf_Component_Event_Component_RecursiveContentChanged('Kwc_Basic_Empty_Component', Kwf_Component_Data_Root::getInstance()->getComponentById(3)));
     $this->_process();
     $this->assertNull(Kwf_Component_Cache::getInstance()->load('2'));
 }
Esempio n. 13
0
 public function getTypes()
 {
     $types = array();
     if (Kwf_Component_Data_Root::getComponentClass()) {
         $types[] = new Kwf_Util_Build_Types_ComponentSettings();
     }
     $types[] = new Kwf_Util_Build_Types_Trl();
     $types[] = new Kwf_Util_Build_Types_Events();
     $types[] = new Kwf_Util_Build_Types_Assets();
     if (Kwf_Component_Data_Root::getComponentClass()) {
         $types[] = new Kwf_Util_Build_Types_RteStyles();
     }
     $ev = new Kwf_Events_Event_FetchBuildTypes(get_class($this));
     Kwf_Events_Dispatcher::fireEvent($ev);
     $types = array_merge($types, $ev->types);
     return $types;
 }
 protected function _getVideoUrl($format = 'mp4')
 {
     $row = $this->getRow();
     if ($row->source_type == 'links') {
         return $row->{$format . '_url'};
     }
     $ret = Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, $format, 'video.' . $format);
     $ev = new Kwf_Component_Event_CreateMediaUrl($this->getData()->componentClass, $this->getData(), $ret);
     Kwf_Events_Dispatcher::fireEvent($ev);
     return $ev->url;
 }
Esempio n. 15
0
 public function testLinkTargetChanged2()
 {
     $html = $this->_root->getChildComponent('_test1')->render(null, true);
     $this->assertContains('content2', $html);
     $this->assertContains('/test3"', $html);
     $this->assertEquals(7, $this->_getViewCacheCount());
     /*
     - root_test1:page
     - root_test1:master
     - root_test1:component
     - root_test2:component
     - root_test4:componentLink   [delete]
     - root_test3:componentLink
     - root_test1:fullPage        [deleted]
     */
     $this->_root->getChildComponent('_test2')->render(null, true);
     /*
     - root_test2:page
     - root_test2:master
     - root_test2:fullPage        [delete]
     */
     $this->assertEquals(7 + 3, $this->_getViewCacheCount());
     $this->_root->getChildComponent('_test3')->render(null, true);
     /*
     - root_test3:page
     - root_test3:master
     - root_test3:component
     - root_test3:fullPage
     */
     $this->assertEquals(7 + 3 + 4, $this->_getViewCacheCount());
     $this->_root->getChildComponent('_test4')->render(null, true);
     /*
     - root_test4:page
     - root_test4:master
     - root_test4:component
     - root_test4:fullPage        [delete]
     */
     $this->assertEquals(7 + 3 + 4 + 4, $this->_getViewCacheCount());
     Kwf_Events_Dispatcher::fireEvent(new Kwf_Component_Event_Page_UrlChanged('Kwf_Component_Cache_FullPage_Test4_Component', $this->_root->getChildComponent('_test4')));
     $this->_process();
     $this->assertEquals(7 + 3 + 4 + 4 - 4, $this->_getViewCacheCount());
     $html = $this->_root->getChildComponent('_test1')->render(null, true);
     $this->assertContains('content2', $html);
     $this->assertContains('/test3"', $html);
     $this->assertEquals(7 + 3 + 4 + 4 - 4 + 2, $this->_getViewCacheCount());
     $this->_root->getChildComponent('_test2')->render(null, true);
     $this->assertEquals(7 + 3 + 4 + 4 - 4 + 2 + 1, $this->_getViewCacheCount());
     $this->_root->getChildComponent('_test3')->render(null, true);
     $this->assertEquals(7 + 3 + 4 + 4 - 4 + 2 + 1, $this->_getViewCacheCount());
     $this->_root->getChildComponent('_test4')->render(null, true);
     $this->assertEquals(7 + 3 + 4 + 4 - 4 + 2 + 1 + 1, $this->_getViewCacheCount());
 }
Esempio n. 16
0
 private function _deleteViewCacheBySelect(Kwf_Model_Select $select, $progressBarAdapter = null)
 {
     //execute select
     $microtime = $this->_getMicrotime();
     $model = $this->getModel();
     $log = Kwf_Events_Log::getInstance();
     $cacheIds = array();
     $options = array('columns' => array('component_id', 'renderer', 'type', 'value', 'domain_component_id', 'url'));
     $partialIds = array();
     $deleteIds = array();
     $checkIncludeIds = array();
     $rows = $model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select, $options);
     $progress = null;
     if ($progressBarAdapter) {
         $count = count($rows);
         $steps = (int) (count($rows) * 2 / 100 + 3);
         $step = 0;
         $progress = new Zend_ProgressBar($progressBarAdapter, 0, $steps);
     }
     $fullPageUrls = array();
     foreach ($rows as $key => $row) {
         if ($progress && $key % 100 == 0) {
             $step += 100;
             $progress->next(1, "viewcache {$step} / {$count}");
         }
         $cacheIds[] = $this->_getCacheId($row['component_id'], $row['renderer'], $row['type'], $row['value']);
         Kwf_Benchmark::countLog('viewcache-delete-' . $row['type']);
         if ($row['type'] != 'fullPage' && !isset($checkIncludeIds[$row['component_id']])) {
             $checkIncludeIds[$row['component_id'] . ':' . $row['type']] = true;
         }
         if ($log) {
             $log->log("delete view cache {$row['component_id']} {$row['renderer']} {$row['type']} {$row['value']}", Zend_Log::INFO);
         }
         $type = $row['type'];
         $value = $row['value'];
         $cId = $row['component_id'];
         if ($type == 'partial' && $value != '') {
             if (!isset($partialIds[$cId])) {
                 $partialIds[$cId] = array();
             }
             $partialIds[$cId][] = $value;
         } else {
             if ($value == '') {
                 if (!isset($deleteIds[$type])) {
                     $deleteIds[$type] = array();
                 }
                 $deleteIds[$type][] = $cId;
             } else {
                 throw new Kwf_Exception('Should not happen.');
             }
         }
         if ($type == 'fullPage') {
             if (!isset($fullPageUrls[$row['domain_component_id']])) {
                 $fullPageUrls[$row['domain_component_id']] = array();
             }
             $fullPageUrls[$row['domain_component_id']][$row['component_id']] = $row['url'];
         }
     }
     // Memcache
     $this->_beforeMemcacheDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $step = 0;
     }
     foreach ($cacheIds as $key => $cacheId) {
         if ($progress && $key % 100 == 0) {
             $step += 100;
             $progress->next(1, "memcache {$step} / {$count}");
         }
         Kwf_Component_Cache_Memory::getInstance()->remove($cacheId, $microtime);
     }
     $this->_afterMemcacheDelete($select);
     // For unit testing - DO NOT DELETE!
     // FullPage
     if ($progress) {
         $progress->next(1, "fullPage");
     }
     $s = new Kwf_Model_Select();
     $s->whereEquals('type', 'fullPage');
     if ($checkIncludeIds) {
         $ids = array_keys($this->_fetchIncludesTree(array_keys($checkIncludeIds)));
         if ($ids) {
             foreach ($ids as &$id) {
                 $id = (string) $id;
             }
             unset($id);
             $s->whereEquals('component_id', $ids);
             if ($log) {
                 foreach ($ids as $id) {
                     $log->log("type=fullPage component_id={$id}", Zend_Log::INFO);
                 }
             }
             $this->_deleteViewCacheBySelect($s);
         }
     }
     // Database
     $this->_beforeDatabaseDelete($select);
     // For unit testing - DO NOT DELETE!
     $deletedCount = 0;
     if ($progress) {
         $progress->next(1, "partialIds");
     }
     foreach ($partialIds as $componentId => $values) {
         $deletedCount += count($values);
         $select = $model->select();
         $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', (string) $componentId), new Kwf_Model_Select_Expr_Equals('type', 'partial'), new Kwf_Model_Select_Expr_Equals('value', $values), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime))));
         $model->updateRows(array('deleted' => true), $select);
     }
     if ($progress) {
         $progress->next(1, "deleteIds");
     }
     foreach ($deleteIds as $type => $componentIds) {
         $deletedCount += count($componentIds);
         $select = $model->select();
         $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', $componentIds), new Kwf_Model_Select_Expr_Equals('type', $type), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime))));
         $model->updateRows(array('deleted' => true), $select);
     }
     if ($fullPageUrls) {
         foreach ($fullPageUrls as $domainComponentId => $urls) {
             Kwf_Events_Dispatcher::fireEvent(new Kwf_Component_Event_ViewCache_ClearFullPage(get_class($this), $domainComponentId, $urls));
         }
     }
     $this->_afterDatabaseDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $progress->finish();
     }
     file_put_contents('log/clear-view-cache', date('Y-m-d H:i:s') . ' ' . round(microtime(true) - Kwf_Benchmark::$startTime, 2) . 's; ' . Kwf_Events_Dispatcher::$eventsCount . ' events; ' . $deletedCount . ' view cache entries deleted; ' . (isset($_SERVER['REQUEST_URI']) ? substr($_SERVER['REQUEST_URI'], 0, 100) : '') . "\n", FILE_APPEND);
     return count($cacheIds);
 }
Esempio n. 17
0
 public function setUp()
 {
     parent::setUp();
     $this->_m = Kwf_Model_Abstract::getInstance('Kwf_Model_Union_DeletedFlag_TestModel');
     Kwf_Events_Dispatcher::addListeners('Kwf_Model_Union_DeletedFlag_TestModel');
 }
Esempio n. 18
0
 public function duplicateChild($source, $parentTarget, Zend_ProgressBar $progressBar = null)
 {
     if ($progressBar) {
         $progressBar->next();
     }
     $progressBar = null;
     //stop here, as getDuplicateProgressSteps doesn't go any deeper
     if ($source->generator !== $this) {
         throw new Kwf_Exception("you must call this only with the correct source");
     }
     $ev = new Kwf_Component_Event_Component_FilterAddComponentClass($source->componentClass, $parentTarget);
     Kwf_Events_Dispatcher::fireEvent($ev);
     if ($ev->deny) {
         return null;
     }
     $newRow = $this->_duplicateRow($source, $parentTarget);
     if (!$newRow) {
         return null;
     }
     $id = $this->_idSeparator . $newRow->{$this->_getModel()->getPrimaryKey()};
     $targetGen = Kwf_Component_Generator_Abstract::getInstance($parentTarget->componentClass, $this->getGeneratorKey());
     $targetChildData = $targetGen->getChildData($parentTarget, array('id' => $id, 'ignoreVisible' => true, 'limit' => 1));
     $target = array_pop($targetChildData);
     if (!$target) {
         return null;
     }
     Kwc_Admin::getInstance($source->componentClass)->duplicate($source, $target, $progressBar);
     return $target;
 }
 /**
  * This function is used by Kwc_Basic_ImageEnlarge_EnlargeTag_ImagePage_Component
  * to get the url to show the image from parent with dimension defined through
  * this component.
  */
 public function getImageUrl()
 {
     $baseUrl = $this->getBaseImageUrl();
     if ($baseUrl) {
         $dimensions = $this->getImageDimensions();
         $imageData = $this->getImageData();
         $width = Kwf_Media_Image::getResponsiveWidthStep($dimensions['width'], Kwf_Media_Image::getResponsiveWidthSteps($dimensions, $imageData['file']));
         $ret = str_replace('{width}', $width, $baseUrl);
         $ev = new Kwf_Component_Event_CreateMediaUrl($this->getData()->componentClass, $this->getData(), $ret);
         Kwf_Events_Dispatcher::fireEvent($ev);
         return $ev->url;
     }
     return null;
 }
 public function getTypes()
 {
     $types = array();
     $simpleCacheBackend = Kwf_Cache_Simple::getBackend();
     if ($simpleCacheBackend == 'memcache' || $simpleCacheBackend == 'redis') {
         $types[] = new Kwf_Util_ClearCache_Types_SimpleCache();
     }
     if (Kwf_Util_Apc::isAvailable()) {
         $types[] = new Kwf_Util_ClearCache_Types_ApcUser();
         $types[] = new Kwf_Util_ClearCache_Types_ApcOptcode();
     }
     foreach ($this->_getCacheDirs() as $d) {
         if ($d != 'config' && $d != 'assets' && $d != 'trl' && $d != 'view') {
             $types[] = new Kwf_Util_ClearCache_Types_Dir($d);
         }
     }
     if (Kwf_Component_Data_Root::getInstance()) {
         $types[] = new Kwf_Util_ClearCache_Types_ComponentView();
         $types[] = new Kwf_Util_ClearCache_Types_ComponentUrl();
     }
     foreach ($this->_getDbCacheTables() as $t) {
         if ($t == 'cache_component' || $t == 'cache_component_includes' || $t == 'cache_component_url') {
             //never completely clear that table as it would break clearing fullPage cache
         } else {
             if ($t == 'cache_users') {
                 //skip, needed during update
             } else {
                 $types[] = new Kwf_Util_ClearCache_Types_Table($t);
             }
         }
     }
     $types[] = new Kwf_Util_ClearCache_Types_Config();
     $types[] = new Kwf_Util_ClearCache_Types_Setup();
     $types[] = new Kwf_Util_ClearCache_Types_Assets();
     if (file_exists('symfony/bin/console')) {
         $types[] = new Kwf_Util_ClearCache_Types_Symfony();
     }
     if (!Kwf_Config::getValue('clearCacheSkipProcessControl') && VENDOR_PATH != '../vendor') {
         $types[] = new Kwf_Util_ClearCache_Types_ProcessControl();
     }
     $ev = new Kwf_Events_Event_FetchClearCacheTypes(get_class($this));
     Kwf_Events_Dispatcher::fireEvent($ev);
     $types = array_merge($types, $ev->types);
     return $types;
 }
Esempio n. 21
0
 /**
  * @internal
  */
 public static function reset($resetCache = true)
 {
     self::$_instance = null;
     Kwf_Component_Generator_Abstract::clearInstances();
     Kwf_Component_Abstract::clearModelInstances();
     Kwf_Events_Dispatcher::clearCache();
     if ($resetCache) {
         Kwf_Component_Abstract::resetSettingsCache();
     }
 }
 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;
 }
Esempio n. 23
0
 public static function fireEvent($event)
 {
     Kwf_Events_Dispatcher::fireEvent($event);
 }
Esempio n. 24
0
 public static function clearCache()
 {
     self::$_listeners = null;
     self::$_subscribedModels = null;
 }
 public function includeCode($position)
 {
     $data = $this->_getView()->component;
     $ret = '';
     if ($position == 'header') {
         if (Kwf_Config::getValue('application.kwf.name') == 'Koala Framework') {
             $ret .= "<!--\n";
             $ret .= "    This website is powered by Koala Web Framework CMS Version " . Kwf_Config::getValue('application.kwf.version') . ".\n";
             $ret .= "    Koala Framework is a free open source Content Management Framework licensed under BSD.\n";
             $ret .= "    http://www.koala-framework.org\n";
             $ret .= "-->\n";
         }
         $helper = new Kwf_View_Helper_DebugData();
         $ret .= $helper->debugData();
     }
     $flag = $position == 'header' ? 'hasHeaderIncludeCode' : 'hasFooterIncludeCode';
     $cmps = $data->getPage()->getRecursiveChildComponents(array('flags' => array($flag => true)));
     if (Kwc_Abstract::getFlag($data->componentClass, $flag)) {
         $cmps[] = $data;
     }
     $statisticsBoxUsed = false;
     $assetsBoxUsed = false;
     foreach ($cmps as $c) {
         $includeCode = $c->getComponent()->getIncludeCode($position);
         if (is_string($includeCode)) {
             $ret .= $includeCode;
         } else {
             if (is_object($includeCode) && $includeCode instanceof Kwf_Component_Data) {
                 $componentHelper = new Kwf_Component_View_Helper_Component();
                 $componentHelper->setRenderer($this->_getRenderer());
                 $componentHelper->setView($this->_getView());
                 $ret .= $componentHelper->component($includeCode);
                 if (is_instance_of($includeCode->componentClass, 'Kwc_Statistics_Analytics_Component') || is_instance_of($includeCode->componentClass, 'Kwc_Statistics_Piwik_Component')) {
                     $statisticsBoxUsed = true;
                 }
                 if (is_instance_of($includeCode->componentClass, 'Kwc_Box_Assets_Component')) {
                     $assetsBoxUsed = true;
                 }
             } else {
                 if (is_null($includeCode)) {
                 } else {
                     throw new Kwf_Exception("invalid getIncludeCode return type");
                 }
             }
         }
     }
     if ($position == 'header') {
         if ($v = Kwf_Config::getValue('kwc.favicon')) {
             $v = Kwf_Setup::getBaseUrl() . $v;
             $ev = new Kwf_Events_Event_CreateAssetUrl(get_class($this), $v, $data->getSubroot());
             Kwf_Events_Dispatcher::fireEvent($ev);
             $v = $ev->url;
             $ret .= "<link rel=\"shortcut icon\" href=\"{$v}\" />\n";
         }
         if (!$assetsBoxUsed) {
             //add default assets if there was no box
             $a = new Kwf_View_Helper_Assets();
             $ret .= $a->assets(Kwf_Assets_Package_Default::getInstance('Frontend'), null);
         }
     } else {
         if ($position == 'footer') {
             if (!$statisticsBoxUsed) {
                 //if there was no statistics box output default code
                 //box is required for eg. multidomains
                 $cfg = Kwf_Config::getValueArray('statistics');
                 if (isset($cfg['analytics']['code']) && $cfg['analytics']['code']) {
                     throw new Kwf_Exception('To support analytics add Kwc_Statistics_Analytics_Component as a box.');
                 }
                 if (isset($cfg['piwik']['id']) && $cfg['piwik']['id']) {
                     throw new Kwf_Exception('To support piwik add Kwc_Statistics_Piwik_Component as a box.');
                 }
             }
         }
     }
     return $ret;
 }
Esempio n. 26
0
 private function _deleteViewCache(array $updates, $dryRun)
 {
     $prefixes = array('component_id' => 'viewids:componentid:', 'db_id' => 'viewids:dbid:', 'page_db_id' => 'viewids:pagedbid:', 'component_class' => 'viewids:cls:', 'tag' => 'viewids:tag:', 'expanded_component_id' => 'viewids:recexpandedid:');
     if (isset($updates['component_id'])) {
         $updates[] = array('component_id' => $updates['component_id'], 'type' => 'component');
         unset($updates['component_id']);
     }
     if (isset($updates['master-component_id'])) {
         $updates[] = array('component_id' => $updates['master-component_id'], 'type' => 'master');
         unset($updates['master-component_id']);
     }
     $ret = 0;
     $checkIncludeIds = array();
     foreach ($updates as $update) {
         $keys = array();
         foreach ($update as $key => $value) {
             if ($key == 'type') {
                 //not in redis query, handled below
                 continue;
             }
             if (!isset($prefixes[$key])) {
                 throw new Kwf_Exception("Unsupported updates key '{$key}'");
             }
             if (!is_array($value)) {
                 if ($key == 'expanded_component_id') {
                     if (substr($value, -1) != '%') {
                         throw new Kwf_Exception("'{$key}' must have % at the end");
                     }
                 } else {
                     if (strpos($value, '%') !== false) {
                         throw new Kwf_Exception("Unsupported % for key '{$key}'");
                     }
                 }
                 $keys[] = $prefixes[$key] . substr($value, 0, -1);
             } else {
                 $tempKey = 'temp:' . md5(implode(':', $value));
                 $args = array($tempKey);
                 foreach ($value as $i) {
                     $args[] = $prefixes[$key] . $i;
                     //key
                 }
                 call_user_func_array(array($this->_redis, 'sUnionStore'), $args);
                 $this->_redis->expire($tempKey, 20);
                 $keys[] = $tempKey;
             }
         }
         if ($update === array()) {
             //only when executing "clear-view-cache --all" on cli
             $prefixLength = strlen($this->_redis->_prefix(''));
             $it = null;
             $keysToDelete = array();
             while ($keys = $this->_redis->scan($it, $this->_redis->_prefix('viewcache:*'))) {
                 foreach ($keys as $i) {
                     $keysToDelete[] = substr($i, $prefixLength);
                 }
             }
             $keysToDelete = array_unique($keysToDelete);
         } else {
             $keysToDelete = $this->_redis->sInter($keys);
         }
         if ($keysToDelete) {
             foreach ($keysToDelete as $keyIndex => $key) {
                 $key = self::_parseCacheId($key);
                 if (isset($update['type'])) {
                     //not in redis query
                     if ($key['type'] != $update['type']) {
                         unset($keysToDelete[$keyIndex]);
                     }
                 }
                 if ($key['type'] != 'fullPage') {
                     $checkIncludeIds[$key['componentId'] . ':' . $key['type']] = true;
                 } else {
                     //type == fullPage, in this case $key also contains the url which we don't have in the view cache key, so generate cacheId
                     $keysToDelete[$keyIndex] = self::_getCacheId($key['componentId'], $key['renderer'], $key['type'], $key['value']);
                 }
             }
             if (Kwf_Cache_Simple::getBackend() == 'memcache') {
                 if (!$dryRun) {
                     foreach ($keysToDelete as $key) {
                         Kwf_Cache_Simple::getMemcache()->delete($key);
                     }
                 } else {
                     $ret = count(Kwf_Cache_Simple::getMemcache()->get($keysToDelete));
                 }
             } else {
                 if (!$dryRun) {
                     $ret += $this->_redis->delete($keysToDelete);
                 } else {
                     foreach ($keysToDelete as $i) {
                         $ret += $this->_redis->exists($i);
                     }
                 }
             }
         }
     }
     // FullPage
     $fullPageUrls = array();
     if (!$dryRun && $checkIncludeIds) {
         $ids = array_keys($this->_fetchIncludesTree(array_keys($checkIncludeIds)));
         if ($ids) {
             $keys = array();
             foreach ($ids as $id) {
                 $keys[] = 'viewids:componentid:' . $id;
             }
             $fullPageKeysToDelete = array();
             foreach (call_user_func_array(array($this->_redis, 'sUnion'), $keys) as $i) {
                 $parts = self::_parseCacheId($i);
                 if ($parts['type'] == 'fullPage') {
                     $fullPageKeysToDelete[] = self::_getCacheId($parts['componentId'], $parts['renderer'], $parts['type'], $parts['value']);
                     if (!isset($fullPageUrls[$parts['domainComponentId']])) {
                         $fullPageUrls[$parts['domainComponentId']] = array();
                     }
                     $fullPageUrls[$parts['domainComponentId']][$parts['componentId']] = $parts['url'];
                 }
             }
             if (Kwf_Cache_Simple::getBackend() == 'memcache') {
                 foreach ($fullPageKeysToDelete as $key) {
                     Kwf_Cache_Simple::getMemcache()->delete($key);
                 }
             } else {
                 $this->_redis->delete($fullPageKeysToDelete);
             }
         }
     }
     if ($fullPageUrls) {
         Kwf_Events_Dispatcher::fireEvent(new Kwf_Component_Event_ViewCache_ClearFullPage(get_class($this), $fullPageUrls));
     }
     return $ret;
 }
 protected function _initFields()
 {
     //--- main generator form (if Category_Generator this contains Pagename and Pagetype)
     $componentOrParent = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getComponentOrParentId(), array('ignoreVisible' => true));
     if (!$componentOrParent || !Kwf_Registry::get('acl')->getComponentAcl()->isAllowed($this->_getAuthData(), $componentOrParent)) {
         throw new Kwf_Exception_AccessDenied();
     }
     if ($this->_getParam('id')) {
         if ($componentOrParent->componentId == 'root') {
             $this->_form = null;
         } else {
             $this->_form = $componentOrParent->generator->getPagePropertiesForm($componentOrParent);
         }
     } else {
         $gens = Kwf_Component_Generator_Abstract::getInstances($componentOrParent, array('pageGenerator' => true));
         if (count($gens) != 1) {
             throw new Kwf_Exception('pageGenerator not found');
         }
         $gen = array_shift($gens);
         $this->_form = $gen->getPagePropertiesForm($componentOrParent);
     }
     if (!$this->_form) {
         $this->_form = new Kwf_Form();
         $this->_form->setModel(Kwf_Model_Abstract::getInstance('Kwf_Component_Model'));
         $this->_form->add(new Kwf_Form_Field_ShowField('name', trlKwf('Name')));
     }
     //--- and now add the more complicated additional forms
     $fields = $this->_form->fields;
     $componentField = $this->_form->getComponentField();
     if ($componentField) {
         $possibleComponentClasses = $componentField->getPossibleComponentClasses();
         $this->_componentField = $componentField;
     } else {
         if (!$this->_getParam('id')) {
             throw new Kwf_Exception("not supported for adding");
         }
         $possibleComponentClasses = array($componentOrParent->componentClass);
     }
     $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getComponentOrParentId(), array('ignoreVisible' => true));
     if ($this->_getParam('id')) {
         //$component is the component, just get inheritClasses
         $inheritClasses = $component->inheritClasses;
     } else {
         //$component is the parent component (we are adding)
         //this code is very similar to Kwf_Component_Data::__get inheritClasses
         $inheritClasses = array();
         $page = $component;
         while ($page) {
             foreach (Kwc_Abstract::getSetting($page->componentClass, 'generators') as $gKey => $g) {
                 if (isset($g['inherit']) && $g['inherit']) {
                     if (isset($g['unique']) && $g['unique']) {
                         continue;
                     }
                     //ignore, not edited
                     if (!in_array($page->componentClass, $inheritClasses)) {
                         $inheritClasses[] = $page->componentClass;
                     }
                 }
             }
             if ($page->inherits) {
                 //wenn page selbst erbt einfach von da übernehmen (rekursiver aufruf)
                 $inheritClasses = array_merge($inheritClasses, $page->inheritClasses);
                 break;
                 //aufhören, rest kommt durch rekursion daher
             }
             $page = $page->parent;
         }
     }
     unset($component);
     $generatorForms = array();
     $componentForms = array();
     $formsForComponent = array();
     $componentValues = array();
     if ($componentField) {
         $componentValues = $componentField->getValues();
     }
     foreach ($possibleComponentClasses as $key => $componentClass) {
         $ev = new Kwf_Component_Event_Component_FilterAddComponentClass($componentClass, $componentOrParent);
         Kwf_Events_Dispatcher::fireEvent($ev);
         if ($ev->deny) {
             if ($this->_getParam('id') && $componentOrParent->componentClass == $componentClass) {
                 //in edit-mode allow already used componentClass
             } else {
                 unset($componentValues[$key]);
                 continue;
             }
         }
         $component = array('componentClass' => $componentClass, 'inheritClasses' => $inheritClasses);
         $formsForComponent[$key] = array();
         $classesToCheckForPagePropertiesForm = array('__pageComponent' => $componentClass);
         foreach (Kwf_Component_Generator_Abstract::getInstances($component) as $g) {
             if ($g->getGeneratorFlag('page')) {
                 continue;
             }
             if (!array_key_exists($g->getClass() . '.' . $g->getGeneratorKey(), $generatorForms)) {
                 $f = $g->getPagePropertiesForm($componentOrParent);
                 if ($f) {
                     $f->setName('gen_' . $g->getClass() . '_' . $g->getGeneratorKey());
                     $f->setIdTemplate('{0}-' . $g->getGeneratorKey());
                     $f->setCreateMissingRow(true);
                     $f->setShowDependingOnComponent(true);
                     $this->_dynamicForms[] = $f;
                     $fields->add($f);
                 }
                 $generatorForms[$g->getClass() . '.' . $g->getGeneratorKey()] = $f;
             }
             if ($generatorForms[$g->getClass() . '.' . $g->getGeneratorKey()]) {
                 $formsForComponent[$key][] = 'gen_' . $g->getClass() . '_' . $g->getGeneratorKey();
             }
             if ($g->getGeneratorFlag('static')) {
                 $classesToCheckForPagePropertiesForm = array_merge($classesToCheckForPagePropertiesForm, $g->getChildComponentClasses());
             }
         }
         foreach ($classesToCheckForPagePropertiesForm as $childComponentKey => $childComponentClass) {
             if (!array_key_exists($key . '_' . $childComponentKey, $componentForms)) {
                 $config = array();
                 $config['component'] = $componentOrParent;
                 if ($this->_getParam('id')) {
                     $config['mode'] = 'edit';
                 } else {
                     $config['mode'] = 'add';
                 }
                 $f = Kwc_Admin::getInstance($childComponentClass)->getPagePropertiesForm($config);
                 if ($f) {
                     $f->setName('cmp_' . $key . '_' . $childComponentKey);
                     if ($childComponentKey == '__pageComponent') {
                         $f->setIdTemplate('{0}');
                     } else {
                         $f->setIdTemplate('{0}-' . $childComponentKey);
                     }
                     $f->setShowDependingOnComponent(true);
                     $this->_dynamicForms[] = $f;
                     $fields->add($f);
                 }
                 $componentForms[$key . '_' . $childComponentKey] = $f;
             }
             if ($componentForms[$key . '_' . $childComponentKey]) {
                 $formsForComponent[$key][] = 'cmp_' . $key . '_' . $childComponentKey;
             }
         }
     }
     if ($componentField) {
         $componentField->setValues($componentValues);
         $componentField->setFormsForComponent($formsForComponent);
     }
     $this->_form->setId($this->_getParam('id'));
 }
 private function _duplicatePageRecursive($parentSourceId, $parentTargetId, $childId, Zend_ProgressBar $progressBar = null)
 {
     $pd = $this->_getPageData($childId);
     if ($progressBar) {
         $progressBar->next(1, trlKwf("Pasting {0}", $pd['name']));
     }
     $data = array();
     $data['parent_id'] = Kwf_Component_Data_Root::getInstance()->getComponentById($parentTargetId, array('ignoreVisible' => true))->dbId;
     $sourceRow = $this->getModel()->getRow($childId);
     if ($sourceRow->is_home) {
         //copy is_home only if target has no home yet
         $t = Kwf_Component_Data_Root::getInstance()->getComponentById($parentTargetId, array('ignoreVisible' => true));
         while ($t && !Kwc_Abstract::getFlag($t->componentClass, 'hasHome')) {
             $t = $t->parent;
         }
         if (!$t || $t->getChildPage(array('home' => true, 'ignoreVisible' => true), array())) {
             $data['is_home'] = false;
         }
     }
     $newRow = $sourceRow->duplicate($data);
     //clear cache in here as while duplicating the modelobserver might be disabled
     Kwf_Cache_Simple::delete('pcIds-' . $newRow->parent_id);
     //ids are numeric, we don't have to use parentSource/parentTarget
     $source = Kwf_Component_Data_Root::getInstance()->getComponentById($childId, array('ignoreVisible' => true));
     $target = Kwf_Component_Data_Root::getInstance()->getComponentById($newRow->id, array('ignoreVisible' => true));
     if (!$target) {
         throw new Kwf_Exception("didn't find just duplicated component '{$newRow->id}' below '{$parentTarget->componentId}'");
     }
     $ev = new Kwf_Component_Event_Component_FilterAddComponentClass($source->componentClass, $target);
     Kwf_Events_Dispatcher::fireEvent($ev);
     if ($ev->deny) {
         //increment for number of child pages as those will be skipped
         if ($progressBar) {
             $progressBar->next($this->getDuplicateProgressSteps($source) - 1);
         }
         return null;
     }
     Kwc_Admin::getInstance($source->componentClass)->duplicate($source, $target, $progressBar);
     $sourceId = $source->componentId;
     $targetId = $target->componentId;
     unset($source);
     unset($target);
     unset($sourceRow);
     unset($newRow);
     /*
     echo round(memory_get_usage()/1024/1024, 2)."MB";
     echo " gen: ".Kwf_Component_Generator_Abstract::$objectsCount.', ';
     echo " data: ".Kwf_Component_Data::$objectsCount.', ';
     echo " row: ".Kwf_Model_Row_Abstract::$objectsCount.'';
     $s = microtime(true);
     */
     Kwf_Component_Data_Root::getInstance()->freeMemory();
     /*
     echo ' / '.round((microtime(true)-$s)*1000, 2).' ms ';
     echo ' / '.round(memory_get_usage()/1024/1024, 2)."MB";
     echo " gen: ".Kwf_Component_Generator_Abstract::$objectsCount.', ';
     echo " data: ".Kwf_Component_Data::$objectsCount.', ';
     echo " row: ".Kwf_Model_Row_Abstract::$objectsCount.'';
     //var_dump(Kwf_Model_Row_Abstract::$objectsByModel);
     //var_dump(Kwf_Component_Data::$objectsById);
     echo "\n";
     */
     foreach ($this->_getChildPageIds($childId) as $i) {
         if ($i != $targetId) {
             //no endless recursion id page is pasted below itself
             $this->_duplicatePageRecursive($sourceId, $targetId, $i, $progressBar);
         }
     }
     return $targetId;
 }
 public function process()
 {
     if ($this->_modelEventFired) {
         Kwf_Events_Dispatcher::fireEvent(new Kwf_Events_Event_Row_UpdatesFinished());
     }
 }