Просмотр файла yahoo/includes/ads.php

Размер файла: 3.06Kb
<?

  /*

* Animated Collapsible DIV- © Dynamic Drive DHTML code library (www.pokazuha.tv)

* This notice MUST stay intact for legal use

* Visit Dynamic Drive at http://www.pokazuha.tv/ for this script and 100s more

* Last Update	: Tuesday, November 13 2005


*/

  function get_ads_html_code($xml, $display_template, $xml_parse_template, $ad_count)
  {
    $xml_templates = explode("\n",$xml_parse_template);
    $replacemets = array();
    $countent = "";
    foreach($xml_templates as $index=>$data)
    {
      preg_match("/.*(\{.*\}).*/",$data,$ret);
      $replacemets[$ret[1]] = str_replace($ret[1],"(.*)",$ret[0]);
    }
    $main_data = array();
    $html_code_array = array();
    foreach($replacemets as $repl_name=>$regexp)
    {
      $regexp = str_replace("[","\[",$regexp);
      $regexp = str_replace("]","\]",$regexp);
      $regexp = str_replace("!","\!",$regexp);
      $regexp = str_replace("/","\/",$regexp);
      $regexp = str_replace("\r","",$regexp);
      preg_match_all("/$regexp/Ui",$xml,$ret);
      $main_data[$repl_name] = $ret[1];
    }

    foreach($main_data as $repl_name=>$data_array)
    {
      if (is_array($data_array))
      {
        foreach($data_array as $index=>$data)
        {
          if (!isset($html_code_array[$index]))
                  $html_code_array[] = $display_template;
          $html_code_array[$index] = str_replace($repl_name,$data,$html_code_array[$index]);
        }
      }

    }
    return $html_code_array;
  }

  function get_ads($type, $keywords, $curr_page = 0)
  {
    db_connect();
    $query = "select * from ads_boxes where adPlacement='$type'";
    $data = db_getrows(db_query($query));
    if (!$data[0]['adActive'])
    {
          return "";
    }
    $url = $data[0]['adSearchUrl'];
    $g_display_template = $data[0]['adgSkin'];
    $display_template = $data[0]['adSkin'];
    $xml_template = $data[0]['adXmlParse'];
    $display_count = $data[0]['adDisplayCount'];
    $start = ($curr_page == 0) ? 1 : ($curr_page);

    $url = str_replace("{keywords}",$keywords,$url);
    $url = str_replace("{ads_count}",$display_count,$url);
    $url = str_replace("{start}",$start,$url);
    $ip = str_replace('.','%2E',$_SERVER['REMOTE_ADDR']);
    $url = str_replace("{IP}",$ip,$url);
    $url = str_replace("{IPN}",$_SERVER['REMOTE_ADDR'],$url);
    $url = str_replace("{UID}",time(),$url);

    if (_DEBUG == 1)
       $xml = file_get_contents("www/5881.xml");
    else
       $xml = @file_get_contents($url);

    $html_code_array = get_ads_html_code($xml, $display_template, $xml_template,$display_count);
    if (count($html_code_array) == 0)
      return "";

    switch($type)
    {
      case 'top':
      case 'bottom':
      case 'side':
      {
        $content = $g_display_template;
        $html_data = "";
        for($i = 0; $i < $display_count; $i++)
        {
           $html_data .= $html_code_array[$i];
        }
        $content = str_replace('{ads_content}',$html_data,$content);
      }break;
    }
    return $content;
  }
?>