差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| web:web_clap [2010/02/11] – administrator | web:web_clap [不明な日付] (現在) – 外部編集 (不明な日付) 127.0.0.1 | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== GJ!(Web拍手)の改造 ====== | ||
| + | http:// | ||
| + | |||
| + | 上記リンクのGJは、Javascriptを使って、画面が切り替わることなく拍手ができるのがおもしろい。ただ、ファイルに書き込むタイプなので、時々ファイルをロックしたままになることがあるので、この部分をMysqlで処理するようにした。 | ||
| + | ===== Mysqlのテーブル ===== | ||
| + | まず、データベースにテーブルを作成しておきます。< | ||
| + | CREATE TABLE `gj_log` ( | ||
| + | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
| + | `entry_id` int(15) unsigned NOT NULL DEFAULT ' | ||
| + | `date` varchar(15) DEFAULT NULL, | ||
| + | `ip` varchar(15) DEFAULT NULL, | ||
| + | PRIMARY KEY (`id`) | ||
| + | ) ; | ||
| + | |||
| + | CREATE TABLE `gj_views` ( | ||
| + | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
| + | `entry_id` int(15) unsigned NOT NULL DEFAULT ' | ||
| + | `views` int(15) unsigned NOT NULL DEFAULT ' | ||
| + | `entry_url` varchar(255) NOT NULL, | ||
| + | PRIMARY KEY (`id`) | ||
| + | );</ | ||
| + | ===== MovableTypeのテンプレート ===== | ||
| + | テンプレートを少し改造。< | ||
| + | <div class=" | ||
| + | <input id = "< | ||
| + | <script type=" | ||
| + | <span id="< | ||
| + | </ | ||
| + | </ | ||
| + | ===== 設定ファイル ===== | ||
| + | データベースの設定を記述しておく。ファイル名はgj_cfg.php< | ||
| + | <? | ||
| + | $DBHost = ' | ||
| + | $DBUser = ' | ||
| + | $DBPassword = ' | ||
| + | $Database = ' | ||
| + | $gj_log_table = ' | ||
| + | $gj_views_table = ' | ||
| + | ?> | ||
| + | </ | ||
| + | ===== 実行ファイル ===== | ||
| + | gj.php< | ||
| + | <?php | ||
| + | error_reporting(0); | ||
| + | include(' | ||
| + | |||
| + | $ButtonImg =" | ||
| + | $R_STR = 0;//Red | ||
| + | $G_STR = 0;//Green | ||
| + | $B_STR = 255;//Blue | ||
| + | |||
| + | $ButtonImg2 =" | ||
| + | $R_STR2 = 0;//Red | ||
| + | $G_STR2 = 0;//Green | ||
| + | $B_STR2 = 255;//Blue | ||
| + | |||
| + | $R_STR3 = 255;//Red | ||
| + | $G_STR3 = 0;//Green | ||
| + | $B_STR3 = 0;//Blue | ||
| + | |||
| + | $STRPOSX = 58;// | ||
| + | $STRPOSY = 3;// | ||
| + | |||
| + | $KETA = 3;// | ||
| + | |||
| + | if(!isset($_GET[" | ||
| + | $pagename = $_GET[" | ||
| + | |||
| + | // | ||
| + | if($_GET[" | ||
| + | { | ||
| + | |||
| + | if (!($mysql = mysql_connect($DBHost, | ||
| + | exit(0); | ||
| + | } | ||
| + | if (!(mysql_select_db($Database))) { | ||
| + | exit(0); | ||
| + | } | ||
| + | |||
| + | if ($pagename < 1 ) { | ||
| + | $img = imagecreatefromgif($ButtonImg); | ||
| + | $col = imagecolorallocate($img, | ||
| + | imagestring($img, | ||
| + | imagegif($img); | ||
| + | imagedestroy($img); | ||
| + | exit(0); | ||
| + | } | ||
| + | |||
| + | $query = " | ||
| + | $res = mysql_query($query); | ||
| + | $row = mysql_fetch_object($res); | ||
| + | $count = intval($row-> | ||
| + | |||
| + | Header (" | ||
| + | |||
| + | if($_GET[" | ||
| + | { | ||
| + | $img = imagecreatefromgif($ButtonImg2); | ||
| + | $col = imagecolorallocate($img, | ||
| + | } | ||
| + | else // | ||
| + | { | ||
| + | $img = imagecreatefromgif($ButtonImg); | ||
| + | $col = imagecolorallocate($img, | ||
| + | } | ||
| + | |||
| + | imagestring($img, | ||
| + | imagegif($img); | ||
| + | imagedestroy($img); | ||
| + | exit(0); | ||
| + | } | ||
| + | // | ||
| + | else if($_GET[" | ||
| + | { | ||
| + | |||
| + | if (!($mysql = mysql_connect($DBHost, | ||
| + | exit(0); | ||
| + | } | ||
| + | if (!(mysql_select_db($Database))) { | ||
| + | exit(0); | ||
| + | } | ||
| + | |||
| + | // | ||
| + | $date = date(" | ||
| + | $ip = $_SERVER[' | ||
| + | $query = " | ||
| + | $res = mysql_query($query); | ||
| + | if (mysql_num_rows($res) == 0) { | ||
| + | $query = " | ||
| + | $res2 = mysql_query($query); | ||
| + | $count_plus = 1; | ||
| + | } else { | ||
| + | $count_plus = 0; | ||
| + | } | ||
| + | |||
| + | // | ||
| + | $query = " | ||
| + | $res2 = mysql_query($query); | ||
| + | |||
| + | // | ||
| + | $url = $_GET[" | ||
| + | $query = " | ||
| + | $res = mysql_query($query); | ||
| + | $row = mysql_fetch_object($res); | ||
| + | $views = intval($row-> | ||
| + | if (mysql_num_rows($res) == 0) { | ||
| + | $query = " | ||
| + | $res2 = mysql_query($query); | ||
| + | } else { | ||
| + | $views += $count_plus; | ||
| + | $query = " | ||
| + | $res2 = mysql_query($query); | ||
| + | } | ||
| + | |||
| + | exit(0); | ||
| + | // | ||
| + | } else { | ||
| + | exit(1); | ||
| + | } | ||
| + | </ | ||
| + | ===== ランキング ===== | ||
| + | ランキングを表示するスクリプトを別ファイルにして、負荷を下げる。< | ||
| + | <? | ||
| + | |||
| + | include(' | ||
| + | |||
| + | $INFOMAX = 100; | ||
| + | |||
| + | print("< | ||
| + | print("< | ||
| + | print("< | ||
| + | print("< | ||
| + | print("</ | ||
| + | print("< | ||
| + | |||
| + | if (!($mysql = mysql_connect($DBHost, | ||
| + | echo " | ||
| + | mysql_query(" | ||
| + | if (!(mysql_select_db($Database))) { | ||
| + | echo " | ||
| + | |||
| + | // | ||
| + | $query = " | ||
| + | $res = mysql_query($query); | ||
| + | $row = mysql_fetch_object($res); | ||
| + | $count = intval($row-> | ||
| + | $avg = $row-> | ||
| + | |||
| + | print("< | ||
| + | print("< | ||
| + | print(" | ||
| + | printf(" | ||
| + | |||
| + | print("< | ||
| + | print("< | ||
| + | |||
| + | // | ||
| + | $query = " | ||
| + | $res = mysql_query($query); | ||
| + | |||
| + | $jun = 1; $sjun = 1; $excount = 0; | ||
| + | |||
| + | if ($res) { | ||
| + | |||
| + | while($row = mysql_fetch_object($res)) { | ||
| + | $title = $row-> | ||
| + | $views = $row-> | ||
| + | $url = $row-> | ||
| + | $school = $school_list[$row-> | ||
| + | |||
| + | if ($excount == $views) {$jun--;} else {$jun = $sjun;} | ||
| + | if ($jun > $INFOMAX) break; | ||
| + | print("< | ||
| + | print("< | ||
| + | print("< | ||
| + | $jun++; $sjun++; $excount = $views; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | print("</ | ||
| + | print("</ | ||
| + | print("</ | ||
| + | |||
| + | exit(1); | ||
| + | |||
| + | ?> | ||
| + | </ | ||