recentプラグインのリミッター

修正

二度目以降は、HTMLのコメント文のみを出力します。このリミッターはrecentプラグインをいずれかの場所に数十個列挙された時のダメージを1倍にするために追加したものです。

メッセージ

(開発談義 より移動)

(開発談義 より移動 ここまで)

--- recent.org.php	Fri Jul 08 02:28:25 2005
+++ recent.inc.php	Fri Jul 15 22:28:02 2005
@@ -12,6 +12,9 @@
 // Default number of 'Show latest N changes'
 define('PLUGIN_RECENT_DEFAULT_LINES', 10);
 
+// Limit number of executions
+define('PLUGIN_RECENT_EXEC_LIMIT', 3);
+
 // ----
 
 define('PLUGIN_RECENT_USAGE', '#recent(number-to-show)');
@@ -22,7 +25,7 @@
 function plugin_recent_convert()
 {
 	global $vars, $date_format, $_recent_plugin_frame;
-	static $done;
+	static $execute_cnt = 1;
 
 	$recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
 	if (func_num_args()) {
@@ -34,8 +37,9 @@
 		}
 	}
 
-	// Show only the first one
-	if (isset($done)) return '<!-- #recent(): You already view changes -->';
+	// Control frequent execution
+	if ($execute_cnt > PLUGIN_RECENT_EXEC_LIMIT)
+		return '<!-- #recent(): You called me too much -->';
 
 	// Get latest N changes
 	if (file_exists(PLUGIN_RECENT_CACHE)) {
@@ -74,7 +78,7 @@
 	// End of the day
 	if ($date != '') $items .= '</ul>' . "\n";
 
-	$done = TRUE;
+	$execute_cnt ++;
 
 	return sprintf($_recent_plugin_frame, count($lines), $items);
 }

*1 正しくは凍結後に機能が発動するというのかな

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-08-09 (金) 04:16:21
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 8.2.12. HTML convert time: 0.490 sec.

SourceForge