chibineko Posted August 27, 2009 Share Posted August 27, 2009 Anybody familiar with the BellaBuzz Ask&Answer script written by Jem Turner? It is a great script but it has no feature for the visitors to leave their names as well. Anybody can help me with this?? Link to comment https://forums.phpfreaks.com/topic/172050-add-a-feature-to-bellabuzz/ Share on other sites More sharing options...
chibineko Posted September 1, 2009 Author Share Posted September 1, 2009 Ohh I forgot to attach the codes of the BellaBuzz. Please help me~~ functions.php <?php //----------------------------------------------------------------------------- // BellaBuzz v1b Copyright © Jem Turner 2008 unless otherwise noted // http://www.jemjabella.co.uk/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License. See README.txt // or LICENSE.txt for more information. //----------------------------------------------------------------------------- function doError($message) { echo '<p style="color: red;">ERROR: '.$message.'</p>'; exit; } function doIpCheck($ip) { $ipPattern = '/\b(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/i'; if (!preg_match($ipPattern, $ip)) return false; else return true; } function doAskBox() { ?> <form action="ask.php" method="post"> <p> <input type="text" name="question" id="question" /> <label for="question">Question</label> <input type="submit" value="Ask" /> </p> </form> <?php } function doCount($cntype) { if ($cntype == "all") return count(file(ANSWERED)) + count(file(UNANSWERED)); elseif ($cntype == "open") return count(file(UNANSWERED)); elseif ($cntype == "done") return count(file(ANSWERED)); } function doAdminHeader() { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>BellaBuzz Control Panel</title> <style type="text/css"> * { font: 11px/15px Verdana, Sans-Serif; } h1, th { font-weight: bold; } td, th { border: 1px solid #eee; padding: 2px 4px; } table { border-collapse: collapse; width: 500px; } img { border: 0; } </style> </head> <body> <?php } function doAdminFooter() { echo "</body>\r\n</html>"; } function doQuestionForm($quesid, $file) { $questions = file($file); list($question,$dateask,$ip,$answer,$dateanswer) = preg_split("/,(?! )/", $questions[$quesid]); ?> <form action="admin.php?page=editprocess" method="post"> <p> <input type="hidden" name="file" id="file" value="<?php echo $file; ?>" /> <input type="hidden" name="quesid" id="quesid" value="<?php echo $quesid; ?>" /> <input type="text" name="question" id="question" value="<?php echo stripslashes(trim($question, "\"\x00..\x1F")); ?>" /> <label for="question">Question</label><br> <textarea name="answer" id="answer" rows="5" cols="35"><?php echo stripslashes(trim($answer, "\"\x00..\x1F")); ?></textarea> <label for="answer">Answer</label><br> <input type="text" name="dateanswer" id="dateanswer" value="<?php echo date("Y-m-d H:i:s", time()); ?>"> <label for="dateanswer">Date Answered</label> </p> <p> <input type="text" name="ip" id="ip" value="<?php echo $ip; ?>" readonly="readonly"> <label for="ip">IP Address</label><br> <input type="text" name="dateask" id="dateask" value="<?php echo $dateask; ?>" readonly="readonly"> <label for="dateask">Date Asked</label><br> <input type="submit" value="Answer" /> </p> </form> <?php } function doDisplayQuesAdmin($mode, $file, $limit) { global $timestamp; $questions = file($file); ?> <table> <tr><th>Question</th> <th>Date Asked</th> <th>IP</th> <th>Admin</th></tr> <?php $i = 0; if (count($questions) >= $limit) $limit = $limit; else $limit = count($questions); while ($i < $limit) { $rowColour = ($i % 2) ? ' style="background: #fff;"' : ' style="background: #ffe;"'; list($question,$date,$ip,$answer,$dateanswer) = preg_split("/,(?! )/", $questions[$i]); $ip = trim($ip, "\"\x00..\x1F"); echo '<tr'.$rowColour.'><td>'.$question.'</td> <td>'.date($timestamp, strtotime($date)).'</td> <td><a href="http://www.geobytes.com/IpLocator.htm?GetLocation&ipaddress='.$ip.'"><img src="admin-icons/spy.gif" title="look-up IP: '.$ip.'" alt="look-up ip"></a></td> <td><a href="admin.php?page='.$mode.'&ques='.$i.'"><img src="admin-icons/pencil.gif" title="'.$mode.' question" alt="'.$mode.'"></a> <a href="admin.php?page=delete&ques='.$i.'&file='.$file.'" onclick="javascript:return confirm(\'Are you sure you want to delete this question?\')"><img src="admin-icons/stop.gif" title="delete question" alt="delete"></a></td></tr>'; $i++; } ?> </table> <?php } function doWrite($file2open, $data, $writetype) { $file = fopen($file2open, $writetype) or die("Couldn't open the right questions file: the question could not be answered."); if (flock($file, LOCK_EX)) { fwrite($file, $data); flock($file, LOCK_UN); } else { exit("Couldn't open the right questions file: the question could not be answered."); } fclose($file); } function blanklinefix($inputfile) { ignore_user_abort(true); $content = file($inputfile); if (count($content) > 0) { $content = array_diff(array_diff($content, array("")), array("\r\n")); $newContent = array(); foreach ($content as $line) { $newContent[] = trim($line); } $newContent = implode("\r\n", $newContent); $fl = fopen($inputfile, "w+"); if (flock($fl, LOCK_EX)) { fwrite($fl, $newContent); flock($fl, LOCK_UN); } else { echo 'The file: '.$inputfile.' could not be locked for writing; the blanklinefix function could not be applied at this time.'; } fclose($fl); } ignore_user_abort(false); } blanklinefix(UNANSWERED); blanklinefix(ANSWERED); error_reporting(0); ?> ask.php <?php //----------------------------------------------------------------------------- // BellaBuzz v1b Copyright © Jem Turner 2008 unless otherwise noted // http://www.jemjabella.co.uk/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License. See README.txt // or LICENSE.txt for more information. //----------------------------------------------------------------------------- require('prefs.php'); if ($_SERVER['REQUEST_METHOD'] != "POST") doError("This page must not be accessed directly."); $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer|DigExt|Jakarta|Missigua|psycheclone|LinkWalker|ZyBorg|Waterunicorn|ICS)/i"; if (preg_match($bots, $_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") doError("Tests on your user agent indicate that there's a high possibility you're a spam bot, and as such <strong>your question has been deleted</strong>."); $ipPattern = '/\b(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/i'; if (doIpCheck($_SERVER['REMOTE_ADDR']) === false) doError("Invalid IP; no need to fiddle with the SERVER array."); if (empty($_POST['question']) || strlen($_POST['question']) < 10) doError("No empty/spammy questions please."); if ($blockurls == "yes") { if (substr_count($_POST['question'], 'http://') > 0 || substr_count($_POST['question'], 'url=') > 0) doError("To prevent link spamming, no URLs can be posted."); } if (doCount("open") == 0) $question = '"'.preg_replace("/,(?! )/", ", ", trim(strip_tags($_POST['question']))).'",'.date("Y-m-d H:i:s", time()).','.$_SERVER['REMOTE_ADDR'].",,"; else $question = "\r\n".'"'.preg_replace("/,(?! )/", ", ", trim(strip_tags($_POST['question']))).'",'.date("Y-m-d H:i:s", time()).','.$_SERVER['REMOTE_ADDR'].",,"; doWrite(UNANSWERED, $question, "a"); if ($emailonask == "yes") mail($admin_email, "New question asked", "A question has been asked:\r\n".$_POST['question']."\r\nIP: ".$_SERVER['REMOTE_ADDR'], "From: $admin_email"); ?> <p>Your question was successfully added thank you! <a href="questions.php">return to questions?</a></p> questions.php <?php //----------------------------------------------------------------------------- // BellaBuzz v1b Copyright © Jem Turner 2008 unless otherwise noted // http://www.jemjabella.co.uk/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License. See README.txt // or LICENSE.txt for more information. //----------------------------------------------------------------------------- require('prefs.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>BellaBuzz</title> <style type="text/css"> * { font: 11px/15px Verdana, Sans-Serif; } .question { font-weight: bold; font-size: 12px; } .answer { font-style: italic; } .dates { display: block; text-align: right; font-size: 10px; } </style> </head> <body> <p>There are currently <?php echo doCount("done"); ?> answered, and <?php echo doCount("open"); ?> unanswered questions.</p> <?php doAskBox(); ?> <?php $count = doCount("done"); if ($count > 0) { if (isset($_GET['page']) && is_numeric($_GET['page'])) $pg = $_GET['page']; else $pg = 1; $questions = file(ANSWERED); $numpages = ceil($count/$perpage); if (isset($sortby) && $sortby == "oldest") { krsort($questions); $questions = array_values($questions); } echo '<p>'; if ($perpage < $count) { if ($pg > 1 && $pg <= $numpages) echo '<a href="questions.php?page='.($pg - 1).'">Prev</a> · '; else echo "Prev · "; for ($x = 1; $x <= $numpages; $x++) { if ($x == $pg) echo '[<strong>'.$x.'</strong>] '; else echo '<a href="questions.php?page='.$x.'">'.$x.'</a> '; } if ($pg < $numpages) echo ' · <a href="questions.php?page='.($pg + 1).'">Next</a>'; else echo " · Next"; } echo '</p>'; $i = $perpage * ($pg - 1); $end = $i + $perpage; if ($end > $count) $end = $count; while ($i<$end) { list($question,$dateask,$ip,$answer,$dateanswer) = preg_split("/,(?! )/", $questions[$i]); $question = trim(stripslashes($question), "\"\x00..\x1F"); $answer = trim(stripslashes($answer), "\"\x00..\x1F"); ?> <p> <span class="question"><?php echo $question; ?></span><br> <span class="answer"><?php echo nl2br($answer); ?></span><br> <span class="dates">Asked: <?php echo date($timestamp, strtotime($dateask)); ?> | Answered: <?php echo date($timestamp, strtotime($dateanswer)); ?></span> </p> <?php $i++; } } else { echo '<p>No answered questions.</p>'; } ?> </body> </html> prefs.php <?php //----------------------------------------------------------------------------- // BellaBuzz v1b Copyright © Jem Turner 2008 unless otherwise noted // http://www.jemjabella.co.uk/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License. See README.txt // or LICENSE.txt for more information. //----------------------------------------------------------------------------- // ADMIN SETTINGS $admin_name = "admin"; // admin username (numbers and letters only) $admin_pass = "password"; // admin password $admin_email = "[email protected]"; // admin e-mail address $secret = "pleasechangeme123"; // this is like a second password. you won't have to remember it, so make it random // GENERAL SETTINGS $emailonask = "no"; // (yes or no) email admin when new question is asked $perpage = 10; // number of questions per page $timestamp = "dS F, y"; // timestamp for last update on index.php (see php.net/date) $showall = "yes"; // (yes or no) show unanswered questions as well as answered $blockurls = "yes"; // (yes or no) block urls to help prevent spam $sortby = "newest"; // (newest or oldest) sort questions preference // REQUIRED TO WORK define("ANSWERED", "answered.txt"); define("UNANSWERED", "unanswered.txt"); require_once('functions.php'); ?> admin.php <?php //----------------------------------------------------------------------------- // BellaBuzz v1b Copyright © Jem Turner 2008 unless otherwise noted // http://www.jemjabella.co.uk/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License. See README.txt // or LICENSE.txt for more information. //----------------------------------------------------------------------------- @require('prefs.php'); if (isset($_COOKIE['bellabuzz'])) { if ($_COOKIE['bellabuzz'] == md5($admin_pass.$secret)) { if (isset($_GET['page'])) $page = $_GET['page']; else $page = NULL; doAdminHeader(); switch($page) { case "answer": if (!isset($_GET['ques']) || !is_numeric($_GET['ques'])) exit("Invalid question."); doQuestionForm($_GET['ques'], UNANSWERED); break; case "edit": if (!isset($_GET['ques']) || !is_numeric($_GET['ques'])) exit("Invalid question."); doQuestionForm($_GET['ques'], ANSWERED); break; case "editprocess": if ($_SERVER['REQUEST_METHOD'] != "POST") doError("This page must not be accessed directly."); if (doIpCheck($_SERVER['REMOTE_ADDR']) === false) doError("Invalid IP; no need to fiddle with the readonly form elements."); foreach ($_POST as $key => $val) { $$key = preg_replace("/,(?! )/", ", ", trim(strip_tags($val))); } $answer = str_replace("<br /><br /><br /><br />", "<br /><br />", preg_replace("([\r\n])", "<br />", $answer)); $storeit = '"'.$question.'",'.$dateask.','.$ip.',"'.$answer.'",'.$dateanswer; if ($file == "answered.txt") { $questions = file(ANSWERED); $questions[$quesid] = $storeit; doWrite(ANSWERED, implode($questions), "w"); } elseif ($file == "unanswered.txt") { $openquestions = file(UNANSWERED); unset($openquestions[$quesid]); doWrite(UNANSWERED, implode($openquestions), "w"); $questions = file(ANSWERED); $questions[] = "\r\n".$storeit; doWrite(ANSWERED, implode($questions), "w"); } echo '<p>Question answered. <a href="admin.php">Return to main?</a></p>'; break; case "delete": if (!isset($_GET['ques']) || !is_numeric($_GET['ques'])) exit("Invalid question."); if (!isset($_GET['file']) && ($_GET['file'] != "answered.txt" || $_GET['file'] != "unanswered.txt")) exit("Invalid file"); $questions = file($_GET['file']); unset($questions[$_GET['ques']]); doWrite($_GET['file'], implode($questions), "w"); echo '<p>Question deleted. <a href="admin.php">Return to main?</a></p>'; break; case "viewall": if (!isset($_GET['file']) && ($_GET['file'] != "answered.txt" || $_GET['file'] != "unanswered.txt")) exit("Invalid file"); if ($_GET['file'] == "unanswered.txt") { echo '<h1>Unanswered Questions</h1>'; doDisplayQuesAdmin("answer", UNANSWERED, doCount("open")); } else { echo '<h1>Answered Questions</h1>'; doDisplayQuesAdmin("edit", ANSWERED, doCount("done")); } break; default: ?> <h1>Latest Unanswered Questions</h1> <?php if (doCount("open") > 0) doDisplayQuesAdmin("answer", UNANSWERED, $perpage); else echo '<p>No unanswered questions.</p>'; ?> <p><a href="admin.php?page=viewall&file=unanswered.txt">View all unanswered</a></p> <h1>Latest Answered Questions</h1> <?php if (doCount("done") > 0) doDisplayQuesAdmin("edit", ANSWERED, $perpage); else echo '<p>No answered questions.</p>'; ?> <p><a href="admin.php?page=viewall&file=answered.txt">View all answered</a></p> <?php break; } doAdminFooter(); exit; } else { exit("<p>Bad cookie. Clear 'em out and start again.</p>"); } } if (isset($_GET['p']) && $_GET['p'] == "login") { if ($_POST['name'] != $admin_name || $_POST['pass'] != $admin_pass) { doAdminHeader(); ?> <p>Sorry, that username and password combination is not valid. Try again.</p> <form method="post" action="admin.php"> Username:<br> <input type="text" name="name"><br> Password:<br> <input type="password" name="pass"><br> <input type="submit" name="submit" value="Login"> </form> <?php doAdminFooter(); exit; } else if ($_POST['name'] == $admin_name && $_POST['pass'] == $admin_pass) { setcookie('bellabuzz', md5($_POST['pass'].$secret), time()+(31*86400)); header("Location: admin.php"); exit; } else { setcookie('bellabuzz', NULL, NULL); header("Location: admin.php"); exit; } } doAdminHeader(); ?> <form method="post" action="admin.php?p=login"> Username:<br> <input type="text" name="name"><br> Password:<br> <input type="password" name="pass"><br> <input type="submit" name="submit" value="Login"> </form> <?php doAdminFooter(); ?> Link to comment https://forums.phpfreaks.com/topic/172050-add-a-feature-to-bellabuzz/#findComment-910103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.