Page 1 of 1

Desperate for help with a flash integration in existing php

Posted: Tue Sep 15, 2009 5:12 pm
by stardotstar
Hi guys,

I am really starting to cast about for places where I can get an expert hand to help me troubleshoot a problem I have with a module I have updated for vBulletin.

It involves the delivery of banners from OpenX to vBulletin via a plugin.

I had to modify the plugin slightly to get an existing addon product to work with the latest vBulletin and new openX - it was origianlly for phpAds.

I have asked this in the vb.org and openx forums but noone is able to help.

I don't think the problem is at all complicated but I can't quite figure out where the delivery of the ads is failing when it comes to flash.

All normal gif/jpg banners are delivered without any problem. When flash/swf is pulled in it only presents the fallback image.

BUT when I lodge the invocation code in its own php script on the same server, indeed in the very same directory as the forums it works.

Here is the deal:

Code: Select all

<?php
  define('MAX_PATH', '/var/www/sourcepoint/htdocs/openx');
  if (@include_once(MAX_PATH . '/www/delivery/alocal.php')) {
    if (!isset($phpAds_context)) {
      $phpAds_context = array();
    }
    // function view_local($what, $zoneid=0, $campaignid=0, $bannerid=0, $target='', $source='', $withtext='', $context='', $charset='')
    $phpAds_raw = view_local('', 1, 0, 266, '', '', '0', $phpAds_context, '');
  }
  echo $phpAds_raw['html'];
?>
This code when called by itself delivers one of my flash ads:
http://www.archeli.com.au/forums/localmode.php

but when that very same code is invoked in the forums the flash is not displayed - only the fallback.

The ads are invoked in vBulletin with the creation of an <ad > tag - which simply calls for the delivery code above and publishes the html necessary in place.

Code: Select all

<td align="$stylevar[center]"><ad what="zone:1" /></td>
is the standard invocation for the zone in which all the campaigns exist - as above you can see I am pulling in ad 266 which is a flash one.

the parsing of the ad tag is handled mainly by vB functions and I don't think is problematic but I include here for completeness.

Code: Select all

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)  );
The call out for the actual delivery is then executed by this plugin:

Code: Select all

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=d ... p_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']);
                }
OA_setTimeZone('Australia/Sydney');    
                return "<!-- BEGIN ad {$adcomment} -->{$ad['html']}<!-- END ad {$adid} -->";
            }
        }
    }
}
On reading that script you will see that the only important sections are the final delivery (after a hardwired time zone fix for vB/OpenX) and "// get banner via direct invocation of phpAdsNew"

I need someone who can understand the essential structure of this to help me troubleshoot and identify where and why the flash content is failing in the invocation in vB but not in its own container.

I have had no joy for quite a long time (being patient and doing my homework to ensure that I don't ask the wrong thing in the wrong place - I ended up getting desperate and asked at vb.com and although they had helped with flash questions before they won't touch this and point me back to .org...)

Here is the history of my question for the record.
http://www.vbulletin.org/forum/showthread.php?t=219301
http://www.vbulletin.org/forum/showthread.php?t=217254
http://forum.openx.org/index.php?sho...=503428016&hl=
http://www.vbulletin.com/forum/showthread.php?t=317840

Please don't see this as cross posting since noone has been willing to help me beyond identifying that it works in its own script...

Best regards from a fledgeling php coder eager to learn and work on the problem as well as get to a solution as directly as possible,
Will

Re: Desperate for help with a flash integration in existing php

Posted: Wed Sep 16, 2009 7:45 pm
by stardotstar
Any suggestions even on where to start to check what could be the problem?

Is there a way that I can get the

Code: Select all

echo $phpAds_raw['html'];
to print out the html code that is being returned so I can play with it in a hard coded way in the vb perhaps>?

Will