/** * @param null $blockConfig */ public function getBlockConfig($blockConfig = null) { $locales = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findAll(); $this->view->assign('blockConfig', $blockConfig, false); $this->view->assign('locales', $locales); $this->view->render('BlockConfig'); }
/** * @param $xml * @return mixed */ public function execBlock($xml) { $languageMenu = array(); $currentLocale = $this->locale->getLocale()->id; $defaultLocale = $this->locale->getDefaultLocale(); $currentMenuItem = $this->route->getCurrentMenuItem(); $locales = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findAll(); foreach ($currentMenuItem->translations as $translation) { $url = $translation->url === '' ? '/' : $translation->url; $languageMenu[$translation->locale->id] = array('url' => $url, 'active' => $translation->locale->id === $currentLocale, 'name' => $translation->locale->name); } foreach ($locales as $locale) { if (!isset($languageMenu[$locale->id])) { $menuItem = $currentMenuItem; do { $m = $menuItem->parent; if ($m) { $menuItem = $m; } } while ($m); foreach ($menuItem->translations as $mTranslation) { if ($mTranslation->locale->id === $locale->id) { $url = $mTranslation->url; break; } elseif ($mTranslation->locale->id === $defaultLocale->id) { $url = $mTranslation->url; } } $languageMenu[$locale->id] = array('url' => $url === '' ? '/' : $url, 'active' => $locale->id === $currentLocale, 'name' => $locale->name); } } $this->languageMenuController->renderHtml($languageMenu); }
/** * @param $locale */ public function setLocale($locale) { if (is_object($locale) === false) { $locale = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findOneById($locale); } $this->locale = $locale; }
/** * @param $xml * @return mixed */ public function execBlock($xml) { $languageMenu = array(); $currentLocale = $this->locale->getLocale()->id; $currentMenuItem = $this->route->getCurrentMenuItem(); foreach ($currentMenuItem->translations as $translation) { $url = $translation->getUrl(true); $languageMenu[$translation->locale->id] = array('enable' => $translation->active, 'url' => $url, 'active' => $translation->locale->id === $currentLocale, 'name' => $translation->locale->name); } foreach ($languageMenu as $locale => $language) { if ($language['enable'] === false) { $menuItem = $currentMenuItem; do { $menuItem = $menuItem->parent; } while ($menuItem->parent); $translation = $menuItem->getTranslation($locale); $languageMenu[$locale]['url'] = $translation ? $translation->url : '/'; } else { $localeData = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findOneById($locale); $localeData = explode('_', strtolower($localeData->locale)); $this->template->addHeadData('<link rel="alternate" hreflang="' . $localeData[0] . '" href="' . $language['url'] . '" />', 'hreflang_' . $localeData[0]); } } $this->languageMenuController->renderHtml($languageMenu); }
/** * @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')); }
/** * @param null $blockId */ public function getBlockConfig($blockId = null) { $configXml = null; if ($blockId) { $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId); $configXml = $this->blockParser->getXMLObjectFromString($this->blockParser->wrapBlockConfig($block)); } $this->imageController->getBlockConfig($configXml); }
/** * @param $modelClassNameOrId * @return mixed */ public function getEntityByStringOrId($modelClassNameOrId) { if (!is_numeric($modelClassNameOrId)) { $entity = $this->db->getRepository('\\Fraym\\EntityManager\\Entity\\Entity')->findOneByClassName($modelClassNameOrId); } else { $entity = $this->db->getRepository('\\Fraym\\EntityManager\\Entity\\Entity')->findOneById($modelClassNameOrId); } return $entity; }
/** * @param null $blockConfig */ public function getBlockConfig($blockConfig = null) { $newsListItems = $this->db->getRepository('\\Fraym\\Extension\\News\\Entity\\News')->findAll(); $selectedNewsItems = isset($blockConfig->listItems) ? explode(',', $blockConfig->listItems) : []; $this->view->assign('selectedNewsItems', $selectedNewsItems); $this->view->assign('blockConfig', $blockConfig); $this->view->assign('newsListItems', $newsListItems); $this->view->render('NewsConfig'); }
public function onRegister() { $tablePrefix = 'fraym_'; if (defined('DB_TABLE_PREFIX')) { $tablePrefix = DB_TABLE_PREFIX; } $stmt = $this->db->getConnection()->prepare(str_replace('###TABLE_PREFIX###', $tablePrefix, file_get_contents('Extension/Theme/DefaultTheme/Data/dummy_blocks.sql'))); $stmt->execute(); }
/** * @return array */ public function getRteMenuItemArray() { $menuItems = []; $locales = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findAll(); foreach ($locales as $locale) { foreach ($locale->menuItemTranslations as $menuItemTranslation) { $menuItems[] = [$menuItemTranslation->title . " ({$locale->name})", $menuItemTranslation->id]; } } return json_encode($menuItems); }
/** * @param $key * @param $val * @return $this */ public function set($key, $val) { $obj = null; if ($this->db->getEntityManager()) { $obj = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Config')->findOneByName(strtoupper($key)); if ($obj === null) { $obj = new \Fraym\Registry\Entity\Config(); $obj->name = strtoupper($key); $this->db->persist($obj); } $obj->value = $val; $this->db->flush(); } return $this; }
/** * @param $site * @return $this */ protected function addMenuItems($site) { $pageRoot = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById(1); /** * 404 Page */ $newPage = new \Fraym\Menu\Entity\MenuItem(); $newPage->site = $site; $newPage->caching = true; $newPage->https = false; $newPage->checkPermission = false; $newPage->is404 = true; $newPage->parent = $pageRoot; $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation(); $newPageTranslation->menuItem = $newPage; $newPageTranslation->visible = false; $newPageTranslation->active = true; $newPageTranslation->title = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale); $newPageTranslation->subtitle = ''; $newPageTranslation->url = '/' . $this->translation->autoTranslation('error', 'en', $this->locale->getLocale()->locale) . '-404'; $newPageTranslation->description = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale); $newPageTranslation->externalUrl = false; $this->db->persist($newPageTranslation); $this->db->flush(); $this->db->clear(); return $this; }
/** * @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 null $blockConfig */ public function getBlockConfig($blockConfig = null) { $locales = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findAll(); $htmlData = array(); if ($blockConfig !== null) { $result = $blockConfig->xpath('html'); while (list(, $node) = each($result)) { $attr = $node->attributes(); $locale = (string) $attr->locale; $htmlData[$locale] = (string) (string) $node; } } $this->view->assign('blockConfig', $htmlData); $this->view->assign('locales', $locales); $this->view->render('BlockConfig'); }
/** * Paste copied block */ private function pasteBlock() { $blockId = $this->request->gp('blockId'); $op = $this->request->gp('op', 'copy') == 'copy' ? 'copy' : 'cut'; $byRef = $this->request->gp('byRef', false) === 'true' ? true : false; $menuId = $this->request->gp('menuId', false); $contentId = $this->request->gp('contentId', false); if ($contentId && $blockId && ($block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId))) { if ($op === 'copy') { $copiedBlock = clone $block; $copiedBlock->id = null; $copiedBlock->contentId = $contentId; $copiedBlock->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId); if ($byRef === true) { $copiedBlock->config = null; if ($block->byRef) { $block = $block->byRef; $copiedBlock->byRef = $block; } $copiedBlock->byRef = $block; } $this->db->persist($copiedBlock); $block = $copiedBlock; } else { $block->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId); $block->contentId = $contentId; $this->db->persist($block); } $this->db->flush(); $this->response->sendAsJson(array('success' => true, 'data' => $this->prepareBlockOutput($block))); } $this->response->sendAsJson(array('success' => false, 'message' => $this->translation->getTranslation('Paste error, please copy again'))); }
/** * @return bool */ protected function checkLogoutRedirectConfig() { if ($this->user->isLoggedIn() === false && isset($this->xml->onLogoutSuccessful) && isset($this->xml->onLogoutSuccessful->redirectTo)) { if (isset($this->xml->onLogoutSuccessful->redirectTo->attributes()->type)) { $type = $this->xml->onLogoutSuccessful->redirectTo->attributes()->type; $redirectToData = (string) $this->xml->onLogoutSuccessful->redirectTo; switch ($type) { case 'id': $redirectMenuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($redirectToData); if ($redirectMenuItem) { $this->route->redirectToUrl($redirectMenuItem->getUrl(true)); } break; case 'url': $this->route->redirectToUrl((string) $this->xml->onLogoutSuccessful->redirectTo); break; } return true; } } elseif ($this->user->isLoggedIn() === false) { $this->route->redirectToUrl($this->route->getSiteBaseURI()); return true; } return false; }
/** * @return mixed */ public function getAdminPanel() { $extensions = $this->db->getRepository('\\Fraym\\SiteManager\\Entity\\Extension')->findBy(array('active' => 1), array('sorter' => 'asc')); $extensionSorted = array(); foreach ($extensions as $extension) { if (!isset($extensionSorted[$extension->id])) { $extensionSorted[$extension->id] = array(); } $extensionSorted[$extension->id] = array('name' => $this->translation->getTranslation($extension->name, 'SITE_EXT_' . strtoupper(str_ireplace(' ', '_', $extension->name))), 'iconCssClass' => $extension->iconCssClass); } uasort($extensionSorted, function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); $this->view->assign('extensions', $extensionSorted); $this->view->assign('inEditMode', $this->block->inEditMode()); return $this->getIframeContent($this->view->fetch('AdminPanelContent'), array('cssClass' => 'admin-panel')); }
/** * @param \SimpleXMLElement $obj * @param null $parent * @return \Doctrine\Common\Collections\ArrayCollection */ protected function getItems(\SimpleXMLElement $obj, $parent = null) { $returnChildren = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($obj->children() as $objData) { $id = $this->blockParser->getXmlAttr($objData, 'id'); $menuItemTranslation = $this->db->createQueryBuilder()->select("menu, translation")->from('\\Fraym\\Menu\\Entity\\MenuItemTranslation', 'translation')->join('translation.menuItem', 'menu')->where('menu.id = :id AND translation.locale = :localeId AND translation.active = 1')->setParameter('id', $id)->setParameter('localeId', $this->route->getCurrentMenuItemTranslation()->locale->id)->getQuery()->getOneOrNullResult(); $this->db->free(); if ($menuItemTranslation) { $menuItem = clone $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuItemTranslation->menuItem->id); $children = $this->getItems($objData, $menuItem); $menuItem->parent = $parent; $menuItem->children = $children; $returnChildren->set($menuItem->id, $menuItem); } } return $returnChildren; }
/** * @param \Doctrine\ORM\Event\OnFlushEventArgs $eventArgs */ public function onFlush(\Doctrine\ORM\Event\OnFlushEventArgs $eventArgs) { $em = $eventArgs->getEntityManager(); $uow = $em->getUnitOfWork(); foreach ($uow->getScheduledEntityUpdates() as $entity) { $lifecycleCallbacks = $this->db->getAnnotationReader()->getClassAnnotation(new \ReflectionClass($entity), 'Fraym\\Annotation\\LifecycleCallback'); if (is_object($lifecycleCallbacks)) { foreach ($lifecycleCallbacks as $lifecycleEvent => $lifecycleCallback) { if (__FUNCTION__ === $lifecycleEvent && count($lifecycleCallback)) { foreach ($lifecycleCallback as $class => $method) { $this->serviceLocator->get($class)->{$method}($entity, $eventArgs, __FUNCTION__); } } } } } }
/** * @param $xml */ public function render($xml) { foreach ($xml as $field => $val) { $val = (string) $val; if ($field === 'image_link') { if (is_numeric($val)) { $menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($val); if ($menuItem) { $val = $menuItem->getUrl(true); } else { $val = null; } } } $this->view->assign($field, $val); } $this->view->setTemplate('Block'); }
/** * Get a entity with parameters * * @param $className * @param $entryData * @return mixed */ protected function getEntity($className, $entryData) { foreach ($entryData as $k => &$data) { if (is_array($data)) { $subEntryData = reset($data); $subEntryClassName = key($data); $data = $this->db->getRepository($subEntryClassName)->findOneBy($subEntryData); } } return $this->db->getRepository($className)->findOneBy($entryData); }
/** * @param $blockId * @param bool $undo */ public function deployBlock($blockId, $undo = false) { $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId); if ($block) { if ($undo) { $this->undoBlock($block); } else { $this->deploy($block); } } }
/** * @param null $blockId */ public function getBlockConfig($blockId = null) { $configXml = null; $config = []; if ($blockId) { $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId); $configXml = $this->blockParser->getXmlObjectFromString($this->blockParser->wrapBlockConfig($block)); $config = json_decode($configXml->mailformOptions, true); } $this->mailformController->getBlockConfig($config); }
private function createBlock($contentId, $menuItemId, $extension, $config) { $block = new \Fraym\Block\Entity\Block(); $block->extension = $extension; $block->contentId = $contentId; $block->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuItemId); $block->site = $this->site; $block->config = $config; $this->db->persist($block); $this->db->flush(); }
/** * @param $blockHistory * @param $block * @param $historyType * @return mixed */ public function setHistoryFrom($blockHistory, $block, $historyType) { if ($historyType != 'deleted') { $blockHistory->from = $block; } else { foreach ($block->histories as $historyBlock) { $historyBlock->from = null; $this->db->persist($historyBlock); } $this->db->flush(); } return $blockHistory; }
/** * @param $blockHtml * @return mixed */ public function replaceLinkTags($blockHtml) { $callback = function ($matches) { $id = trim(trim($matches[1], '"'), "'"); if (is_numeric($id)) { $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($id); if ($menuItemTranslation) { return ' href="' . $this->route->buildFullUrl($menuItemTranslation->menuItem, true) . '"'; } } return $matches[0]; }; return preg_replace_callback('#\\s*(?i)href\\s*=\\s*(\\"([^"]*\\")|\'[^\']*\'|([^\'">\\s]+))#si', $callback, $blockHtml); }
/** * @return bool|mixed|string */ public function repositorySearch() { $searchTerm = $this->request->post('term', ''); $availableExtensions = new \Doctrine\Common\Collections\ArrayCollection(); $unregisteredExtensions = $this->registryManager->getUnregisteredExtensions(); $installedExtensions = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findBy(array(), array('name' => 'asc')); $extensions = $this->registryManager->repositoryRequest('listModules', array('searchTerm' => $searchTerm, 'offset' => 0, 'limit' => 20)); foreach ($installedExtensions as $installedExtension) { $availableExtensions->set($installedExtension->repositoryKey, $installedExtension); } foreach ($unregisteredExtensions as $unregisteredExtension) { $availableExtensions->set($unregisteredExtension['repositoryKey'], $unregisteredExtension); } $this->view->assign('availableExtensions', $availableExtensions); $this->view->assign('extensions', $extensions ?: array()); return $this->template->fetch('RepositorySearch'); }
/** * @return bool|mixed|string */ public function repositorySearch() { $searchTerm = $this->request->post('term', ''); $extensions = $this->registryManager->searchPackage($searchTerm); $availableExtensions = new \Doctrine\Common\Collections\ArrayCollection(); $unregisteredExtensions = $this->registryManager->getUnregisteredExtensions(); $installedExtensions = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findBy([], ['name' => 'asc']); foreach ($installedExtensions as $installedExtension) { $availableExtensions->set($installedExtension->repositoryKey, $installedExtension); } foreach ($unregisteredExtensions as $unregisteredExtension) { $availableExtensions->set($unregisteredExtension['repositoryKey'], $unregisteredExtension); } $this->view->assign('availableExtensions', $availableExtensions); $this->view->assign('extensions', $extensions ?: []); return $this->view->fetch('RepositorySearch'); }
/** * */ private function editMenuItem() { $menu = $this->request->post('menu'); if ($menu !== null) { $newMenuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menu['id']); try { foreach ($menu['translations'] as $k => $translation) { if (empty($translation['title'])) { unset($menu['translations'][$k]); } } $newMenuItem->updateEntity($menu); $this->response->sendAsJson(array('error' => false, 'menuId' => $newMenuItem->id, 'translations' => array())); } catch (\Exception $e) { $this->response->sendAsJson(array('error' => true, 'message' => $e->getMessage())); } } }
/** * Paste copied block */ protected function pasteBlock() { $blockId = $this->request->gp('blockId'); $op = $this->request->gp('op', 'copy') == 'copy' ? 'copy' : 'cut'; $byRef = $this->request->gp('byRef', false) === 'true' ? true : false; $menuId = $this->request->gp('menuId', false); $contentId = $this->request->gp('contentId', false); if ($contentId && $blockId && ($block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId))) { $menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId); $blocks = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findBy(['menuItem' => $menuItem, 'contentId' => $contentId], ['position' => 'asc']); // Re-Order other blocks foreach ($blocks as $k => $b) { $b->position = $k + 1; } if ($op === 'copy') { $block = $block->changeSets->count() ? $block->changeSets->last() : $block; $copiedBlock = clone $block; $copiedBlock->id = null; $copiedBlock->position = 0; $copiedBlock->contentId = $contentId; $copiedBlock->menuItem = $menuItem; if ($byRef === true) { $copiedBlock->config = null; if ($block->byRef) { $block = $block->byRef; $copiedBlock->byRef = $block; } $copiedBlock->byRef = $block; } $changedBlock = $this->createChangeSet($copiedBlock, null, \Fraym\Block\Entity\ChangeSet::ADDED); } else { $changedBlock = $block->changeSets->count() ? $block->changeSets->last() : $block; $changedBlock->position = 0; $changedBlock->menuItem = $menuItem; $changedBlock->contentId = $contentId; $this->createChangeSet($changedBlock, $block, \Fraym\Block\Entity\ChangeSet::MOVED); } $this->db->flush(); $this->response->sendAsJson(['success' => true, 'data' => $this->prepareBlockOutput($changedBlock)]); } $this->response->sendAsJson(['success' => false, 'message' => $this->translation->getTranslation('Paste error, please reload the page and copy again.')]); }