ChangeSet ID: 21383 CVSROOT: /opt/cvs-commit Module name: lostwages Changes by: jnewman@winehq.org 2005/11/21 11:23:15
Modified files: include : html.php incl.php utils.php include/themes/winehq: content.template Added files: bin : .htaccess ad
Log message: revamp of the banner ad code. We now will store a cookie. If a user views the banner ad 50 times, we will fix to a static image. Ad code is also now in it's own file. This will allow us to embed the ad into other parts of the website. i.e. the appdb, and the bug tracker.
Patch: http://cvs.winehq.org/patch.py?id=21383
Old revision New revision Changes Path Added 1.1 +0 -0 lostwages/bin/.htaccess Added 1.1 +0 -0 lostwages/bin/ad 1.15 1.16 +1 -2 lostwages/include/html.php 1.9 1.10 +0 -3 lostwages/include/incl.php 1.9 1.10 +1 -29 lostwages/include/utils.php 1.9 1.10 +2 -6 lostwages/include/themes/winehq/content.template
Index: lostwages/bin/.htaccess diff -u -p /dev/null lostwages/bin/.htaccess:1.1 --- /dev/null 21 Nov 2005 17:23:15 -0000 +++ lostwages/bin/.htaccess 21 Nov 2005 17:23:15 -0000 @@ -0,0 +1,7 @@ +deny from all + +<Files ad> + allow from all + ForceType application/x-httpd-php +</Files> + Index: lostwages/bin/ad diff -u -p /dev/null lostwages/bin/ad:1.1 --- /dev/null 21 Nov 2005 17:23:16 -0000 +++ lostwages/bin/ad 21 Nov 2005 17:23:16 -0000 @@ -0,0 +1,87 @@ +<?PHP + +/* Banner Ad Code */ +/* For WineHQ */ + +// path for banner ad +$bannerads_path = '../images/bannerads/'; + +// base filename of the static ad +$fixed_ad = 'cw-ad02'; + +// max count until we fix on static ad +$max_ads = 50; + +// open file and display contents of selected tag (very simple) +function get_xml_tags ($file, $tags = null) +{ + if (is_array($tags) and file_exists($file)) + { + $content = array(); + $fp = @fopen($file, "r"); + $data = fread($fp, filesize($file)); + @fclose($fp); + foreach ($tags as $tag) + { + if (eregi("<" . $tag . ">(.*)</" . $tag . ">", $data, $out)) + { + array_push($content, $out[1]); + } + } + return $content; + } + else + { + return null; + } +} +// end get_xml_tags() + +// check cookie for ad counter +$whqac = 1; +if (isset($_COOKIE['whqac'])) + $whqac = $_COOKIE['whqac']; +unset($_COOKIE["whqac"]); +$whqac++; + +// randomly select a banner and display it +if ($whqac >= $max_ads) +{ + // display fixed ad + $whqac = $max_ads; + $img = $fixed_ad; +} +else +{ + // display random ad + $ads = array(); + $d = opendir($bannerads_path); + while($entry = readdir($d)) + { + if(!ereg("(.+)\\.gif$", $entry, $arr)) + continue; + array_push($ads, $arr[1]); + } + closedir($d); + sort($ads); + $img = $ads[(rand(1,count($ads))-1)]; +} +list($url, $alt) = get_xml_tags($bannerads_path.$img.'.xml', array('url', 'alt')); + +// da banner +setcookie("whqac", $whqac, time()+60*60*24*1); +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); +?> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> + <title><?=$alt?></title> +</head> +<body bgcolor="#000000" text="#FFFFFF" marginwidth="0" marginheight="0" style="margin:0px;"><a href="<?=$url?>" +target="_top"><img src="../images/bannerads/<?=$img?>.gif" +width="468" height="60" border="0" alt="<?=$alt?>" /></a> <?=$whqac?></body> +</html> Index: lostwages/include/html.php diff -u -p lostwages/include/html.php:1.15 lostwages/include/html.php:1.16 --- lostwages/include/html.php:1.15 21 Nov 2005 17:23:16 -0000 +++ lostwages/include/html.php 21 Nov 2005 17:23:16 -0000 @@ -85,8 +85,7 @@ class html 'page_title' => $title, 'page_body' => $body, 'page_sidebar' => $menu, - 'page_search' => $search, - 'banner_ad' => $this->banner_ad + 'page_search' => $search ) ); } Index: lostwages/include/incl.php diff -u -p lostwages/include/incl.php:1.9 lostwages/include/incl.php:1.10 --- lostwages/include/incl.php:1.9 21 Nov 2005 17:23:16 -0000 +++ lostwages/include/incl.php 21 Nov 2005 17:23:16 -0000 @@ -39,9 +39,6 @@ if (isset($_GET['theme']) and in_array($ $config->theme = $_GET['theme']; }
-// load a banner ad -$html->banner_ad = banner_ad(); - // load the path for the page if ($_SERVER['PATH_INFO']) { Index: lostwages/include/utils.php diff -u -p lostwages/include/utils.php:1.9 lostwages/include/utils.php:1.10 --- lostwages/include/utils.php:1.9 21 Nov 2005 17:23:16 -0000 +++ lostwages/include/utils.php 21 Nov 2005 17:23:16 -0000 @@ -3,7 +3,7 @@ /* WineHQ by Jeremy Newman jnewman@codeweavers.com -*/ +*/
/* * winehq misc utils @@ -33,34 +33,6 @@ function get_files ($dir, $filter = null return $files; }
-// load and display banner ads -function banner_ad () -{ - global $file_root, $html; - $bannerads_path = $file_root.'/images/bannerads/'; - - // read dir and get list of banners - $ads = array(); - $d = opendir($bannerads_path); - while($entry = readdir($d)) - { - if(!ereg("(.+)\.gif$", $entry, $arr)) - continue; - array_push($ads, $arr[1]); - } - closedir($d); - sort($ads); - - // randomly select a banner and display it - $img = $ads[(rand(1,count($ads))-1)]; - list($url, $alt) = get_xml_tags($bannerads_path.$img.'.xml', array('url', 'alt')); - - // da banner - $banner = $html->ahref($html->img('bannerads/'.$img.".gif", "", $alt), $url); - - return $banner; -} - // open file and display contents of selected tag (very simple) function get_xml_tags ($file, $tags = null) { Index: lostwages/include/themes/winehq/content.template diff -u -p lostwages/include/themes/winehq/content.template:1.9 lostwages/include/themes/winehq/content.template:1.10 --- lostwages/include/themes/winehq/content.template:1.9 21 Nov 2005 17:23:16 -0000 +++ lostwages/include/themes/winehq/content.template 21 Nov 2005 17:23:16 -0000 @@ -20,13 +20,9 @@ <td> <img src="{$root}/images/blank.gif" border=0 width=10 height=1 alt=""> </td> - <td width="100%" align="center" valign="middle"> + <td width="468" align="center" valign="middle"> <!-- BANNER AD --> - <table border=0 cellpadding=1 cellspacing=0> - <tr><td valign="middle" align="center" class="black" - >{$banner_ad}</td - ></tr> - </table> + <iframe src="{$root}/bin/ad" scrolling="no" frameBorder="0" height="60" width="468"></iframe> <!-- END BANNER AD --> </td> <td>