001 : <?php 002 : //------------------------------------------------------------ 003 : // RateMe.php ─ Website Rating System 004 : // 005 : // By M.Miyazaki 006 : // Created : 2012.09.18 007 : // Modified : 2012.09.25 008 : //------------------------------------------------------------ 009 : 010 : // Usage: Insert the next HTML source onto your website page. Please change the path to RateMe.php if you need. 011 : // Example: <iframe id="WebsiteRatingSystem" src="./common/RateMe/RateMe.html" scrolling="no" frameborder="0" allowTransparency="true"></iframe> 012 : 013 : // Configurations 014 : ### Log File (0:Date 1:IP 2:Host 3:URL 4:DataType 5:Data) 015 : $LOG_FILE = "./logdir/logfile.txt"; 016 : 017 : 018 : // Execute This Program 019 : main(); 020 : 021 : // Functions 022 : /** 023 : * Main Routine 024 : */ 025 : function main() 026 : { 027 : ini_set("date.timezone", "Asia/Tokyo"); 028 : 029 : if (isPostMode()) 030 : { 031 : // 1. Count to Database. 032 : //var_dump($_POST); // for debug 033 : receivePost(); 034 : } 035 : else 036 : { 037 : print getHtml(); 038 : } 039 : } 040 : 041 : //===== Data Analyzing ===== 042 : 043 : 044 : 045 : 046 : //===== Reveive User's Post ===== 047 : /** 048 : * Receive all user's post. 049 : */ 050 : function receivePost() 051 : { 052 : $type = null; 053 : if (array_key_exists("type", $_POST)) 054 : { 055 : $type = $_POST['type']; 056 : } 057 : 058 : switch ($type) 059 : { 060 : case "starRating": 061 : receiveStarRatingPost(); 062 : break; 063 : case "comment": 064 : receiveStarRatingCommentPost(); 065 : break; 066 : case "yet": 067 : receiveYetPost(); 068 : break; 069 : default: 070 : // Unexpected type! 071 : } 072 : 073 : return; 074 : } 075 : 076 : /** 077 : * Get User's Access Information. 078 : */ 079 : function getAccessInformation() 080 : { 081 : $line = ""; 082 : 083 : $date = date("Y.m.d H:i:s"); 084 : $ip = $_SERVER["REMOTE_ADDR"]; 085 : $host = gethostbyaddr($ip); 086 : $line = sprintf("%s\t\t%s\t\t%s", $date, $ip, $host); 087 : 088 : return $line; 089 : } 090 : 091 : /** 092 : * Receive StarRating post. 093 : */ 094 : function receiveStarRatingPost() 095 : { 096 : $line = getAccessInformation(); 097 : $line .= sprintf("\t\t%s\t\t%s\t\t%s\n", $_POST['href'], $_POST['type'], $_POST['value']); 098 : addLine($line); 099 : return; 100 : } 101 : 102 : /** 103 : * Receive StarRating Comment post. 104 : */ 105 : function receiveStarRatingCommentPost() 106 : { 107 : $line = getAccessInformation(); 108 : $line .= sprintf("\t\t%s\t\t%s\t\t%s\n", $_POST['href'], $_POST['type'], $_POST['value']); 109 : addLine($line); 110 : return; 111 : } 112 : 113 : /** 114 : * Receive Yet post. 115 : */ 116 : function receiveYetPost() 117 : { 118 : $line = getAccessInformation(); 119 : $line .= sprintf("\t\t%s\t\t%s\t\t%s\n", $_POST['href'], $_POST['type'], ""); 120 : addLine($line); 121 : return; 122 : } 123 : 124 : /** 125 : * Add line to log file. 126 : */ 127 : function addLine($line) 128 : { 129 : global $LOG_FILE; 130 : $resource = fopen($LOG_FILE, "a+"); 131 : fwrite($resource, $line); 132 : fclose($resource); 133 : return; 134 : } 135 : 136 : 137 : //===== Show HTML ===== 138 : /** 139 : * Check Mode is Post or Print 140 : * Implemented : 2012.09.19 141 : */ 142 : function isPostMode() 143 : { 144 : $aBoolean = false; 145 : 146 : // 1. Check Mode & Set boolean. 147 : if (array_key_exists("mode", $_POST) && $_POST['mode'] === "post") 148 : { 149 : $aBoolean = true; 150 : } 151 : 152 : return $aBoolean; 153 : } 154 : 155 : /** 156 : * Get the HTML source. 157 : * Implemented : 2012.09.18 158 : */ 159 : function getHtml() 160 : { 161 : $html = ""; 162 : 163 : if (isCompletedPage()) 164 : { 165 : $html .= getHeader(); 166 : $html .= "<table style=\"margin:0px;\"><tr style=\"vertical-align:top;\">\n"; 167 : $html .= "<td style=\"padding-top:2px;\">\n"; 168 : $html .= getLikeButtonSection(); 169 : $html .= "</td>\n"; 170 : $html .= "<td>\n"; 171 : $html .= getRatingSection(); 172 : $html .= "</td>\n"; 173 : $html .= "</tr></table>\n"; 174 : $html .= getFooter(); 175 : } 176 : else 177 : { 178 : $html .= getHeader(); 179 : $html .= getUrgeButtonSection(); 180 : $html .= getFooter(); 181 : } 182 : 183 : return $html; 184 : } 185 : 186 : /** 187 : * Check webpage is completed or not. 188 : * Implemented : 2012.09.19 189 : * Modified : 2012.09.26 190 : */ 191 : function isCompletedPage() 192 : { 193 : $aBoolean = true; 194 : 195 : // 1. Check GET['isComplete'] data 196 : if (array_key_exists("isComplete", $_GET)) 197 : { 198 : $isComplete = $_GET['isComplete']; 199 : 200 : if ($isComplete === "yes") 201 : { 202 : $aBoolean = true; 203 : } 204 : else if ($isComplete === "no") 205 : { 206 : $aBoolean = false; 207 : } 208 : else 209 : { 210 : // Nothing to do... 211 : } 212 : } 213 : else { 214 : // Nothing to do... 215 : } 216 : 217 : return $aBoolean; 218 : } 219 : 220 : /** 221 : * Get the HTML source of Like Button for Facebook. 222 : * Implemented : 2012.09.18 223 : */ 224 : function getLikeButtonSection() 225 : { 226 : $html = ""; 227 : 228 : // 1. Get the URL of this page. 229 : if (array_key_exists("href", $_GET)) 230 : { 231 : $url = $_GET['href']; 232 : $regularUrl = getRegularUrl($url); 233 : 234 : // 2. Create HTML source with the URL. 235 : $html .= '<iframe src="http://www.facebook.com/plugins/like.php?href='; 236 : $html .= urlencode($regularUrl); 237 : $html .= '&send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=21" '; 238 : $html .= 'scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>'; 239 : } 240 : 241 : return $html; 242 : } 243 : 244 : /** 245 : * Get the HTML source of Rating Section. 246 : * Implemented : 2012.09.19 247 : */ 248 : function getRatingSection() 249 : { 250 : $html = ""; 251 : 252 : $url = ""; 253 : if (array_key_exists("href", $_GET)) 254 : { 255 : $url = $_GET['href']; 256 : } 257 : 258 : // 1. Create HTML source. 259 : $html .= "<div id=\"firstDisplayStarRating\">\n"; 260 : $html .= "<select id=\"StarRating\" onchange=\"submitStarRating();\">\n"; 261 : $html .= " <option value=\"-1\">-- 未評価 --</option>\n"; 262 : $html .= " <option value=\"0\">0 ☆☆☆☆☆</option>\n"; 263 : $html .= " <option value=\"1\">1 ★☆☆☆☆</option>\n"; 264 : $html .= " <option value=\"2\">2 ★★☆☆☆</option>\n"; 265 : $html .= " <option value=\"3\">3 ★★★☆☆</option>\n"; 266 : $html .= " <option value=\"4\">4 ★★★★☆</option>\n"; 267 : $html .= " <option value=\"5\">5 ★★★★★</option>\n"; 268 : $html .= "</select>\n"; 269 : $html .= "<label for=\"StarRating\">このページをご評価ください。</label>\n"; 270 : $html .= "</div>\n"; 271 : $html .= "<div id=\"secondDisplayStarRating\" style=\"display:none;\">\n"; 272 : $html .= "<label for=\"StarRatingComment\">ありがとうございます。コメントをいただけると非常に助かります。</label><br>\n"; 273 : $html .= "<input id=\"StarRatingComment\" type=\"text\" style=\"width:300px;\"><input type=\"button\" value=\"送る\" onclick=\"submitStarRatingComment();\"><br>\n"; 274 : $html .= "</div>\n"; 275 : $html .= "<div id=\"thirdDisplayStarRating\" style=\"display:none;\">\n"; 276 : $html .= "<label>ご協力に感謝します。コメントを活用して制作に努めてまいります!</label><br>\n"; 277 : $html .= "</div>\n"; 278 : $html .= "<div id=\"processingStarRating\" style=\"display:none;\">\n"; 279 : $html .= "<img src=\"../ajax-loader.gif\" width=\"16\" height=\"16\">\n"; 280 : $html .= "</div>\n"; 281 : $html .= "<div id=\"sorryStarRating\" style=\"display:none;\">\n"; 282 : $html .= "<label>(ごめんなさい、評価を送信できませんでした...)</label><br>\n"; 283 : $html .= "</div>\n"; 284 : $html .= "<br>\n"; 285 : 286 : return $html; 287 : } 288 : 289 : /** 290 : * Get the HTML source of Urge Button. 291 : * Implemented : 2012.09.19 292 : */ 293 : function getUrgeButtonSection() 294 : { 295 : $html = ""; 296 : 297 : // 1. Create HTML source. 298 : $html .= "<div id=\"firstDisplayYet\">\n"; 299 : $html .= "<input id=\"yet\" type=\"button\" value=\"まだ?\" onclick=\"submitYet();\">\n"; 300 : $html .= "<label for=\"yet\">"; 301 : 302 : if (($count = countOfYet()) > 0) 303 : { 304 : $html .= $count . "人が「まだ?」と言っています。"; 305 : } 306 : 307 : $html .= "「まだ?」を押して、サイト管理者に執筆を促しましょう。</label><br>\n"; 308 : $html .= "</div>\n"; 309 : $html .= "<div id=\"secondDisplayYet\" style=\"display:none;\">\n"; 310 : $html .= "<label>【管理者より】未だに準備中で申し訳ありません...。「まだ?」を真摯に受け止め、早期執筆に努めます!</label>\n"; 311 : $html .= "</div>\n"; 312 : $html .= "<div id=\"processingYet\" style=\"display:none;\">\n"; 313 : $html .= "<img src=\"../ajax-loader.gif\" width=\"16\" height=\"16\">\n"; 314 : $html .= "</div>\n"; 315 : $html .= "<div id=\"sorryYet\" style=\"display:none;\">\n"; 316 : $html .= "<label>(ごめんなさい、「まだ?」を送信できませんでした...)</label><br>\n"; 317 : $html .= "</div>\n"; 318 : $html .= "<br>\n"; 319 : 320 : return $html; 321 : } 322 : 323 : /** 324 : * Count the number of persons pressed Yet Button. 325 : * Implemented : 2012.09.19 326 : */ 327 : function countOfYet() 328 : { 329 : global $LOG_FILE; 330 : 331 : $count = 0; 332 : 333 : // 1. Read dat file & count it. 334 : if (array_key_exists("href", $_GET)) 335 : { 336 : $checkingUrl = $_GET['href']; 337 : 338 : $lines = file($LOG_FILE); 339 : foreach ($lines as $line) 340 : { 341 : $line = explode("\t\t", $line); 342 : $url = $line[3]; 343 : $dataType = $line[4]; 344 : if ($checkingUrl === $url && $dataType === "yet") 345 : { 346 : $count++; 347 : } 348 : } 349 : } 350 : 351 : return $count; 352 : } 353 : 354 : /** 355 : * Convert a URL to regular URL. 356 : * Implemented : 2012.09.19 357 : */ 358 : function getRegularUrl($url) 359 : { 360 : $regularUrl = ""; 361 : 362 : // 1. Make the url regular. 363 : // (It doesn't need yet.) 364 : $regularUrl = $url; 365 : 366 : return $regularUrl; 367 : } 368 : 369 : /** 370 : * Get the HTML Header. 371 : * Implemented : 2012.09.19 372 : */ 373 : function getHeader() 374 : { 375 : $html = ""; 376 : $url = ""; 377 : 378 : if (array_key_exists("href", $_GET)) 379 : { 380 : $url = $_GET['href']; 381 : } 382 : 383 : $html .= "<!DOCTYPE html>\n"; 384 : $html .= "<html lang=\"ja\">\n"; 385 : $html .= "<head>\n"; 386 : $html .= "<meta charset=\"UTF-8\" />\n"; 387 : $html .= "<title>RateMe</title>\n"; 388 : $html .= "<style type=\"text/css\">\n"; 389 : $html .= "<!--\n"; 390 : $html .= "label {\n"; 391 : $html .= " font-size : 11px;\n"; 392 : $html .= " color : #666;\n"; 393 : $html .= "}\n"; 394 : $html .= "-->\n"; 395 : $html .= "</style>\n"; 396 : $html .= "<body style=\"margin:0px;\">\n"; 397 : $html .= "<script src=\"../jquery-1.8.1.min.js\"></script>\n"; 398 : $html .= "<script src=\"./RateMe.js\"></script>\n"; 399 : $html .= "<input type=\"hidden\" id=\"PageUrl\" value=\"" . urlencode($url) . "\">\n"; 400 : 401 : return $html; 402 : } 403 : 404 : /** 405 : * Get the HTML Footer. 406 : * Implemented : 2012.09.19 407 : */ 408 : function getFooter() 409 : { 410 : $html = ""; 411 : 412 : $html .= "</body>\n"; 413 : $html .= "</html>"; 414 : 415 : return $html; 416 : } 417 : 418 : ?>
This document was generated by NanigashiBiyori on 2012/09/26 at 02:01:55.