codice:
<fieldset>
<legend>Other</legend>
Update Every: <input type="text" maxlength="3" name="update_seconds" value="<?php echo get_option('shoutbox_update_seconds') / 1000; ?>" size="2" /> Seconds
This determines how "live" the shoutbox is. With a bigger number, it will take more time for messages to show up, but also decrease the server load. You may use decimals. This number is used as the base for the first 8 javascript loads. After that, the number gets successively bigger. Adding a new comment or mousing over the shoutbox will reset the interval to the number suplied above. Default: 4 Seconds</p>
Fade Length: <input type="text" maxlength="3" name="fade_length" value="<?php echo get_option('shoutbox_fade_length') / 1000; ?>" size="2" /> Seconds
The amount of time it takes for the fader to completely blend with the background color. You may use decimals. Default 1.5 seconds</p>
Use textarea: <input type="checkbox" name="use_textarea" <?php if(get_option('shoutbox_use_textarea') == 'true') { echo 'checked="checked" '; } ?>/>
A textarea is a bigger type of input box. Users will have more room to type their comments, but it will take up more space.</p>
Use URL field: <input type="checkbox" name="use_url" <?php if(get_option('shoutbox_use_url') == 'true') echo 'checked="checked" '; ?>/>
Check this if you want users to have an option to add their URL when submitting a message.</p>
Only allow registered users: <input type="checkbox" name="registered_only" <?php if(get_option('shoutbox_registered_only') == '1') echo 'checked="checked" '; ?>/>
This will only let your registered users use the form that allows one to type messages. Users who are NOT logged in will be able to watch the chat and a message saying they must be logged in to comment. Note: this is not completely "secure" .. If someone REALLY wanted to, they could write a script that interacts directly with the message receiving file. They'd have to know what they're doing and it would be quite pointless.</p>
</fieldset>
<input type="submit" name="jal_admin_options" value="Save" class="button" style="font-size: 140%" />
<input type="submit" name="jal_truncate" id="jal_truncate_all" onclick="return confirm('You are about to delete ALL messages in the shoutbox. It will completely erase all messages. Are you sure you want to do this?');" value="Delete ALL messages" />
</form>
<fieldset>
<legend>Data (showing the last <?php echo $jal_number_of_comments; ?> messages)</legend>
Reminder: You MUST have at LEAST one comment in your shoutbox at all times. This is not live. New comments made while viewing this page will not magically appear like they do in the real thing.</p>
<?php
$results = $wpdb->get_results("SELECT * FROM ".$table_prefix."liveshoutbox ORDER BY id DESC LIMIT ". $jal_number_of_comments);
if (!$results) { echo "You must have at least 1 message in your shoutbox at all times!
Go to your shoutbox and add a messages."; } else {
$jal_first_time = "yes"; // Will only add the last message div if it is looping for the first time
foreach( $results as $r ) { // Loops the messages into a list
$url = (empty($r->url) && $r->url = "http://") ? $r->name : ''.$r->name.'';
if ($jal_first_time == "yes") { echo '<div id="lastMessage"><span>Last Message</span> <em id="responseTime">'.jal_time_since( $r->time ).' ago[/i]</div>
<ul id="outputList">
'; }
echo '[*]<form name="shoutbox_options" action="" method="get"><span>'.stripslashes($url).' : </span><input type="text" name="jal_text" value="'.stripslashes($r->text).'" size="60" />
<input type="hidden" name="page" value="wordspew" />
<input type="hidden" name="jal_comment_id" value="'.$r->id.'" />
<input type="submit" name="jal_delete" value="Delete" />
<input type="submit" name="jal_edit" value="Edit" /></form>
';
$jal_first_time = "0"; } }
?>
[/list]
</fieldset>
</div>
<?php } }
// To add administration page under Management Section
function shoutbox_admin_page() {
global $jal_admin_user_level;
add_management_page('Shoutbox Management', 'Live Shoutbox', $jal_admin_user_level, "wordspew", 'jal_shoutbox_admin');
}
// Time Since function courtesy
// http://blog.natbat.co.uk/archive/200...jal_time_since
// Works out the time since the entry post, takes a an argument in unix time (seconds)
function jal_time_since($original) {
// array of time period chunks
$chunks = array(
array(60 * 60 * 24 * 365 , 'year'),
array(60 * 60 * 24 * 30 , 'month'),
array(60 * 60 * 24 * 7, 'week'),
array(60 * 60 * 24 , 'day'),
array(60 * 60 , 'hour'),
array(60 , 'minute'),
);
$original = $original - 10; // Shaves a second, eliminates a bug where $time and $original match.
$today = time(); /* Current unix time */
$since = $today - $original;
// $j saves performing the count function each time around the loop
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
// finding the biggest chunk (if the chunk fits, break)
if (($count = floor($since / $seconds)) != 0) {
break;
}
}
$print = ($count == 1) ? '1 '.$name : "$count {$name}s";
if ($i + 1 < $j) {
// now getting the second item
$seconds2 = $chunks[$i + 1][0];
$name2 = $chunks[$i + 1][1];
// add second item if it's greater than 0
if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
$print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
}
}
return $print;
}
////////////////////////////////////////////////////////////
// Functions Below are for getting comments from the database
////////////////////////////////////////////////////////////
// Never cache this page
if ($jalGetChat == "yes" || $jalSendChat == "yes") {
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )."GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header("Content-Type: text/html; charset=utf-8");
//if the request does not provide the id of the last know message the id is set to 0
if (!$jal_lastID) $jal_lastID = 0;
}
// retrieves all messages with an id greater than $jal_lastID
if ($jalGetChat == "yes") {
jal_getData($jal_lastID);
}
// Where the shoutbox receives information
function jal_getData ($jal_lastID) {
$html = implode('', file("../../../wp-config.php"));
$html = str_replace ("require_once", "// ", $html);
$html = str_replace ("<?php", "", $html);
eval($html);
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
$sql = "SELECT * FROM ".$table_prefix."liveshoutbox WHERE id > ".$jal_lastID." ORDER BY id DESC";
$results = mysql_query($sql, $conn);
$loop = "";
while ($row = mysql_fetch_array($results)) {
$id = $row[0];
$time = $row[1];
$name = $row[2];
$text = $row[3];
$url = $row[4];
// append the new id's to the beginning of $loop
$loop = $id."---".stripslashes($name)."---".stripslashes($text)."---".jal_time_since($time)." ago---".stripslashes($url)."---" . $loop; // --- is being used to separate the fields in the output
}
echo $loop;
// if there's no new data, send one byte. Fixes a bug where safari gives up w/ no data
if (empty($loop)) { echo "0"; }
}
function jal_special_chars ($s) {
$s = htmlspecialchars($s, ENT_COMPAT,'UTF-8');
return str_replace("---","−-−",$s);
}
////////////////////////////////////////////////////////////
// Functions Below are for submitting comments to the database
////////////////////////////////////////////////////////////
// When user submits and javascript fails
if (isset($_POST['shout_no_js'])) {
if ($_POST['shoutboxname'] != '' && $_POST['chatbarText'] != '') {
jal_addData($_POST['shoutboxname'], $_POST['chatbarText'], $_POST['shoutboxurl']);
jal_deleteOld(); //some database maintenance
setcookie("jalUserName",$_POST['shoutboxname'],time()+60*60*24*30*3,'/');
setcookie("jalUrl",$_POST['shoutboxurl'],time()+60*60*24*30*3,'/');
//take them right back where they left off
header('location: '.$_SERVER['HTTP_REFERER']);
} else echo "You must have a name and a comment";
}
//only if a name and a message have been provides the information is added to the db
if ($jal_user_name != '' && $jal_user_text != '' && $jalSendChat == "yes") {
jal_addData($jal_user_name,$jal_user_text,$jal_user_url); //adds new data to the database
jal_deleteOld(); //some database maintenance
echo "0";
}
function jal_addData($jal_user_name,$jal_user_text,$jal_user_url) {
//the message is cut of after 500 letters
$jal_user_text = substr($jal_user_text,0,500);
$jal_user_name = substr(trim($jal_user_name), 0,18);
///// The code below can mess up multibyte strings
// If there isn't a url, truncate the words to 25 chars each
// if (!preg_match("`(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?`i", $jal_user_text, $matches))
// $jal_user_text = preg_replace("/([^\s]{25})/","$1 ",$jal_user_text);
// CENSORS .. default is off. To turn it on, uncomment the line below. Add new lines with new censors as needed.
//$jal_user_text = str_replace("fuck", "****", $jal_user_text);
$jal_user_text = jal_special_chars(trim($jal_user_text));
$jal_user_name = (empty($jal_user_name)) ? "Anonymous" : jal_special_chars($jal_user_name);
$jal_user_url = ($jal_user_url == "http://") ? "" : jal_special_chars($jal_user_url);
$html = implode('', file("../../../wp-config.php"));
$html = str_replace ("require_once", "// ", $html);
$html = str_replace ("<?php", "", $html);
eval($html);
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
mysql_query("INSERT INTO ".$table_prefix."liveshoutbox (time,name,text,url) VALUES ('".time()."','".mysql_real_escape_string($jal_user_name)."','".mysql_real_escape_string($jal_user_text)."','".mysql_real_escape_string($jal_user_url)."')", $conn);
}
//Maintains the database by deleting past comments
function jal_deleteOld() {
global $jal_number_of_comments;
$html = implode('', file("../../../wp-config.php"));
$html = str_replace ("require_once", "// ", $html);
$html = str_replace ("<?php", "", $html);
eval($html);
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
$results = mysql_query("SELECT * FROM ".$table_prefix."liveshoutbox ORDER BY id DESC LIMIT ".$jal_number_of_comments, $conn);
while ($row = mysql_fetch_array($results)) { $id = $row[0]; }
if ($id) mysql_query("DELETE FROM ".$table_prefix."liveshoutbox WHERE id < ".$id, $conn);
}
// Prints the html structure for the shoutbox
function jal_get_shoutbox () {
global $wpdb, $table_prefix, $jal_number_of_comments;
?>
<div id="wordspew">
<div id="chatoutput">