コード例 #1
0
ファイル: Taxonomy.php プロジェクト: francoisfaubert/strata
 /**
  * Returns the complete taxonomy query var variable
  */
 public function getQueryVar()
 {
     $wordpressKey = $this->getWordpressKey();
     $generatedQueryVar = Strata::config("runtime.taxonomy.query_vars.{$wordpressKey}");
     if (!is_null($generatedQueryVar)) {
         return $generatedQueryVar;
     }
     return $wordpressKey;
 }
コード例 #2
0
 /**
  * Registers the plugin and saved the context in which
  * the plugin will run.
  */
 public function addFilters()
 {
     register_activation_hook(Strata::config('runtime.polyglot.loaderPath'), function () {
         $query = new Query();
         $query->createTable();
     });
     $polyglot = new Polyglot();
     // We need to rehook into setCurrentLocaleByContext because we need to
     // try again once global post objects are loaded.
     add_action(is_admin() ? 'admin_init' : 'wp', array($polyglot, "setCurrentLocaleByContext"), 3);
     is_admin() ? AdminAdaptor::addFilters() : FrontAdaptor::addFilters();
     CommonAdaptor::addFilters();
     WidgetAdaptor::addFilters();
 }
コード例 #3
0
 private function taxonomyWasLocalizedInStrata($wordpressKey)
 {
     return !is_null(Strata::config("runtime.taxonomy.query_vars.{$wordpressKey}"));
 }
コード例 #4
0
 public function shouldFallbackToDefaultLocale()
 {
     return (bool) Strata::config("i18n.default_locale_fallback");
 }
コード例 #5
0
 /**
  * Generates the template file path base directory.
  * @return string
  */
 protected function getTemplatePath()
 {
     $dirname = dirname(Strata::config('runtime.polyglot.loaderPath'));
     $paths = array($dirname, 'src', 'Admin', 'View');
     return implode(DIRECTORY_SEPARATOR, $paths) . DIRECTORY_SEPARATOR;
 }
コード例 #6
0
 private function generateTaxonomyTags($taxonomy)
 {
     $shouldFallback = (bool) Strata::config("i18n.default_locale_fallback");
     $defaultLocale = Strata::i18n()->getDefaultLocale();
     $currentLocale = Strata::i18n()->getCurrentLocale();
     $permalinkManager = new TermPermalinkManager();
     $currentPermalink = get_term_link($taxonomy, $taxonomy->taxonomy);
     // Keep the default url handy
     $defaultFallbackUrl = "";
     if ($shouldFallback) {
         $permalinkManager->enforceLocale($defaultLocale);
         $defaultFallbackUrl = $permalinkManager->generatePermalink($currentPermalink, $taxonomy, $taxonomy->taxonomy);
     }
     foreach (Strata::i18n()->getLocales() as $locale) {
         $permalinkManager->enforceLocale($locale);
         try {
             $localizedUrl = $permalinkManager->generatePermalink($currentPermalink, $taxonomy, $taxonomy->taxonomy);
             $destinationIsTheSame = $localizedUrl === $currentPermalink;
             $isNotDefaultButIsNotTheCurrent = !$locale->isDefault() && $locale->getCode() !== $currentLocale->getCode();
             if ($isNotDefaultButIsNotTheCurrent && $destinationIsTheSame && $shouldFallback) {
                 $this->alternates[] = sprintf('<link rel="alternate" hreflang="%s" href="%s">', $locale->getCode(), $defaultFallbackUrl);
                 $this->canonicals[] = sprintf('<link rel="canonical" href="%s">', $defaultFallbackUrl);
             } else {
                 $this->alternates[] = sprintf('<link rel="alternate" hreflang="%s" href="%s">', $locale->getCode(), $localizedUrl);
             }
         } catch (Exception $e) {
         }
     }
 }
コード例 #7
0
ファイル: I18n.php プロジェクト: francoisfaubert/strata
 /**
  * Goes through the list of localization configurations values in Strata's
  * configuration file.
  * @return array A list of instantiated Locale object.
  */
 protected function parseLocalesFromConfig()
 {
     $localeInfos = Hash::normalize((array) Strata::config("i18n.locales"));
     $locales = array();
     foreach ($localeInfos as $key => $config) {
         $locales[$key] = new Locale($key, $config);
     }
     return $locales;
 }
コード例 #8
0
 protected function getPluginLocalePath()
 {
     return dirname(Strata::config('runtime.polyglot.loaderPath')) . DIRECTORY_SEPARATOR . 'locale';
 }