PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wordpress/wp-content/plugins/podpress/podpress_admin_stats_class.php

https://github.com/bill742/verbalbrew
PHP | 1961 lines | 1585 code | 171 blank | 205 comment | 314 complexity | a5136e2db41d32c39249e679f9bee3d5 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-3.0, AGPL-1.0, LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. License:
  4. ==============================================================================
  5. Copyright 2006 Dan Kuykendall (email : dan@kuykendall.org)
  6. Modifications: Jeff Norris (email : jeff@iscifi.tv)
  7. Thanks to The P2R Team ( prepare2respond.com ) for stats suggestions.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-107 USA
  19. */
  20. class podPressAdmin_class extends podPress_class {
  21. function podPressAdmin_class() {
  22. GLOBAL $wpdb;
  23. $this->path = get_option('siteurl').'/wp-admin/admin.php?page=podpress/podpress_stats.php';
  24. if (isset($_GET['display']) && is_string($_GET['display'])) {
  25. $this->path .= '&amp;display='.$_GET['display'];
  26. }
  27. // since 8.8.5 beta 3
  28. parent::wherestr_to_exclude_bots();
  29. $this->wpdb = $wpdb;
  30. /* set default language for graphs */
  31. $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  32. $primary_language = $languages[0];
  33. if (in_array($primary_language, array('de-de', 'de'))) {
  34. /* German specification */
  35. setlocale(LC_TIME, 'de_DE@euro:UTF-8', 'de_de:UTF-8', 'de_DE:UTF-8', 'de:UTF-8', 'ge:UTF-8', 'German_Germany.1252:UTF-8');
  36. $local_settings = array(
  37. 'numbers' => array(',', '.'),
  38. 'short_date' => '%a.%n%d.%m.%y',
  39. 'creation_date' => '%d.%m.%y',
  40. );
  41. } else {
  42. /* default specification: english */
  43. setlocale(LC_TIME, 'en_US:UTF-8', 'en_en:UTF-8', 'en:UTF-8');
  44. $local_settings = array(
  45. 'numbers' => array('.', ','),
  46. 'short_date' => '%a.%n%m/%d/%y',
  47. 'creation_date' => '%m/%d/%y',
  48. );
  49. }
  50. $this->local_settings = $local_settings;
  51. $this->podPress_class();
  52. return;
  53. }
  54. #############################################
  55. #############################################
  56. function podSafeDigit($digit = 0) {
  57. if (is_numeric($digit) && ($digit < 10000)) {
  58. $digit = abs((int)$digit);
  59. } else {
  60. $digit = 0;
  61. }
  62. return $digit;
  63. }
  64. #############################################
  65. #############################################
  66. function paging($start, $limit, $total, $text = null) {
  67. $pages = ceil($total / $limit);
  68. $actualpage = ceil($start / $limit);
  69. if ($pages > 0) {
  70. if ($start > 0) {
  71. $start_new = ($start - $limit < 0) ? 0 : ($start - $limit);
  72. $right = '<a href="'.$this->path.'&amp;start='.$start_new.'">'.__('Next Entries &raquo;').'</a>';
  73. }
  74. if ($start + $limit < $total) {
  75. $start_new = ($start + $limit);
  76. $left = '<a href="'.$this->path.'&amp;start='.$start_new.'">'.__('&laquo; Previous Entries').'</a>';
  77. }
  78. echo '<div id="podPress_paging">'."\n";
  79. echo ' <div id="podPress_pagingLeft">'."\n";
  80. if ($pages > 1) {
  81. if (!is_null($text)) {
  82. echo $text;
  83. }
  84. echo ' <select name="podPress_pageSelect" onchange="javascript: window.location = \''.$this->path.'&start=\'+this.value;">';
  85. $i = 0;
  86. while ($i < $total) {
  87. $selected = ($i == $start) ? ' selected="selected"': null;
  88. $newi = ($i + $limit);
  89. if ($newi > $total) {
  90. $newi = $total;
  91. }
  92. echo ' <option value="'.$i.'"'.$selected.'>'.ceil($total - ($newi - 1)).' - '.ceil($total - ($i)).'</option>';
  93. #$i = ($newi + 1);
  94. $i = $newi;
  95. }
  96. echo ' </select>';
  97. echo ' '.__('of', 'podpress').' '.$total;
  98. }
  99. echo ' </div>'."\n";
  100. echo ' <div id="podPress_pagingRight">';
  101. if ($start + $limit < $total) {
  102. echo $left;
  103. }
  104. if (($start + $limit < $total) AND ($start > 0)) {
  105. echo '&nbsp;&nbsp;|&nbsp;&nbsp;';
  106. }
  107. if ($start > 0) {
  108. echo $right;
  109. }
  110. echo " </div>\n";
  111. echo "</div>\n";
  112. }
  113. }
  114. // ntm: paging() revised for v8.8.5 beta 3
  115. // -'previous/next entries' string swaped
  116. // - '$text from x to y' - select box revised
  117. function paging2($start, $limit, $total, $text = null) {
  118. $pages = ceil($total / $limit);
  119. if ($pages > 0) {
  120. echo '<div id="podPress_paging">'."\n";
  121. echo ' <div id="podPress_pagingLeft">'."\n";
  122. if ($pages > 1) {
  123. if (!is_null($text)) {
  124. echo $text;
  125. }
  126. echo ' <select name="podPress_pageSelect" onchange="javascript: window.location = \''.$this->path.'&start=\'+this.value;">';
  127. $low = (1);
  128. for ($i=$low; $i <= $total; $i++) {
  129. $selected = (($i-1) == $start) ? ' selected="selected"': '';
  130. if ( ($i % $limit) == 1 ) {
  131. if ((($low-1)+$limit) < $total) {
  132. $high = ($low-1)+$limit;
  133. } else {
  134. $high = $total;
  135. }
  136. if ($low != $high) {
  137. echo ' <option value="'.($i-1).'"'.$selected.'>'.$low.' - '.$high.'</option>';
  138. } else {
  139. echo ' <option value="'.($i-1).'"'.$selected.'>'.$high.'</option>';
  140. }
  141. $low += $limit;
  142. }
  143. }
  144. echo ' </select>';
  145. echo ' '.__('of', 'podpress').' '.$total;
  146. }
  147. //echo '<p>'.$start.' | '.$limit.' | '.$total.' | '.$text.'</p>';
  148. echo ' </div>'."\n";
  149. if ($start + $limit < $total) {
  150. $right = '<a href="'.$this->path.'&amp;start='.($start+$limit).'">'.__('Next Entries &raquo;').'</a>';
  151. }
  152. if ($start > 0) {
  153. $left = '<a href="'.$this->path.'&amp;start='.($start-$limit).'">'.__('&laquo; Previous Entries').'</a>';
  154. }
  155. echo ' <div id="podPress_pagingRight">';
  156. if ($start > 0) {
  157. echo $left;
  158. }
  159. if (($start + $limit < $total) AND ($start > 0)) {
  160. echo '&nbsp;|&nbsp;';
  161. }
  162. if ($start + $limit < $total) {
  163. echo $right;
  164. }
  165. echo " </div>\n";
  166. echo "</div>\n";
  167. }
  168. }
  169. #############################################
  170. #############################################
  171. function podGetHighest($data) {
  172. $highest = 0;
  173. foreach ($data AS $key => $idata) {
  174. if ($idata->value > $highest) {
  175. $highest = $idata->value;
  176. }
  177. }
  178. return $highest;
  179. }
  180. #############################################
  181. #############################################
  182. function podGraph($data, $splitter = null) {
  183. $cnt_data = count($data);
  184. if ($cnt_data > 0) {
  185. $box_width = 600;
  186. $box_height = 400;
  187. $bar_margin = 2;
  188. $bar_width = floor(($box_width - ($cnt_data * $bar_margin)) / $cnt_data);
  189. $bar_width = ($bar_width < 2) ? 2: $bar_width;
  190. $highest = $this->podGetHighest($data);
  191. $factor = ($highest / $box_height);
  192. $output = '<div id="podGraph" style="height: '.$box_height.'px; width: '.$box_width.'px; float: left; border: 1px solid #ccc; padding: 0.5em;">';
  193. foreach ($data AS $key => $idata) {
  194. $image_height = floor($idata->value / $factor);
  195. $margin = ($box_height - $image_height);
  196. $bgcolor = (is_array($splitter) && ($idata->$splitter[0] == $splitter[1])) ? '#aaa': '#ccc';
  197. $bgcolor = ($image_height == $box_height) ? '#d00': $bgcolor;
  198. $output .= ' <div style="float: left; margin-top: '.$margin.'px; margin-right: '.$bar_margin.'px; height: '.$image_height.'px; background-color: '.$bgcolor.'; width: '.$bar_width.'px; cursor: help;'.$split.'" title="'.$idata->title.' ('.number_format($idata->value, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]).' x)"></div>'."\n";
  199. }
  200. $output .= "</div>\n";
  201. } else {
  202. $output = '<p>'.__('We\'re sorry. At the moment we don\'t have enough data collected to display the graph.', 'podpress')."</p>\n";
  203. }
  204. return $output;
  205. }
  206. #############################################
  207. #############################################
  208. function settings_stats_edit() {
  209. GLOBAL $wpdb, $wp_version;
  210. podPress_isAuthorized();
  211. $baseurl = get_option('siteurl') . '/wp-admin/admin.php?page=podpress/podpress_stats.php&display=';
  212. echo '<div class="wrap">'."\n";
  213. if ( TRUE == version_compare($wp_version, '2.7', '>=') ) {
  214. echo '<div id="podpress-icon" class="icon32"><br /></div>';
  215. }
  216. if ( TRUE == version_compare($wp_version, '2.8', '>=') ) {
  217. echo ' <h2>'.__('Download Statistics', 'podpress').'</h2>'."\n";
  218. // get the plugins version information via the WP plugins version check
  219. if ( TRUE == version_compare($wp_version, '2.9', '>=') ) {
  220. $versioninfo = get_site_transient( 'update_plugins' );
  221. } else {
  222. $versioninfo = get_transient( 'update_plugins' );
  223. }
  224. // If there is a new version then there is a 'response'. This is the method from the plugins page.
  225. if ( FALSE !== isset($versioninfo->response[plugin_basename(dirname(__FILE__).'/podpress.php')]->new_version) ) {
  226. echo '<div class="message updated"><p><a href="http://wordpress.org/extend/plugins/podpress/" target="_blank">'.__('a new podPress version is available', 'podpress').'</a></p></div>';
  227. }
  228. } else {
  229. echo ' <h2>'.__('Download Statistics', 'podpress').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.mightyseek.com/podpress/#download" target="_new"><img src="http://www.mightyseek.com/podpress_downloads/versioncheck.php?current='.PODPRESS_VERSION.'" alt="'.__('Checking for updates... Failed.', 'podpress').'" border="0" /></a></h2>'."\n";
  230. }
  231. if($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus') {
  232. // Show all statistics which are based on wp_stats [stat logging: Full and Full+]
  233. $navi = array(
  234. 'downloads_per_media_file' => __('Downloads Per Media File', 'podpress'),
  235. 'downloads_per_post' => __('Downloads Per Post', 'podpress'),
  236. 'topips' => __('Downloads Per IP Address', 'podpress'),
  237. 'graphbydate' => __('Graph by Date', 'podpress'),
  238. 'rawstats' => __('Raw Stats', 'podpress'),
  239. );
  240. echo ' <ul id="podPress_navi">'."\n";
  241. foreach ($navi AS $key => $value) {
  242. $active = (($_GET['display'] == $key) OR (!$_GET['display'] AND ($key == 'downloads_per_media_file'))) ? ' class="current"': null;
  243. echo ' <li class="podpress_stats_sub_menu_item"><a href="'.$baseurl.$key.'"'.$active.'>'.$value.'</a>';
  244. if($this->checkGD()) {
  245. if ($value == __('Graph by Date', 'podpress')) {
  246. echo ' (<a href="'.$baseurl.'graphbydatealt" title="'.sprintf(__('An alternative view of the %1$s', 'podpress'), __('Graph by Date', 'podpress')).'">'. __('alt', 'podpress').'</a>)';
  247. }
  248. }
  249. echo '</li>'."\n";
  250. }
  251. echo ' </ul>'."\n";
  252. // bot management menu (since 8.8.5 beta 3)
  253. $navi2 = array(
  254. 'botdb_mark_bots' => __('Select / Deselect Bots', 'podpress'),
  255. 'botdb_list' => __('List of Bots', 'podpress'),
  256. );
  257. echo ' <ul id="podPress_navi">'."\n";
  258. foreach ($navi2 AS $key => $value) {
  259. $active = (($_GET['display'] == $key) OR (!$_GET['display'] AND ($key == 'quickcounts'))) ? ' class="current"': null;
  260. echo ' <li class="podpress_stats_sub_menu_item"><a href="'.$baseurl.$key.'"'.$active.'>'.$value.'</a></li>'."\n";
  261. }
  262. echo ' </ul>'."\n";
  263. } else {
  264. // Show all statistics which are based on wp_statcounts [stat logging: Counts Only]
  265. // old: $_GET['display'] = 'downloads_per_media_file';
  266. $navi = array(
  267. 'quickcounts' => __('Quick Counts', 'podpress'),
  268. 'graphbypost' => __('Graph by Post', 'podpress'),
  269. );
  270. echo ' <ul id="podPress_navi">'."\n";
  271. foreach ($navi AS $key => $value) {
  272. $active = (($_GET['display'] == $key) OR (!$_GET['display'] AND ($key == 'quickcounts'))) ? ' class="current"': null;
  273. echo ' <li class="podpress_stats_sub_menu_item"><a href="'.$baseurl.$key.'"'.$active.'>'.$value.'</a>';
  274. if($this->checkGD()) {
  275. if($value == __('Graph by Post', 'podpress')) {
  276. echo ' (<a href="'.$baseurl.'graphbypostalt" title="'.sprintf(__('An alternative view of the %1$s', 'podpress'), __('Graph by Post', 'podpress')).'">'. __('alt', 'podpress').'</a>)';
  277. }
  278. }
  279. echo '</li>'."\n";
  280. }
  281. echo ' </ul>'."\n";
  282. }
  283. // Set Paging-Settings
  284. $start = (isset($_GET['start'])) ? $this->podSafeDigit($_GET['start']): 0;
  285. //~ ####################
  286. //~ Limit is limiting the number of rows of the statistic tables
  287. $limit = 25;
  288. //~ ####################
  289. // ntm: since 8.8.5 beta 3 there are two different default statistic tables quickcounts and downloads_per_media_file that is why the default value has to be found before that Switch (and not with this Switch)
  290. if (FALSE == isset($_GET['display']) OR FALSE !== empty($_GET['display'])) {
  291. if ($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus') {
  292. $show_this_page = 'downloads_per_media_file';
  293. } else {
  294. $show_this_page = 'quickcounts';
  295. }
  296. } else {
  297. $show_this_page = $_GET['display'];
  298. }
  299. Switch($show_this_page) {
  300. case 'botdb_list':
  301. // ntm: stat logging: Full and Full+
  302. podPress_isAuthorized();
  303. $botdb = get_option('podpress_botdb');
  304. if ( isset($_POST['podPress_submitted']) AND 'botdb' == $_POST['podPress_submitted'] ) {
  305. if ( function_exists('check_admin_referer') ) {
  306. check_admin_referer('podPress_botdb_nonce');
  307. }
  308. $IPs = $_POST['podpress_remote_ips'];
  309. $fullbotnames = stripslashes_deep($_POST['podpress_user_agents']);
  310. if ( is_array($botdb) ) {
  311. $something_removed=FALSE;
  312. if ( is_array($IPs) and is_array($botdb['IP'])) {
  313. $botdb['IP'] = array_diff($botdb['IP'], $IPs);
  314. sort($botdb['IP']);
  315. }
  316. if ( is_array($fullbotnames) and is_array($botdb['fullbotnames'])) {
  317. $botdb['fullbotnames'] = array_diff($botdb['fullbotnames'], $fullbotnames);
  318. sort($botdb['fullbotnames']);
  319. }
  320. }
  321. if ( isset($_POST['podpress_maxrowsperpage']) AND FALSE == empty($_POST['podpress_maxrowsperpage']) AND $limit <= intval($_POST['podpress_maxrowsperpage']) ) {
  322. $this->settings['maxrowsperpage_'.$show_this_page] = intval($_POST['podpress_maxrowsperpage']);
  323. }
  324. if ( isset($this->settings['maxrowsperpage_'.$show_this_page]) AND is_int($this->settings['maxrowsperpage_'.$show_this_page]) AND $limit <= $this->settings['maxrowsperpage_'.$show_this_page] ) {
  325. $limit = $this->settings['maxrowsperpage_'.$show_this_page];
  326. }
  327. $result = podPress_update_option('podPress_config', $this->settings);
  328. $updated=update_option('podpress_botdb', $botdb);
  329. if (isset($updated) AND TRUE === $updated) {
  330. echo '<div id="message" class="updated fade"><p>'. __('Settings Saved', 'podpress').'</p></div>';
  331. }
  332. }
  333. echo ' <div class="wrap">'."\n";
  334. echo ' <fieldset class="options">'."\n";
  335. echo ' <legend>'.__('The list of IP addresses and names of bots', 'podpress').'</legend>'."\n";
  336. echo ' <form method="post">'."\n";
  337. if ( function_exists('wp_nonce_field') ) { // since WP 2.0.4
  338. wp_nonce_field('podPress_botdb_nonce');
  339. }
  340. echo ' <table class="the-list-x widefat">'."\n";
  341. echo ' <thead>'."\n";
  342. echo ' <tr><th rowspan="2">'.__('Nr.', 'podpress').'</th><th rowspan="2">'.__('Bot IP Address', 'podpress').'</th><th rowspan="2">'.__('Bot User Agent', 'podpress').'</th><th colspan="2">'.__('Remove this', 'podpress').'</th></tr><tr><th>'.__('IP', 'podpress').'</th><th>'.__('Name', 'podpress').'</th></tr>'."\n";
  343. echo ' </thead>'."\n";
  344. echo ' <tbody>'."\n";
  345. $nobots = FALSE;
  346. if (is_array($botdb) and (is_array($botdb['fullbotnames']) OR is_array($botdb['IP'])) ) {
  347. $botnames_len = count($botdb['fullbotnames']);
  348. $IPs_len = count($botdb['IP']);
  349. $rows_total = max($botnames_len, $IPs_len);
  350. if ( $rows_total > ($start+$limit) ) {
  351. $high = $start+$limit;
  352. } else {
  353. $high = $rows_total;
  354. }
  355. $low = ($start+1);
  356. for ($i=$low; $i <= $high; $i++) {
  357. $style = ($i % 2) ? '' : ' class="alternate"';
  358. echo ' <tr'.$style.'>'."\n";
  359. echo ' <td>'.($start +$i).'.</td>'."\n";
  360. if ($i <= ($IPs_len-$start)) {
  361. $col_ip = ' <td>'.stripslashes($botdb['IP'][($i-1)]).'</td>'."\n";
  362. $col_ip_chb = ' <td><input type="checkbox" id="podpress_remote_ip_'.$i.'" name="podpress_remote_ips[]" value="'.$botdb['IP'][($i-1)].'" '.$ip_chb_checked.' /></td>'."\n";
  363. } else {
  364. $col_ip = $col_ip_chb = ' <td></td>'."\n";
  365. }
  366. if ($i <= ($botnames_len-$start)) {
  367. $col_botname = ' <td>'.stripslashes($botdb['fullbotnames'][($i-1)]).'</td>'."\n";
  368. $col_botname_chb = ' <td><input type="checkbox" id="podpress_user_agent_'.$i.'" name="podpress_user_agents[]" value="'.attribute_escape($botdb['fullbotnames'][($i-1)]).'" '.$name_chb_checked.' /></td>'."\n";
  369. } else {
  370. $col_botname = $col_botname_chb = ' <td></td>'."\n";
  371. }
  372. echo $col_ip.$col_botname.$col_ip_chb.$col_botname_chb;
  373. echo ' </tr>'."\n";
  374. }
  375. if ( 0 == $botnames_len AND 0 == $IPs_len ) {
  376. $nobots = TRUE;
  377. }
  378. } else {
  379. $nobots = TRUE;
  380. }
  381. if (TRUE == $nobots) {
  382. echo ' <td colspan="5">'.__('Currently are no IP addresses or user agents marked as bots.', 'podpress').'</td>'."\n";
  383. }
  384. echo ' </tbody>'."\n";
  385. echo ' <tfoot>'."\n";
  386. echo ' <tr>'."\n";
  387. echo ' <th colspan="5">'."\n";
  388. // Show paging
  389. echo $this->paging2($start, $limit, $rows_total, __('names and IPs','podpress'));
  390. echo ' </th>'."\n";
  391. echo ' </tr>'."\n";
  392. echo ' </tfoot>'."\n";
  393. echo ' </table>'."\n";
  394. $this->podpress_print_maxrowsperpage($limit);
  395. echo ' <p class="submit"> '."\n";
  396. echo ' <input class="button-primary" type="submit" name="Submit" value="'.__('Remove marked elements / Update options', 'podpress').' &raquo;" /><br />'."\n";
  397. echo ' </p> '."\n";
  398. echo ' <input type="hidden" name="podPress_submitted" value="botdb" />'."\n";
  399. echo ' </form>'."\n";
  400. echo ' </fieldset>'."\n";
  401. echo ' </div>';
  402. break;
  403. case 'botdb_mark_bots':
  404. // ntm: stat logging: Full and Full+
  405. podPress_isAuthorized();
  406. $blog_charset = get_bloginfo('charset');
  407. $botdb = get_option('podpress_botdb');
  408. if ( isset($_POST['podPress_submitted']) AND 'botdb' == $_POST['podPress_submitted'] ) {
  409. if ( function_exists('check_admin_referer') ) {
  410. check_admin_referer('podPress_botdb_nonce');
  411. }
  412. $IPs = $_POST['podpress_remote_ips'];
  413. $fullbotnames = stripslashes_deep($_POST['podpress_user_agents']);
  414. if (is_array($botdb)) {
  415. $current_IP_set = $_POST['podpress_current_IP_set'];
  416. $unique_current_data_IPs = array_unique($_POST['podpress_current_IP_set']);
  417. //add new bots
  418. if (is_array($IPs)) {
  419. $unique_IPs = array_unique($IPs);
  420. foreach ($unique_IPs as $IP) {
  421. if (is_array($botdb['IP'])) {
  422. if ( FALSE === array_search($IP, $botdb['IP']) ) {
  423. $botdb['IP'][] = $IP;
  424. }
  425. } else {
  426. $botdb['IP'][] = $IP;
  427. }
  428. }
  429. // eventually remove bots
  430. $unmarked_IPs = array_diff($unique_current_data_IPs, $unique_IPs);
  431. $botdb['IP'] = array_diff($botdb['IP'], $unmarked_IPs);
  432. sort($botdb['IP']);
  433. } else {
  434. if (is_array($botdb['IP'])) {
  435. $botdb['IP'] = array_diff($botdb['IP'], $unique_current_data_IPs);
  436. sort($botdb['IP']);
  437. }
  438. }
  439. $current_user_agent_set = $_POST['podpress_current_user_agent_set'];
  440. $unique_current_data_fbnames = array_unique($_POST['podpress_current_user_agent_set']);
  441. if (is_array($fullbotnames)) {
  442. $unique_fullbotnames = array_unique($fullbotnames);
  443. foreach ($unique_fullbotnames as $fullbotname) {
  444. if (is_array($botdb['fullbotnames'])) {
  445. if ( FALSE === array_search($fullbotname, $botdb['fullbotnames']) ) {
  446. $botdb['fullbotnames'][] = $fullbotname;
  447. }
  448. } else {
  449. $botdb['fullbotnames'][] = $fullbotname;
  450. }
  451. }
  452. // eventually remove bots
  453. $unmarked_fullbotnames = array_diff($unique_current_data_fbnames, $unique_fullbotnames);
  454. $botdb['fullbotnames'] = array_diff($botdb['fullbotnames'], $unmarked_fullbotnames);
  455. sort($botdb['fullbotnames']);
  456. } else {
  457. // eventually remove bots
  458. if (is_array($botdb['fullbotnames'])) {
  459. $botdb['fullbotnames'] = array_diff($botdb['fullbotnames'], $unique_current_data_fbnames);
  460. sort($botdb['fullbotnames']);
  461. }
  462. }
  463. } else {
  464. //add new bots (first time)
  465. if (is_array($IPs)) {
  466. $unique_IPs = array_unique($IPs);
  467. foreach ($unique_IPs as $IP) {
  468. $botdb['IP'][] = $IP;
  469. }
  470. }
  471. if (is_array($fullbotnames)) {
  472. $unique_fullbotnames = array_unique($fullbotnames);
  473. foreach ($unique_fullbotnames as $fullbotname) {
  474. $botdb['fullbotnames'][] = $fullbotname;
  475. }
  476. }
  477. }
  478. if ( isset($_POST['podpress_maxrowsperpage']) AND FALSE == empty($_POST['podpress_maxrowsperpage']) AND $limit <= intval($_POST['podpress_maxrowsperpage']) ) {
  479. $this->settings['maxrowsperpage_'.$show_this_page] = intval($_POST['podpress_maxrowsperpage']);
  480. }
  481. if ( isset($this->settings['maxrowsperpage_'.$show_this_page]) AND is_int($this->settings['maxrowsperpage_'.$show_this_page]) AND $limit <= $this->settings['maxrowsperpage_'.$show_this_page] ) {
  482. $limit = $this->settings['maxrowsperpage_'.$show_this_page];
  483. }
  484. $result = podPress_update_option('podPress_config', $this->settings);
  485. $updated=update_option('podpress_botdb', $botdb);
  486. if (isset($updated) AND TRUE === $updated) {
  487. echo '<div id="message" class="updated fade"><p>'. __('Settings Saved', 'podpress').'</p></div>';
  488. }
  489. }
  490. $where='';
  491. $rows_total = intval($wpdb->get_var('SELECT COUNT(DISTINCT remote_ip, user_agent) AS total FROM '.$wpdb->prefix.'podpress_stats '.$where));
  492. $query_string = 'SELECT DISTINCT remote_ip, user_agent FROM '.$wpdb->prefix.'podpress_stats '.$where.'ORDER BY dt DESC LIMIT '.$start.', '.$limit;
  493. $stats = $wpdb->get_results($query_string);
  494. echo ' <div class="wrap">'."\n";
  495. echo ' <fieldset class="options">'."\n";
  496. echo ' <legend>'.__('Which IP address or user agent name is from a web bot?', 'podpress').'</legend>'."\n";
  497. echo ' <p>'.__('Probably not every counted download is a download of a real human listener. Some hits are eventually from so called <a href="http://en.wikipedia.org/wiki/Internet_bot" target="_blank" title="en.Wikipedia: Internet Bot">Internet bots</a>. Every downloader has an <a href="http://en.wikipedia.org/wiki/IP_address" target="_blank" title="en.Wikipedia: IP Address">IP address</a> and a <a href="http://en.wikipedia.org/wiki/User_agent" target="_blank" title="en.Wikipedia: User Agent">user agent</a> name. The user agent name indicates often very good whether it is the name of a browser of a real listener or a name of a bot. Whether a IP address is one of a bot or not is more difficult. But there are some websites which can help to find out more about an IP address. (Some bots are using IP addresses only temporarily.)<br />The list below shows all unique combinations of IP addresses and user agent names. It is possible to select (resp. deselect) only the IP address or the user agent name or both. Downloads of the selected IP addresses or user agents do not appear in the statistics.', 'podpress').'</p>'."\n";
  498. echo ' <form method="post">'."\n";
  499. if ( function_exists('wp_nonce_field') ) { // since WP 2.0.4
  500. wp_nonce_field('podPress_botdb_nonce');
  501. }
  502. echo "\n".' <table class="the-list-x widefat">'."\n";
  503. echo ' <thead>'."\n";
  504. echo ' <tr><th rowspan="2">'.__('Nr.', 'podpress').'</th><th rowspan="2">'.__('IP Address', 'podpress').'</th><th rowspan="2">'.__('User Agent', 'podpress').'</th><th colspan="2">'.__('Is it a bot?', 'podpress').'</th></tr><tr><th>'.__('IP', 'podpress').'</th><th>'.__('Name', 'podpress').'</th></tr>'."\n";
  505. echo ' </thead>'."\n";
  506. echo ' <tbody>'."\n";
  507. if(0 < count($stats)) {
  508. $i = 0;
  509. foreach ($stats as $stat) {
  510. ++$i;
  511. $alternate = ($i % 2) ? '' : 'alternate';
  512. $bot_style = '';
  513. $ip_chb_checked = '';
  514. $name_chb_checked = '';
  515. if (TRUE == is_array($botdb)) {
  516. if (TRUE == is_array($botdb['IP']) AND FALSE !== array_search($stat->remote_ip, $botdb['IP'])) {
  517. $bot_style = ' podpress_is_bot';
  518. $ip_chb_checked = ' checked="checked"';
  519. }
  520. if (TRUE == is_array($botdb['fullbotnames']) AND FALSE !== array_search($stat->user_agent, $botdb['fullbotnames'])) {
  521. $bot_style = ' podpress_is_bot';
  522. $name_chb_checked = ' checked="checked"';
  523. }
  524. }
  525. echo ' <tr id ="podpress_ip_user_agent_row_'.($i).'" class="'.$alternate.$bot_style.'">'."\n";
  526. echo ' <td>'.($start+$i).'</td>'."\n";
  527. echo ' <td>'.$stat->remote_ip.'<input type="hidden" name="podpress_current_IP_set[]" value="'.$stat->remote_ip.'" /></td>'."\n";
  528. echo ' <td>'.podPress_strlimiter2($stat->user_agent, 80, TRUE).'<input type="hidden" name="podpress_current_user_agent_set[]" value="'.attribute_escape($stat->user_agent).'" /></td>'."\n";
  529. echo ' <td><input type="checkbox" id="podpress_remote_ip_'.$i.'" name="podpress_remote_ips[]" value="'.$stat->remote_ip.'" onclick="podpress_mark_same_all_bots( \'remote_ips\' , '.$i.', '.($start).' );" '.$ip_chb_checked.' /></td>'."\n";
  530. echo ' <td><input type="checkbox" id="podpress_user_agent_'.$i.'" name="podpress_user_agents[]" value="'.attribute_escape($stat->user_agent).'" onclick="podpress_mark_same_all_bots( \'user_agent\' , '.$i.', '.($start).' );" '.$name_chb_checked.' /></td>'."\n";
  531. echo ' </tr>'."\n";
  532. }
  533. } else {
  534. echo '<td colspan="5">'.__('No downloads yet.','podpress')."</td>\n";
  535. }
  536. echo ' </tbody>'."\n";
  537. echo ' <tfoot>'."\n";
  538. echo ' <tr>'."\n";
  539. echo ' <th colspan="5">'."\n";
  540. // Show paging
  541. echo $this->paging2($start, $limit, $rows_total, __('names and IPs','podpress'));
  542. echo ' </th>'."\n";
  543. echo ' </tr>'."\n";
  544. echo ' </tfoot>'."\n";
  545. echo ' </table>'."\n";
  546. $this->podpress_print_maxrowsperpage($limit);
  547. echo ' <p class="submit"> '."\n";
  548. echo ' <input class="button-primary" type="submit" name="Submit" value="'.__('Update Options', 'podpress').' &raquo;" /><br />'."\n";
  549. echo ' </p> '."\n";
  550. echo ' <input type="hidden" name="podPress_submitted" value="botdb" />'."\n";
  551. echo ' </form>'."\n";
  552. echo ' </fieldset>'."\n";
  553. echo ' </div>';
  554. break;
  555. case 'downloads_per_media_file':
  556. // ntm: stat logging: Full and Full+
  557. $where = $this->wherestr_to_exclude_bots('pod');
  558. $query_string = "SELECT COUNT(DISTINCT pod.media) as total_rows FROM ".$wpdb->prefix."podpress_stats as pod ".$where;
  559. $rows_total = intval($wpdb->get_var($query_string));
  560. if ( isset($_POST['podPress_submitted']) AND $show_this_page == $_POST['podPress_submitted'] ) {
  561. if ( isset($_POST['podpress_maxrowsperpage']) AND FALSE == empty($_POST['podpress_maxrowsperpage']) AND $limit <= intval($_POST['podpress_maxrowsperpage']) ) {
  562. $this->settings['maxrowsperpage_'.$show_this_page] = intval($_POST['podpress_maxrowsperpage']);
  563. }
  564. $result = podPress_update_option('podPress_config', $this->settings);
  565. }
  566. if ( isset($this->settings['maxrowsperpage_'.$show_this_page]) AND is_int($this->settings['maxrowsperpage_'.$show_this_page]) AND $limit <= $this->settings['maxrowsperpage_'.$show_this_page] ) {
  567. $limit = $this->settings['maxrowsperpage_'.$show_this_page];
  568. }
  569. $query_string = "SELECT DISTINCT (pod.media) FROM ".$wpdb->prefix."podpress_stats as pod ".$where." LIMIT ".$start.", ".$limit;
  570. $posts_with_podpressmedia = $wpdb->get_results($query_string);
  571. $nr_postswpm = count($posts_with_podpressmedia);
  572. if ( 0 < $nr_postswpm) {
  573. $i=1;
  574. if (FALSE == empty($where)) {
  575. $where_posts = "AND pod.media IN (";
  576. } else {
  577. $where_posts = "WHERE pod.media IN (";
  578. }
  579. foreach ($posts_with_podpressmedia as $post) {
  580. if ($i == $nr_postswpm) {
  581. $where_posts .= "'".$wpdb->escape($post->media)."'";
  582. } else {
  583. $where_posts .= "'".$wpdb->escape($post->media)."', ";
  584. }
  585. $i++;
  586. }
  587. $where_posts .= ") ";
  588. } else {
  589. $where_posts = '';
  590. }
  591. $query_string="SELECT pod.media, pod.method, COUNT(*) as downloads FROM ".$wpdb->prefix."podpress_stats as pod ".$where.$where_posts."GROUP BY pod.method, pod.media ORDER BY pod.media DESC";
  592. $stat_data_sets = $wpdb->get_results($query_string);
  593. if (FALSE == empty($where)) {
  594. $where_or_and = "AND";
  595. } else {
  596. $where_or_and = "WHERE";
  597. }
  598. $methods = Array('feed', 'web', 'play');
  599. foreach ($methods as $method) {
  600. $query_string="SELECT COUNT(*) as downloads, pod.media FROM ".$wpdb->prefix."podpress_stats AS pod ".$where.$where_or_and." pod.method='".$method."' GROUP BY pod.media ORDER BY downloads DESC";
  601. $downloads_col = $wpdb->get_col($query_string);
  602. switch ($method) {
  603. case 'feed' :
  604. $feed_max = intval($downloads_col[0]);
  605. break;
  606. case 'web' :
  607. $web_max = intval($downloads_col[0]);
  608. break;
  609. case 'play' :
  610. $play_max = intval($downloads_col[0]);
  611. break;
  612. }
  613. }
  614. $query_string="SELECT COUNT(*) as downloads, pod.media FROM ".$wpdb->prefix."podpress_stats AS pod ".$where." GROUP BY pod.media ORDER BY downloads DESC";
  615. $downloads_col = $wpdb->get_col($query_string);
  616. $total_max = intval($downloads_col[0]);
  617. // prepare the query result for the output:
  618. // - if a media file was not downloaded by one or more method then add this method and a int(0) to the media file
  619. foreach ($stat_data_sets as $stat_data_set) {
  620. $feed = $web = $play = 0;
  621. switch ($stat_data_set->method) {
  622. case 'feed' :
  623. $feed = intval($stat_data_set->downloads);
  624. break;
  625. case 'web' :
  626. $web = intval($stat_data_set->downloads);
  627. break;
  628. case 'play' :
  629. $play = intval($stat_data_set->downloads);
  630. break;
  631. }
  632. $total_sum = $feed+$web+$play;
  633. $stats[$stat_data_set->media]['feed'] += $feed;
  634. $stats[$stat_data_set->media]['web'] += $web;
  635. $stats[$stat_data_set->media]['play'] += $play;
  636. $stats[$stat_data_set->media]['total'] += $total_sum;
  637. }
  638. // sort the media files by their 'total' value
  639. if ( is_array($stats) AND FALSE == empty($stats) AND method_exists($this, 'sort_downloads_per_media_desc') ) {
  640. uasort($stats, array($this, 'sort_downloads_per_media_desc'));
  641. }
  642. echo ' <div class="wrap">'."\n";
  643. echo ' <fieldset class="options">'."\n";
  644. echo ' <legend>'.__('Downloads Per Media File', 'podpress').'</legend>'."\n";
  645. echo ' <table class="the-list-x widefat">'."\n";
  646. echo ' <thead>';
  647. echo " <tr>\n";
  648. echo ' <th rowspan="2">'.__('Nr.', 'podpress')."</th>\n";
  649. echo ' <th rowspan="2">'.__('Media File', 'podpress')."</th>\n";
  650. echo ' <th class="podpress_stats_nr_head" colspan="2">'.__('Feed', 'podpress')."</th>\n";
  651. echo ' <th class="podpress_stats_nr_head" colspan="2">'.__('Web', 'podpress')."</th>\n";
  652. echo ' <th class="podpress_stats_nr_head" colspan="2">'.__('Play', 'podpress')."</th>\n";
  653. echo ' <th class="podpress_stats_nr_head" rowspan="2">'.__('Total', 'podpress')."</th>\n";
  654. echo ' </tr>'."\n";
  655. echo ' <tr>'."\n";
  656. echo ' <th class="podpress_stats_nr_head">'.__('Files', 'podpress')."</th>\n";
  657. echo ' <th class="podpress_stats_nr_head">'.__('%', 'podpress')."</th>\n";
  658. echo ' <th class="podpress_stats_nr_head">'.__('Files', 'podpress')."</th>\n";
  659. echo ' <th class="podpress_stats_nr_head">'.__('%', 'podpress')."</th>\n";
  660. echo ' <th class="podpress_stats_nr_head">'.__('Files', 'podpress')."</th>\n";
  661. echo ' <th class="podpress_stats_nr_head">'.__('%', 'podpress')."</th>\n";
  662. echo ' </tr>'."\n";
  663. echo ' </thead>';
  664. echo ' <tbody>';
  665. if (0 < count($stat_data_sets)) {
  666. $i = 0;
  667. foreach ( $stats as $media => $downloads_per_method ) {
  668. $i++;
  669. $style = ($i % 2 != 0) ? '' : ' class="alternate"';
  670. $highest_feed = ($downloads_per_method['feed'] == $feed_max AND 0 < $feed_max) ? ' podpress_stats_highest': '';
  671. $highest_web = ($downloads_per_method['web'] == $web_max AND 0 < $web_max) ? ' podpress_stats_highest': '';
  672. $highest_play = ($downloads_per_method['play'] == $play_max AND 0 < $play_max) ? ' podpress_stats_highest': '';
  673. $highest_total = ($downloads_per_method['total'] == $total_max AND 0 < $total_max) ? ' podpress_stats_highest': '';
  674. $perc_feed = number_format(($downloads_per_method['feed'] * 100 / $downloads_per_method['total']), 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
  675. $perc_web = number_format(($downloads_per_method['web'] * 100 / $downloads_per_method['total']), 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
  676. $perc_play = number_format(($downloads_per_method['play'] * 100 / $downloads_per_method['total']), 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
  677. echo ' <tr'.$style.'>'."\n";
  678. echo ' <td>'.($start +$i).'.</td>'."\n";
  679. echo ' <td>'.podPress_strlimiter2(urldecode($media), 50, TRUE).'</td>'."\n";
  680. echo ' <td class="podpress_stats_numbers_abs'.$highest_feed.'">'.number_format($downloads_per_method['feed'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1])."</td>\n";
  681. echo ' <td class="podpress_stats_numbers_percent'.$highest_feed.'">'.$perc_feed."</td>\n";
  682. echo ' <td class="podpress_stats_numbers_abs'.$highest_web.'" >'.number_format($downloads_per_method['web'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1])."</td>\n";
  683. echo ' <td class="podpress_stats_numbers_percent'.$highest_web.'">'.$perc_web."</td>\n";
  684. echo ' <td class="podpress_stats_numbers_abs'.$highest_play.'">'.number_format($downloads_per_method['play'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1])."</td>\n";
  685. echo ' <td class="podpress_stats_numbers_percent'.$highest_play.'">'.$perc_play."</td>\n";
  686. echo ' <td class="podpress_stats_numbers_total'.$highest_total.'">'.number_format($downloads_per_method['total'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1])."</td>\n";
  687. echo ' </tr>'."\n";
  688. }
  689. } else {
  690. if (FALSE == empty($where)) {
  691. echo '<td colspan="9">'.__('No downloads yet. (Bots have been filtered.)','podpress')."</td>\n";
  692. } else {
  693. echo '<td colspan="9">'.__('No downloads yet.','podpress')."</td>\n";
  694. }
  695. }
  696. echo ' </tbody>';
  697. echo ' <tfoot>'."\n";
  698. echo ' <tr>'."\n";
  699. echo ' <th colspan="9">'."\n";
  700. // Show paging
  701. echo $this->paging2($start, $limit, $rows_total, __('Ranks','podpress'));
  702. echo ' </th>'."\n";
  703. echo ' </tr>'."\n";
  704. echo ' </tfoot>'."\n";
  705. echo ' </table>'."\n";
  706. echo ' <form method="post">'."\n";
  707. $this->podpress_print_maxrowsperpage($limit, TRUE);
  708. echo ' <input type="hidden" name="podPress_submitted" value="'.$show_this_page.'" />'."\n";
  709. echo ' </form>'."\n";
  710. echo ' </fieldset>'."\n";
  711. echo ' </div>';
  712. break;
  713. case 'rawstats':
  714. // ntm: stat logging: Full and Full+
  715. $date_format = get_option('date_format');
  716. $time_format = get_option('time_format');
  717. $botdb = get_option('podpress_botdb');
  718. $where = '';
  719. if ( isset($_POST['podPress_submitted']) AND $show_this_page == $_POST['podPress_submitted'] ) {
  720. if ( isset($_POST['podpress_maxrowsperpage']) AND FALSE == empty($_POST['podpress_maxrowsperpage']) AND $limit <= intval($_POST['podpress_maxrowsperpage']) ) {
  721. $this->settings['maxrowsperpage_'.$show_this_page] = intval($_POST['podpress_maxrowsperpage']);
  722. }
  723. $result = podPress_update_option('podPress_config', $this->settings);
  724. }
  725. if ( isset($this->settings['maxrowsperpage_'.$show_this_page]) AND is_int($this->settings['maxrowsperpage_'.$show_this_page]) AND $limit <= $this->settings['maxrowsperpage_'.$show_this_page] ) {
  726. $limit = $this->settings['maxrowsperpage_'.$show_this_page];
  727. }
  728. $rows_total = $wpdb->get_var('SELECT COUNT(*) FROM '.$wpdb->prefix.'podpress_stats '.$where);
  729. $stats = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'podpress_stats '.$where.'ORDER BY id DESC LIMIT '.$start.', '.$limit);
  730. echo ' <div class="wrap">'."\n";
  731. echo ' <fieldset class="options">'."\n";
  732. echo ' <legend>'.__('The raw list', 'podpress').'</legend>'."\n";
  733. echo ' <table class="the-list-x widefat">'."\n"; //width="100%" cellpadding="1" cellspacing="1"
  734. echo ' <thead>';
  735. echo ' <tr><th>'.__('Hit', 'podpress').'</th><th>'.__('Media File', 'podpress').'</th><th>'.__('Method', 'podpress').'</th><th>'.__('IP', 'podpress').'</th><th>'.__('User Agent', 'podpress').'</th><th>'.__('Timestamp', 'podpress').'</th></tr>'."\n";
  736. echo ' </thead>';
  737. echo ' <tbody>';
  738. if(0 < count($stats)) {
  739. if ( TRUE === is_array($botdb['IP']) OR TRUE === is_array($botdb['fullbotnames']) ) {
  740. $i = 0;
  741. foreach ($stats as $stat) {
  742. ++$i;
  743. $style = ($i % 2) ? '' : 'alternate';
  744. if ( (FALSE !== empty($botdb['fullbotnames']) OR FALSE === array_search($stat->user_agent, $botdb['fullbotnames']))) {
  745. if ( (FALSE !== empty($botdb['IP']) OR FALSE === array_search($stat->remote_ip, $botdb['IP']))) {
  746. $bot_style = '';
  747. } else {
  748. $bot_style = ' podpress_is_bot';
  749. }
  750. } else {
  751. $bot_style = ' podpress_is_bot';
  752. }
  753. echo ' <tr class="'.$style.$bot_style.'">'."\n";
  754. echo ' <td>'.($start +$i).'.</td>'."\n";
  755. echo ' <td>'.podPress_strlimiter2(urldecode($stat->media), 20, TRUE).'</td>'."\n";
  756. echo ' <td>'.$stat->method.'</td>'."\n";
  757. // iscifi : mod of stats output to create a link to domaintools.com whois lookup
  758. // domaintools seems faster and provides more concise infomation, url can not have trailing /
  759. echo ' <td><a href="http://whois.domaintools.com/'.$stat->remote_ip.'" target="_blank" title="'.__('Look for more details about this IP at whois.domaintools.com', 'podpress').'">'.$stat->remote_ip.'</a></td>'."\n";
  760. // OLD code where this .echo ' <td>'.$stat->remote_ip.'</td>'."\n";
  761. echo ' <td>'.podPress_strlimiter2($stat->user_agent, 50, TRUE).'</td>'."\n";
  762. echo ' <td>'.date($date_format.' - '.$time_format, intval($stat->dt)).'</td>'."\n";
  763. echo ' </tr>'."\n";
  764. }
  765. } else {
  766. $i = 0;
  767. foreach ($stats as $stat) {
  768. ++$i;
  769. $style = ($i % 2) ? '' : 'alternate';
  770. echo ' <tr class="'.$style.'">'."\n";
  771. echo ' <td>'.($start +$i).'.</td>'."\n";
  772. echo ' <td>'.podPress_strlimiter2(urldecode($stat->media), 20, TRUE).'</td>'."\n";
  773. echo ' <td>'.$stat->method.'</td>'."\n";
  774. // iscifi : mod of stats output to create a link to domaintools.com whois lookup
  775. // domaintools seems faster and provides more concise infomation, url can not have trailing /
  776. echo ' <td><a href="http://whois.domaintools.com/'.$stat->remote_ip.'" target="_blank">'.$stat->remote_ip.'</a></td>'."\n";
  777. // OLD code where this .echo ' <td>'.$stat->remote_ip.'</td>'."\n";
  778. echo ' <td>'.podPress_strlimiter2($stat->user_agent, 50, TRUE).'</td>'."\n";
  779. echo ' <td>'.date($date_format.' - '.$time_format, intval($stat->dt)).'</td>'."\n";
  780. echo ' </tr>'."\n";
  781. }
  782. }
  783. } else {
  784. echo '<td colspan="6">'.__('No downloads yet.','podpress').'</td>'."\n";
  785. }
  786. echo ' </tbody>';
  787. echo ' <tfoot>'."\n";
  788. echo ' <tr>'."\n";
  789. echo ' <th colspan="6">'."\n";
  790. // Show paging
  791. echo $this->paging2($start, $limit, $rows_total, __('Hit','podpress'));
  792. echo ' </th>'."\n";
  793. echo ' </tr>'."\n";
  794. echo ' </tfoot>'."\n";
  795. echo ' </table>'."\n";
  796. echo ' <form method="post">'."\n";
  797. $this->podpress_print_maxrowsperpage($limit, TRUE);
  798. echo ' <input type="hidden" name="podPress_submitted" value="'.$show_this_page.'" />'."\n";
  799. echo ' </form>'."\n";
  800. echo ' </fieldset>'."\n";
  801. echo ' </div>';
  802. break;
  803. case 'topips':
  804. // ntm: stat logging: Full and Full+
  805. $where = $this->wherestr_to_exclude_bots();
  806. $rows_total = ($wpdb->get_var('SELECT COUNT(DISTINCT remote_ip) as uniq FROM '.$wpdb->prefix.'podpress_stats '.$where));
  807. if ( isset($_POST['podPress_submitted']) AND $show_this_page == $_POST['podPress_submitted'] ) {
  808. if ( isset($_POST['podpress_maxrowsperpage']) AND FALSE == empty($_POST['podpress_maxrowsperpage']) AND $limit <= intval($_POST['podpress_maxrowsperpage']) ) {
  809. $this->settings['maxrowsperpage_'.$show_this_page] = intval($_POST['podpress_maxrowsperpage']);
  810. }
  811. $result = podPress_update_option('podPress_config', $this->settings);
  812. }
  813. if ( isset($this->settings['maxrowsperpage_'.$show_this_page]) AND is_int($this->settings['maxrowsperpage_'.$show_this_page]) AND $limit <= $this->settings['maxrowsperpage_'.$show_this_page] ) {
  814. $limit = $this->settings['maxrowsperpage_'.$show_this_page];
  815. }
  816. $sql = 'SELECT remote_ip AS IPAddress, COUNT(DISTINCT remote_ip, media) as uniq, COUNT( * ) AS total FROM '.$wpdb->prefix.'podpress_stats '.$where.'GROUP BY remote_ip ORDER BY total DESC LIMIT '.$start.', '.$limit;
  817. $stats = $wpdb->get_results($sql);
  818. echo ' <div class="wrap">'."\n";
  819. echo ' <fieldset class="options">'."\n";
  820. echo ' <legend>'.__('Top IP Addresses', 'podpress').'</legend>'."\n";
  821. echo ' <table class="the-list-x widefat">'."\n";
  822. echo ' <thead>';
  823. echo ' <tr><th>'.__('Nr.', 'podpress').'</th><th>'.__('IP Address', 'podpress').'</th><th><abbr class="podpress_abbr" title="'.__('Only one download per file from this IP address has been counted. In other words: It is the number of different files which were downloaded from this IP address.','podpress').'">'.__('Unique Files', 'podpress').'</abbr></th><th>'.__('Total', 'podpress').'</th></tr>'."\n";
  824. echo ' </thead>';
  825. echo ' <tbody>';
  826. if(0<count($stats)) {
  827. $i = 0;
  828. foreach ($stats as $stat) {
  829. ++$i;
  830. $style = ($i % 2) ? '' : ' class="alternate"';
  831. echo ' <tr'.$style.'>'."\n";
  832. echo ' <td>'.($start +$i).'.</td>'."\n";
  833. echo ' <td>'.$stat->IPAddress.'</td>'."\n";
  834. echo ' <td>'.$stat->uniq.'</td>'."\n";
  835. echo ' <td>'.$stat->total.'</td>'."\n";
  836. echo ' </tr>'."\n";
  837. }
  838. } else {
  839. if (FALSE == empty($where)) {
  840. echo '<td colspan="4">'.__('No downloads yet. (Bots have been filtered.)','podpress')."</td>\n";
  841. } else {
  842. echo '<td colspan="4">'.__('No downloads yet.','podpress')."</td>\n";
  843. }
  844. }
  845. echo ' </tbody>';
  846. echo ' <tfoot>'."\n";
  847. echo ' <tr>'."\n";
  848. echo ' <th colspan="4">'."\n";
  849. // Show paging
  850. echo $this->paging2($start, $limit, $rows_total, __('IP Address','podpress'));
  851. echo ' </th>'."\n";
  852. echo ' </tr>'."\n";
  853. echo ' </tfoot>'."\n";
  854. echo ' </table>'."\n";
  855. echo ' <form method="post">'."\n";
  856. $this->podpress_print_maxrowsperpage($limit, TRUE);
  857. echo ' <input type="hidden" name="podPress_submitted" value="'.$show_this_page.'" />'."\n";
  858. echo ' </form>'."\n";
  859. echo ' </fieldset>'."\n";
  860. echo ' </div>';
  861. break;
  862. case 'graphbydate':
  863. // ntm: stat logging: Full and Full+
  864. if ($this->checkGD() ) {//&& ($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus')
  865. $this->graphByDate();
  866. } else {
  867. $this->graphByDateAlt('With <a href="http://us2.php.net/manual/en/ref.image.php">gdlib-support</a> you\'ll have access to more detailed graphicals stats. Please ask your provider.');
  868. }
  869. break;
  870. case 'graphbydatealt':
  871. // ntm: stat logging: Full and Full+
  872. $this->graphByDateAlt();
  873. break;
  874. case 'graphbypost':
  875. // ntm: stat logging: Counts Only
  876. echo '<p>'.__('<strong>Notice:</strong> This graph is only faultless if your podcast posts contain only one media file per post, each file has a unique name and if you change the media file name on a re-post (deleting a post and publishing the content in a new post)!', 'podpress').'</p>';
  877. if ($this->checkGD()) {
  878. $this->graphByPost();
  879. } else {
  880. $this->graphByPostAlt('With <a href="http://us2.php.net/manual/en/ref.image.php">gdlib-support</a> you\'ll have access to more detailed graphicals stats. Please ask your provider.');
  881. }
  882. break;
  883. case 'graphbypostalt':
  884. // ntm: stat logging: Counts Only
  885. echo '<p>'.__('<strong>Notice:</strong> This graph is only faultless if your podcast posts contain only one media file per post, each file has a unique name and if you change the media file name on a re-post (deleting a post and publishing the content in a new post)!', 'podpress').'</p>';
  886. $this->graphByPostAlt();
  887. break;
  888. case 'downloads_per_post' :
  889. // ntm: stat logging: Full and Full+
  890. $where = $this->wherestr_to_exclude_bots('pod');
  891. // get the number of all post with podPress podcasts
  892. //~ $query_string = "SELECT COUNT(DISTINCT postID) as posts FROM ".$wpdb->prefix."podpress_stats ".$where;
  893. // take only posts which are still in the wp_posts table. It is possible that the stats table contains stats of file which were only in posts which are deleted.
  894. if ( TRUE == empty($where) ) {
  895. $where_ID .= " WHERE p.ID = pod.postID";
  896. } else {
  897. $where_ID .= " AND p.ID = pod.postID";
  898. }
  899. // get all post with podPress podcasts
  900. $query_string = "SELECT DISTINCT(pod.postID), p.post_title FROM ".$wpdb->prefix."podpress_stats AS pod LEFT JOIN ".$wpdb->prefix."posts AS p ON pod.postID = p.ID ".$where.$where_ID." ORDER BY pod.postID DESC";
  901. $posts_with_podpressmedia = $wpdb->get_results($query_string);
  902. echo ' <div class="wrap">'."\n";
  903. echo ' <fieldset class="options">'."\n";
  904. echo ' <legend>'.__('Downloads Per Post', 'podpress').'</legend>'."\n";
  905. echo ' <form method="post">'."\n";
  906. if ( function_exists('wp_nonce_field') ) { // since WP 2.0.4
  907. wp_nonce_field('podPress_downloads_per_post_nonce');
  908. }
  909. echo ' <label>'.__('Select a post with a media file (attached with podPress):', 'podpress').'</label><br />'."\n";
  910. echo ' <select id="post_with_podpressmedia" name="post_with_podpressmedia" size="5">'."\n";
  911. foreach ($posts_with_podpressmedia as $post) {
  912. if ($post->postID == $_POST['post_with_podpressmedia']) {
  913. $selected = ' selected="selected"';
  914. } else {
  915. $selected = '';
  916. }
  917. echo ' <option value="'.$post->postID.'"'.$selected.'>'.$post->post_title.'</option>'."\n";
  918. $post_titles[$post->postID] = $post->post_title;
  919. }
  920. echo ' </select>'."\n";
  921. echo ' <p class="submit"> '."\n";
  922. echo ' <input type="submit" name="Submit" value="'.__('Show the stats for this post', 'podpress').' &raquo;" /><br />'."\n";
  923. echo ' </p> '."\n";
  924. echo ' <input type="hidden" name="podPress_submitted" value="downloadsperpost" />'."\n";
  925. echo ' </form>'."\n";
  926. echo ' </fieldset>'."…

Large files files are truncated, but you can click here to view the full file