PageRenderTime 58ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wordspew/wordspew.php

https://github.com/alx/blogsfera
PHP | 1160 lines | 1008 code | 91 blank | 61 comment | 172 complexity | 7dbfc2391b5459fd2c6cf03cb1445b70 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Plugin Name: Pierre's Wordspew
  4. Plugin URI: http://pierre.sudarovich.free.fr/
  5. Description: A plugin that creates a live shoutbox, using AJAX as a backend. Users can chat freely from your blog without refreshing the page! It uses the Fade Anything Technique for extra glamour
  6. Author: Andrew Sutherland, Modified by Pierre
  7. Version: 3.73
  8. Author URI: http://blog.jalenack.com
  9. */
  10. define('wordspew', 'wordspew/wordspew');
  11. define('split',16);
  12. // Version of this plugin. Not very useful for you, but for the dev
  13. $jal_version = "3.73";
  14. // The required user level needed to access the admin page for this plugin
  15. $jal_admin_user_level = 8;
  16. if (!isset($table_prefix)) {
  17. $html = implode('', file("../../../wp-config.php"));
  18. $html = str_replace ("require_once", "// ", $html);
  19. $html = str_replace ("<?php", "", $html);
  20. eval($html);
  21. }
  22. $portal_id = 1;
  23. $jal_table_prefix = $table_prefix . $portal_id . "_";
  24. // Register globals - Thanks Karan et Etienne
  25. $jal_lastID = isset($_GET['jal_lastID']) ? $_GET['jal_lastID'] : "";
  26. $jal_user_name = isset($_POST['n']) ? $_POST['n'] : "";
  27. $jal_user_url = isset($_POST['u']) ? $_POST['u'] : "";
  28. $jal_user_text = isset($_POST['c']) ? $_POST['c'] : "";
  29. $jal_user_calc = isset($_POST['shoutboxOp']) ? $_POST['shoutboxOp'] : "-2";
  30. $jal_user_Control=isset($_POST['shoutboxControl']) ? $_POST['shoutboxControl'] : "-3";
  31. $jalGetChat = isset($_GET['jalGetChat']) ? $_GET['jalGetChat'] : "";
  32. $jalSendChat = isset($_GET['jalSendChat']) ? $_GET['jalSendChat'] : "";
  33. @session_start();
  34. if ( !function_exists('current_user_can') ) :
  35. function current_user_can() { return 0; }
  36. endif;
  37. function jal_install_shout () {
  38. global $jal_table_prefix, $wpdb, $user_level, $jal_admin_user_level, $wp_version;
  39. get_currentuserinfo();
  40. $current=current_user_can('level_'.$jal_admin_user_level);
  41. if ($user_level < $jal_admin_user_level && $current!=1) return;
  42. $result = mysql_list_tables(DB_NAME);
  43. $tables = array();
  44. while ($row = mysql_fetch_row($result)) { $tables[] = $row[0]; }
  45. if (!in_array($jal_table_prefix."liveshoutbox", $tables)) {
  46. $first_install = "yes";
  47. }
  48. $qry="CREATE TABLE ".$jal_table_prefix."liveshoutbox (
  49. id mediumint(7) NOT NULL AUTO_INCREMENT,
  50. time bigint(11) DEFAULT '0' NOT NULL,
  51. name tinytext NOT NULL,
  52. text text NOT NULL,
  53. url text NOT NULL,
  54. ipaddr varchar(16),
  55. UNIQUE KEY id (id)
  56. ) CHARACTER SET utf8;
  57. CREATE TABLE ".$jal_table_prefix."liveshoutbox_useronline (
  58. timestamp int(15) NOT NULL default '0',
  59. username varchar(50) NOT NULL default '',
  60. ip varchar(40) NOT NULL default '',
  61. location varchar(255) NOT NULL default '',
  62. url varchar(255) NOT NULL default '',
  63. PRIMARY KEY (timestamp),
  64. KEY username (username),
  65. KEY ip (ip),
  66. KEY file (location)
  67. ) CHARACTER SET utf8;
  68. ";
  69. $pathtoFunction = (floatval($wp_version) >= '2.3') ? "wp-admin/includes/upgrade.php" : "wp-admin/upgrade-functions.php";
  70. require_once(ABSPATH . $pathtoFunction);
  71. dbDelta($qry);
  72. if ($first_install == "yes") {
  73. $welcome_name = "Pierre";
  74. $welcome_text = __('Congratulations, you just completed the installation of this shoutbox.',wordspew);
  75. @mysql_query("SET CHARACTER SET 'utf8'");
  76. @mysql_query("SET NAMES utf8");
  77. $wpdb->query("INSERT INTO ".$jal_table_prefix."liveshoutbox (time,name,text) VALUES ('".time()."','".$welcome_name."','".$welcome_text."')");
  78. // Default shoutbox config
  79. add_option('shoutbox_fade_from', "666666",'','yes');
  80. add_option('shoutbox_fade_to', "FFFFFF",'','yes');
  81. add_option('shoutbox_update_seconds', 4000,'','yes');
  82. add_option('shoutbox_fade_length', 1500,'','yes');
  83. add_option('shoutbox_text_color', "333333",'','yes');
  84. add_option('shoutbox_name_color', "0066CC",'','yes');
  85. add_option('shoutbox_registered_only', '0','','yes');
  86. }
  87. else {
  88. $wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox CHARACTER SET utf8");
  89. $wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox MODIFY `text` TEXT NOT NULL, CHARACTER SET utf8");
  90. $wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox MODIFY `name` TINYTEXT NOT NULL, CHARACTER SET utf8");
  91. $wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox_useronline CHARACTER SET utf8");
  92. $wpdb->query("ALTER TABLE ".$jal_table_prefix."liveshoutbox_useronline MODIFY `username` VARCHAR(50) NOT NULL, CHARACTER SET utf8");
  93. }
  94. add_option('shoutbox_sound', '0','','yes');
  95. add_option('shoutbox_spam', '0','','yes');
  96. add_option('shoutbox_XHTML', '0','','yes');
  97. add_option('shoutbox_online', '0','','yes');
  98. add_option('shoutbox_Smiley', '0','','yes');
  99. add_option('shoutbox_Show_Spam', '0','','yes');
  100. add_option('shoutbox_nb_comment', '35','','yes');
  101. add_option('shoutbox_Captcha','0','','yes');
  102. add_option('shoutbox_HideUsers','0','','yes');
  103. }
  104. if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
  105. add_action('init', 'jal_install_shout');
  106. }
  107. // function to print the external javascript and css links
  108. function jal_add_to_head () {
  109. global $jal_version, $jal_table_prefix, $user_ID;
  110. $jal_wp_url = get_bloginfo('wpurl') . "/";
  111. echo '
  112. <!-- Added By Wordspew Plugin, modified by Pierre, version '.$jal_version.' -->
  113. <link rel="alternate" type="application/rss+xml" title="'. __('Wordspew-RSS-Feed for:', wordspew). ' '. get_bloginfo('name').'" href="'.$jal_wp_url.'wp-content/plugins/wordspew/wordspew-rss.php"/>
  114. <link rel="stylesheet" href="'.$jal_wp_url.'wp-content/plugins/wordspew/css.php" type="text/css" />
  115. <link rel="stylesheet" href="'.$jal_wp_url.'wp-content/plugins/wordspew/users.css" type="text/css" />
  116. <script type="text/javascript" src="'.$jal_wp_url.'wp-content/plugins/wordspew/fatAjax.php"></script>
  117. <script type="text/javascript">
  118. //<![CDATA[
  119. function trim(s) {
  120. return s.replace(/^( | )+/, \'\').replace(/( | )+$/, \'\');
  121. }
  122. function CheckSpam(theText,theURL) {
  123. theMsg=document.getElementById(\'chatbarText\').value;
  124. theMsg=theMsg.toLowerCase();
  125. count_http=theMsg.split("http").length;
  126. var limit=2;
  127. if((document.getElementById(\'shoutboxU\').value).length>7) {
  128. if(document.getElementById(\'shoutboxU\').style.display!="none") {
  129. limit++;
  130. count_http++;
  131. }
  132. }
  133. if(count_http>limit) {
  134. alert("'. __('Sorry, but you can post only one url by message...',wordspew) .'");
  135. return false;
  136. }
  137. theText+=\' \'+theURL;';
  138. $spam=get_option('moderation_keys');
  139. if($spam!="") {
  140. $spam = str_replace("'", "\'", $spam);
  141. $spam = str_replace("\r\n", "','", $spam);
  142. $spam="'".strtolower($spam)."'";
  143. }
  144. echo '
  145. var spam = ['. str_replace(",''", "", $spam) .'];
  146. TextToScan=theText.toLowerCase();
  147. for (var i = 0; i < spam.length; i++) {
  148. if(TextToScan.indexOf(spam[i])!=-1) {
  149. alert("'. __('No, sorry you used a banned word!',wordspew) .'\n-> "+spam[i].toUpperCase());
  150. return false;
  151. break;
  152. }
  153. }
  154. ';
  155. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  156. mysql_select_db(DB_NAME, $conn);
  157. if (defined("DB_CHARSET")) {
  158. @mysql_query("SET CHARACTER SET 'utf8'", $conn);
  159. @mysql_query("SET NAMES utf8", $conn);
  160. }
  161. $column = (floatval(get_bloginfo('version')) > '1.5') ? "display_name" : "user_nickname";
  162. $SQL="SELECT ".$column." FROM ".$jal_table_prefix."users";
  163. $result=mysql_query($SQL,$conn);
  164. while ($row = mysql_fetch_assoc($result)) {
  165. $users.= "'".str_replace("'","\'",$row[$column])."',";
  166. $LoggedUsers.=$row[$column].",";
  167. }
  168. $users=strtolower(substr($users, 0, -1));
  169. $_SESSION['LoggedUsers']=strtolower(substr($LoggedUsers, 0, -1));
  170. $_SESSION['LoggedMsg']=__('No, sorry you used the name of a registered user! You have to change it please.',wordspew);
  171. if(get_option('shoutbox_HideUsers')==0 && !$user_ID) {
  172. echo '
  173. var users=['.$users.'];
  174. for (var i = 0; i < users.length; i++) {
  175. if(trim(document.getElementById(\'shoutboxname\').value.toLowerCase())==users[i]) {
  176. msg="'.$_SESSION['LoggedMsg'].'";
  177. msg+="\n-> "+trim(document.getElementById(\'shoutboxname\').value);
  178. alert(msg);
  179. return false;
  180. break;
  181. }
  182. }
  183. ';
  184. }
  185. if (!defined("DB_CHARSET")) {
  186. @mysql_query("SET CHARACTER SET 'latin1'");
  187. @mysql_query("SET NAMES latin1");
  188. }
  189. echo '
  190. return true;
  191. }
  192. //]]>
  193. </script>
  194. ';
  195. }
  196. // In the administration page, add some style and script...
  197. function jal_add_to_admin_head () { ?>
  198. <style type="text/css">
  199. input[name=jal_delete]:hover, #jal_truncate_all:hover, input[name=jal_ban]:hover { background: #c22; color: #fff; cursor: pointer; }
  200. input[name=jal_edit]:hover { background: #2c2; color: #fff; cursor: pointer; }
  201. #shoutbox_options p { text-indent: 15px; padding: 5px 0; color: #555; }
  202. #shoutbox_options span { border: 1px dotted #ccc; padding: 4px 14px; }
  203. #outputList { list-style-type:none; }
  204. </style>
  205. <?php
  206. }
  207. // HTML printed to the admin panel
  208. function jal_shoutbox_admin () {
  209. global $jal_admin_user_level, $wpdb, $user_level, $jal_table_prefix, $nb, $jal_version;
  210. get_currentuserinfo(); // Gets logged in user.
  211. $jal_number_of_comments=get_option('shoutbox_nb_comment');
  212. if ($jal_number_of_comments=="")
  213. $jal_number_of_comments=35;
  214. $nb =get_option('shoutbox_spam');
  215. if($nb=="") {
  216. jal_install_shout();
  217. $nb=0;
  218. }
  219. $current=current_user_can('level_'.$jal_admin_user_level);
  220. // If user is not allowed to use the admin page
  221. if ($user_level < $jal_admin_user_level && $current!=1) {
  222. echo '<div class="wrap"><h2>' . __("No Access for you!",wordspew) .'</h2></div>';
  223. }
  224. else { ?>
  225. <?php if (isset($_GET['jal_delete'])) { ?>
  226. <div class="updated"><p><?php _e('The comment was deleted successfully.',wordspew);?></p></div>
  227. <?php } if (isset($_GET['jal_edit'])) { ?>
  228. <div class="updated"><p><?php _e('The comment was edited successfully.',wordspew);?></p></div>
  229. <?php } if (isset($_GET['jal_truncate'])) { ?>
  230. <div class="updated"><p><?php _e('The shoutbox database has been wiped. You now have a fresh slate!',wordspew);?></p></div>
  231. <?php } if (isset($_GET['jal_ban'])) { ?>
  232. <div class="updated"><p><?php _e('The source ip of this comment was marked as spammer.',wordspew);?></p></div>
  233. <?php } ?>
  234. <div class="wrap">
  235. <h2><?php printf(__('Jalenack\'s Live Shoutbox (Actually <font color="red">%s</font> spams blocked)',wordspew),$nb);?> v. <?php
  236. echo $jal_version; ?></h2>
  237. <p><?php _e('When you update the Times and Colors, you may need to refresh/empty cache before you see the changes take effect',wordspew);?></p>
  238. <p><?php
  239. $results = $wpdb->get_var("SELECT id FROM ".$jal_table_prefix."liveshoutbox ORDER BY id DESC LIMIT 1");
  240. printf(__('There have been <b>%s</b> messages in this shoutbox',wordspew),$results);?></p>
  241. <form name="shoutbox_options" action="edit.php?page=wordspew" method="get" id="shoutbox_options">
  242. <fieldset>
  243. <legend><b><?php _e('Colors (Must be 6 digit hex)',wordspew);?></b></legend>
  244. <input type="hidden" name="page" value="wordspew" />
  245. <?php _e('Fade from',wordspew);?>: #<input type="text" maxlength="6" name="fade_from"
  246. value="<?php echo get_option('shoutbox_fade_from'); ?>" size="6" /> <span
  247. style="background: #<?php echo get_option('shoutbox_fade_from'); ?>;">&nbsp;</span>
  248. <p><?php _e('The color that new messages fade in from. Default',wordspew);?>: <span style="color: #666">666666</span></p>
  249. <?php _e('Fade to',wordspew);?>: #<input type="text" maxlength="6" name="fade_to" value="<?php echo get_option('shoutbox_fade_to'); ?>" size="6" /> <span style="background: #<?php echo get_option('shoutbox_fade_to'); ?>;">&nbsp;</span>
  250. <p><?php _e('Also used as the background color of the box. Default: FFFFFF (white)',wordspew);?></p>
  251. <?php _e('Text Color',wordspew);?>: #<input type="text" maxlength="6" name="text_color"
  252. value="<?php echo get_option('shoutbox_text_color'); ?>" size="6" /> <span
  253. style="background: #<?php echo get_option('shoutbox_text_color'); ?>;">&nbsp;</span>
  254. <p><?php _e('The color of text within the box. Default',wordspew);?>: <span style="color: #333">333333</span></p>
  255. <?php _e('Name Color',wordspew);?>: #<input type="text" maxlength="6" name="name_color"
  256. value="<?php echo get_option('shoutbox_name_color'); ?>" size="6" /> <span
  257. style="background: #<?php echo get_option('shoutbox_name_color'); ?>;">&nbsp;</span>
  258. <p><?php _e('The color of peoples\' names. Default',wordspew);?>: <span style="color: #06c">0066CC</span></p>
  259. </fieldset>
  260. <br />
  261. <fieldset>
  262. <legend><b><?php _e('Other',wordspew);?></b></legend>
  263. <?php _e('Show',wordspew);?>:<input type="text" maxlength="3" name="nb_comment" value="<?php echo $jal_number_of_comments; ?>"
  264. size="2" /> <?php _e('comments in the shoutbox',wordspew);?><br />
  265. <p><?php _e('Enter, here, the number of shouts you want to show in your shoutbox', wordspew);?></p>
  266. <?php _e('Update Every',wordspew);?>: <input type="text" maxlength="3" name="update_seconds"
  267. value="<?php echo get_option('shoutbox_update_seconds') / 1000; ?>" size="2" /> <?php _e('Seconds',wordspew);?><br />
  268. <p><?php _e('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',wordspew);?></p>
  269. <?php _e('Fade Length',wordspew);?>: <input type="text" maxlength="3" name="fade_length"
  270. value="<?php echo get_option('shoutbox_fade_length') / 1000; ?>" size="2" /> <?php _e('Seconds',wordspew);?><br />
  271. <p><?php _e('The amount of time it takes for the fader to completely blend with the background color. You may use decimals. Default 1.5 seconds',wordspew);?></p>
  272. <?php _e('Use textarea',wordspew);?>: <input type="checkbox" name="use_textarea" <?php if(get_option('shoutbox_use_textarea') == 'true') { echo 'checked="checked" '; } ?>/>
  273. <p><?php _e('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.',wordspew);?></p>
  274. <?php _e('Use URL field',wordspew);?>: <input type="checkbox" name="use_url" <?php if(get_option('shoutbox_use_url') == 'true') echo 'checked="checked" '; ?>/>
  275. <p><?php _e('Check this if you want users to have an option to add their URL when submitting a message.',wordspew);?></p>
  276. <?php _e('Use sound alert',wordspew);?>: <input type="checkbox" name="use_sound" <?php if(get_option('shoutbox_sound') == '1') echo 'checked="checked" '; ?>/>
  277. <p><?php _e('Check this if you want to hear a sound alert when someone post message',wordspew);?></p>
  278. <?php _e('XHTML strict',wordspew);?>: <input type="checkbox" name="XHTML" <?php if(get_option('shoutbox_XHTML') == '1') echo 'checked="checked" '; ?>/>
  279. <p><?php _e('Check this if you want to use XHTML strict',wordspew);?></p>
  280. <?php _e('Show users online',wordspew);?>: <input type="checkbox" name="Show_Users" <?php if(get_option('shoutbox_online') == '1') echo 'checked="checked" '; ?>/>
  281. <p><?php _e('Check this if you want to show, in real time, users online',wordspew);?></p>
  282. <?php _e('Show smileys list',wordspew);?>: <input type="checkbox" name="Show_Smiley" <?php if(get_option('shoutbox_Smiley') == '1') echo 'checked="checked" '; ?>/>
  283. <p><?php _e('Check this if you want to show the smileys list',wordspew);?></p>
  284. <?php _e('Show blocked spams',wordspew);?>: <input type="checkbox" name="Show_Spam" <?php if(get_option('shoutbox_Show_Spam') == '1') echo 'checked="checked" '; ?>/>
  285. <p><?php _e('Check this if you want to show blocked spams',wordspew);?></p>
  286. <?php _e('Use a captcha',wordspew);?>: <input type="checkbox" name="Captcha" <?php if(get_option('shoutbox_Captcha') == '1') echo 'checked="checked" '; ?>/> <input type="text" name="hash"
  287. value="<?php echo get_option('shoutbox_hash'); ?>" size="30" /> <?php _e('Enter here your secret sentence',wordspew);?>
  288. <p><?php _e('Check this if you want to use a captcha (in fact it\'s a simple addition that users have to resolve before post any new message in the shoutbox).',wordspew);?></p>
  289. <?php _e('Hide users list',wordspew);?>: <input type="checkbox" name="Hide_Users" <?php if(get_option('shoutbox_HideUsers') == '1') echo 'checked="checked" '; ?>/>
  290. <p><?php _e('Check this if you want to hide users list from document header in the javascript function. It permit to not expose your users list from a "view source".',wordspew);?></p>
  291. <?php _e('Only allow registered users',wordspew);?>: <input type="checkbox" name="registered_only" <?php if(get_option('shoutbox_registered_only') == '1') echo 'checked="checked" '; ?>/>
  292. <p><?php _e('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. <b>Note:</b> 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.',wordspew);?></p>
  293. </fieldset><br />
  294. <input type="submit" name="jal_admin_options" value="<?php _e('Save',wordspew);?>" class="button" style="font-size: 140%" /><br /><br />
  295. <input type="submit" name="jal_truncate" id="jal_truncate_all" onclick="return confirm('<?php _e("You are about to delete ALL messages in the shoutbox. It will completely erase all messages.\\nAre you sure you want to do this?\\n\'Cancel\' to stop, \'OK\' to delete.",wordspew); ?>');" value="<?php _e('Delete ALL messages',wordspew);?>" /><br /><br />
  296. </form>
  297. <fieldset>
  298. <legend><b><?php _e('Data',wordspew);?></b> <?php printf(__('(showing the last <b>%s</b> messages)',wordspew),$jal_number_of_comments);?></legend>
  299. <p><?php _e('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.',wordspew);?></p>
  300. <p><?php printf(__('<a href="%s"><b>Click here</b></a> to manage your banned words list and IP addresses.',wordspew),get_bloginfo('wpurl')."/wp-admin/options-discussion.php#moderation_keys");?></p>
  301. <p><?php _e('<b><font color="red">Important !</font></b> To ban a single IP address just click on "Ban this IP" button. If you want to ban a range of IP, use this syntax (for this example i can say good bye to Vsevolod Stetsinsky) : 195.225.176/179.* where slash means from 176 to 179 and * from 0 to 255.<br/>BTW i ban IP addresses from 195.225.176.0 to 195.225.179.255. You can mix the two options...',wordspew);?></p>
  302. <?php
  303. @mysql_query("SET CHARACTER SET 'utf8'");
  304. @mysql_query("SET NAMES utf8");
  305. $results = $wpdb->get_results("SELECT * FROM ".$jal_table_prefix."liveshoutbox ORDER BY id DESC LIMIT ". $jal_number_of_comments);
  306. $jal_first_time = "yes"; // Will only add the last message div if it is looping for the first time
  307. foreach( $results as $r ) { // Loops the messages into a list
  308. if($r->url!="") if (strpos($r->url, $Actual_URL)===false && $XHTML==0) $target=' target="_blank"';
  309. $url = (empty($r->url) && $r->url = "http://") ? '<span title="'.jal_time_since( $r->time ).'">'.$r->name.'</span>' : '<a href="'.$r->url.'"'.$target.' title="'.jal_time_since( $r->time ).'">'.$r->name.'</a>';
  310. if ($jal_first_time == "yes") {
  311. printf(__('<div id="lastMessage"><span>Last Message</span> <em id="responseTime">%s ago</em></div>',wordspew),jal_time_since($r->time));
  312. echo '<hr/><div align="right">
  313. <ul id="outputList">'; }
  314. echo '<li><form action="edit.php?page=wordspew" method="get"><span>'.stripslashes($url).' : </span>
  315. <a href="http://whois.domaintools.com/'.$r->ipaddr.'" target="_blank" title="Whois">*</a>
  316. <input type="text" name="jal_text" value="'.htmlspecialchars(stripslashes($r->text),ENT_QUOTES).'" size="60"/>
  317. <input type="hidden" name="page" value="wordspew"/>
  318. <input type="hidden" name="jal_comment_id" value="'.$r->id.'"/>
  319. <input type="text" name="ip" value="'.$r->ipaddr.'" size="16"/>
  320. <input type="submit" name="jal_ban" value="'.__("Ban this IP",wordspew).'"/>
  321. <input type="submit" name="jal_delete" value="'.__("Delete",wordspew).'"/>
  322. <input type="submit" name="jal_edit" value="'.__("Edit",wordspew).'"/></form></li>
  323. ';
  324. $jal_first_time = "0"; }
  325. ?>
  326. </ul></div>
  327. </fieldset>
  328. </div>
  329. <?php } }
  330. // To add administration page under Management Section
  331. function shoutbox_admin_page() {
  332. global $jal_admin_user_level;
  333. add_management_page('Shoutbox Management', 'Live Shoutbox', $jal_admin_user_level, "wordspew", 'jal_shoutbox_admin');
  334. }
  335. // Time Since function courtesy
  336. // http://blog.natbat.co.uk/archive/2003/Jun/14/jal_time_since
  337. // Works out the time since the entry post, takes a an argument in unix time (seconds)
  338. function jal_time_since($original) {
  339. // array of time period chunks
  340. $chunks = array(
  341. array(60 * 60 * 24 * 365 , __('year',wordspew),__('years',wordspew)),
  342. array(60 * 60 * 24 * 30 , __('month',wordspew),__('months',wordspew)),
  343. array(60 * 60 * 24 * 7, __('week',wordspew),__('weeks',wordspew)),
  344. array(60 * 60 * 24 , __('day',wordspew),__('days',wordspew)),
  345. array(60 * 60 , __('hour',wordspew),__('hours',wordspew)),
  346. array(60 , __('minute',wordspew),__('minutes',wordspew)),
  347. );
  348. $original = $original - 10; // Shaves a second, eliminates a bug where $time and $original match.
  349. $today = time(); /* Current unix time */
  350. $since = $today - $original;
  351. // $j saves performing the count function each time around the loop
  352. for ($i = 0, $j = count($chunks); $i < $j; $i++) {
  353. $seconds = $chunks[$i][0];
  354. $name = $chunks[$i][1];
  355. $name_s = $chunks[$i][2];
  356. // finding the biggest chunk (if the chunk fits, break)
  357. if (($count = floor($since / $seconds)) != 0) {
  358. break;
  359. }
  360. }
  361. $print = $count ." ".pluralize($count,$name,$name_s);
  362. if ($i + 1 < $j) {
  363. // now getting the second item
  364. $seconds2 = $chunks[$i + 1][0];
  365. $name2 = $chunks[$i + 1][1];
  366. $name2_s= $chunks[$i + 1][2];
  367. // add second item if it's greater than 0
  368. if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
  369. $print .= ", " .$count2." ".pluralize($count2,$name2,$name2_s);
  370. }
  371. }
  372. return $print;
  373. }
  374. if(!function_exists('pluralize')) :
  375. function pluralize($count, $singular, $plural = false) {
  376. if (!$plural) $plural = $singular . 's';
  377. return ($count < 2 ? $singular : $plural) ;
  378. }
  379. endif;
  380. ////////////////////////////////////////////////////////////
  381. // Functions Below are for getting comments from the database
  382. ////////////////////////////////////////////////////////////
  383. // Never cache this page
  384. if ($jalGetChat == "yes" || $jalSendChat == "yes") {
  385. header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  386. header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )."GMT" );
  387. header( "Cache-Control: no-cache, must-revalidate" );
  388. header( "Pragma: no-cache" );
  389. header("Content-Type: text/html; charset=utf-8");
  390. //if the request does not provide the id of the last know message the id is set to 0
  391. if (!$jal_lastID) $jal_lastID = 0;
  392. }
  393. // retrieves all messages with an id greater than $jal_lastID
  394. if ($jalGetChat == "yes") {
  395. jal_getData($jal_lastID);
  396. }
  397. // Where the shoutbox receives information
  398. function jal_getData ($jal_lastID) {
  399. global $jal_table_prefix;
  400. if(isset($_SESSION['spam_msg'])) {
  401. $loop =$jal_lastID."---SPAMMER---".$_SESSION['spam_msg'];
  402. $who=($_SESSION['Show_Users']==0) ? "" : jal_get_useronline_extended();
  403. echo $who."\n".$loop;
  404. unset($_SESSION['spam_msg']);
  405. }
  406. else {
  407. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  408. mysql_select_db(DB_NAME, $conn);
  409. @mysql_query("SET CHARACTER SET 'utf8'", $conn);
  410. @mysql_query("SET NAMES utf8", $conn);
  411. $sql = "SELECT * FROM ".$jal_table_prefix."liveshoutbox WHERE id > ".$jal_lastID." ORDER BY id DESC";
  412. $results = mysql_query($sql, $conn);
  413. $loop = "";
  414. while ($row = mysql_fetch_array($results)) {
  415. $id = $row[0];
  416. $time = $row[1];
  417. $name = $row[2];
  418. $text = $row[3];
  419. $url = $row[4];
  420. if(verifyName($name))
  421. $user=1;
  422. else
  423. $user=0;
  424. // append the new id's to the beginning of $loop --- is being used to separate the fields in the output
  425. $loop = $id."---".stripslashes($name)."---".stripslashes($text)."---".stripslashes($url)."---".$user."---" . $loop;
  426. }
  427. $who=($_SESSION['Show_Users']==0) ? "" : jal_get_useronline_extended();
  428. echo $who."\n".$loop;
  429. // if there's no new data, send one byte. Fixes a bug where safari gives up w/ no data
  430. if (empty($loop)) { echo "0"; }
  431. }
  432. }
  433. function jal_special_chars ($s) {
  434. $s = htmlspecialchars($s, ENT_COMPAT,'UTF-8');
  435. return str_replace("---","&minus;-&minus;",$s);
  436. }
  437. function check_ip_address($from, $checkip) {
  438. global $spam_msg;
  439. $checkip=trim($checkip);
  440. if(strpos($checkip,"*") || strpos($checkip,"/")) {
  441. $checkip =str_replace("*", "([0-9]{1,3})", $checkip);
  442. if(strpos($checkip,"/")) {
  443. $ar=explode(".",$checkip);
  444. for($i=0; $i<@count($ar); $i++) {
  445. $ar2=explode("/",$ar[$i]);
  446. if(@count($ar2)==2) {
  447. $ip="(";
  448. for($j=intval($ar2[0]); $j<intval($ar2[1]);$j++) {
  449. $ip.=$j."|";
  450. }
  451. $ip.=$ar2[1].")";
  452. $ar[$i]=eregi_replace("([0-9]{1,3})/([0-9]{1,3})", $ip, $ar[$i]);
  453. }
  454. }
  455. $checkip =$ar[0].".".$ar[1].".".$ar[2].".".$ar[3];
  456. }
  457. if (eregi($checkip, $from)) return false;
  458. }
  459. elseif($from==$checkip) return false;
  460. return true;
  461. }
  462. function CheckSpam($theText,$TheURL) {
  463. global $spam_msg, $jal_table_prefix, $ip;
  464. $count_http=substr_count($theText,"http");
  465. if($count_http>1) {
  466. $spam_msg=$_SESSION['HTTPLimit'];
  467. return false;
  468. }
  469. $count_content_type=substr_count($theText,"content-type");
  470. if($count_content_type>=1) {
  471. $spam_msg=$_SESSION['DLSpam'];
  472. return false;
  473. }
  474. $theText.=$TheURL;
  475. $ip = $_SERVER['REMOTE_ADDR'];
  476. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  477. mysql_select_db(DB_NAME, $conn);
  478. @mysql_query("SET CHARACTER SET 'utf8'", $conn);
  479. @mysql_query("SET NAMES utf8", $conn);
  480. $spam=array();
  481. $SQL="SELECT option_value FROM ".$jal_table_prefix."options WHERE option_name = 'moderation_keys'";
  482. $spam=mysql_query($SQL,$conn);
  483. $sql_create_arr = mysql_fetch_array($spam);
  484. $spam= $sql_create_arr[0];
  485. $spam=explode("\r\n",strtolower($spam));
  486. if($spam[0]!="") {
  487. for($i=0;$i<@count($spam);$i++) {
  488. $str=$spam[$i];
  489. if (strlen($str)>8 && intval($str)) {
  490. if(!check_ip_address($ip, $str)) {
  491. $spam_msg=$_SESSION['IPLogged'];
  492. return false;
  493. break;
  494. }
  495. }
  496. $pos=strpos($theText,$str);
  497. if(is_int($pos)) {
  498. $spam_msg=$_SESSION['DLSpam'];
  499. return false;
  500. break;
  501. }
  502. }
  503. }
  504. return true;
  505. }
  506. //////////////////////////////////////////////////////
  507. // Functions Below are for submitting comments to the database
  508. //////////////////////////////////////////////////////
  509. // When user submits and javascript fails
  510. if (isset($_POST['shout_no_js'])) {
  511. $myURL = isset($_POST['shoutboxU']) ? $_POST['shoutboxU'] : "";
  512. if ($_POST['shoutboxname'] != '' && $_POST['chatbarText'] != '')
  513. jal_addData($_POST['shoutboxname'], $_POST['chatbarText'], $myURL);
  514. else echo "You must have a name and a comment...";
  515. }
  516. //only if a name and a message have been provides the information is added to the db
  517. if ($jal_user_name != '' && $jal_user_text != '' && $jalSendChat == "yes") {
  518. jal_addData($jal_user_name,$jal_user_text,$jal_user_url); //adds new data to the database
  519. echo "0";
  520. }
  521. function mySplit ($captures){
  522. // si url ou email, on passe...
  523. 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])) {
  524. $return = $captures[0];
  525. }
  526. else {
  527. $splited = preg_replace("/([^\s]{".split."})/iu","$1 ",$captures[0]);
  528. $return = trim($splited);
  529. }
  530. return $return;
  531. }
  532. function jal_addData($jal_user_name,$jal_user_text,$jal_user_url) {
  533. global $spam_msg, $jal_table_prefix, $jal_user_val, $jal_user_calc, $jal_user_Control, $ip;
  534. $SearchText=strtolower(trim($jal_user_text));
  535. $SearchURL=strtolower(trim($jal_user_url));
  536. //replacement of non-breaking spaces...
  537. $SearchName=str_replace(" "," ",$jal_user_name);
  538. $SearchName=trim($SearchName);
  539. $SearchName=strtolower($SearchName);
  540. $myBolean="";
  541. //if the BadCalc variable is not set then it's a bot (direct access to wordspew)
  542. if(!isset($_SESSION['BadCalc'])) {
  543. AddSpam("I DON'T LIKE SPAM !!!");
  544. exit;
  545. }
  546. if($SearchURL == "http://") $SearchURL="";
  547. if($SearchName==$SearchText || isset($_POST['shoutboxurl'])) {
  548. AddSpam($_SESSION['DLSpam']);
  549. exit;
  550. }
  551. $hashtext = $_SESSION['hashtext'];
  552. $jal_user_calc=md5($jal_user_calc.$hashtext);
  553. if($jal_user_calc!=$jal_user_Control) {
  554. AddSpam($_SESSION['BadCalc']);
  555. exit;
  556. }
  557. if(!isset($_SESSION['Logged']) && verifyName($SearchName)) {
  558. AddSpam($_SESSION['LoggedMsg']);
  559. exit;
  560. }
  561. if(CheckSpam($SearchText.' '.$SearchName, $SearchURL)) {
  562. setcookie("jalUserName",$jal_user_name,time()+60*60*24*30*3,'/');
  563. //the message is cut of after 500 letters
  564. $jal_user_text = trim(substr($jal_user_text,0,500));
  565. // masque pour capturer toute chaîne de plus de $split car.
  566. $pattern = '#[^ ]{'.split.',}#u';
  567. // appel à une fonction callback de remplacement (*beaucoup* plus rapide que preg_replace() option e)
  568. $jal_user_text = preg_replace_callback($pattern, 'mySplit', $jal_user_text);
  569. $jal_user_text=jal_special_chars($jal_user_text);
  570. $jal_user_name = substr(trim($jal_user_name), 0,18);
  571. $jal_user_name=jal_special_chars($jal_user_name);
  572. $jal_user_url = ($jal_user_url == "http://") ? "" : jal_special_chars($jal_user_url);
  573. if (substr($jal_user_url,0,3)=="www") $jal_user_url ="http://".$jal_user_url;
  574. if (strpos($jal_user_url,"@")!=false) $jal_user_url ="mailto:".$jal_user_url;
  575. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  576. mysql_select_db(DB_NAME, $conn);
  577. @mysql_query("SET CHARACTER SET 'utf8'", $conn);
  578. @mysql_query("SET NAMES utf8", $conn);
  579. if($jal_user_url!="") {
  580. setcookie("jalUrl",str_replace("mailto:","",$jal_user_url),time()+60*60*24*30*3,'/');
  581. if($_SESSION['useURL']=="") $myBolean="false";
  582. }
  583. if($myBolean=="") {
  584. if($_SESSION['useCaptcha']=="1") setcookie("jalCaptcha","Ok",time()+60*60*24*30*3,'/');
  585. 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);
  586. jal_deleteOld(); //some database maintenance
  587. //take them right back where they left off
  588. header('location: '.$_SERVER['HTTP_REFERER']);
  589. }
  590. else {
  591. AddSpam($_SESSION['DLSpam']);
  592. }
  593. }
  594. else AddSpam($spam_msg);
  595. }
  596. function AddSpam($msg) {
  597. global $jal_table_prefix, $jalSendChat;
  598. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  599. mysql_select_db(DB_NAME, $conn);
  600. $SQL= mysql_query("SELECT option_value FROM ".$jal_table_prefix."options WHERE option_name='shoutbox_spam'");
  601. $nb= mysql_result($SQL, 0)+1;
  602. mysql_query("UPDATE ".$jal_table_prefix."options SET option_value='".$nb."' WHERE option_name='shoutbox_spam'",$conn);
  603. if($jalSendChat=="yes") {
  604. $_SESSION['spam_msg']= $msg;
  605. header('location: '.$_SERVER['HTTP_REFERER']);
  606. }
  607. else echo $msg;
  608. }
  609. //Maintains the database by deleting past comments
  610. function jal_deleteOld() {
  611. global $jal_table_prefix;
  612. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  613. mysql_select_db(DB_NAME, $conn);
  614. $SQL=mysql_query("SELECT option_value FROM ".$jal_table_prefix."options WHERE option_name = 'shoutbox_nb_comment'");
  615. $jal_number_of_comments=mysql_result($SQL,0);
  616. $results = mysql_query("SELECT * FROM ".$jal_table_prefix."liveshoutbox ORDER BY id DESC LIMIT ".$jal_number_of_comments, $conn);
  617. while ($row = mysql_fetch_array($results)) { $id = $row[0]; }
  618. if ($id) mysql_query("DELETE FROM ".$jal_table_prefix."liveshoutbox WHERE id < ".$id, $conn);
  619. }
  620. function sanitize_name($name) {
  621. $bad = array(" ", " ", "'", ".");
  622. $good= array("", "", "", "");
  623. return str_replace($bad, $good, $name);
  624. }
  625. function verifyName($name) {
  626. $ar=explode(",",$_SESSION['LoggedUsers']);
  627. if(in_array(strtolower($name), $ar)) return true;
  628. else return false;
  629. }
  630. // Prints the html structure for the shoutbox
  631. function jal_get_shoutbox () {
  632. global $wpdb, $jal_table_prefix, $user_level, $user_nickname, $user_url, $user_ID, $jal_admin_user_level, $user_identity;
  633. get_currentuserinfo(); // Gets logged in user.
  634. $theuser_nickname=$user_nickname;
  635. $ActualVersion=round(get_bloginfo('version'));
  636. if($ActualVersion>=2) $theuser_nickname=$user_identity;
  637. if(get_option('shoutbox_spam')=="") jal_install_shout();
  638. $XHTML=get_option('shoutbox_XHTML');
  639. $Captcha=get_option('shoutbox_Captcha');
  640. $jal_number_of_comments=get_option('shoutbox_nb_comment');
  641. $Actual_URL=get_bloginfo('wpurl');
  642. $_SESSION['Show_Users']=get_option('shoutbox_online');
  643. $_SESSION['BadCalc']=__("You should learn to count before use the shoutbox :)",wordspew);
  644. $_SESSION['DLSpam']=__("I DON'T LIKE SPAM !!!",wordspew);
  645. $_SESSION['HTTPLimit']=__("Sorry, but you can post only one url by message...",wordspew);
  646. $_SESSION['IPLogged']=__("Your IP address have been banned from this blog, if you feel this is in error please contact the webmaster.",wordspew);
  647. $_SESSION['hashtext']=get_option('shoutbox_hash');
  648. $_SESSION['useURL']=get_option('shoutbox_use_url');
  649. $_SESSION['useCaptcha']=get_option('shoutbox_Captcha');
  650. ?>
  651. <div id="wordspew">
  652. <div id="chatoutput">
  653. <?php
  654. @mysql_query("SET CHARACTER SET 'utf8'");
  655. @mysql_query("SET NAMES utf8");
  656. $wpdb->hide_errors();
  657. $results = $wpdb->get_results("SELECT * FROM ".$jal_table_prefix."liveshoutbox ORDER BY id DESC LIMIT ".$jal_number_of_comments);
  658. $wpdb->show_errors();
  659. // Will only add the last message div if it is looping for the first time
  660. $jal_first_time = true;
  661. $registered_only = (get_option('shoutbox_registered_only') == "1") ? TRUE : FALSE;
  662. // Loops the messages into a list
  663. foreach( $results as $r ) {
  664. $target="";
  665. // Add links
  666. if (strpos($r->text, $Actual_URL)===false && $XHTML==0) $target=' target="_blank"';
  667. $theLink=__("link",wordspew); $theMail=__("email",wordspew);
  668. $r->text = preg_replace("`(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"\\0\"$target>&laquo;$theLink&raquo;</a>", $r->text);
  669. $r->text = preg_replace("`([-_a-z0-9]+(\.[-_a-z0-9]+)*@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,6})`i","<a href=\"mailto:\\1\">&laquo;$theMail&raquo;</a>", $r->text);
  670. if ($jal_first_time == true) {
  671. $rand1=mt_rand(0,10);
  672. $rand2=mt_rand(0,10);
  673. $total=intval($rand1+$rand2);
  674. if (get_option('shoutbox_sound') == "1") {
  675. $img_sound=($_COOKIE['jalSound']==1 || $_COOKIE['jalSound']=="") ? "sound_1.gif" : "sound_0.gif";
  676. echo '<img src="'. $Actual_URL .'/wp-content/plugins/wordspew/'.$img_sound.'" alt=""
  677. onclick="setSound();" id="JalSound" title="';
  678. _e("Click this to turn on/off sound",wordspew);
  679. echo '"/>
  680. ';
  681. }
  682. if(get_option('shoutbox_Show_Spam')) {
  683. $nb = get_option('shoutbox_spam');
  684. printf(__('<div id="Show_Spam">%s spams blocked</div>',wordspew),$nb);
  685. }
  686. printf(__('<div id="lastMessage"><span>Last Message</span> <em id="responseTime">%s ago</em></div>',wordspew),jal_time_since($r->time));
  687. echo '<div id="usersOnline">'.jal_get_useronline_extended().'</div>';
  688. echo '<ul id="outputList">'; }
  689. if ($jal_first_time == true) $lastID = $r->id;
  690. $target="";
  691. if($r->url!="") if (strpos($r->url, $Actual_URL)===false && $XHTML==0) $target=' target="_blank"';
  692. $url = (empty($r->url) && $r->url = "http://") ? $r->name : '<a href="'.$r->url.'"'.$target.'>'.$r->name.'</a>';
  693. if($jal_first_time == true && !isset($_COOKIE['jalCaptcha']) && !$user_ID && !$registered_only && $_SESSION['useCaptcha'] == '1')
  694. echo '<li><span>'.__("Info",wordspew).' : </span><b>'.__("Please, resolve the addition below before post any new comment...",wordspew).'</b></li>';
  695. if(verifyName($r->name)) {
  696. $class="jal_user ";
  697. }
  698. echo '<li><span title="'.jal_time_since( $r->time ).'" class="'.$class. sanitize_name($r->name).'">'.stripslashes($url).' : </span>'.convert_smilies(" ".stripslashes($r->text)).'</li>
  699. ';
  700. $jal_first_time = false;
  701. $class="";
  702. }
  703. $use_url = (get_option('shoutbox_use_url') == "true") ? TRUE : FALSE;
  704. $use_textarea = (get_option('shoutbox_use_textarea') == "true") ? TRUE : FALSE;
  705. if (!defined("DB_CHARSET")) {
  706. @mysql_query("SET CHARACTER SET 'latin1'");
  707. @mysql_query("SET NAMES latin1");
  708. }
  709. ?>
  710. </ul>
  711. </div>
  712. <div id="chatInput">
  713. <?php
  714. $hashtext = $_SESSION['hashtext'];
  715. if (!$registered_only || ($registered_only && $user_ID)) {
  716. $display_name=($_COOKIE['jalUserName']) ? $_COOKIE['jalUserName'] : __("Guest_",wordspew).rand(0,5000);
  717. $display_name=str_replace("\'", "'", $display_name);
  718. ?>
  719. <form id="chatForm" method="post" action="<?php bloginfo('wpurl'); ?>/wp-content/plugins/wordspew/wordspew.php">
  720. <?php
  721. $current=current_user_can('level_'.$jal_admin_user_level);
  722. if ($user_level >= $jal_admin_user_level || $current==1) { // If user is allowed to use the admin page
  723. echo '<a href="'.get_bloginfo("wpurl").'/wp-admin/edit.php?page=wordspew" id="shoutboxAdmin">'. __("Admin",wordspew).'</a>';
  724. }
  725. if (!empty($theuser_nickname)) { /* If they are logged in, then print their nickname */
  726. $_SESSION['Logged']="ok"; ?>
  727. <input type="hidden" name="shoutboxControl" id="shoutboxControl" value="<?php echo md5($total.$hashtext); ?>"/>
  728. <input type="hidden" name="shoutboxOp" id="shoutboxOp" value="<?php echo $total; ?>"/>
  729. <label><?php _e('Name',wordspew); ?>: <em><?php echo $theuser_nickname ?></em></label>
  730. <input type="hidden" name="shoutboxname" id="shoutboxname" value="<?php echo $theuser_nickname; ?>"/>
  731. <input type="hidden" name="shoutboxU" id="shoutboxU" value="<?php if($use_url) { echo $user_url; } ?>"/>
  732. <?php } else { echo "\n"; /* Otherwise allow the user to pick their own name */ ?>
  733. <?php if ($Captcha==1) { ?>
  734. <input type="hidden" name="shoutboxControl" id="shoutboxControl" value="<?php echo md5($total.$hashtext); ?>"/>
  735. <div id="shoutbox_captcha">
  736. <label><?php _e('Captcha',wordspew); ?>:</label> <select name="shoutboxOp" id="shoutboxOp"
  737. onchange="MasqueSelect()" onclick="MasqueSelect()">
  738. <option value="-3"><?php echo $rand1."+".$rand2."="; ?></option>
  739. <?php for ($i = 0; $i < 21; $i++) {
  740. echo '<option value="'.$i.'">'.$i.'</option>';
  741. }
  742. echo '</select></div>';
  743. }
  744. else { ?>
  745. <input type="hidden" name="shoutboxControl" id="shoutboxControl" value="<?php echo md5($total.$hashtext); ?>"/>
  746. <input type="hidden" name="shoutboxOp" id="shoutboxOp" value="<?php echo $total; ?>"/>
  747. <? } ?>
  748. <label for="shoutboxname"><?php _e('Name',wordspew); ?>:</label>
  749. <input type="text" name="shoutboxname" id="shoutboxname" value="<?php echo $display_name; ?>" maxlength="18"/>
  750. <label for="shoutboxU"<?php if (!$use_url) echo ' style="display: none"'; ?>><?php _e('URL/Email',wordspew); ?>:</label>
  751. <input type="text" name="shoutboxU" id="shoutboxU" value="<?php if ($_COOKIE['jalUrl'] && $use_url) echo $_COOKIE['jalUrl']; else echo 'http://'; ?>"<?php if (!$use_url) echo ' style="display: none"'; ?>/>
  752. <?php } echo "\n"; ?>
  753. <label for="chatbarText"><?php _e('Message',wordspew) ?>:</label>
  754. <?php if ($use_textarea) { ?>
  755. <textarea rows="4" cols="16" name="chatbarText" id="chatbarText" onkeypress="return pressedEnter(this,event);"></textarea>
  756. <?php } else { ?>
  757. <input type="text" name="chatbarText" id="chatbarText"/>
  758. <?php } ?>
  759. <input type="hidden" id="jal_lastID" value="<?php echo $lastID + 1; ?>" name="jal_lastID"/>
  760. <input type="hidden" name="shout_no_js" value="true"/>
  761. <div id="SmileyList"></div>
  762. <input type="submit" id="submitchat" name="submit" value="<?php _e('Send',wordspew);?>"/>
  763. </form>
  764. <?php }
  765. else { ?>
  766. <form id="chatForm" action="">
  767. <p align="center"><?php _e('You must be a registered user to participate in this chat',wordspew); ?></p>
  768. <input type="hidden" name="shoutboxControl" id="shoutboxControl" value="<?php echo md5($total.$hashtext); ?>"/>
  769. <input type="hidden" name="shoutboxOp" id="shoutboxOp" value="<?php echo $total; ?>"/>
  770. <input type="hidden" id="shoutboxname"/>
  771. <input type="hidden" id="shoutboxU"/>
  772. <input type="hidden" id="chatbarText"/>
  773. <input type="hidden" id="jal_lastID" value="<?php echo $lastID+1; ?>"/>
  774. <input type="submit" id="submitchat" name="submit" style="display:none;"/>
  775. </form>
  776. <?php } ?>
  777. </div>
  778. </div>
  779. <?php if (get_option('shoutbox_sound') == "1") echo('<span id="TheBox"></span>'); }
  780. /* Widget */
  781. if (function_exists("add_action")) {
  782. include_once ('widgetized.php');
  783. add_action("plugins_loaded","jal_on_plugins_loaded");
  784. }
  785. /* End Widget */
  786. function jal_admin_options() {
  787. global $wpdb, $jal_table_prefix, $user_level, $jal_admin_user_level;
  788. // Security
  789. get_currentuserinfo();
  790. $current=current_user_can('level_'.$jal_admin_user_level);
  791. if ($user_level < $jal_admin_user_level && $current!=1) die(__("Cheatin' uh ?"));
  792. // Convert from milliseconds
  793. $fade_length = $_GET['fade_length'] * 1000;
  794. $update_seconds = $_GET['update_seconds'] * 1000;
  795. // Update choices from admin panel
  796. update_option('shoutbox_fade_from', $_GET['fade_from']);
  797. update_option('shoutbox_fade_to', $_GET['fade_to']);
  798. update_option('shoutbox_update_seconds', $update_seconds);
  799. update_option('shoutbox_fade_length', $fade_length);
  800. update_option('shoutbox_text_color', $_GET['text_color']);
  801. update_option('shoutbox_name_color', $_GET['name_color']);
  802. $use_url = ($_GET['use_url']) ? "true" : "";
  803. $use_textarea = ($_GET['use_textarea']) ? "true" : "";
  804. $registered_only = ($_GET['registered_only']) ? "1" : "0";
  805. $use_sound = ($_GET['use_sound']) ? "1" : "0";
  806. $XHTML=($_GET['XHTML']) ? "1" : "0";
  807. $Online=($_GET['Show_Users']) ? "1" : "0";
  808. $Smiley=($_GET['Show_Smiley']) ? "1" : "0";
  809. $Show_Spam=($_GET['Show_Spam']) ? "1" : "0";
  810. $Captcha=($_GET['Captcha']) ? "1" : "0";
  811. $hash=($_GET['hash']!="") ? $_GET['hash'] : __("Your secret sentence",wordspew)."_".mt_rand(0,5000);
  812. $HideUsers=($_GET['Hide_Users']) ? "1" : "0";
  813. if(!is_numeric($_GET['nb_comment']))
  814. $nb_comment=35;
  815. else
  816. $nb_comment=intval($_GET['nb_comment']);
  817. update_option('shoutbox_use_url', $use_url);
  818. update_option('shoutbox_use_textarea', $use_textarea);
  819. update_option('shoutbox_registered_only', $registered_only);
  820. update_option('shoutbox_sound', $use_sound);
  821. update_option('shoutbox_XHTML', $XHTML);
  822. update_option('shoutbox_online', $Online);
  823. update_option('shoutbox_Smiley', $Smiley);
  824. update_option('shoutbox_Show_Spam', $Show_Spam);
  825. update_option('shoutbox_nb_comment', $nb_comment);
  826. update_option('shoutbox_Captcha', $Captcha);
  827. update_option('shoutbox_hash', $hash);
  828. update_option('shoutbox_HideUsers', $HideUsers);
  829. }
  830. function jal_shout_edit() {
  831. global $wpdb, $jal_table_prefix, $user_level, $jal_admin_user_level;
  832. // Security
  833. get_currentuserinfo();
  834. $current=current_user_can('level_'.$jal_admin_user_level);
  835. if ($user_level < $jal_admin_user_level && $current!=1) die(__("Cheatin' uh ?"));
  836. @mysql_query("SET CHARACTER SET 'utf8'");
  837. @mysql_query("SET NAMES utf8");
  838. $wpdb->query("UPDATE ".$jal_table_prefix."liveshoutbox SET text = '".$wpdb->escape($_GET['jal_text'])."',ipaddr='".trim($_GET['ip'])."' WHERE id = ".$wpdb->escape($_GET['jal_comment_id']));
  839. }
  840. function jal_shout_delete() {
  841. global $wpdb, $jal_table_prefix, $user_level, $jal_admin_user_level;
  842. // Security
  843. get_currentuserinfo();
  844. $current=current_user_can('level_'.$jal_admin_user_level);
  845. if ($user_level < $jal_admin_user_level && $current!=1) die(__("Cheatin' uh ?"));
  846. $results = count($wpdb->get_results("SELECT * FROM ".$jal_table_prefix."liveshoutbox"));
  847. if(1==$results) jal_shout_truncate();
  848. else {
  849. if($_GET['jal_comment_id']) {
  850. $wpdb->query("DELETE FROM ".$jal_table_prefix."liveshoutbox WHERE id = ".$wpdb->escape($_GET['jal_comment_id']));
  851. }
  852. }
  853. }
  854. function jal_shout_truncate() {
  855. global $wpdb, $jal_table_prefix, $user_level, $jal_admin_user_level;
  856. // Security
  857. get_currentuserinfo();
  858. $current=current_user_can('level_'.$jal_admin_user_level);
  859. if ($user_level < $jal_admin_user_level && $current!=1) die(__("Cheatin' uh ?"));
  860. $wpdb->query("TRUNCATE TABLE ".$jal_table_prefix."liveshoutbox");
  861. $welcome_name = "Pierre";
  862. $welcome_text = __('Your shoutbox is blank. Add a message!',wordspew);
  863. $wpdb->query("INSERT INTO ".$jal_table_prefix."liveshoutbox (time,name,text) VALUES ('".time()."','".$welcome_name."','".$welcome_text."')");
  864. }
  865. function jal_shout_spam() {
  866. global $user_level, $jal_admin_user_level, $ip;
  867. $ip=trim($_GET['ip']);
  868. $pos=0;
  869. get_currentuserinfo();
  870. $current=current_user_can('level_'.$jal_admin_user_level);
  871. if ($user_level < $jal_admin_user_level && $current!=1) die(__("Cheatin' uh ?"));
  872. $spam=get_option('moderation_keys');
  873. $ar=explode("\r\n",$spam);
  874. if(!in_array($ip, $ar)) update_option('moderation_keys', $ip."\r\n".$spam);
  875. jal_shout_delete();
  876. }
  877. // If user has updated the admin panel
  878. if (isset($_GET['jal_admin_options']))
  879. add_action('init', 'jal_admin_options');
  880. // If someone has deleted an entry through the admin panel
  881. if (isset($_GET['jal_delete']))
  882. add_action('init', 'jal_shout_delete');
  883. // If someone has edited an entry through the admin panel
  884. if (isset($_GET['jal_edit']))
  885. add_action('init', 'jal_shout_edit');
  886. // If someone has clicked the "delete all" button
  887. if (isset($_GET['jal_truncate']))
  888. add_action('init', 'jal_shout_truncate');
  889. // If it's a spam
  890. if (isset($_GET['jal_ban']))
  891. add_action('init', 'jal_shout_spam');
  892. // Print to the <script> and <link> (for css) to the head of the document
  893. // And adds the admin menu
  894. if (function_exists('add_action')) {
  895. if(function_exists('load_plugin_textdomain')) load_plugin_textdomain(wordspew);
  896. add_action('wp_head', 'jal_add_to_head');
  897. add_action('admin_menu', 'shoutbox_admin_page');
  898. if (strstr($_SERVER['REQUEST_URI'], 'wordspew'))
  899. add_action('admin_head', 'jal_add_to_admin_head');
  900. }
  901. /* useronline code */
  902. function jal_get_IP() {
  903. if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
  904. $ip_address = $_SERVER["REMOTE_ADDR"];
  905. } else {
  906. $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
  907. }
  908. if(strpos($ip_address, ',') !== false) {
  909. $ip_address = explode(',', $ip_address);
  910. $ip_address = $ip_address[0];
  911. }
  912. return $ip_address;
  913. }
  914. function jal_get_useronline_engine($usertimeout = 60) {
  915. global $jal_table_prefix;
  916. $tableuseronline = $jal_table_prefix.'liveshoutbox_useronline';
  917. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  918. mysql_select_db(DB_NAME, $conn);
  919. @mysql_query("SET CHARACTER SET 'utf8'", $conn);
  920. @mysql_query("SET NAMES utf8", $conn);
  921. // Search Bots
  922. $bots = array('Google' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
  923. // Useronline Settings
  924. $timeoutseconds = $usertimeout;
  925. $timestamp = time();
  926. $timeout = $timestamp-$timeoutseconds;
  927. $sql = "SELECT option_value from {$jal_table_prefix}options where option_name = 'siteurl'";
  928. $result = mysql_query($sql,$conn);
  929. while($element = mysql_fetch_array($result)) $siteurl = $element["option_value"];
  930. // Check Members
  931. if(isset($_COOKIE['jalUserName']) && (strtolower(substr($_COOKIE['jalUserName'],0,4)) != strtolower(substr(trim($_SESSION['guest']),0,4)))) {
  932. $memberonline = mysql_real_escape_string(str_replace("\'", "'", $_COOKIE['jalUserName']));
  933. $where = "WHERE username='".$memberonline."'";
  934. } else { // guestify the user
  935. $memberonline = 'guest';
  936. $where = "WHERE ip='".jal_get_IP()."'";
  937. }
  938. // Check For Bot
  939. foreach ($bots as $name => $lookfor) {
  940. if (stristr($_SERVER['HTTP_USER_AGENT'], $lookfor) !== false) {
  941. $memberonline = mysql_real_escape_string($name);
  942. $where = "WHERE ip='".jal_get_IP()."'";
  943. }
  944. }
  945. $make_page = "(unknown page title)";
  946. $visitinguri = $_SERVER['REQUEST_URI'];
  947. if (str_replace("/wordspew.php","",$_SERVER['REQUEST_URI']) != $_SERVER['REQUEST_URI'])
  948. $visitinguri = null;
  949. $s = ""; foreach ($_COOKIE as $key=>$val) { $s.="[$key]='$val' --- "; }
  950. $s = "Live chat: username detected: '" . $memberonline . "' --- cookie: " .$s;
  951. mysql_query("LOCK TABLES $tableuseronline WRITE", $conn);
  952. if ($visitinguri != null)
  953. mysql_query("UPDATE $tableuseronline SET timestamp = '$timestamp', ip = '".jal_get_IP()."', location = '".mysql_real_escape_string($make_page)."', url = '".mysql_real_escape_string($visitinguri)."' $where", $conn);
  954. else
  955. mysql_query("UPDATE $tableuseronline SET timestamp = '$timestamp', ip = '".jal_get_IP()."' $where", $conn);
  956. // If No User Insert It
  957. if (mysql_affected_rows($conn) == 0) {
  958. if ($visitinguri != null)
  959. mysql_query("INSERT INTO $tableuseronline VALUES ('$timestamp', '$memberonline', '".jal_get_IP()."', '".mysql_real_escape_string($make_page)."', '".mysql_real_esca

Large files files are truncated, but you can click here to view the full file