From 761921fb895123f9c2a73e455e5b17740bb971bc Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 14 Oct 2021 16:30:56 +0200 Subject: [PATCH] first commit - v1.0.0 --- componentbuilderlanguagetabs.php | 63 +++++++ componentbuilderlanguagetabs.xml | 31 +++ fields/excludedlanguages.php | 176 ++++++++++++++++++ fields/index.html | 1 + forms/index.html | 1 + forms/joomla_component.xml | 73 ++++++++ index.html | 1 + ...g_content_componentbuilderlanguagetabs.ini | 20 ++ ...ntent_componentbuilderlanguagetabs.sys.ini | 20 ++ language/en-GB/index.html | 1 + language/index.html | 1 + rules/index.html | 1 + script.php | 79 ++++++++ 13 files changed, 468 insertions(+) create mode 100644 componentbuilderlanguagetabs.php create mode 100644 componentbuilderlanguagetabs.xml create mode 100644 fields/excludedlanguages.php create mode 100644 fields/index.html create mode 100644 forms/index.html create mode 100644 forms/joomla_component.xml create mode 100644 index.html create mode 100644 language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.ini create mode 100644 language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.sys.ini create mode 100644 language/en-GB/index.html create mode 100644 language/index.html create mode 100644 rules/index.html create mode 100644 script.php diff --git a/componentbuilderlanguagetabs.php b/componentbuilderlanguagetabs.php new file mode 100644 index 0000000..68ce1ad --- /dev/null +++ b/componentbuilderlanguagetabs.php @@ -0,0 +1,63 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\Registry\Registry; +use Joomla\CMS\Form\Form; + +JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); + +/** + * Content - Componentbuilder Language Tabs plugin. + * + * @package ComponentbuilderLanguageTabs + * @since 1.0.0 + */ +class PlgContentComponentbuilderLanguageTabs extends CMSPlugin +{ + /** + * Affects constructor behavior. If true, language files will be loaded automatically. + * + * @var boolean + * @since 1.0 + */ + protected $autoloadLanguage = true; + + /** + * Runs on content preparation of form. + * + * @param JForm $form The form + * @param stdClass $data The data + * + * @return boolean + * + * @since 1.0 + */ + public function onContentPrepareForm(Form $form, $data) + { + $context = $form->getName(); + + // When this is componentbuilder admin view + if (strpos($context, 'com_componentbuilder.joomla_component') === 0) + { + // Add the forms path + Form::addFormPath(__DIR__ . '/forms'); + // add the admin view params for privacy integration + $form->loadFile('joomla_component'); + } + return true; + } + +} diff --git a/componentbuilderlanguagetabs.xml b/componentbuilderlanguagetabs.xml new file mode 100644 index 0000000..86cd938 --- /dev/null +++ b/componentbuilderlanguagetabs.xml @@ -0,0 +1,31 @@ + + + PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS + 20th February, 2021 + Llewellyn van der Merwe + llewellyn@joomlacomponentbuilder.com + http://www.joomlacomponentbuilder.com + Copyright (C) 2015 Vast Development Method. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + 1.0.0 + PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_XML_DESCRIPTION + + + script.php + + + + en-GB/en-GB.plg_content_componentbuilderlanguagetabs.ini + en-GB/en-GB.plg_content_componentbuilderlanguagetabs.sys.ini + + + + + componentbuilderlanguagetabs.php + index.html + language + fields + forms + rules + + \ No newline at end of file diff --git a/fields/excludedlanguages.php b/fields/excludedlanguages.php new file mode 100644 index 0000000..89e3f04 --- /dev/null +++ b/fields/excludedlanguages.php @@ -0,0 +1,176 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// import the list field type +jimport('joomla.form.helper'); +JFormHelper::loadFieldClass('list'); + +/** + * Excludedlanguages Form Field class for the Componentbuilder component + */ +class JFormFieldExcludedlanguages extends JFormFieldList +{ + /** + * The excludedlanguages field type. + * + * @var string + */ + public $type = 'excludedlanguages'; + + /** + * Override to add new button + * + * @return string The field input markup. + * + * @since 3.2 + */ + protected function getInput() + { + // see if we should add buttons + $set_button = $this->getAttribute('button'); + // get html + $html = parent::getInput(); + // if true set button + if ($set_button === 'true') + { + $button = array(); + $script = array(); + $button_code_name = $this->getAttribute('name'); + // get the input from url + $app = JFactory::getApplication(); + $jinput = $app->input; + // get the view name & id + $values = $jinput->getArray(array( + 'id' => 'int', + 'view' => 'word' + )); + // check if new item + $ref = ''; + $refJ = ''; + if (!is_null($values['id']) && strlen($values['view'])) + { + // only load referral if not new item. + $ref = '&ref=' . $values['view'] . '&refid=' . $values['id']; + $refJ = '&ref=' . $values['view'] . '&refid=' . $values['id']; + // get the return value. + $_uri = (string) JUri::getInstance(); + $_return = urlencode(base64_encode($_uri)); + // load return value. + $ref .= '&return=' . $_return; + $refJ .= '&return=' . $_return; + } + // get button label + $button_label = trim($button_code_name); + $button_label = preg_replace('/_+/', ' ', $button_label); + $button_label = preg_replace('/\s+/', ' ', $button_label); + $button_label = preg_replace("/[^A-Za-z ]/", '', $button_label); + $button_label = ucfirst(strtolower($button_label)); + // get user object + $user = JFactory::getUser(); + // only add if user allowed to create language + if ($user->authorise('language.create', 'com_componentbuilder') && $app->isAdmin()) // TODO for now only in admin area. + { + // build Create button + $button[] = ' + '; + } + // only add if user allowed to edit language + if ($user->authorise('language.edit', 'com_componentbuilder') && $app->isAdmin()) // TODO for now only in admin area. + { + // build edit button + $button[] = ''; + // build script + $script[] = " + jQuery(document).ready(function() { + jQuery('#adminForm').on('change', '#jform_".$button_code_name."',function (e) { + e.preventDefault(); + var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val(); + ".$button_code_name."Button(".$button_code_name."Value); + }); + var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val(); + ".$button_code_name."Button(".$button_code_name."Value); + }); + function ".$button_code_name."Button(value) { + if (value > 0) { + // hide the create button + jQuery('#".$button_code_name."Create').hide(); + // show edit button + jQuery('#".$button_code_name."Edit').show(); + var url = 'index.php?option=com_componentbuilder&view=languages&task=language.edit&id='+value+'".$refJ."'; + jQuery('#".$button_code_name."Edit').attr('href', url); + } else { + // show the create button + jQuery('#".$button_code_name."Create').show(); + // hide edit button + jQuery('#".$button_code_name."Edit').hide(); + } + }"; + } + // check if button was created for language field. + if (is_array($button) && count($button) > 0) + { + // Load the needed script. + $document = JFactory::getDocument(); + $document->addScriptDeclaration(implode(' ',$script)); + // return the button attached to input field. + return '
' .$html . implode('',$button).'
'; + } + } + return $html; + } + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + */ + protected function getOptions() + { + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.langtag','a.name'),array('langtag','languages_name'))); + $query->from($db->quoteName('#__componentbuilder_language', 'a')); + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->order('a.langtag ASC'); + $db->setQuery((string)$query); + $items = $db->loadObjectList(); + // add the main language + $main_lang = trim(JComponentHelper::getParams('com_componentbuilder')->get('language', 'en-GB')); + // check if any language was added + $wasAdded = false; + $options = array(); + if ($items) + { + $options[] = JHtml::_('select.option', '', 'Select an option'); + foreach($items as $item) + { + $item->langtag = trim($item->langtag); + // do not add main language + if ($main_lang !== $item->langtag) + { + $options[] = JHtml::_('select.option', $item->langtag, $item->languages_name . ' (' .$item->langtag.')'); + $wasAdded = true; + } + } + } + // now if none was added give notice + if (!$wasAdded) + { + $options[] = JHtml::_('select.option', '', 'Add languages to select'); + } + return $options; + } +} diff --git a/fields/index.html b/fields/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/fields/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/forms/index.html b/forms/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/forms/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/forms/joomla_component.xml b/forms/joomla_component.xml new file mode 100644 index 0000000..44436f3 --- /dev/null +++ b/forms/joomla_component.xml @@ -0,0 +1,73 @@ + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.ini b/language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.ini new file mode 100644 index 0000000..76f3762 --- /dev/null +++ b/language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.ini @@ -0,0 +1,20 @@ +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS="Content - Componentbuilder Language Tabs" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_DESCRIPTION="This plugin is used to link your components to the language packaging and extending options, so you can set all the required details for the integration." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_XML_DESCRIPTION="

Content - Componentbuilder Language Tabs (v.1.0.0)

This plugin is used to link your components to the language packaging and extending options, so you can set all the required details for the integration.

Created by Llewellyn van der Merwe
Development started 19th March, 2020

" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LANGUAGE_OPTIONS="Language Options" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGE_NOTE_LABEL="Would you like to move languages to their own packages?" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGE_NOTE_DESCRIPTION="

Adding all your translations to your component can increase its size dramatically, so now you are able to move each extra language translation to its own installing package, leaving just your main language in the component.

Please note that this is only relevant if you actually have added extra translations to your component in the Language Translations area of JCB.

" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_ACTIVATE_LABEL="Activate" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_ACTIVATE_DESCRIPTION="Turn on the integration." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_YES="Yes" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NO="No" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_USE_PERCENTAGELANGUAGEADD_LABEL="Add Language Settings" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_USE_PERCENTAGELANGUAGEADD_DESCRIPTION="Select what option should be used" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_GLOBAL="Global" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LOCAL="Local" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_PERCENTAGELANGUAGEADD_LABEL="Add Language if %? ready." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_PERCENTAGELANGUAGEADD_DESCRIPTION="Select percentage any language should be translated before the system should add the language to the component during compilation." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGES_KEEP_LABEL="Do want to keep some languages in your component?" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGES_KEEP_DESCRIPTION="The JCB system main language will always be kept in your component. Select any of the other languages you would like to keep in your component. They will then be excluded from this language packaging option. (or leave blank for none)" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LANGUAGES_LABEL="Languages" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LANGUAGES_DESCRIPTION="The JCB system main language will always be kept in your component. Select any of the other languages you would like to keep in your component. They will then be excluded from this language packaging option. (or leave blank for none)" \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.sys.ini b/language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.sys.ini new file mode 100644 index 0000000..76f3762 --- /dev/null +++ b/language/en-GB/en-GB.plg_content_componentbuilderlanguagetabs.sys.ini @@ -0,0 +1,20 @@ +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS="Content - Componentbuilder Language Tabs" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_DESCRIPTION="This plugin is used to link your components to the language packaging and extending options, so you can set all the required details for the integration." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_XML_DESCRIPTION="

Content - Componentbuilder Language Tabs (v.1.0.0)

This plugin is used to link your components to the language packaging and extending options, so you can set all the required details for the integration.

Created by Llewellyn van der Merwe
Development started 19th March, 2020

" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LANGUAGE_OPTIONS="Language Options" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGE_NOTE_LABEL="Would you like to move languages to their own packages?" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGE_NOTE_DESCRIPTION="

Adding all your translations to your component can increase its size dramatically, so now you are able to move each extra language translation to its own installing package, leaving just your main language in the component.

Please note that this is only relevant if you actually have added extra translations to your component in the Language Translations area of JCB.

" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_ACTIVATE_LABEL="Activate" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_ACTIVATE_DESCRIPTION="Turn on the integration." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_YES="Yes" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NO="No" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_USE_PERCENTAGELANGUAGEADD_LABEL="Add Language Settings" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_USE_PERCENTAGELANGUAGEADD_DESCRIPTION="Select what option should be used" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_GLOBAL="Global" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LOCAL="Local" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_PERCENTAGELANGUAGEADD_LABEL="Add Language if %? ready." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_PERCENTAGELANGUAGEADD_DESCRIPTION="Select percentage any language should be translated before the system should add the language to the component during compilation." +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGES_KEEP_LABEL="Do want to keep some languages in your component?" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_NOTE_LANGUAGES_KEEP_DESCRIPTION="The JCB system main language will always be kept in your component. Select any of the other languages you would like to keep in your component. They will then be excluded from this language packaging option. (or leave blank for none)" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LANGUAGES_LABEL="Languages" +PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_LANGUAGES_DESCRIPTION="The JCB system main language will always be kept in your component. Select any of the other languages you would like to keep in your component. They will then be excluded from this language packaging option. (or leave blank for none)" \ No newline at end of file diff --git a/language/en-GB/index.html b/language/en-GB/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/language/en-GB/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/language/index.html b/language/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/language/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/rules/index.html b/rules/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/rules/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/script.php b/script.php new file mode 100644 index 0000000..8c1024b --- /dev/null +++ b/script.php @@ -0,0 +1,79 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +/** + * Content - Componentbuilder Language Tabs script file. + * + * @package PlgContentComponentbuilderLanguageTabs + */ +class plgContentComponentbuilderLanguageTabsInstallerScript +{ + + /** + * Called before any type of action + * + * @param string $route Which action is happening (install|uninstall|discover_install|update) + * @param JAdapterInstance $adapter The object responsible for running this script + * + * @return boolean True on success + */ + public function preflight($route, JAdapterInstance $adapter) + { + // get application + $app = JFactory::getApplication(); + + // the default for both install and update + $jversion = new JVersion(); + if (!$jversion->isCompatible('3.8.0')) + { + $app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error'); + return false; + } + + if ('install' === $route) + { + // check that componentbuilder is installed + $pathToCore = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'; + if (!JFile::exists($pathToCore)) + { + $app->enqueueMessage('Joomla Component Builder must first be installed from Joomla Component Builder.', 'error'); + return false; + } + // load the helper class + JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); + // block install + $blockInstall = true; + // check the version of JCB + $manifest = ComponentbuilderHelper::manifest(); + if (isset($manifest->version) && strpos($manifest->version, '.') !== false) + { + // get the version + $jcbVersion = explode('.', $manifest->version); + // check that we have JCB 2.10.13 or higher installed + if (count($jcbVersion) == 3 && $jcbVersion[0] >= 2 && $jcbVersion[1] >= 10 && (($jcbVersion[1] == 10 && $jcbVersion[2] >= 13) || ($jcbVersion[1] > 10))) + { + $blockInstall = false; + } + } + // allow install if all conditions are met + if ($blockInstall) + { + $app->enqueueMessage('Please upgrade to JCB 2.10.13 or higher before installing this plugin.', 'error'); + return false; + } + } + + return true; + } +}