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

less $lang->load() part 1: tpl files backend and libraries/joomla/* #132

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions administrator/components/com_menus/models/menutypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ protected function getTypeOptionsFromLayouts($component, $view)
$layouts = array();
$layoutNames = array();
$templateLayouts = array();
$lang = JFactory::getLanguage();

// Get the layouts from the view folder.
$path = JPATH_SITE.'/components/'.$component.'/views/'.$view.'/tmpl';
Expand Down Expand Up @@ -300,10 +299,7 @@ protected function getTypeOptionsFromLayouts($component, $view)
{
if (JFolder::exists($folder . '/html/' . $component . '/' . $view)) {
$template = JFile::getName($folder);
$lang->load('tpl_'.$template.'.sys', JPATH_SITE, null, false, false)
|| $lang->load('tpl_'.$template.'.sys', JPATH_SITE.'/templates/'.$template, null, false, false)
|| $lang->load('tpl_'.$template.'.sys', JPATH_SITE, $lang->getDefault(), false, false)
|| $lang->load('tpl_'.$template.'.sys', JPATH_SITE.'/templates/'.$template, $lang->getDefault(), false, false);
JFactory::getLanguage()->load('tpl_'.$template.'.sys', array(JPATH_SITE, JPATH_SITE.'/templates/'.$template), true, false, false);

$templateLayouts = JFolder::files($folder . '/html/' . $component . '/' . $view, '.xml$', false, true);

Expand Down
6 changes: 1 addition & 5 deletions administrator/components/com_menus/views/items/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ public function display($tpl = null)
$temp = explode(':', $vars['layout']);
$file = JPATH_SITE.'/templates/'.$temp[0].'/html/'.$item->componentname.'/'.$vars['view'].'/'.$temp[1].'.xml';
// Load template language file
$lang->load('tpl_'.$temp[0].'.sys', JPATH_SITE, null, false, false)
|| $lang->load('tpl_'.$temp[0].'.sys', JPATH_SITE.'/templates/'.$temp[0], null, false, false)
|| $lang->load('tpl_'.$temp[0].'.sys', JPATH_SITE, $lang->getDefault(), false, false)
|| $lang->load('tpl_'.$temp[0].'.sys', JPATH_SITE.'/templates/'.$temp[0], $lang->getDefault(), false, false);

$lang->load('tpl_'.$temp[0].'.sys', array(JPATH_SITE, JPATH_SITE.'/templates/'.$temp[0]), true, false, false);
}
else
{
Expand Down
5 changes: 1 addition & 4 deletions administrator/components/com_modules/models/positions.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ public function getItems()
$xml = simplexml_load_file($path);
if (isset($xml->positions[0]))
{
$lang->load('tpl_'.$template->element.'.sys', $client->path, null, false, false)
|| $lang->load('tpl_'.$template->element.'.sys', $client->path.'/templates/'.$template->element, null, false, false)
|| $lang->load('tpl_'.$template->element.'.sys', $client->path, $lang->getDefault(), false, false)
|| $lang->load('tpl_'.$template->element.'.sys', $client->path.'/templates/'.$template->element, $lang->getDefault(), false, false);
$lang->load('tpl_'.$template->element.'.sys', array($client->path, $client->path.'/templates/'.$template->element), true, false, false);
foreach ($xml->positions[0] as $position)
{
$value = (string)$position['value'];
Expand Down
6 changes: 1 addition & 5 deletions administrator/components/com_templates/models/style.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ protected function preprocessForm(JForm $form, $data, $group = 'content')
// Initialise variables.
$clientId = $this->getState('item.client_id');
$template = $this->getState('item.template');
$lang = JFactory::getLanguage();
$client = JApplicationHelper::getClientInfo($clientId);
if (!$form->loadFile('style_'.$client->name, true)) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
Expand All @@ -325,10 +324,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content')
$formFile = JPath::clean($client->path.'/templates/'.$template.'/templateDetails.xml');

// Load the core and/or local language file(s).
$lang->load('tpl_'.$template, $client->path, null, false, false)
|| $lang->load('tpl_'.$template, $client->path.'/templates/'.$template, null, false, false)
|| $lang->load('tpl_'.$template, $client->path, $lang->getDefault(), false, false)
|| $lang->load('tpl_'.$template, $client->path.'/templates/'.$template, $lang->getDefault(), false, false);
JFactory::getLanguage()->load('tpl_'.$template, array($client->path,$client->path.'/templates/'.$template), true, false, true);

if (file_exists($formFile)) {
// Get the template form.
Expand Down
10 changes: 5 additions & 5 deletions administrator/components/com_templates/models/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ public function getFiles()
{
// Initialise variables.
$result = array();
$standard = JFactory::getApplication()->getTemplate();

if ($template = $this->getTemplate()) {
jimport('joomla.filesystem.folder');

$client = JApplicationHelper::getClientInfo($template->client_id);
$path = JPath::clean($client->path.'/templates/'.$template->element.'/');
$lang = JFactory::getLanguage();

// Load the core and/or local language file(s).
$lang->load('tpl_'.$template->element, $client->path, null, false, false)
|| $lang->load('tpl_'.$template->element, $client->path.'/templates/'.$template->element, null, false, false)
|| $lang->load('tpl_'.$template->element, $client->path, $lang->getDefault(), false, false)
|| $lang->load('tpl_'.$template->element, $client->path.'/templates/'.$template->element, $lang->getDefault(), false, false);
if ($template->element !== $standard)
{
JFactory::getLanguage()->load('tpl_'.$template->element, $client->path, true, false, false);
}

// Check if the template path exists.

Expand Down
5 changes: 1 addition & 4 deletions libraries/joomla/application/component/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ public static function renderComponent($option, $params = array())
// Load template language files.
$template = $app->getTemplate(true)->template;
$lang = JFactory::getLanguage();
$lang->load('tpl_' . $template, JPATH_BASE, null, false, false)
|| $lang->load('tpl_' . $template, JPATH_THEMES . "/$template", null, false, false)
|| $lang->load('tpl_' . $template, JPATH_BASE, $lang->getDefault(), false, false)
|| $lang->load('tpl_' . $template, JPATH_THEMES . "/$template", $lang->getDefault(), false, false);
$lang->load('tpl_' . $template, array(JPATH_BASE, JPATH_THEMES . "/{$template}"), true);

if (empty($option))
{
Expand Down
6 changes: 1 addition & 5 deletions libraries/joomla/application/component/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,7 @@ public function loadTemplate($tpl = null)
$tpl = isset($tpl) ? preg_replace('/[^A-Z0-9_\.-]/i', '', $tpl) : $tpl;

// Load the language file for the template
$lang = JFactory::getLanguage();
$lang->load('tpl_' . $template, JPATH_BASE, null, false, false)
|| $lang->load('tpl_' . $template, JPATH_THEMES . "/$template", null, false, false)
|| $lang->load('tpl_' . $template, JPATH_BASE, $lang->getDefault(), false, false)
|| $lang->load('tpl_' . $template, JPATH_THEMES . "/$template", $lang->getDefault(), false, false);
JFactory::getLanguage()->load('tpl_' . $template, array(JPATH_BASE, JPATH_THEMES . "/$template"), true, false, false);

// Change the template folder if alternative layout is in different template
if (isset($layoutTemplate) && $layoutTemplate != '_' && $layoutTemplate != $template)
Expand Down
12 changes: 4 additions & 8 deletions libraries/joomla/application/module/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,7 @@ public static function renderModule($module, $attribs = array())
// $module->user is a check for 1.0 custom modules and is deprecated refactoring
if (empty($module->user) && file_exists($path))
{
$lang = JFactory::getLanguage();
// 1.5 or Core then 1.6 3PD
$lang->load($module->module, JPATH_BASE, null, false, false) ||
$lang->load($module->module, dirname($path), null, false, false) ||
$lang->load($module->module, JPATH_BASE, $lang->getDefault(), false, false) ||
$lang->load($module->module, dirname($path), $lang->getDefault(), false, false);
JFactory::getLanguage()->load($module->module, array(JPATH_BASE, dirname($path)), true, false, true);

$content = '';
ob_start();
Expand Down Expand Up @@ -349,8 +344,9 @@ protected static function &_load()
{
$module = &$modules[$i];

// The module is excluded if there is an explicit prohibition
$negHit = ($negId === (int) $module->menuid);
// The module is excluded if there is an explicit prohibition or if
// the Itemid is missing or zero and the module is in exclude mode.
$negHit = ($negId === (int) $module->menuid) || (!$negId && (int) $module->menuid < 0);

if (isset($dupes[$module->id]))
{
Expand Down
8 changes: 1 addition & 7 deletions libraries/joomla/document/html/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,7 @@ protected function _fetchTemplate($params = array())
}

// Load the language file for the template
$lang = JFactory::getLanguage();
// 1.5 or core then 1.6

$lang->load('tpl_' . $template, JPATH_BASE, null, false, false)
|| $lang->load('tpl_' . $template, $directory . '/' . $template, null, false, false)
|| $lang->load('tpl_' . $template, JPATH_BASE, $lang->getDefault(), false, false)
|| $lang->load('tpl_' . $template, $directory . '/' . $template, $lang->getDefault(), false, false);
JFactory::getLanguage()->load('tpl_' . $template, array(JPATH_BASE, $directory . '/' . $template), true, false, false);

// Assign the variables
$this->template = $template;
Expand Down
10 changes: 2 additions & 8 deletions libraries/joomla/form/fields/componentlayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,7 @@ protected function getInput()
foreach ($templates as $template)
{
// Load language file
$lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false)
|| $lang->load(
'tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false
);
$lang->load('tpl_' . $template->element . '.sys', array($client->path, $client->path . '/templates/' . $template->element), true, false, false);

$template_path = JPath::clean($client->path . '/templates/' . $template->element . '/html/' . $extn . '/' . $view);

Expand Down Expand Up @@ -219,8 +214,7 @@ protected function getInput()
{
// Add an option to the template group
$value = JFile::stripext(JFile::getName($file));
$text = $lang
->hasKey($key = strtoupper('TPL_' . $template->name . '_' . $extn . '_' . $view . '_LAYOUT_' . $value))
$text = $lang->hasKey($key = strtoupper('TPL_' . $template->name . '_' . $extn . '_' . $view . '_LAYOUT_' . $value))
? JText::_($key) : $value;
$groups[$template->name]['items'][] = JHtml::_('select.option', $template->element . ':' . $value, $text);
}
Expand Down
8 changes: 1 addition & 7 deletions libraries/joomla/form/fields/modulelayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ protected function getInput()
foreach ($templates as $template)
{
// Load language file
$lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false)
|| $lang->load(
'tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(),
false, false
);
$lang->load('tpl_' . $template->element . '.sys', array($client->path, $client->path . '/templates/' . $template->element), true, false, false);

$template_path = JPath::clean($client->path . '/templates/' . $template->element . '/html/' . $module);

Expand Down
5 changes: 1 addition & 4 deletions libraries/joomla/form/fields/templatestyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ protected function getGroups()
foreach ($styles as $style)
{
$template = $style->template;
$lang->load('tpl_' . $template . '.sys', $client->path, null, false, false)
|| $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template, null, false, false)
|| $lang->load('tpl_' . $template . '.sys', $client->path, $lang->getDefault(), false, false)
|| $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template, $lang->getDefault(), false, false);
$lang->load('tpl_' . $template . '.sys', array($client->path, $client->path . '/templates/' . $template), true, false, false);
$name = JText::_($style->name);
// Initialize the group if necessary.
if (!isset($groups[$name]))
Expand Down
82 changes: 51 additions & 31 deletions libraries/joomla/language/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,60 +700,80 @@ public static function exists($lang, $basePath = JPATH_BASE)
}

/**
* Loads a single language file and appends the results to the existing strings
* Loads a single language file and appends the results to the existing strings.
*
* @param string $extension The extension for which a language file should be loaded.
* @param string $basePath The basepath to use.
* @param string $lang The language to load, default null for the current language.
* @param mixed $basePath The basepath to use, or an array/iterable object with paths
* @param string $lang The language to load, default TRUE for the current language.
* @param boolean $reload Flag that will force a language to be reloaded if set to true.
* @param boolean $default Flag that force the default language to be loaded if the current does not exist.
*
* @return boolean True if the file has successfully loaded.
*
* @since 11.1
*/
public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = null, $reload = false, $default = true)
public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = true, $reload = false, $default = true)
{
if (!$lang)
// testing null for BC with !lang
if ($lang === true || $lang === null)
{
// use current
$lang = $this->lang;
if ($default == true && ($lang == $this->default))
{
// current IS the default, no need to force it
$default == false;
}
}

$path = self::getLanguagePath($basePath, $lang);

$internal = $extension == 'joomla' || $extension == '';
$filename = $internal ? $lang : $lang . '.' . $extension;
$filename = "$path/$filename.ini";
if (is_string($basePath))
{
$basePath = array($basePath);
}

$result = false;
$stack = array();

if (isset($this->paths[$extension][$filename]) && !$reload)
while ($base = array_shift($basePath))
{
// This file has already been tested for loading.
$result = $this->paths[$extension][$filename];
}
else
{
// Load the language file
$result = $this->loadLanguage($filename, $extension);
$stack[] = $base;

// Check whether there was a problem with loading the file
if ($result === false && $default)
// one path matched, no need to iterate further
if ($result == true)
{
// No strings, so either file doesn't exist or the file is invalid
$oldFilename = $filename;
break;
}

// Check the standard file name
$path = self::getLanguagePath($basePath, $this->default);
$filename = $internal ? $this->default : $this->default . '.' . $extension;
$filename = "$path/$filename.ini";
$path = self::getLanguagePath($base, $lang);

// If the one we tried is different than the new name, try again
if ($oldFilename != $filename)
{
$result = $this->loadLanguage($filename, $extension, false);
}
$internal = $extension == 'joomla' || $extension == '';
$filename = $internal ? $lang : $lang . '.' . $extension;
$filename = "$path/$filename.ini";

$result = false;

if (isset($this->paths[$extension][$filename]) && !$reload)
{
// This file has already been tested for loading.
$result = $this->paths[$extension][$filename];
break;
}

// Load the language file
$result = $this->loadLanguage($filename, $extension);
}

// Check whether there was a problem with loading the file
if ($result === false && $default)
{
// refill
if (count($basePath))
{
$stack = $stack + $basePath;
}

// Check the standard file name and default language
$result = $this->load($extension, $stack, $this->default, $reload, $default);
}

return $result;
Expand Down