Jump to content

I have a need to reset a TimeZone after calling an external script


Recommended Posts

This should be easy guys!

 

There is a bug in openx2.8 when calling ads by local mode invocation where the timezone gets reset to GMT/UTC and subsequently on my vBulletin integration I get UTC times after calling an ad.

 

There is a bug registered in openx and most people there say that they worked around it by resetting the local environment thus:

 

putenv("TZ=Australia/Sydney");

 

after the view_local function was called...

 

I have to work out how to add the correct code to my vBulletin plugin to reset the local timezone every time the plugin is called so that the posts and other timestamps on the board are correctly displayed when ads are called using local mode (which is much faster)

 

So this is what I have - I suspect it is simply a matter of adding the right piece of code after the plugin has done its bit and before returning to the board page build:

 

so...

 

The Header Template calls the product using <ad /> tags which invoke openx on the localhost with this plugin/php script:

 

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} -->";
putenv("TZ=Australia/Sydney");
		}
	}
}
}

 

The bit that is doing the work for me is the local mode state:

 

			// 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} -->";
putenv("TZ=Australia/Sydney");
		}
	}
}
}

 

You can see where I did the putenv bit it works not...

 

What can you suggest on this - have I got it in the wrong place - is it not using the necessary syntax??

 

Appreciated,

Will

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.