= '2.3') ? "wp-admin/includes/upgrade.php" : "wp-admin/upgrade-functions.php";
require_once(ABSPATH . $pathtoFunction);
dbDelta($qry);
if ($first_install == "yes") {
$welcome_name = "Pierre";
$welcome_text = __('Congratulations, you just completed the installation of this shoutbox.',wordspew);
@mysql_query("SET CHARACTER SET 'utf8'");
@mysql_query("SET NAMES utf8");
$wpdb->query("INSERT INTO ".$jal_table_prefix."liveshoutbox (time,name,text) VALUES ('".time()."','".$welcome_name."','".$welcome_text."')");
// Default shoutbox config
add_option('shoutbox_fade_from', "666666",'','yes');
add_option('shoutbox_fade_to', "FFFFFF",'','yes');
add_option('shoutbox_update_seconds', 4000,'','yes');
add_option('shoutbox_fade_length', 1500,'','yes');
add_option('shoutbox_text_color', "333333",'','yes');
add_option('shoutbox_name_color', "0066CC",'','yes');
add_option('shoutbox_registered_only', '0','','yes');
}
else {
$wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox CHARACTER SET utf8");
$wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox MODIFY `text` TEXT NOT NULL, CHARACTER SET utf8");
$wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox MODIFY `name` TINYTEXT NOT NULL, CHARACTER SET utf8");
$wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox_useronline CHARACTER SET utf8");
$wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox_useronline MODIFY `username` VARCHAR(50) NOT NULL, CHARACTER SET utf8");
}
add_option('shoutbox_sound', '0','','yes');
add_option('shoutbox_spam', '0','','yes');
add_option('shoutbox_XHTML', '0','','yes');
add_option('shoutbox_online', '0','','yes');
add_option('shoutbox_Smiley', '0','','yes');
add_option('shoutbox_Show_Spam', '0','','yes');
add_option('shoutbox_nb_comment', '35','','yes');
add_option('shoutbox_Captcha','0','','yes');
add_option('shoutbox_HideUsers','0','','yes');
}
if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
add_action('init', 'jal_install_shout');
}
// function to print the external javascript and css links
function jal_add_to_head () {
global $jal_version, $jal_table_prefix, $user_ID;
$jal_wp_url = get_bloginfo('wpurl') . "/";
echo '
';
}
// In the administration page, add some style and script...
function jal_add_to_admin_head () { ?>
' . __("No Access for you!",wordspew) .'
';
}
else { ?>
%s spams blocked)',wordspew),$nb);?> v.
get_var("SELECT id FROM ".$jal_table_prefix."liveshoutbox ORDER BY id DESC LIMIT 1");
printf(__('There have been %s messages in this shoutbox',wordspew),$results);?>
".$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];
if(verifyName($name))
$user=1;
else
$user=0;
// append the new id's to the beginning of $loop --- is being used to separate the fields in the output
$loop = $id."---".stripslashes($name)."---".stripslashes($text)."---".stripslashes($url)."---".$user."---" . $loop;
}
$who=($_SESSION['Show_Users']==0) ? "" : jal_get_useronline_extended();
echo $who."\n".$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);
}
function check_ip_address($from, $checkip) {
global $spam_msg;
$checkip=trim($checkip);
if(strpos($checkip,"*") || strpos($checkip,"/")) {
$checkip =str_replace("*", "([0-9]{1,3})", $checkip);
if(strpos($checkip,"/")) {
$ar=explode(".",$checkip);
for($i=0; $i<@count($ar); $i++) {
$ar2=explode("/",$ar[$i]);
if(@count($ar2)==2) {
$ip="(";
for($j=intval($ar2[0]); $j1) {
$spam_msg=$_SESSION['HTTPLimit'];
return false;
}
$count_content_type=substr_count($theText,"content-type");
if($count_content_type>=1) {
$spam_msg=$_SESSION['DLSpam'];
return false;
}
$theText.=$TheURL;
$ip = $_SERVER['REMOTE_ADDR'];
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
@mysql_query("SET CHARACTER SET 'utf8'", $conn);
@mysql_query("SET NAMES utf8", $conn);
$spam=array();
$SQL="SELECT option_value FROM ".$jal_table_prefix."options WHERE option_name = 'moderation_keys'";
$spam=mysql_query($SQL,$conn);
$sql_create_arr = mysql_fetch_array($spam);
$spam= $sql_create_arr[0];
$spam=explode("\r\n",strtolower($spam));
if($spam[0]!="") {
for($i=0;$i<@count($spam);$i++) {
$str=$spam[$i];
if (strlen($str)>8 && intval($str)) {
if(!check_ip_address($ip, $str)) {
$spam_msg=$_SESSION['IPLogged'];
return false;
break;
}
}
$pos=strpos($theText,$str);
if(is_int($pos)) {
$spam_msg=$_SESSION['DLSpam'];
return false;
break;
}
}
}
return true;
}
//////////////////////////////////////////////////////
// Functions Below are for submitting comments to the database
//////////////////////////////////////////////////////
// When user submits and javascript fails
if (isset($_POST['shout_no_js'])) {
$myURL = isset($_POST['shoutboxU']) ? $_POST['shoutboxU'] : "";
if ($_POST['shoutboxname'] != '' && $_POST['chatbarText'] != '')
jal_addData($_POST['shoutboxname'], $_POST['chatbarText'], $myURL);
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
echo "0";
}
function mySplit ($captures){
// si url ou email, on passe...
if(preg_match('#^(?:(?:http|ftp)s?://|[-_a-z0-9]+(?:\.[-_a-z0-9]+)*@[-a-z0-9]+(?:\.[-a-z0-9]+)*\.[a-z]{2,6})#i',$captures[0])) {
$return = $captures[0];
}
else {
$splited = preg_replace("/([^\s]{".split."})/iu","$1 ",$captures[0]);
$return = trim($splited);
}
return $return;
}
function jal_addData($jal_user_name,$jal_user_text,$jal_user_url) {
global $spam_msg, $jal_table_prefix, $jal_user_val, $jal_user_calc, $jal_user_Control, $ip;
$SearchText=strtolower(trim($jal_user_text));
$SearchURL=strtolower(trim($jal_user_url));
//replacement of non-breaking spaces...
$SearchName=str_replace("Â "," ",$jal_user_name);
$SearchName=trim($SearchName);
$SearchName=strtolower($SearchName);
$myBolean="";
//if the BadCalc variable is not set then it's a bot (direct access to wordspew)
if(!isset($_SESSION['BadCalc'])) {
AddSpam("I DON'T LIKE SPAM !!!");
exit;
}
if($SearchURL == "http://") $SearchURL="";
if($SearchName==$SearchText || isset($_POST['shoutboxurl'])) {
AddSpam($_SESSION['DLSpam']);
exit;
}
$hashtext = $_SESSION['hashtext'];
$jal_user_calc=md5($jal_user_calc.$hashtext);
if($jal_user_calc!=$jal_user_Control) {
AddSpam($_SESSION['BadCalc']);
exit;
}
/*
if(!isset($_SESSION['Logged']) && verifyName($SearchName)) {
AddSpam($_SESSION['LoggedMsg']);
exit;
}
*/
if(CheckSpam($SearchText.' '.$SearchName, $SearchURL)) {
setcookie("jalUserName",$jal_user_name,time()+60*60*24*30*3,'/');
//the message is cut of after 500 letters
$jal_user_text = trim(substr($jal_user_text,0,500));
// masque pour capturer toute chaîne de plus de $split car.
$pattern = '#[^ ]{'.split.',}#u';
// appel à une fonction callback de remplacement (*beaucoup* plus rapide que preg_replace() option e)
$jal_user_text = preg_replace_callback($pattern, 'mySplit', $jal_user_text);
$jal_user_text=jal_special_chars($jal_user_text);
$jal_user_name = substr(trim($jal_user_name), 0,18);
$jal_user_name=jal_special_chars($jal_user_name);
$jal_user_url = ($jal_user_url == "http://") ? "" : jal_special_chars($jal_user_url);
if (substr($jal_user_url,0,3)=="www") $jal_user_url ="http://".$jal_user_url;
if (strpos($jal_user_url,"@")!=false) $jal_user_url ="mailto:".$jal_user_url;
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
@mysql_query("SET CHARACTER SET 'utf8'", $conn);
@mysql_query("SET NAMES utf8", $conn);
if($jal_user_url!="") {
setcookie("jalUrl",str_replace("mailto:","",$jal_user_url),time()+60*60*24*30*3,'/');
if($_SESSION['useURL']=="") $myBolean="false";
}
if($myBolean=="") {
if($_SESSION['useCaptcha']=="1") setcookie("jalCaptcha","Ok",time()+60*60*24*30*3,'/');
mysql_query("INSERT INTO ".$jal_table_prefix."liveshoutbox (time,name,text,url,ipaddr) VALUES ('".time()."','".mysql_real_escape_string($jal_user_name)."','".mysql_real_escape_string($jal_user_text)."','".mysql_real_escape_string($jal_user_url)."', '".mysql_real_escape_string($ip)."')", $conn);
jal_deleteOld(); //some database maintenance
//take them right back where they left off
header('location: '.$_SERVER['HTTP_REFERER']);
}
else {
AddSpam($_SESSION['DLSpam']);
}
}
else AddSpam($spam_msg);
}
function AddSpam($msg) {
global $jal_table_prefix, $jalSendChat;
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
$SQL= mysql_query("SELECT option_value FROM ".$jal_table_prefix."options WHERE option_name='shoutbox_spam'");
$nb= mysql_result($SQL, 0)+1;
mysql_query("UPDATE ".$jal_table_prefix."options SET option_value='".$nb."' WHERE option_name='shoutbox_spam'",$conn);
if($jalSendChat=="yes") {
$_SESSION['spam_msg']= $msg;
header('location: '.$_SERVER['HTTP_REFERER']);
}
else echo $msg;
}
//Maintains the database by deleting past comments
function jal_deleteOld() {
global $jal_table_prefix;
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
$SQL=mysql_query("SELECT option_value FROM ".$jal_table_prefix."options WHERE option_name = 'shoutbox_nb_comment'");
$jal_number_of_comments=mysql_result($SQL,0);
$results = mysql_query("SELECT * FROM ".$jal_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 ".$jal_table_prefix."liveshoutbox WHERE id < ".$id, $conn);
}
function sanitize_name($name) {
$bad = array(" ", "Â ", "'", ".");
$good= array("", "", "", "");
return str_replace($bad, $good, $name);
}
function verifyName($name) {
$ar=explode(",",$_SESSION['LoggedUsers']);
if(in_array(strtolower($name), $ar)) return true;
else return false;
}
// Prints the html structure for the shoutbox
function jal_get_shoutbox () {
global $wpdb, $jal_table_prefix, $user_level, $user_nickname, $user_url, $user_ID, $jal_admin_user_level, $user_identity;
get_currentuserinfo(); // Gets logged in user.
$theuser_nickname=$user_nickname;
$ActualVersion=round(get_bloginfo('version'));
if($ActualVersion>=2) $theuser_nickname=$user_identity;
if(get_option('shoutbox_spam')=="") jal_install_shout();
$XHTML=get_option('shoutbox_XHTML');
$Captcha=get_option('shoutbox_Captcha');
$jal_number_of_comments=get_option('shoutbox_nb_comment');
$Actual_URL=get_bloginfo('wpurl');
$_SESSION['Show_Users']=get_option('shoutbox_online');
$_SESSION['BadCalc']=__("You should learn to count before use the shoutbox :)",wordspew);
$_SESSION['DLSpam']=__("I DON'T LIKE SPAM !!!",wordspew);
$_SESSION['HTTPLimit']=__("Sorry, but you can post only one url by message...",wordspew);
$_SESSION['IPLogged']=__("Your IP address have been banned from this blog, if you feel this is in error please contact the webmaster.",wordspew);
$_SESSION['hashtext']=get_option('shoutbox_hash');
$_SESSION['useURL']=get_option('shoutbox_use_url');
$_SESSION['useCaptcha']=get_option('shoutbox_Captcha');
?>
hide_errors();
$results = $wpdb->get_results("SELECT * FROM ".$jal_table_prefix."liveshoutbox ORDER BY id DESC LIMIT ".$jal_number_of_comments);
$wpdb->show_errors();
// Will only add the last message div if it is looping for the first time
$jal_first_time = true;
$registered_only = (get_option('shoutbox_registered_only') == "1") ? TRUE : FALSE;
// Loops the messages into a list
foreach( $results as $r ) {
$target="";
// Add links
if (strpos($r->text, $Actual_URL)===false && $XHTML==0) $target=' target="_blank"';
$theLink=__("link",wordspew); $theMail=__("email",wordspew);
$r->text = preg_replace("`(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?`i", "«$theLink»", $r->text);
$r->text = preg_replace("`([-_a-z0-9]+(\.[-_a-z0-9]+)*@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,6})`i","«$theMail»", $r->text);
if ($jal_first_time == true) {
$rand1=mt_rand(0,10);
$rand2=mt_rand(0,10);
$total=intval($rand1+$rand2);
if (get_option('shoutbox_sound') == "1") {
$img_sound=($_COOKIE['jalSound']==1 || $_COOKIE['jalSound']=="") ? "sound_1.gif" : "sound_0.gif";
echo '
';
}
if(get_option('shoutbox_Show_Spam')) {
$nb = get_option('shoutbox_spam');
printf(__('