The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
[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. 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 /> </if> </td> ad_header_logo is now simple: Code:
<ad what="zone:1" /> 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 ('&cb=' + m3_r); if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used); document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : '')); document.write ("&loc=" + escape(window.location)); if (document.referrer) document.write ("&referer=" + escape(document.referrer)); if (document.context) document.write ("&context=" + escape(document.context)); if (document.mmm_fo) document.write ("&mmm_fo=1"); document.write ("'><\/scr"+"ipt>"); //]]>--></script> 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) ); 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} -->"; } 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 Code:
18-05-2009 04:07 PM Australia/ACT 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 |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|