/** * @throws Exception */ public function languageDetectionAction() { // Get the browser language $locale = new Zend_Locale(); $browserLanguage = $locale->getLanguage(); $languages = Tool::getValidLanguages(); // Check if the browser language is a valid frontend language if (in_array($browserLanguage, $languages)) { $language = $browserLanguage; } else { // If it is not, take the first frontend language as default $language = reset($languages); } // Get the folder of the current language (in the current site) $currentSitePath = $this->document->getRealFullPath(); $folder = Document\Page::getByPath($currentSitePath . '/' . $language); if ($folder) { $document = $this->findFirstDocumentByParentId($folder->getId()); if ($document) { $this->redirect($document->getPath() . $document->getKey()); } else { throw new Exception('No document found in your browser language'); } } else { throw new Exception('No language folder found that matches your browser language'); } }
/** * @return bool */ public static function createTables() { $result = true; if (self::checkTables()) { return true; } try { $db = PluginLib\AbstractPlugin::getDb(); // Create table $db->query("CREATE TABLE `" . self::$_tableName . "` (\n\t\t\t\t\t\t\t\t `document_id` BIGINT(20) NOT NULL,\n\t\t\t\t\t\t\t\t `language` VARCHAR(2) DEFAULT NULL,\n\t\t\t\t\t\t\t\t `sourcePath` VARCHAR(255) DEFAULT NULL,\n\t\t\t\t\t\t\t\t PRIMARY KEY (`document_id`)\n\t\t\t\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n\t\t\t\t\t\t\t"); $languages = Tool::getValidLanguages(); // Get list of sites $siteList = new \Pimcore\Model\Site\Listing(); $sites = $siteList->load(); if ($languages && count($languages) >= 1) { $primaryLanguage = $languages[0]; foreach ($languages as $language) { $rootIds = array(); if ($sites) { // Multisite website, add language folders for all subsites /** * @var $site Site */ foreach ($sites as $site) { $rootIds[] = $site->getRootId(); } } else { // No sites; just use the primary root $rootIds[] = 1; } foreach ($rootIds as $rootId) { $rootDocument = Document::getById($rootId); if ($rootDocument->getKey() == '') { $sourcePath = $rootDocument->getRealFullPath() . $primaryLanguage; } else { $sourcePath = $rootDocument->getRealFullPath() . '/' . $primaryLanguage; } if ($rootDocument->getKey() == '') { $rootPath = $rootDocument->getRealFullPath() . $language; } else { $rootPath = $rootDocument->getRealFullPath() . '/' . $language; } $folder = Document\Page::getByPath($rootPath); if (!$folder) { $folder = Document\Page::create($rootId, array('key' => $language, "userOwner" => 1, "userModification" => 1, "published" => true, "module" => "Multilingual", "controller" => 'default', "action" => 'go-to-first-child')); } // Also set the language property for the document $folder->setProperty('language', 'text', $language); $folder->setProperty('isLanguageRoot', 'text', 1, false, false); $folder->save(); // Create enty in plugin table, so basic link is provided $sql = "INSERT INTO " . self::$_tableName . "(document_id,language,sourcePath) VALUES(\n\t\t\t\t\t'" . $folder->getId() . "',\n\t\t\t\t\t'" . $language . "',\n\t\t\t\t\t'" . $sourcePath . "')"; $db->query($sql); } } } } catch (Exception $e) { $result = false; Logger::error("Failed to create tables: " . $e->getMessage()); } return $result; }
private function createEmailDocuments() { try { $email = Email::getByPath(self::DOCUMENT_EMAIL_CONFIRMATION_PATH); if (!is_object($email)) { $email = new Email(); $email->setParent(Page::getByPath(dirname(self::DOCUMENT_EMAIL_CONFIRMATION_PATH))); $email->setKey(basename(self::DOCUMENT_EMAIL_CONFIRMATION_PATH)); $email->setModule(self::CLASS_PARTICIPATION_NAME); $email->setController('Email'); $email->setAction('confirmation'); $email->setSubject(self::EMAIL_CONFIRMATION_SUBJECT_DEFAULT); $email->save(); } } catch (\Exception $exception) { throw new \Exception('Unable to create email document page [' . Plugin::DOCUMENT_EMAIL_CONFIRMATION_PATH . ']: ' . $exception->getMessage()); } }