[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Language/ -> Multilanguage.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Language;
  11  
  12  use Joomla\CMS\Application\CMSApplication;
  13  use Joomla\CMS\Factory;
  14  use Joomla\Database\DatabaseInterface;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('JPATH_PLATFORM') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Utility class for multilang
  22   *
  23   * @since  2.5.4
  24   */
  25  class Multilanguage
  26  {
  27      /**
  28       * Flag indicating multilanguage functionality is enabled.
  29       *
  30       * @var    boolean
  31       * @since  4.0.0
  32       */
  33      public static $enabled = false;
  34  
  35      /**
  36       * Method to determine if the language filter plugin is enabled.
  37       * This works for both site and administrator.
  38       *
  39       * @param   CMSApplication     $app  The application
  40       * @param   DatabaseInterface  $db   The database
  41       *
  42       * @return  boolean  True if site is supporting multiple languages; false otherwise.
  43       *
  44       * @since   2.5.4
  45       */
  46      public static function isEnabled(CMSApplication $app = null, DatabaseInterface $db = null)
  47      {
  48          // Flag to avoid doing multiple database queries.
  49          static $tested = false;
  50  
  51          // Do not proceed with testing if the flag is true
  52          if (static::$enabled) {
  53              return true;
  54          }
  55  
  56          // Get application object.
  57          $app = $app ?: Factory::getApplication();
  58  
  59          // If being called from the frontend, we can avoid the database query.
  60          if ($app->isClient('site')) {
  61              static::$enabled = $app->getLanguageFilter();
  62  
  63              return static::$enabled;
  64          }
  65  
  66          // If already tested, don't test again.
  67          if (!$tested) {
  68              // Determine status of language filter plugin.
  69              $db    = $db ?: Factory::getDbo();
  70              $query = $db->getQuery(true)
  71                  ->select($db->quoteName('enabled'))
  72                  ->from($db->quoteName('#__extensions'))
  73                  ->where(
  74                      [
  75                          $db->quoteName('type') . ' = ' . $db->quote('plugin'),
  76                          $db->quoteName('folder') . ' = ' . $db->quote('system'),
  77                          $db->quoteName('element') . ' = ' . $db->quote('languagefilter'),
  78                      ]
  79                  );
  80              $db->setQuery($query);
  81  
  82              static::$enabled = (bool) $db->loadResult();
  83              $tested = true;
  84          }
  85  
  86          return static::$enabled;
  87      }
  88  
  89      /**
  90       * Method to return a list of language home page menu items.
  91       *
  92       * @param   DatabaseInterface  $db  The database
  93       *
  94       * @return  array of menu objects.
  95       *
  96       * @since   3.5
  97       */
  98      public static function getSiteHomePages(DatabaseInterface $db = null)
  99      {
 100          // To avoid doing duplicate database queries.
 101          static $multilangSiteHomePages = null;
 102  
 103          if (!isset($multilangSiteHomePages)) {
 104              // Check for Home pages languages.
 105              $db    = $db ?: Factory::getDbo();
 106              $query = $db->getQuery(true)
 107                  ->select(
 108                      [
 109                          $db->quoteName('language'),
 110                          $db->quoteName('id'),
 111                      ]
 112                  )
 113                  ->from($db->quoteName('#__menu'))
 114                  ->where(
 115                      [
 116                          $db->quoteName('home') . ' = ' . $db->quote('1'),
 117                          $db->quoteName('published') . ' = 1',
 118                          $db->quoteName('client_id') . ' = 0',
 119                      ]
 120                  );
 121              $db->setQuery($query);
 122  
 123              $multilangSiteHomePages = $db->loadObjectList('language');
 124          }
 125  
 126          return $multilangSiteHomePages;
 127      }
 128  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer