Quote:
Originally Posted by Brad
Second thing, hooks will not get you into every corner of the code. Some things will always be done best with a hack. For example if you are looking to add something but need to query the db for some extra data and want to avoid and extra query (in other words you are going to modify an existing one with a join or such) forget it and hack it in, there are no hooks that let you modify existing queries.
|
This quote should be updated:
You can join into Queries now:
Lets say you wanted to show some custom info on each post. In 3.0x you would modify an exsiting query. Its the biggest query in showthread.php. Starts like "$posts = $db->query_read("".
You would have to add you own SELECT statments like table.username AS username, and JOIN statements like LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = post.userid). You don't need to do that anymore.
If you wanted to do this is 3.5 using hooks you can. Open showthread.php and find around line: 923-924. You should see...
PHP Code:
$hook_query_fields = $hook_query_joins = '';
($hook = vBulletinHook::fetch_hook('showthread_query')) ? eval($hook) : false;
Under that you will see a very large query, in that query you will notice the variables, $hook_query_fields, and $hook_query_joins. Thats your ticket into this query.
You would simple go into the plugins, add new plugin and write it like so: Plugin Name is "showthread_query"
PHP Code:
$hook_query_fields = ",tablename.rowname AS newname";
$hook_query_joins = "LEFT JOIN " . TABLE_PREFIX . "tablename AS newtable ON(tablename.rowname = post.rowname)";
Tips:
Just remember to start "$hook_query_fields" variable with a comma.
You can also add conditions around this which is great I think. Example:
PHP Code:
if ($var == $var2)
{
$hook_query_fields = ",tablename.rowname AS newname";
$hook_query_joins = "LEFT JOIN " . TABLE_PREFIX . "tablename AS newtable ON(tablename.rowname = post.rowname)";
}
Hope this helps some advance users.