/** * Returns a CMSModule instance by it's ID * * @param int $moduleID * @param CmsPage $cmsPage * @param bool $combineSettings * @param bool $loadSubElements * * @throws CMSException * * @return CmsElement */ public function getElementInstanceByID($moduleID, CmsPage $cmsPage, $combineSettings = true, $loadSubElements = true) { $resMod = $this->db->select($this->stmntMod, array($cmsPage->getID(), $moduleID)); if (count($resMod) <= 0) { throw new CMSException('Module with ID ' . $moduleID . ' not found'); } $modInfo = $resMod[0]; /** @var $elementInstance CmsElement */ $elementInstance = new $modInfo->class($moduleID, $modInfo->page_IDFK); $elementInstance->setParentElementID($modInfo->parent_mod_IDFK); $elementInstance->setHidden($modInfo->hidden == 1); if ($elementInstance instanceof CmsElementSettingsLoadable) { /** @var CmsElementSettingsLoadable $elementInstance */ $settings = $elementInstance->getSettingsForElements($this->db, array($moduleID), PageModel::getPageIdsRecursive($cmsPage)); // Combine the settings if (isset($settings[$moduleID])) { $settingsEntry = null; if ($combineSettings === true) { $settingsEntry = $this->combineSettings($settings[$moduleID]); } elseif (isset($settings[$moduleID][$cmsPage->getID()]) === true) { $settingsEntry = $settings[$moduleID][$cmsPage->getID()]; } if ($settingsEntry !== null) { $elementInstance->setSettings($settingsEntry); } } $elementInstance->setSettingsSelf(isset($settings[$moduleID][$cmsPage->getID()])); } if ($elementInstance instanceof LayoutElement && $loadSubElements === true) { $elementInstance->setElements($this->getChildElementInstances($elementInstance->getID(), $cmsPage)); } return $elementInstance; }
private function hasUserAccess(CmsPage $page, CmsAuthHandlerDB $auth, $mode) { if ($auth->hasRootAccess()) { return true; } $pageRightsCompressed = array(); if (count($page->getRights()) <= 0) { return false; } foreach (array_reverse($page->getRights()) as $pr) { $pageRightsCompressed[$pr->groupkey] = $pr->rights; } foreach ($pageRightsCompressed as $id => $right) { if ($auth->hasRightGroup($id) === false) { continue; } if ($right == 3 || $mode === 'read' && $right == 2 || $mode === 'write' && $right == 1) { return true; } } return false; }
/** * Generates a string with all the JS/CSS stored using {@see CmsPage::addJs} using the * target {@see CmsPage::PAGE_AREA_BODY} * * @param CmsPage $cmsPage The requested CMS page * * @return string The HTML for all the JS which should ne present in the footer of the page */ protected function generateAreaBody(CmsPage $cmsPage) { $env = $this->currentDomain->environment; $isDebug = $this->core->getSettings()->core->environments->{$env}->debug === true; $areaBodyHtml = $isDebug ? '<!-- AREA BODY START -->' . PHP_EOL : null; $jsEntries = $cmsPage->getJs(CmsPage::PAGE_AREA_BODY); foreach ($jsEntries as $jsGroup) { foreach ($jsGroup as $jsEntry) { $areaBodyHtml .= $jsEntry . PHP_EOL; } } $areaBodyHtml .= $isDebug ? '<!-- AREA BODY STOP -->' . PHP_EOL : null; return $areaBodyHtml . PHP_EOL; }
/** * Sets the last modified time to now and the last modifier to the authenticated user * * @param CmsPage $cmsPage The CMS page to update */ protected function updatePage(CmsPage $cmsPage) { $stmntUpdatePage = $this->db->prepare("UPDATE page SET last_modified = NOW(), modifier_IDFK = ? WHERE ID = ?"); $this->db->update($stmntUpdatePage, array($this->auth->getUserID(), $cmsPage->getID())); $this->eventDispatcher->dispatch('mod_core.pageModified', new PageEvent($cmsPage)); }