public function setPathInfo($pathInfo = null) { parent::setPathInfo($pathInfo); $path = $this->_pathInfo; $paths = explode('/', trim($path, '/')); $language = !empty($paths[0]) ? $paths[0] : ''; if (in_array($language, Core_Model_Language::getLanguageCodes())) { $this->_language_code = $language; unset($paths[array_search($language, $paths)]); $paths = array_values($paths); } if (!$this->isInstalling()) { if (!empty($paths[0]) and $paths[0] == Application_Model_Application::OVERVIEW_PATH) { $this->_is_application = true; $this->_use_application_key = true; unset($paths[0]); } if (Application_Model_Application::getInstance()->getDomain() == $this->getHttpHost()) { $this->_is_application = true; $this->_use_application_key = false; } } $paths = array_diff($paths, Core_Model_Language::getLanguageCodes()); $paths = array_values($paths); $this->_pathInfo = '/' . implode('/', $paths); return $this; }
protected function _prepareFiles() { $links = glob($this->_dst . '/src/com/' . $this->_formatted_bundle_name . '/' . $this->_formatted_name . '/*'); $url = $this->getUrl(); if (!$links) { return $this; } $links = array_merge(array($this->_dst . '/AndroidManifest.xml'), $links); foreach ($links as $link) { if (!is_dir($link)) { $this->__replace(array('siberian.app' => $this->_formatted_bundle_name . '.' . $this->_formatted_name), $link); if (strpos($link, 'CommonUtilities.java') !== false) { $this->__replace(array('String SENDER_ID = ""' => 'String SENDER_ID = "' . Push_Model_Certificat::getAndroidSenderId() . '"', 'SERVEUR_URL = "http://www.siberiancms.com/";' => 'SERVEUR_URL = "' . $this->getUrl() . '";'), $link); } } } $name = str_replace(array('&', '/'), 'AND', $this->getApplication()->getName()); $this->__replace(array('<name>Siberian</name>' => '<name>' . $name . '</name>'), $this->_dst . '/.project'); $replacements = array('http://app.siberiancms.com' => $this->getApplication()->getUrl(null, array(), false, 'en'), '<string name="app_name">Siberian</string>' => '<string name="app_name">' . $name . '</string>'); $this->__replace($replacements, $this->_dst . '/res/values/strings.xml'); foreach (Core_Model_Language::getLanguageCodes() as $lang) { if ($lang != 'en') { $replacements = array('http://app.siberiancms.com' => $this->getApplication()->getUrl(null, array(), false, $lang), '<string name="app_name">Siberian</string>' => '<string name="app_name">' . $name . '</string>'); $this->__replace($replacements, $this->_dst . '/res/values-' . $lang . '/strings.xml'); } } return $this; }
public static function create($url = '', array $params = array(), $locale = null) { $request = Zend_Controller_Front::getInstance()->getRequest(); if ($request->getParam('overview') and !in_array('overview', array_values($params))) { $params['overview'] = 1; } $exclude = array(); $setLocale = false; $encode = false; if (!empty($params['encode'])) { $encode = true; unset($params['encode']); } if (!is_null($locale) and in_array($locale, Core_Model_Language::getLanguageCodes())) { $request->addLanguageCode($locale); } $url = str_replace($request->getBaseUrl(), '', $url); $url = trim($url, '/'); $url = explode('/', $url); $url = array_diff($url, $exclude); $count = count($url); if ($count == 0) { $url = array_fill(0, 3, ''); } while ($count > 0 && $count++ < 3) { $url[] = 'index'; } $url = array_values($url); $url = array('module' => $url[0], 'controller' => $url[1], 'action' => $url[2]); if (!empty($params)) { if (!empty($params['module'])) { unset($params['module']); } if (!empty($params['controller'])) { unset($params['controller']); } if (!empty($params['action'])) { unset($params['action']); } $url = array_merge($url, $params); } $reset = empty($params['keep_params']); $router = Zend_Controller_Front::getInstance()->getRouter(); $url = $router->assemble($url, 'default', $reset, false); $request->setLanguageCode(null); return $url; }
public function findAction() { $data = $data_csv = $data_all = array(); if ($lang_id = $this->getRequest()->getParam("lang_id")) { $lang_id = base64_decode($lang_id); $lang_id = explode("_", strtolower($lang_id)); if (count($lang_id) == 2) { $lang_id[1] = strtoupper($lang_id[1]); } $lang_id = implode("_", $lang_id); $data["section_title"] = $this->_("Edit the language: %s", Core_Model_Language::getLanguage($lang_id)->getName()); $data["is_edit"] = true; } else { $data["section_title"] = $this->_("Create a new language"); $data["is_edit"] = false; } $data["country_code"] = $lang_id; $locale = Zend_Registry::get("Zend_Locale"); $languages = $locale->getTranslationList('language'); $existing_languages = Core_Model_Language::getLanguageCodes(); foreach ($languages as $k => $language) { if (!$locale->isLocale($k) or in_array($k, $existing_languages)) { unset($languages[$k]); } } asort($languages, SORT_LOCALE_STRING); $data["country_codes"] = $languages; $data_csv = $this->_parseCsv($lang_id); $data_xml = $this->_parseXml($lang_id); $data_all["translation_files"] = array_merge($data_csv["translation_files"], $data_xml["translation_files"]); $data_all["translation_files_data"] = array_merge($data_csv["translation_files_data"], $data_xml["translation_files_data"]); ksort($data_all["translation_files"]); $data["translation_files"] = $data_all["translation_files"]; ksort($data_all["translation_files_data"]); $data["translation_files_data"] = $data_all["translation_files_data"]; $data["info"] = array_merge($data_csv["info"], $data_xml["info"]); $this->_sendHtml($data); }
public function setPathInfo($pathInfo = null) { parent::setPathInfo($pathInfo); $path = $this->_pathInfo; $paths = explode('/', trim($path, '/')); $language = !empty($paths[0]) ? $paths[0] : ''; if (in_array($language, Core_Model_Language::getLanguageCodes())) { $this->_language_code = $language; unset($paths[0]); $paths = array_values($paths); } if (!$this->isInstalling()) { $paths = $this->_initApplication($paths); if (!$this->isApplication()) { $this->_initWhiteLabelEditor(); } } // $paths = array_diff($paths, Core_Model_Language::getLanguageCodes()); $paths = array_values($paths); $this->_pathInfo = '/' . implode('/', $paths); $detector = new Mobile_Detect(); $this->_is_native = $detector->isNative(); return $this; }
protected function _changeData() { // Créé les variables et ouvre le fichier $file = $this->_dst . '/Application/Objects/url.m'; $newContent = ''; $common = @fopen($file, 'r+'); if (!$common) { throw new Exception('An error occured while processing the file ' . $file); } if (!($uri = parse_url($this->getApplication()->getUrl()))) { throw new Exception("An error occured while parsing the application's URL. Please check the URL and try again."); } if (empty($uri['scheme']) or empty($uri['host'])) { throw new Exception($this->_("An error occured while parsing the application's URL. Please check the URL and try again.")); } $scheme = $uri['scheme']; $domain = $uri['host']; $path = ltrim(str_replace(Core_Model_Language::getLanguageCodes(), '', $uri['path']), '/'); while ($data = fgets($common, 1024)) { if (stripos($data, 'scheme = @"') !== false) { $newContent .= ' scheme = @"' . $scheme . '"; '; } else { if (stripos($data, 'domain = @"') !== false) { $newContent .= ' domain = @"' . $domain . '"; '; } else { if (stripos($data, 'path = @"') !== false) { $newContent .= ' path = @"' . $path . '"; '; } else { $newContent .= $data; } } } } fclose($common); // Met à jour le contenu du fichier $common = @fopen($file, 'w'); fputs($common, $newContent); fclose($common); // Met à jour le contenu du fichier $common = @fopen($file, 'w'); fputs($common, $newContent); fclose($common); }
protected function _initLanguage() { $available_languages = Core_Model_Language::getLanguageCodes(); $current_language = in_array($this->_request->getLanguageCode(), $available_languages) ? $this->_request->getLanguageCode() : ''; $language_session = Core_Model_Language::getSession(); $language = ''; if ($language_session) { $language = $language_session->current_language; } if (!empty($current_language)) { Core_Model_Language::setCurrentLanguage($current_language); } else { if (!empty($language)) { // $this->_request->setLanguageCode($language); } else { if ($accepted_languages = Zend_Locale::getBrowser()) { $accepted_languages = array_keys($accepted_languages); // $accepted_languages = preg_split('/(,)|(;)|(-)|(=)/', $accepted_languages); foreach ($accepted_languages as $lang) { if (in_array($lang, $available_languages)) { $current_language = $lang; break; } } if (!$current_language) { $current_language = Core_Model_Language::getDefaultLanguage(); } Core_Model_Language::setCurrentLanguage($current_language); } } } }
protected function _initLanguage() { $available_languages = Core_Model_Language::getLanguageCodes(); $current_language = in_array($this->getRequest()->getLanguageCode(), $available_languages) ? $this->getRequest()->getLanguageCode() : ""; $language_session = Core_Model_Language::getSession(); $language = ''; if (!$this->getRequest()->isApplication()) { if ($language_session->current_language) { $language = $language_session->current_language; } else { if (!$this->getRequest()->isInstalling()) { $current_language = System_Model_Config::getValueFor("system_default_language"); } } } else { $language = $language_session->current_language; } if (!empty($current_language)) { Core_Model_Language::setCurrentLanguage($current_language); } else { if (!empty($language)) { } else { if ($accepted_languages = Zend_Locale::getBrowser()) { $accepted_languages = array_keys($accepted_languages); foreach ($accepted_languages as $lang) { if (in_array($lang, $available_languages)) { $current_language = $lang; break; } } if (!$current_language) { $current_language = Core_Model_Language::getDefaultLanguage(); } Core_Model_Language::setCurrentLanguage($current_language); } else { Core_Model_Language::setCurrentLanguage(Core_Model_Language::getDefaultLanguage()); } } } }
public function languagesAction() { $this->getLayout()->setHtml(implode(",", Core_Model_Language::getLanguageCodes())); }
protected function _prepareFiles() { // $source = $this->_sources_dst.'/java/com/'.$this->_formatted_bundle_name.'/'.$this->_folder_name; $source = $this->_sources_dst . '/java/' . str_replace(".", "/", $this->_package_name); $links = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, 4096), RecursiveIteratorIterator::SELF_FIRST); $allowed_extensions = array("java", "xml"); if (!$links) { return $this; } foreach ($links as $link) { if (!$link->isDir()) { $info = pathinfo($link->getPathName()); $extension = $info["extension"]; if (in_array($extension, $allowed_extensions)) { if (strpos($link, 'CommonUtilities.java') !== false) { $this->__replace(array('String SENDER_ID = ""' => 'String SENDER_ID = "' . Push_Model_Certificate::getAndroidSenderId() . '"', 'String APP_ID = ""' => 'String APP_ID = "' . $this->getApplication()->getId() . '"', 'SERVEUR_URL = "http://base.appsmobilecompany.com/";' => 'SERVEUR_URL = "' . $this->getUrl() . '";'), $link); } } } } $replacements = array('com.appsmobilecompany.base' => $this->_package_name, '[ENCRYPT_KEY]' => $this->getDevice()->getKeyPass()); $source = $this->_dst; $links = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, 4096), RecursiveIteratorIterator::SELF_FIRST); foreach ($links as $link) { if ($link->isDir()) { continue; } $this->__replace($replacements, $link->getRealPath()); } $this->__replace($replacements, $this->_sources_dst . '/AndroidManifest.xml'); $this->__replace($replacements, $this->_sources_dst . '/../../build.gradle'); $name = str_replace("'", "\\'", $this->getApplication()->getName()); // Retrieve the available languages $languages = Core_Model_Language::getLanguageCodes(); // Check if all the available languages exist in the Android source foreach ($languages as $lang) { if ($lang == "en") { continue; } if (stripos($lang, "_") !== false) { $lang = explode("_", $lang); if (count($lang) == 2) { $lang[1] = "r" . $lang[1]; } $lang = implode("-", $lang); } // If not, create them out of the English one. if (!file_exists($this->_sources_dst . '/res/values-' . $lang . '/strings.xml')) { mkdir($this->_sources_dst . '/res/values-' . $lang, 0777); copy($this->_sources_dst . '/res/values/strings.xml', $this->_sources_dst . '/res/values-' . $lang . '/strings.xml'); } } $replacements = array('http://localhost/overview' => $this->getApplication()->getUrl(null, array(), 'en', false), '<string name="app_name">Apps Mobile Company</string>' => '<string name="app_name"><![CDATA[' . $name . ']]></string>'); $this->__replace($replacements, $this->_sources_dst . '/res/values/strings.xml'); if ($fbk_app_id = $this->getApplication()->getFacebookId()) { $replacements_sharing = array('<!-- FACEBOOK -->' => '<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>'); if ($this->getApplication()->getData("facebook_id")) { $replacements_sharing['<!-- FACEBOOK PROVIDER -->'] = '<provider android:authorities="com.facebook.app.FacebookContentProvider' . $fbk_app_id . '" android:name="com.facebook.FacebookContentProvider" android:exported="true" />'; } $replacements_sharing_ids = array('[FACEBOOK_APP_ID]' => $fbk_app_id); $this->__replace($replacements_sharing_ids, $this->_sources_dst . '/res/values/sharings_id.xml'); $this->__replace($replacements_sharing, $this->_sources_dst . '/AndroidManifest.xml'); } foreach ($languages as $lang) { if ($lang == "en") { continue; } if (stripos($lang, "_") !== false) { $android_lang = explode("_", $lang); if (count($android_lang) == 2) { $android_lang[1] = "r" . $android_lang[1]; } $android_lang = implode("-", $android_lang); } else { $android_lang = $lang; } $replacements = array('http://localhost/overview' => $this->getApplication()->getUrl(null, array(), $lang, false), '<string name="app_name">SiberianCMS</string>' => '<string name="app_name"><![CDATA[' . $name . ']]></string>', '<string name="app_name">Apps Mobile Company</string>' => '<string name="app_name"><![CDATA[' . $name . ']]></string>'); $this->__replace($replacements, $this->_sources_dst . "/res/values-{$android_lang}/strings.xml"); } if (file_exists($this->_sources_dst . '/res/values-fr/strings.xml')) { $this->__replace($replacements, $this->_sources_dst . '/res/values-fr/strings.xml'); } $version = explode(".", $this->getDevice()->getVersion()); $version_code = !empty($version[0]) ? $version[0] : 1; $version_name = !empty($version[0]) && !empty($version[1]) ? $version[0] . "." . $version[1] : "1.0"; if ($version_code != 1 || $version_name != "1.0") { $replacements = array("versionCode 1" => "versionCode {$version_code}", 'versionName "1.0"' => 'versionName "' . $version_name . '"'); $this->__replace($replacements, $this->_sources_dst . "/../../build.gradle"); $this->__replace($replacements, $this->_sources_dst . "/../../build.gradle.save"); } return $this; }