Esempio n. 1
0
 /** @override */
 public static function init($em, $reader)
 {
     // http://www.w3schools.com/tags/ref_language_codes.asp
     static::$listener = $listener = new \Gedmo\Translatable\TranslatableListener();
     // Current translation locale should be set from session or hook later into the listener
     // Most importantly, before the entity manager is flushed
     $lang = \Config::get('language', 'en');
     $default = \Config::get('language_fallback', $lang);
     if (is_array($default)) {
         $default = $default[0];
     }
     $listener->setTranslatableLocale($lang);
     $listener->setDefaultLocale($default);
     $listener->setAnnotationReader($reader);
     $listener->setTranslationFallback(true);
     $em->getEventManager()->addEventSubscriber($listener);
 }
Esempio n. 2
0
 public function onBootstrap(EventInterface $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $config = $e->getApplication()->getServiceManager()->get('config');
     $translator = $serviceManager->get('translator');
     // Gestion de la locale
     if (PHP_SAPI !== 'cli') {
         //translator
         // Gestion locale pour le back
         if ($serviceManager->get('router')->match($serviceManager->get('request')) && strpos($serviceManager->get('router')->match($serviceManager->get('request'))->getMatchedRouteName(), 'admin') !== false) {
             if ($e->getRequest()->getCookie() && $e->getRequest()->getCookie()->offsetExists('pg_locale_back')) {
                 $locale = $e->getRequest()->getCookie()->offsetGet('pg_locale_back');
             }
         }
         if (empty($locale)) {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
             } else {
                 $locale = 'fr_FR';
             }
         }
         $translator->setLocale($locale);
         // plugins
         $translate = $serviceManager->get('viewhelpermanager')->get('translate');
         $translate->getTranslator()->setLocale($locale);
         $options = $serviceManager->get('playgroundcore_module_options');
         $options->setLocale($locale);
     }
     // positionnement de la langue pour les traductions de date avec strftime
     setlocale(LC_TIME, "fr_FR", 'fr_FR.utf8', 'fra');
     AbstractValidator::setDefaultTranslator($translator, 'playgroundcore');
     /*
      * Entity translation based on Doctrine Gedmo library
      */
     $doctrine = $serviceManager->get('doctrine.entitymanager.orm_default');
     $evm = $doctrine->getEventManager();
     $translatableListener = new \Gedmo\Translatable\TranslatableListener();
     // TODO : Set the Default locale to be taken from config
     $translatableListener->setDefaultLocale('fr_FR');
     // If no translation is found, fallback to entity data
     $translatableListener->setTranslationFallback(true);
     // set Locale
     if (!empty($locale)) {
         $translatableListener->setTranslatableLocale($locale);
     }
     $evm->addEventSubscriber($translatableListener);
     /**
      * Adding a Filter to slugify a string (make it URL compliiant)
      */
     $filterChain = new \Zend\Filter\FilterChain();
     $filterChain->getPluginManager()->setInvokableClass('slugify', 'PlaygroundCore\\Filter\\Slugify');
     $filterChain->attach(new Filter\Slugify());
     // Start the session container
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     /**
      * Optional: If you later want to use namespaces, you can already store the
      * Manager in the shared (static) Container (=namespace) field
      */
     \Zend\Session\Container::setDefaultManager($sessionManager);
     // Google Analytics : When the render event is triggered, we invoke the view helper to
     // render the javascript code.
     $e->getApplication()->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function (\Zend\Mvc\MvcEvent $e) use($serviceManager) {
         $view = $serviceManager->get('ViewHelperManager');
         $plugin = $view->get('googleAnalytics');
         $plugin();
         $pluginOG = $view->get('facebookOpengraph');
         $pluginOG();
     });
     if (PHP_SAPI !== 'cli') {
         $session = new Container('facebook');
         $fb = $e->getRequest()->getPost()->get('signed_request');
         if ($fb) {
             list($encoded_sig, $payload) = explode('.', $fb, 2);
             $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
             $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
             $session->offsetSet('signed_request', $data);
             // This fix exists only for safari on Windows : we need to redirect the user to the page outside of iframe
             // for the cookie to be accepted. Core just adds a 'redir_fb_page_id' var to alert controllers
             // that they need to send the user back to FB...
             if (!count($_COOKIE) > 0 && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')) {
                 echo '<script type="text/javascript">' . 'window.top.location.href = window.location.href+"?redir_fb_page_id=' . $data["page"]["id"] . '";' . '</script>';
             }
             // This fix exists only for IE6+, when this app is embedded into an iFrame : The P3P policy has to be set.
             $response = $e->getResponse();
             if ($response instanceof \Zend\Http\Response && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strpos($_SERVER['HTTP_USER_AGENT'], 'rv:11.'))) {
                 $response->getHeaders()->addHeaderLine('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * Gets the 'stof_doctrine_extensions.listener.translatable' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * This service is private.
  * If you want to be able to request this service from the container directly,
  * make it public, otherwise you might end up with broken code.
  *
  * @return \Gedmo\Translatable\TranslatableListener A Gedmo\Translatable\TranslatableListener instance
  */
 protected function getStofDoctrineExtensions_Listener_TranslatableService()
 {
     $this->services['stof_doctrine_extensions.listener.translatable'] = $instance = new \Gedmo\Translatable\TranslatableListener();
     $instance->setAnnotationReader($this->get('annotation_reader'));
     $instance->setDefaultLocale('en');
     $instance->setTranslatableLocale('en');
     $instance->setTranslationFallback(false);
     $instance->setPersistDefaultLocaleTranslation(false);
     $instance->setSkipOnLoad(false);
     return $instance;
 }
Esempio n. 4
0
 /**
  * @return $this
  * @throws \Exception
  */
 public function setUpTranslateable()
 {
     $defaultLocale = $this->locale->getDefaultLocale();
     if ($defaultLocale === null) {
         throw new \Exception('Default locale not found! Fraym is not correctly installed, please reinstall Fraym.');
     }
     $translatableListener = new \Gedmo\Translatable\TranslatableListener();
     $translatableListener->setDefaultLocale($defaultLocale->locale);
     $translatableListener->setAnnotationReader($this->cachedAnnotationReader);
     $translatableListener->setTranslationFallback(true);
     $translatableListener->setPersistDefaultLocaleTranslation(true);
     $this->eventManager->addEventSubscriber($translatableListener);
     return $this;
 }