From d113d7b91bd8b72a52a8049ec313bc8f3a0b5f9f Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 6 Apr 2017 22:40:22 +0100 Subject: [PATCH] Added the new language feature to the export and import of Components, so that their related translations can also be linked to the exported package. --- README.md | 2 +- admin/README.txt | 2 +- admin/assets/css/joomla_component.css | 4 +- admin/assets/css/joomla_components.css | 4 +- admin/controllers/joomla_component.php | 4 +- admin/controllers/joomla_components.php | 4 +- admin/models/forms/joomla_component.js | 4 +- admin/models/import_joomla_components.php | 105 ++++++++++++++++++ admin/models/joomla_component.php | 4 +- admin/models/joomla_components.php | 64 ++++++++++- admin/tables/joomla_component.php | 4 +- admin/views/joomla_component/submitbutton.js | 4 +- admin/views/joomla_component/tmpl/edit.php | 4 +- admin/views/joomla_component/view.html.php | 4 +- .../views/joomla_components/tmpl/default.php | 4 +- .../tmpl/default_batch_body.php | 4 +- .../tmpl/default_batch_footer.php | 4 +- .../joomla_components/tmpl/default_body.php | 4 +- .../joomla_components/tmpl/default_foot.php | 4 +- .../joomla_components/tmpl/default_head.php | 4 +- .../tmpl/default_toolbar.php | 4 +- admin/views/joomla_components/view.html.php | 4 +- 22 files changed, 205 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 0532b82a2..163d92dc3 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.4.2 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **105639** ++ *Line count*: **105804** + *File count*: **639** + *Folder count*: **115** diff --git a/admin/README.txt b/admin/README.txt index 0532b82a2..163d92dc3 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -109,7 +109,7 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.4.2 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **105639** ++ *Line count*: **105804** + *File count*: **639** + *Folder count*: **115** diff --git a/admin/assets/css/joomla_component.css b/admin/assets/css/joomla_component.css index 995ab078b..b2d67e780 100644 --- a/admin/assets/css/joomla_component.css +++ b/admin/assets/css/joomla_component.css @@ -9,8 +9,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_component.css diff --git a/admin/assets/css/joomla_components.css b/admin/assets/css/joomla_components.css index 13f47756a..1364656f2 100644 --- a/admin/assets/css/joomla_components.css +++ b/admin/assets/css/joomla_components.css @@ -9,8 +9,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_components.css diff --git a/admin/controllers/joomla_component.php b/admin/controllers/joomla_component.php index f31a3c84b..16ac7bd06 100644 --- a/admin/controllers/joomla_component.php +++ b/admin/controllers/joomla_component.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_component.php diff --git a/admin/controllers/joomla_components.php b/admin/controllers/joomla_components.php index 11127a42b..6bc94ee08 100644 --- a/admin/controllers/joomla_components.php +++ b/admin/controllers/joomla_components.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_components.php diff --git a/admin/models/forms/joomla_component.js b/admin/models/forms/joomla_component.js index 75cc4c3cd..1c6cefaf3 100644 --- a/admin/models/forms/joomla_component.js +++ b/admin/models/forms/joomla_component.js @@ -9,8 +9,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_component.js diff --git a/admin/models/import_joomla_components.php b/admin/models/import_joomla_components.php index 316f64b77..95c82b3c6 100644 --- a/admin/models/import_joomla_components.php +++ b/admin/models/import_joomla_components.php @@ -691,6 +691,16 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy { return false; } + // we then store the languages + if (!$this->saveSmartItems($data, 'language', $db, $user, $today)) + { + return false; + } + // we then store the language translations + if (!$this->saveSmartItems($data, 'language_translation', $db, $user, $today)) + { + return false; + } // we then store the custom_code if (!$this->saveSmartItems($data, 'custom_code', $db, $user, $today)) { @@ -845,6 +855,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy // okay we have it local (check if the version is newer) if ($this->forceUpdate == 1 || $dbDate > $localDate) { + // add some local values to item to combine + if ($type === 'language_translation') + { + $item->localComponents = $local->components; + $item->localTranslation = $local->translation; + } // make sure we have the correct ID set $item->id = $local->id; // yes it is newer, lets update (or is being forced) @@ -1416,6 +1432,87 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy } } break; + case 'language_translation': + // update the component ID where needed + if (isset($item->components) && ComponentbuilderHelper::checkJson($item->components)) + { + $components = json_decode($item->components, true); + foreach ($components as $nr => $id) + { + if (!is_numeric($id)) + { + continue; + } + // update the components + if (isset($this->newID['joomla_component'][$id])) + { + $components[$nr] = $this->newID['joomla_component'][$id]; + } + else + { + unset($components[$nr]); + } + } + } + // load the local components if found + if (isset($item->localComponents) && ComponentbuilderHelper::checkJson($item->localComponents)) + { + if (!isset($components)) + { + $components= array(); + } + $localComponents = json_decode($item->localComponents, true); + foreach ($localComponents as $lid) + { + if (!is_numeric($lid)) + { + continue; + } + // add if not already there + if (!in_array($lid, $components)) + { + $components[] = $lid; + } + } + } + // remove the localComponents + if (isset($item->localComponents)) + { + unset($item->localComponents); + } + // load it back + if (isset($components) && ComponentbuilderHelper::checkArray($components)) + { + // load it back + $item->components = json_encode(array_values($components)); + } + // merge the translations where needed + if (isset($item->translation) && isset($item->localTranslation) + && ComponentbuilderHelper::checkJson($item->translation) + && ComponentbuilderHelper::checkJson($item->localTranslation)) + { + $translations = json_decode($item->translation, true); + $localTranslations = json_decode($item->localTranslation, true); + foreach ($localTranslations['translation'] as $nr => $value) + { + if (!in_array($value, $translations['translation'])) + { + $translations['translation'][] = $value; + $translations['language'][] = $localTranslations['language'][$nr]; + } + } + $item->translation = json_encode($translations); + } + elseif (isset($item->localTranslation) && ComponentbuilderHelper::checkJson($item->localTranslation)) + { + $item->translation = $item->localTranslation; + } + // remove the localTranslation + if (isset($item->localTranslation)) + { + unset($item->localTranslation); + } + break; } // final action prep switch($action) @@ -1829,6 +1926,14 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy $retryAgain = 2; } break; + case 'language_translation': + // get by English translation since there should just be one + $getter = 'entranslation'; + break; + case 'language': + // get by language tag since there should just be one + $getter = 'langtag'; + break; default: // can't be found so return false return false; diff --git a/admin/models/joomla_component.php b/admin/models/joomla_component.php index 914e39937..7ff37279a 100644 --- a/admin/models/joomla_component.php +++ b/admin/models/joomla_component.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_component.php diff --git a/admin/models/joomla_components.php b/admin/models/joomla_components.php index e48641bec..aeeb43547 100644 --- a/admin/models/joomla_components.php +++ b/admin/models/joomla_components.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_components.php @@ -213,6 +213,8 @@ class ComponentbuilderModelJoomla_components extends JModelList $this->setData($user, $db, 'site_view', $item->addsite_views, 'siteview'); // set the custom code ID's $this->setCustomCodeIds($item, 'joomla_component'); + // set the language strings for this component + $this->setLanguageTranslation($user, $db, $item->id); // load to global object $this->smartExport['joomla_component'][$item->id] = $item; } @@ -882,6 +884,64 @@ class ComponentbuilderModelJoomla_components extends JModelList } } + /** + * Set the language strings for this component + * + * @param int $id The component id + * + * @return void + * + */ + protected function setLanguageTranslation(&$user, &$db, &$id) + { + // Create a new query object. + $query = $db->getQuery(true); + $query->select(array('a.*')); + $query->from('#__componentbuilder_language_translation AS a'); + // Implement View Level Access + if (!$user->authorise('core.options', 'com_componentbuilder')) + { + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + } + + // Order the results by ordering + $query->order('a.ordering ASC'); + + // Load the items + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + $items = $db->loadObjectList(); + // check if we have items + if (ComponentbuilderHelper::checkArray($items)) + { + if (!isset($this->smartExport['language_translation'])) + { + $this->smartExport['language_translation'] = array(); + } + foreach ($items as $item) + { + if (!isset($this->smartExport['language_translation'][$item->id]) && ComponentbuilderHelper::checkJson($item->components)) + { + $components = json_decode($item->components, true); + if (in_array($id, $components)) + { + // load to global object + $this->smartExport['language_translation'][$item->id] = $item; + // add languages + if (isset($item->translation)) + { + $this->setData($user, $db, 'language', $item->translation, 'language'); + } + } + } + } + } + } + } + /** * Get the package name * diff --git a/admin/tables/joomla_component.php b/admin/tables/joomla_component.php index bc16cefcb..448b11115 100644 --- a/admin/tables/joomla_component.php +++ b/admin/tables/joomla_component.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage joomla_component.php diff --git a/admin/views/joomla_component/submitbutton.js b/admin/views/joomla_component/submitbutton.js index c864165b8..510231827 100644 --- a/admin/views/joomla_component/submitbutton.js +++ b/admin/views/joomla_component/submitbutton.js @@ -9,8 +9,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage submitbutton.js diff --git a/admin/views/joomla_component/tmpl/edit.php b/admin/views/joomla_component/tmpl/edit.php index ad8a0b600..ec7e9cb0c 100644 --- a/admin/views/joomla_component/tmpl/edit.php +++ b/admin/views/joomla_component/tmpl/edit.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage edit.php diff --git a/admin/views/joomla_component/view.html.php b/admin/views/joomla_component/view.html.php index 60beea8a0..35d77c51d 100644 --- a/admin/views/joomla_component/view.html.php +++ b/admin/views/joomla_component/view.html.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage view.html.php diff --git a/admin/views/joomla_components/tmpl/default.php b/admin/views/joomla_components/tmpl/default.php index 65bf238f2..90f86b002 100644 --- a/admin/views/joomla_components/tmpl/default.php +++ b/admin/views/joomla_components/tmpl/default.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage default.php diff --git a/admin/views/joomla_components/tmpl/default_batch_body.php b/admin/views/joomla_components/tmpl/default_batch_body.php index 4f2c59b78..6905ea2b4 100644 --- a/admin/views/joomla_components/tmpl/default_batch_body.php +++ b/admin/views/joomla_components/tmpl/default_batch_body.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage default_batch_body.php diff --git a/admin/views/joomla_components/tmpl/default_batch_footer.php b/admin/views/joomla_components/tmpl/default_batch_footer.php index 2efba2306..4d70df94d 100644 --- a/admin/views/joomla_components/tmpl/default_batch_footer.php +++ b/admin/views/joomla_components/tmpl/default_batch_footer.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage default_batch_footer.php diff --git a/admin/views/joomla_components/tmpl/default_body.php b/admin/views/joomla_components/tmpl/default_body.php index c025e96d2..05ed903ee 100644 --- a/admin/views/joomla_components/tmpl/default_body.php +++ b/admin/views/joomla_components/tmpl/default_body.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage default_body.php diff --git a/admin/views/joomla_components/tmpl/default_foot.php b/admin/views/joomla_components/tmpl/default_foot.php index 4c86cf5a6..702e286b9 100644 --- a/admin/views/joomla_components/tmpl/default_foot.php +++ b/admin/views/joomla_components/tmpl/default_foot.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage default_foot.php diff --git a/admin/views/joomla_components/tmpl/default_head.php b/admin/views/joomla_components/tmpl/default_head.php index bd946f8af..242209039 100644 --- a/admin/views/joomla_components/tmpl/default_head.php +++ b/admin/views/joomla_components/tmpl/default_head.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage default_head.php diff --git a/admin/views/joomla_components/tmpl/default_toolbar.php b/admin/views/joomla_components/tmpl/default_toolbar.php index d81cb7f83..604d98fdb 100644 --- a/admin/views/joomla_components/tmpl/default_toolbar.php +++ b/admin/views/joomla_components/tmpl/default_toolbar.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage default_toolbar.php diff --git a/admin/views/joomla_components/view.html.php b/admin/views/joomla_components/view.html.php index de0ef0800..51ca21086 100644 --- a/admin/views/joomla_components/view.html.php +++ b/admin/views/joomla_components/view.html.php @@ -10,8 +10,8 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 318 of this MVC - @build 5th April, 2017 + @version @update number 329 of this MVC + @build 6th April, 2017 @created 6th May, 2015 @package Component Builder @subpackage view.html.php