Fixed gh-534 so that the correct comment is made in the module area with the GUI placeholders. First steps towards adding multi languages for both modules and plugins gh-503 gh-493 in JCB. Other small improvments to the date helper methods. Add the otpion to target the admin area with modules.
This commit is contained in:
176
admin/models/fields/excludedlanguages.php
Normal file
176
admin/models/fields/excludedlanguages.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 - 2020 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[] = '<a id="'.$button_code_name.'Create" class="btn btn-small btn-success hasTooltip" title="'.JText::sprintf('PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_CREATE_NEW_S', $button_label).'" style="border-radius: 0px 4px 4px 0px; padding: 4px 4px 4px 7px;"
|
||||
href="index.php?option=com_componentbuilder&view=language&layout=edit'.$ref.'" >
|
||||
<span class="icon-new icon-white"></span></a>';
|
||||
}
|
||||
// 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[] = '<a id="'.$button_code_name.'Edit" class="btn btn-small hasTooltip" title="'.JText::sprintf('PLG_CONTENT_COMPONENTBUILDERLANGUAGETABS_EDIT_S', $button_label).'" style="display: none; padding: 4px 4px 4px 7px;" href="#" >
|
||||
<span class="icon-edit"></span></a>';
|
||||
// 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 '<div class="input-append">' .$html . implode('',$button).'</div>';
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
@@ -36,33 +36,43 @@ class JFormFieldLang extends JFormFieldList
|
||||
protected function getOptions()
|
||||
{
|
||||
$db = JFactory::getDBO();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array('a.langtag','a.name'),array('langtag','language_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();
|
||||
// make sure the English GB is added
|
||||
$wasAdded = false;
|
||||
$options = array();
|
||||
if ($items)
|
||||
{
|
||||
$options[] = JHtml::_('select.option', '', 'Select an option');
|
||||
foreach($items as $item)
|
||||
{
|
||||
$options[] = JHtml::_('select.option', trim($item->langtag), $item->language_name . ' (' .$item->langtag.')');
|
||||
if ('en-GB' === trim($item->langtag))
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array('a.langtag','a.name'),array('langtag','language_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'));
|
||||
// make sure the main language is added
|
||||
$wasAdded = false;
|
||||
$options = array();
|
||||
if ($items)
|
||||
{
|
||||
$wasAdded = true;
|
||||
$options[] = JHtml::_('select.option', '', 'Select an option');
|
||||
foreach($items as $item)
|
||||
{
|
||||
$item->langtag = trim($item->langtag);
|
||||
$options[] = JHtml::_('select.option', $item->langtag, $item->language_name . ' (' .$item->langtag.')');
|
||||
if ($main_lang === $item->langtag)
|
||||
{
|
||||
$wasAdded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// now add it if not already added
|
||||
if (!$wasAdded)
|
||||
{
|
||||
$options[] = JHtml::_('select.option', 'en-GB', 'English GB (en-GB)');
|
||||
}
|
||||
return $options;
|
||||
// now add it if not already added (it must default to $main_lang)
|
||||
if (!$wasAdded)
|
||||
{
|
||||
if ('en-GB' === $main_lang)
|
||||
{
|
||||
$options[] = JHtml::_('select.option', $main_lang, 'English GB (' . $main_lang . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
$options[] = JHtml::_('select.option', $main_lang, 'Main Language (' . $main_lang . ')');
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@@ -100,15 +100,34 @@
|
||||
readonly="true"
|
||||
disabled="true"
|
||||
/>
|
||||
<!-- Plugins Field. Type: Joomlaplugins. (custom) -->
|
||||
<field
|
||||
type="joomlaplugins"
|
||||
name="plugins"
|
||||
label="COM_COMPONENTBUILDER_LANGUAGE_TRANSLATION_PLUGINS_LABEL"
|
||||
class="list_class span12"
|
||||
multiple="true"
|
||||
default="0"
|
||||
button="true"
|
||||
/>
|
||||
<!-- Modules Field. Type: Joomlamodules. (custom) -->
|
||||
<field
|
||||
type="joomlamodules"
|
||||
name="modules"
|
||||
label="COM_COMPONENTBUILDER_LANGUAGE_TRANSLATION_MODULES_LABEL"
|
||||
class="list_class span12"
|
||||
multiple="true"
|
||||
default="0"
|
||||
button="true"
|
||||
/>
|
||||
<!-- Components Field. Type: Components. (custom) -->
|
||||
<field
|
||||
type="components"
|
||||
name="components"
|
||||
label="COM_COMPONENTBUILDER_LANGUAGE_TRANSLATION_COMPONENTS_LABEL"
|
||||
class="list_class"
|
||||
class="list_class span12"
|
||||
multiple="true"
|
||||
default="0"
|
||||
required="true"
|
||||
button="false"
|
||||
/>
|
||||
<!-- Translation Field. Type: Subform. (joomla) -->
|
||||
@@ -141,7 +160,7 @@
|
||||
label="COM_COMPONENTBUILDER_LANGUAGE_TRANSLATION_LANGUAGE_LABEL"
|
||||
class="list_class"
|
||||
multiple="false"
|
||||
default="0"
|
||||
default="en-GB"
|
||||
required="true"
|
||||
button="false"
|
||||
/>
|
||||
|
@@ -29,7 +29,9 @@ class ComponentbuilderModelLanguage_translation extends JModelAdmin
|
||||
'fullwidth' => array(
|
||||
'source',
|
||||
'translation',
|
||||
'components'
|
||||
'components',
|
||||
'modules',
|
||||
'plugins'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -905,6 +907,18 @@ class ComponentbuilderModelLanguage_translation extends JModelAdmin
|
||||
$data['translation'] = '';
|
||||
}
|
||||
|
||||
// Set the plugins string to JSON string.
|
||||
if (isset($data['plugins']))
|
||||
{
|
||||
$data['plugins'] = (string) json_encode($data['plugins']);
|
||||
}
|
||||
|
||||
// Set the modules string to JSON string.
|
||||
if (isset($data['modules']))
|
||||
{
|
||||
$data['modules'] = (string) json_encode($data['modules']);
|
||||
}
|
||||
|
||||
// Set the components string to JSON string.
|
||||
if (isset($data['components']))
|
||||
{
|
||||
|
@@ -104,50 +104,13 @@ class ComponentbuilderModelLanguage_translations extends JModelList
|
||||
continue;
|
||||
}
|
||||
|
||||
// escape all strings if not being exported
|
||||
if (!isset($_export))
|
||||
{
|
||||
$item->source = ComponentbuilderHelper::htmlEscape($item->source, 'UTF-8', true, 150);
|
||||
}
|
||||
}
|
||||
}
|
||||
// show all languages that are already set for this string
|
||||
if (!isset($_export) && ComponentbuilderHelper::checkArray($items))
|
||||
{
|
||||
foreach ($items as $nr => &$item)
|
||||
{
|
||||
$langBucket = array();
|
||||
if (ComponentbuilderHelper::checkJson($item->translation))
|
||||
{
|
||||
$translations = json_decode($item->translation, true);
|
||||
if (ComponentbuilderHelper::checkArray($translations))
|
||||
{
|
||||
foreach ($translations as $language)
|
||||
{
|
||||
if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation'])
|
||||
&& isset($language['language']) && ComponentbuilderHelper::checkString($language['language']))
|
||||
{
|
||||
$langBucket[$language['language']] = $language['language'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// set how many component use this string
|
||||
$componentCounter = '';
|
||||
if (ComponentbuilderHelper::checkJson($item->components))
|
||||
{
|
||||
$item->components = json_decode($item->components, true);
|
||||
}
|
||||
if (ComponentbuilderHelper::checkArray($item->components))
|
||||
{
|
||||
$componentCounter = ' - <small>' . JText::_('COM_COMPONENTBUILDER_USED_IN') . ' ' . count($item->components) . '</small>';
|
||||
}
|
||||
// load the languages to the string
|
||||
if (ComponentbuilderHelper::checkArray($langBucket))
|
||||
{
|
||||
$item->source = '<small><em>(' . implode(', ', $langBucket) . ')</em></small> ' . ComponentbuilderHelper::htmlEscape($item->source, 'UTF-8', true, 150) . $componentCounter;
|
||||
}
|
||||
else
|
||||
{
|
||||
$item->source = '<small><em>(' . JText::_('COM_COMPONENTBUILDER_NOTRANSLATION') . ')</em></small> ' . ComponentbuilderHelper::htmlEscape($item->source, 'UTF-8', true, 150) . $componentCounter;
|
||||
}
|
||||
}
|
||||
}
|
||||
// prep the lang strings for export
|
||||
if (isset($_export) && $_export && ComponentbuilderHelper::checkArray($items))
|
||||
{
|
||||
@@ -157,6 +120,8 @@ class ComponentbuilderModelLanguage_translations extends JModelList
|
||||
{
|
||||
// remove some values completely
|
||||
unset($item->components);
|
||||
unset($item->modules);
|
||||
unset($item->plugins);
|
||||
unset($item->params);
|
||||
unset($item->published);
|
||||
unset($item->created_by);
|
||||
@@ -331,6 +296,11 @@ class ComponentbuilderModelLanguage_translations extends JModelList
|
||||
continue;
|
||||
}
|
||||
|
||||
// escape all strings if not being exported
|
||||
if (!isset($_export))
|
||||
{
|
||||
$item->source = ComponentbuilderHelper::htmlEscape($item->source, 'UTF-8', true, 150);
|
||||
}
|
||||
// unset the values we don't want exported.
|
||||
unset($item->asset_id);
|
||||
unset($item->checked_out);
|
||||
@@ -344,49 +314,7 @@ class ComponentbuilderModelLanguage_translations extends JModelList
|
||||
array_unshift($items,$headers);
|
||||
}
|
||||
|
||||
// show all languages that are already set for this string
|
||||
if (!isset($_export) && ComponentbuilderHelper::checkArray($items))
|
||||
{
|
||||
foreach ($items as $nr => &$item)
|
||||
{
|
||||
$langBucket = array();
|
||||
if (ComponentbuilderHelper::checkJson($item->translation))
|
||||
{
|
||||
$translations = json_decode($item->translation, true);
|
||||
if (ComponentbuilderHelper::checkArray($translations))
|
||||
{
|
||||
foreach ($translations as $language)
|
||||
{
|
||||
if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation'])
|
||||
&& isset($language['language']) && ComponentbuilderHelper::checkString($language['language']))
|
||||
{
|
||||
$langBucket[$language['language']] = $language['language'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// set how many component use this string
|
||||
$componentCounter = '';
|
||||
if (ComponentbuilderHelper::checkJson($item->components))
|
||||
{
|
||||
$item->components = json_decode($item->components, true);
|
||||
}
|
||||
if (ComponentbuilderHelper::checkArray($item->components))
|
||||
{
|
||||
$componentCounter = ' - <small>' . JText::_('COM_COMPONENTBUILDER_USED_IN') . ' ' . count($item->components) . '</small>';
|
||||
}
|
||||
// load the languages to the string
|
||||
if (ComponentbuilderHelper::checkArray($langBucket))
|
||||
{
|
||||
$item->source = '<small><em>(' . implode(', ', $langBucket) . ')</em></small> ' . ComponentbuilderHelper::htmlEscape($item->source, 'UTF-8', true, 150) . $componentCounter;
|
||||
}
|
||||
else
|
||||
{
|
||||
$item->source = '<small><em>(' . JText::_('COM_COMPONENTBUILDER_NOTRANSLATION') . ')</em></small> ' . ComponentbuilderHelper::htmlEscape($item->source, 'UTF-8', true, 150) . $componentCounter;
|
||||
}
|
||||
}
|
||||
}
|
||||
// prep the lang strings for export
|
||||
// prep the lang strings for export
|
||||
if (isset($_export) && $_export && ComponentbuilderHelper::checkArray($items))
|
||||
{
|
||||
// insure we have the same order in the languages
|
||||
@@ -395,6 +323,8 @@ class ComponentbuilderModelLanguage_translations extends JModelList
|
||||
{
|
||||
// remove some values completely
|
||||
unset($item->components);
|
||||
unset($item->modules);
|
||||
unset($item->plugins);
|
||||
unset($item->params);
|
||||
unset($item->published);
|
||||
unset($item->created_by);
|
||||
|
Reference in New Issue
Block a user