• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisão34a4ca0b0d69995f903e808936abceeb49ec1711 (tree)
Hora2017-06-11 21:47:12
Autorumorigu <umorigu@gmai...>
Commiterumorigu

Mensagem de Log

BugTrack/2422 popular plugin supports Dababase counter

Mudança Sumário

Diff

--- a/plugin/counter.inc.php
+++ b/plugin/counter.inc.php
@@ -203,6 +203,108 @@ function plugin_counter_get_count($page)
203203 return $c;
204204 }
205205
206+function plugin_counter_get_popular_list($today, $except, $max) {
207+ if (PLUGIN_COUNTER_USE_DB === 0) {
208+ return plugin_counter_get_popular_list_file($today, $except, $max);
209+ } else {
210+ return plugin_counter_get_popular_list_db($today, $except, $max);
211+ }
212+}
213+
214+function plugin_counter_get_popular_list_file($today, $except, $max) {
215+ global $whatsnew;
216+ $counters = array();
217+ $except_quote = str_replace('#', '\#', $except);
218+ foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
219+ if (($except != '' && preg_match("#$except_quote#", $page)) ||
220+ $page == $whatsnew || check_non_list($page) ||
221+ ! is_page($page))
222+ continue;
223+
224+ $array = file(COUNTER_DIR . $file);
225+ $count = rtrim($array[0]);
226+ $date = rtrim($array[1]);
227+ $today_count = rtrim($array[2]);
228+
229+ if ($today) {
230+ // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
231+ // array_splice()によってキー値が変更されてしまうのを防ぐ
232+ // ため、キーに '_' を連結する
233+ if ($today == $date) $counters['_' . $page] = $today_count;
234+ } else {
235+ $counters['_' . $page] = $count;
236+ }
237+ }
238+
239+ asort($counters, SORT_NUMERIC);
240+
241+ // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
242+ $counters = array_reverse($counters, TRUE); // with array_splice()
243+ $counters = array_splice($counters, 0, $max);
244+ return $counters;
245+}
246+
247+function plugin_counter_get_popular_list_db($today, $except, $max) {
248+ global $whatsnew;
249+ $page_counter_t = PLUGIN_COUNTER_DB_TABLE_NAME_PREFIX . 'page_counter';
250+ if ($today) {
251+ $order_by_c = 'today_viewcount';
252+ } else {
253+ $order_by_c = 'total';
254+ }
255+ $counters = array();
256+ try {
257+ $pdo = new PDO(PLUGIN_COUNTER_DB_CONNECT_STRING,
258+ PLUGIN_COUNTER_DB_USERNAME, PLUGIN_COUNTER_DB_PASSWORD,
259+ $plugin_counter_db_options);
260+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
261+ $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
262+ $pdo->setAttribute(PDO::ATTR_TIMEOUT, 5);
263+ if ($today) {
264+ $stmt = $pdo->prepare(
265+"SELECT page_name, total, update_date,
266+ today_viewcount, yesterday_viewcount
267+ FROM $page_counter_t
268+ WHERE update_date = ?
269+ ORDER BY $order_by_c DESC
270+ LIMIT ?"
271+ );
272+ } else {
273+ $stmt = $pdo->prepare(
274+"SELECT page_name, total, update_date,
275+ today_viewcount, yesterday_viewcount
276+ FROM $page_counter_t
277+ ORDER BY $order_by_c DESC
278+ LIMIT ?"
279+ );
280+ }
281+ $except_quote = str_replace('#', '\#', $except);
282+ $limit = $max + 100;
283+ if ($today) {
284+ $stmt->execute(array($today, $limit));
285+ } else {
286+ $stmt->execute(array($limit));
287+ }
288+ foreach ($stmt as $r) {
289+ $page = $r['page_name'];
290+ if (($except != '' && preg_match("#$except_quote#", $page)) ||
291+ $page == $whatsnew || check_non_list($page) ||
292+ ! is_page($page)) {
293+ continue;
294+ }
295+ if ($today) {
296+ $counters['_' . $page] = $r['today_viewcount'];
297+ } else {
298+ $counters['_' . $page] = $r['total'];
299+ }
300+ }
301+ $stmt->closeCursor();
302+ return array_splice($counters, 0, $max);
303+ } catch (Exception $e) {
304+ die('counter.inc.php: Error occurred on getting pupular pages');
305+ }
306+}
307+
206308 /**
207309 * php -r "include 'plugin/counter.inc.php'; plugin_counter_tool_setup_table();"
208310 */
--- a/plugin/popular.inc.php
+++ b/plugin/popular.inc.php
@@ -1,17 +1,15 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone
3-// $Id: popular.inc.php,v 1.20 2011/01/25 15:01:01 henoheno Exp $
4-// Copyright (C)
5-// 2003-2005, 2007 PukiWiki Developers Team
3+// popular.inc.php
4+// Copyright
5+// 2003-2017 PukiWiki Development Team
66 // 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
77 // License: WHERE IS THE RECORD?
88 //
99 // Popular pages plugin: Show an access ranking of this wiki
1010 // -- like recent plugin, using counter plugin's count --
1111
12-/*
13- * (C) 2003-2005 PukiWiki Developers Team
14- * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
12+/**
1513 *
1614 * 通算および今日に別けて一覧を作ることができます。
1715 *
@@ -29,9 +27,11 @@
2927
3028 define('PLUGIN_POPULAR_DEFAULT', 10);
3129
30+require_once(PLUGIN_DIR . 'counter.inc.php');
31+
3232 function plugin_popular_convert()
3333 {
34- global $vars, $whatsnew;
34+ global $vars;
3535 global $_popular_plugin_frame, $_popular_plugin_today_frame;
3636
3737 $max = PLUGIN_POPULAR_DEFAULT;
@@ -42,37 +42,9 @@ function plugin_popular_convert()
4242 switch (func_num_args()) {
4343 case 3: if ($array[2]) $today = get_date('Y/m/d');
4444 case 2: $except = $array[1];
45- case 1: $max = $array[0];
45+ case 1: $max = (int)$array[0];
4646 }
47-
48- $counters = array();
49- $except_quote = str_replace('#', '\#', $except);
50- foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
51- if (($except != '' && preg_match("#$except_quote#", $page)) ||
52- $page == $whatsnew || check_non_list($page) ||
53- ! is_page($page))
54- continue;
55-
56- $array = file(COUNTER_DIR . $file);
57- $count = rtrim($array[0]);
58- $date = rtrim($array[1]);
59- $today_count = rtrim($array[2]);
60-
61- if ($today) {
62- // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
63- // array_splice()によってキー値が変更されてしまうのを防ぐ
64- // ため、キーに '_' を連結する
65- if ($today == $date) $counters['_' . $page] = $today_count;
66- } else {
67- $counters['_' . $page] = $count;
68- }
69- }
70-
71- asort($counters, SORT_NUMERIC);
72-
73- // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
74- $counters = array_reverse($counters, TRUE); // with array_splice()
75- $counters = array_splice($counters, 0, $max);
47+ $counters = plugin_counter_get_popular_list($today, $except, $max);
7648
7749 $items = '';
7850 if (! empty($counters)) {
@@ -99,4 +71,3 @@ function plugin_popular_convert()
9971
10072 return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
10173 }
102-