_wp_unfiltered_html_comment replacer v0.1
id属性”_wp_unfiltered_html_comment”の先頭のアンダーバーを除去するプラグイン。(ただし、手動)
有効化すると、ツールにwuhc_replacerが出来ます。
id属性”_wp_unfiltered_html_comment”の先頭のアンダーバーを除去するプラグイン。(ただし、手動)
有効化すると、ツールにwuhc_replacerが出来ます。
WordPressプラグインで管理ページ以外のところにフックを使ったことがなかったので、試しにthe_contentにフックしてみた。
とりあえず、記事に書かれた任意のhtmlコメントを置換してみることに。
“<!– uptime!!#uptime –>”で連続稼働時間
“<!– uptime!!#idletime –>”でアイドル時間
ま、実用性はないよねぇ…
uptimeは/proc/uptimeを参照してるだけなようなので、こっちを見て計算した方がuptimeコマンドのフォーマットに左右されないし、秒まで表示できるのでこっちを使いましょ。
$ cat /proc/uptime 8946563.01 17548528.13
/proc/uptimeを表示してみると、こんな感じ。
稼働時間 アイドル時間となってる。
まぁ、最初見たときはアイドル時間が稼働時間より長くて「なんぞ?」と思ったけど、コア二つ分のアイドル時間を合わせたものだと思うとしっくりくる。
うん、実はデュアルコアなんだ。
てなわけで、60で割ったり24で割ったりと頭がぐちゃぐちゃになりながらもできました。
時間の計算ってメンドイヨネ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | <?php /* Plugin Name: uptime!! Plugin URI: http://www.dazzlingworld2.com/post_4177.html Description: サーバーのアップタイムを表示する。 Version: 0.2 Author: だかね Author URI: http://www.dazzlingworld2.com/ */ function the_uptime() { $uptime = get_uptime(); echo $uptime[0] . "日 " . $uptime[1] . "時間 " . $uptime[2] . "分 " . $uptime[3] . "秒 " . $uptime[4]; } function the_idletime() { $idletime = get_uptime(1); echo $idletime[0] . "日 " . $idletime[1] . "時間 " . $idletime[2] . "分 " . $idletime[3] . "秒 " . $idletime[4]; } /* 稼働時間またはアイドル時間を取得する。 $sw = 0 : 稼働時間 $sw = 1 : アイドル時間 */ function get_uptime($sw = 0) { $uptime = array(0 ,0 ,0 ,0, 0); // 日時分秒㍉ // 引数が0, 1以外の場合は終了する。 if($sw != 0 && $sw != 1) return $uptime; // "/proc/uptime" から稼働時間(秒)を取得する unset($stdout); // $stdoutを空にする exec('/bin/cat /proc/uptime', $stdout, $rcode); $proc_uptime = explode(" ", $stdout[0]); // 取得に失敗した場合は終了する。 if($rcode) return $uptime; // 稼働時間(秒)を日時分秒㍉に変換 $usec = explode(".", $proc_uptime[$sw]); $uptime[4] = $usec[1]; // ㍉ $uptime[3] = $usec[0] % 60; // 秒 $time = ($proc_uptime[$sw] - $uptime[3]) / 60; if($time > 0) { $uptime[2] = $time % 60; // 分 $time = ($time - $uptime[2]) / 60; } if($time > 0) { $uptime[1] = $time % 24; // 時 $time = ($time - $uptime[1]) / 24; } $uptime[0] = floor($time); // 日数 return $uptime; } ?> |
<?php the_uptime(); ?>を呼べば稼働時間が、
<?php the_idletime(); ?>を呼べばアイドル時間が表示される。
実行結果
103日 13時間 27分 19秒 73 203日 3時間 11分 2秒 96
CPU:「かなり暇…」
サーバーの連続稼働時間を表示してみたくなったので、ちょろっと作ってみた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <?php /* Plugin Name: uptime!! Plugin URI: http://www.dazzlingworld2.com/post_4166.html Description: サーバーのアップタイムを表示する。 Version: 0.1 Author: だかね Author URI: http://www.dazzlingworld2.com/ */ function the_uptime() { echo get_uptime(); } function get_uptime() { $uptime = `uptime`; $day = 0; $hur = 0; $min = 0; // 稼働日数の取得("x day" or "xx days"を検索) if(preg_match("/(\d+)\s+days?/", $uptime, $matches)) { $day = $matches[1]; } // 稼働時間の取得 if(preg_match("/(up|,)(\s+)(\d{1,2}):(\d{1,2})/", $uptime, $matches)) { // "up h:mm" or ", h:mm" $hur = $matches[3]; $min = $matches[4]; } else if(preg_match("/(up|,)(\s+)(\d{1,2})(\s+)min/", $uptime, $matches)) { // "up m min" or ", m min" $hur = 0; $min = $matches[3]; } return $day . "日 " . $hur . "時間 " . $min . "分"; } ?> |
uptimeの表示形式が稼働時間によって統一されてないので、表示がおかしくなるかも…
デスクトップにtest.phpってファイル名で置いてたら、消して後悔しそうだったのでここに書いておこうと思う。
id属性”_wp_unfiltered_html_comment”の先頭のアンダーバーを除去するプラグイン。(ただし、手動)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | <?php $initdir = "/wordpress/"; $ext = ".php"; $find = "_wp_unfiltered_html_comment"; $replace = "wp_unfiltered_html_comment"; $filelist = get_filelist($initdir, $ext); foreach($filelist as $key => $filename) { // ファイルを読み込む $fcontents = @file_get_contents($filename); // 検索 $pos = strpos($fcontents, "_wp_unfiltered_html_comment"); if($pos !== FALSE) { // 文字列が存在した場合 // 置換 $fout = fopen($filename, "w"); fwrite($fout, str_replace($find, $replace, $fcontents)); fclose($fout); echo "replace : " . $filename . "\n"; } } // $initdir以下の$extファイルのリストを取得する function get_filelist($startDir, $ext) { $dir = $startDir; $dirs = array(); $filename = array(); $next = 0; foreach(glob($dir."*".$ext) as $_filename) { $filename[] = $_filename; } while(true) { $_dirs = glob($dir."*", GLOB_ONLYDIR | GLOB_MARK); if(count($_dirs)) { foreach ($_dirs as $key => $_dir) { foreach(glob($_dir."*".$ext) as $_filename) { $filename[] = $_filename; } $dirs[] = $_dir; } } else { break; } $dir = $dirs[$next++]; } return $filename; } ?> |