PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/www/admin/lib-graph.inc.php

https://bitbucket.org/blackriver/openx
PHP | 201 lines | 107 code | 45 blank | 49 comment | 20 complexity | d31c504dfd66ffc86840799a84bb6233 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: lib-graph.inc.php 81772 2012-09-11 00:07:29Z chris.nutting $
  25. */
  26. // Required files
  27. require_once MAX_PATH . '/www/admin/lib-gdcolors.inc.php';
  28. require_once MAX_PATH . '/www/admin/lib-gd.inc.php';
  29. require_once MAX_PATH . '/lib/max/Delivery/common.php';
  30. /*-------------------------------------------------------*/
  31. /* Create the legends */
  32. /*-------------------------------------------------------*/
  33. function legend($im, $x, $y, $text, $fillcolor, $outlinecolor, $textcolor)
  34. {
  35. ImageFilledRectangle($im,$x,$y,$x+10,$y+10,$fillcolor);
  36. ImageRectangle($im,$x,$y,$x+10,$y+10,$outlinecolor);
  37. imagestring($im, 2, $x+15, $y, $text, $textcolor);
  38. }
  39. /*-------------------------------------------------------*/
  40. /* Main code */
  41. /*-------------------------------------------------------*/
  42. $i = 0;
  43. $totalViews = 0;
  44. $totalClicks = 0;
  45. $maxViews = 0;
  46. $maxClicks = 0;
  47. $count=array();
  48. $maxlen=0;
  49. $items_count=count($items);
  50. for($x=0;$x<$items_count;$x++)
  51. {
  52. // AdViews
  53. $count[$x] = $items[$x]["value1"];
  54. $totalViews += $items[$x]["value1"];
  55. if($items[$x]["value1"] > $maxViews)
  56. $maxViews = $items[$x]["value1"];
  57. // AdClicks
  58. $count2[$x] = $items[$x]["value2"];
  59. $totalClicks += $items[$x]["value2"];
  60. if($items[$x]["value2"] > $maxClicks)
  61. $maxClicks = $items[$x]["value2"];
  62. // Strings
  63. if(strlen($items[$x]['text']) > $maxlen)
  64. $maxlen=strlen($items[$x]['text']);
  65. }
  66. // Get next round number
  67. if (strlen($maxViews) > 2)
  68. $maxViews = ceil($maxViews / pow(10, strlen($maxViews) - 2)) * pow(10, strlen($maxViews) - 2);
  69. else
  70. $maxViews = 100;
  71. if (strlen($maxClicks) > 2)
  72. $maxClicks = ceil($maxClicks / pow(10, strlen($maxClicks) - 2)) * pow(10, strlen($maxClicks) - 2);
  73. elseif (strlen($maxClicks) > 1)
  74. $maxClicks = ceil($maxClicks / pow(10, strlen($maxClicks) - 1)) * pow(10, strlen($maxClicks) - 1);
  75. else
  76. $maxClicks = 10;
  77. // Use the same scale
  78. if (defined('LIB_GRAPH_SAME_SCALE'))
  79. {
  80. if ($maxViews > $maxClicks)
  81. $maxClicks = $maxViews;
  82. else
  83. $maxViews = $maxClicks;
  84. }
  85. // Margins
  86. $leftMargin = strlen($maxViews) * imageFontWidth(2);
  87. $rightMargin = strlen($maxClicks) * imageFontWidth(2);
  88. $margin = $leftMargin + $rightMargin;
  89. // Headers
  90. $text["value1"] .= ": ".$totalViews;
  91. $text["value2"] .= ": ".$totalClicks;
  92. // Dimensions
  93. if (!isset($height))
  94. $height=180;
  95. if (!isset($width))
  96. $width = max($margin + 20 + 12 * $items_count, $margin + 50 + imageFontwidth(2) * (strlen($text["value1"]) + strlen($text["value2"])));
  97. $im = imagecreate($width,$height);
  98. $bgcolor = ImageColorAllocate($im,$bgcolors[0],$bgcolors[1],$bgcolors[2]);
  99. $linecolor = ImageColorAllocate($im,$linecolors[0],$linecolors[1],$linecolors[2]);
  100. $graycolor = ImageColorAllocate($im,$RGB['lgray'][0],$RGB['lgray'][1],$RGB['lgray'][2]);
  101. $textcolor = ImageColorAllocate($im,$textcolors[0],$textcolors[1],$textcolors[2]);
  102. $adviewscolor = ImageColorAllocate($im,$adviewscolors[0],$adviewscolors[1],$adviewscolors[2]);
  103. $adclickscolor = ImageColorAllocate($im,$adclickscolors[0],$adclickscolors[1],$adclickscolors[2]);
  104. for($x=0;$x<$items_count;$x++)
  105. imagestringup($im, 1, $leftMargin + 12 + ($x * 12), 130 + imageFontwidth(1) * $maxlen , $items[$x]["text"], $textcolor);
  106. if ($maxViews == 0)
  107. $scaleViews = 100;
  108. else
  109. $scaleViews = (double)100/(double)$maxViews;
  110. if (defined('LIB_GRAPH_SAME_SCALE'))
  111. $scaleClicks = $scaleViews;
  112. elseif ($maxClicks == 0)
  113. $scaleClicks = 50;
  114. else
  115. $scaleClicks = (double)50/(double)$maxClicks;
  116. imageline($im, $leftMargin + 10, 20, $leftMargin + 10 + ($items_count * 12), 20, $graycolor);
  117. imageline($im, $leftMargin + 10, 45, $leftMargin + 10 + ($items_count * 12), 45, $graycolor);
  118. imageline($im, $leftMargin + 10, 70, $leftMargin + 10 + ($items_count * 12), 70, $graycolor);
  119. imageline($im, $leftMargin + 10, 95, $leftMargin + 10 + ($items_count * 12), 95, $graycolor);
  120. imageline($im, $leftMargin + 10, 120, $leftMargin + 10 + ($items_count * 12), 120, $linecolor);
  121. legend($im, $leftMargin + 10, 2, $text["value1"], $adviewscolor, $linecolor, $textcolor);
  122. legend($im, $leftMargin + 40 + (imageFontwidth(2) * strlen($text["value1"])), 2, $text["value2"], $adclickscolor, $linecolor, $textcolor);
  123. // Views
  124. imagestring($im, 2, $leftMargin - (imageFontwidth(2) * strlen($maxViews)), 12, $maxViews, $textcolor);
  125. imagestring($im, 2, $leftMargin - (imageFontwidth(2) * strlen('0')), 115, '0', $textcolor);
  126. // Clicks
  127. if (!defined('LIB_GRAPH_SAME_SCALE'))
  128. {
  129. imagestring($im, 2, $leftMargin + 20 + ($items_count * 12), 63, $maxClicks, $textcolor);
  130. imagestring($im, 2, $leftMargin + 20 + ($items_count * 12), 115, '0', $textcolor);
  131. }
  132. for($x = 0;$x<$items_count;$x++)
  133. {
  134. // AdViews
  135. ImageFilledRectangle($im, $leftMargin + 10 + ($x * 12), 120-(int)($count[$x]*$scaleViews), $leftMargin + 19 + ($x * 12), 120,$adviewscolor);
  136. ImageRectangle($im, $leftMargin + 10 + ($x * 12), 120-(int)($count[$x]*$scaleViews), $leftMargin + 19 + ($x * 12), 120,$linecolor);
  137. // AdClicks
  138. ImageFilledRectangle($im, $leftMargin + 12 + ($x * 12), 120-(int)($count2[$x]*$scaleClicks), $leftMargin + 21 + ($x * 12), 120,$adclickscolor);
  139. ImageRectangle($im, $leftMargin + 12 + ($x * 12), 120-(int)($count2[$x]*$scaleClicks), $leftMargin + 21 + ($x * 12), 120,$linecolor);
  140. }
  141. // IE workaround: Turn off outputbuffering
  142. // if zlib compression is turned on
  143. if (strpos ($_SERVER['HTTP_USER_AGENT'], 'MSIE') > 0 &&
  144. function_exists('ini_get') && (
  145. ini_get ('zlib.output_compression') ||
  146. ini_get ('output_handler') == 'ob_gzhandler'))
  147. ob_end_clean ();
  148. // Send the content-type header
  149. phpAds_GDContentType();
  150. // No caching
  151. MAX_commonSetNoCacheHeaders();
  152. // Display modified image
  153. phpAds_GDShowImage($im);
  154. // Release allocated ressources
  155. ImageDestroy($im);
  156. ?>