PDA

View Full Version : can this be done with hooks (postbit escape)


Ron1n
07-29-2005, 05:04 AM
I am trying to prevent the first post of every thread from being displayed. I was going to add to the $hook_query_where string, but that causes the thread to appear locked when there is only one post (i.e. nothing is returned).

I decided that hacking the following top places would be best:

foreach (explode(',', $cache_postids) AS $id)
{
// get the post from the post array
if (!isset($postarray["$id"]))
{
continue;
}
$post = $postarray["$id"];

if ($tachyuser = in_coventry($post['userid']) AND !can_moderate($thread['forumid']))
{
continue;
}while ($post = $db->fetch_array($posts))
{
if ($post['visible'] == 1)
{
// fix to prevent deleted posts that are the last post on the page from not being shown
if ($counter >= $perpage)
{
break;
}
++$counter;
if ($postorder)
{
$post['postcount'] = --$postcount;
}
else
{
$post['postcount'] = ++$postcount;
}
}

if ($tachyuser = in_coventry($post['userid']) AND !can_moderate($thread['forumid']))
{
continue;
}
But there werent any hooks, so I resorted to this hook in class_postbit.php:

($hook =& vBulletinHook::fetch_hook('postbit_display_start') ) ? eval($hook) : false;

However, I cannot use return ''; to get out of it because that just retuns '' for the hook. Any suggestions on how to do this without modifying files by hand?

Marco van Herwaarden
07-29-2005, 06:32 AM
Ok, 2 suggestions:

1. I didn't try it, but can't you test if it is the first post in the hook that gets executed as last in processing the current post, and then simply unset (or make empty) the postbit variable if it is the first post?

2. Use continue or break:

Continue will stop processing the current instance of the foreach, while,.. loops, and procede to the next element in the loop.

Break will stop the current loop, and will continue at the statement following the end of the loop.

If you are nesting loops, for example:
foreach ($rows as $row) // loop 1
{
foreach ($row AS $field) // loop 2
{
location A. ...lets put something here..
}
Location B
}
Location C.

If you put the following on Location A:
continue; - Will stop processing the current item and continue the next item in loop 2
continue 2; - Will stop processing the current item of both loop 1 & 2 and continue the next item in loop 1 (continue X, will break the loop for X nested levels)


break; - Will stop processing loop 2, and continue as Location B
break2; - Will stop processing loop 1 & 2, and continue as Location C


Edit: Hope this helps, because i didn't totally understand what the problem is.

Andreas
07-29-2005, 07:07 AM
continue/break don't affect Code outside eval(), eg. doesn't work in Plugins.

You could try

if (THIS_SCRIPT == 'showthread' AND $this->post[postid] == $thread[firstpostid])
{
$this->templatename = 'foobar';
}

pimpery
07-29-2005, 10:39 AM
continue/break don't affect Code outside eval(), eg. doesn't work in Plugins.

You could try

if (THIS_SCRIPT == 'showthread' AND $this->post[postid] == $thread[firstpostid])
{
$this->templatename = 'foobar';
}


redefine the function. php allows it.

Andreas
07-29-2005, 10:45 AM
redefine the function. php allows it.
1) Which function?
2) Don't think so ... example code?

Ron1n
07-29-2005, 11:29 AM
1) Which function?
2) Don't think so ... example code?Thats a good idea KirbeDE. I had been treating the first post like the poll, but because of your suggestion I decided to treat the first post just like any other post, except I created a new class, and using this hook:

($hook = vBulletinHook::fetch_hook('showthread_postbit_crea te')) ? eval($hook) : false;

$postbit_obj =& $postbit_factory->fetch_postbit($fetchtype);
if ($fetchtype == 'post')
{
$postbit_obj->highlight =& $replacewords;
}
$postbit_obj->cachable = $post_cachable; I have made it so it calls vB_Postbit_MyClass. That did require some code editing to create the class, but its something that is very easy and only requires one edit.

Maybe I'll suggest they make a hook at this location:

function &fetch_postbit($postbit_type)
{
switch ($postbit_type)
{
case 'post':
$out =& new vB_Postbit_Post();
if ($this->registry->options['legacypostbit'])
{
$out->templatename = 'postbit_legacy';
}
break; It seems like they could handle it better than throwing an error on 'default' too.

Thanks for your help, everyone. And, if anyone gets 'continue' or 'return;' to work... I would love that as well.