PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/module/stats/index.php

https://github.com/benhorns/daniel
PHP | 389 lines | 279 code | 81 blank | 29 comment | 19 complexity | 9c17c1ffb92215717f24d31a1be90a12 MD5 | raw file
  1. <?php if (!defined('SITE')) exit('No direct script access allowed');
  2. class Stats extends Router
  3. {
  4. var $error = FALSE;
  5. var $error_msg;
  6. function Stats()
  7. {
  8. parent::Router();
  9. }
  10. function page_index()
  11. {
  12. global $go;
  13. // default/validate $_GET
  14. $go['page'] = getURI('page', 0, 'digit', 5);
  15. $this->template->location = $this->lang->word('main');
  16. // sub-locations
  17. $this->template->sub_location[] = array($this->lang->word('referrers'),
  18. "?a=$go[a]&amp;q=refer");
  19. $this->template->sub_location[] = array($this->lang->word('page visits'),
  20. "?a=$go[a]&amp;q=hits");
  21. load_module_helper('files', $go['a']);
  22. $today = convertToStamp(getNow());
  23. $day = substr($today,6,2);
  24. $mn = substr($today,4,2);
  25. $yr = substr($today,0,4);
  26. $thirtydays = date('Y-m-d', mktime('00', '00', '00', $mn-1, $day, $yr));
  27. // ++++++++++++++++++++++++++++++++++++++++++++++++++++
  28. $body = "<div class='half'>\n";
  29. $body .= "<div class='cola'>\n";
  30. $total_since_hits = $this->db->getCount("SELECT count(*) FROM ".PX."stats");
  31. $total_since_unique_hits = $this->db->getCount("SELECT COUNT(DISTINCT hit_addr) AS 'total' FROM ".PX."stats");
  32. $total_since_refer_hits = $this->db->getCount("SELECT COUNT(DISTINCT hit_addr) AS 'total' FROM ".PX."stats WHERE hit_referrer != ''");
  33. $body .= "<table class='table380' cellpadding='0' cellspacing='0' border='0'>\n";
  34. $body .= "<tr>\n";
  35. $body .= th($this->lang->word('since'), "class='toptext' width='40%'");
  36. $body .= th($this->lang->word('total'), "class='toptext cell-middle' width='20%'");
  37. $body .= th($this->lang->word('unique'), "class='toptext cell-middle' width='20%'");
  38. $body .= th($this->lang->word('refers'), "class='toptext cell-middle' width='20%'");
  39. $body .= "</tr>\n";
  40. $body .= "<tr class='over'>\n";
  41. $body .= td(convertDate($this->access->settings['installdate'],
  42. $this->access->prefs['user_offset'],
  43. $this->access->prefs['user_format']),"class='cell-doc'");
  44. $body .= td('<b>'.$total_since_hits.'</b>',"class='cell-middle'");
  45. $body .= td('<b>'.$total_since_unique_hits.'</b>',"class='cell-middle'");
  46. $body .= td('<b>'.$total_since_refer_hits.'</b>',"class='cell-middle'");
  47. $body .= "</tr>\n";
  48. $body .= "</table>\n";
  49. // ++++++++++++++++++++++++++++++++++++++++++++
  50. // dailies
  51. $days = getDailyHits(NULL);
  52. $body .= "<table class='table380' cellpadding='0' cellspacing='0' border='0'>\n";
  53. $body .= "<tr>\n";
  54. $body .= th($this->lang->word('this week'), "class='toptext' width='40%'");
  55. $body .= th($this->lang->word('total'), "class='toptext cell-middle' width='20%'");
  56. $body .= th($this->lang->word('unique'), "class='toptext cell-middle' width='20%'");
  57. $body .= th($this->lang->word('refers'), "class='toptext cell-middle' width='20%'");
  58. $body .= "</tr>\n";
  59. $i = 1;
  60. foreach ($days as $key => $out) {
  61. $body .= "<tr".row_color(" class='color'").">\n";
  62. $body .= td($this->lang->word($key), "class='cell-doc'");
  63. $body .= td($this->db->getCount("SELECT count(*) FROM ".PX."stats WHERE hit_time > '$out[0]' AND hit_time < '$out[1]'"),"class='cell-middle'");
  64. $body .= td($this->db->getCount("SELECT count(DISTINCT hit_addr) FROM ".PX."stats WHERE hit_time > '$out[0]' AND hit_time < '$out[1]'"),"class='cell-middle'");
  65. $body .= td($this->db->getCount("SELECT count(DISTINCT hit_addr) FROM ".PX."stats WHERE hit_time > '$out[0]' AND hit_time < '$out[1]' AND hit_referrer != ''"),"class='cell-middle'");
  66. $body .= "</tr>\n";
  67. $i++;
  68. }
  69. $body .= "</table>\n";
  70. // ++++++++++++++++++++++++++++++++++++++++++++
  71. $week = getWeekHits(NULL);
  72. $body .= "<table class='table380' cellpadding='0' cellspacing='0' border='0'>\n";
  73. $body .= "<tr>\n";
  74. $body .= th($this->lang->word('this month'), "class='toptext' width='40%'");
  75. $body .= th($this->lang->word('total'), "class='toptext cell-middle' width='20%'");
  76. $body .= th($this->lang->word('unique'), "class='toptext cell-middle' width='20%'");
  77. $body .= th($this->lang->word('refers'), "class='toptext cell-middle' width='20%'");
  78. $body .= "</tr>\n";
  79. $i = 1;
  80. foreach ($week as $key => $out) {
  81. $body .= "<tr".row_color(" class='color'").">\n";
  82. $body .= td($this->lang->word($key),"class='cell-doc'");
  83. $body .= td($this->db->getCount("SELECT count(*) FROM ".PX."stats WHERE hit_time > '$out[0]' AND hit_time < '$out[1]'"),"class='cell-middle'");
  84. $body .= td($this->db->getCount("SELECT count(DISTINCT hit_addr) FROM ".PX."stats WHERE hit_time > '$out[0]' AND hit_time < '$out[1]'"),"class='cell-middle'");
  85. $body .= td($this->db->getCount("SELECT count(DISTINCT hit_addr) FROM ".PX."stats WHERE hit_time > '$out[0]' AND hit_time < '$out[1]' AND hit_referrer != ''"),"class='cell-middle'");
  86. $body .= "</tr>\n";
  87. $i++;
  88. }
  89. $body .= "</table>\n";
  90. // ++++++++++++++++++++++++++++++++++++++++++++
  91. $months = getMonthlyHits(NULL);
  92. $body .= "<table class='table380' cellpadding='0' cellspacing='0' border='0'>\n";
  93. $body .= "<tr>\n";
  94. $body .= th($this->lang->word('year'), "class='toptext' width='40%'");
  95. $body .= th($this->lang->word('total'), "class='toptext cell-middle' width='20%'");
  96. $body .= th($this->lang->word('unique'), "class='toptext cell-middle' width='20%'");
  97. $body .= th($this->lang->word('refers'), "class='toptext cell-middle' width='20%'");
  98. $body .= "</tr>\n";
  99. $i = 1;
  100. foreach ($months as $key => $out) {
  101. $numero = $this->db->getCount("SELECT count(*) FROM ".PX."stats WHERE hit_time LIKE '$out[0]%'");
  102. $body .= "<tr".row_color(" class='color'").">\n";
  103. $body .= td($this->lang->word($key), "class='cell-doc'");
  104. $body .= td($numero,"class='cell-middle'");
  105. $body .= td($this->db->getCount("SELECT count(DISTINCT hit_addr) FROM ".PX."stats WHERE hit_time LIKE '$out[0]%'"),"class='cell-middle'");
  106. $body .= td($this->db->getCount("SELECT count(DISTINCT hit_addr) FROM ".PX."stats WHERE hit_time LIKE '$out[0]%' AND hit_referrer != ''"),"class='cell-middle'");
  107. $body .= "</tr>\n";
  108. $i++;
  109. }
  110. $body .= "</table>\n";
  111. $body .= "</div>\n";
  112. // ++++++++++++++++++++++++++++++++++++++++++++
  113. $body .= "<div class='colb'>\n";
  114. // ++++++++++++++++++++++++++++++++++++++++++++
  115. // top referrers...
  116. // we need to forget our own host...
  117. $repeat = $this->db->fetchArray("SELECT hit_referrer,hit_domain, COUNT(hit_referrer) AS 'refer' FROM ".PX."stats WHERE hit_referrer != '' AND hit_domain != '' AND hit_time > '$thirtydays' GROUP by hit_referrer ORDER BY refer DESC LIMIT 10");
  118. if (is_array($repeat)) {
  119. $body .= "<table class='table380' cellpadding='0' cellspacing='0' border='0'>\n";
  120. $body .= "<tr>\n";
  121. $body .= th($this->lang->word('top 10 referrers').' '.
  122. span("(".$this->lang->word('past 30').")","class='small-txt'")
  123. ,"class='toptext' width='75%'");
  124. $body .= th('Total',"class='toptext cell-middle' width='25%'");
  125. $body .= "</tr>\n";
  126. $i = 1;
  127. foreach ($repeat as $out) {
  128. $body .= "<tr".row_color(" class='color'").">\n";
  129. $host = parse_url($out['hit_referrer']);
  130. $body .= td(href($out['hit_domain'],$out['hit_referrer'],"target='_new'"),"class='cell-doc'");
  131. $body .= td($out['refer'],"class='cell-middle'");
  132. $body .= "</tr>\n";
  133. $i++;
  134. }
  135. $body .= "</table>\n";
  136. }
  137. // top search terms...
  138. $terms = $this->db->fetchArray("SELECT hit_keyword, COUNT(hit_keyword) AS 'keywords' FROM ".PX."stats WHERE hit_keyword != '' AND hit_time > '$thirtydays' GROUP by hit_keyword ORDER BY keywords DESC LIMIT 10");
  139. if (is_array($terms)) {
  140. $body .= "<table class='table380' cellpadding='0' cellspacing='0' border='0'>\n";
  141. $body .= "<tr>\n";
  142. $body .= th($this->lang->word('top 10 keywords').' '.
  143. span("(".$this->lang->word('past 30').")","class='small-txt'")
  144. ,"class='toptext' width='75%'");
  145. $body .= th('Total',"class='toptext cell-middle' width='25%'");
  146. $body .= "</tr>\n";
  147. $i = 1;
  148. foreach ($terms as $out) {
  149. $body .= "<tr".row_color(" class='color'").">\n";
  150. $keyword = ($out['hit_keyword'] == '') ? 'Unknown' : $out['hit_keyword'];
  151. $body .= td($keyword,"class='cell-doc'");
  152. $body .= td($out['keywords'],"class='cell-middle'");
  153. $body .= "</tr>\n";
  154. $i++;
  155. }
  156. $body .= "</table>\n";
  157. }
  158. // if installed...
  159. // top countries...
  160. $cntry = $this->db->fetchArray("SELECT hit_country, COUNT(hit_country) AS 'total' FROM ".PX."stats WHERE hit_country != '' AND hit_time > '$thirtydays' GROUP by hit_country ORDER BY total DESC LIMIT 10");
  161. if (is_array($cntry)) {
  162. $body .= "<table class='table380' cellpadding='0' cellspacing='0' border='0'>\n";
  163. $body .= "<tr>\n";
  164. $body .= th($this->lang->word('top 10 countries').' '.
  165. span("(".$this->lang->word('past 30').")","class='small-txt'")
  166. ,"class='toptext' width='75%'");
  167. $body .= th('Total',"class='toptext cell-middle' width='25%'");
  168. $body .= "</tr>\n";
  169. $i = 1;
  170. foreach ($cntry as $out) {
  171. $body .= "<tr".row_color(" class='color'").">\n";
  172. $country = ($out['hit_country'] == '') ? 'Unknown' : $out['hit_country'];
  173. $body .= td($country,"class='cell-doc'");
  174. $body .= td($out['total'],"class='cell-middle'");
  175. $body .= "</tr>\n";
  176. $i++;
  177. }
  178. $body .= "</table>\n";
  179. }
  180. // ++++++++++++++++++++++++++++++++++++++++++++
  181. $body .= "</div>\n";
  182. // ++++++++++++++++++++++++++++++++++++++++++++
  183. $body .= "<div class='cl'><!-- --></div>\n\n";
  184. $body .= "</div>\n";
  185. $this->template->body = $body;
  186. return;
  187. }
  188. function page_refer()
  189. {
  190. global $go;
  191. // default/validate $_GET
  192. $go['page'] = getURI('page', 0, 'digit', 3);
  193. $this->template->location = $this->lang->word('main');
  194. // sub-locations
  195. $this->template->sub_location[] = array($this->lang->word('page visits'),
  196. "?a=$go[a]&amp;q=hits");
  197. $this->template->sub_location[] = array($this->lang->word('main'),
  198. "?a=$go[a]");
  199. load_module_helper('files', $go['a']);
  200. $today = convertToStamp(getNow());
  201. $day = substr($today,6,2);
  202. $mn = substr($today,4,2);
  203. $yr = substr($today,0,4);
  204. $thirtydays = date('Y-m-d', mktime('00', '00', '00', $mn-1, $day, $yr));
  205. $rs = $this->db->fetchArray("SELECT * FROM ".PX."stats
  206. WHERE hit_referrer != ''
  207. ORDER by hit_time DESC
  208. LIMIT $go[page]," . $this->access->prefs['threads']*2 . "");
  209. // ++++++++++++++++++++++++++++++++++++++++++++++++++++
  210. // table for all our results
  211. $body = "<table cellpadding='0' cellspacing='0' border='0'>\n";
  212. $body .= "<tr class='top'>\n";
  213. $body .= "<th width='17%' class='toptext'><strong>".$this->lang->word('ip')." | ".$this->lang->word('date')."</strong></th>\n";
  214. $body .= "<th width='13%' class='toptext'><strong>".$this->lang->word('country')."</strong></th>\n";
  215. $body .= "<th width='50%' class='toptext'><strong>".$this->lang->word('page')." | ".$this->lang->word('refers')."</strong></th>\n";
  216. $body .= "<th width='20%' class='toptext'><strong>".$this->lang->word('keyword')."</strong></th>\n";
  217. $body .= "</tr>\n";
  218. $body .= "</table>\n";
  219. // dynamic output for table
  220. $body .= "<table cellpadding='0' cellspacing='0' border='0'>\n";
  221. if (!$rs)
  222. {
  223. $body .= tr(td('No records yet', "colspan='4'"));
  224. }
  225. else
  226. {
  227. foreach($rs as $ar) {
  228. $body .= tr(
  229. td(href($ar['hit_addr'],
  230. "http://www.dnsstuff.com/tools/city.ch?ip=$ar[hit_addr]","target='_new'").
  231. "<br /><small>" . convertDate($ar['hit_time'],
  232. $this->access->prefs['user_offset'],
  233. $this->access->prefs['user_format'] . ' %T') . "</small>",
  234. "width='17%' class='cell-doc'").
  235. td($ar['hit_country'],"width='13%' class='cell-doc'").
  236. td($ar['hit_page'].br().
  237. href($ar['hit_domain'], $ar['hit_referrer']),
  238. "width='50%' class='cell-mid'").
  239. td($ar['hit_keyword'],"width='20%' class='cell-mid'"),
  240. row_color(" class='color'"));
  241. }
  242. }
  243. // end dynamic rows output
  244. $body .= "</table>\n";
  245. // pagination
  246. $paginate = $this->template->tpl_paginate($go['page'], $this->access->prefs['threads']*2,
  247. "SELECT hit_id FROM ".PX."stats WHERE hit_referrer != ''",
  248. "?a=$go[a]&q=refer");
  249. $num = ($paginate['total'] == 0) ? '&nbsp;': $paginate['total'].' '.$this->lang->word('total pages');
  250. $body .=
  251. div(div($num,"class='col'").
  252. div($paginate['back'].$paginate['next'],"class='col txt-right'").
  253. div("<!-- -->","class='cl'"),"class='c2 brdr-top'");
  254. $this->template->body = $body;
  255. return;
  256. }
  257. function page_hits()
  258. {
  259. global $go;
  260. // default/validate $_GET
  261. $go['page'] = getURI('page', 0, 'digit', 5);
  262. $this->template->location = $this->lang->word('main');
  263. // sub-locations
  264. $this->template->sub_location[] = array($this->lang->word('referrers'),
  265. "?a=$go[a]&amp;q=refer");
  266. $this->template->sub_location[] = array($this->lang->word('main'),
  267. "?a=$go[a]");
  268. load_module_helper('files', $go['a']);
  269. $today = convertToStamp(getNow());
  270. $day = substr($today,6,2);
  271. $mn = substr($today,4,2);
  272. $yr = substr($today,0,4);
  273. $thirtydays = date('Y-m-d', mktime('00', '00', '00', $mn-1, $day, $yr));
  274. $rs = $this->db->fetchArray("SELECT hit_page,
  275. COUNT(hit_page) AS 'total'
  276. FROM ".PX."stats
  277. GROUP by hit_page
  278. ORDER BY total DESC");
  279. // ++++++++++++++++++++++++++++++++++++++++++++++++++++
  280. // table for all our results
  281. $body = "<table cellpadding='0' cellspacing='0' border='0'>\n";
  282. $body .= "<tr class='top'>\n";
  283. $body .= "<th width='90%' class='toptext'><strong>".$this->lang->word('page')."</strong></th>\n";
  284. $body .= "<th width='10%' class='toptext'><strong>".$this->lang->word('visits')."</strong></th>\n";
  285. $body .= "</tr>\n";
  286. $body .= "</table>\n";
  287. // dynamic output for table
  288. $body .= "<table cellpadding='0' cellspacing='0' border='0'>\n";
  289. if (!$rs)
  290. {
  291. $body .= tr(td('No hits yet', "colspan='2'"));
  292. }
  293. else
  294. {
  295. foreach($rs as $ar) {
  296. $body .= tr(
  297. td($ar['hit_page'],"width='90%' class='cell-doc'").
  298. td($ar['total'],"width='10%' class='cell-mid'"),
  299. row_color(" class='color'"));
  300. }
  301. }
  302. // end dynamic rows output
  303. $body .= "</table>\n";
  304. $this->template->body = $body;
  305. return;
  306. }
  307. }
  308. ?>