vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Lil help? trying to change my code edit to a plugin (https://vborg.vbsupport.ru/showthread.php?t=258525)

Mutt 02-08-2011 12:03 AM

Lil help? trying to change my code edit to a plugin
 
1 Attachment(s)
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

Mutt 02-08-2011 12:06 AM

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.

Lynne 02-08-2011 01:39 AM

That code means nothing (what is $criteria['condition1']?) since we are unfamiliar with the code at all.

Mutt 02-08-2011 11:41 AM

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


Lynne 02-08-2011 04:36 PM

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.


All times are GMT. The time now is 06:53 PM.

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.01164 seconds
  • Memory Usage 1,831KB
  • 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
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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