Imagina que quieres añadir a tu foro vBulletin una página con código HTML/PHP custom pero utilizando el sistema de plantillas de vBulletin. Para verlo, nada mejor que un ejemplo. Vamos a añadir una página de ‘Reglamento’ a nuestro foro.
Estos son los pasos que debes seguir:
Creación del fichero reglamento.php
Generamos un fichero llamado reglamento.php y lo subimos a la carpeta raiz de nuestro servidor. El contenido será tal que asi (sustituye ‘reglamento’ por el titulo de tu pagina. Ojo! Es case-sensitive)
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'reglamento');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('reglamento',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
$navbits = construct_navbits(array('' => 'Politica de privacidad'));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'Reglamento (titulo de mi página custom)';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('reglamento');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
?> |
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'reglamento');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('reglamento',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
$navbits = construct_navbits(array('' => 'Politica de privacidad'));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'Reglamento (titulo de mi página custom)';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('reglamento');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
?>
Creación de nueva plantilla (template)
Vamos al AdminControl Panel: ACP > Estilos y Plantillas > Administrar estilos, veremos el nombre del estilo que estamos utilizando en ese instante y en el desplegeable de la derecha pulsamos en ‘Añadir nueva plantilla’.
Nuestra plantilla se va a llamar ‘reglamento’ (el mismo nombre que le dimos antes dentro del fichero reglamento.php).
Pegamos el código de la plantilla, donde irá la parte del custom HTML/PHP:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
{vb:raw headinclude}
{vb:raw headinclude_bottom}
</head>
<body>
{vb:raw header}
{vb:raw navbar}
<div id="pagetitle">
<h1>{vb:raw pagetitle}</h1>
</div>
<h2 class="blockhead">Reglamento de mi foro vBulletin 4</h2>
<div class="blockbody">
<div class="blockrow">
<!-- AQUI EMPIEZA EL CUSTOM CODE -->
<!-- /AQUI TERMINA EL CUSTOM CODE -->
</div>
</div>
{vb:raw footer}
</body>
</html> |
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
{vb:raw headinclude}
{vb:raw headinclude_bottom}
</head>
<body>
{vb:raw header}
{vb:raw navbar}
<div id="pagetitle">
<h1>{vb:raw pagetitle}</h1>
</div>
<h2 class="blockhead">Reglamento de mi foro vBulletin 4</h2>
<div class="blockbody">
<div class="blockrow">
<!-- AQUI EMPIEZA EL CUSTOM CODE -->
<!-- /AQUI TERMINA EL CUSTOM CODE -->
</div>
</div>
{vb:raw footer}
</body>
</html>
Creación de plugins
A continuación creamos dos plugins: ACP > Plugins y productos > Agregar nuevo plugin
Crearemos uno llamado plugincustom1 con Ubicación de Enganche = online_location_process (curiosa traducción de hook) con el siguiente contenido y nos aseguraremos de marcarlo como activo:
switch ($filename)
{
case 'reglamento.php':
$userinfo['activity'] = 'Reglamento';
break;
// add more cases here if you have more than one custom page. no need for multiple plugins. one plugin can handle all.
} |
switch ($filename)
{
case 'reglamento.php':
$userinfo['activity'] = 'Reglamento';
break;
// add more cases here if you have more than one custom page. no need for multiple plugins. one plugin can handle all.
}
A continuación crearemos el plugincustom2 con Ubicación de enganche = online_location_unknown con el siguiente contenido y nos aseguramos de marcarlo como activo:
switch ($userinfo['activity'])
{
case 'Reglamento':
$userinfo['where'] = '<a href="reglamento.php?'.$vbulletin->session->vars[sessionurl].'">Reglamento</a>';
$userinfo['action'] = "Reglamento de mi foro vBulletin";
$handled = true;
break;
// add more cases here if you have more than one custom page. no need for multiple plugins. one plugin can handle all.
} |
switch ($userinfo['activity'])
{
case 'Reglamento':
$userinfo['where'] = '<a href="reglamento.php?'.$vbulletin->session->vars[sessionurl].'">Reglamento</a>';
$userinfo['action'] = "Reglamento de mi foro vBulletin";
$handled = true;
break;
// add more cases here if you have more than one custom page. no need for multiple plugins. one plugin can handle all.
}
Creación del enlace
Llegados a este punto ya podemos probar la URL de nuestro reglamento: http://www.misitioweb.com/reglamento.php debería funcionarnos. En este punto modificaremos la plantilla del punto 2 y meteremos nuestro custom code en ‘reglamento’.
A continuación querremos enlazar esta nueva página. Para ello, vamos a suponer que queremos enlazarla desde el menú de pie de página (gestionado por la plantilla footer) o la barra de navegación superior (gestionado por la plantilla navbar).
Si, por ejemplo, deseamos añadirlo a la barra de navegación: ACP > Estilos y plantillas > Administrar Estilos y en el desplegable de la derecha, elegiremos Editar plantillas, desplegamos ‘Navigation breadcrumb Plantillas‘ y seleccionamos ‘navbar‘.
Buscamos:
{vb:raw template_hook.navtab_end} |
{vb:raw template_hook.navtab_end}
Y lo cambiamos por:
<!-- nueva pestaña en navbar -->
<vb:if condition="THIS_SCRIPT == 'reglamento'">
<li class="selected"><a class="navtab" href="reglamento.php">Reglamento</a></li>
<vb:else />
<li><a class="navtab" href="reglamento.php">Reglamento</a></li>
</vb:if>
<!-- /nueva pestaña reglamento -->
{vb:raw template_hook.navtab_end} |
<!-- nueva pestaña en navbar -->
<vb:if condition="THIS_SCRIPT == 'reglamento'">
<li class="selected"><a class="navtab" href="reglamento.php">Reglamento</a></li>
<vb:else />
<li><a class="navtab" href="reglamento.php">Reglamento</a></li>
</vb:if>
<!-- /nueva pestaña reglamento -->
{vb:raw template_hook.navtab_end}
Y ya está 🙂