コード例 #1
0
ファイル: view.html.php プロジェクト: thangredweb/redCORE
 /**
  * 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);
 }
コード例 #2
0
ファイル: view.html.php プロジェクト: thangredweb/redCORE
 /**
  * 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);
 }
コード例 #3
0
ファイル: translations.php プロジェクト: thangredweb/redCORE
 /**
  * Build an SQL query to load the list data.
  *
  * @return  JDatabaseQuery
  */
 protected function getListQuery()
 {
     $table = RedcoreHelpersTranslation::getTranslationTable();
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     if (empty($table)) {
         $query->select('*')->from('#__extensions')->where('1=2');
         return $query;
     }
     $query->select('o.*')->from($db->qn($table->table, 'o'));
     $columns = (array) $table->columns;
     foreach ($columns as $column) {
         $query->select($db->qn('t.' . $column, 't_' . $column));
     }
     $query->select(array($db->qn('t.rctranslations_id'), $db->qn('t.rctranslations_language'), $db->qn('t.rctranslations_originals'), $db->qn('t.rctranslations_modified'), $db->qn('t.rctranslations_state')));
     $leftJoinOn = array();
     foreach ($table->primaryKeys as $primaryKey) {
         $leftJoinOn[] = 'o.' . $primaryKey . ' = t.' . $primaryKey;
     }
     if ($language = $this->getState('filter.language')) {
         $leftJoinOn[] = 't.rctranslations_language = ' . $db->q($language);
     } else {
         // We will return empty query
         $leftJoinOn[] = '1 = 2';
     }
     $leftJoinOn = implode(' AND ', $leftJoinOn);
     $query->leftJoin($db->qn(RTranslationTable::getTranslationsTableName($table->table, ''), 't') . (!empty($leftJoinOn) ? ' ON ' . $leftJoinOn . '' : ''));
     // Filter search
     $search = $this->getState('filter.search_translations');
     if (!empty($search)) {
         $search = $db->quote('%' . $db->escape($search, true) . '%');
         $searchColumns = array();
         foreach ($columns as $column) {
             $searchColumns[] = '(o.' . $column . ' LIKE ' . $search . ')';
             $searchColumns[] = '(t.' . $column . ' LIKE ' . $search . ')';
         }
         if (!empty($searchColumns)) {
             $query->where('(' . implode(' OR ', $searchColumns) . ')');
         }
     }
     // Content Element filter
     $contentElement = RTranslationHelper::getContentElement($table->option, $table->xml);
     $filters = $contentElement->getTranslateFilter();
     if (!empty($filters)) {
         foreach ($filters as $filter) {
             $query->where((string) $filter);
         }
     }
     // Ordering
     $orderList = $this->getState('list.ordering');
     $directionList = $this->getState('list.direction');
     $order = !empty($orderList) ? $orderList : 't.rctranslations_language';
     $direction = !empty($directionList) ? $directionList : 'DESC';
     $query->order($db->escape($order) . ' ' . $db->escape($direction));
     return $query;
 }
コード例 #4
0
ファイル: translation.php プロジェクト: thangredweb/redCORE
 /**
  * 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;
 }
コード例 #5
0
ファイル: table.php プロジェクト: thangredweb/redCORE
 /**
  * Delete Content Element Table and XML file
  *
  * @param   string  $option   The Extension Name ex. com_redcore
  * @param   string  $xmlFile  XML file to install
  *
  * @return  boolean  Returns true if Content element was successfully purged
  */
 public static function deleteContentElement($option = 'com_redcore', $xmlFile = '')
 {
     // Load Content Element
     $contentElement = RTranslationHelper::getContentElement($option, $xmlFile);
     if (self::uninstallContentElement($option, $xmlFile) || empty($contentElement->table)) {
         if (empty($contentElement)) {
             JFactory::getApplication()->enqueueMessage(JText::_('COM_REDCORE_CONFIG_TRANSLATIONS_CONTENT_ELEMENT_NOT_INSTALLED'), 'warning');
             return false;
         }
         $xmlFilePath = RTranslationContentElement::getContentElementXmlPath($option, $xmlFile);
         try {
             JFile::delete($xmlFilePath);
         } catch (Exception $e) {
             JFactory::getApplication()->enqueueMessage(JText::sprintf('LIB_REDCORE_TRANSLATIONS_CONTENT_ELEMENT_ERROR', $e->getMessage()), 'error');
             return false;
         }
         JFactory::getApplication()->enqueueMessage(JText::_('COM_REDCORE_CONFIG_TRANSLATIONS_CONTENT_ELEMENT_DELETED'), 'message');
         return true;
     }
     return false;
 }