lms
26/11/2009, 14:32
vBulletin usa un sistema de enganche para facilitarnos el hacer modificaciones y evitar hacer cambios en nuestros archivos cada vez que actualizamos vBulletin, los hooks del combo solo los vas a encontrar en archivos PHP, nunca en plantillas ni en otro lugar (1) ya que es codigo PHP que lo vamos a "Incrustar", los hooks en plantilla son muy similares, pero es un tema aparte
Ejemplo Practico
Un Ejemplo de como funciona seria el siguiente (El Codigo no es real)
//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'); ]
Ese es el código original en los archivos php de vBulletin, si se ejecuta la función llamar_a_hook no tendrá efecto si no hay nada en ese gancho
Ahora, supongamos que he hecho un plugin con el siguiente código:
if ($usuario['grupo']=='Administrador')
{
$usar_postbit_legancy='LEGANCY';
}
else
{
$usar_postbit_legancy=$opciones_vbulletin['valor_configurado'];
}
¿Donde creen que debo engancharlo? en postbit_display_start o en postbit_display_complete
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 ahí que uno siempre escucha: "USANDO EL HOOK CORRECTO".... nuestro código cuando se ejecute (por el hook) será internamente así:
//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');
De ahí es que se llama GANCHO, porque estas anexando código.
************************************************** **************************************
Ejemplo Real
Abran el archivo showthread.php linea 1000 aproximadamente y van a encontrar
$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
");
Ahi por ejemplo tenemos 2 variables a modo de hooks ($hook_query_fields y $hook_query_joins) que los programadores de vBulletin lo pusieron para que nosotros hagamos alguna modificación en el SQL (ver la consulta). así que podemos poner alguna condición y, según eso, setear esas variables Solo los usuarios registrados pueden ver enlaces las posibilidades son muchas
la llamada de plugin en plantillas es:
($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 código externo, solo que en este caso, el código está en la base de datos
Salud2
Ejemplo Practico
Un Ejemplo de como funciona seria el siguiente (El Codigo no es real)
//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'); ]
Ese es el código original en los archivos php de vBulletin, si se ejecuta la función llamar_a_hook no tendrá efecto si no hay nada en ese gancho
Ahora, supongamos que he hecho un plugin con el siguiente código:
if ($usuario['grupo']=='Administrador')
{
$usar_postbit_legancy='LEGANCY';
}
else
{
$usar_postbit_legancy=$opciones_vbulletin['valor_configurado'];
}
¿Donde creen que debo engancharlo? en postbit_display_start o en postbit_display_complete
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 ahí que uno siempre escucha: "USANDO EL HOOK CORRECTO".... nuestro código cuando se ejecute (por el hook) será internamente así:
//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');
De ahí es que se llama GANCHO, porque estas anexando código.
************************************************** **************************************
Ejemplo Real
Abran el archivo showthread.php linea 1000 aproximadamente y van a encontrar
$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
");
Ahi por ejemplo tenemos 2 variables a modo de hooks ($hook_query_fields y $hook_query_joins) que los programadores de vBulletin lo pusieron para que nosotros hagamos alguna modificación en el SQL (ver la consulta). así que podemos poner alguna condición y, según eso, setear esas variables Solo los usuarios registrados pueden ver enlaces las posibilidades son muchas
la llamada de plugin en plantillas es:
($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 código externo, solo que en este caso, el código está en la base de datos
Salud2