Ejemplo n.º 1
0
 public function edit()
 {
     $input = JFactory::getApplication()->input;
     $id = $input->getInt('id');
     $refid = $input->get('refid');
     $adapter = JalangHelper::getHelperContent();
     if ($adapter) {
         $linkEdit = $adapter->getEditLink($id);
         if (!$linkEdit) {
             JError::raise(E_WARNING, 300, $adapter->getError());
             $this->setRedirect(JRoute::_('index.php?option=com_jalang&view=items', false));
             return false;
         }
         /*$return = JRoute::_('index.php?option=com_jalang&view=items', false);
         		$return = urlencode(base64_encode($return));*/
         $linkEdit = JRoute::_($linkEdit . '&jaref=' . $adapter->table . '.' . $refid, false);
         if ($adapter->edit_context) {
             $app = JFactory::getApplication();
             $this->holdEditId($adapter->edit_context, $id);
             $app->setUserState($adapter->edit_context . '.data', null);
         }
         $this->setRedirect($linkEdit);
     } else {
         JError::raise(E_ERROR, 500, JText::_('INVALID_REQUEST'));
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 public function getEditLink($id)
 {
     if ($this->checkout($id)) {
         if (JalangHelper::isJoomla32()) {
             return 'index.php?option=com_newsfeeds&view=newsfeed&layout=modal&tmpl=component&id=' . $id;
         } else {
             return 'index.php?option=com_newsfeeds&view=newsfeed&layout=edit&id=' . $id;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 public function getEditLink($id)
 {
     if ($this->checkout($id)) {
         $row = $this->getRow($id);
         if (JalangHelper::isJoomla32()) {
             return 'index.php?option=com_categories&view=category&layout=modal&tmpl=component&id=' . $id . '&extension=' . $row->extension;
         } else {
             return 'index.php?option=com_categories&view=category&layout=edit&id=' . $id . '&extension=' . $row->extension;
         }
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Add the page title and toolbar.
  *
  * @since   1.6
  */
 protected function addToolbar()
 {
     $user = JFactory::getUser();
     // Get the toolbar object instance
     $bar = JToolBar::getInstance('toolbar');
     JToolbarHelper::title(JText::_('TRANSLATION_MANAGER'), 'article.png');
     JToolbarHelper::preferences('com_jalang');
     if (JalangHelper::isInstalled('com_flexicontent')) {
         JToolBarHelper::custom('tool.bindFLEXI', 'copy', '', JText::_('Transfer to FLEXI'));
     }
     if (JalangHelper::isJoomla3x()) {
         JHtmlSidebar::setAction('index.php?option=com_jalang&view=tool');
     }
 }
Ejemplo n.º 6
0
 /**
  * Display the view
  *
  * @return  void
  */
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $this->item = $this->get('Item');
     $adapter = JalangHelper::getHelperContent();
     if ($adapter) {
         $this->primarykey = $adapter->primarykey;
         $this->alias_field = $adapter->alias_field;
         $this->translate_fields = $adapter->translate_fields;
         $this->reference_fields = $adapter->reference_fields;
     } else {
         $this->primarykey = null;
         $this->alias_field = null;
         $this->translate_fields = array();
         $this->reference_fields = array();
     }
     parent::display($tpl);
 }
Ejemplo n.º 7
0
 */
defined('_JEXEC') or die;
if (!JFactory::getUser()->authorise('core.manage', 'com_jalang')) {
    return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
}
/*
require_once( __DIR__ . '/helpers/helper.php' );
require_once( __DIR__ . '/helpers/content/content.php' );
require_once( __DIR__ . '/helpers/translator/translator.php' );
*/
require_once dirname(__FILE__) . '/helpers/helper.php';
require_once dirname(__FILE__) . '/helpers/tool.php';
require_once dirname(__FILE__) . '/helpers/content/content.php';
require_once dirname(__FILE__) . '/helpers/translator/translator.php';
$app = JFactory::getApplication();
$helper = new JalangHelper();
$helper->update();
$itemtype = JRequest::getVar('itemtype', 'content');
if (!empty($itemtype)) {
    $app->setUserState('com_jalang.itemtype', $itemtype);
}
$mainlanguage = JRequest::getVar('mainlanguage', JalangHelper::getDefaultLanguage());
if (!empty($mainlanguage)) {
    $app->setUserState('com_jalang.mainlanguage', $mainlanguage);
}
//asset
$document = JFactory::getDocument();
if (JalangHelper::isJoomla3x()) {
    $document->addStyleSheet('components/com_jalang/asset/style.css');
} else {
    $document->addStyleSheet('components/com_jalang/asset/style_2x.css');
Ejemplo n.º 8
0
 /**
  * Method to get a list of articles.
  * Overridden to add a check for access levels.
  *
  * @return  mixed  An array of data items on success, false on failure.
  * @since   1.6.1
  */
 public function getItems()
 {
     $items = parent::getItems();
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $adapter = JalangHelper::getHelperContent();
     $translator = new JalangHelperTranslator();
     $params = JComponentHelper::getParams('com_jalang');
     $language = $app->getUserState('com_jalang.mainlanguage', '*');
     $languages = JHtml::_('contentlanguage.existing', true, true);
     if ($adapter->table_type == 'table') {
         if (!$language || $language == '*') {
             $language = JalangHelper::getDefaultLanguage();
         }
         $translator->fromLangTag = $language;
         $from_table = $translator->getLangTable('#__' . $adapter->table, $language);
         $filterById = $db->quoteName('st') . '.' . $db->quoteName($adapter->primarykey) . '=%d';
     } else {
         $translator->fromLangTag = $language;
         $from_table = '#__' . $adapter->table;
         $filterById = $db->quoteName('c') . '.' . $db->quoteName($adapter->primarykey) . '=%d';
         $translator->loadAssociate($adapter->table, $adapter->primarykey, $adapter->associate_context, false);
     }
     for ($x = 0, $count = count($items); $x < $count; $x++) {
         $sourceid = $items[$x]->{$adapter->primarykey};
         if ($adapter->table_type == 'table') {
             foreach ($languages as $cl) {
                 if ($cl->value != $language) {
                     $translator->toLangTag = $cl->value;
                     $translator->loadAssociate($adapter->table, $adapter->primarykey, $adapter->associate_context, true, array(sprintf($filterById, $sourceid)));
                 }
             }
         }
         $items[$x]->associations = isset($translator->aAssociation[$adapter->table][$sourceid]) ? $translator->aAssociation[$adapter->table][$sourceid] : array();
     }
     return $items;
 }
Ejemplo n.º 9
0
<?php

/**
 * ------------------------------------------------------------------------
 * JA Multilingual Component for Joomla 2.5 & 3.4
 * ------------------------------------------------------------------------
 * Copyright (C) 2004-2011 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
 * @license - GNU/GPL, http://www.gnu.org/licenses/gpl.html
 * Author: J.O.O.M Solutions Co., Ltd
 * Websites: http://www.joomlart.com - http://www.joomlancers.com
 * ------------------------------------------------------------------------
 */
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
if (JalangHelper::isJoomla3x()) {
    JHtml::_('bootstrap.tooltip');
    JHtml::_('behavior.multiselect');
    JHtml::_('dropdown.init');
    JHtml::_('formbehavior.chosen', 'select');
}
JHtml::_('behavior.modal', 'a.modal', array('fullScreen' => true));
$app = JFactory::getApplication();
$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$archived = $this->state->get('filter.published') == 2 ? true : false;
$trashed = $this->state->get('filter.published') == -2 ? true : false;
$saveOrder = $listOrder == 'a.ordering';
if ($saveOrder) {
    $saveOrderingUrl = 'index.php?option=com_jalang&task=articles.saveOrderAjax&tmpl=component';
Ejemplo n.º 10
0
 public function translateAll()
 {
     $this->consoleInit();
     $input = JFactory::getApplication()->input;
     //$from = $input->get('translate_from', '*');
     //$to = $input->get('translate_to', '*');
     $languages = JalangHelper::getListInstalledLanguages();
     $from = JalangHelper::getDefaultLanguage();
     if (!headers_sent()) {
         header('Content-type: text/html; charset=utf-8');
     }
     foreach ($languages as $lang) {
         if ($lang->element == $from) {
             continue;
         }
         $params = JComponentHelper::getParams('com_jalang');
         $translator = JalangHelperTranslator::getInstance($params->get('translator_api_active', 'bing'));
         $translator->sendOutput('<h3>' . JText::sprintf('START_TO_TRANSLATE_FOR_THE_VAR_LANGUAGE', $lang->name) . '</h3>');
         $translator->translateAllTables($from, $lang->element);
         //sleep(2);
         $translator->sendOutput(str_pad('', 50, '-'));
     }
     jexit('Done');
 }
Ejemplo n.º 11
0
 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?
 }
Ejemplo n.º 12
0
 /**
  * @param $alias - alias of default item
  * @param $fromLangTag - source language tag
  * @param $toLangTag - destination language tag
  * @param $row - data of new item
  * @param $generateFrom - how to generate alias
  * @param $makeUnique - if true, it will test if generate alias is existed and try to create another one.
  * @return string - new alias
  */
 public function getNewAlias($alias, $fromLangTag, $toLangTag, $row = null, $generateFrom = '', $makeUnique = false)
 {
     static $checkedAlias = array();
     @(list($from, $fromCountry) = explode('-', $fromLangTag));
     @(list($to, $toCountry) = explode('-', $toLangTag));
     $fromCountry = strtolower($fromCountry);
     $toCountry = strtolower($toCountry);
     $hasTitle = is_array($row) && isset($row[$this->title_field]) && !empty($row[$this->title_field]);
     if (!$generateFrom) {
         if ($from == $to) {
             $generateFrom = 'alias';
         } else {
             $params = JComponentHelper::getParams('com_jalang');
             $generateFrom = $params->get('alias_type', 'title');
             if ($this->table_type == 'alias') {
                 $generateFrom = 'alias';
             }
         }
     }
     if ($generateFrom == 'title' && $hasTitle) {
         $newAlias = $row[$this->title_field];
         $newAlias = JApplication::stringURLSafe($newAlias);
         if ($newAlias == $alias) {
             $newAlias .= '-' . JalangHelper::getAliasSuffix($toLangTag);
         }
     } else {
         //append language code after alias of item in default language
         $suffix = JalangHelper::getAliasSuffix($fromLangTag);
         $newAlias = preg_replace('/\\-(' . str_replace('-', '\\-', $suffix) . ')$/', '', $alias);
         //remove suffix of other language
         $newAlias .= '-' . JalangHelper::getAliasSuffix($toLangTag);
         if ($newAlias == $alias) {
             //source language and destination language have a same language code
         }
     }
     if ($makeUnique) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select($db->quoteName($this->alias_field))->from('#__' . $this->table);
         $i = (int) (isset($checkedAlias[$newAlias]) ? $checkedAlias[$newAlias] : 0);
         do {
             $testAlias = $i ? $newAlias . '-' . $i : $newAlias;
             $query->clear('where');
             $query->where($db->quoteName($this->alias_field) . '=' . $db->quote($testAlias));
             $db->setQuery($query);
             $test = $db->loadResult();
             $i++;
         } while ($test);
         $checkedAlias[$newAlias] = $i;
         $newAlias = $testAlias;
     }
     return $newAlias;
 }
Ejemplo n.º 13
0
 * ------------------------------------------------------------------------
 */
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
if (JalangHelper::isJoomla3x()) {
    JHtml::_('bootstrap.tooltip');
    JHtml::_('behavior.multiselect');
    JHtml::_('dropdown.init');
    JHtml::_('formbehavior.chosen', 'select');
}
JHtml::_('behavior.modal', 'a.modal', array('fullScreen' => true, 'onClose' => '\\function(){ window.location.reload(); }'));
$app = JFactory::getApplication();
$user = JFactory::getUser();
$userId = $user->get('id');
$languages = JalangHelper::getListInstalledLanguages();
$defaultLanguage = JalangHelper::getLanguage();
$params = JComponentHelper::getParams('com_jalang');
$input = JFactory::getApplication()->input;
if ($input->get('debug', 0)) {
    $lang = $input->get('lang', '');
    if ($lang) {
        $db = JFactory::getDbo();
        $query = "SELECT language FROM #__content WHERE `alias` LIKE '%-{$lang}'";
        $db->setQuery($query);
        $langtag = $db->loadResult();
        var_dump($langtag);
    }
}
?>

<script type="text/javascript">
Ejemplo n.º 14
0
 /**
  * Returns an array of fields the table can be sorted by
  *
  * @return  array  Array containing the field name to sort by as the key and display text as value
  *
  * @since   3.0
  */
 protected function getSortFields()
 {
     $adapter = JalangHelper::getHelperContent();
     if (!$adapter) {
         return array();
     }
     return $adapter->getSortFields();
 }
Ejemplo n.º 15
0
 public function updateTemplateStyles()
 {
     // get all template styles
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('*')->from('#__template_styles')->where('client_id=0');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $mm_config = null;
     $fromAlias = JalangHelper::getAliasSuffix($this->fromLangTag);
     foreach ($rows as $row) {
         $params = json_decode($row->params, true);
         if (!$params || !isset($params['mm_config'])) {
             continue;
         }
         $mmca = json_decode($params['mm_config'], true);
         $update = 0;
         if (is_array($mmca)) {
             foreach ($mmca as $mmt => $mmc) {
                 if (preg_match('/-' . $this->from . '$/', $mmt) || !preg_match('/-[a-z]{2}$/', $mmt)) {
                     //convert from configuration of megamenu in default language
                     $mmt = preg_replace('/-(' . $this->from . '|' . $fromAlias . ')$/', '', $mmt);
                     $mmc1 = json_encode($mmc);
                     $mmt2 = $mmt . '-' . JalangHelper::getAliasSuffix($this->toLangTag);
                     //if(isset($mmca[$mmt2])) continue;
                     $mmc2 = preg_replace_callback('/(")(item|position)(["\\-:]+)(\\d+)([^\\d]?)/', array($this, 'updateTemplateStyles_callback'), $mmc1);
                     $mmca[$mmt2] = json_decode($mmc2, true);
                     $update = 1;
                 }
             }
         }
         if ($update) {
             $mm_config = json_encode($mmca);
             $params['mm_config'] = $mm_config;
             // update template style
             $query->clear();
             $query->update('#__template_styles')->set($db->quoteName('params') . '=' . $db->quote(json_encode($params)))->where('`id`=' . $row->id);
             $db->setQuery($query);
             $db->execute();
         }
     }
 }
Ejemplo n.º 16
0
 protected function updateVersion105()
 {
     /**
      * Version 1.0.5
      * Update alias of item in table type alias (E.g: menu_types table) from using language code (E.g: mainmenu-en) as alias suffix
      * to use language tag instead (E.g: mainmenu-en-us)
      *
      * This fix is help to translate content into many languages that have same language code (E.g: en-US, en-GB, en-AU,...)
      */
     $defaultLanguage = JalangHelper::getDefaultLanguage();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     //update menu_types and menu items
     $query->select('mt.id, mt.menutype, m.language')->from('#__menu_types AS mt')->innerJoin('#__menu AS m ON m.menutype = mt.menutype')->where('m.language <> ' . $db->quote($defaultLanguage))->where('m.language <> ' . $db->quote('*'))->group('mt.id');
     $db->setQuery($query);
     $list = $db->loadObjectList();
     if (count($list)) {
         foreach ($list as $item) {
             $langTag = $item->language;
             @(list($lang, $country) = explode('-', $langTag));
             $oldmenutype = $memnutype = $item->menutype;
             //remove old suffix
             $memnutype = preg_replace('/-' . $lang . '$/', '', $memnutype);
             //add new suffix format
             $memnutype .= '-' . JalangHelper::getAliasSuffix($langTag);
             //update menu type
             $query->clear();
             $query->update('#__menu_types')->set($db->quoteName('menutype') . '=' . $db->quote($memnutype))->where($db->quoteName('menutype') . '=' . $db->quote($oldmenutype));
             $db->setQuery($query);
             $db->execute();
             //update menu item
             $query->clear();
             $query->update('#__menu')->set($db->quoteName('menutype') . '=' . $db->quote($memnutype))->where($db->quoteName('menutype') . '=' . $db->quote($oldmenutype));
             $db->setQuery($query);
             $db->execute();
             //update module
             $query->clear();
             $query->select('m.id, m.params')->from('#__modules AS m')->where('m.language = ' . $db->quote($langTag));
             $db->setQuery($query);
             $modules = $db->loadObjectList();
             if (count($modules)) {
                 foreach ($modules as $mod) {
                     $registry = new JRegistry();
                     $registry->loadString($mod->params);
                     $params = $registry->toArray();
                     if ($registry->get('menutype') == $oldmenutype) {
                         $registry->set('menutype', $memnutype);
                         $query->clear();
                         $query->update('#__modules')->set($db->quoteName('params') . '=' . $db->quote($registry->toString()))->where($db->quoteName('id') . '=' . $mod->id);
                         $db->setQuery($query);
                         $db->execute();
                     }
                 }
             }
             //update template style - JA Mega menu config
             $query->clear();
             $query->select('t.id, t.params')->from('#__template_styles AS t')->where('t.client_id=0');
             $db->setQuery($query);
             $styles = $db->loadObjectList();
             if (count($styles)) {
                 foreach ($styles as $style) {
                     $params = preg_replace('/\\b' . $oldmenutype . '\\b/', $memnutype, $style->params);
                     if ($params != $style->params) {
                         $query->clear();
                         $query->update('#__template_styles')->set($db->quoteName('params') . '=' . $db->quote($params))->where($db->quoteName('id') . '=' . $style->id);
                         $db->setQuery($query);
                         $db->execute();
                     }
                 }
             }
         }
     }
     return true;
 }