Ejemplo n.º 1
0
 /**
  * @return HttpResponse
  * @throws CMSException
  */
 public function getAjaxSettingsBox()
 {
     $pageModel = new PageModel($this->db);
     $cmsPage = $pageModel->getPageByID($this->route->getParam(1));
     $moduleModel = new ModuleModel($this->db);
     $elementInstance = $moduleModel->getElementInstanceByID($this->route->getParam(0), $cmsPage, false, false);
     if ($elementInstance instanceof CmsElementSettingsLoadable === false) {
         return $this->generateResponse(404, 'No configurable module');
     }
     try {
         /** @var CmsElementSettingsLoadable $elementInstance */
         $res = $elementInstance->generateConfigBox($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);
 }
Ejemplo n.º 2
0
    /**
     * This method renders a template.
     *
     * @param string $pageHtml
     * @param array $tplVars Variables that should be accessible in the template files
     *
     * @return string The rendered template
     */
    protected function renderBasicTemplate($pageHtml, $tplVars = array())
    {
        $currentEnv = $this->core->getCurrentDomain()->environment;
        $defaultTplVars = array('_core' => $this->core, '_auth' => $this->auth, 'page_html' => $pageHtml, 'logged_in' => $this->auth->isLoggedIn(), 'username' => null, 'siteTitle' => null, 'scripts_footer' => null, 'admin_bar' => null, 'meta_description' => null, 'js_revision' => isset($this->core->getSettings()->cms->{$currentEnv}->js_revision) ? $this->core->getSettings()->cms->{$currentEnv}->js_revision : 1, 'css_revision' => isset($this->core->getSettings()->cms->{$currentEnv}->css_revision) ? $this->core->getSettings()->cms->{$currentEnv}->css_revision : 1, 'area_head' => null, 'area_body' => null, 'cms_page' => null);
        $lang = $this->core->getLocaleHandler()->getLanguage();
        $navModules = array();
        foreach ($this->moduleModel->getAllModules() as $module) {
            if ($module->backendcontroller === null) {
                continue;
            }
            $module->display_name = isset($module->manifest_content->name->{$lang}) ? $module->manifest_content->name->{$lang} : $module->name;
            $navModules[] = $module;
        }
        usort($navModules, function ($a, $b) {
            return $a->display_name > $b->display_name;
        });
        if ($this->auth->isLoggedIn()) {
            $adminBarHtml = '<div class="mfadminbar">
				<a href="/backend"><img class="adminbar-logo" src="/images/adminbar-logo.png" alt=""></a>
				<ul class="adminbar-nav">
					<li class="more"><a href="#" id="nav-general">General</a>
						<ul class="adminbar-nav-sub">
							<li><a href="/backend/general/phpinfo" id="nav-phpinfo">PHP Info</a></li>
						</ul>
					</li>
					<li class="more"><a href="/backend/modules" id="nav-modules">' . $this->translator->_d('backend', 'Modules') . '</a>
						<ul class="adminbar-nav-sub">';
            foreach ($navModules as $module) {
                $baseModuleLink = '/backend/module/' . $module->name;
                $adminBarHtml .= '<li><a href="' . $baseModuleLink . '" id="nav-' . $module->name . '">' . $module->display_name . '</a>' . $this->renderModuleNavigation($module->backendcontroller, $baseModuleLink, BackendNavigationInterface::DISPLAY_IN_ADMIN_BAR) . '</li>';
            }
            $adminBarHtml .= '</ul>
					</li>
					<li><a href="/backend/elements" id="nav-elements">' . $this->translator->_d('backend', 'Elements') . '</a></li>
					<li><a href="/">' . $this->translator->_d('backend', 'Inline editing') . '</a></li>
				</ul>
				<ul class="adminbar-user">
					<li><a href="/backend/myaccount">' . $this->auth->getUserData()->username . '</a></li>
					<li class="user-logout"><a href="/backend/logout"><span></span></a></li>
				</ul>
			</div>';
            $tplVars['username'] = $this->auth->getUserData()->username;
            $tplVars['admin_bar'] = $adminBarHtml;
        }
        return $this->cmsView->render('template.html', $tplVars + $defaultTplVars);
    }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function loadNeededModules()
 {
     $moduleModel = new ModuleModel($this->db);
     foreach ($moduleModel->getAllModules() as $module) {
         if ($module->frontendcontroller === null || class_exists($module->frontendcontroller) === false || ($implementedInterfaces = class_implements($module->frontendcontroller)) === false || in_array('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface', $implementedInterfaces) === false) {
             continue;
         }
         $moduleControllerInstance = new $module->frontendcontroller($this, $module->name);
         $this->eventDispatcher->addSubscriber($moduleControllerInstance);
         $this->loadedModules[$module->name] = $moduleControllerInstance;
     }
 }
Ejemplo n.º 4
0
 /**
  * @return HttpResponse
  * @throws CMSException
  * @throws HttpException
  * @throws \Exception
  */
 public function restoreElementAjax()
 {
     list($elementType, $elementID, $elementPageID) = explode('-', $this->httpRequest->getVar('module', 'strip_tags'));
     $revisionFile = $this->httpRequest->getVar('revision', 'strip_tags');
     $cmsPage = $this->pageModel->getPageByID($elementPageID);
     $moduleModel = new ModuleModel($this->db);
     $modInstance = $moduleModel->getElementInstanceByID($elementID, $cmsPage);
     try {
         $this->db->setListenersMute(true);
         $this->db->beginTransaction();
         $revisionControl = new RevisionControl($this->db);
         $revisionControl->restoreFromFile($revisionFile);
         $fileNameParts = explode('.', StringUtils::afterLast($revisionFile, '/'));
         $this->updateElementRevision($modInstance, $fileNameParts[2]);
         $this->db->commit();
         $this->db->setListenersMute(false);
     } catch (\Exception $e) {
         $this->db->setListenersMute(false);
         $this->db->rollBack();
         $this->logger->error('Could not restore element ' . $e->getMessage());
         return new HttpResponse(500, 'Could not restore element: ' . $e->getMessage());
     }
     // RENDER ELEMENT AGAIN, SEND BACK
     if ($modInstance instanceof CmsElementSettingsLoadable) {
         /** @var CmsElement $modInstance */
         $moduleModel->reloadSettings($modInstance, $cmsPage);
     }
     $referrerPath = StringUtils::beforeFirst($this->httpRequest->getVar('referrer', 'strip_tags'), '?');
     $httpRequestFrontend = clone $this->httpRequest;
     $httpRequestFrontend->setPath($referrerPath);
     $httpRequestFrontend->setRequestMethod('GET');
     $frontendController = new FrontendController($this->core, $httpRequestFrontend, $this->route);
     $frontendController->deliverCMSPage();
     // @TODO render and replace parent module of this one
     $newModuleHtml = $modInstance->render($frontendController, $this->moduleView);
     return new HttpResponse(200, $newModuleHtml);
 }
Ejemplo 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');
 }
 protected function getModuleOptions()
 {
     $moduleModel = new ModuleModel($this->cmsController->getDB());
     $moduleOptions = array(0 => '- please choose -');
     $lang = $this->cmsController->getLocaleHandler()->getLanguage();
     foreach ($moduleModel->getModulesWithFrontendController() as $mod) {
         $moduleOptions[$mod->ID] = $mod->manifest_content->name->{$lang};
     }
     return $moduleOptions;
 }
Ejemplo n.º 7
0
 private function getAllRights()
 {
     $moduleModel = new ModuleModel($this->db);
     $rights = array();
     foreach ($moduleModel->getAllModules() as $mod) {
         if (isset($mod->manifest_content->rights) === false) {
             continue;
         }
         foreach ($mod->manifest_content->rights as $rKey => $rLang) {
             $rights[] = $rKey;
         }
     }
     return $rights;
 }