Skip to content

Instantly share code, notes, and snippets.

View sergiois's full-sized avatar

Sergio Iglesias sergiois

View GitHub Profile
@sergiois
sergiois / password_joomla.php
Last active December 22, 2015 04:18
Función que permite generar una contraseña tal cual la crea el Core de Joomla!
<?php
function joomlaPassword($password) {
$password= base64_decode($password);
$salt = md5(mt_rand());
$encrypt = md5($password . $salt);
return $encrypt . ':' . $salt;
}
?>
@sergiois
sergiois / categories_joomla.php
Last active December 22, 2015 04:19
Función que permite recoger las categorías de Joomla! y mostrarlas en un select
<?php
public function getCats()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('a.id, a.title, a.level');
$query->from('#__categories AS a');
$query->join('LEFT', $db->quoteName('#__categories').' AS b ON a.lft > b.lft AND a.rgt where('a.extension = "com_content"');
$query->where('a.published IN (0,1)');
@sergiois
sergiois / image_introtext_joomla.php
Last active December 22, 2015 04:19
Función para coger y quitar la primera imagen del introtext de Joomla! (texto que va hasta el readmore)
<?php
// cogemos imagen de introtext
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $this->item->introtext, $src);
$first_img = $src[1][0];
if(!empty($src[1][0])){
echo '<div class="first_img"><img src="'.$src[1][0].'" alt="" /></div>';
}
// quitamos todas las imágenes de introtext
$re_cleanImages = '/<img[^>]*>/';
$myCleanHtml = preg_replace($re_cleanImages,'',$this->item->introtext);
@sergiois
sergiois / link_introtext_joomla.php
Last active December 22, 2015 04:19
Función para eliminar enlaces y recortar el introtext de Joomla! (texto que va hasta el readmore) + Añadimos nuevo código para que en el recorte la última palabra, si tiene caracteres especiales, se vea bien. + Añadimos nuevo código para que en el recorte aparezca la última palabra completa.
@sergiois
sergiois / parameters_module_joomla.php
Last active December 22, 2015 04:28
Como cargar los parámetros de un módulo en Joomla! 2.5
<?php
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mymodulename');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
// Ahora podemos llamar al parámetro
$param = $moduleParams->get('paramName', 'defaultValue');
?>
@sergiois
sergiois / jquery_joomla.php
Last active December 22, 2015 04:29
Joomla! 3.0 ha introducido jQuery como característica principal en el Core. Las extensiones de terceros ya no necesitan cargar jQuery, debido a que ya se suministra con Joomla!. La única cosa que extensiones requieren una simple llamada a la clase JHTML:
<?php
JHtml::_('jquery.framework');
?>
@sergiois
sergiois / url_joomla.php
Last active December 22, 2015 04:29
Conseguir la ruta absoluta de un URL en Joomla
<?php
$uri = & JFactory::getURI();
$absolute_url = $uri->toString();
echo $absolute_url;
?>
@sergiois
sergiois / frontpage_joomla.php
Last active December 22, 2015 04:29
Cómo saber si estamos en la página de inicio de Joomla
// Básico
<?php $menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
} ?>
// Multi-idioma
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
@sergiois
sergiois / id_url_jooma.php
Last active December 22, 2015 04:29
Quitar id en urls amigables de Joomla
<?php
// Editar fichero components\com_content\router.php
// Dentro de función ContentBuildRoute(&$query)
// Cambiar $advanced = $params->get('sef_advanced_link', 0); por
$advanced = $params->get('sef_advanced_link', 1);
// Dentro de función ContentParseRoute($segments)
// Cambiar $advanced = $params->get('sef_advanced_link', 0); por
$advanced = $params->get('sef_advanced_link', 1);
@sergiois
sergiois / constantes_joomla.php
Created October 4, 2013 19:34
Constantes que facilitan la tarea de accesos a distintas partes del CMS Joomla!
<?php
JPATH_ADMINISTRATOR The path to the administrator folder.
JPATH_BASE The path to the installed Joomla! site.
JPATH_CACHE The path to the cache folder.
JPATH_COMPONENT The path to the current component being executed.
JPATH_COMPONENT_ADMINISTRATOR The path to the administration folder of the current component being executed.
JPATH_COMPONENT_SITE The path to the site folder of the current component being executed.
JPATH_CONFIGURATION The path to folder containing the configuration.php file.
JPATH_INSTALLATION The path to the installation folder.
JPATH_LIBRARIES The path to the libraries folder.