Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last searchtools #39

Open
wants to merge 12 commits into
base: staging
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Receive overridable options
$data['options'] = !empty($data['options']) ? $data['options'] : array();

if ($data['view'] instanceof LanguagesViewInstalled)
if ($data['view'] instanceof LanguagesViewInstalled || $data['view'] instanceof LanguagesViewOverrides)
{
JFactory::getDocument()->addStyleDeclaration("
/* Fixed filter field in search bar */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$data = $displayData;

if ($data['view'] instanceof LanguagesViewInstalled)
if ($data['view'] instanceof LanguagesViewInstalled || $data['view'] instanceof LanguagesViewOverrides)
{
// We will get the client filter & remove it from the form filters
$clientIdField = $data['view']->filterForm->getField('client_id');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_languages
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_BASE') or die;

JFormHelper::loadFieldClass('list');

/**
* Form Field class for the Joomla Framework.
*
* @since 3.5.2
*/
class JFormFieldLanguageClient extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 3.5.2
*/
protected $type = 'LanguageClient';

/**
* Method to get the field options.
*
* @return array The field option objects
*
* @since 3.5.2
*/
protected function getOptions()
{
// Get client and language from the request to set the value.
$app = JFactory::getApplication();
$clientId = $app->getUserStateFromRequest('com_languages.overrides.client_id', 'client_id', 0, 'int');
$languageTag = $app->getUserStateFromRequest('com_languages.overrides.filter_language', 'filter_language', '', 'cmd');

// Get installed languages for the client.
$clientPath = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$languages = JLanguage::getKnownLanguages($clientPath);

$options = array();

foreach ($languages as $languageClientTag => $languageClient)
{
$options[] = JHtml::_('select.option', $languageClientTag, $languageClient['name']);
}

// Merge any additional options in the XML definition.
return array_merge(parent::getOptions(), $options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<field
name="client_id"
type="list"
label=""
onchange="this.form.submit();"
>
<option value="0">JSITE</option>
<option value="1">JADMINISTRATOR</option>
</field>
<fields name="filter">
<field
name="search"
type="text"
label="JSEARCH_FILTER"
description="COM_LANGUAGES_VIEW_OVERRIDES_FILTER_SEARCH_DESC"
hint="JSEARCH_FILTER"
/>
<field
name="language"
type="LanguageClient"
label="JOPTION_FILTER_LANGUAGE"
description="JOPTION_FILTER_LANGUAGE_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_LANGUAGE</option>
</field>
</fields>
<fields name="list">
<field
name="fullordering"
type="list"
onchange="this.form.submit();"
default="key ASC"
>
<option value="">JGLOBAL_SORT_BY</option>
<option value="key ASC">COM_LANGUAGES_VIEW_OVERRIDES_KEY_ASC</option>
<option value="key DESC">COM_LANGUAGES_VIEW_OVERRIDES_KEY_DESC</option>
<option value="text ASC">COM_LANGUAGES_VIEW_OVERRIDES_TEXT_ASC</option>
<option value="text DESC">COM_LANGUAGES_VIEW_OVERRIDES_TEXT_DESC</option>
<option value="language ASC">COM_LANGUAGES_HEADING_LANGUAGE_ASC</option>
<option value="language DESC">COM_LANGUAGES_HEADING_LANGUAGE_DESC</option>
<option value="language_tag ASC">COM_LANGUAGES_HEADING_LANG_TAG_ASC</option>
<option value="language_tag DESC">COM_LANGUAGES_HEADING_LANG_TAG_DESC</option>
</field>
<field
name="limit"
type="limitbox"
class="input-mini"
default="25"
onchange="this.form.submit();"
/>
</fields>
</form>
43 changes: 21 additions & 22 deletions administrator/components/com_languages/models/override.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ public function getForm($data = array(), $loadData = true)
return false;
}

$client = $this->getState('filter.client', 'site');
$language = $this->getState('filter.language', 'en-GB');
$langName = JLanguage::getInstance($language)->getName();
$clientId = (int) $this->getState('client_id');
$client = $clientId ? 'administrator' : 'site';
$clientPath = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$language = $this->getState('language');
$languageName = JLanguage::getInstance($language)->getName();

if (!$langName)
if (!$languageName)
{
// If a language only exists in frontend, it's meta data cannot be
// loaded in backend at the moment, so fall back to the language tag.
$langName = $language;
$languageName = $language;
}

$form->setValue('client', null, JText::_('COM_LANGUAGES_VIEW_OVERRIDE_CLIENT_' . strtoupper($client)));
$form->setValue('language', null, JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDE_LANGUAGE', $langName, $language));
$form->setValue('file', null, JPath::clean(constant('JPATH_' . strtoupper($client)) . '/language/overrides/' . $language . '.override.ini'));
$form->setValue('language', null, JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDE_LANGUAGE', $languageName, $language));
$form->setValue('file', null, JPath::clean($clientPath . '/language/overrides/' . $language . '.override.ini'));

return $form;
}
Expand Down Expand Up @@ -91,11 +93,11 @@ public function getItem($pk = null)
{
require_once JPATH_COMPONENT . '/helpers/languages.php';

$input = JFactory::getApplication()->input;
$pk = (!empty($pk)) ? $pk : $input->get('id');
$filename = constant('JPATH_' . strtoupper($this->getState('filter.client')))
. '/language/overrides/' . $this->getState('filter.language', 'en-GB') . '.override.ini';
$strings = LanguagesHelper::parseFile($filename);
$input = JFactory::getApplication()->input;
$pk = (!empty($pk)) ? $pk : $input->get('id');
$clientPath = (int) $this->getState('client_id') ? JPATH_ADMINISTRATOR : JPATH_SITE;
$filename = $clientPath . '/language/overrides/' . $this->getState('language') . '.override.ini';
$strings = LanguagesHelper::parseFile($filename);

$result = new stdClass;
$result->key = '';
Expand Down Expand Up @@ -126,13 +128,13 @@ public function save($data, $opposite_client = false)
require_once JPATH_COMPONENT . '/helpers/languages.php';
jimport('joomla.filesystem.file');

$client = $app->getUserState('com_languages.overrides.filter.client', 0);
$language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB');
$clientId = (int) $app->getUserStateFromRequest('com_languages.overrides.client_id', 'client_id', 0, 'int');
$language = $app->getUserStateFromRequest('com_languages.overrides.language', 'language', 'en-GB', 'cmd');

// If the override should be created for both.
if ($opposite_client)
{
$client = 1 - $client;
$clientId = 1 - $clientId;
}

// Return false if the constant is a reserved word, i.e. YES, NO, NULL, FALSE, ON, OFF, NONE, TRUE
Expand All @@ -145,10 +147,10 @@ public function save($data, $opposite_client = false)
return false;
}

$client = $client ? 'administrator' : 'site';
$clientPath = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;

// Parse the override.ini file in oder to get the keys and strings.
$filename = constant('JPATH_' . strtoupper($client)) . '/language/overrides/' . $language . '.override.ini';
$filename = $clientPath . '/language/overrides/' . $language . '.override.ini';
$strings = LanguagesHelper::parseFile($filename);

if (isset($strings[$data['id']]))
Expand Down Expand Up @@ -211,10 +213,7 @@ protected function populateState()
{
$app = JFactory::getApplication();

$client = $app->getUserStateFromRequest('com_languages.overrides.filter.client', 'filter_client', 0, 'int') ? 'administrator' : 'site';
$this->setState('filter.client', $client);

$language = $app->getUserStateFromRequest('com_languages.overrides.filter.language', 'filter_language', 'en-GB', 'cmd');
$this->setState('filter.language', $language);
$this->setState('client_id', $app->getUserStateFromRequest('com_languages.overrides.client_id', 'client_id', 0, 'int'));
$this->setState('language', $app->getUserStateFromRequest('com_languages.overrides.language', 'language', 'en-GB', 'cmd'));
}
}
Loading