parse mobpartners xml feed for text creatives

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    parse mobpartners xml feed for text creatives

    so here is the script which parses mobpartners xml feed and creates an array with text creatives:

    generate your xml file at MobPartner - Mobile Affiliate Network - Mobile CPA Campaigns - Home
    dont forget to check the option: Display promotions

    PHP Code:
    function parse_mobpartners_feed($feed_file)
    {
        $xml = simplexml_load_file($feed_file,'SimpleXMLElement',LIBXML_NOCDATA);
        foreach($xml->catalog->campaign AS $campaign)
        {
      $countries = gum_foreach($campaign->actions->action->countries->country);
      foreach($countries AS $country)
      {
       unset($crs);
       $creatives = gum_foreach($country->creatives->creative);
       foreach($creatives AS $creative)
       {
        
        if($creative->format=='Text')
        {
         $cr['creative_url'] = (string)$creative->click_url;
         $cr['creative_text'] = (string)$creative->content;
         $crs[] = $cr;
        }
        
       }
       if(is_array($crs))
       {
        $cc = (string)$country->country_name;
        if (isset($arr[$cc]['creatives']))
        {
         $arr[$cc]['creatives'] = array_merge($arr[$cc]['creatives'],$crs);
        }
        else
        $arr[$cc]['creatives'] = $crs;
       }
      }
      
        }
        return $arr;
    }
    function gum_foreach($vars)
    {
        if(isset($vars[0]))
        {
      foreach($vars AS $var)
      {
       $arr[] = $var;
      }
        }
        else
        {
      $arr[] = $vars;
        }
        return $arr;
    } 
    
    array will look like this:

    Code:
        [KG] => Array
            (
                [creatives] => Array
                    (
                        [0] => Array
                            (
                                [creative_url] => http://c.mobpartner.mobi/?s=112519&a=402&p=9728
                                [creative_text] => Click here to find images!!
                            )
    
                        [1] => Array
                            (
                                [creative_url] => http://c.mobpartner.mobi/?s=112519&a=402&p=9910
                                [creative_text] => Click here to find videos!!
                            )
    
                    )
    
            )
    Added after 12 minutes:

    usage example:
    PHP Code:
    $feed_file = 'test/test.xml';
    $arr = parse_mobpartners_feed($feed_file);
    $country_code = 'ES'; /* for country code detection use mod_geoip or other ip to country solutions */
    if(isset($arr[$country_code]))
    {
        $rand = rand(0, count($arr[$country_code]['creatives'])-1);
        echo '<a href="'.$arr[$country_code]['creatives'][$rand]['creative_url'].'">'.$arr[$country_code]['creatives'][$rand]['creative_text'].'</a>';
    } 
    
    Last edited by GumSlone; 03.01.12, 14:05.
    Advertise your mobile site for FREE with AdTwirl

Working...
X