vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   can this be done with hooks (postbit escape) (https://vborg.vbsupport.ru/showthread.php?t=93118)

Ron1n 07-29-2005 06:04 AM

can this be done with hooks (postbit escape)
 
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:

PHP Code:

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

PHP Code:

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:

PHP Code:

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

However, I cannot use
PHP Code:

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 07: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:
PHP Code:

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 08:07 AM

continue/break don't affect Code outside eval(), eg. doesn't work in Plugins.

You could try
PHP Code:

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



pimpery 07-29-2005 11:39 AM

Quote:

Originally Posted by KirbyDE
continue/break don't affect Code outside eval(), eg. doesn't work in Plugins.

You could try
PHP Code:

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



redefine the function. php allows it.

Andreas 07-29-2005 11:45 AM

Quote:

Originally Posted by pimpery
redefine the function. php allows it.

1) Which function?
2) Don't think so ... example code?

Ron1n 07-29-2005 12:29 PM

Quote:

Originally Posted by KirbyDE
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:

PHP Code:

        ($hook vBulletinHook::fetch_hook('showthread_postbit_create')) ? 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:

PHP Code:

    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.


All times are GMT. The time now is 05:57 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02414 seconds
  • Memory Usage 1,764KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (9)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete