Ejemplo n.º 1
0
 /**
  * @static
  * @param $id - translation key
  * @param bool $create - creates an empty translation entry if the key doesn't exists
  * @param bool $returnIdIfEmpty - returns $id if no translation is available
  * @return Translation_Website
  */
 public static function getByKey($id, $create = false, $returnIdIfEmpty = false)
 {
     $translation = new self();
     try {
         $translation->getResource()->getByKey($id);
     } catch (Exception $e) {
         if (!$create) {
             throw new Exception($e->getMessage());
         } else {
             $translation->setKey($id);
             $translation->setDate(time());
             $translations = array();
             foreach (Pimcore_Tool::getValidLanguages() as $lang) {
                 $translations[$lang] = "";
             }
             $translation->setTranslations($translations);
             $translation->save();
         }
     }
     if ($returnIdIfEmpty) {
         $translations = $translation->getTranslations();
         foreach ($translations as $key => $value) {
             $translations[$key] = $value ?: $id;
         }
         $translation->setTranslations($translations);
     }
     return $translation;
 }
Ejemplo n.º 2
0
 /**
  * @return void
  */
 public function update()
 {
     foreach ($this->fieldsToSave as $field) {
         if (in_array($field, $this->validColumns)) {
             $getter = 'get' . ucfirst($field);
             if (in_array($field, $this->localizedFields)) {
                 // handle localized Fields
                 $localizedValues = array();
                 foreach (Pimcore_Tool::getValidLanguages() as $lang) {
                     $localizedValues[$lang] = $value = $this->model->{$getter}($lang);
                 }
                 $value = $localizedValues;
             } else {
                 // normal case
                 $value = $this->model->{$getter}();
             }
             if (is_array($value) || is_object($value)) {
                 $value = serialize($value);
             } else {
                 if (is_bool($value)) {
                     $value = (int) $value;
                 }
             }
             $data[$field] = $value;
         }
     }
     $this->db->update(self::TABLE_NAME, $data, 'id=' . $this->db->quote($this->model->getId()));
 }
Ejemplo n.º 3
0
 protected function getLanguages()
 {
     if ($this->languages == null) {
         $languages = Pimcore_Tool::getValidLanguages();
         $this->languages = $languages;
     }
     return $this->languages;
 }
Ejemplo n.º 4
0
 public function configureOptions()
 {
     $validLanguages = (array) Pimcore_Tool::getValidLanguages();
     $languages = Zend_Locale::getTranslationList('language');
     asort($languages);
     $options = array();
     foreach ($languages as $short => $translation) {
         if ($this->getOnlySystemLanguages()) {
             if (!in_array($short, $validLanguages)) {
                 continue;
             }
         }
         if (strlen($short) == 2 or strlen($short) == 5 and strpos($short, "_") == 2) {
             $options[] = array("key" => $translation, "value" => $short);
         }
     }
     $this->setOptions($options);
 }
 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.º 6
0
 protected function _loadTranslationData($data = null, $locale, array $options = array())
 {
     $list = new Translation_Website_List();
     $list->load();
     foreach ($list->getTranslations() as $translation) {
         if ($translation instanceof Translation_Abstract) {
             foreach ($translation->getTranslations() as $language => $text) {
                 $this->_translate[$language][$translation->getKey()] = Pimcore_Tool_Text::removeLineBreaks($text);
             }
         }
     }
     $availableLanguages = (array) Pimcore_Tool::getValidLanguages();
     foreach ($availableLanguages as $language) {
         if (!array_key_exists($language, $this->_translate) || empty($this->_translate[$language])) {
             $this->_translate[$language] = array("__pimcore_dummy" => "only_a_dummy");
         }
     }
     return $this->_translate;
 }
Ejemplo n.º 7
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.º 8
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.º 9
0
 public function getAvailableLanguagesAction()
 {
     if ($languages = Pimcore_Tool::getValidLanguages()) {
         $this->_helper->json($languages);
     }
     $t = new Translation_Website();
     $this->_helper->json($t->getAvailableLanguages());
 }
Ejemplo n.º 10
0
 /**
  * @param  $fd
  * @return void
  */
 protected function setFieldData($object, $fd, $refDocument, $refAsset, $minAmountLazyRelations)
 {
     foreach ($fd as $field) {
         $name = $field->getName();
         $type = $field->getFieldType();
         $class = "Object_Class_Data_" . ucfirst($type);
         $this->assertTrue(class_exists($class));
         $data = new $class();
         $setter = "set" . ucfirst($name);
         if (!$field->isRelationType() or !$field->isRemoteOwner()) {
             $this->assertTrue(method_exists($object, $setter));
         }
         if ($data instanceof Object_Class_Data_Checkbox) {
             $object->{$setter}(true);
         } else {
             if ($data instanceof Object_Class_Data_Time) {
                 $object->{$setter}("18:00");
             } else {
                 if ($data instanceof Object_Class_Data_Password) {
                     $object->{$setter}("verySecret");
                 } else {
                     if ($data instanceof Object_Class_Data_Input) {
                         $object->{$setter}("simple input");
                     } else {
                         if ($data instanceof Object_Class_Data_Date) {
                             $object->{$setter}(new Zend_Date());
                         } else {
                             if ($data instanceof Object_Class_Data_Datetime) {
                                 $object->{$setter}(new Zend_Date());
                             } else {
                                 if ($data instanceof Object_Class_Data_Href) {
                                     $object->{$setter}(Object_Abstract::getById($object->getId() - 1));
                                 } else {
                                     if ($data instanceof Object_Class_Data_Objects and !$data->isRemoteOwner()) {
                                         $data = array();
                                         $o = Object_Abstract::getById($object->getId() - 1);
                                         if (!$o instanceof Object_Folder) {
                                             $data[] = $o;
                                         }
                                         $data[] = Object_Abstract::getById($object->getId());
                                         $object->{$setter}($data);
                                     } else {
                                         if ($data instanceof Object_Class_Data_Fieldcollections) {
                                             $items = new Object_Fieldcollection();
                                             $collectionA = Object_Fieldcollection_Definition::getByKey("collectionA");
                                             $itemDefinitions = $collectionA->getFieldDefinitions();
                                             $item = new Object_Fieldcollection_Data_CollectionA();
                                             $this->setFieldData($item, $itemDefinitions, $refDocument, $refAsset, $minAmountLazyRelations);
                                             $items->add($item);
                                             $object->{$setter}($items);
                                         } else {
                                             if ($data instanceof Object_Class_Data_Localizedfields) {
                                                 $getter = "get" . ucfirst($name);
                                                 $data = $object->getO_class()->getFieldDefinition("localizedfields");
                                                 $localizedData = array();
                                                 $validLanguages = Pimcore_Tool::getValidLanguages();
                                                 foreach ($validLanguages as $language) {
                                                     foreach ($data->getFieldDefinitions() as $fd) {
                                                         $fieldData = $this->getLocalizedFieldDataFor($fd, $language, $refAsset);
                                                         $localizedData[$language][$fd->getName()] = $fieldData;
                                                     }
                                                 }
                                                 $object->{$setter}(new Object_Localizedfield($localizedData));
                                             } else {
                                                 if ($data instanceof Object_Class_Data_Multihref) {
                                                     $data = array();
                                                     $data[] = Object_Abstract::getById($object->getId() - 1);
                                                     $data[] = $refAsset;
                                                     //dummy for checking if relation is saved twice
                                                     $data[] = Asset::getById($refAsset->getId());
                                                     $data[] = $refDocument;
                                                     $fd = $object->geto_Class()->getFieldDefinition($name);
                                                     if ($fd->getLazyLoading()) {
                                                         for ($i = 1; $i <= $minAmountLazyRelations; $i++) {
                                                             $data[] = $this->createRandomObject("unittest");
                                                         }
                                                     }
                                                     $object->{$setter}($data);
                                                 } else {
                                                     if ($data instanceof Object_Class_Data_Languagemultiselect) {
                                                         $object->{$setter}(array("de", "en"));
                                                     } else {
                                                         if ($data instanceof Object_Class_Data_Countrymultiselect) {
                                                             $object->{$setter}(array("AT", "AU"));
                                                         } else {
                                                             if ($data instanceof Object_Class_Data_Multiselect) {
                                                                 $object->{$setter}(array("cat", "cow"));
                                                             } else {
                                                                 if ($data instanceof Object_Class_Data_User) {
                                                                     //create a user to set
                                                                     $user = new User();
                                                                     $user->setUsername(uniqid());
                                                                     $user->setParentId(0);
                                                                     $user->setHasCredentials(true);
                                                                     $user->setPassword(md5("unitTestUser"));
                                                                     $user->save();
                                                                     $object->{$setter}($user->getId());
                                                                 } else {
                                                                     if ($data instanceof Object_Class_Data_Language) {
                                                                         $object->{$setter}("en");
                                                                     } else {
                                                                         if ($data instanceof Object_Class_Data_Country) {
                                                                             $object->{$setter}("AU");
                                                                         } else {
                                                                             if ($data instanceof Object_Class_Data_Select) {
                                                                                 $object->{$setter}(2);
                                                                             } else {
                                                                                 if ($data instanceof Object_Class_Data_Geobounds) {
                                                                                     $object->{$setter}(new Object_Data_Geobounds(new Object_Data_Geopoint(150.96588134765625, -33.704920213014425), new Object_Data_Geopoint(150.60333251953125, -33.893217379440884)));
                                                                                 } else {
                                                                                     if ($data instanceof Object_Class_Data_Geopoint) {
                                                                                         $object->{$setter}(new Object_Data_Geopoint(151.2111111, -33.8599722));
                                                                                     } else {
                                                                                         if ($data instanceof Object_Class_Data_Geopolygon) {
                                                                                             $data = array(new Object_Data_Geopoint(150.54428100585938, -33.464671118242684), new Object_Data_Geopoint(150.73654174804688, -33.913733814316245), new Object_Data_Geopoint(151.2542724609375, -33.9946115848146));
                                                                                             $object->{$setter}($data);
                                                                                         } else {
                                                                                             if ($data instanceof Object_Class_Data_Image) {
                                                                                                 $object->{$setter}($refAsset);
                                                                                             } else {
                                                                                                 if ($data instanceof Object_Class_Data_Slider) {
                                                                                                     $object->{$setter}(6);
                                                                                                 } else {
                                                                                                     if ($data instanceof Object_Class_Data_Numeric) {
                                                                                                         $object->{$setter}(12000);
                                                                                                     } else {
                                                                                                         if ($data instanceof Object_Class_Data_Table) {
                                                                                                             $object->{$setter}(array(array("eins", "zwei", "drei"), array(1, 2, 3), array("a", "b", "c")));
                                                                                                         } else {
                                                                                                             if ($data instanceof Object_Class_Data_Textarea) {
                                                                                                                 $object->{$setter}("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
                                                                                                             } else {
                                                                                                                 if ($data instanceof Object_Class_Data_Wysiwyg) {
                                                                                                                     $object->{$setter}("<p>This is some <strong>HTML</strong> content</p><ul><li>list one</li><li>list two</li></ul>");
                                                                                                                 } else {
                                                                                                                     if ($data instanceof Object_Class_Data_Link) {
                                                                                                                         $l = new Object_Data_Link();
                                                                                                                         $l->setPath("http://www.pimcore.org");
                                                                                                                         $l->setTitle("pimcore.org");
                                                                                                                         $l->setText("pimcore.org");
                                                                                                                         $object->{$setter}($l);
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * @param mixed $value
  * @return mixed
  */
 public function getFromWebserviceImport($value)
 {
     if (is_array($value)) {
         $validLanguages = Pimcore_Tool::getValidLanguages();
         foreach ($value as $v) {
             if (!in_array($v->language, $validLanguages)) {
                 throw new Exception("Invalid language in localized fields");
             }
         }
         $data = array();
         foreach ($value as $field) {
             if (!$field instanceof Webservice_Data_Object_Element) {
                 throw new Exception("Invalid import data in field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]");
             }
             $fd = $this->getFielddefinition($field->name);
             if (!$fd instanceof Object_Class_Data) {
                 throw new Exception("Unknnown field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ] ");
             } else {
                 if ($fd->getFieldtype() != $field->type) {
                     throw new Exception("Type mismatch for field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]. Should be [ " . $fd->getFieldtype() . " ], but is [ " . $field->type . " ] ");
                 }
             }
             $data[$field->language][$field->name] = $this->getFielddefinition($field->name)->getFromWebserviceImport($field->value);
         }
         $localizedFields = new Object_Localizedfield($data);
         return $localizedFields;
     } else {
         if (!empty($value)) {
             throw new Exception("Invalid data in localized fields");
         } else {
             return null;
         }
     }
 }
Ejemplo n.º 12
0
<?php

// get db connection
$db = Pimcore_Resource::get();
$languages = Pimcore_Tool::getValidLanguages();
$list = new Object_Class_List();
$classes = $list->load();
if (!empty($classes)) {
    foreach ($classes as $class) {
        if ($class->getFielddefinition("localizedfields")) {
            $tableName = "object_localized_data_" . $class->getId();
            $cols = $db->fetchRow("SELECT * FROM " . $tableName . " LIMIT 1");
            if (is_array($cols)) {
                $cols = array_keys($cols);
                foreach ($cols as &$col) {
                    $col = $db->quoteIdentifier($col);
                }
                foreach ($languages as $language) {
                    $tableQueryName = "object_localized_query_" . $class->getId() . "_" . $language;
                    try {
                        $db->query("INSERT INTO " . $tableQueryName . " (" . implode(",", $cols) . ") SELECT * FROM " . $tableName . " WHERE language = '" . $language . "'");
                    } catch (\Exception $e) {
                        echo $e->getMessage() . "<br />";
                    }
                }
            }
        }
    }
}
Ejemplo n.º 13
0
 /**
  * Try to set the locale from different sources
  *
  * @param $locale
  * @return void
  */
 public function setLocale($locale = null)
 {
     if ($locale instanceof Zend_Locale) {
         $this->locale = $locale;
     } elseif (is_string($locale)) {
         $this->locale = new Zend_Locale($locale);
     } elseif ($this->getParam('locale') || $this->getParam('language')) {
         $this->setLocale($this->getParam('locale') ? $this->getParam('locale') : $this->getParam('language'));
     } else {
         $document = $this->getDocument();
         if ($document instanceof Document && $document->getProperty("language")) {
             $this->setLocale($document->getProperty("language"));
         }
         if (is_null($this->locale)) {
             //last chance -> get it from registry or use the first Language defined in the system settings
             if (Zend_Registry::isRegistered("Zend_Locale")) {
                 $this->locale = Zend_Registry::get("Zend_Locale");
             } else {
                 list($language) = Pimcore_Tool::getValidLanguages();
                 $this->locale = new Zend_Locale($language);
             }
         }
     }
 }
 private function reindex_documents(Document $document)
 {
     if (!$document instanceof Document_Page) {
         return;
     }
     $config = SphinxSearch_Config::getInstance();
     switch (SphinxSearch_Config_Plugin::getValue("indexer", "onchange")) {
         case "immediately":
             $documents_config = $config->getDocumentsAsArray();
             $languages = array("all");
             if ($this->config->documents->use_i18n == "true") {
                 $languages = Pimcore_Tool::getValidLanguages();
             }
             $controller = $document->getController();
             $action = $document->getAction();
             $template = $document->getTemplate();
             $config_name = $controller . "_" . $action;
             if ($template != "") {
                 $config_name . "_" . $template;
             }
             $indexes = array();
             foreach ($languages as $lang) {
                 foreach ($documents_config as $document_name => $document_properties) {
                     if ($config_name == $document_name) {
                         $indexes[] = "idx_document_" . $document_name . "_" . $lang;
                     }
                 }
             }
             if (sizeof($indexes) > 0) {
                 $indexes = implode(" ", $indexes);
                 $this->runIndexer($indexes);
             }
             break;
         case "reschedule":
             SphinxSearch_Config_Plugin::setValue("indexer", "lastrun", 0);
             break;
         default:
             // Do nothing
             break;
     }
 }
    public function writeSphinxConfig()
    {
        $pimcore_config = Pimcore_Config::getSystemConfig();
        $params = $pimcore_config->database->params;
        $db_host = $params->host;
        $db_user = $params->username;
        $db_password = $params->password;
        $db_name = $params->dbname;
        $db_port = $params->port;
        $index_path = SPHINX_VAR . DIRECTORY_SEPARATOR . "index";
        $cli_path = PIMCORE_PLUGINS_PATH . DIRECTORY_SEPARATOR . "SphinxSearch" . DIRECTORY_SEPARATOR . "cli";
        $pid_path = SphinxSearch_Config_Plugin::getValue("path", "pid");
        $logfile_path = SphinxSearch_Config_Plugin::getValue("path", "log");
        $querylog_path = SphinxSearch_Config_Plugin::getValue("path", "querylog");
        $port = SphinxSearch_Config_Plugin::getValue("searchd", "port");
        if (substr($pid_path, 0, 1) != DIRECTORY_SEPARATOR) {
            $pid_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $pid_path;
        }
        if (substr($logfile_path, 0, 1) != DIRECTORY_SEPARATOR) {
            $logfile_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $logfile_path;
        }
        if (substr($querylog_path, 0, 1) != DIRECTORY_SEPARATOR) {
            $querylog_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $querylog_path;
        }
        $config = <<<EOL

indexer
{
mem_limit = 32M
}

searchd
{
port = {$port}
log = {$logfile_path}
query_log = {$querylog_path}
read_timeout = 5
max_children = 30
pid_file = {$pid_path}
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}

EOL;
        $indexer = SphinxSearch_Config_Plugin::getValue("path", "phpcli") . " " . $cli_path . DIRECTORY_SEPARATOR . "index_documents.php";
        $documents_config = $this->getDocumentsAsArray();
        $languages = array("all");
        if (SphinxSearch_Config_Plugin::getValue("documents", "use_i18n") == "true") {
            $languages = Pimcore_Tool::getValidLanguages();
        }
        foreach ($languages as $lang) {
            foreach ($documents_config as $document_name => $document_properties) {
                $source_name = "document_" . $document_name . "_" . $lang;
                $index_name = "idx_document_" . $document_name . "_" . $lang;
                $document_index_path = $index_path . DIRECTORY_SEPARATOR . "document_" . $document_name . "_" . $lang;
                $config .= <<<EOL

source {$source_name} {
    type = xmlpipe2
    xmlpipe_command = {$indexer} -d {$document_name} -l {$lang}
}

index {$index_name} {
    source = {$source_name}
    path   = {$document_index_path}
    charset_type = utf-8
}

EOL;
            }
        }
        foreach ($this->getClasses()->children() as $class) {
            /**
             * @var $class SimpleXMLElement
             */
            $class_name = $class->getName();
            $object_class = Object_Class::getByName($class_name);
            $fields = array("oo_id", "o_creationDate", "o_modificationDate", "o_published", "o_type");
            $attributes = array("o_creationDate" => "sql_attr_timestamp", "o_modificationDate" => "sql_attr_timestamp", "o_published" => "sql_field_string", "o_type" => "sql_field_string");
            foreach ($class->children() as $field) {
                $fields[] = $field->attributes()->name;
                if ($field->attributes()->field_type) {
                    $attributes[$field->attributes()->name->__toString()] = $field->attributes()->field_type;
                }
            }
            $fields = "`" . implode("`,`", $fields) . "`";
            $attributes_definition = "";
            foreach ($attributes as $key => $value) {
                $attributes_definition .= "        {$value} = {$key}\n";
                // Yes, really $value first
            }
            // Do we have localized fields?
            if ($object_class->getFieldDefinition("localizedfields")) {
                $pimcore_languages = Pimcore_Tool::getValidLanguages();
                foreach ($pimcore_languages as $lang) {
                    $source_class_name = $class_name . "_" . $lang;
                    $table = "object_localized_" . $object_class->getId() . "_" . $lang;
                    $config .= <<<EOL
source {$source_class_name}
{
        type                    = mysql

        sql_host                = {$db_host}
        sql_user                = {$db_user}
        sql_pass                = {$db_password}
        sql_db                  = {$db_name}
        sql_port                = {$db_port}  # optional, default is 3306

        sql_query               = SELECT {$fields} FROM {$table}
        sql_query_info          = SELECT oo_id FROM {$table} WHERE oo_id=\$id
{$attributes_definition}
}

index idx_{$source_class_name}
{
        source                  = {$source_class_name}
        path                    = {$index_path}/{$source_class_name}
        docinfo                 = extern
        charset_type            = utf-8

        min_word_len            = 1
        min_prefix_len          = 0
        min_infix_len           = 1
}

EOL;
                }
            } else {
                $table = "object_" . $object_class->getId();
                $document_index_path = $index_path . DIRECTORY_SEPARATOR . $class_name;
                $config .= <<<EOL
source {$class_name}
{
        type                    = mysql

        sql_host                = {$db_host}
        sql_user                = {$db_user}
        sql_pass                = {$db_password}
        sql_db                  = {$db_name}
        sql_port                = {$db_port}  # optional, default is 3306

        sql_query               = SELECT {$fields} FROM {$table}
        sql_query_info          = SELECT oo_id FROM {$table} WHERE oo_id=\$id
{$attributes_definition}
}

index idx_{$class_name}
{
        source                  = {$class_name}
        path                    = {$document_index_path}
        docinfo                 = extern
        charset_type            = utf-8

        min_word_len            = 1
        min_prefix_len          = 0
        min_infix_len           = 1
}

EOL;
            }
        }
        if (is_dir(SPHINX_VAR . DIRECTORY_SEPARATOR . "sphinx.conf.d")) {
            foreach (glob(SPHINX_VAR . DIRECTORY_SEPARATOR . "sphinx.conf.d/*.conf") as $filename) {
                $config .= file_get_contents($filename);
            }
        }
        file_put_contents(SPHINX_VAR . DIRECTORY_SEPARATOR . "sphinx.conf", $config);
    }