Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 07-29-2005, 06:04 AM
Ron1n Ron1n is offline
 
Join Date: Jun 2004
Posts: 373
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 07-29-2005, 07:32 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 07-29-2005, 08:07 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Reply With Quote
  #4  
Old 07-29-2005, 11:39 AM
pimpery pimpery is offline
 
Join Date: Nov 2004
Posts: 103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 07-29-2005, 11:45 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by pimpery
redefine the function. php allows it.
1) Which function?
2) Don't think so ... example code?
Reply With Quote
  #6  
Old 07-29-2005, 12:29 PM
Ron1n Ron1n is offline
 
Join Date: Jun 2004
Posts: 373
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:04 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04139 seconds
  • Memory Usage 2,243KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (9)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete