mod_templatechooser:
- mod_templatechooser.php
Kod PHP:
<?php
/**
* Template Chooser Module Entry Point
*
* @package Joomla
* @subpackage Modules
* @link http://templates.linkster.be/
* @license GNU/GPL, see LICENSE.php
* mod_templatechooser is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
global $mainframe;
$cur_template = $mainframe->getTemplate();
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
$chooserID = $module->id? $module->id : '0';
$titlelength = $params->get( 'title_length', 20 );
$preview_height = $params->get( 'preview_height', 90 );
$preview_width = $params->get( 'preview_width', 140 );
$show_preview = $params->get( 'show_preview', 0 );
$keep_cookie = $params->get( 'keep_cookie', 0 );
$moduleclass_sfx = $params->get('moduleclass_sfx')?$params->get('moduleclass_sfx'):'' ;
if (isset( $_POST["mod_change_template_".$chooserID])) {
modTemplateChooserHelper::setTemplate($_POST["mod_change_template_".$chooserID], $keep_cookie);
} else {
if (($keep_cookie == 1)&&(isset($_COOKIE["joomla_template"]))&&
($cur_template != $_COOKIE["joomla_template"])) {
$cookietemplate = $_COOKIE["joomla_template"];
modTemplateChooserHelper::setTemplate($cookietemplate, $keep_cookie);
}
}
$darray = modTemplateChooserHelper::getTemplates($params);
require( JModuleHelper::getLayoutPath( 'mod_templatechooser' ) );
?>
- helper.php
Kod PHP:
<?php
/**
* Helper class for Template Chooser module
*
* @package mod_templatechooser
* @subpackage Modules
* @link http://templates.linkster.be/
* @license GNU/GPL, see LICENSE.php
* mod_templatechooseris free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
class modTemplateChooserHelper
{
function setTemplate($newTemplate, $keepcookie)
{
global $mainframe;
// Initialize some variables
$_SESSION['template'] = $newTemplate;
// store in cookie if needed
if ($keepcookie == 1) {
setcookie("joomla_template", $newTemplate, time()+ (86400 * 365));
}
$uri =& JURI::getInstance();
$url = $uri->current();
$url .= '?';
$paramarray = $uri->getQuery(true);
foreach ($paramarray as $paramname => $paramvalue) {
if ($paramname != 'template') {
$url .= $paramname;
$url .= '=';
$url .= $paramvalue;
$url .= '&&';
}
}
$url .= 'template=';
$url .= $newTemplate;
$mainframe->redirect($url);
}
function getTemplates(&$params) {
// titlelength can be set in module params
$titlelength = $params->get( 'title_length', 20 );
$preview_height = $params->get( 'preview_height', 90 );
$preview_width = $params->get( 'preview_width', 140 );
$keep_cookie = $params->get( 'keep_cookie', 0 );
$show_preview = $params->get( 'show_preview', 0 );
// Read files from template directory
$template_path = "templates";
$templatefolder = @dir( $template_path );
$darray = array();
if ($templatefolder) {
while ($templatefile = $templatefolder->read()) {
if ($templatefile != "." && $templatefile != ".."&& $templatefile != "_system"&& $templatefile != "system" && $templatefile != ".svn" && $templatefile != "css" && is_dir( "$template_path/$templatefile" ) ) {
if ($params->get($templatefile, 1) == 1 ) {
$templatefile_new = $params->get($templatefile."_name") ? $params->get($templatefile."_name") : $templatefile;
if(strlen($templatefile_new) > $titlelength) {
$templatename = substr( $templatefile_new, 0, $titlelength-3 );
$templatename .= "...";
} else {
$templatename = $templatefile_new;
}
$darray[] = JHTML::_('select.option', $templatefile, $templatename );
}
}
}
$templatefolder->close();
}
sort( $darray );
return $darray;
}
}
plg_templatechooser
-templatechooser.php
Kod PHP:
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.event.plugin');
class plgSystemTemplateChooser extends JPlugin
{
function plgSystemTemplateChooser(&$subject, $config)
{
parent::__construct($subject,$config);
}
function onAfterInitialise()
{
global $mainframe;
if ($mainframe->isAdmin()) {
return;
}
if (isset($_SESSION['template'])&&($_SESSION['template']!='')) {
$mainframe->setTemplate($_SESSION['template']);
return true;
}
}
}
?>
Gdyby czegoś Wam brakowało to pliki leżą na serwerze: http://www.mylenium.pl/template_chooser.zip
Autor modułu twierdzi, że aby działał prawidłowo plg też musi być zainstalowany. Ja go wyłączyłem dziś dla testów i nie widzę różnicy.
Innych modułów umożliwiających ręczną zmianę templatki w "locie" przez odwiedzającego stronę w bazie extensions.joomla.org oprócz dwóch wymienionych w 1 poście nie znalazłem... Dziwią mnie też super oceny tych modułów. Najwidoczniej ci co z nich korzystają nie mają submenu i nie wymagają zapamiętywania wybranej skórki po wyłączeniu przeglądarki ;). Wtedy faktycznie sprawdzą się idealnie.