Exemplo n.º 1
0
 /**
  * @return HttpResponse
  */
 public function getAjaxRevisionControlBox()
 {
     $pageModel = new PageModel($this->db);
     $cmsPage = $pageModel->getPageByID($this->route->getParam(1));
     $elementModel = new ElementModel($this->db);
     $elementTree = $elementModel->getElementTree($cmsPage);
     $elementInstance = $elementModel->findElementIDInTree($elementTree, $this->route->getParam(0));
     try {
         $res = $elementInstance->generateRevisionBox($this, $cmsPage->getID());
     } catch (PHPException $e) {
         return $this->generateResponse(500, '<p><b>PHP Error:</b> ' . $e->getMessage() . ' in ' . $e->getFile() . ' (Line: ' . $e->getLine() . ')</p><pre>' . $e->getTraceAsString() . '</pre>');
     } catch (\Exception $e) {
         return $this->generateResponse(500, '<p>' . $e->getMessage() . '</p>');
     }
     return $this->generateResponse(200, $res);
 }
Exemplo n.º 2
0
 public function index()
 {
     $oldReqUri = $_SERVER['REQUEST_URI'];
     $_SERVER['REQUEST_URI'] = '';
     $pageModel = new PageModel($this->indexer->getDB());
     $elementModel = new ElementModel($this->indexer->getDB());
     $searchModel = new SearchModel($this->indexer->getDB());
     $stmntPages = $this->indexer->getDB()->prepare("\n\t\t\tSELECT p.ID, p.language_codeFK lang, p.title, p.description, r.pattern, p.role\n\t\t\tFROM page p\n\t\t\tLEFT JOIN route r ON r.page_IDFK = p.ID\n\t\t\tWHERE r.ID IS NOT NULL\n\t\t");
     $resPages = $this->indexer->getDB()->select($stmntPages);
     $indexedPages = 0;
     foreach ($resPages as $p) {
         if ($p->role !== 'page') {
             echo "  Skipped page #" . $p->ID . ": reason -> unusable role: " . $p->role . PHP_EOL;
             continue;
         }
         $searchIndexInterface = $this->indexer->getIndex($p->lang);
         // Index page
         echo "  Indexing page #" . $p->ID . " into index \"" . $p->lang . "\": ";
         $cmsPage = $pageModel->getPageByID($p->ID);
         $elementTree = $elementModel->getElementTree($cmsPage);
         try {
             $searchableContent = $this->renderElementTreeRecursive($elementTree, $cmsPage->getLanguage());
         } catch (\Exception $e) {
             echo " Error -> " . $e->getMessage() . "\n";
             continue;
         }
         $searchDoc = new Document();
         $searchDoc->setInternalID($p->ID);
         $searchDoc->setLanguage($p->lang);
         $searchDoc->setTitle($p->title);
         $searchDoc->setDescription($searchableContent);
         $searchDoc->setPath($p->pattern);
         $searchDoc->setType('core_page');
         $docID = $searchModel->saveDocument($searchDoc);
         $luceneDocument = new \ZendSearch\Lucene\Document();
         $luceneDocument->addField(Field::keyword('ID', $docID));
         $luceneDocument->addField(Field::unStored('content', $searchableContent));
         $luceneDocument->addField(Field::unStored('description', $p->description));
         $searchIndexInterface->addDocument($luceneDocument);
         echo "done";
         echo "\n";
         ++$indexedPages;
     }
     $_SERVER['REQUEST_URI'] = $oldReqUri;
     echo "  Total indexed pages: " . $indexedPages . "\n";
 }
Exemplo n.º 3
0
 /**
  * Generates an error page for a thrown exception which was not caught anywhere else in the code
  * 
  * @param \Exception $e The uncaught exception
  *
  * @return HttpResponse The HTTP response for sending back to the client (e.x. a nice styled error message)
  */
 public function generateErrorPage(\Exception $e)
 {
     $errorCode = 500;
     if ($e instanceof HttpException) {
         $errorCode = $e->getCode();
     }
     if ($e instanceof HttpException === false || $e->getCode() === 500) {
         $this->logger->error('An uncaught error occurred', $e);
     }
     $stmntErrorPage = $this->db->prepare("SELECT ID FROM page WHERE role = 'error' AND error_code = ?");
     $resErrorPage = $this->db->select($stmntErrorPage, array($errorCode));
     $env = $this->currentDomain->environment;
     if ($this->core->getSettings()->core->environments->{$env}->debug === true || count($resErrorPage) <= 0) {
         return parent::generateErrorPage($e);
     }
     $pageModel = new PageModel($this->db);
     $this->cmsPage = $pageModel->getPageByID($resErrorPage[0]->ID);
     return $this->generateCMSPage($pageModel);
 }
Exemplo n.º 4
0
 /**
  * Reloads settings for a given element
  * @param CmsElement $cmsElement The element which settings should be reloaded
  * @param CmsPage $cmsPage The CmsPage in which context the settings for the element should be loaded
  */
 public function reloadSettings(CmsElement $cmsElement, CmsPage $cmsPage)
 {
     if ($cmsElement instanceof CmsElementSettingsLoadable === false) {
         return;
     }
     /** @var CmsElementSettingsLoadable $cmsElement */
     $cmsElement->resetSettingsFound();
     /** @var CmsElementSettingsLoadable $cmsElement */
     $settings = $cmsElement->getSettingsForElements($this->db, array($cmsElement->getID()), PageModel::getPageIdsRecursive($cmsPage));
     foreach ($settings as $settingEntries) {
         /** @var CmsElement */
         $settingsEntry = $this->combineSettings($settingEntries);
         $cmsElement->setSettings($settingsEntry);
     }
 }
Exemplo n.º 5
0
 public function processRouteEdit()
 {
     $this->abortIfUserHasNotRights('CMS_ROUTES_EDIT');
     //$coreModel = new CoreModel($this->db);
     $pageModel = new PageModel($this->db);
     $routeModel = new RouteModel($this->db);
     $moduleModel = new ModuleModel($this->db);
     $pageOptions = array();
     foreach ($pageModel->getAllPages() as $p) {
         $pageOptions[$p->ID] = $p->language_codeFK . ', ' . $p->title;
     }
     $routeOptions = array();
     foreach ($routeModel->getAllRoutes() as $r) {
         if ($r->ID == $this->route->getParam(0)) {
             continue;
         }
         $routeOptions[$r->ID] = $r->pattern;
     }
     $moduleOptions = array();
     foreach ($moduleModel->getModulesWithFrontendController() as $m) {
         $routeOptions[$m->ID] = $m->ID;
     }
     $this->formHelper = new FormHelper(FormHelper::METHOD_POST);
     $this->formHelper->addField('pattern', null, FormHelper::TYPE_STRING, true, array('missingError' => 'Please insert a pattern for this route'));
     $this->formHelper->addField('page', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please select a valid page', 'options' => $pageOptions));
     $this->formHelper->addField('robots', null, FormHelper::TYPE_STRING, false);
     $this->formHelper->addField('regexp', null, FormHelper::TYPE_CHECKBOX);
     $this->formHelper->addField('route_typ', null, FormHelper::TYPE_OPTION);
     $this->formHelper->addField('redirect', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please select a valid page', 'options' => $pageOptions));
     $this->formHelper->addField('module', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please select a valid module', 'options' => $moduleOptions));
     if (!$this->formHelper->sent() || !$this->formHelper->validate()) {
         return $this->getRouteEdit();
     }
     $patternStr = $this->formHelper->getFieldValue('pattern');
     if (StringUtils::startsWith($patternStr, '/')) {
         $this->formHelper->addError(null, 'The route can not start with a slash (/)');
         return $this->getRouteEdit();
     }
     if (preg_match('@^[A-Za-z0-9\\-\\._/?#\\@&+=]+$@', $patternStr) === 0) {
         $this->formHelper->addError(null, 'The route should only have alphanumeric characters and -._/?#@&+= in it');
         return $this->getRouteEdit();
     }
     if ($patternStr === 'backend' || StringUtils::startsWith($patternStr, 'backend/') === true) {
         $this->formHelper->addError(null, 'The route should not start with "backend/". This URI node is reserved by the CMS');
         return $this->getRouteEdit();
     }
     // save settings
     $routeTyp = $this->formHelper->getFieldValue('route_typ');
     $stmntUpdate = $this->db->prepare("\n\t\t\tINSERT INTO route\n\t\t\t\tSET ID = ?, pattern = ?, regex = ?, page_IDFK = ?, mod_IDFK = ?, robots = ?, redirect_route_IDFK = ?\n\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\tpattern = ?, regex = ?, page_IDFK = ?, mod_IDFK = ?, robots = ?, redirect_route_IDFK = ?\n\n\t\t");
     $resUpdate = $this->db->update($stmntUpdate, array($this->route->getParam(0), '/' . $patternStr, $this->formHelper->getFieldValue('regexp'), $routeTyp == 1 ? $this->formHelper->getFieldValue('page') : null, $this->formHelper->getFieldValue('module') == 0 ? null : $this->formHelper->getFieldValue('module'), $this->formHelper->getFieldValue('robots'), $routeTyp == 2 ? $this->formHelper->getFieldValue('redirect') : null, '/' . $patternStr, $this->formHelper->getFieldValue('regexp'), $routeTyp == 1 ? $this->formHelper->getFieldValue('page') : null, $this->formHelper->getFieldValue('module') == 0 ? null : $this->formHelper->getFieldValue('module'), $this->formHelper->getFieldValue('robots'), $routeTyp == 2 ? $this->formHelper->getFieldValue('redirect') : null));
     RequestHandler::redirect('/backend/routes');
 }
Exemplo n.º 6
0
    /**
     * @param FrontendController $frontendController
     * @param $html
     *
     * @return null|string
     */
    protected function renderEditable(FrontendController $frontendController, $html)
    {
        $pageModel = new PageModel($frontendController->getDB());
        // @TODO dont know if it works 2014-02-03 pam else comment in and delete line after again
        //$cmsPage = $pageModel->getPageByID($frontendController->getCmsPage()->getID());
        $cmsPage = $frontendController->getCmsPage();
        // @TODO Move the $this->hidden compare earlier in the code, before the rendering begins or is over to save resources
        if ($pageModel->hasUserWriteAccess($cmsPage, $frontendController->getAuth()) === false) {
            return $this->hidden === false ? $html : null;
        }
        $modIDStr = 'mod-' . $this->ID . '-' . $frontendController->getCmsPage()->getID();
        $layerClass = 'element';
        $sortableClass = null;
        $hiddenClass = null;
        if ($this instanceof LayoutElement) {
            $layerClass = 'element-layout';
        }
        if ($this instanceof CmsElementSortable) {
            $sortableClass = 'element-sortable ';
        }
        if ($this->hidden === true) {
            $hiddenClass = 'element-hidden ';
        }
        $editableHtml = '<div id="' . $modIDStr . '" class="element-editable ' . $hiddenClass . $sortableClass . str_replace('_', '-', $this->identifier) . ' clearfix">
			<div id="' . $modIDStr . '-content" class="' . $layerClass . ' edit-area clearfix">
				' . $html . '
				<div class="edit-area-btn-group">
					<!--<a class="edit-area-btn edit-area-btn-info ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" href="javascript:alert(\'Element type: ' . $this->identifier . '\');"><span class="ui-button-icon-primary ui-icon ui-icon-info"></span><span class="ui-button-text">Element Info</span></a>-->
					' . ($this->parentElement instanceof CmsElementSortable ? '<a class="edit-area-btn edit-area-btn-history ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-move" title="move" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-arrow-4"></span><span class="ui-button-text">move</span></a>' : null) . '
					' . ($this instanceof TextElement ? '<a class="edit-area-btn edit-area-btn-edit ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" title="edit content" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span><span class="ui-button-text">edit</span></a> ' : null) . '
					' . ($this->hasConfig($frontendController) ? '<a class="edit-area-btn edit-area-btn-settings ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" href="/backend/element/' . $this->ID . '-' . $frontendController->getCmsPage()->getID() . '/ajax-settingsbox" role="button" title="Module settings: ' . $modIDStr . ' (' . $this->identifier . ')"><span class="ui-button-icon-primary ui-icon ui-icon-gear"></span><span class="ui-button-text">Settings</span></a> ' : null) . '
					<a class="edit-area-btn edit-area-btn-history ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" href="/backend/element/' . $this->ID . '-' . $frontendController->getCmsPage()->getID() . '/ajax-revision-control" role="button" title="Revision control: ' . $modIDStr . ' (' . $this->identifier . ')"><span class="ui-button-icon-primary ui-icon ui-icon-clock"></span><span class="ui-button-text">Revision control</span></a>';
        if ($this->pageID == $frontendController->getCmsPage()->getID()) {
            $editableHtml .= '<a class="edit-area-btn edit-area-btn-delete ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" title="delete" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-trash"></span><span class="ui-button-text">delete</span></a>';
        } else {
            $editableHtml .= $this->hidden === false ? '<a class="edit-area-btn edit-area-btn-hide ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" title="hide" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">hide</span></a>' : '<a class="edit-area-btn edit-area-btn-reveal ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" title="show" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">show</span></a>';
        }
        $editableHtml .= '</div>
			</div>
		</div>';
        return $editableHtml;
    }
Exemplo n.º 7
0
 /**
  * @param CmsPage $cmsPage
  * @param bool $useCache
  * @return \ArrayObject The element tree for the current page
  */
 private function generateElementTree(CmsPage $cmsPage, $useCache = false)
 {
     // TODO check if any page inheriting from has changed
     $pageIDs = PageModel::getPageIdsRecursive($cmsPage);
     /*if($useCache === true) {
     			$stmntFetchCache = $this->db->prepare("
     				SELECT pc.ID, pc.cached_elements, pc.cache_time
     				FROM page_cache pc
     				LEFT JOIN page p ON p.ID = pc.ID
     				WHERE pc.cache_time >= p.last_modified
     				AND pc.ID IN(" . DB::createInQuery($pageIDs) . ")
     			");
     
     			$resFetchCache = $this->db->select($stmntFetchCache,
     				$pageIDs
     			);
     
     			if(count($resFetchCache) === count($pageIDs)) {
     				foreach($resFetchCache as $fc) {
     					if($fc->ID != $cmsPage->getID())
     						continue;
     
     					return unserialize($fc->cached_elements);
     				}
     			}
     		}*/
     /*$stmntElements = $this->db->prepare("
     			SELECT ei.ID, ei.mod_IDFK element_ID, ei.page_IDFK page_ID, parent_mod_IDFK parent_element_ID, ea.class, ea.name, ei.revision,
     			IF(ih.element_instance_IDFK IS NULL, 0, 1) hidden
     			FROM cms_element_instance ei
     			LEFT JOIN cms_element_available ea ON ea.ID = ei.mod_IDFK
     			LEFT JOIN cms_element_instance_hidden ih ON ih.element_instance_IDFK = ei.ID AND ih.page_IDFK = ?
     			WHERE ei.page_IDFK IN (" . DB::createInQuery($pageIDs) . ")
     			AND ea.active = 1
     		");
     
     		$resElements = $this->db->select($stmntElements,
     			array_merge(array($cmsPage->getID()), $pageIDs)
     		);*/
     $stmntElements = $this->db->prepare("\n\t\t\tSELECT ei.ID, ei.mod_IDFK element_ID, ei.page_IDFK page_ID, parent_mod_IDFK parent_element_ID, ea.class, ea.name, ei.revision,\n\t\t\tIF(ih.element_instance_IDFK IS NULL, 0, 1) hidden\n\t\t\tFROM cms_element_instance ei\n\t\t\tLEFT JOIN cms_element_available ea ON ea.ID = ei.mod_IDFK\n\t\t\tLEFT JOIN cms_element_instance_hidden ih ON ih.element_instance_IDFK = ei.ID AND ih.page_IDFK IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\tWHERE ei.page_IDFK IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\tAND ea.active = 1\n\t\t");
     $resElements = $this->db->select($stmntElements, array_merge($pageIDs, $pageIDs));
     // Settings und co
     $elementTypes = array();
     $elementInstances = array();
     foreach ($resElements as $e) {
         /** @var CmsElement $elementInstance */
         $elementInstance = new $e->class($e->ID, $e->page_ID, $e->name);
         if ($e->revision !== null) {
             $elementInstance->setRevision($e->revision);
         }
         $elementInstance->setHidden($e->hidden == 1);
         $elementInstances[$e->ID] = $elementInstance;
         $elementTypes[$e->class][] = $e->ID;
     }
     // Load settings for modules
     foreach ($elementTypes as $class => $modIDs) {
         $refClass = new \ReflectionClass($class);
         if ($refClass->isSubclassOf('ch\\metanet\\cms\\common\\CmsElementSettingsLoadable') === false) {
             continue;
         }
         /** @var CmsElementSettingsLoadable $class */
         $settings = $class::getSettingsForElements($this->db, $modIDs, $pageIDs);
         foreach ($settings as $key => $settingEntries) {
             $settingsEntry = $this->combineSettings($settingEntries);
             $elementInstances[$key]->setSettings($settingsEntry);
         }
     }
     $cachedTree = new \ArrayObject($this->createTree($resElements, $elementInstances));
     if ($useCache === true) {
         $cachedTreeSerialized = serialize($cachedTree);
         try {
             $stmntCacheElements = $this->db->prepare("\n\t\t\t\t\tINSERT INTO page_cache SET\n\t\t\t\t\t\tID = ?, cached_elements = ?, cache_time = NOW()\n\t\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\t\tcached_elements = ?, cache_time = NOW()\n\t\t\t\t");
             $this->db->insert($stmntCacheElements, array($cmsPage->getID(), $cachedTreeSerialized, $cachedTreeSerialized));
         } catch (\Exception $e) {
             // Cache could not be saved
         }
     }
     return $cachedTree;
 }