Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2011, 12:03 AM
Mutt's Avatar
Mutt Mutt is offline
 
Join Date: Nov 2001
Posts: 331
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Lil help? trying to change my code edit to a plugin

Hi, I need help getting my hack to work via a plugin instead of the hard coded edit I'm using now. I'm adding a THIS_SCRIPT criteria to the advertising manager. That way I can stick an ad in the 'Below Navbar' location but only have it appear in say forumdisplay or better yet, set the forum ID & limit it to forumdisplay. that way in a particular forum I can have different ads in the threads than on the forumdisplay listing.

I suppose I could have just added a template conditional to my ad code but I need to learn how to make vb4 plugins anyway & this seemed like it would be something I could handle. I was wrong.

FYI: when I say my hack, to be fair I blatantly stole the NJAquaman - Notices THIS_SCRIPT Criteria mod & just changed it to work for Adverting instead of notices. All of the control panel stuff NJAquaman did in his mod works for this one w/ just minor edits. it's when I get to hook 'ad_check_criteria' that I couldn't get it to work which means the ad displays regardless of the THIS_SCRIPT setting.

attached is a snippet of functions_ad.php and I've highlighted my added bit of code.

this snippet of code makes the hack work & since it's directly above hook 'ad_check_criteria' my brain tells me I should be able to enter that same code into a plugin and call it at hook location 'ad_check_criteria' & I should be good to go. sadly it does not work. I guess I'm rustier than I thought.

anyone have any idea what I'm doing wrong? thanks in advance
Attached Images
File Type: jpg Screenshot_4.jpg (70.3 KB, 0 views)
Reply With Quote
  #2  
Old 02-08-2011, 12:06 AM
Mutt's Avatar
Mutt Mutt is offline
 
Join Date: Nov 2001
Posts: 331
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PS - I know there's an s missing from the criteria 'thiscript' but the var is called that throughout. it's now NJAquaman had it in his hack & I saw no need to change it. it's not that. like I said it works when hard coded.
Reply With Quote
  #3  
Old 02-08-2011, 01:39 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That code means nothing (what is $criteria['condition1']?) since we are unfamiliar with the code at all.
Reply With Quote
  #4  
Old 02-08-2011, 11:41 AM
Mutt's Avatar
Mutt Mutt is offline
 
Join Date: Nov 2001
Posts: 331
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

sorry Lynne, it's part of vb4.11 function_ad.php the code above my highlighted code is the original code that i'm mimicking and my code works as is. it's when i move it to the plugin that is called at the hook directly below my highlighted code that it stops working. i was thinking my question was less about the code & more about plugin restrictions or maybe something special I need to do when using a plugin like registering variables or something.

i'm gonna keep plugging away at it after work.

I didn't want to post a big pile of code but if you need to see more to put it into context, here's the rest.

PHP Code:
        // active ads on the same location only
        
if ($ad['active'] AND $ad['adlocation'] == $location)
        {
            
$criterion $vbulletin->db->query_read("
                SELECT * FROM " 
TABLE_PREFIX "adcriteria
                WHERE adid = " 
$adid "
            "
);

            
// create the template conditionals
            
$conditional_prefix "";
            
$conditional_postfix "";

            while(
$criteria $vbulletin->db->fetch_array($criterion))
            {
                switch(
$criteria['criteriaid'])
                {
                    case 
"in_usergroup_x":
                        
$conditional_prefix .= '<vb:if condition="is_member_of($' 'bbuserinfo, ' $criteria['condition1'] . ')">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"not_in_usergroup_x":
                        
$conditional_prefix .= '<vb:if condition="!is_member_of($' 'bbuserinfo, ' $criteria['condition1'] . ')">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"browsing_content_page":
                        
$conditional_prefix .= '<vb:if condition="CONTENT_PAGE == ' $criteria['condition1'] . '">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"browsing_forum_x":
                        
$conditional_prefix .= '<vb:if condition="$' 'vbulletin->GPC[\'forumid\'] == ' $criteria['condition1'] . '">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"browsing_forum_x_and_children":
                        
// find out who the children are:
                        
$forum $vbulletin->db->query_first("SELECT childlist FROM " TABLE_PREFIX "forum WHERE forumid = " intval($criteria['condition1']));
                        
$conditional_prefix .= '<vb:if condition="in_array($' 'vbulletin->GPC[\'forumid\'], array(' $forum['childlist'] . '))">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"style_is_x":
                        
$conditional_prefix .= '<vb:if condition="STYLEID == ' intval($criteria['condition1']) . '">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"no_visit_in_x_days":
                        
$conditional_prefix .= '<vb:if condition="$' 'bbuserinfo[\'lastactivity\'] < TIMENOW - (86400*' intval($criteria['condition1']) . ')">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"no_posts_in_x_days":
                        
$conditional_prefix .= '<vb:if condition="$' 'bbuserinfo[\'lastpost\'] < TIMENOW - (86400*' intval($criteria['condition1']) . ')">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"has_x_postcount":
                        
$conditional_prefix .= '<vb:if condition="$' 'bbuserinfo[\'posts\'] > ' intval($criteria['condition1']) . ' AND $' 'bbuserinfo[\'posts\'] < ' intval($criteria['condition2']) . '">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"has_never_posted":
                        
$conditional_prefix .= '<vb:if condition="$' 'bbuserinfo[\'lastpost\'] == 0">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"has_x_reputation":
                        
$conditional_prefix .= '<vb:if condition="$' 'bbuserinfo[\'reputation\'] > ' intval($criteria['condition1']) . ' AND $' 'bbuserinfo[\'reputation\'] < ' intval($criteria['condition2']) . '">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"pm_storage_x_percent_full":
                        
$conditional_prefix .= '<vb:if condition="$' 'pmboxpercentage = $' 'bbuserinfo[\'pmtotal\'] / $' 'bbuserinfo[\'permissions\'][\'pmquota\'] * 100"></vb:if>';
                        
$conditional_prefix .= '<vb:if condition="$' 'pmboxpercentage > ' intval($criteria['condition1']) . ' AND $' 'pmboxpercentage < ' intval($criteria['condition2']) . '">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"came_from_search_engine":
                        
$conditional_prefix .= '<vb:if condition="is_came_from_search_engine()">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                    case 
"is_date":
                        if (
$criteria['condition2'])
                        {
                            
$conditional_prefix .= '<vb:if condition="gmdate(\'d-m-Y\', TIMENOW) == \'' str_replace("'""\'"$criteria['condition1']) .'\'">';
                            
$conditional_postfix .= "</vb:if>";
                        }
                        else
                        {
                            
$conditional_prefix .= '<vb:if condition="vbdate(\'d-m-Y\', TIMENOW, false, false) == \'' str_replace("'""\'"$criteria['condition1']) .'\'">';
                            
$conditional_postfix .= "</vb:if>";
                        }
                        break;
                    case 
"is_time":
                        if (
preg_match('#^(\d{1,2}):(\d{2})$#'$criteria[1], $start_time) AND preg_match('#^(\d{1,2}):(\d{2})$#'$criteria[2], $end_time))
                        {
                            if (
$criteria['condition3'])
                            {
                                
$start gmmktime($start_time[1], $start_time[2]);
                                
$end   gmmktime($end_time[1], $end_time[2]);
                                
// $now   = gmmktime();
                                
$conditional_prefix .= '<vb:if condition="$' 'now = gmmktime()"></vb:if>';
                            }
                            else
                            {
                                
$start mktime($start_time[1], $start_time[2]) + $vbulletin->options['hourdiff'];
                                
$end   mktime($end_time[1], $end_time[2]) + $vbulletin->options['hourdiff'];
                                
// $now   = mktime() + $vbulletin->options['hourdiff'];
                                
$conditional_prefix .= '<vb:if condition="$' 'now = mktime() + ' $vbulletin->options['hourdiff'] . '"></vb:if>';
                            }
                            
$conditional_prefix .= '<vb:if condition="$' 'now > ' $start ' OR $' 'now < ' $end '">';
                            
$conditional_postfix .= '</vb:if>';
                        }
                        break;
                    case 
"ad_x_not_displayed":
                        
// no ad shown? make note of it, and create the array for us
                        
$conditional_prefix .= '<vb:if condition="$noadshown = !isset($' 'adsshown)"></vb:if>';
                        
$conditional_prefix .= '<vb:if condition="$noadshown"><vb:if condition="$' 'adsshown = array()"></vb:if></vb:if>';
                        
// if no ads shown, OR ad x have not been shown, show the ad
                        
$conditional_prefix .= '<vb:if condition="$noadshown OR !in_array(' intval($criteria['condition1']) . ', $' 'adsshown)">';
                        
$conditional_postfix .= '</vb:if>';
                        break;
                    default:
                    case 
"thiscript":
                        
$conditional_prefix .= '<vb:if condition="THIS_SCRIPT == ' $criteria['condition1'] . '">';
                        
$conditional_postfix .= "</vb:if>";
                        break;
                        (
$hook vBulletinHook::fetch_hook('ad_check_criteria')) ? eval($hook) : false;
                        break;
                }
            } 
Reply With Quote
  #5  
Old 02-08-2011, 04:36 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you are changing hook locations, make sure you find the hook in the php code and see if the variable names have changed. Also, see if it's in a function because you may have to globalize a variable for use.
Reply With Quote
Reply


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 07:37 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.04170 seconds
  • Memory Usage 2,324KB
  • Queries Executed 14 (?)
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
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (1)postbit_attachment
  • (5)postbit_onlinestatus
  • (5)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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete