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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2009, 02:32 AM
stardotstar stardotstar is offline
 
Join Date: May 2008
Location: SYD, AU
Posts: 156
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [FIXED]Programmer help required to update an old but good plugin

Hi all,

I am new at building product/plugins for vB - I spent much time with phpBB cutting my teeth on the mods for the 2.x series.

I am getting my head around calling php from external programmes and in this case I am using a product from vB.org that integrates phpAdsNew - now openx.

The problem I have found there is that it is only supported up to vB3.5 and after playing with it I got it working just fine on 3.8.2 with one major flaw.

I needed to use what openx calls local mode invocation since the ad server and vB are on the same physical machine - using javascript is very slow when there are a few ads on the page.

This apparently is a simple call to openx server in php called view.raw with the necessary variables set.

Having got the product working and the necessary calls into the templates - it uses a new tag <ad /> I got my dearly needed speed increase (further improved by implementing memchached).

But suddenly I notice that the post timestamps are skewed into the past (about 10 or 11 hours - the same as taking off the GMT offset - on my board +10). I checked the server = ok, I sent emails = OK, I checked an unmodded board = ok and therefore started to troubleshoot.

I found that in my templates/styles if I removed any reference to the invocation of the phpAdsNew integration the time would revert to normal offset.

Therefore the time is not being altered only displayed incorrectly - and only within certain frames - for example the time is incorrect (- 10 hours) in personal message received times and all posts within threads and indexes etc BUT not at the very bottom of the board where the board time is displayed eg:

Code:
All times are GMT +10. The time now is 1:09pm.
So I would see this post if I had lodged it just then as 03:09am and if I took the call to the openx server out it would revert to 13:09 or 01:09pm as it should be.

Note that the server is set to Localtime (+10) and the time is correct, the time is also correctly set within openx and I am investigating there what may be happening when the call is made.

Interestingly the use of javascript to pull the ad into the board (although slow) does not cause this time skew - only the "local mode" call.


Here is what I think is happening.

When a page is generated the header has a call to another template which contains the "invocation code" for the ad. In the past I have used Javascript here.

so:

Code:
<td align="$stylevar[left]" id="header_right_cell">
        <if condition="$ad_location['ad_header_logo']">$ad_location[ad_header_logo]<else />&nbsp;</if>
    </td>
in the header serves an ad up to the right of the site logo.

ad_header_logo is now simple:

Code:
<ad what="zone:1" />
where in the past it was the javascript invoation code like this:
Code:
<!--/* OpenX Javascript Tag v2.8.0 */-->
<script type='text/javascript'><!--//<![CDATA[
   var m3_u = (location.protocol=='https:'?'https://www.sourcepoint.com.au/openx/www/delivery/ajs.php':'http://www.sourcepoint.com.au/openx/www/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=1");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");
//]]>--></script>
So far so good. The local mode call invokes the following two plugins as part of the product phpAdsNew Integration

ad_tag_callback in template_compile execution order 5
Code:
if (!function_exists('_tag_callback'))
{
    /**
    * Callback-function for process_template_tag() which "parses" arguments and returns PHP code for eval
    *
    * @param    string    Options/arguments of tag
    * @param    string    Name of function to call
    * @param    array    Associative array of argument names and default values
    *
    * @return    string
    */
    function _tag_callback($options, $functionhandle, $arglist)
    {
        $options = stripslashes($options);
        trim($options);
        trim($functionhandle);

        if (!function_exists('replace_template_variables'))
        {
            require_once(DIR . '/includes/functions_misc.php');
        }

        $param = array();
        if (is_array($arglist))
        {
            reset($arglist);
            foreach ($arglist AS $key => $val)
            {
                if (preg_match('#'.$key.'=([\\\]["\'])(.*?)\1#', $options, $matches))
                {
                    $param[] = $matches[2];
                }
                else
                {
                    // default argument
                    $param[] = $val;
                }
            }
        }
       
        foreach ($param AS $argument)
        {
            if ($return == '')
            {
                $return = '" . ' . $functionhandle . '(';
            }
            else
            {
                $return .= ', ';
            }
            // Surround variables with {} - not failsafe, but should do the job in most cases
            $argument = preg_replace('#\$([a-z0-9_>-]+)((\[\'.*?\'\])+)#i', '{$\\1\\2}', $argument);
            // {{$foo}} --> {$foo}
            $argument = preg_replace('#(\{+)\$(.*?)(\}+)#i', '{$\\2}', $argument);

            // Replace legacy variable names in templates with their modern equivalents
            $argument = replace_template_variables($argument, true);

            $return .= '"' . $argument . '"';
        }
        $return .= ') . "';
        return $return;
    }
}

if (!function_exists('process_template_tag'))
{
    /**
    * Processes user-defined tags <tagname [argument="foo" ...]/> into myfunction() PHP code for eval
    *
    * @param    string    Title of tag
    * @param    string    Un-parsed template HTML
    * @param    string    Name of function to call
    * @param    array    Associative array of argument names and default values, order must be the same as for the function specified previously
    *
    * @return    string
    */
    function process_template_tag($tagname, $text, $functionhandle='', $arglist)
    {
        if ($functionhandle == '')
        {
            // No function specified - remove tag
            return preg_replace("#<{$tagname}\s?/?>|<{$tagname}\s.*?/?>#si", '', $text);
        }
        else
        {
            return preg_replace("#<({$tagname})(\s+(.*?)/?)>#sie", "_tag_callback('\\3', \$functionhandle, \$arglist)", $text);
        }
    }
}

$template = process_template_tag('ad', $template, 'view_ad', array('what' => '', 'clientid' => 0, 'target' => '', 'source' => '', 'withtext' => 0)  );
Then we have
view_ad function in init_startup also at 5

Code:
if (!function_exists('view_ad'))
{
    /**
    * Calls view_raw function from phpAdsNew either locally or via xml-rpc to get HTML advertisement code, see phpAdsNew for infos.
    *
    * @param    string    Zone name (zone:x) or keywords (keyword1|keyword2|...)
    * @param    integer    Client-ID
    * @param    string    Target
    * @param    string    Source
    * @param    integer    Withtext
    *
    * @return    string
    */
    function view_ad($what, $clientid = 0, $target = '', $source = '', $withtext = 0)
    {
        global $vbulletin;
        static $panpath;
       
        if (!$panpath)
        {
            trim($vbulletin->options['panpath']);
            $panpath = @parse_url($vbulletin->options['panpath']);
        }
       
        // Calculate an identifier for the requested ad - this could be used to cache banners retrieved via xmlrpc in future versions
        $adid = sprintf('%u', crc32($what . $clientid . $target . $source . $withtext));
       
        if ($vbulletion->options['addtemplatename'] or $vbulletin->config['Misc']['debug'])
        {
            // Be verbose
            $adcomment = 'id="' . $adid . '" what="' . htmlspecialchars($what) . '" clientid="' . htmlspecialchars($clientid)
                    . '" target="' . htmlspecialchars($target) . '" source="' . htmlspecialchars($source)
                    . '" withtext="' . htmlspecialchars($withtext) . '"';
        }
        else
        {
            $adcomment = $adid;
        }
       
        if ($vbulletin->options['panpath'] == '')
        {
            // Path to phpAdsNew is empty - disable ads
            return "<!-- ad {$adcomment} / -->";
        }
        elseif (strtolower($panpath['scheme']) == 'http')
        {
            // get banner from phpAdsNew via xml-rpc
            /*
            //    ATTN:
            //    In phpAdsNew 2.0.6 (and maybe earlier versions) is a tiny bug which prevents xml-rpc from working cleanly.
            //   
            //    Patch:
            //    --- phpAdsNew/misc/samples/xmlrpc/php/lib-xmlrpc.inc.php.orig    Tue Aug 16 10:51:26 2005
            //    +++ phpAdsNew/misc/samples/xmlrpc/php/lib-xmlrpc.inc.php    Thu Oct 27 17:12:26 2005
            //    @@ -76,6 +76,7 @@
            //            global $xmlrpcStruct;
            //     
            //            global $xmlrpcTypes;
            //    +        global $xmlrpc_valid_parents;
            //            global $xmlEntities;
            //            global $xmlrpcerr;
            //            global $xmlrpcstr;
            //           
            //    See https://sourceforge.net/tracker/?func=detail&atid=111386&aid=1339623&group_id=11386 for details.
            */
   
            global $xmlrpcbanner, $phpAds_remoteInfo;
            require_once(DIR . '/includes/lib-xmlrpc-class.inc.php');  // see misc/samples/xmlrpc/php/ directory of your phpAdsNew installation
   
            if (!$xmlrpcbanner)
            {
                $xmlrpcbanner = new phpAds_XmlRpc($panpath['host'], $panpath['path'], (intval($panpath['port']) > 0 ? $panpath['port'] : 80));
            }
   
            $ad = $xmlrpcbanner->view_raw($what, $clientid, $target, $source, $withtext);
   
            return "<!-- BEGIN ad {$adcomment} -->{$ad['html']}<!-- END ad {$adid} -->";
        }
        else
        {
            // get banner via direct invocation of phpAdsNew
            // this is basically taken from the invocationcode generated by phpAdsNew - it does its own checks to prevent multiple inclusion
   
            global $phpAds_context;
           
            if (@require($vbulletin->options['panpath'] . (strstr($vbulletin->options['panpath'] , '/phpadsnew.inc.php') ? '' : '/phpadsnew.inc.php' )))
            {
                if (!isset($phpAds_context))
                {
                    $phpAds_context = array();
                }
   
                $ad = view_raw($what, $clientid, $target, $source, $withtext, $phpAds_context);
               
                if ($vbulletin->options['panbandupes'])
                {
                    // Remember bannerid to prevent showing banner multiple times on same page
                    $phpAds_context[] = array('!=' => 'bannerid:'.$ad['bannerid']);
                }
   
                return "<!-- BEGIN ad {$adcomment} -->{$ad['html']}<!-- END ad {$adid} -->";
            }
        }
    }
}

The important part in this as far as I can see is the local mode not xmlrpc

Code:
else
        {
            // get banner via direct invocation of phpAdsNew
            // this is basically taken from the invocationcode generated by phpAdsNew - it does its own checks to prevent multiple inclusion
   
            global $phpAds_context;
           
            if (@require($vbulletin->options['panpath'] . (strstr($vbulletin->options['panpath'] , '/phpadsnew.inc.php') ? '' : '/phpadsnew.inc.php' )))
            {
                if (!isset($phpAds_context))
                {
                    $phpAds_context = array();
                }
   
                $ad = view_raw($what, $clientid, $target, $source, $withtext, $phpAds_context);
               
                if ($vbulletin->options['panbandupes'])
                {
                    // Remember bannerid to prevent showing banner multiple times on same page
                    $phpAds_context[] = array('!=' => 'bannerid:'.$ad['bannerid']);
                }
   
                return "<!-- BEGIN ad {$adcomment} -->{$ad['html']}<!-- END ad {$adid} -->";
            }
Can anyone see within this code what might cause the date/time stamp of the board to be replaced but only on each page display not within the actual time keeping itself?

You can see this phenomenon for you self without needing to log in at my board. http://www.archeli.com.au/forums

It is also interesting to note that this does not effect the display of the time when "detailed" is used - I guess because that function doesn't care if the time is "zoned" as such since it is a "difference" not a literal stamp.

I have just tried to change the time to "Normal" and edited the time format to "h:i A e" which shows the time zone - and what do you know - UTC Is what is being delivered back to the pages as they render:
Code:
18-05-2009 06:07 AM UTC
instead of
Code:
18-05-2009 04:07 PM Australia/ACT
which is what is shown at the base of the pages.

The time of the post from the postbit is

$post[posttime]

and somehow that is getting transformed back to UTC...

Any help would be appreciated, I am starting to get somewhere as a developer of this kind of code and will continue to ponder and submerge myself in the workings of vB and the products/openx.

Cheers
Will
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 05:10 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.03521 seconds
  • Memory Usage 2,255KB
  • Queries Executed 11 (?)
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
  • (9)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (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_threadedmode.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • 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