/** * Translate text using google api * * @param string $text text to translate * @param string $source source language * @param string $target target language * * @return string * * @throws Exception */ public function translate($text, $source, $target) { // Convert from JISO to ISO codes $source = $this->convertFromJisoToIso($source); $target = $this->convertFromJisoToIso($target); $apiKey = NenoSettings::get('translator_api_key'); $url = 'https://www.googleapis.com/language/translate/v2'; //Chunk the text if need be $chunks = NenoHelper::chunkHTMLString($text, 4900); $translatedChunks = array(); foreach ($chunks as $chunk) { // Invoke the POST request. $response = $this->post($url, array('key' => $apiKey, 'q' => $chunk, 'source' => $source, 'target' => $target), array('X-HTTP-Method-Override' => 'GET')); // Log it if server response is not OK. if ($response->code != 200) { NenoLog::log('Google API failed with response: ' . $response->code, 1); $responseData = json_decode($response->body, true); throw new Exception($responseData['error']['errors'][0]['message'] . ' (' . $responseData['error']['errors'][0]['reason'] . ')', $response->code); } else { $responseBody = json_decode($response->body); $translatedChunks[] = $responseBody->data->translations[0]->translatedText; } } return implode(' ', $translatedChunks); }
/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { $languages = NenoHelper::getLanguages(); $defaultLanguage = NenoSettings::get('source_language'); $profiler = new JProfiler(); foreach ($languages as $language) { if ($language->lang_code !== $defaultLanguage) { $profiler->mark('Before create job' . $language->lang_code . ' Method: Machine'); $machineJob = NenoJob::createJob($language->lang_code, NenoContentElementTranslation::MACHINE_TRANSLATION_METHOD); $profiler->mark('After create job' . $language->lang_code . ' Method: Machine'); // If there are translations for this language and for this translation method if ($machineJob !== null) { NenoLog::add(count($machineJob->getTranslations()) . ' translations have been found to translate through machine translation'); } $proJob = NenoJob::createJob($language->lang_code, NenoContentElementTranslation::PROFESSIONAL_TRANSLATION_METHOD); // If there are translations for this language and for this translation method if ($proJob !== null) { NenoLog::add(count($proJob->getTranslations()) . ' translations have been found to translate through professional translation'); } if ($machineJob !== null || $proJob !== null) { NenoTaskMonitor::addTask('job_sender'); } } } }
/** * Display the view * * @param string $tpl Template name * * @return void * * @throws Exception */ public function display($tpl = null) { $this->langs = NenoHelper::getTargetLanguages(false); NenoHelperBackend::addSubmenu(''); $this->sidebar = JHtmlSidebar::render(); parent::display($tpl); }
/** * Translate text using google api * * @param string $text text to translate * @param string $source source language * @param string $target target language * * @return string * * @throws Exception */ public function translate($text, $source, $target) { // Convert from JISO to ISO codes $source = $this->convertFromJisoToIso($source); $target = $this->convertFromJisoToIso($target); list($clientId, $clientSecret) = explode(':', NenoSettings::get('translator_api_key')); $accessToken = $this->requestAccessToken($clientId, $clientSecret); $url = 'http://api.microsofttranslator.com/V2/Http.svc/Translate'; //Chunk the text if need be $chunks = NenoHelper::chunkHTMLString($text, 4900); $translatedChunks = array(); foreach ($chunks as $chunk) { $query = http_build_query(array('from' => $source, 'text' => $chunk, 'to' => $target)); // Invoke the POST request. $response = $this->get($url . '?' . $query, array('Authorization' => 'Bearer ' . $accessToken)); $responseBody = (array) simplexml_load_string($response->body); // Log it if server response is not OK. if ($response->code != 200) { NenoLog::log('Bing API failed with response: ' . $response->code, 1); throw new Exception((string) $responseBody['body']->p[1], $response->code); } else { $translatedChunks[] = $responseBody[0]; } } return implode(' ', $translatedChunks); }
/** * Translate text using yandex api * * @param string $text text to translate * @param string $source source language * @param string $target target language * * @return string * * @throws Exception */ public function translate($text, $source, $target) { // Convert from JISO to ISO codes $target = $this->convertFromJisoToIso($target); // Language parameter for url $source = $this->convertFromJisoToIso($source); $lang = $source . "-" . $target; $apiKey = NenoSettings::get('translator_api_key'); //Chunk the text if need be $chunks = NenoHelper::chunkHTMLString($text, 9900); $translatedChunks = array(); foreach ($chunks as $chunk) { $url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?key=' . $apiKey . '&lang=' . $lang; // Invoke the POST request. $response = $this->post($url, array('text' => $chunk)); // Log it if server response is not OK. if ($response->code != 200) { NenoLog::log('Yandex API failed with response: ' . $response->code, 1); $responseData = json_decode($response->body, true); throw new Exception(JText::_('COM_NENO_EDITOR_YANDEX_ERROR_CODE_' . $responseData['code']), $responseData['code']); } else { $responseBody = json_decode($response->body); $translatedChunks[] = $responseBody->text[0]; } } return implode(' ', $translatedChunks); }
/** * Show confirmation before moving anything * * @return void */ public function show() { $input = JFactory::getApplication()->input; // Overwrite the view $input->set('view', 'moveelementconfirm'); $groups = $input->get('groups', array(), 'array'); $tables = $input->get('tables', array(), 'array'); $files = $input->get('files', array(), 'files'); // If a group is selected then load all the elements from that group if (!empty($groups)) { foreach ($groups as $groupId) { $group = NenoContentElementGroup::getGroup($groupId); // Handle tables $groupTables = $group->getTables(); if (!empty($groupTables)) { /* @var $groupTable NenoContentElementGroup */ foreach ($groupTables as $groupTable) { // Add the table id to the tables array $tables[] = $groupTable->getId(); } } // Handle files $groupFiles = $group->getLanguageFiles(); if (!empty($groupFiles)) { /* @var $groupFile NenoContentElementLanguageFile */ foreach ($groupFiles as $groupFile) { // Add the file id to the files array $files[] = $groupFile->getId(); } } } } // Remove duplicates array_unique($tables); array_unique($files); // Load table info if (!empty($tables)) { foreach ($tables as $key => $table) { $tables[$key] = NenoContentElementTable::load($table); } } // Load files info if (!empty($files)) { foreach ($files as $key => $file) { $files[$key] = NenoContentElementLanguageFile::load($file); } } // Show output // Get the view /* @var $view NenoViewMoveElementConfirm */ $view = $this->getView('MoveElementConfirm', 'html'); $view->groups = NenoHelper::convertNenoObjectListToJObjectList(NenoHelper::getGroups()); // Assign data from the model $view->tables = NenoHelper::convertNenoObjectListToJObjectList($tables); $view->files = NenoHelper::convertNenoObjectListToJObjectList($files); // Display the view $view->display(); }
/** * Display the view * * @param string $tpl Template * * @return void * * @throws Exception This will happen if there are errors during the process to load the data * * @since 1.0 */ public function display($tpl = null) { $this->state = $this->get('State'); $this->items = NenoHelper::convertNenoObjectListToJObjectList($this->get('Items')); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors)); } NenoHelperBackend::addSubmenu('groupselements'); $this->addToolbar(); $this->sidebar = JHtmlSidebar::render(); parent::display($tpl); }
/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $query = $db->getQuery(true); $extensions = $db->quote(NenoHelper::whichExtensionsShouldBeTranslated()); $query->select('e.*')->from('`#__extensions` AS e')->where(array('e.type IN (' . implode(',', $extensions) . ')', 'e.name NOT LIKE \'%neno\'', 'NOT EXISTS (SELECT 1 FROM #__neno_content_element_groups_x_extensions AS ge WHERE ge.extension_id = e.extension_id)'))->order('name'); $db->setQuery($query); $extensions = $db->loadAssocList(); foreach ($extensions as $extension) { NenoHelper::discoverExtension($extension); } return true; }
/** * {@inheritdoc} * * * @return array */ public function getItems() { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $db->setQuery($this->getListQuery()); $languages = $db->loadObjectListMultiIndex('lang_code'); $items = array(); foreach ($languages as $language) { $translated = 0; $queued = 0; $changed = 0; $untranslated = 0; $item = new stdClass(); $item->lang_code = $language[0]->lang_code; $item->comment = $language[0]->comment; $item->published = $language[0]->published; $item->title = $language[0]->title; $item->image = $language[0]->image; $item->errors = NenoHelper::getLanguageErrors((array) $language[0]); $item->isInstalled = NenoHelper::isCompletelyInstall($item->lang_code); foreach ($language as $internalItem) { switch ($internalItem->state) { case NenoContentElementTranslation::TRANSLATED_STATE: $translated = (int) $internalItem->word_count; break; case NenoContentElementTranslation::QUEUED_FOR_BEING_TRANSLATED_STATE: $queued = (int) $internalItem->word_count; break; case NenoContentElementTranslation::SOURCE_CHANGED_STATE: $changed = (int) $internalItem->word_count; break; case NenoContentElementTranslation::NOT_TRANSLATED_STATE: $untranslated = (int) $internalItem->word_count; break; } } $item->wordCount = new stdClass(); $item->wordCount->translated = $translated; $item->wordCount->queued = $queued; $item->wordCount->changed = $changed; $item->wordCount->untranslated = $untranslated; $item->wordCount->total = $translated + $queued + $changed + $untranslated; $item->translationMethods = NenoHelper::getLanguageDefault($item->lang_code); $items[] = $item; } return $items; }
/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { if (!empty($taskData['language'])) { $languageTag = $taskData['language']; $groups = NenoHelper::getGroups(false); /* @var $group NenoContentElementGroup */ foreach ($groups as $group) { $group->generateContentForLanguage($languageTag); } // Publish language content $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->update('#__languages')->set('published = 1')->where('lang_code = ' . $db->quote($languageTag)); $db->setQuery($query); $db->execute(); } }
/** * Task to get a confirmation language * * @return void */ public function confirmationMessageForLanguageDeletion() { $input = $this->input; $language = $input->getString('language'); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*')->update('#__languages')->where('lang_code = ' . $db->quote($language)); $db->setQuery($query); $languageData = $db->loadAssoc(); $languageErrors = NenoHelper::getLanguageErrors($languageData); $displayData = new stdClass(); $displayData->error = false; $displayData->messages = $languageErrors; if (empty($languageErrors)) { // Calculate statistics $query->clear()->select('COUNT(*)')->from('#__neno_content_element_translations')->where('language = ' . $db->quote($language)); $db->setQuery($query); $counter = $db->loadResult(); $displayData->messages[] = JText::sprintf('COM_NENO_DASHBOARD_DELETE_LANGUAGE', $counter); } else { $displayData->error = true; } echo JLayoutHelper::render('messages', $displayData, JPATH_NENO_LAYOUTS); }
/** * Loads all the elements using its parent id and the parent Id value * * @param string $elementsTableName Table Name * @param string $parentColumnName Parent column name * @param string $parentId Parent Id * @param boolean $transformProperties If the properties should be transform to CamelCase * @param array $extraWhereStatements Extra where statements * * @return array */ public static function getElementsByParentId($elementsTableName, $parentColumnName, $parentId, $transformProperties = false, $extraWhereStatements = array()) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*')->from($elementsTableName)->where($parentColumnName . ' = ' . intval($parentId)); if (!empty($extraWhereStatements)) { foreach ($extraWhereStatements as $extraWhereStatement) { $query->where($extraWhereStatement); } } $db->setQuery($query); $elements = $db->loadObjectList(); if ($transformProperties) { for ($i = 0; $i < count($elements); $i++) { $data = new stdClass(); $elementArray = get_object_vars($elements[$i]); foreach ($elementArray as $property => $value) { $data->{NenoHelper::convertDatabaseColumnNameToPropertyName($property)} = $value; } $elements[$i] = $data; } } return $elements; }
/** * {@inheritdoc} * * @return array */ public function getItems() { return NenoHelper::getLanguageConfigurationData(); }
/** * {@inheritdoc} * * @return array */ public function getItems() { $this->setState('list.limit', 0); $groups = NenoHelper::getGroups(true); return $groups; }
<img src="<?php echo JUri::root() . 'media/mod_languages/images/' . $item['image'] . '.gif'; ?> "/> <?php } ?> <?php echo $item['title']; ?> </h4> <?php if ($item['placement'] == 'dashboard') { ?> <?php echo NenoHelper::renderWordCountProgressBar($item['wordCount'], true, true); ?> <a class="btn <?php echo $item['isInstalled'] == false ? 'not-ready' : ''; ?> " href="<?php echo JRoute::_('index.php?option=com_neno&task=setWorkingLang&lang=' . $item['lang_code'] . '&next=editor'); ?> "> <?php echo JText::_('COM_NENO_DASHBOARD_TRANSLATE_BUTTON'); ?> </a> <?php }
/** * Load elements using AJAX * * @return void * * @throws Exception */ public function getElements() { $input = JFactory::getApplication()->input; $groupId = $input->getInt('group_id'); if (!empty($groupId)) { /* @var $group NenoContentElementGroup */ $group = NenoContentElementGroup::load($groupId); $tables = $group->getTables(false, false, true); $files = $group->getLanguageFiles(); $displayData = array(); /* @var $model NenoModelStrings */ $model = $this->getModel(); $displayData['tables'] = NenoHelper::convertNenoObjectListToJObjectList($tables); //Remove fields marked as Don't translate foreach ($displayData['tables'] as $table) { foreach ($table->fields as $key => $field) { if (!$field->translate) { unset($table->fields[$key]); } } } $displayData['files'] = NenoHelper::convertNenoObjectListToJObjectList($files); $displayData['state'] = $model->getState(); $tablesHTML = JLayoutHelper::render('multiselecttables', $displayData, JPATH_NENO_LAYOUTS); echo $tablesHTML; } JFactory::getApplication()->close(); }
/** * Get languages * * @return array */ public function getLanguages() { $languages = NenoHelper::getLanguages(false); $workingLanguage = NenoHelper::getWorkingLanguage(); $defaultLanguage = NenoSettings::get('source_language'); foreach ($languages as $key => $language) { if ($language->lang_code == $workingLanguage || $language->lang_code == $defaultLanguage) { unset($languages[$key]); } } return $languages; }
/** * Move the translation to its place in the shadow table * * @return bool */ public function moveTranslationToTarget() { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $query = $db->getQuery(true); // If the translation comes from database content, let's load it if ($this->contentType == self::DB_STRING) { $query->clear()->select(array('f.field_name', 't.table_name'))->from('`#__neno_content_element_fields` AS f')->innerJoin('`#__neno_content_element_tables` AS t ON f.table_id = t.id')->where('f.id = ' . $this->element->id); $db->setQuery($query); $row = $db->loadRow(); list($fieldName, $tableName) = $row; // Ensure data integrity $this->string = NenoHelperData::ensureDataIntegrity($this->element->id, $this->string, $this->language); $query->clear()->select(array('f.field_name', 'ft.value'))->from('`#__neno_content_element_fields_x_translations` AS ft')->innerJoin('`#__neno_content_element_fields` AS f ON f.id = ft.field_id')->where('ft.translation_id = ' . $this->id); $db->setQuery($query); $whereValues = $db->loadAssocList('field_name'); $shadowTableName = $db->generateShadowTableName($tableName, $this->language); $query->clear()->update($shadowTableName)->set($db->quoteName($fieldName) . ' = ' . $db->quote($this->string)); foreach ($whereValues as $whereField => $where) { $query->where($db->quoteName($whereField) . ' = ' . $db->quote($where['value'])); } $db->setQuery($query); $db->execute(); return true; } else { $query->select(array('REPLACE(lf.filename, lf.language, ' . $db->quote($this->language) . ') AS filename', 'lf.filename as originalFilename', 'ls.constant'))->from('#__neno_content_element_translations AS tr')->innerJoin('#__neno_content_element_language_strings AS ls ON ls.id = tr.content_id')->innerJoin('#__neno_content_element_language_files AS lf ON ls.languagefile_id = lf.id')->where('tr.id = ' . (int) $this->id); $db->setQuery($query); $translationData = $db->loadAssoc(); $existingStrings = array(); if (!empty($translationData)) { $filePath = JPATH_ROOT . "/language/" . $this->language . '/' . $translationData['filename']; if (file_exists($filePath)) { $existingStrings = NenoHelper::readLanguageFile($filePath); } else { $defaultLanguage = NenoSettings::get('source_language'); if (file_exists(JPATH_ROOT . "/language/{$defaultLanguage}/" . $translationData['originalFilename'])) { $existingStrings = NenoHelper::readLanguageFile(JPATH_ROOT . "/language/{$defaultLanguage}/" . $translationData['originalFilename']); } } $existingStrings[$translationData['constant']] = $this->string; NenoHelper::saveIniFile($filePath, $existingStrings); } } return false; }
echo $group->id; ?> "/></td> <td colspan="3"><a href="#" class="modalgroupform"><?php echo $group->group_name; ?> </a></td> <td<?php echo $group->element_count ? ' class="load-elements"' : ''; ?> ><?php echo $group->element_count; ?> </td> <td><?php echo NenoHelper::renderWordCountProgressBar($group->word_count, 1); ?> </td> <td> <a href="#" class="modalgroupform"> <?php if (empty($group->assigned_translation_methods)) { ?> <?php echo JText::_('COM_NENO_VIEW_GROUPSELEMENTS_ADD_TRANSLATION_METHOD'); ?> <?php } else { ?> <?php echo NenoHelperBackend::renderTranslationMethodsAsCSV($group->assigned_translation_methods);
/** * Discover the element * * @return bool True on success */ public function discoverElement() { // Save the hierarchy first, if ($this->isNew() || NenoSettings::get('discovering_element_0') == $this->id) { NenoHelper::setSetupState(JText::sprintf('COM_NENO_INSTALLATION_MESSAGE_PARSING_GROUP', $this->groupName)); $level = '1.1'; } else { $level = '1.2'; } $this->persist(); $elementId = $this->id; if (empty($this->tables) && empty($this->languageFiles)) { NenoHelper::setSetupState(JText::sprintf('COM_NENO_INSTALLATION_MESSAGE_CONTENT_NOT_DETECTED', $this->getGroupName()), 1, 'warning'); $level = 0; $elementId = 0; } NenoSettings::set('installation_level', $level); NenoSettings::set('discovering_element_0', $elementId); }
public function fixMenus() { NenoHelper::createMenuStructure(); JFactory::getApplication()->redirect('index.php?option=com_neno&view=dashboard'); }
<?php /** * @package Joomla.Administrator * @subpackage mod_neno_dashboard * * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; //Adding Language files $lang = JFactory::getLanguage(); $lang->load('com_neno', JPATH_ADMINISTRATOR, $lang->getTag(), true); //Get Items $languageData = NenoHelper::getLanguageConfigurationData(); require JModuleHelper::getLayoutPath('mod_neno_dashboard');
<td class='setting-label'> <?php echo JText::_('COM_NENO_SETTINGS_SETTING_NAME_TRANSLATOR'); ?> <span class="modal-tooltip" data-toggle="tooltip" data-html="true" data-placement="right" title='<?php echo JText::_('COM_NENO_SETTINGS_SETTING_INFO_TRANSLATOR'); ?> '>[?]</span> </td> <td class=''> <?php echo NenoHelper::getTranslatorsSelect(); ?> </td> </tr> <tr> <td class='setting-label'> <?php echo JText::_('COM_NENO_SETTINGS_SETTING_NAME_TRANSLATOR_API_KEY'); ?> </td> <td class=''> <input type="text" name="translator_api_key" id="translator_api_key" class="input-setting input-large" value="" /> </td> </tr>
/** * Get language configuration data * * @return array */ public static function getLanguageConfigurationData() { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $query = $db->getQuery(true); $default = NenoSettings::get('source_language'); $subquery1 = $db->getQuery(true); $subquery2 = $db->getQuery(true); $subquery2->select('tr2.*')->from('#__neno_content_element_translations AS tr2')->where('content_type = ' . $db->quote('lang_string')); $subquery1->select('tr.*')->from('#__neno_content_element_translations AS tr')->innerJoin('#__neno_content_element_fields AS f ON tr.content_id = f.id')->innerJoin('#__neno_content_element_tables AS t ON t.id = f.table_id')->where(array('content_type = ' . $db->quote('db_string'), 'f.translate = 1', 't.translate = 1'))->union($subquery2); $query->select(array('l.lang_code', 'l.published', 'l.title', 'l.image', 'tr.state', 'SUM(tr.word_counter) AS word_count', 'lc.comment'))->from('#__languages AS l')->leftJoin('#__neno_language_external_translators_comments AS lc ON l.lang_code = lc.language')->leftJoin('(' . (string) $subquery1 . ') AS tr ON tr.language = l.lang_code')->where('l.lang_code <> ' . $db->quote($default))->group(array('l.lang_code', 'tr.state'))->order('lang_code'); $db->setQuery($query); $languages = $db->loadObjectListMultiIndex('lang_code'); $items = array(); if (!empty($languages)) { foreach ($languages as $language) { $translated = 0; $queued = 0; $changed = 0; $untranslated = 0; $item = new stdClass(); $item->lang_code = $language[0]->lang_code; $item->comment = $language[0]->comment; $item->published = $language[0]->published; $item->title = $language[0]->title; $item->image = $language[0]->image; $item->errors = NenoHelper::getLanguageErrors((array) $language[0]); $item->isInstalled = NenoHelper::isCompletelyInstall($item->lang_code); foreach ($language as $internalItem) { switch ($internalItem->state) { case NenoContentElementTranslation::TRANSLATED_STATE: $translated = (int) $internalItem->word_count; break; case NenoContentElementTranslation::QUEUED_FOR_BEING_TRANSLATED_STATE: $queued = (int) $internalItem->word_count; break; case NenoContentElementTranslation::SOURCE_CHANGED_STATE: $changed = (int) $internalItem->word_count; break; case NenoContentElementTranslation::NOT_TRANSLATED_STATE: $untranslated = (int) $internalItem->word_count; break; } } $item->wordCount = new stdClass(); $item->wordCount->translated = $translated; $item->wordCount->queued = $queued; $item->wordCount->changed = $changed; $item->wordCount->untranslated = $untranslated; $item->wordCount->total = $translated + $queued + $changed + $untranslated; $item->translationMethods = NenoHelper::getLanguageDefault($item->lang_code); $items[] = $item; } } $languagesOnLanguageTable = array_keys($languages); $knownLanguages = JFactory::getLanguage()->getKnownLanguages(); $defaultTranslationsMethods = NenoHelper::getDefaultTranslationMethods(); foreach ($knownLanguages as $languageTag => $languageInfo) { if ($languageTag != $default && !in_array($languageTag, $languagesOnLanguageTable)) { $languagesData = new stdClass(); $languagesData->lang_code = $languageInfo['tag']; $languagesData->title = $languageInfo['name']; $languagesData->translationMethods = $defaultTranslationsMethods; $languagesData->errors = NenoHelper::getLanguageErrors((array) $languagesData); $languagesData->placement = 'dashboard'; $languagesData->image = NenoHelper::getLanguageImage($languageInfo['tag']); $languagesData->published = NenoHelper::isLanguagePublished($languageInfo['tag']); $languagesData->comment = NenoHelper::getLanguageTranslatorComment($languageInfo['tag']); $items[] = $languagesData; } } return $items; }
" title="<?php echo $translationStatesText[$translation->state]; ?> "></span> </td> <td title="<?php echo JText::sprintf('COM_NENO_VIEW_STRINGS_EDIT', NenoHelper::html2text($translation->original_text, 200)); ?> "> <a href="index.php?option=com_neno&view=editor&stringId=<?php echo $translation->id; ?> "> <?php echo NenoHelper::html2text($translation->string, 200); ?> </a> </td> <td><?php echo $translation->breadcrumbs[0]; ?> </td> <td><?php echo $translation->breadcrumbs[1]; ?> </td> <td><?php echo $translation->breadcrumbs[2]; ?> </td>
/** * Load group data * * @return void */ protected function getGroupData() { $groups = NenoHelper::getGroups(false); /* @var $group NenoContentElementGroup */ foreach ($groups as $key => $group) { $groups[$key] = $group->prepareDataForView(); } $this->groups = $groups; }
/** * This event discover/sync tables * * @param string $tableName Table name * * @return void */ public function onDatabaseStructure($tableName) { $db = JFactory::getDbo(); // Unify table name $tableName = str_replace($db->getPrefix(), '#__', $tableName); /* @var $table NenoContentElementTable */ $table = NenoContentElementTable::load(array('table_name' => $tableName)); if (empty($table)) { $otherGroup = NenoContentElementGroup::load(array('other_group' => 1)); $table = NenoHelper::createTableInstance($tableName, $otherGroup); $table->persist(); } else { $table->sync(); } }
public function refreshWordCount() { $input = $this->input; // Refresh content for groups $groups = $input->get('groups', array(), 'ARRAY'); $tables = $input->get('tables', array(), 'ARRAY'); $files = $input->get('files', array(), 'ARRAY'); $workingLanguage = NenoHelper::getWorkingLanguage(); /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('tr.id')->from('#__neno_content_element_translations AS tr')->innerJoin('#__neno_content_element_fields AS f ON tr.content_id = f.id')->innerJoin('#__neno_content_element_tables AS t ON t.id = f.table_id')->where(array('tr.state = ' . $db->quote(NenoContentElementTranslation::TRANSLATED_STATE), 'tr.language = ' . $db->quote($workingLanguage))); if (!empty($groups)) { $query->innerJoin('#__neno_content_element_groups AS g ON t.group_id = g.id')->where('g.id IN (' . implode(',', $db->quote($groups)) . ')'); } elseif (!empty($tables) || !empty($files)) { $where = array(); if (!empty($tables)) { $where[] = '(t.id IN (' . implode(',', $db->quote($tables)) . ') AND tr.content_type = ' . $db->quote(NenoContentElementTranslation::DB_STRING) . ')'; } if (!empty($files)) { $where[] = '(t.id IN (' . implode(',', $db->quote($tables)) . ') AND tr.content_type = ' . $db->quote(NenoContentElementTranslation::LANG_STRING) . ')'; } $query->where('(' . implode(' OR ', $where) . ')'); } $db->setQuery($query); $translationIds = $db->loadArray(); foreach ($translationIds as $translationId) { /* @var $translation NenoContentElementTranslation */ $translation = NenoContentElementTranslation::load($translationId, false, true); $translation->persist(); } JFactory::getApplication()->redirect('index.php?option=com_neno&view=groupselements'); }
/** * Get Worker related to a task * * @return NenoTaskWorker */ protected function getWorker() { // Generate Worker class name $className = 'NenoTaskWorker' . ucfirst(NenoHelper::convertDatabaseColumnNameToPropertyName($this->task)); // Check if the class exists, if it doesn't, let's try to load it. if (class_exists($className)) { $worker = new $className(); return $worker; } else { NenoLog::log('Worker not found for this task', 1); throw new UnexpectedValueException('Worker not found for this task'); } }
/** * Grouping tables that haven't been discovered * * @param bool $persist Persist the group * * @return NenoContentElementGroup */ public static function groupingTablesNotDiscovered($persist = true) { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); // Get all the tables that haven't been detected using naming convention. $tablesNotDiscovered = self::getTablesNotDiscovered(); $tablesAdded = false; $otherGroup = null; if (!empty($tablesNotDiscovered)) { // Check if this group exists already $query = $db->getQuery(true); $query->select('g.id')->from('#__neno_content_element_groups AS g')->where('NOT EXISTS (SELECT 1 FROM #__neno_content_element_groups_x_extensions AS ge WHERE ge.group_id = g.id)'); $db->setQuery($query); $groupId = $db->loadResult(); if (!empty($groupId)) { /* @var $otherGroup NenoContentElementGroup */ $otherGroup = NenoContentElementGroup::load($groupId); } else { $otherGroup = new NenoContentElementGroup(array('group_name' => 'Other')); } $tablesIgnored = NenoHelper::getDoNotTranslateTables(); foreach ($tablesNotDiscovered as $tableNotDiscovered) { if (!in_array($tableNotDiscovered, $tablesIgnored)) { // Create an array with the table information $tableData = array('tableName' => $tableNotDiscovered, 'primaryKey' => $db->getPrimaryKey($tableNotDiscovered), 'translate' => 1, 'group' => $otherGroup); // Create ContentElement object $table = new NenoContentElementTable($tableData); // Get all the columns a table contains $fields = $db->getTableColumns($table->getTableName()); foreach ($fields as $fieldName => $fieldType) { $fieldData = array('fieldName' => $fieldName, 'fieldType' => $fieldType, 'translate' => NenoContentElementField::isTranslatableType($fieldType), 'table' => $table); $field = new NenoContentElementField($fieldData); $table->addField($field); } $otherGroup->addTable($table); $tablesAdded = true; } } $otherGroup->setAssignedTranslationMethods(NenoHelper::getTranslationMethodsForLanguages()); if ($persist) { $otherGroup->persist(); } } if (!$tablesAdded) { $otherGroup = null; } return $otherGroup; }