/** * @return mixed */ public function getContent() { if ($this->user->isAdmin() === false) { return false; } if ($this->request->isPost()) { $cmd = $this->request->post('cmd', null); if (method_exists($this, $cmd)) { return $this->{$cmd}(); } $this->response->finish(); } $extensions = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findBy(array(), array('name' => 'asc')); $unregisteredExtensions = $this->registryManager->getUnregisteredExtensions(); $extensionUpdates = new \Doctrine\Common\Collections\ArrayCollection(); $updates = $this->registryManager->getUpdates($extensions); if (is_object($updates)) { foreach ($updates as $k => $update) { $extensionUpdates->set($k, $update); } } $this->view->assign('unregisteredExtensions', $unregisteredExtensions); $this->view->assign('extensions', $extensions); $this->view->assign('extensionUpdates', $extensionUpdates); return $this->siteManagerController->getIframeContent($this->template->fetch('Extension')); }
/** * @return bool|mixed */ public function getContent() { if ($this->user->isAdmin() === false) { return false; } $currentEntity = false; $errors = false; $data = array(); $formFields = array(); $entities = array(); $modelClass = false; $model = false; $modelName = $this->request->gp('model', false); $groupedModels = $this->db->getRepository('\\Fraym\\EntityManager\\Entity\\Group')->findAll(); if ($modelName) { $model = $this->entityManager->getEntityByStringOrId($modelName); if ($model) { $modelClass = $model->className; } } if ($this->request->isXmlHttpRequest()) { return $this->createEntityFromSingleField($modelClass); } if ($modelClass && $this->request->isPost()) { $data = $this->request->getGPAsArray(); $validation = $this->validation->setData($data)->getFormFieldValidation($modelClass); if ($id = $this->request->post('id')) { $currentEntity = $this->db->getRepository($modelClass)->findOneById($id); if (isset($data['cmd']) && $data['cmd'] == 'update' && $currentEntity && ($errors = $validation->check()) === true) { $currentEntity->updateEntity($data); } elseif (isset($data['cmd']) && $data['cmd'] == 'remove' && $currentEntity) { $this->db->remove($currentEntity); $this->db->flush(); $data = array(); $currentEntity = false; } elseif (isset($data['cmd']) && $data['cmd'] == 'update') { $currentEntity->updateEntity($data, false); } } else { if (isset($data['cmd']) && $data['cmd'] == 'new' && ($errors = $validation->check()) === true) { $currentEntity = new $modelClass(); $currentEntity->updateEntity($data); } } } if ($modelClass && $model) { $entities = $this->db->getRepository($modelClass)->findAll(); $formFields = $this->formField->setClassName($modelClass)->getFields(); } $this->view->assign('locales', $this->locale->getLocales()); $this->view->assign('data', $data); $this->view->assign('errors', $errors); $this->view->assign('currentEntity', $currentEntity); $this->view->assign('entities', $entities); $this->view->assign('groupedModels', $groupedModels); $this->view->assign('model', $model); $this->view->assign('formFields', $formFields); return $this->siteManagerController->getIframeContent($this->template->fetch('EntityView')); }
/** * @return bool|mixed */ public function getContent() { if ($this->user->isAdmin() === false) { return false; } $this->view->assign('sites', $this->blockChangeSetManager->getSites()); $this->view->assign('changeSets', $this->blockChangeSetManager->getChangeSets(), false); return $this->siteManagerController->getIframeContent($this->view->fetch('BlockChangeSetManager')); }
/** * save the output to cache file * * @return bool ture or false */ public function setCacheContent() { if (!is_dir(self::DIR_PAGES)) { mkdir(self::DIR_PAGES, 0755, true); } $filename = $this->getCacheName(); // create the cache filename $cacheFilename = self::DIR_PAGES . $filename . '.cache.php'; $cacheFilenamePhpData = self::DIR_PAGES . $filename . '.cache.config.php'; $cacheInfo = "/*\n\n" . str_ireplace('*', '', print_r($_SERVER, true)) . "\n\n*/\n\n"; $phpCode = '<?php ' . $cacheInfo; $currentMenuItem = $this->route->getCurrentMenuItemTranslation(); if (!$this->request->isXmlHttpRequest() && !$this->request->isPost() && $this->user->isAdmin() === false && (!is_file($cacheFilename) || !is_file($cacheFilenamePhpData)) && $this->isCachingActive($currentMenuItem->menuItem)) { // save cached file $source = $this->template->outputFilter(ob_get_contents()); $phpCode .= '$menuItemTranslation = <<<\'EOT\'' . "\n" . json_encode($currentMenuItem->toArray()) . "\n" . 'EOT;' . "\n"; $phpCode .= '$domain = "' . $this->route->getCurrentDomain() . '";'; $phpCode .= '$executedBlocks = <<<\'EOT\'' . "\n" . json_encode($this->blockParser->getExecutedBlocks()) . "\n" . 'EOT;' . "\n"; file_put_contents($cacheFilenamePhpData, $phpCode); file_put_contents($cacheFilename, $source . "<!-- CACHED : " . date('Y-m-d H:i:s') . " -->"); // clean the output buffer ob_clean(); // parse cached blocks for first output echo $this->blockParser->parse($source, false, true); return true; } $source = $this->template->outputFilter(ob_get_contents()); // clean the output buffer ob_clean(); // parse cached blocks for first output echo $this->blockParser->parse($source, false, true); return false; }
/** * @param $menuItemTranslation * @return bool * @throws \Exception */ protected function setupPage($menuItemTranslation) { try { $this->currentMenuItemTranslation = $menuItemTranslation; $this->currentMenuItem = $menuItemTranslation->menuItem; $this->db->setTranslatableLocale($menuItemTranslation->locale->locale); $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir); if ($this->request->isXmlHttpRequest() || $this->user->isAdmin()) { $localeId = $this->request->gp('locale_id'); if ($localeId && is_numeric($localeId)) { $this->locale->setLocale($localeId); } else { $this->locale->setLocale($menuItemTranslation->locale); } } else { $this->locale->setLocale($menuItemTranslation->locale); } $pageTitle = (string) $menuItemTranslation->pageTitle === '' ? $menuItemTranslation->title : $menuItemTranslation->pageTitle; $pageTitle = str_replace('[SITE_NAME]', $menuItemTranslation->menuItem->site->name, $pageTitle); $this->template->setPageTitle($pageTitle); $this->template->setPageDescription($menuItemTranslation->description); $this->template->setKeywords(explode(',', $menuItemTranslation->keywords)); setlocale(LC_ALL, $this->locale->getLocale()->locale); } catch (Exception $e) { throw new \Exception('Error setup page: ' . $e->getMessage()); } return true; }
/** * @param bool $routeInit * @param null $menuItemTranslation */ public function renderSite($routeInit = true, $menuItemTranslation = null) { $tpl = $this->template; if (is_object($menuItemTranslation)) { $this->loadVirtualRoutes(); $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($menuItemTranslation->id); if (!$this->getCurrentDomain()) { $this->setCurrentDomain($this->getRequestDomain()); } // must set before check route, because the locale must be set $this->setupPage($menuItemTranslation); $virtualRouteContent = $this->checkVirtualRoute(); if ($virtualRouteContent === false && $this->request->isXmlHttpRequest() === false && $this->isHTTPS() === false && $this->currentMenuItem->https === true) { $this->redirectToURL('https://' . $this->getRequestRoute()); } $this->sitefullRoute = rtrim($this->buildFullUrl($this->currentMenuItem), '/'); if ($routeInit == true) { if ($virtualRouteContent !== false) { // virtual route content $this->response->send($virtualRouteContent, true); } if ($this->currentMenuItem->checkPermission === true && $this->currentMenuItem->parent !== null && $this->user->isLoggedIn() === false) { return $this->menuItemNotFound(); } // read the template content $mainTemplateString = $menuItemTranslation->menuItem->template ? $menuItemTranslation->menuItem->template->html : $this->getDefaultMenuItemTemplate(); if ($this->getFoundURI(false) != trim($this->getRequestRoute(false, false), '/')) { $this->blockParser->setCheckRouteError(true); $tpl->setTemplate('string:' . $mainTemplateString); $content = $tpl->prepareTemplate(); $routeExistModules = $this->blockParser->moduleRouteExist($content); if ($routeExistModules === false) { return $this->menuItemNotFound(); } else { if ($this->request->isXmlHttpRequest() === true) { // only exec modules where we find the route $this->core->response->send($this->blockParser->parse($routeExistModules)); } else { $this->siteManager->addAdminPanel(); echo $this->blockParser->parse($content); } } } else { $this->siteManager->addAdminPanel(); $tpl->renderString($mainTemplateString); } // cache page if cache enable $this->cache->setCacheContent(); } else { $tpl->renderString($menuItemTranslation->menuItem->template->html); } } else { $this->menuItemNotFound(); } }
/** * @param $block * @param $historyType */ public function saveHistory($block, $historyType) { $blockHistory = new \Fraym\Block\Entity\BlockHistory(); $blockHistory = $block->copyEntityTo($blockHistory); $blockHistory->user = $this->user->getUserEntity(); $blockHistory->type = $historyType; $blockHistory = $this->setHistoryFrom($blockHistory, $block, $historyType); $this->db->persist($block); $this->db->persist($blockHistory); $this->db->flush(); }
/** * AJAX handler function * * @return bool */ public function ajaxHandler() { if ($this->user->isAdmin() === false) { return; } $cmd = trim($this->request->gp('cmd', '')); if (method_exists($this, $cmd)) { return $this->{$cmd}(); } return false; }
/** * LogOut function for Users. It unsets the session. * * @return mixed */ public function viewlogOut() { if ($this->request->isPost() && $this->request->post('logout', false) == '1') { $this->user->logout(); $this->checkLoginRedirectConfig(); } $this->view->assign('user', $this->user); if ($this->xml === false) { return $this->siteManagerController->getIframeContent($this->view->fetch('AdminArea'), ['cssClass' => 'admin-login']); } else { $this->view->setTemplate('LogOut'); } }
/** * @return mixed */ public function getContent() { if ($this->user->isAdmin() === false) { return false; } if ($this->request->isPost()) { $cmd = $this->request->post('cmd', null); if (method_exists($this, $cmd)) { return $this->{$cmd}(); } $this->response->finish(); } $extensions = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findBy([], ['name' => 'asc']); $updates = $this->registryManager->getUpdates($extensions); $extensionPackages = $this->registryManager->getExtensionPackages($extensions); $unregisteredExtensions = $this->registryManager->getUnregisteredExtensions(); $this->registryManager->updateUnregisteredExtensions($unregisteredExtensions); $this->view->assign('unregisteredExtensions', $unregisteredExtensions); $this->view->assign('extensions', $extensions); $this->view->assign('extensionPackages', $extensionPackages, false); $this->view->assign('extensionUpdates', $updates, false); return $this->siteManagerController->getIframeContent($this->view->fetch('Extension')); }
/** * @return mixed */ public function adminPanelInit() { if ($this->user->isAdmin() === false) { return; } $cmd = $this->request->gp('cmd', false); if ($cmd !== false) { if (method_exists($this, $cmd)) { return $this->{$cmd}(); } } $this->view->addHeadData('<script type="text/javascript">var menu_id=\'' . $this->route->getCurrentMenuItem()->id . '\';var menu_translation_id=\'' . $this->route->getCurrentMenuItemTranslation()->id . '\';var base_path=\'' . $this->route->getSiteBaseURI() . '\';var menu_path=\'' . $this->route->getMenuPath() . '\';</script>'); $this->view->assign('inEditMode', $this->block->inEditMode()); $this->view->render('AdminPanel'); }
/** * @return bool|mixed */ public function getContent() { if ($this->user->isAdmin() === false) { return false; } if ($this->request->isXmlHttpRequest()) { return $this->ajaxHandler(); } else { $this->view->assign('sites', $this->db->getRepository('\\Fraym\\Site\\Entity\\Site')->findAll()); $params = $this->request->getGPAsArray(); if (isset($params['function'])) { return $this->addAndEditMenuItem($params); } $mode = $this->request->gp('mode', false); $this->view->assign('mode', $mode); return $this->siteManager->getIframeContent($this->view->fetch('SiteMenuOverview')); } }
/** * @return mixed */ public function fileViewer() { if ($this->user->isAdmin() === false) { return; } $fileContent = $this->request->post('fileContent', false); $storage = $this->request->gp('storage'); $path = $this->request->gp('path'); $cmd = $this->request->gp('cmd'); $cropOpt = $this->request->gp('cropOpt'); $fullPath = $this->fileManager->pathExists($storage, $path); if ($fullPath) { $content = ''; $inlineImage = null; if (is_file($fullPath)) { if ($fileContent) { file_put_contents($fullPath, $fileContent); } $content = file_get_contents($fullPath); } $pathinfo = pathinfo($fullPath); if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], array('png', 'gif', 'jpg', 'jpeg', 'bmp', 'tiff'))) { if ($cmd === 'crop') { $cropFilename = dirname($fullPath) . DIRECTORY_SEPARATOR . 'crop_' . implode('_', $cropOpt) . basename($fullPath); /** * var \Imagine\Gd\Imagine $imagine */ $imagine = $this->serviceLocator->get('Imagine'); $image = $imagine->open($fullPath); $image->crop(new \Imagine\Image\Point($cropOpt['x'], $cropOpt['y']), new \Imagine\Image\Box($cropOpt['w'], $cropOpt['h']))->save($cropFilename); $fullPath = $cropFilename; } $size = getimagesize($fullPath); $inlineImage = 'data:' . $size['mime'] . ';base64,' . base64_encode(file_get_contents($fullPath)); } $this->view->assign('inlineImage', $inlineImage); $this->view->assign('storage', $storage); $this->view->assign('file', basename($fullPath)); $this->view->assign('path', $path); $this->view->assign('content', $content); } return $this->siteManagerController->getIframeContent($this->view->fetch('FileViewer')); }
/** * @param $changedBlock * @param $parentBlock * @param $type * @return Entity\ChangeSet */ protected function createChangeSet($changedBlock, $parentBlock, $type) { $changeSet = new \Fraym\Block\Entity\ChangeSet(); $changeSet->contentId = $changedBlock->contentId; $changeSet->position = $changedBlock->position; $changeSet->menuItem = $changedBlock->menuItem; $changeSet->site = $changedBlock->site; $changeSet->menuItemTranslation = $changedBlock->menuItemTranslation; $changeSet->extension = $changedBlock->extension; $changeSet->user = $this->user->getUserEntity(); $changeSet->byRef = $changedBlock->byRef; $changeSet->block = $parentBlock; $changeSet->type = $type; if (!$changedBlock->byRef) { $changeSet->config = $changedBlock->config; } $this->db->persist($changeSet); $this->db->flush(); return $changeSet; }
/** * Add block xml before </body> to add the site manager admin panel */ public function addAdminPanel() { if ($this->user->isAdmin()) { $this->template->addFootData($this->blockParser->parse('<block type="module" permission="user" editable="false"><class>\\Fraym\\SiteManager\\SiteManagerController</class><method>adminPanelInit</method><checkRoute>checkRoute</checkRoute></block>')); } }
/** * Check the block elements of a string to call the "checkBlockRouteByXml" * method an check if a modules accept the custom route. * * @param $html * @return bool|string */ public function moduleRouteExist($html) { // the function method of the module xml will not be executed if this is false $this->execModule = false; $this->foundRouteModules = ''; if ($this->user->isAdmin()) { $adminBlock = "<block type='module'><class>Fraym\\Block\\BlockController</class><method>ajaxHandler</method><checkRoute>checkRoute</checkRoute></block>"; $xml = $this->getXMLObjectFromString($adminBlock); $this->foundRouteModules .= $this->checkBlockRouteByXml($xml); } $blocks = $this->getXMLTags('block', $html); if (isset($blocks[0])) { foreach ($blocks[0] as $block) { $xml = $this->getXMLObjectFromString($block); if ($this->isBlockEnable($xml) === false) { continue; } $this->foundRouteModules .= $this->checkBlockRouteByXml($xml); } } $blocks = $this->db->createQueryBuilder()->select("block, byRef")->from('\\Fraym\\Block\\Entity\\Block', 'block')->leftJoin('block.byRef', 'byRef')->where("block.menuItem IS NULL OR block.menuItem = :menuId")->andWhere("block.menuItemTranslation IS NULL OR block.menuItemTranslation = :menuTranslationId")->setParameter('menuId', $this->route->getCurrentMenuItem()->id)->setParameter('menuTranslationId', $this->route->getCurrentMenuItemTranslation()->id)->getQuery()->getResult(); foreach ($blocks as $block) { $xml = $this->getXMLObjectFromString($this->wrapBlockConfig($block)); if ($this->isBlockEnable($xml) === false) { continue; } $this->foundRouteModules .= $this->checkBlockRouteByXml($xml); } if (!empty($this->foundRouteModules)) { $this->checkRouteError = false; } $this->execModule = true; return $this->isRouteError() && $this->block->inEditMode() === false || empty($this->foundRouteModules) ? false : $this->foundRouteModules; }
/** * @param $block * @return string */ public function wrapBlockConfig($block) { if ($this->user->isAdmin()) { $block = $block->changeSets->count() ? $block->changeSets->last() : $block; } $blockConfigXml = $block->getConfig($this->user->isAdmin()); $dom = new \DOMDocument(); $blockElement = $dom->createElement("block"); if (empty($blockConfigXml) === false) { $fragment = $dom->createDocumentFragment(); $fragment->appendXML($blockConfigXml); $blockElement->appendChild($fragment); } $class = $dom->createElement('class', $block->extension->class); $function = $dom->createElement('method', $block->extension->execMethod); $blockElement->appendChild($class); $blockElement->appendChild($function); $dom->appendChild($blockElement); return $dom->saveXML(); }
/** * @return array|bool */ protected function initConfigurations() { $gp = $this->request->getGPAsObject(); $errors = []; /** * create default language */ $locale = new \Fraym\Locale\Entity\Locale(); switch ($gp->locale) { case 'german': $locale->name = 'German'; $locale->locale = 'de_DE'; $locale->country = 'Germany'; $locale->default = true; break; case 'french': $locale->name = 'French'; $locale->locale = 'fr_FR'; $locale->country = 'France'; $locale->default = true; break; case 'swedish': $locale->name = 'swedish'; $locale->locale = 'sv_SE'; $locale->country = 'Sweden'; $locale->default = true; break; case 'spanish': $locale->name = 'Spanish'; $locale->locale = 'es_ES'; $locale->country = 'Spain'; $locale->default = true; break; default: // english $locale->name = 'English'; $locale->locale = 'en_US'; $locale->country = 'USA'; $locale->default = true; break; } $this->db->persist($locale); $this->db->flush(); $this->locale->setLocale($locale); $this->db->setUpTranslateable()->setUpSortable(); /** * create site */ $site = new \Fraym\Site\Entity\Site(); $site->name = $gp->site->name; $site->caching = true; $site->active = true; $site->menuItems->clear(); $this->db->persist($site); /** * create domain for site */ $domain = new \Fraym\Site\Entity\Domain(); $domain->site = $site; $domain->address = $gp->site->url; $this->db->persist($domain); $this->addMenuItems($site); $adminGroup = new \Fraym\User\Entity\Group(); $adminGroup->name = $this->translation->autoTranslation('Administrator', 'en', $this->locale->getLocale()->locale); $adminGroup->identifier = 'Administrator'; $this->db->persist($adminGroup); $adminUser = new \Fraym\User\Entity\User(); $adminUser->updateEntity($gp->user, false); if (strlen($gp->user->password) < 8) { $errors[] = 'Password is too short.'; } elseif ($gp->user->password === $gp->user->password_repeat) { $adminUser->password = $gp->user->password; } else { $errors[] = 'Passwords do not match.'; } $adminUser->groups->add($adminGroup); $this->db->persist($adminUser); if (count($errors) === 0) { $this->db->flush(); $this->db->clear(); /** * Register extensions, default theme... */ $this->registry->registerExtensions(); /** * Set menuitem template -> default theme */ $this->setupMenuItemTemplate(); /** * Login admin user */ $this->user->setUserId($adminUser->id); return true; } return $errors; }
/** * @return bool */ public function inEditMode() { return $this->user->isAdmin() && $this->inEditMode; }