(New page: This is the code of the BoWoB chat plugin for Wordpress. The initial posting is the original code of [http://wordpress.org/extend/plugins/bowob/ BoWoB v3.0]. Changes made will be visible i...)
 
m (Bot: Adding {{catneeded}} tag to uncategorized pages)
Line 794: Line 794:
?>
?>
</pre>
</pre>
{{catneeded}}

Revision as of 14:48, 18 December 2009

This is the code of the BoWoB chat plugin for Wordpress. The initial posting is the original code of BoWoB v3.0. Changes made will be visible in the history page.

<?php

/*
Plugin Name: BoWoB
Version: 3.0
Plugin URI: http://www.bowob.com/wordpress/
Description: Free Chat for your website, integrated with your system users and design
Author: Jonatan Linares
Author URI: http://www.bowob.com
*/

$path = dirname(__FILE__) . "/bowob_config.php";

global $bowob_chat_id, $bowob_chat_onlyreg, $bowob_chat_name;
global $bowob_icones, $bowob_icones_path, $bowob_icones_button_path, $bowob_colours, $bowob_language_object, $bowob_language, $bowob_sounds_path, $bowob_sounds_volume, $bowob_format_bold, $bowob_format_underline, $bowob_format_italic, $bowob_format_colours, $bowob_format_icones;

if(file_exists($path)){
  require($path);
}
else{
  $bowob_chat_id = array();
  $bowob_chat_onlyreg = array();
  $bowob_chat_name = array();
}

function bowob_link(){
  echo "<li><h2>" . __('Chat') . "</h2>\n";
  bowob_link_rooms();
  echo "</li>\n";
}

function bowob_link_rooms(){
  bowob_config();
  global $bowob_chat_id, $bowob_chat_name, $page_info, $page_perma;

  echo "<ul>\n";

  if(sizeof($bowob_chat_id) == 1){
    echo "<li><a href=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/1" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=1")."\" title=\"".__('Chat')."\">".__('Chat')."</a></li>\n";
  }
  else{
    for($bowob_i = 0; $bowob_i < sizeof($bowob_chat_id); $bowob_i++){
      echo "<li><a href=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".($bowob_i + 1) : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".($bowob_i + 1))."\" title=\"".$bowob_chat_name[$bowob_i]."\">".$bowob_chat_name[$bowob_i]."</a></li>\n";
    }
  }

  echo "</ul>\n";
}

function bowob_login(){
  echo "<li><h2>" . __('Chat') . "</h2>\n";
  bowob_login_rooms();
  echo "</li>\n";
}

function bowob_login_rooms(){
  bowob_config();
  global $bowob_chat_id, $bowob_chat_onlyreg, $bowob_chat_name, $page_info, $page_perma;

  $rooms_all = 0;
  $rooms_reg = 0;
  for($i = 0; $i < sizeof($bowob_chat_id); $i++){
    if($bowob_chat_onlyreg[$i]){
      $rooms_reg++;
    }
    else{
      $rooms_all++;
    }
  }

  if($rooms_all){
    $bowob_username = "";

    $user = wp_get_current_user();
    if($user->ID){
      $bowob_username = $user->user_login;
    }

    if($rooms_all == 1){
      for($i = 0; $i < sizeof($bowob_chat_id); $i++){
        if(!$bowob_chat_onlyreg[$i]){
          if(sizeof($bowob_chat_id) > 1){
            echo "<ul><li>".$bowob_chat_name[$i]."\n";
          }
          echo "<form name=\"bowob_login\" id=\"bowob_login\" action=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".($i + 1)."/1" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".($i + 1)."&bowob_step=1")."\" method=\"post\">";

          break;
        }
      }

      if(sizeof($bowob_chat_id) == 1){
        echo "<ul><li>";
      }
      echo "<label>";
      _e('Username:');
    	echo "<br><input type=\"text\" name=\"user_login\" class=\"input\" value=\"".$bowob_username."\" size=\"15\" /></label>\n";
    	echo "<br><input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" value=\"" . __('Chat') . "\" /></li></ul>\n";
    }
    else{
      echo "<form name=\"bowob_login\" id=\"bowob_login\" action=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/1/1" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=1&bowob_step=1")."\" method=\"post\">";
      echo "<ul><li>";

      $checked = false;
      for($i = 0; $i < sizeof($bowob_chat_id); $i++){
        if(!$bowob_chat_onlyreg[$i]){
          echo "<label><input name=\"room\" value=\"".$i."\" type=\"radio\"";
          if(!$checked){
            echo " checked=\"checked\"";
            $checked = true;
          }
          echo "> ".$bowob_chat_name[$i]."</label><br>\n";
        }
      }

      $submit_js = "for(var i = 0; i < document.getElementById('bowob_login').room.length; i++){";
    	$submit_js .= "   if(document.getElementById('bowob_login').room[i].checked){";
    	if($page_perma){
        $submit_js .= "      document.getElementById('bowob_login').action = '".get_bloginfo('url')."/".$page_info["post_name"]."/' + (parseInt(document.getElementById('bowob_login').room[i].value) + 1) + '/1'";
      }
      else{
        $submit_js .= "      document.getElementById('bowob_login').action = '".get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=' + (parseInt(document.getElementById('bowob_login').room[i].value) + 1) + '&bowob_step=1'";
      }
    	$submit_js .= "   }";
    	$submit_js .= "}";

    	echo "<label>";
      _e('Username:');
    	echo "<br><input type=\"text\" name=\"user_login\" class=\"input\" value=\"".$bowob_username."\" size=\"15\" /></label>\n";
    	echo "<br><input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" value=\"" . __('Chat') . "\" onclick=\"".$submit_js."\" /></li></ul>\n";
    }

    echo "</form>\n";
  }

  if($rooms_reg){
    if($rooms_all){
      echo "<br>\n";
    }

    echo "<ul>\n";
    for($i = 0; $i < sizeof($bowob_chat_id); $i++){
      if($bowob_chat_onlyreg[$i]){
        if(sizeof($bowob_chat_id) == 1){
          echo "<li><a href=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".($i + 1) : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".($i + 1))."\" title=\"".__('Chat')."\">".__('Chat')."</a></li>";
        }
        else{
          echo "<li><a href=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".($i + 1) : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".($i + 1))."\" title=\"".$bowob_chat_name[$i]."\">".$bowob_chat_name[$i]."</a></li>";
        }
      }
    }
    echo "</ul>\n";
  }

}

function widget_bowob_init(){

	if(!function_exists('register_sidebar_widget'))
		return;

	function widget_bowob_link($args){
    bowob_config();
    global $bowob_chat_id, $bowob_chat_name, $page_info, $page_perma;

    extract($args);
  	$options = get_option('widget_bowob_link');
  	$title = empty($options['title']) ? __('Chat') : $options['title'];

  	echo "  		".$before_widget."\n";
    echo "  			".$before_title.$title.$after_title."\n";
    bowob_link_rooms();
    echo "  		".$after_widget."\n";
  }

  function widget_bowob_link_control(){
    global $bowob_chat_id;
    global $bowob_chat_name;

    $options = $newoptions = get_option('widget_bowob_link');
  	if($_POST["bowob_link-submit"]){
  		$newoptions['title'] = strip_tags(stripslashes($_POST["bowob_link-title"]));
  	}
  	if($options != $newoptions){
  		$options = $newoptions;
  		update_option('widget_bowob_link', $options);
  	}
  	$title = attribute_escape($options['title']);

    echo "  			<p><label for=\"bowob_link-title\">"._e('Title:')."<input style=\"width: 250px;\" id=\"bowob_link-title\" name=\"bowob_link-title\" type=\"text\" value=\"".$title."\" /></label></p>";
    echo "  			<input type=\"hidden\" id=\"bowob_link-submit\" name=\"bowob_link-submit\" value=\"1\" />";
  }

  function widget_bowob_login($args){
    bowob_config();
    global $bowob_chat_id, $bowob_chat_name, $page_info, $page_perma;

    extract($args);
  	$options = get_option('widget_bowob_login');
  	$title = empty($options['title']) ? __('Chat') : $options['title'];

  	echo "  		".$before_widget."\n";
    echo "  			".$before_title.$title.$after_title."\n";
    bowob_login_rooms();
    echo "  		".$after_widget."\n";
  }

  function widget_bowob_login_control(){
    global $bowob_chat_id;
    global $bowob_chat_name;

    $options = $newoptions = get_option('widget_bowob_login');
  	if($_POST["bowob_login-submit"]){
  		$newoptions['title'] = strip_tags(stripslashes($_POST["bowob_login-title"]));
  	}
  	if($options != $newoptions){
  		$options = $newoptions;
  		update_option('widget_bowob_login', $options);
  	}
  	$title = attribute_escape($options['title']);

    echo "  			<p><label for=\"bowob_login-title\">"._e('Title:')."<input style=\"width: 250px;\" id=\"bowob_login-title\" name=\"bowob_login-title\" type=\"text\" value=\"".$title."\" /></label></p>";
    echo "  			<input type=\"hidden\" id=\"bowob_login-submit\" name=\"bowob_login-submit\" value=\"1\" />";
  }

	register_sidebar_widget(array('BoWoB Link', 'widgets'), 'widget_bowob_link');
	register_widget_control(array('BoWoB Link', 'widgets'), 'widget_bowob_link_control', 300, 280);
	register_sidebar_widget(array('BoWoB Login', 'widgets'), 'widget_bowob_login');
	register_widget_control(array('BoWoB Login', 'widgets'), 'widget_bowob_login_control', 300, 280);
}

function bowob_content($content){
	if(eregi("\[\[BOWOB\]\]", $content)){
		bowob_page();

		return "";
	}
  else{
    return $content;
	}
}

function bowob_activate(){
  global $wp_rewrite;
  $wp_rewrite->flush_rules();
}

function bowob_deactivate(){
  global $wpdb, $table_prefix;

  $wpdb->query("DROP TABLE IF EXISTS {$table_prefix}bowob");
  $wpdb->query("DELETE FROM {$table_prefix}posts WHERE post_name = 'bowob'");
}

function bowob_query_vars($vars){
   $vars[] = "bowob_id";
   $vars[] = "bowob_step";

   return $vars;
}

function bowob_rewrite_rules($wp_rewrite){
	global $wp_rewrite;

	$xdforum_rules = array(
		'bowob/([^/\(\)]*)/?([^/\(\)]*)' => '/bowob/index.php?pagename=bowob&bowob_id=$matches[1]&bowob_step=$matches[2]'
	);

	$wp_rewrite->rules = $xdforum_rules + $wp_rewrite->rules;
}

function bowob_header(){
  if(is_page("bowob")){

    bowob_config();
    global $bowob_chat_id, $bowob_chat_onlyreg, $bowob_chat_name, $page_info, $page_perma;

    $current = get_option('active_plugins');
  	if(!in_array('bowob/bowob.php', $current)){
      exit();
    }

    $rooms_all = 0;
    $rooms_reg = 0;
    for($i = 0; $i < sizeof($bowob_chat_id); $i++){
      if($bowob_chat_onlyreg[$i]){
        $rooms_reg++;
      }
      else{
        $rooms_all++;
      }
    }

    if(!$rooms_all){
      if(!$rooms_reg){
        wp_redirect(get_bloginfo('url')."/index.php");
      }
      else if($rooms_reg == 1){
        if(get_query_var("bowob_id") == NULL){
          wp_redirect(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/1" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=1");
        }
      }
    }

    if($bowob_chat_onlyreg[get_query_var("bowob_id") - 1]){ // Only reg users

      $user = wp_get_current_user();

      if(!$user->ID){  // Logued
        wp_redirect(get_bloginfo('url')."/wp-login.php");
        exit();
      }

    }
    else{ // All users

      require_once(ABSPATH.WPINC.'/registration.php');

      if(get_query_var("bowob_step") == "1"){

        if(@$_POST["user_login"] == ""){
          wp_redirect(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".get_query_var("bowob_id")."/2" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".get_query_var("bowob_id")."&bowob_step=2");
          exit();
        }

        $_POST["user_login"] = sanitize_user($_POST["user_login"]);

        if(!validate_username($_POST["user_login"])){
          wp_redirect(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".get_query_var("bowob_id")."/3" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".get_query_var("bowob_id")."&bowob_step=3");
          exit();
        }

        $user = wp_get_current_user();

        if($user->ID){  // Logued
          if(strtolower($_POST["user_login"]) != strtolower($user->user_login)){
            if(username_exists($_POST["user_login"])){  // Taken
              wp_redirect(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".get_query_var("bowob_id")."/4" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".get_query_var("bowob_id")."&bowob_step=4");
              exit();
            }
          }
        }
        else{ // Guest
          if(username_exists($_POST["user_login"])){  // Taken
            wp_redirect(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".get_query_var("bowob_id")."/4" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".get_query_var("bowob_id")."&bowob_step=4");
            exit();
          }
        }

      }
      else{

        $bowob_username = "";

        $user = wp_get_current_user();
        if($user->ID){
          $bowob_username = $user->user_login;
        }

        if(get_query_var("bowob_step") == 2){
          $errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');
        }
        elseif(get_query_var("bowob_step") == 3){
          $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.');
        }
        elseif(get_query_var("bowob_step") == 4){
          $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
          $errors['user_login'] .= '<br><a href="'.get_bloginfo('url').'/wp-login.php">'.__('Login').'</a>';
        }

    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head>
	<title><?php bloginfo('name'); ?> › <?php echo $title; ?></title>
	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
	<?php
	wp_admin_css( 'login', true );
	wp_admin_css( 'colors-fresh', true );
	?>
	<script type="text/javascript">
		function focusit() {
			document.getElementById('user_login').focus();
		}
		window.onload = focusit;
	</script>
</head>
<body class="login">

    <div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://wordpress.org/'); ?>" title="<?php echo apply_filters('login_headertitle', __('Powered by WordPress')); ?>"><?php bloginfo('name'); ?></a></h1>
    <?php
        echo apply_filters('login_message', '<p class="message register">' . __('Chat') . '</p>') . "\n";

        // Incase a plugin uses $error rather than the $errors array
        if ( !empty( $error ) ) {
        	$errors['error'] = $error;
        	unset($error);
        }

        if ( !empty( $errors ) ) {
        	if ( is_array( $errors ) ) {
        		$newerrors = "\n";
        		foreach ( $errors as $error ) $newerrors .= '	' . $error . "<br />\n";
        		$errors = $newerrors;
        	}

         echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div><br>\n";
        }

      echo "<form name=\"bowob\" id=\"bowob\" action=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/1/1" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=1&bowob_step=1")."\" method=\"post\">";

      if($rooms_all){
        if($rooms_all == 1){
          for($i = 0; $i < sizeof($bowob_chat_id); $i++){
            if(!$bowob_chat_onlyreg[$i]){
              if(sizeof($bowob_chat_id) > 1){
                echo $bowob_chat_name[$i]."\n";
              }

              break;
            }
          }

          echo "<br><br><p>\n";
        	echo "	<label>";
          _e('Username:');
          echo "<br />\n";
        	echo "	<input type=\"text\" name=\"user_login\" id=\"user_login\" class=\"input\" value=\"".$bowob_username."\" size=\"20\" tabindex=\"10\" /></label>\n";
        	echo "</p>\n";
        	echo "<p class=\"submit\">\n";
        	echo "	<input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" value=\"" . __('Chat') . "\" tabindex=\"100\" onclick=\"document.getElementById('bowob').action = '".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".($i + 1)."/1" : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".($i + 1)."&bowob_step=1")."';\" />\n";
        	echo "</p><br>\n";
        }
        else{

          $checked = false;
          for($i = 0; $i < sizeof($bowob_chat_id); $i++){
            if(!$bowob_chat_onlyreg[$i]){
              echo "<label><input name=\"room\" value=\"".$i."\" class=\"form-radio\" type=\"radio\"";
              if(get_query_var("bowob_id") == ($i + 1) || !$checked){
                echo " checked=\"checked\"";
                $checked = true;
              }
              echo "> ".$bowob_chat_name[$i]."</label><br>\n";
            }
          }

          $submit_js = "for(var i = 0; i < document.getElementById('bowob').room.length; i++){";
        	$submit_js .= "   if(document.getElementById('bowob').room[i].checked){";
        	if($page_perma){
            $submit_js .= "      document.getElementById('bowob').action = '".get_bloginfo('url')."/".$page_info["post_name"]."/' + (parseInt(document.getElementById('bowob').room[i].value) + 1) + '/1'";
          }
          else{
            $submit_js .= "      document.getElementById('bowob').action = '".get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=' + (parseInt(document.getElementById('bowob').room[i].value) + 1) + '&bowob_step=1'";
          }
        	$submit_js .= "   }";
        	$submit_js .= "}";

          echo "<br><br><p>\n";
        	echo "	<label>";
          _e('Username:');
          echo "<br />\n";
        	echo "	<input type=\"text\" name=\"user_login\" id=\"user_login\" class=\"input\" value=\"".$bowob_username."\" size=\"20\" tabindex=\"10\" /></label>\n";
        	echo "</p>\n";
        	echo "<p class=\"submit\">\n";
        	echo "	<input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" value=\"" . __('Chat') . "\" tabindex=\"100\" onclick=\"".$submit_js."\" />\n";
        	echo "</p><br>\n";
        }

      }

      for($i = 0; $i < sizeof($bowob_chat_id); $i++){
        if($bowob_chat_onlyreg[$i]){
          echo "<br><a href=\"".(($page_perma) ? get_bloginfo('url')."/".$page_info["post_name"]."/".($i + 1) : get_bloginfo('url')."/?page_id=".$page_info["ID"]."&bowob_id=".($i + 1))."\" title=\"".$bowob_chat_name[$i]."\">".$bowob_chat_name[$i]."</a>";
        }
      }
?>

</form>

<p id="nav">
<?php wp_loginout(); ?>
<br>
<?php if (get_option('users_can_register')) : ?>
<a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=register"><?php _e('Register') ?></a> |
<a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a>
<?php else : ?>
<a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a>
<?php endif; ?>
<br><br><br>Plugin by <a href="http://www.bowob.com/" target="_blank">BoWoB Chat for Wordpress</a>
</p>

</div>
<p id="backtoblog"><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('« Back to %s'), get_bloginfo('title', 'display' )); ?></a></p>

</body>
</html>
    <?php
        exit();
      }

    }

  }
}

function bowob_footer(){
  echo "<br><center><span style=\"font-size: 10px\">Chat plugin by <a href=\"http://www.bowob.com/\" target=\"_blank\">BoWoB Chat for Wordpress</a></span></center>\n";
}

function bowob_page(){

  global $bowob_chat_id;
  global $bowob_chat_onlyreg;

  if($bowob_chat_onlyreg[get_query_var("bowob_id") - 1]){ // Only reg users

    $user = wp_get_current_user();

    if($user->ID){  // Logued
      //CHAT REG
      $bowob_data = bowob_synchronize(1, $bowob_chat_id[get_query_var("bowob_id") - 1], $user->user_login, 0);
      bowob_show_chat($bowob_chat_id[get_query_var("bowob_id") - 1], $bowob_data[0], $bowob_data[1]);
  		return;
    }

    return;

  }
  else{ // All users

    if(@$_POST["user_login"] == ""){
      return;
    }

    $_POST["user_login"] = sanitize_user($_POST["user_login"]);

    if(!validate_username($_POST["user_login"])){
      return;
    }

    $user = wp_get_current_user();

    if($user->ID){  // Logued
      if(strtolower($_POST["user_login"]) == strtolower($user->user_login)){
        //CHAT REG
        $bowob_data = bowob_synchronize(1, $bowob_chat_id[get_query_var("bowob_id") - 1], $user->user_login, 0);
        bowob_show_chat($bowob_chat_id[get_query_var("bowob_id") - 1], $bowob_data[0], $bowob_data[1]);
    		return;
      }
      else{
        if(username_exists($_POST["user_login"])){  // Taken
          return;
        }
        else{
          //CHAT GUEST
          $bowob_data = bowob_synchronize(1, $bowob_chat_id[get_query_var("bowob_id") - 1], $_POST["user_login"], 1);
          bowob_show_chat($bowob_chat_id[get_query_var("bowob_id") - 1], $bowob_data[0], $bowob_data[1]);
          return;
        }
      }
    }
    else{ // Guest
      if(username_exists($_POST["user_login"])){  // Taken
          return;
        }
        else{
          //CHAT GUEST
          $bowob_data = bowob_synchronize(1, $bowob_chat_id[get_query_var("bowob_id") - 1], $_POST["user_login"], 1);
          bowob_show_chat($bowob_chat_id[get_query_var("bowob_id") - 1], $bowob_data[0], $bowob_data[1]);
          return;
        }
    }

  }

}

function bowob_db_install(){
  global $wpdb, $table_prefix;

  $charset_collate = '';

  if(version_compare(mysql_get_server_info(), '4.1.0', '>=')){
    if(!empty($wpdb->charset)){
      $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
    }
  	if(!empty($wpdb->collate)){
      $charset_collate .= " COLLATE $wpdb->collate";
    }
  }

  $wpdb->query("CREATE TABLE IF NOT EXISTS {$table_prefix}bowob (
    bowob_id int(10) unsigned NOT NULL auto_increment,
    bowob_sync varchar(50) NOT NULL default '',
    bowob_time int(10) unsigned NOT NULL default '0',
    bowob_mode int(10) unsigned NOT NULL default '0',
    bowob_id_chat int(10) unsigned NOT NULL default '0',
    bowob_user varchar(50) NOT NULL default '',
    bowob_type int(10) unsigned NOT NULL default '0',
    PRIMARY KEY  (`bowob_id`)
  ) ".$charset_collate);
}

function bowob_synchronize($bowob_mode, $bowob_id_chat, $bowob_user, $bowob_type){
  $bowob_time = time();
  $bowob_pattern = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  $bowob_sync = "";
  for($bowob_i = 0; $bowob_i < 50; $bowob_i++){
    $bowob_sync .= $bowob_pattern[rand(0, 61)];
  }

  global $wpdb, $table_prefix;

  bowob_db_install();

  $wpdb->query($wpdb->prepare("INSERT INTO {$table_prefix}bowob (bowob_sync,bowob_time,bowob_mode,bowob_id_chat,bowob_user,bowob_type) VALUES (%s,%d,%d,%d,%s,%d)", $bowob_sync ,$bowob_time , $bowob_mode, $bowob_id_chat, $bowob_user, $bowob_type));

  $bowob_rs = $wpdb->get_results($wpdb->prepare("SELECT bowob_id,bowob_sync,bowob_user FROM {$table_prefix}bowob WHERE bowob_sync=%s AND bowob_time=%d AND bowob_mode=%d AND bowob_id_chat=%d AND bowob_user=%s AND bowob_type=%d", $bowob_sync, $bowob_time, $bowob_mode, $bowob_id_chat, $bowob_user, $bowob_type));

  for($i = 0; $i < sizeof($bowob_rs); $i++){
    if($bowob_rs[$i]->bowob_sync == $bowob_sync && $bowob_rs[$i]->bowob_user == $bowob_user){ // Upper Lower Case
      if($bowob_mode == 2){
        header("location: http://www.bowob.com/chat.php?type=5&id_chat=".$bowob_id_chat."&id=".$bowob_rs[$i]->bowob_id."&sync=".$bowob_sync);
        exit();
      }
      else{
        $bowob_data = array($bowob_rs[$i]->bowob_id, $bowob_sync);
        return $bowob_data;
      }
    }
  }

  echo "BoWoB: db error";
  exit();
}

if(@$_GET["type"] == 2){

  require_once('../../../wp-config.php');

  if(!@is_numeric(@$_GET["id"]) || @$_GET["sync"] == ""){
    echo "BoWoB: GET: no data received";
    exit();
  }

  global $wpdb, $table_prefix;

  bowob_db_install();

  $wpdb->query("DELETE FROM {$table_prefix}bowob WHERE bowob_time<".(time() - 300));

  $bowob_rs = $wpdb->get_results($wpdb->prepare("SELECT bowob_sync,bowob_mode,bowob_id_chat,bowob_user,bowob_type FROM {$table_prefix}bowob WHERE bowob_id=%d AND bowob_sync=%s", $_GET["id"], $_GET["sync"]));

  if(!$bowob_rs || $bowob_rs[0]->bowob_sync != $_GET["sync"]){
    echo "BoWoB: GET: bad data received";
    exit();
  }

  $wpdb->query("DELETE FROM {$table_prefix}bowob WHERE bowob_id=".$_GET["id"]);

  header('Cache-Control: no-cache');
  header('Content-Type: text/html; charset=utf-8');

  echo utf8_encode("bowob_mode: ").$bowob_rs[0]->bowob_mode.utf8_encode("\n");
  echo utf8_encode("bowob_id_chat: ").$bowob_rs[0]->bowob_id_chat.utf8_encode("\n");
  echo utf8_encode("bowob_user: ").$bowob_rs[0]->bowob_user.utf8_encode("\n");
  echo utf8_encode("bowob_type: ").$bowob_rs[0]->bowob_type.utf8_encode("\n");

}
else{
  global $wpdb;

  $bowob_page = $wpdb->get_row("SELECT * FROM {$table_prefix}posts WHERE post_name = 'bowob'", ARRAY_A);

  if($bowob_page["post_name"] != "bowob"){
  	$wpdb->query("INSERT INTO {$table_prefix}posts (post_author, post_date, post_date_gmt, post_content, post_title, post_category, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type) VALUES ('1', '1986-11-17 17:17:17', '1986-11-17 17:17:17', '[[BOWOB]]', 'Chat', '0', '', 'publish', 'closed', 'closed', '', 'bowob', '', '', '1986-11-17 17:17:17', '1986-11-17 17:17:17', '', '0', '', '0', 'page')");
  }

  add_action("wp", "bowob_header");
  add_action("widgets_init", "widget_bowob_init");
  add_filter("the_content", "bowob_content");
  add_filter("query_vars", "bowob_query_vars");
  add_action("generate_rewrite_rules","bowob_rewrite_rules");
  add_action("activate_bowob/bowob.php","bowob_activate");
  add_action("deactivate_bowob/bowob.php","bowob_deactivate");
  add_action("wp_footer","bowob_footer");

}
function bowob_config(){
  global $wpdb, $table_prefix, $wp_rewrite, $page_info, $page_perma;

  $page_info = $wpdb->get_row("SELECT * FROM {$table_prefix}posts WHERE post_name = 'bowob'", ARRAY_A);

  $page_perma = ($wp_rewrite->get_page_permastruct() == "") ? false : true;
}

function bowob_show_chat($id_chat, $id, $sync){
  global $bowob_icones, $bowob_icones_path, $bowob_icones_button_path, $bowob_colours, $bowob_language_object, $bowob_language, $bowob_sounds_path, $bowob_sounds_volume, $bowob_format_bold, $bowob_format_underline, $bowob_format_italic, $bowob_format_colours, $bowob_format_icones;    
  
  $output = "<br>\n";
  $output .= "<center>\n";
  $output .= "<DIV ID=\"bowob_a\"></DIV>\n";
  $output .= "<DIV ID=\"bowob_b\"></DIV>\n";
  $output .= "<SCRIPT LANGUAGE=\"javascript\">\n";
  $output .= "bowob_icones = new Array();\n";
  $output .= "bowob_icones_path = new Array();\n";
  $output .= "bowob_colours = new Array(\"\");\n";
  $output .= "bowob_language = new Object();\n";
  $output .= "bowob_sounds = new Array();\n";

  for($j = 0; $j < sizeof($bowob_icones); $j ++){
    $output .= "bowob_icones[" . $j . "] = \"" . str_replace("\"", "\\\"", str_replace("\\", "\\\\", $bowob_icones[$j])) . "\";\n";
    $output .= "bowob_icones_path[" . $j . "] = \"" . $bowob_icones_path[$j] . "\";\n";
  }
  
  $output .= "bowob_icones_button = \"" . $bowob_icones_button_path . "\";\n";

  for($j = 0; $j < sizeof($bowob_sounds_path); $j ++){
    $output .= "bowob_sounds[" . $j . "] = \"" . $bowob_sounds_path[$j] . "\";\n";
  }
  
  $output .= "bowob_sounds_volume = ";
  if($bowob_sounds_volume){
    $output .= "2";
  }
  else{
    $output .= "0";
  }
  $output .= ";\n";
  
  for($j = 0; $j < sizeof($bowob_colours); $j ++){
    $output .= "bowob_colours[" . ($j + 1) . "] = \"" . $bowob_colours[$j] . "\";\n";
  }
  
  for($j = 0; $j < sizeof($bowob_language); $j ++){
    $output .= "bowob_language." . $bowob_language_object[$j] . " = \"" . str_replace("\"", "\\\"", str_replace("\\", "\\\\", $bowob_language[$j])) . "\";\n";
  }
  
  $output .= "bowob_format_bold = ";
  if($bowob_format_bold){
    $output .= "true";
  }
  else{
    $output .= "false";
  }
  $output .= ";\n";

  $output .= "bowob_format_underline = ";
  if($bowob_format_underline){
    $output .= "true";
  }
  else{
    $output .= "false";
  }
  $output .= ";\n";

  $output .= "bowob_format_italic = ";
  if($bowob_format_italic){
    $output .= "true";
  }
  else{
    $output .= "false";
  }
  $output .= ";\n";

  $output .= "bowob_format_colours = ";
  if($bowob_format_colours){
    $output .= "true";
  }
  else{
    $output .= "false";
  }
  $output .= ";\n";

  $output .= "bowob_format_icones = ";
  if($bowob_format_icones){
    $output .= "true";
  }
  else{
    $output .= "false";
  }
  $output .= ";\n";
  
  $output .= "</SCRIPT>\n";
  $output .= "<script type=\"text/javascript\" src=\"http://www.bowob.com/chat.php?type=1&id_chat=".$id_chat."&id=".$id."&sync=".$sync."\"></script>\n";
  $output .= "<noscript>NOSCRIPT: This content requires JavaScript.</noscript>\n";
  $output .= "</center>\n";
  
  echo $output;
}

?>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.