private function walk_path($folder, $options = null, $path = "")
 {
     if (is_null($options)) {
         $options = array();
     }
     if ($folder) {
         $source = $this->_getParam("source_methodname");
         if (Pimcore_Version::getRevision() > 3303) {
             $object_name = "Pimcore\\Model\\Object\\" . ucfirst($this->_getParam("source_classname"));
         } else {
             $object_name = "Object_" . ucfirst($this->_getParam("source_classname"));
         }
         $children = $folder->getChilds();
         $usesI18n = sizeof($children) > 0 && $this->isUsingI18n($children[0], $source);
         $current_lang = $this->_getParam("current_language");
         if (!Pimcore_Tool::isValidLanguage($current_lang)) {
             $languages = Pimcore_Tool::getValidLanguages();
             $current_lang = $languages[0];
             // TODO: Is this sensible?
         }
         foreach ($children as $child) {
             $class = get_class($child);
             switch ($class) {
                 case "Object_Folder":
                     /**
                      * @var Object_Folder $child
                      */
                     $key = $child->getProperty("Taglabel") != "" ? $child->getProperty("Taglabel") : $child->getKey();
                     if ($this->_getParam("source_recursive") == "true") {
                         $options = $this->walk_path($child, $options, $path . $this->separator . $key);
                     }
                     break;
                 case $object_name:
                     $key = $usesI18n ? $child->{$source}($current_lang) : $child->{$source}();
                     $options[] = array("value" => $child->getId(), "key" => ltrim($path . $this->separator . $key, $this->separator));
                     if ($this->_getParam("source_recursive") == "true") {
                         $options = $this->walk_path($child, $options, $path . $this->separator . $key);
                     }
                     break;
             }
         }
     }
     return $options;
 }
Ejemplo n.º 2
0
 protected function initTranslation()
 {
     $translate = null;
     if (Zend_Registry::isRegistered("Zend_Translate")) {
         $t = Zend_Registry::get("Zend_Translate");
         // this check is necessary for the case that a document is rendered within an admin request
         // example: send test newsletter
         if ($t instanceof Pimcore_Translate) {
             $translate = $t;
         }
     }
     if (!$translate) {
         // setup Zend_Translate
         try {
             $locale = Zend_Registry::get("Zend_Locale");
             $translate = new Pimcore_Translate_Website($locale);
             if (Pimcore_Tool::isValidLanguage($locale)) {
                 $translate->setLocale($locale);
             } else {
                 Logger::error("You want to use an invalid language which is not defined in the system settings: " . $locale);
                 // fall back to the first (default) language defined
                 $languages = Pimcore_Tool::getValidLanguages();
                 if ($languages[0]) {
                     Logger::error("Using '" . $languages[0] . "' as a fallback, because the language '" . $locale . "' is not defined in system settings");
                     $translate = new Pimcore_Translate_Website($languages[0]);
                     // reinit with new locale
                     $translate->setLocale($languages[0]);
                 } else {
                     throw new Exception("You have not defined a language in the system settings (Website -> Frontend-Languages), please add at least one language.");
                 }
             }
             // register the translator in Zend_Registry with the key "Zend_Translate" to use the translate helper for Zend_View
             Zend_Registry::set("Zend_Translate", $translate);
         } catch (Exception $e) {
             Logger::error("initialization of Pimcore_Translate failed");
             Logger::error($e);
         }
     }
     return $translate;
 }
Ejemplo n.º 3
0
 public function initTranslation()
 {
     if (Zend_Registry::isRegistered("Zend_Translate")) {
         $translator = Zend_Registry::get("Zend_Translate");
     } else {
         // setup Zend_Translate
         try {
             $locale = Zend_Registry::get("Zend_Locale");
             $cacheKey = "translator_website";
             if (!($translate = Pimcore_Model_Cache::load($cacheKey))) {
                 $translate = new Pimcore_Translate_Website($locale);
                 Pimcore_Model_Cache::save($translate, $cacheKey, array("translator", "translator_website", "translate"), null, 999);
             }
             if (Pimcore_Tool::isValidLanguage($locale)) {
                 $translate->setLocale($locale);
             } else {
                 Logger::error("You want to use an invalid language which is not defined in the system settings: " . $locale);
                 // fall back to the first (default) language defined
                 $languages = Pimcore_Tool::getValidLanguages();
                 if ($languages[0]) {
                     Logger::error("Using '" . $languages[0] . "' as a fallback, because the language '" . $locale . "' is not defined in system settings");
                     $translate->setLocale($languages[0]);
                 } else {
                     throw new Exception("You have not defined a language in the system settings (Website -> Frontend-Languages), please add at least one language.");
                 }
             }
             // register the translator in Zend_Registry with the key "Zend_Translate" to use the translate helper for Zend_View
             Zend_Registry::set("Zend_Translate", $translate);
         } catch (Exception $e) {
             Logger::error("initialization of Pimcore_Translate failed");
             Logger::error($e);
         }
     }
     return $translator;
 }
Ejemplo n.º 4
0
 private function createEmptyTranslation($locale, $messageId)
 {
     // don't create translation if it's just empty
     if (array_key_exists($messageId, $this->_translate[$locale])) {
         return;
     }
     // no translation found create key
     if (Pimcore_Tool::isValidLanguage($locale)) {
         try {
             $t = Translation_Website::getByKey($messageId);
         } catch (Exception $e) {
             $t = new Translation_Website();
             $t->setKey($messageId);
         }
         $t->addTranslation($locale, "");
         $t->save();
     }
 }
Ejemplo n.º 5
0
 /**
  * @return string
  */
 protected function getTableName()
 {
     if (empty($this->tableName)) {
         // default
         $this->tableName = "object_" . $this->model->getClassId();
         // check for a localized field and if they should be used for this list
         if (property_exists("Object_" . ucfirst($this->model->getClassName()), "localizedfields") && !$this->model->getIgnoreLocalizedFields()) {
             $language = "default";
             if (!$this->model->getIgnoreLocale()) {
                 if ($this->model->getLocale()) {
                     if (Pimcore_Tool::isValidLanguage((string) $this->model->getLocale())) {
                         $language = (string) $this->model->getLocale();
                     }
                 }
                 try {
                     $locale = Zend_Registry::get("Zend_Locale");
                     if (Pimcore_Tool::isValidLanguage((string) $locale) && $language == "default") {
                         $language = (string) $locale;
                     }
                 } catch (Exception $e) {
                 }
             }
             $this->tableName = "object_localized_" . $this->model->getClassId() . "_" . $language;
         }
     }
     return $this->tableName;
 }
Ejemplo n.º 6
0
 /**
  * @throws Exception
  * @param null $language
  * @return string
  */
 public function getLanguage($language = null)
 {
     if ($language) {
         return (string) $language;
     }
     // try to get the language from the registry
     try {
         $locale = Zend_Registry::get("Zend_Locale");
         if (Pimcore_Tool::isValidLanguage((string) $locale)) {
             return (string) $locale;
         }
         throw new Exception("Not supported language");
     } catch (Exception $e) {
         // try to get default from system settings
         $conf = Pimcore_Config::getSystemConfig();
         if ($conf->general->validLanguages) {
             $languages = explode(",", $conf->general->validLanguages);
             return $languages[0];
         }
     }
 }