Posts tagged Joomla!

Joomla: Check if component content is empty

0

We use and love Blank Component to show pages without component but even with no title Blank Component still shows html code. This article describes the method used to fully remove component output.
(más…)

Joomla: Alternate category layouts

0

We were searching in Joomla content category layouts similar to K2 category templates. Since Joomla 1.6 this is possible.

In K2 it’s quite simple, you just set clone and rename the default template and assign it to category. In Joomla content the system is harder to set but it’s more powerful since you can override also category parameters and translation strings.

The information for this article was extrated from Joomla Docs: Layout overrides in Joomla 1.6 (más…)

Joomla: funciones para obtener la plantilla actual o por defecto

0

Compartimos dos nuevas funciones

Necesitábamos obtener el nombre de la plantilla actual o por defecto en Joomla. La plantilla actual es la plantilla asignada al Itemid del menú en el que nos encontramos. Cuando no hay Itemid o este no tiene asignada una plantilla específica se carga el nombre de la plantilla por defecto.

Un requisito de la implementación era que el código tenía que poderse usar en plugins. Esto invalida el método basado en el propio menú de Joomla que está más extendido por internet.

/**
* Get the name of the default themplate
* @author Jiden - Digital Disseny, S.L.
* @version 18/04/2012
*
* @param 0/1 $client_id - 0 frontend default | 1 backend default
*/
public function getDefaultTplName($client_id = 0) {
$result = null;
$db = JFactory::getDBO();
$query =  " SELECT template FROM #__template_styles "
." WHERE client_id=".(int)$client_id." "
." AND home = 1 ";
$db->setQuery($query);
try {
$result = $db->loadResult();
} catch (JDatabaseException $e) {
return $e;
}

return $result;
/**
* Get the name of the current template
* Works also @ plugins method
* @author Jiden - Digital Disseny, S.L.
* @version 23/04/2012
*
* @return string the name of the active template
*/
public function getCurrentTplName() {
// required objects
$app =& JFactory::getApplication();
$jinput = $app->input;
$db = JFactory::getDBO();
// default values
$menuParams = new JRegistry();
$client_id = $app->isSite() ? 0 : 1;
$itemId = $jinput->get('Itemid',0);
$tplName = null;

// try to load custom template if assigned
if ($itemId) {
$sql = " SELECT ts.template " .
" FROM #__menu as m " .
" INNER JOIN #__template_styles as ts" .
" ON ts.id = m.template_style_id " .
" WHERE m.id=".(int)$itemId." " .
"";
$db->setQuery($sql);
$tplName = $db->loadResult();
}
// if no itemId or no custom template assigned load default template
if( !$itemId || empty($tplName)) {
$tplName = getDefaultTplName($client_id);
}

return $tplName;
}
}

Joomla: functions to get current/default template

0

Today we are sharing two new functions.

We needed to get the current and the default Joomla templates. Current template is the template style assigned to the menu entry. Default template is template used when no template style is assigned to menus.

A requisite was that both methods must work on plugins so the alternative method based on menu object ( commonly seen on internet ) wasn’t valid for us.

/**
* Get the name of the default themplate
* @author Jiden - Digital Disseny, S.L.
* @version 18/04/2012
*
* @param 0/1 $client_id - 0 frontend default | 1 backend default
*/
public function getDefaultTplName($client_id = 0) {
$result = null;
$db = JFactory::getDBO();
$query =  " SELECT template FROM #__template_styles "
." WHERE client_id=".(int)$client_id." "
." AND home = 1 ";
$db->setQuery($query);
try {
$result = $db->loadResult();
} catch (JDatabaseException $e) {
return $e;
}

return $result;
/**
* Get the name of the current template
* Works also @ plugins method
* @author Jiden - Digital Disseny, S.L.
* @version 23/04/2012
*
* @return string the name of the active template
*/
public function getCurrentTplName() {
// required objects
$app =& JFactory::getApplication();
$jinput = $app->input;
$db = JFactory::getDBO();
// default values
$menuParams = new JRegistry();
$client_id = $app->isSite() ? 0 : 1;
$itemId = $jinput->get('Itemid',0);
$tplName = null;

// try to load custom template if assigned
if ($itemId) {
$sql = " SELECT ts.template " .
" FROM #__menu as m " .
" INNER JOIN #__template_styles as ts" .
" ON ts.id = m.template_style_id " .
" WHERE m.id=".(int)$itemId." " .
"";
$db->setQuery($sql);
$tplName = $db->loadResult();
}
// if no itemId or no custom template assigned load default template
if( !$itemId || empty($tplName)) {
$tplName = getDefaultTplName($client_id);
}

return $tplName;
}
}

Joomla: cargar archivos de idioma

0

En ocasiones queremos forzar la carga de un archivo de lenguaje determinado de un componente desde un módulo, plugin o similar.

En nuestro caso queríamos cargar en una librería archivos de lenguaje. El sistema es sencillo:

$lang =& JFactory::getLanguage();
$lang->load('lib_mylibrary', JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'mylibrary');

Esto cargaría los archivos de idioma actual desde lib/mylibrary/language

La función tiene parámetros adicionales para cargar un idioma en concreto o para forzar la recarga. Por ejemplo si quisiéramos forzar la carga del idioma español quedaría:

$lang =& JFactory::getLanguage();
$lang->load('lib_mylibrary', JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'mylibrary', 'es-ES', true);
Más información sobre la función de carga y sus parámetros:
JLanguage::load(string $extension, string $basePath, string $lang, boolean $reload, boolean $default)

Loads a single language file and appends the results to the existing strings

Parameters:
 
string $extension The extension for which a language file should be loaded.
 
string $basePath The basepath to use.
 
string $lang The language to load, default null for the current language.
 
boolean $reload Flag that will force a language to be reloaded if set to true.
 
boolean $default Flag that force the default language to be loaded if the current does not exist.
Returns:
  boolean True if the file has successfully loaded.
Since:
11.1

Joomla: get POST jForm variables sent with jInput

0

Method to receive with jInput the jForm $_POST variables in Joomla administration.

$jinput = JFactory::getApplication()->input;
$variables = $jinput->post->get('jform',array(),'ARRAY');

Joomla: función para obtener las posiciones de un template

0

Necesitábamos una función para cargar las posiciones disponibles en un template. Al no encontrar mucha información al respecto hemos decidido publicar la función resultante para ahorrar tiempo a quien pueda necesitarla.

/**
* Parse templateDetails.xml and get available positions
* @author Jiden - Digital Disseny, S.L.
* @version 04/04/2012
*
* @param string $tplPath - path of the current theme
* @param boolean $nameAsKey - set position name as output array key?
*
* @return array of positions
*/
function getTplPositions($tplPath, $nameAsKey = false) {
$outputArray = array();
$templateXML = $tplPath.'/templateDetails.xml';
// try to load positions from template XML file
$xml = JFactory::getXML($templateXML);
if (is_object($xml)) {
$positions = $xml->xpath('positions/position');
if ($positions) {
foreach ($positions as $position) {
$name = (string)$position->data();
// clean name
$name = preg_replace("/(\-a|\-b|\-c|\-d|\-e|\-f)$/i", "", $name);
// do not add duplicates
if(!in_array($name, $outputArray)) {
// use position name as array key?
if($nameAsKey) $outputArray[$name] = $name;
else $outputArray[] = $name;
}
}
}
}
return $outputArray;
}

Usaríamos la función así:

$tplPath = JPATH_SITE . '/templates/' . $this->template;
$positions = getTplPositions();
print_r($positions);

Y obtendríamos algo parecido a:

Array
(
    [0] => debug
    [1] => header-top
    [2] => header
    [3] => header-bottom
    [4] => topmenu
    [5] => rsidebar-top
    [6] => rsidebar
    [7] => rsidebar-bottom
    [8] => lsidebar-top
    [9] => lsidebar
    [10] => lsidebar-bottom
    [11] => main-top
    [12] => main
    [13] => main-bottom
    [14] => component-top
    [15] => component
    [16] => component-bottom
    [17] => footer-top
    [18] => footer
    [19] => footer-bottom

Esperamos haberte ahorrado algo de tiempo.

Joomla: function to get template positions

0

We needed a function to get available template positions. Didn’t found lot of info out there so we created our own function.

/**
* Parse templateDetails.xml and get available positions
* @author Jiden - Digital Disseny, S.L.
* @version 04/04/2012
*
* @param string $tplPath - path of the current theme
* @param boolean $nameAsKey - set position name as output array key?
*
* @return array of positions
*/
function getTplPositions($tplPath, $nameAsKey = false) {
$outputArray = array();
$templateXML = $tplPath.'/templateDetails.xml';
// try to load positions from template XML file
$xml = JFactory::getXML($templateXML);
if (is_object($xml)) {
$positions = $xml->xpath('positions/position');
if ($positions) {
foreach ($positions as $position) {
$name = (string)$position->data();
// clean name
$name = preg_replace("/(\-a|\-b|\-c|\-d|\-e|\-f)$/i", "", $name);
// do not add duplicates
if(!in_array($name, $outputArray)) {
// use position name as array key?
if($nameAsKey) $outputArray[$name] = $name;
else $outputArray[] = $name;
}
}
}
}
return $outputArray;
}

Now you can use the function as:

$tplPath = JPATH_SITE . '/templates/' . $this->template;
$positions = getTplPositions();
print_r($positions);

That will return  something like:

Array
(
    [0] => debug
    [1] => header-top
    [2] => header
    [3] => header-bottom
    [4] => topmenu
    [5] => rsidebar-top
    [6] => rsidebar
    [7] => rsidebar-bottom
    [8] => lsidebar-top
    [9] => lsidebar
    [10] => lsidebar-bottom
    [11] => main-top
    [12] => main
    [13] => main-bottom
    [14] => component-top
    [15] => component
    [16] => component-bottom
    [17] => footer-top
    [18] => footer
    [19] => footer-bottom

Solucionar errores com_installer , com_joomlaupdate tras actualizar Joomla a 2.5.4

6

Tras actualizar una de nuestras páginas de Joomla empezamos a apreciar un montón de errores en la administración parecidos a:

Error cargando Componente: com_joomlaupdate, 1
Error cargando Componente: com_installer, 1

Al parecer “algo” ha borrado los registros com_installer & com_joomlaupdate de la tabla #__extensions. Tras obtener los registros de un Joomla 2.5.4 recién instalado y restaurarlos en la base de datos que daba error desaparecen los mensajes de error.

Para solucionar el error ejecuta esta query de SQL reemplazando #__extensions con el nombre de tu tabla de extensiones. Por ejemplo si el prefijo de tu base de datos jml25_ sustituye #__extensions con jml25_extensions


INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES (10, 'com_installer', 'component', 'com_installer', '', 1, 1, 1, 1, '{"legacy":false,"name":"com_installer","type":"component","creationDate":"April 2006","author":"Joomla! Project","copyright":"(C) 2005 - 2012 Open Source Matters. All rights reserved.\\t","authorEmail":"admin@joomla.org","authorUrl":"www.joomla.org","version":"2.5.0","description":"COM_INSTALLER_XML_DESCRIPTION","group":""}', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES (28, 'com_joomlaupdate', 'component', 'com_joomlaupdate', '', 1, 1, 0, 1, '{"legacy":false,"name":"com_joomlaupdate","type":"component","creationDate":"February 2012","author":"Joomla! Project","copyright":"(C) 2005 - 2012 Open Source Matters. All rights reserved.\\t","authorEmail":"admin@joomla.org","authorUrl":"www.joomla.org","version":"2.5.0","description":"COM_JOOMLAUPDATE_XML_DESCRIPTION","group":""}', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

Espero que a alguien le ahorre algo de tiempo.

Solve com_installer , com_joomlaupdate errors after Joomla 2.5.4 upgrade

0

Just upgraded one of our Joomla sites and noticed that administration shows errors like:

Error loading Component: com_joomlaupdate, 1
Error loading Component: com_installer, 1

Seems that “something” deleted com_installer & com_joomlaupdate entries in the #__extensions table. I got the deleted values from a clean Joomla 2.5.4. install and after restoring them to the broken database all works fine again.

So to solve the problem you just have to run a sql query replacing #__extensions with your exact table name so if your database prefix is, for example, jml25_ replace #__extensions with jml25_extensions


INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES (10, 'com_installer', 'component', 'com_installer', '', 1, 1, 1, 1, '{"legacy":false,"name":"com_installer","type":"component","creationDate":"April 2006","author":"Joomla! Project","copyright":"(C) 2005 - 2012 Open Source Matters. All rights reserved.\\t","authorEmail":"admin@joomla.org","authorUrl":"www.joomla.org","version":"2.5.0","description":"COM_INSTALLER_XML_DESCRIPTION","group":""}', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES (28, 'com_joomlaupdate', 'component', 'com_joomlaupdate', '', 1, 1, 0, 1, '{"legacy":false,"name":"com_joomlaupdate","type":"component","creationDate":"February 2012","author":"Joomla! Project","copyright":"(C) 2005 - 2012 Open Source Matters. All rights reserved.\\t","authorEmail":"admin@joomla.org","authorUrl":"www.joomla.org","version":"2.5.0","description":"COM_JOOMLAUPDATE_XML_DESCRIPTION","group":""}', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

Hope this helps.

Go to Top