COMPLEMENTOS Cambiar Plantilla (Usuario) (Act 1.3) - Versión para impresión
+- PHPost | Soporte, Descargas y Tutoriales de Risus Nova (
https://phpost.es)
+-- Foro: Risus 1.3 (
https://phpost.es/foro-Risus-1-3)
+--- Foro: Complementos (
https://phpost.es/foro-Complementos)
+---- Foro: Complementos Terminados (
https://phpost.es/foro-Complementos-Terminados)
+---- Tema:
COMPLEMENTOS Cambiar Plantilla (Usuario) (Act 1.3) (
/tema-Complementos-Terminados-Cambiar-Plantilla-Usuario-Act-1-3)
Cambiar Plantilla (Usuario) (Act 1.3) -
Chctrpgo - 01-25-2021
DEMO
http://Registrate o inicia tu sesión para ver este contenido
Captura gif
[img]Registrate o inicia tu sesión para ver este contenido[/img]
En header.php
Buscar:
Código PHP:
// Configuraciones
$smarty->assign('tsConfig',$tsCore->settings);
Debajo agregar:
Código PHP:
// Configuraciones
$smarty->assign('tsThemes',$tsCore->getThemes());
En c.core.php --> inc --> class --> c.core.php
Buscar:
Código PHP:
function __construct()
{
// CARGANDO CONFIGURACIONES
$this->settings = $this->getSettings();
$this->settings['domain'] = str_replace('http://','',$this->settings['url']);
$this->settings['categorias'] = $this->getCategorias();
$this->settings['default'] = $this->settings['url'].'/themes/default';
$this->settings['tema'] = $this->getTema();
$this->settings['images'] = $this->settings['tema']['t_url'].'/images';
$this->settings['css'] = $this->settings['tema']['t_url'].'/css';
$this->settings['js'] = $this->settings['tema']['t_url'].'/js';
//
if($_GET['do'] == 'portal' || $_GET['do'] == 'posts') $this->settings['news'] = $this->getNews();
# Mensaje del instalador y pendientes de moderación #
$this->settings['install'] = $this->existinstall();
$this->settings['novemods'] = $this->getNovemods();
}
Reemplazar por:
Código PHP:
function __construct()
{
// CARGANDO CONFIGURACIONES
$this->settings = $this->getSettings();
$this->settings['domain'] = str_replace('http://','',$this->settings['url']);
$this->settings['categorias'] = $this->getCategorias();
$this->settings['default'] = $this->settings['url'].'/themes/default';
if(!isset($_COOKIE['tema']) || !file_exists(TS_ROOT.DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR.$_COOKIE['tema'])) {
$default = db_exec('fetch_array', db_exec(array(__FILE__, __LINE__), 'query', 'SELECT * FROM w_temas WHERE tid = '.$this->settings['tema_id']));
$_COOKIE['tema'] = $default['t_path'];
}
$this->settings['tema']['t_path'] = $_COOKIE['tema'];
$this->settings['tema']['t_url'] = $this->settings['url'].'/themes/'.$this->settings['tema']['t_path'];
$this->settings['images'] = $this->settings['tema']['t_url'].'/images';
$this->settings['css'] = $this->settings['tema']['t_url'].'/css';
$this->settings['js'] = $this->settings['tema']['t_url'].'/js';
//
if($_GET['do'] == 'portal' || $_GET['do'] == 'posts') $this->settings['news'] = $this->getNews();
# Mensaje del instalador y pendientes de moderación #
$this->settings['install'] = $this->existinstall();
$this->settings['novemods'] = $this->getNovemods();
}
Buscar:
Código PHP:
/*
getNews()
*/
function getNews()
{
//
$query = db_exec(array(__FILE__, __LINE__), 'query', 'SELECT not_body FROM w_noticias WHERE not_active = \'1\' ORDER by RAND()');
while($row = db_exec('fetch_assoc', $query)){
$row['not_body'] = $this->parseBBCode($row['not_body'],'news');
$data[] = $row;
}
//
return $data;
}
Debajo agregar:
Código PHP:
/*
getThemes()
*/
function getThemes(){
$query = db_exec(array(__FILE__, __LINE__), 'query', 'SELECT * FROM w_temas');
return result_array($query);
}
En c.smarty.php --> inc --> class --> c.smarty.php
Buscar:
Código PHP:
function __construct()
{
global $tsCore;
//
$this->template_dir = TS_ROOT.DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR.TS_TEMA.DIRECTORY_SEPARATOR.'templates';
$this->compile_dir = TS_ROOT.DIRECTORY_SEPARATOR.'cache';
$this->template_cb = array('url' => $tsCore->settings['url'], 'title' => $tsCore->settings['titulo']);
//
$this->_tpl_hooks = array();
}
Reemplazar por:
Código PHP:
function __construct()
{
global $tsCore;
//
$this->template_dir = TS_ROOT.DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR.TS_TEMA.DIRECTORY_SEPARATOR.'templates';
$this->compile_dir = TS_ROOT.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.TS_TEMA;
if(!file_exists($this->compile_dir)) mkdir($this->compile_dir);
$this->template_cb = array('url' => $tsCore->settings['url'], 'title' => $tsCore->settings['titulo']);
//
$this->_tpl_hooks = array();
}
Importante: Ahora este código debe estar en todas la plantillas, si no, solo se podría cambiar el theme desde una plantilla y desde las otras no.
Ejemplo en el footer
Buscar:
Código PHP:
<a href="{$tsConfig.url}/pages/dmca/">Report Abuse - DMCA</a>
Debajo agregar:
Código PHP:
<a class="blanco" onclick="change.menu();">Cambiar plantilla</a>
<style>
{literal}
.change_option { display: block; padding: 10px 15px; border-bottom: 1px solid #ccc; }
.change_option:first-child { border-top: 1px solid #ccc; }
.change_option:hover { background: #444; color: white; }
{/literal}
</style>
<script>
{literal}
var change = {
menu: function() {
mydialog.show();
mydialog.title('Cambiar plantilla');
mydialog.body('{/literal}{foreach from=$tsThemes item=t}<a class="change_option" onclick="change.theme({$t.tid})">{if $tsConfig.tema.t_path == $t.t_path}<img src="{$tsConfig.images}/tick-button.png" style="vertical-align: middle;">{/if} {$t.t_name}</a>{/foreach}{literal}');
mydialog.buttons(true, true, 'Cancelar', 'close', true);
mydialog.center();
},
theme: function(id) {
$.get(global_data.url+'/change.php?theme='+id).done(function() { window.location.reload(); });
}
};
{/literal}
</script>
Y subir esta carpeta
Mega
http://Registrate o inicia tu sesión para ver este contenido
Google Drive
http://Registrate o inicia tu sesión para ver este contenido
Mediafire
http://Registrate o inicia tu sesión para ver este contenido
Creditos: Rhuan
RE: Cambiar Plantilla (Usuario) (Act 1.3) -
vaniglia - 03-23-2021
en c.smarty.php, lo mas parecido que tengo es esto:
Código:
function tsSmarty() {
global $tsCore;
# necesario para que smarty pueda imprimir la plantilla
parent::__construct();
//
# setea los directorios para smarty
$this->setTemplateDir(TS_ROOT . DIRECTORY_SEPARATOR .'themes'. DIRECTORY_SEPARATOR . TS_TEMA . DIRECTORY_SEPARATOR . 'templates');
$this->setCompileDir(TS_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'templates_c');
$this->setCacheDir(TS_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'cache');
$this->setConfigDir(array(
'url' => $tsCore->settings['url'],
'title' => $tsCore->settings['titulo'])
);
# define si smarty esta en modo depuracion
$this->debugging = false;
# define la configuracion de cache
$this->caching = false;
# define tiempo de vida de cache, si esta activa
$this->cache_lifetime = 10;
# no se que es xd
$this->_tpl_hooks = array();
}
no puedo continuar desde ese punto editando
RE: Cambiar Plantilla (Usuario) (Act 1.3) -
Tronlar - 03-23-2021
Hola @
vaniglia , cambialo por esto
Código PHP:
function tsSmarty() {
global $tsCore;
# necesario para que smarty pueda imprimir la plantilla
parent::__construct();
//
# setea los directorios para smarty
$this->setTemplateDir(TS_ROOT . DIRECTORY_SEPARATOR .'themes'. DIRECTORY_SEPARATOR . TS_TEMA . DIRECTORY_SEPARATOR . 'templates');
$this->setCompileDir(TS_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR.TS_TEMA . 'templates_c');
$this->setCacheDir(TS_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'cache');
$this->setConfigDir(array(
'url' => $tsCore->settings['url'],
'title' => $tsCore->settings['titulo'])
);
RE: Cambiar Plantilla (Usuario) (Act 1.3) -
vaniglia - 03-24-2021
(03-23-2021, 08:18 AM)Tronlar escribió: Hola @ vaniglia , cambialo por esto
Código PHP:
function tsSmarty() {
global $tsCore;
# necesario para que smarty pueda imprimir la plantilla
parent::__construct();
//
# setea los directorios para smarty
$this->setTemplateDir(TS_ROOT . DIRECTORY_SEPARATOR .'themes'. DIRECTORY_SEPARATOR . TS_TEMA . DIRECTORY_SEPARATOR . 'templates');
$this->setCompileDir(TS_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR.TS_TEMA . 'templates_c');
$this->setCacheDir(TS_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'cache');
$this->setConfigDir(array(
'url' => $tsCore->settings['url'],
'title' => $tsCore->settings['titulo'])
);
muchas gracias, ahora pruebo
funciona muy bien!
por si sirve de aporte, el archivo footer está en
themes/<nombre del tema>/templates/sections/main_footer.tpl
por ejemplo:
themes/default/templates/sections/main_footer.tpl
y
/Flatpost/templates/sections/main_footer.tpl
RE: Cambiar Plantilla (Usuario) (Act 1.3) -
Anun55 - 01-19-2024
Gracias