/** * Display method * * @param string $tpl The template name * * @return void */ public function display($tpl = null) { $this->form = $this->get('Form'); $this->translationTable = RedcoreHelpersTranslation::getTranslationTable(); $this->contentElement = RTranslationHelper::getContentElement($this->translationTable->option, $this->translationTable->xml); $this->item = $this->get('Item'); $editor = JFactory::getConfig()->get('editor'); $this->editor = JEditor::getInstance($editor); $this->columns = array(); $this->noTranslationColumns = array(); $tableColumns = (array) $this->translationTable->columns; $this->fieldsXml = $this->contentElement->getTranslateFields(); foreach ($this->fieldsXml as $field) { foreach ($tableColumns as $column) { if ($column == (string) $field['name']) { $attributes = current($field->attributes()); $attributes['titleLabel'] = (string) $field; $this->columns[$column] = $attributes; break; } } if ((string) $field['translate'] == '0' && (string) $field['type'] != 'referenceid') { $attributes = current($field->attributes()); $attributes['titleLabel'] = (string) $field; $this->noTranslationColumns[(string) $field['name']] = $attributes; } } // Check if option is enabled if (RBootstrap::getConfig('enable_translations', 0) == 0) { JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_REDCORE_CONFIG_TRANSLATIONS_PLUGIN_LABEL_WARNING', '<a href="index.php?option=com_plugins&view=plugins&filter_search=redcore">' . JText::_('COM_REDCORE_CONFIGURE') . '</a>'), 'error'); } parent::display($tpl); }
/** * Constructor * * @param JDatabase &$db A database connector object * * @throws UnexpectedValueException */ public function __construct(&$db) { $this->_tableName = 'extension'; $this->_tbl_key = 'rctranslations_id'; $table = RedcoreHelpersTranslation::getTranslationTable(); $this->_tbl = RTranslationTable::getTranslationsTableName($table->table, ''); $this->_tableName = str_replace('#__', '', $this->_tbl); if (empty($this->_tbl) || empty($this->_tbl_key) && empty($this->_tbl_keys)) { throw new UnexpectedValueException(sprintf('Missing data to initialize %s table | id: %s', $this->_tbl, $this->_tbl_key)); } parent::__construct($db); // Initialise custom fields $this->loadCustomFields(); }
/** * Method to get the options to populate to populate list * * @return array The field option objects. * * @since 1.0 */ protected function getOptions() { // Accepted modifiers $hash = md5($this->element); if (!isset(static::$cache[$hash])) { static::$cache[$hash] = parent::getOptions(); $options = array(); $translationTables = RTranslationHelper::getInstalledTranslationTables(); if (!empty($translationTables)) { foreach ($translationTables as $value) { $options[] = JHtml::_('select.option', str_replace('#__', '', $value->table), $value->name); } static::$cache[$hash] = array_merge(static::$cache[$hash], $options); } } $contentElement = RedcoreHelpersTranslation::getCurrentContentElement(); if (!empty($contentElement)) { $this->value = $contentElement; } return static::$cache[$hash]; }
/** * Display method * * @param string $tpl The template name * * @return void */ public function display($tpl = null) { $model = $this->getModel(); $app = JFactory::getApplication(); $this->contentElementName = RedcoreHelpersTranslation::getCurrentContentElement(); $this->componentName = $app->input->get->get('component', $model->getState('filter.component', '')); $this->activeFilters = $model->getActiveFilters(); $this->state = $model->getState(); $this->filterForm = $model->getForm(); $this->pagination = $model->getPagination(); if (!empty($this->contentElementName)) { $this->translationTable = RedcoreHelpersTranslation::getTranslationTable(); $this->contentElement = RTranslationHelper::getContentElement($this->translationTable->option, $this->translationTable->xml); $this->items = $model->getItems(); $this->filterForm->removeField('component', 'filter'); } else { /** @var RedcoreModelConfig $modelConfig */ $modelConfig = RModelAdmin::getAdminInstance('Config', array('ignore_request' => true), 'com_redcore'); if (!empty($this->componentName)) { $this->component = $modelConfig->getComponent($this->componentName); } $this->contentElements = $modelConfig->loadContentElements($this->componentName); $this->missingContentElements = $modelConfig->loadMissingContentElements($this->componentName, $this->contentElements); $this->return = base64_encode('index.php?option=com_redcore&view=translations&contentelement=&component=' . $this->componentName); $layout = 'manage'; $this->setLayout($layout); $app->input->set('layout', $layout); $this->filterForm->removeField('language', 'filter'); $this->filterForm->removeField('search_translations', 'filter'); $this->filterForm->removeField('translations_limit', 'list'); $this->filterForm->removeField('contentelement', 'filter'); } // Check if option is enabled if (RBootstrap::getConfig('enable_translations', 0) == 0) { JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_REDCORE_CONFIG_TRANSLATIONS_PLUGIN_LABEL_WARNING', '<a href="index.php?option=com_plugins&view=plugins&filter_search=redcore">' . JText::_('COM_REDCORE_CONFIGURE') . '</a>'), 'error'); } parent::display($tpl); }
/** * Method to get an array of data items. * * @return mixed An array of data items on success, false on failure. * * @since 12.2 */ public function getItems() { $items = parent::getItems(); $table = RedcoreHelpersTranslation::getTranslationTable(); $columns = (array) $table->columns; if (!empty($items)) { foreach ($items as $itemKey => $item) { $items[$itemKey]->translationStatus = RedcoreHelpersTranslation::getTranslationItemStatus($item, $columns); } } return $items; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. */ public function save($data) { $translationTable = RedcoreHelpersTranslation::getTranslationTable(); $contentElement = RTranslationHelper::getContentElement($translationTable->option, $translationTable->xml); $translation = JFactory::getApplication()->input->get('translation', array(), 'array'); $original = JFactory::getApplication()->input->get('original', array(), 'array'); $id = !empty($data['rctranslations_id']) ? (int) $data['rctranslations_id'] : 0; $data = array_merge($data, $translation); $fieldsXml = $contentElement->getTranslateFields(); foreach ($fieldsXml as $field) { if ((string) $field['type'] == 'params' && (string) $field['translate'] == '1') { $fieldName = (string) $field['name']; $original[$fieldName] = $original['params_' . $fieldName]; $paramsChanged = false; if (!empty($data[$fieldName])) { $registry = new JRegistry(); $registry->loadString($original[$fieldName]); $originalParams = $registry->toArray(); foreach ($data[$fieldName] as $paramKey => $paramValue) { if (!isset($originalParams[$paramKey]) && $paramValue != '' || $originalParams[$paramKey] != $paramValue) { $paramsChanged = true; break; } } if ($paramsChanged) { $data[$fieldName] = json_encode($data[$fieldName]); } else { $data[$fieldName] = ''; } } } } $dispatcher = RFactory::getDispatcher(); /** @var RedcoreTableTranslation $table */ $table = $this->getTable(); if (empty($id)) { $db = $this->getDbo(); $query = $db->getQuery(true)->select('rctranslations_id')->from($db->qn(RTranslationTable::getTranslationsTableName($translationTable->table, '')))->where('rctranslations_language = ' . $db->q($data['rctranslations_language'])); foreach ($translationTable->primaryKeys as $primaryKey) { if (!empty($data[$primaryKey])) { $query->where($db->qn($primaryKey) . ' = ' . $db->q($data[$primaryKey])); } } $db->setQuery($query); $id = $db->loadResult(); } foreach ($translationTable->primaryKeys as $primaryKey) { $original[$primaryKey] = $data[$primaryKey]; } $isNew = true; // Load the row if saving an existing item. $table->load((int) $id); if ($table->rctranslations_modified) { $isNew = false; } $data['rctranslations_originals'] = RTranslationTable::createOriginalValueFromColumns($original, $translationTable->columns); // We run posthandler methods foreach ($fieldsXml as $field) { $postHandler = (string) $field['posthandler']; $fieldName = (string) $field['name']; if (!empty($postHandler) && (string) $field['translate'] == '1') { $postHandlerFunctions = explode(',', $postHandler); foreach ($postHandlerFunctions as $postHandlerFunction) { $postHandlerFunctionArray = explode('::', $postHandlerFunction); if (empty($postHandlerFunctionArray[1])) { $postHandlerFunctionArray[1] = $postHandlerFunctionArray[0]; $postHandlerFunctionArray[0] = 'RTranslationContentHelper'; $postHandlerFunction = 'RTranslationContentHelper::' . $postHandlerFunction; } if (method_exists($postHandlerFunctionArray[0], $postHandlerFunctionArray[1])) { call_user_func_array(array($postHandlerFunctionArray[0], $postHandlerFunctionArray[1]), array($field, &$data[$fieldName], &$data, $translationTable)); } } } } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // Trigger the onContentAfterSave event. $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew)); $this->setState($this->getName() . '.id', $table->rctranslations_id); // Clear the cache $this->cleanCache(); return true; }
<?php /** * @package Redcore.Admin * @subpackage Views * * @copyright Copyright (C) 2008 - 2015 redCOMPONENT.com. All rights reserved. * @license GNU General Public License version 2 or later, see LICENSE. */ defined('_JEXEC') or die; jimport('joomla.html.editor'); $status = RedcoreHelpersTranslation::getTranslationItemStatus($this->item->original, array_keys($this->columns)); $hiddenFields = array(); // HTML helpers JHtml::_('behavior.keepalive'); JHtml::_('rbootstrap.tooltip'); JHtml::_('rjquery.chosen', 'select'); JHtml::_('rsearchtools.main'); $action = JRoute::_('index.php?option=com_redcore&view=translation'); $input = JFactory::getApplication()->input; $predefinedOptions = array(1 => 'JPUBLISHED', 0 => 'JUNPUBLISHED', 2 => 'JARCHIVED', -2 => 'JTRASHED', '*' => 'JALL'); ?> <script type="text/javascript"> function setTranslationValue(elementName, elementOriginal, setParams) { if (setParams) { var originalValue = ''; var name = ''; var originalField = {}; jQuery('#translation_field_' + elementName + ' :input').each(function(){