vBulletin: Invalid Security Token [SOLVED]

Problem: After upgrading to vBulletin 3.8.5, I am getting this Invalid Security Token errors on the Mark Forums as read tool.

This fix is quite easy:

1. In your forumhome template, find:

<a href="forumdisplay.php?$session[sessionurl]do=markread rel="nofollow">$vbphrase[mark_forums_read]</a>

And replace with:

<a href="forumdisplay.php?$session[sessionurl]do=markread&amp;markreadhash=$bbuserinfo[securitytoken]" rel="nofollow">$vbphrase[mark_forums_read]</a>

2. In your navbar template (twice), find:

<td class="vbmenu_control"><a href="forumdisplay.php?$session[sessionurl]do=markread" rel="nofollow">$vbphrase[mark_forums_read]</a></td>

And replace with:

<a href="forumdisplay.php?$session[sessionurl]do=markread&amp;markreadhash=$bbuserinfo[securitytoken]" rel="nofollow">$vbphrase[mark_forums_read]</a>

If your search for those strings does not return any result, do the same search without rel=”nofollow”. This is:

FORUMHOME:

<a href="forumdisplay.php?$session[sessionurl]do=markread>$vbphrase[mark_forums_read]</a>

NAVBAR:

<td class="vbmenu_control"><a href="forumdisplay.php?$session[sessionurl]do=markread">$vbphrase[mark_forums_read]</a></td>

vBulletin 4: Disable plugin/mod per style [SOLVED]

Suppose you install a new vBulletin 4 plugin that affects all your styles. For instance, the Subforum maganer plugin I talked about some days ago.

This Subforum manager plugin does NOT work with the mobile style included in vBulletin 4.1.8.

If the mod has an on/off switch, then you can write a plugin to turn off the mod when using styleid xx. You can use the hook location style_fetch for that. If the mod doesn’t have an on/off switch, then you will need to put a condition around the modification plugins themselves to turn them off for styleid xx.

For instance, my mobile styleid is styleid=6 (if I type mysite.com/?styleid=6) I see the mobile theme.

Looking at the XML file for the product I want to disable for mobile style I notice this line which indicates there is indeed an option for activating/desactivating this product, $vbulletin->options[‘sub_forum_manager’]

<stylevardfns>
	</stylevardfns>
	<stylevars>
	</stylevars>
	<plugins>
		<plugin active="1" executionorder="5">
			<title>Sub-forum Manager (FORUMDISPLAY)</title>
			<hookname>forumdisplay_complete</hookname>
			<phpcode><![CDATA[if ( $vbulletin->options['sub_forum_manager'] )

I want to disable the product ‘Hasann – Sub-Forum Manager’ for styleid=6 so I write a new plugin like this:

Product: Hassan - Sub-Forum-Manager
Hook: style_fetch
Title: DisableHassanForMobileStyle
Order: 1
PHP Code:
if ($styleid == 6){
  $vbulletin->options['sub_forum_manager'] = 0;
}
Active plugin: YES

Job done!

vBulletin 4: Añadir páginas custom

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());
 
?>

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>

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.
}

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.
}

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}

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}

Y ya está 🙂

vBulletin: Non-www to www redirection [SOLVED]

Another common thing I usually do for my clients is to redirect non-www version of their vbulletin forums to www-version.

This can be easily achieved by creating a .htaccess file which contains:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

Just replace domain.com with your domain name and upload the file to the /public_html folder 🙂

If your forums are in a subfolder, i.e. /forum, you should put this .htaccess file IN that folder.
/forum/.htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/forum/$1 [R=301,L]

The sessions might not work (cookies issues) if you set the “forum url” (in “ACP -> Sitename/URL/Contact info”) to: domain.com instead of www.domain.com

Do not forget to check this if the sessions don’t work (this is, your login is right, but next time you click any link in the forum, you are unlogged)

vBulletin: How to list subforums in new line (not comma separated) [SOLVED]

List subforums in new lines can be achieved in vBulletin 4 just by making changes to CSS files.
If you are looking for the vBulletin3 way, check this link

EDIT: Just found this plugin which does the job and lets admin control the display of subforums in columns too! Cool, ain’t it?

To remove the commas between forums and separate them with a linea break in vBulletin 4, just edit your vbulletin.css and change from:

.commalist li {
	display:inline-block;
}
 
.commalist li:after {
/*	Comma + &nbsp; */
	content:",\0000A0";
}

To:

.commalist li {
        display:block;
}
 
.commalist li:after {
/*	 &nbsp; */
        content:" \0000A0";
}

Now, to add a line break after the “subforums: ” text, edit forumbits.css and change from:

.moderators h4, .moderators .commalist, .subforums h4, .subforums .commalist {
	float:{vb:stylevar left};
	clear:{vb:stylevar right};
}

To:

.moderators h4, .moderators .commalist, .subforums h4, .subforums .commalist {
	float:{vb:stylevar left};
        clear:both;
}

vBulletin 4.1.7 – Instalar spanish language pack [RESUELTO]

Muchas veces, las traducciones (aka language packs) de vBulletin salen bastante tiempo después que las versiones oficiales. Es por ello que, si descargamos la última versión de vBulletin para instalarla en nuestro sitio web, es posible que aun no tengamos disponible la última actualización de la traducción al español.

Hay una forma de engañar a vBulletin para que nos permita instalar un language pack de una versión que no corresponde con la instalada. Por ejemplo, suponed que tenéis instalado vBulletin 4.1.7 y disponéis del language pack de vBulletin 4.1.4.

Como sabéis, el language pack es un fichero .xml que importaremos a nuestro vBulletin siguiendo las instrucciones oficiales. Tal que asi:

Ir al panel de administración > Languages & Phrases > Download / Upload Languages.
Desde el recuadro Import Language XML File
    Darle al botón Browse... (Choose file en otros navegadores), localizar el archivo del lenguaje que has descargado
    Presionamos el botón Import y listo.

Podemos instalar una versión del langpack que no se corresponde con la instalada de vBulletin o bien marcando la opción Ignore Language Version a “Yes”. o bien editando directamente el fichero .xml del langpack y cambiándole la versión.

El fichero de la traducción a español de vBulletin 4.1.4 tiene esta pinta:

<?xml version="1.0" encoding="ISO-8859-1"?>
<language name="Español (ES)" vbversion="4.1.4" product="vbulletin" type="custom">
	<settings>
		<options><![CDATA[1]]></options>
		<languagecode><![CDATA[es]]></languagecode>
		<charset><![CDATA[ISO-8859-1]]></charset>
		<imagesoverride />
		<dateoverride><![CDATA[%d/%m/%Y]]></dat

Basta con cambiar la primera línea para que nos permita instalarlo como traducción al español de la versión 4.1.7:

<?xml version="1.0" encoding="ISO-8859-1"?>
<language name="Español (ES)" vbversion="4.1.7" product="vbulletin" type="custom">
	<settings>
		<options><![CDATA[1]]></options>
		<languagecode><![CDATA[es]]></languagecode>
		<charset><![CDATA[ISO-8859-1]]></charset>
		<imagesoverride />
		<dateoverride><![CDATA[%d/%m/%Y]]></dat

vBulletin 4: Add right or left sidebar [SOLVED]

A common question asked in forums is “how to add a right sidebar to vBulletin 4″. In vbulletin 3 this could be achieved by changing the templates or installing hacks (for instance, Ultimate Side Columns. In vb4 it is way easier.

Log in to admin panel (usually in http://yoursite.com/admincp), then:

ACP > SETTINGS > OPTIONS > FORUM SIDEBAR AND BLOCK OPTIONS

Once enabled set the side you want them to appear on. Do NOT change the setting at the bottom.
Then go to:

FORUMS AND MODERATORS > FORUM BLOCK MANAGER
From there click on > ADD BLOCK and select the block type you want to use.

There are several blocks preconfigured to use and you can also build your own custom PHP/HTML/text block.

vBA news module customization (avoid topic links display)

A client’s vBulletin board uses vbadvaced news module to display posts from a hidden forum. Every post is wrapped with adv_portal_module_wrapper.

My client did not want the topic links to be displayed, so he asked me to hack the code to achieve this.

Change adv_portal_module_wrapper

The adv_portal_module_wrapper you will find in you ACP —> style manager —> in the drop down for which ever style your working on pick edit templates —> vbadvanced cmps templates —> adv_portal_module_wrapper (should be located halfway down in the list of templates)

However you might want to copy that template and make a new one in case you need the default, you can add one by ACP —> style manager —> the add template. copy and paste your adv_portal_module_wrapper contents in for a starting point.

The following is the original code of adv_portal_module_wrapper:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$mods[formcode]
 
<div style="padding-bottom:$vba_style[portal_vspace]px">
	<table align="center" border="0" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%">
		<thead>
			<tr>
				<td class="tcat" colspan="$mods[colspan]">
				<if condition="$vba_style['portal_collapsemods']">
					<a href="#top" onclick="return toggle_collapse('module_$mods[collapse]')" style="float:$stylevar[right]"><img alt="" border="0" id="collapseimg_module_$mods[collapse]" src="$stylevar[imgdir_button]/collapse_tcat$modimgcollapse.gif" /></a>
				</if>
				<span class="smallfont"><strong>$vba_style[portal_blockbullet] <if condition="$mods['link']"><a href="$mods[link]">$mods[title]</a><else />$mods[title]</if></strong></span></td>
			</tr>
		</thead>
		<tbody id="collapseobj_module_$mods[collapse]" style="$modcollapse">
			<if condition="$show['tablerow']">
				<tr>
					<td class="$bgclass">
						$modulehtml
					</td>
				</tr>
			<else />
				$modulehtml
			</if>
		</tbody>
	</table>
</div>
<if condition="$show['endform']"></form></if>

I noticed the links where being created with the $mods[title] (refer to line 11). So where is this variable defined? Thanks to grep linux command I found out where it was assigned a value:

/includes/vba_cmps_include_top.php
/modules/news.php

In /modules/news.php there is this line, which gave me the clue on how to solve this issue

$mods['title'] = ($news['prefix'] ? $news['prefix'] : '') . ' <a href="' . $vbulletin->options['bburl'] . '/showthread.php?' . $vbulletin->session->vars['sessionurl'] . 't=' . $news['threadid'] . '">' . $news['title'] . '</a>';

So I thought I’d change the $mods[‘title’] call in adv_portal_module_wrapper to $news[‘title’], so my resulting copy of adv_portal_module_wrapper is called adv_portal_module_wrapper_miguel and is like follows (the only thing changed is line 11):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$mods[formcode]
<!-- adv_portal_module_wrapper_miguel -->
<div style="padding-bottom:$vba_style[portal_vspace]px">
	<table align="center" border="0" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%">
		<thead>
			<tr>
				<td class="tcat" colspan="$mods[colspan]">
				<if condition="$vba_style['portal_collapsemods']">
					<a href="#top" onclick="return toggle_collapse('module_$mods[collapse]')" style="float:$stylevar[right]"><img alt="" border="0" id="collapseimg_module_$mods[collapse]" src="$stylevar[imgdir_button]/collapse_tcat$modimgcollapse.gif" /></a>
				</if>
				<span class="smallfont"><strong>$vba_style[portal_blockbullet] $news[title]</strong></span></td>
			</tr>
		</thead>
		<tbody id="collapseobj_module_$mods[collapse]" style="$modcollapse">
			<if condition="$show['tablerow']">
				<tr>
					<td class="$bgclass">
						$modulehtml
					</td>
				</tr>
			<else />
				$modulehtml
			</if>
		</tbody>
	</table>
</div>
<if condition="$show['endform']"></form></if>