/**
  * @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);
 }
Esempio n. 2
0
 /**
  * @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);
 }
Esempio n. 3
0
 /**
  * @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;
 }
Esempio n. 4
0
 /**
  * Create the table entries from the registry annotation
  *
  * @param $registry
  * @param $classAnnotation
  * @param $oldRegistryEntry
  * @return $this
  */
 private function createEntities($registry, $classAnnotation, $oldRegistryEntry = null)
 {
     if (count($classAnnotation->entity)) {
         foreach ($classAnnotation->entity as $className => $entries) {
             if ($oldRegistryEntry !== null && isset($classAnnotation->updateEntity[$className])) {
                 foreach ($classAnnotation->updateEntity[$className] as $entryData) {
                     $entry = $this->getEntity($className, $entryData);
                     if ($entry) {
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $data = $this->getEntityDataForUpdate($entryData, $classAnnotation->entity[$className]);
                         $entry->updateEntity($data);
                     }
                 }
             } elseif ($oldRegistryEntry === null) {
                 foreach ($entries as $entryData) {
                     $entryDataWithSubEntries = $this->getSubEntries($entryData, $registry);
                     if ($this->getEntity($className, $entryDataWithSubEntries) === null) {
                         $entry = new $className();
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $entry->updateEntity($entryDataWithSubEntries);
                     }
                 }
             }
         }
     }
     if (count($classAnnotation->config)) {
         foreach ($classAnnotation->config as $configName => $data) {
             $className = '\\Fraym\\Registry\\Entity\\Config';
             $data['name'] = $configName;
             $data['registry'] = $registry;
             $entity = $this->db->getRepository($className)->findOneByName($configName);
             if ($entity === null) {
                 $entry = new $className();
                 $entry->updateEntity($data);
             }
         }
     }
     if (count($classAnnotation->translation)) {
         foreach ($classAnnotation->translation as $translation) {
             $defaultValue = $translation[0];
             $key = isset($translation[1]) ? $translation[1] : $defaultValue;
             $locale = isset($translation[2]) ? $translation[2] : 'en_US';
             $this->translation->createTranslation($key, $defaultValue, $this->locale->getLocale()->locale, $locale);
         }
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * @param $key
  * @param $locale
  * @param string $default
  * @param string $defaultLocale
  * @return Entity\Translation|mixed|object
  */
 private function getTranslationEntity($key, $locale, $default = '', $defaultLocale = 'en_US')
 {
     $translationString = empty($default) ? $key : $default;
     $translation = $this->db->getRepository('\\Fraym\\Translation\\Entity\\Translation')->findOneByKey($key);
     if (null === $translation) {
         return $this->createTranslation($key, $translationString, $locale, $defaultLocale);
     }
     $repository = $this->db->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     $translations = $repository->findTranslations($translation);
     if (isset($translations[$locale])) {
         return (object) $translations[$locale];
     } elseif ($this->locale->getLocale()->locale == $locale) {
         $translation->locale = $locale;
         $this->db->refresh($translation);
         $this->db->clear();
         return $translation;
     } else {
         return $this->updateTranslationLocales($translation, $translationString, $locale, $defaultLocale);
     }
     return (object) $translations[$locale];
 }
Esempio n. 6
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $template = null;
     $dataSource = null;
     $locale = $this->locale->getLocale();
     $variables = unserialize((string) $xml->dynamicTemplateConfig);
     if (!empty((string) $xml->dynamicTemplate)) {
         $template = $this->getTemplatePath() . DIRECTORY_SEPARATOR . (string) $xml->dynamicTemplate;
     }
     $obj = $this->getTemplateXmlObject((string) $xml->dynamicTemplate);
     if (isset($obj->dataSource)) {
         $dataSource = $obj->dataSource;
         $class = (string) $dataSource->class;
         $method = (string) $dataSource->method;
         if (method_exists($class, $method)) {
             $classObj = $this->serviceLocator->get($class);
             $dataSource = $classObj->{$method}($locale->id, $variables);
         }
     }
     $this->dynamicTemplateController->render($template, $locale->id, $variables, $dataSource);
 }
Esempio n. 7
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $errors = [];
     $submit = false;
     $values = $this->request->getGPAsArray();
     $requiredFields = $this->getRequiredFields($xml);
     $formHash = $this->createFormHash($requiredFields);
     if ($this->request->post('mailform')) {
         $required = $values['required'];
         $fields = $values['field'];
         if ($this->isFormValid($formHash, $this->getValidationRules($required))) {
             $submit = true;
             $this->validation->setData($fields);
             $this->validation->addRule('email', 'email');
             $errorMessages = [];
             foreach ($requiredFields as $field => $val) {
                 $this->validation->addRule($field, $val['rule'], $val['param']);
                 $errorMessages = array_merge($errorMessages, [$field => [$field => $this->translation->getTranslation('Please fill out the field')]]);
             }
             $this->validation->setErrorMessages($errorMessages);
             $check = $this->validation->check();
             if ($check === true) {
                 $config = json_decode($xml->mailformOptions, true);
                 $receiver = $config[$this->locale->getLocale()->id]['email'];
                 $subject = $config[$this->locale->getLocale()->id]['subject'];
                 $msg = $this->mail->getMessageInstance();
                 $msg->setFrom([$fields['email']]);
                 $msg->setSubject($subject);
                 $msg->setTo(explode(',', $receiver));
                 $this->template->assign('fields', $fields, false);
                 $msg->setBody($this->template->fetch('Extension/Mailform/Mail'), 'text/html');
                 $this->mail->send();
             } else {
                 $errors = $check;
             }
         }
     }
     $this->mailformController->renderHtml($submit, $values, $errors);
 }
Esempio n. 8
0
 /**
  * @param $number
  * @param string $symbol
  * @return mixed
  */
 public function formatCurrency($number, $symbol = '')
 {
     $fmt = new \NumberFormatter($this->locale->getLocale()->locale, \NumberFormatter::CURRENCY);
     return $fmt->formatCurrency($number, $symbol);
 }
Esempio n. 9
0
 /**
  * @param $menuItemTranslation
  * @return bool
  */
 private function setupPage($menuItemTranslation)
 {
     try {
         $this->currentMenuItemTranslation = $menuItemTranslation;
         $this->currentMenuItem = $menuItemTranslation->menuItem;
         $this->locale->setLocale($menuItemTranslation->locale);
         $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
         $pageTitle = ((string) $menuItemTranslation->pageTitle === '' ? $menuItemTranslation->title : $menuItemTranslation->pageTitle) . ' | ' . $menuItemTranslation->menuItem->site->name;
         $this->template->setPageTitle($pageTitle);
         $this->template->setPageDescription($menuItemTranslation->longDescription);
         $this->template->setKeywords(explode(',', $menuItemTranslation->keywords));
         setlocale(LC_ALL, $this->locale->getLocale()->locale);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
Esempio n. 10
0
File: Route.php Progetto: fraym/core
 /**
  * @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;
 }