"Fossies" - the Fresh Open Source Software Archive

Member "betterawstats/modules/render_map.inc.php" (17 Mar 2008, 9914 Bytes) of package /linux/www/old/betterawstats-1.0.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * betterawstats - an alternative display for awstats data
    4  *
    5  * @author      Oliver Spiesshofer, support at betterawstats dot com
    6  * @copyright   2008 Oliver Spiesshofer
    7  * @version     1.0
    8  * @link        http://betterawstats.com
    9 
   10  * Based on the initial BAWstats drupal module map
   11  * copyright 2007  Andrew Gillies (anaru at equivocation dot org)
   12  *
   13  * This program is free software; you can redistribute it and/or
   14  * modify it under the terms of the GNU General Public License
   15  * as published by the Free Software Foundation; either version 2
   16  * of the License, or (at your option) any later version.
   17  *
   18  * This program is distributed in the hope that it will be useful,
   19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21  * GNU General Public License for more details.
   22  *
   23  * You should have received a copy of the GNU General Public License
   24  * along with this program; if not, write to the Free Software
   25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   26  */
   27 
   28 
   29 // this file can't be used on its own
   30 if (isset($_GET['getmap'])) {
   31     baw_render_map_img();
   32 } else if (strpos ($_SERVER['PHP_SELF'], 'reder_map.inc.php') !== false) {
   33     die ('This file can not be used on its own!');
   34 }
   35 
   36 function baw_render_map($data, $top_x = false) {
   37     global $BAW_CONF;
   38     // if we don't have GD2 functions, we can't generate the image
   39     baw_debug("rendering map");
   40     if (!function_exists('imagecreatetruecolor')) {
   41         echo baw_raise_error('gd2notavailable', array());
   42         return;
   43     }
   44 
   45     $im = $BAW_CONF['site_path'] .'/icons/wmap.png';
   46     if (!file_exists($im)) {
   47         echo baw_raise_error('mapnotavailable', array($im));
   48     }
   49 
   50     // fix data for geography
   51     $us_domains =array('us', 'mil', 'edu', 'gov', 'arpa');
   52     foreach ($us_domains as $us_domain) {
   53         if (isset($data[$us_domain][3])) {
   54             if (!isset($data['us'])) {
   55                 $data['us'] = array(0,0,0,0,0);
   56             }
   57             $data['us'][3] += $data[$us_domain][3];
   58         }
   59         if (isset($data[$us_domain][4])) {
   60             if (!isset($data['us'])) {
   61                 $data['us'] = array(0,0,0,0,0);
   62             }
   63             $data['us'][4] += $data[$us_domain][4];
   64         }
   65     }
   66     $new_data = '';
   67     $doms = 0;
   68     foreach ($data as $country => $vars) {
   69         if (($doms >= $top_x) && ($top_x !== false)) {
   70             break;
   71         }
   72         $new_data .= "&amp;c[$country][0]={$vars[3]}&amp;c[$country][1]={$vars[4]}";
   73         $doms ++;
   74     }
   75     $module = $BAW_CONF['module'];
   76     if ($module == 'drupal') {
   77         $img_url = drupal_get_path('module', 'bawstats');
   78     } else {
   79         $img_url = $BAW_CONF['site_url'];
   80     }
   81     $img_url .= "/modules/render_map.inc.php?getmap=true$new_data&amp;m=$module";
   82     $out = "<div class=\"aligncenter\"><img width=\"574\" height=\"286\" alt=\"map of domains\" src=\"$img_url\"" . XHTML . "></div>";
   83     baw_debug("rendering map finished");
   84     return $out;
   85 }
   86 
   87 function baw_render_map_img() {
   88     $data = $_GET['c'];
   89     $module = $_GET['m'];
   90 
   91     // Set headers
   92     header('Expires: Mon, 01 Jan 1997 05:00:00 GMT');
   93     header('Cache-Control: no-store, no-cache, must-revalidate');
   94     header('Cache-Control: post-check=0, pre-check=0', false);
   95     header('Pragma: no-cache');
   96 
   97     header('Content-type: image/png');
   98 
   99     if ($module == 'drupal') {
  100         $BAW_CONF['site_path'] = drupal_get_path('module', 'bawstats');
  101     } else {
  102         include_once("./../config.php");
  103     }
  104 
  105     $im = $BAW_CONF['site_path'] .'/icons/wmap.png';
  106     if (!file_exists($im)) {
  107         echo "Error!";
  108     }
  109     $im = imagecreatefrompng($im);
  110     imagealphablending($im, true);
  111 
  112     $mapX = imagesx($im);
  113     $mapY = imagesy($im);
  114 
  115     $dommap = array(
  116         'uk' => array(266,88), 'au' => array(485,224), 'nz' => array(545,251),
  117         'be' => array(276,95), 'es' => array(262,116), 'pt' => array(256,117),
  118         'ad' => array(271,111), 'it' => array(289,111), 'fr' => array(272,103),
  119         'ie' => array(257,90), 'nl' => array(277,92), 'de' => array(284,94),
  120         'pl' => array(292,91), 'lu' => array(276,97), 'ch' => array(283,102),
  121         'at' => array(287,102), 'gr' => array(304,118), 'al' => array(300,114),
  122         'cs' => array(299,109), 'ba' => array(296,108), 'mk' => array(303,114),
  123         'bg' => array(307,110), 'ro' => array(309,105), 'hu' => array(300,102),
  124         'sk' => array(300,99), 'cz' => array(292,97), 'pl' => array(296,91),
  125         'dk' => array(283,83), 'va' => array(288,112), 'tr' => array(321,117),
  126         'ua' => array(320,97), 'by' => array(312,88), 'lt' => array(304,86),
  127         'lv' => array(305,81), 'ee' => array(308,77), 'fi' => array(310,65),
  128         'se' => array(296,64), 'no' => array(281,72), 'is' => array(241,62),
  129         'cy' => array(321,125), 'sy' => array(329,125), 'il' => array(325,129),
  130         'ps' => array(325,130), 'jo' => array(326,132), 'sa' => array(339,142),
  131         'iq' => array(340,130), 'ir' => array(358,130), 'kw' => array(344,135),
  132         'bh' => array(348,140), 'qa' => array(350,141), 'ae' => array(355,144),
  133         'om' => array(358,148), 'ye' => array(345,157), 'eg' => array(316,140),
  134         'pk' => array(372,135), 'af' => array(368,125), 'tm' => array(364,119),
  135         'uz' => array(365,111), 'kz' => array(371,97), 'kg' => array(379,112),
  136         'ti' => array(378,116), 'in' => array(391,152), 'np' => array(402,137),
  137         'bd' => array(411,143), 'lk' => array(396,171), 'bt' => array(412,137),
  138         'mm' => array(419,146), 'la' => array(431,151), 'vn' => array(435,149),
  139         'kh' => array(435,162), 'th' => array(431,159), 'my' => array(430,177),
  140         'sg' => array(433,180), 'ph' => array(462,162), 'id' => array(459,185),
  141         'ti' => array(468,197), 'tw' => array(460,144), 'cn' => array(433,120),
  142         'mm' => array(411,92), 'ru' => array(399,64), 'kr' => array(471,121),
  143         'kp' => array(469,115), 'jp' => array(490,120), //TODO polynesia
  144         'gl' => array(204,27), 'ca' => array(103,76), 'us' => array(107,116),
  145         'bm' => array(160,132), 'mx' => array(108,145), 'cu' => array(145,149),
  146         'gt' => array(126,156), 'bz' => array(129,155), 'hn' => array(134,160),
  147         'sv' => array(128,161), 'ni' => array(136,163), 'cr' => array(138,169),
  148         'pa' => array(145,170), 'co' => array(152,176), 've' => array(165,170),
  149         'gy' => array(175,174), 'sr' => array(182,177), 'gf' => array(186,177),
  150         'pe' => array(151,196), 'ec' => array(147,183), 'br' => array(189,197),
  151         'bo' => array(170,212), 'py' => array(176,218), 'uy' => array(182,235),
  152         'cl' => array(158,231), 'ar' => array(168,235), 'fk' => array(177,274),
  153         'ly' => array(293,135), 'tn' => array(284,124), 'dz' => array(174,128),
  154         'ma' => array(258,130), 'eh' => array(249,139), 'mr' => array(252,152),
  155         'ml' => array(263,154), 'ne' => array(282,155), 'td' => array(304,158),
  156         'sd' => array(316,154), 'et' => array(331,165), 'er' => array(330,156),
  157         'dj' => array(336,162), 'sn' => array(246,159), 'gm' => array(244,160),
  158         'gw' => array(246,163), 'gn' => array(248,163), 'sl' => array(250,168),
  159         'lr' => array(255,172), 'ci' => array(260,170), 'gh' => array(267,169),
  160         'bf' => array(266,163), 'bj' => array(273,176), 'ng' => array(276,167),
  161         'tg' => array(174,167), 'cm' => array(288,174), 'cf' => array(299,170),
  162         'so' => array(343,173), 'ke' => array(325,183), 'cd' => array(309,186),
  163         'ug' => array(319,183), 'rw' => array(319,188), 'bi' => array(319,190),
  164         'tz' => array(325,194), 'ao' => array(298,200), 'zm' => array(313,204),
  165         'mz' => array(329,202), 'mw' => array(323,204), 'zw' => array(315,212),
  166         'bw' => array(305,221), 'na' => array(296,216), 'za' => array(306,230),
  167         'sz' => array(317,227), 'mg' => array(343,212),  'com' => array(40,158),
  168         'net' => array(40,188), 'org' => array(40,221), 'info' => array(94,222),
  169         'ip' => array(94,189), 'mobi'=>  array(40,253), 'mobi'=>  array(94,253)
  170     );
  171 
  172     $maxpages = 0;
  173     $maxhits = 0;
  174     $doms = array();
  175     //var_dump($data);
  176     foreach ($data as $domain => $set) {
  177         $pages  = $set[0];
  178         $hits  = $set[1];
  179         // we use hits here since they are always bigger than pages
  180         if (isset($dommap[$domain]) && ($hits>0)) {
  181             $doms[$domain] = array('pages' => $pages, 'hits' => $hits);
  182             if ($hits > $maxhits) {
  183                 $maxhits = $hits;
  184             }
  185             if ($pages > $maxpages) {
  186                 $maxpages = $pages;
  187             }
  188         }
  189     }
  190 
  191     $crcblue = $BAW_CONF['site_path'] .'/icons/circ-blue.png';
  192     $crcblue = @imagecreatefrompng($crcblue);
  193     imagealphablending($crcblue, true);
  194     $crcgreen = $BAW_CONF['site_path'] .'/icons/circ-green.png';
  195     $crcgreen = @imagecreatefrompng($crcgreen);
  196     imagealphablending($crcgreen, true);
  197     $crcX = imagesx($crcgreen);
  198     $crcY = imagesy($crcgreen);
  199 
  200     $maxcirc = 80;
  201     $mincirc = 2;
  202 
  203     foreach ($doms as $dom => $val) {
  204         $hits = ($val['hits'] / $maxhits);
  205         $scz = $mincirc + ($hits*($maxcirc-$mincirc));
  206         imagecopyresampled(
  207             $im,
  208             $crcgreen,
  209             $dommap[$dom][0]-1,
  210             $dommap[$dom][1]-($scz/2),
  211             0,
  212             0,
  213             $scz/2,
  214             $scz,
  215             $crcX,
  216             $crcY
  217         );
  218         $pages = ($val['pages'] / $maxpages);
  219         $scz = $mincirc + ($pages*($maxcirc-$mincirc));
  220         imagecopyresampled(
  221             $im,
  222             $crcblue,
  223             $dommap[$dom][0]-($scz/2),
  224             $dommap[$dom][1]-($scz/2),
  225             0,
  226             0,
  227             $scz/2,
  228             $scz,
  229             $crcX,
  230             $crcY
  231         );
  232     }
  233     //output image to browser
  234     imagepng($im);
  235     imagedestroy($im);
  236 }