/** * @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; }
/** * 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; }
/** * @return $this */ private function initExtensionRoutes() { // Init only for admins if (!$this->user->isAdmin()) { return $this; } foreach ($this->db->getRepository('\\Fraym\\SiteManager\\Entity\\Extension')->findAll() as $extsension) { $this->addVirtualRoute('siteManagerExt_' . $extsension->id, '/fraym/admin/extension/' . $extsension->id, array($extsension->class, $extsension->method)); } return $this; }
/** * @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')); }
/** * 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; }
/** * @return bool */ public function inEditMode() { return $this->user->isAdmin() && $this->inEditMode; }
/** * @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(); }