Esempio n. 1
0
 /**
  * Checks if this query is qualified for translation and parses query
  *
  * @param   string  $sql     SQL query
  * @param   string  $prefix  Table prefix
  *
  * @return  mixed  Parsed query with added table joins and fields if found
  */
 public static function buildTranslationQuery($sql = '', $prefix = '')
 {
     $db = JFactory::getDbo();
     $selectedLanguage = !empty($db->forceLanguageTranslation) ? $db->forceLanguageTranslation : JFactory::getLanguage()->getTag();
     if (!empty($db->parseTablesBefore)) {
         foreach ($db->parseTablesBefore as $tableGroup) {
             $sql = self::parseSelectQuery($sql, $prefix, $tableGroup->language, $tableGroup->translationTables);
         }
     }
     /**
      * Basic check for translations, translation will not be inserted if:
      * If we do not have SELECT anywhere in query
      * If current language is site default language
      * If we are in administration
      */
     if (empty($sql) || JFactory::getApplication()->isAdmin() || !stristr(mb_strtolower($sql), 'select') || RTranslationHelper::getSiteLanguage() == $selectedLanguage) {
         if (empty($db->parseTablesBefore) && empty($db->parseTablesAfter)) {
             return null;
         }
     }
     $translationTables = RTranslationHelper::getInstalledTranslationTables();
     $translationTables = RTranslationHelper::removeFromEditForm($translationTables);
     $sql = self::parseSelectQuery($sql, $prefix, $selectedLanguage, $translationTables);
     if (!empty($db->parseTablesAfter)) {
         foreach ($db->parseTablesAfter as $tableGroup) {
             $sql = self::parseSelectQuery($sql, $prefix, $tableGroup->language, $tableGroup->translationTables);
         }
     }
     return $sql;
 }