- Desde
- 6 Sep 2008
- Mensajes
- 959
Ejemplo Practico
Un Ejemplo de como funciona seria el siguiente (El Codigo no es real)
PHP:
//Mi Archivo.php que me muestra los usuarios en linea
$usar_postbit_legancy=$opciones_vbulletin['valor_configurado'];
llamar_a_hook('postbit_display_start'); //Hook
funcion_procesar_postbit();
llamar_a_hook('postbit_display_complete'); //Hook
imprimir_plantilla('postbit_template');
Ahora, supongamos que he hecho un plugin con el siguiente codigo:
PHP:
if ($usuario['grupo']=='Administrador')
{
$usar_postbit_legancy='LEGANCY';
}
else
{
$usar_postbit_legancy=$opciones_vbulletin['valor_configurado'];
}
Para los que dijeron postbit_display_start Felicitaciones; usamos ese hook porque vamos a CONFIGURAR la forma de la plantilla y debe ser antes de PROCESARLA, de ahi que uno siempre escucha: "USANDO EL HOOK CORRECTO".... nuestro codigo cuando se ejecute (por el hook) será internamente asi:
PHP:
//Mi Archivo.php que me muestra los usuarios en linea
$usar_postbit_legancy=$opciones_vbulletin['valor_configurado'];
if ($usuario['grupo']=='Administrador')
{
$usar_postbit_legancy='LEGANCY';
}
else
{
$usar_postbit_legancy=$opciones_vbulletin['valor_configurado'];
}
funcion_procesar_postbit();
llamar_a_hook('postbit_display_complete'); //Hook
imprimir_plantilla('postbit_template');
************************************************
Ejemplo Real
Abran el archivo showthread.php linea 1000 aproximadamente y van a encontrar
PHP:
$hook_query_fields = $hook_query_joins = '';
($hook = vBulletinHook::fetch_hook('showthread_query')) ? eval($hook) : false;
$posts = $db->query_read("
SELECT
post.*, post.username AS postusername, post.ipaddress AS ip, IF(post.visible = 2, 1, 0) AS isdeleted,
user.*, userfield.*, usertextfield.*,
" . iif($forum['allowicons'], 'icon.title as icontitle, icon.iconpath,') . "
" . iif($vbulletin->options['avatarenabled'], 'avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight,') . "
" . ((can_moderate($thread['forumid'], 'canmoderateposts') OR can_moderate($thread['forumid'], 'candeleteposts')) ? 'spamlog.postid AS spamlog_postid,' : '') . "
" . iif($deljoin, 'deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason,') . "
editlog.userid AS edit_userid, editlog.username AS edit_username, editlog.dateline AS edit_dateline,
editlog.reason AS edit_reason, editlog.hashistory,
postparsed.pagetext_html, postparsed.hasimages,
sigparsed.signatureparsed, sigparsed.hasimages AS sighasimages,
sigpic.userid AS sigpic, sigpic.dateline AS sigpicdateline, sigpic.width AS sigpicwidth, sigpic.height AS sigpicheight,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
" . iif(!($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehiddencustomfields']), $vbulletin->profilefield['hidden']) . "
$hook_query_fields
FROM " . TABLE_PREFIX . "post AS post
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = post.userid)
LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON(userfield.userid = user.userid)
LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
" . iif($forum['allowicons'], "LEFT JOIN " . TABLE_PREFIX . "icon AS icon ON(icon.iconid = post.iconid)") . "
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "
" . ((can_moderate($thread['forumid'], 'canmoderateposts') OR can_moderate($thread['forumid'], 'candeleteposts')) ? "LEFT JOIN " . TABLE_PREFIX . "spamlog AS spamlog ON(spamlog.postid = post.postid)" : '') . "
$deljoin
LEFT JOIN " . TABLE_PREFIX . "editlog AS editlog ON(editlog.postid = post.postid)
LEFT JOIN " . TABLE_PREFIX . "postparsed AS postparsed ON(postparsed.postid = post.postid AND postparsed.styleid = " . intval(STYLEID) . " AND postparsed.languageid = " . intval(LANGUAGEID) . ")
LEFT JOIN " . TABLE_PREFIX . "sigparsed AS sigparsed ON(sigparsed.userid = user.userid AND sigparsed.styleid = " . intval(STYLEID) . " AND sigparsed.languageid = " . intval(LANGUAGEID) . ")
LEFT JOIN " . TABLE_PREFIX . "sigpic AS sigpic ON(sigpic.userid = post.userid)
$hook_query_joins
WHERE $postids
ORDER BY post.dateline $postorder
");
la llamada de plugin en plantillas es:
PHP:
($hook = vBulletinHook::fetch_hook('NOMBRE_HOOK')) ? eval($hook) : false;
_____________________________
(1)Nota programadores: Un hook en vBulletin es equivalente a un require, es decir llama a un codigo externo, solo que en este caso, el codigo está en la base de datos