コード例 #1
0
ファイル: item.php プロジェクト: thumbs-up-sign/TuVanDuAn
 public function getItem($pk = null)
 {
     $input = JFactory::getApplication()->input;
     $id = $input->getInt('id');
     if (!$id) {
         return false;
     }
     $adapter = JalangHelper::getHelperContent();
     if (!$adapter) {
         return false;
     }
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('*')->from('#__' . $adapter->table)->where($db->quoteName($adapter->primarykey) . '=' . $id);
     $db->setQuery($query);
     $row = $db->loadObject();
     //get reference value
     if (count($adapter->reference_fields)) {
         foreach ($adapter->reference_fields as $field => $table) {
             $adapter2 = JalangHelperContent::getInstance($table);
             if ($adapter2) {
                 $query = $db->getQuery(true);
                 $query->select('*')->from('#__' . $adapter2->table)->where($db->quoteName($adapter2->primarykey) . '=' . $row->{$field});
                 $db->setQuery($query);
                 $row2 = $db->loadObject();
                 if ($row2) {
                     $row->{$field . '_ref'} = $row2->{$adapter2->title_field};
                 }
             }
         }
     }
     return $row;
 }
コード例 #2
0
ファイル: modules.php プロジェクト: thumbs-up-sign/TuVanDuAn
 public function beforeSave(&$translator, $sourceid, &$row)
 {
     //Update module settings depend on module type
     $module = $row['module'];
     $adapter = JalangHelperContent::getInstance('categories');
     if ($adapter) {
         $translator->loadAssociate($adapter->table, $adapter->primarykey, $adapter->associate_context);
     }
     $params = json_decode($row['params']);
     if ($module == 'mod_custom') {
         //do nothing since content had been translated
     } elseif ($module == 'mod_menu') {
         if ($params->menutype) {
             $params->menutype = $this->getNewAlias($params->menutype, $translator->fromLangTag, $translator->toLangTag, null, 'alias', false);
         }
     } elseif ($module == 'mod_related_items') {
         //do nothing
     } elseif ($module == 'mod_articles_archive') {
         //do nothing
     } elseif ($module == 'mod_articles_categories') {
         $params->parent = $translator->getAssociatedItem('categories', $params->parent, $params->parent);
     }
     // update category ids
     $cats = array('catid', 'catsid', 'display_model-modcats-category', 'category', 'featured_categories', 'list_categories');
     /**
      * @todo whenever new component is added to translation list
      * it requires to update below code snippet to get correct category id for that component's items
      */
     if (strpos($module, 'k2') !== false) {
         $tableCategory = 'k2_categories';
     } elseif (strpos($module, 'virtuemart') !== false) {
         $tableCategory = 'virtuemart_categories';
     } else {
         $tableCategory = 'categories';
     }
     if ($module == 'mod_ja_acm') {
         if (isset($params->{"jatools-config"})) {
             $config = json_decode($params->{"jatools-config"});
             $pattern = "/^[a-z0-9\\-]+\\[(" . implode('|', $cats) . ")\\]/i";
             foreach ($config as $property => $value) {
                 if (is_object($value)) {
                     foreach ($value as $field => $fvalue) {
                         if (preg_match($pattern, $field)) {
                             if (!is_array($fvalue)) {
                                 $cid = $fvalue;
                                 $value->{$field} = $translator->getAssociatedItem($tableCategory, $cid, $cid);
                             } else {
                                 $catid = array();
                                 foreach ($fvalue as $cid) {
                                     $catid[] = $translator->getAssociatedItem($tableCategory, $cid, $cid);
                                 }
                                 $value->{$field} = $catid;
                             }
                         }
                     }
                     $config->{$property} = $value;
                 }
             }
             $params->{"jatools-config"} = json_encode($config);
         }
     } else {
         foreach ($cats as $cat) {
             if (isset($params->{$cat})) {
                 if (is_array($params->{$cat}) && count($params->{$cat})) {
                     $catid = array();
                     foreach ($params->{$cat} as $cid) {
                         $catid[] = $translator->getAssociatedItem($tableCategory, $cid, $cid);
                     }
                     $params->{$cat} = $catid;
                 } else {
                     if (is_numeric($params->{$cat})) {
                         $cid = $params->{$cat};
                         $params->{$cat} = $translator->getAssociatedItem($tableCategory, $cid, $cid);
                     }
                 }
             }
         }
     }
     $row['params'] = json_encode($params);
 }
コード例 #3
0
ファイル: tool.php プロジェクト: thumbs-up-sign/TuVanDuAn
 public final function removeLanguage($languageTag)
 {
     if (!$languageTag || $languageTag == '*') {
         $this->sendOutput(JText::_('SOURCE_LANGUAGE_IS_NOT_SPECIFIED_OR_NOT_SUPPORTED'));
         return false;
     }
     if ($languageTag == JalangHelper::getDefaultLanguage()) {
         $this->sendOutput(JText::_('ALERT_CANNOT_REMOVE_DEFAULT_LANGUAGE'));
         return false;
     }
     $langId = JalangHelper::getLanguageIdFromCode($languageTag);
     $parts = explode('-', $languageTag);
     $langCode = strtolower(trim($parts[0]));
     $adapters = JalangHelperContent::getListAdapters();
     $db = JFactory::getDbo();
     foreach ($adapters as $adapter) {
         $component = $adapter['title'];
         $adapter = JalangHelperContent::getInstance($adapter['name']);
         $table = '#__' . $adapter->table;
         $this->sendOutput('<h3>' . JText::sprintf('START_TO_REMOVE_ITEM_FROM_THE_COMPONENT', $component) . '</h3>');
         if ($adapter->table_type == 'native' || $adapter->table_type == 'table_ml') {
             if (!$adapter->language_field) {
                 continue;
             }
             if ($adapter->language_mode == 'id') {
                 $where = $db->quoteName($adapter->language_field) . '=' . $db->quote($langId);
             } else {
                 $where = $db->quoteName($adapter->language_field) . '=' . $db->quote($languageTag);
             }
             if ($adapter->table_type == 'native') {
                 //delete association data
                 $query = "DELETE FROM #__associations\r\n\t\t\t\t\t\tWHERE id IN (\r\n\t\t\t\t\t\t\tSELECT " . $db->quote($adapter->primarykey) . "\r\n\t\t\t\t\t\t\tFROM " . $table . "\r\n\t\t\t\t\t\t\tWHERE `context` = " . $db->quote($adapter->associate_context) . "\r\n\t\t\t\t\t\t\tAND " . $where . "\r\n\t\t\t\t\t\t)";
                 $db->setQuery($query);
                 $db->execute();
             }
             //delete items
             $query = $db->getQuery(true);
             $query->delete($table);
             $query->where($where);
             $db->setQuery($query);
             $db->execute();
             $num_items = $db->getAffectedRows();
             $this->sendOutput(JText::sprintf('NUM_ITEMS_ARE_REMOVED', $num_items) . '<br />');
         } elseif ($adapter->table_type == 'alias') {
             $query = $db->getQuery(true);
             $query->delete($table);
             $query->where($db->quoteName($adapter->alias_field) . ' LIKE ' . $db->quote('%-' . $langCode));
             $db->setQuery($query);
             $db->execute();
             $num_items = $db->getAffectedRows();
             $this->sendOutput(JText::sprintf('NUM_ITEMS_ARE_REMOVED', $num_items) . '<br />');
         } elseif ($adapter->table_type == 'table') {
             $tableml = $this->getLangTable($table, $languageTag);
             $query = "DROP TABLE " . $db->quoteName($tableml);
             $db->setQuery($query);
             $db->execute();
             $this->sendOutput(JText::sprintf('DROP_THE_LANGUAGE_TABLE', $tableml) . '<br />');
         }
     }
     //remove content language?
 }
コード例 #4
0
ファイル: movelang.php プロジェクト: thumbs-up-sign/TuVanDuAn
echo JText::_('WHICH_COMPONENT_WILL_BEING_MOVED_ITEMS');
?>
						<a href="#" onclick="jQuery('#component-list').toggle(300);" title="<?php 
echo JText::_('JHIDE');
?>
"><?php 
echo JText::_('JHIDE');
?>
</a>
						<div id="component-list" style="">
							<ol>
								<?php 
foreach ($this->adapters as $itemtype => $props) {
    ?>
									<?php 
    $adapter = JalangHelperContent::getInstance($props['name']);
    if (!$adapter || $adapter->table_type != 'native') {
        continue;
    }
    ?>
									<li><?php 
    echo $props['title'];
    ?>
</li>
								<?php 
}
?>
							</ol>
						</div>
					</td>
				</tr>
コード例 #5
0
 public function loadAssociate($table, $id = 'id', $context, $reload = false, $filter = array())
 {
     $defaultLanguage = JalangHelper::getDefaultLanguage();
     if ($this->fromLangTag == '*' && $this->convertLangTag) {
         $fromLangTag = $this->convertLangTag;
     } else {
         $fromLangTag = $this->fromLangTag;
     }
     $adapter = JalangHelperContent::getInstance($table);
     if ($adapter->table_type == 'table') {
         $this->createLangTable('#__' . $table, $fromLangTag);
         $this->createLangTable('#__' . $table, $this->toLangTag);
     }
     if (!isset($this->aAssociation[$table]) || $reload || $adapter->table_type == 'table') {
         if (!isset($this->aAssociation[$table])) {
             $this->aAssociation[$table] = array();
         }
         $aMap =& $this->aAssociation[$table];
         $db = JFactory::getDbo();
         if ($adapter->table_type == 'table') {
             $from_table = $this->getLangTable('#__' . $table, $fromLangTag);
             $to_table = $this->getLangTable('#__' . $table, $this->toLangTag);
             $query = $db->getQuery(true);
             $query->select('st.' . $adapter->primarykey . ' AS sourceid, dt.' . $adapter->primarykey . ' AS newid');
             $query->from($from_table . ' AS st');
             $query->innerJoin($to_table . ' AS dt ON (st.' . $adapter->primarykey . ' = dt.' . $adapter->primarykey . ')');
             if (count($filter)) {
                 $query->where($filter);
             }
             $db->setQuery($query);
             $rows = $db->loadObjectList();
             if (count($rows)) {
                 foreach ($rows as $row) {
                     if (!isset($aMap[$row->sourceid])) {
                         $aMap[$row->sourceid] = array();
                     }
                     $aMap[$row->sourceid][$fromLangTag] = $row->sourceid;
                     $aMap[$row->sourceid][$this->toLangTag] = $row->newid;
                 }
             }
         } elseif ($adapter->table_type == 'table_ml') {
             $query = $db->getQuery(true);
             // content association
             $langField = $db->quoteName($adapter->language_field);
             $query->select('a.' . $adapter->primarykey . " AS sourceid, GROUP_CONCAT(l.lang_code, ',', a.{$adapter->primarykey} SEPARATOR '|') AS `data`")->from('#__' . $adapter->table . ' AS a');
             if ($adapter->language_mode == 'id') {
                 $query->innerJoin('#__languages AS l ON l.lang_id = a.' . $adapter->language_field);
             } else {
                 $query->innerJoin('#__languages AS l ON l.lang_code = a.' . $adapter->language_field);
             }
             $query->group('a.' . $adapter->primarykey);
             $db->setQuery($query);
             $rows = $db->loadObjectList();
             if (count($rows)) {
                 foreach ($rows as $row) {
                     if (!$row->data) {
                         continue;
                     }
                     $aMap[$row->sourceid] = array();
                     $data = explode('|', $row->data);
                     $assoc = array();
                     foreach ($data as $d) {
                         list($language, $contentid) = explode(',', $d);
                         if ($language != $fromLangTag) {
                             $aMap[$row->sourceid][$language] = $contentid;
                         }
                     }
                 }
             }
         } elseif ($adapter->table_type == 'alias') {
             $query = $db->getQuery(true);
             $query->select('a.lang_code, a.title, a.title_native')->from('#__languages AS a');
             $db->setQuery($query);
             $list = $db->loadObjectList();
             $languages = array();
             foreach ($list as $item) {
                 $lang_code = preg_replace('/\\-.*/', '', $item->lang_code);
                 $languages[$lang_code] = $item;
             }
             //
             $query = $db->getQuery(true);
             $query->select('*')->from('#__' . $adapter->table);
             if ($this->fromLangTag != '*') {
                 $lang_code = preg_replace('/\\-.*/', '', $this->fromLangTag);
                 if ($this->fromLangTag == $defaultLanguage) {
                     $query->where('(' . $db->quoteName($adapter->alias_field) . ' LIKE ' . $db->quote('%-' . $lang_code) . ' OR ' . $db->quoteName($adapter->alias_field) . ' NOT REGEXP ' . $db->quote('-[a-z]{2}$') . ')');
                 } else {
                     $query->where($db->quoteName($adapter->alias_field) . ' LIKE ' . $db->quote('%-' . $lang_code));
                 }
             } else {
                 $query->where($db->quoteName($adapter->alias_field) . ' NOT REGEXP ' . $db->quote('-[a-z]{2}$'));
             }
             $db->setQuery($query);
             $rows = $db->loadObjectList();
             if (count($rows)) {
                 foreach ($rows as $row) {
                     $sourceid = $row->{$adapter->primarykey};
                     if (!isset($aMap[$sourceid])) {
                         $aMap[$sourceid] = array();
                     }
                     $aMap[$sourceid][$this->fromLangTag] = $sourceid;
                     $alias = $row->{$adapter->alias_field};
                     if ($this->fromLangTag != '*') {
                         $lang_code = preg_replace('/\\-.*/', '', $this->fromLangTag);
                         $alias = preg_replace('/\\-' . $lang_code . '$/', '', $alias);
                     }
                     $query = $db->getQuery(true);
                     $query->select('*')->from('#__' . $adapter->table);
                     $where = array();
                     $where[] = $db->quoteName($adapter->alias_field) . ' = ' . $db->quote($alias);
                     $where[] = $db->quoteName($adapter->alias_field) . ' REGEXP ' . $db->quote($alias . '-[a-z]{2}$');
                     $query->where($where, 'OR');
                     $db->setQuery($query);
                     $rows2 = $db->loadObjectList();
                     if (count($rows2)) {
                         foreach ($rows2 as $row2) {
                             if ($alias == $row2->{$adapter->alias_field}) {
                                 $aMap[$sourceid]['*'] = $row2->{$adapter->primarykey};
                                 if (!isset($aMap[$sourceid][$defaultLanguage])) {
                                     $aMap[$sourceid][$defaultLanguage] = $row2->{$adapter->primarykey};
                                 }
                             } else {
                                 foreach ($languages as $lang_code => $item) {
                                     if ($alias . '-' . $lang_code == $row2->{$adapter->alias_field}) {
                                         $aMap[$sourceid][$item->lang_code] = $row2->{$adapter->primarykey};
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             //table_type = native
             $query = $db->getQuery(true);
             // content association
             $langField = $db->quoteName($adapter->language_field);
             $query->select("a.key, GROUP_CONCAT(c.{$langField}, ',', c.id SEPARATOR '|') AS `data`");
             $query->from('#__associations AS a');
             $query->innerJoin('#__' . $table . ' AS c ON  (a.id=c.' . $id . ' AND a.context = ' . $db->quote($context) . ')');
             $query->group('a.key');
             $db->setQuery($query);
             $rows = $db->loadObjectList();
             if (count($rows)) {
                 foreach ($rows as $row) {
                     if (!$row->data) {
                         continue;
                     }
                     $data = explode('|', $row->data);
                     $assoc = array();
                     foreach ($data as $d) {
                         list($language, $contentid) = explode(',', $d);
                         $assoc[$language] = $contentid;
                         if ($language == '*' && !isset($assoc[$defaultLanguage])) {
                             $assoc[$defaultLanguage] = $contentid;
                         }
                     }
                     if (isset($assoc[$fromLangTag])) {
                         $aMap[$assoc[$fromLangTag]] = $assoc;
                     }
                 }
             }
         }
     }
     //return @$this->aAssociation[$table];
 }
コード例 #6
0
ファイル: helper.php プロジェクト: thumbs-up-sign/TuVanDuAn
 public static function getHelperContent()
 {
     $app = JFactory::getApplication();
     $itemtype = $app->getUserState('com_jalang.itemtype', 'content');
     return JalangHelperContent::getInstance($itemtype);
 }