public function jsonDuplicateAction() { if (!isset($this->_permissions['duplicate']) || !$this->_permissions['duplicate']) { throw new Kwf_Exception("Duplicate is not allowed."); } $ids = $this->getRequest()->getParam($this->_primaryKey); $ids = explode(';', $ids); $this->view->data = array('duplicatedIds' => array()); $parentTarget = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId')); foreach ($ids as $id) { $sourceId = $this->_getParam('componentId') . '_' . $id; $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($sourceId); // Switch off observer due to performance - it's not necessary here Kwf_Events_ModelObserver::getInstance()->disable(); $newDetail = Kwf_Util_Component::duplicate($source, $parentTarget); Kwf_Util_Component::afterDuplicate($source, $newDetail); Kwf_Events_ModelObserver::getInstance()->enable(); $newDetailRow = $newDetail->row; $newDetailRow->create_date = date('Y-m-d H:i:s'); $newDetailRow->mails_per_minute = 'normal'; $newDetailRow->start_date = null; $newDetailRow->resume_date = null; $newDetailRow->last_sent_date = null; $newDetailRow->count_sent = null; $newDetailRow->status = null; $newDetailRow->save(); $mailRow = $newDetail->getChildComponent('_mail')->getComponent()->getRow(); $mailRow->subject = trlKwf('Copy of') . ' ' . $mailRow->subject; $mailRow->save(); } }
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 jsonPasteAction() { $session = new Kwf_Session_Namespace('PagesController:copy'); $id = $session->id; if (!$id || !Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true))) { throw new Kwf_Exception_Client(trlKwf('Clipboard is empty')); } $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true)); $target = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('id'), array('ignoreVisible' => true)); $user = Zend_Registry::get('userModel')->getAuthedUser(); $acl = Kwf_Registry::get('acl')->getComponentAcl(); if (!$acl->isAllowed($user, $source) || !$acl->isAllowed($user, $target)) { throw new Kwf_Exception_AccessDenied(); } $progressBar = new Zend_ProgressBar(new Kwf_Util_ProgressBar_Adapter_Cache($this->_getParam('progressNum')), 0, Kwf_Util_Component::getDuplicateProgressSteps($source)); Kwf_Util_MemoryLimit::set(256); Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. $newPage = Kwf_Util_Component::duplicate($source, $target, $progressBar); Kwf_Util_Component::afterDuplicate($source, $newPage); Kwf_Events_ModelObserver::getInstance()->enable(); $progressBar->finish(); $s = new Kwf_Model_Select(); $s->whereEquals('parent_id', $newPage->row->parent_id); $s->order('pos', 'DESC'); $s->limit(1); $lastRow = $newPage->generator->getModel()->getRow($s); $row = $newPage->generator->getModel()->getRow($newPage->row->id); $row->pos = $lastRow ? $lastRow->pos + 1 : 1; $row->visible = false; $row->save(); }
public function testAction() { $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('source'), array('ignoreVisible' => true)); if (!$source) { throw new Kwf_Exception_Client("source not found"); } $parentTarget = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('target'), array('ignoreVisible' => true)); if (!$parentTarget) { throw new Kwf_Exception_Client("target not found"); } Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. echo "counting pages..."; $steps = Kwf_Util_Component::getDuplicateProgressSteps($source); echo " " . $steps . "\n"; $ad = new Zend_ProgressBar_Adapter_Console(); $ad->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT, Zend_ProgressBar_Adapter_Console::ELEMENT_ETA)); $progressBar = new Zend_ProgressBar($ad, 0, $steps); $target = Kwf_Util_Component::duplicate($source, $parentTarget, $progressBar); Kwf_Util_Component::afterDuplicate($source, $target); $progressBar->finish(); exit; }
public function jsonPasteAction() { $session = new Kwf_Session_Namespace('Kwc_Paragraphs:copy'); $id = $session->id; if (!$id || !Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true))) { throw new Kwf_Exception_Client(trlKwf('Clipboard is empty')); } $target = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId'), array('ignoreVisible' => true)); $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true)); $c = $target; while ($c->parent) { if ($c->dbId == $source->dbId) { throw new Kwf_Exception_Client(trlKwf("You can't paste a paragraph into itself.")); } if ($c->isPage) { break; } $c = $c->parent; } $sourceIsParagraphs = is_instance_of($source->componentClass, 'Kwc_Paragraphs_Component'); if ($source->isPage && $sourceIsParagraphs) { //a whole paragraphs component is in clipboard $sources = $source->getChildComponents(array('generator' => 'paragraphs', 'ignoreVisible' => true)); } else { if (!$source->isPage && !is_instance_of($source->parent->componentClass, 'Kwc_Paragraphs_Component')) { //a whole paragraphs component is in clipboard $sources = $source->getChildComponents(array('generator' => 'paragraphs', 'ignoreVisible' => true)); } else { //a single paragraph (paragraphs child) is in clipboard $sources = array($source); } } $classes = Kwc_Abstract::getChildComponentClasses($target->componentClass, 'paragraphs'); Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. $progressBar = new Zend_ProgressBar(new Kwf_Util_ProgressBar_Adapter_Cache($this->_getParam('progressNum')), 0, Kwf_Util_Component::getDuplicateProgressSteps($source)); $newPos = $this->_getParam('pos'); $countDuplicated = 0; $errorMsg = false; foreach ($sources as $s) { $targetCls = false; if (isset($classes[$s->row->component])) { $targetCls = $classes[$s->row->component]; } $sourceCls = $s->componentClass; $sourceCls = strpos($sourceCls, '.') ? substr($sourceCls, 0, strpos($sourceCls, '.')) : $sourceCls; $targetCls = strpos($targetCls, '.') ? substr($targetCls, 0, strpos($targetCls, '.')) : $targetCls; if ($sourceCls != $targetCls) { if (Kwc_Abstract::hasSetting($s->componentClass, 'componentName')) { $name = Kwf_Trl::getInstance()->trlStaticExecute(Kwc_Abstract::getSetting($s->componentClass, 'componentName')); $errorMsg = trlKwf("Can't paste paragraph type '{0}', as it is not avaliable here.", $name); } else { $errorMsg = trlKwf('Source and target paragraphs are not compatible.'); } continue; //skip this one } $newParagraph = Kwf_Util_Component::duplicate($s, $target, $progressBar); $countDuplicated++; $row = $newParagraph->row; $row->pos = $newPos++; $row->visible = false; $row->save(); } Kwf_Util_Component::afterDuplicate($source, $target); $progressBar->finish(); Kwf_Events_ModelObserver::getInstance()->enable(); if (!$countDuplicated && $errorMsg) { //if at least one was duplicated show no error, else show one throw new Kwf_Exception_Client($errorMsg); } }
public function jsonPasteAction() { $this->_validateMaxEntries(); $session = new Kwf_Session_Namespace('Kwc_Abstract_List:copy'); $id = $session->id; if (!$id || !Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true))) { throw new Kwf_Exception_Client(trlKwf('Clipboard is empty')); } $target = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId'), array('ignoreVisible' => true)); $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true)); if ($source->parent->componentClass != $target->componentClass) { throw new Kwf_Exception_Client(trlKwf('Source and target paragraphs are not compatible.')); } Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. $progressBar = null; $newItem = Kwf_Util_Component::duplicate($source, $target, $progressBar); $row = $newItem->row; $target->getChildComponents(array('ignoreVisible' => true)); $row->pos = null; //moves to end of list $row->visible = false; $row->save(); Kwf_Util_Component::afterDuplicate($source, $target); Kwf_Events_ModelObserver::getInstance()->enable(); }
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 function testDuplicate() { $source = $this->_root->getComponentById('1'); $target = $this->_root->getComponentById('4'); $this->assertEquals(0, count($target->getChildPages())); Kwf_Events_ModelObserver::getInstance()->disable(); //PagesController also does that (for performance reasons) Kwf_Util_Component::duplicate($source, $target); Kwf_Events_ModelObserver::getInstance()->enable(); $this->assertEquals(1, count($target->getChildPages())); $this->assertEquals(1, count($target->getChildPage()->getChildPages())); }
public function jsonDuplicateAction() { if (!isset($this->_permissions['duplicate']) || !$this->_permissions['duplicate']) { throw new Kwf_Exception("Duplicate is not allowed."); } $ids = $this->getRequest()->getParam($this->_primaryKey); $ids = explode(';', $ids); $progressBar = null; $this->view->data = array('duplicatedIds' => array()); ignore_user_abort(true); if (Zend_Registry::get('db')) { Zend_Registry::get('db')->beginTransaction(); } $dir = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId'), array('ignoreVisible' => true, 'limit' => 1)); foreach ($ids as $id) { $child = $dir->getChildComponent(array('id' => '-' . $id, 'ignoreVisible' => true)); $newChild = Kwf_Util_Component::duplicate($child, $dir, $progressBar); $newChild->row->save(); $this->view->data['duplicatedIds'][] = $newChild->id; } if (Zend_Registry::get('db')) { Zend_Registry::get('db')->commit(); } }