Beispiel #1
0
 public function __construct(Dispatcher $dispatcher)
 {
     $cmsCache = new CmsCache();
     $languages = $cmsCache->get('languages');
     $defaultLangArray = array_values(array_slice($languages, 0, 1));
     $defaultLang = $defaultLangArray[0];
     $request = $this->getDI()->get('request');
     $queryLang = $request->getQuery('lang');
     if (!$queryLang) {
         $langParam = $dispatcher->getParam('lang');
     } else {
         $langParam = $queryLang;
     }
     if (!$langParam) {
         $langParam = $defaultLang['iso'];
     }
     foreach ($languages as $language) {
         if ($langParam == $language['iso']) {
             define('LANG', $language['iso']);
             define('LANG_URL', '/' . $language['url']);
         }
     }
     if (!defined('LANG')) {
         define('LANG', $defaultLang['iso']);
         \Application\Mvc\Model\Model::$lang = $defaultLang['iso'];
     }
     if (!defined('LANG_URL')) {
         define('LANG_URL', $defaultLang['url']);
     }
     $translations = \Cms\Model\Translate::findCachedByLangInArray(LANG);
     $this->getDI()->set('translate', new \Phalcon\Translate\Adapter\NativeArray(['content' => $translations]));
 }
 public function indexAction()
 {
     $model = new Translate();
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         if (!empty($post)) {
             foreach ($post as $key => $value) {
                 $key = str_replace('_', ' ', $key);
                 // При отправке формы POST-запросом, все пробелы заменяются на "_". Меняем обратно.
                 $phrase = $model->findByPhraseAndLang($key);
                 if ($phrase) {
                     $phrase->setTranslation($value);
                     $phrase->update();
                 } else {
                     $phraseNew = new Translate();
                     $phraseNew->setPhrase($key);
                     $phraseNew->setLang(LANG);
                     $phraseNew->setTranslation($value);
                     $phraseNew->create();
                 }
             }
         }
         CmsCache::getInstance()->save('translates', Translate::buildCmsTranslatesCache());
         $this->flash->success($this->helper->at('Saved has been successful'));
         $lang = LANG;
         $key = HOST_HASH . md5("Translate::findByLang({$lang})");
         $this->cache->delete($key);
         return $this->redirect($this->url->get() . 'cms/translate?lang=' . LANG);
     }
     $scanner = new Scanner();
     $phrases = $scanner->search();
     $this->view->phrases = $phrases;
     $this->view->model = $model;
 }
Beispiel #3
0
 public function addML($pattern, $paths = null, $name)
 {
     $languages = CmsCache::getInstance()->get('languages');
     foreach ($languages as $lang) {
         $iso = $lang['iso'];
         if ($lang['primary']) {
             $this->add($pattern, $paths)->setName(self::ML_PREFIX . $name . '_' . $iso);
         } else {
             $new_pattern = '/' . $lang['url'] . $pattern;
             $paths['lang'] = $iso;
             // будущее значение константы LANG
             $this->add($new_pattern, $paths)->setName(self::ML_PREFIX . $name . '_' . $iso);
         }
     }
 }
Beispiel #4
0
 public static function findCachedLanguages()
 {
     return CmsCache::getInstance()->get('languages');
 }
Beispiel #5
0
 public static function types()
 {
     return CmsCache::getInstance()->get('publication_types');
 }
Beispiel #6
0
 public static function translates()
 {
     return CmsCache::getInstance()->get('translates');
 }
Beispiel #7
0
 public static function urls()
 {
     return CmsCache::getInstance()->get('seo_manager');
 }