[ PHPXref.com ] [ Generated: Sun Jul 20 19:53:39 2008 ] [ PHProjekt 5.0.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/chat/ -> chat.php (source)

   1  <?php
   2  
   3  // chat.php - PHProjekt Version 5.0

   4  // copyright © 2000-2005 Albrecht Guenther ag@phprojekt.com

   5  // www.phprojekt.com

   6  // Author: Albrecht Guenther, $Author: fgraf $

   7  // $Id: chat.php,v 1.38.2.1 2005/09/07 14:02:32 fgraf Exp $

   8  
   9  $module = 'chat';
  10  $path_pre = '../';
  11  global $chatfreq;
  12  
  13  $include_path = $path_pre.'lib/lib.inc.php';
  14  include_once $include_path;
  15  
  16  $include_path = $path_pre.'lib/dbman_lib.inc.php';
  17  include_once $include_path;
  18  
  19  $chatfreq = (!PHPR_CHATFREQ) ? '10000' : PHPR_CHATFREQ;
  20  
  21  
  22  if ($toggle_html_editor_flag == 1) html_editor_mode($module);
  23  //html_editor_mode('chat');

  24  $he_add = array();
  25  // if (eregi("gecko", $_SERVER["HTTP_USER_AGENT"]))

  26  $he_add[] = '
  27  <script type="text/javascript">
  28  <!--
  29  window.setTimeout("chat_reload()",'.$chatfreq.');
  30  function chat_reload() {
  31      var obj = encodeURIComponent(document.frm.content.value);
  32      var loc = "chat.php?content=" + obj;
  33      location.href = loc;
  34  }
  35  //-->

  36  </script>
  37  ';
  38  
  39  // for all other browsers

  40  /* else {

  41      $he_add[] = '  <meta http-equiv="refresh" content="'.ceil($chatfreq/1000).

  42             '; URL=chat.php?mode='.$mode.'&'.session_name().'='.session_id().'" />'."\n";

  43  }*/
  44  //$onload[] = 'document.frm.content.focus();';

  45  
  46  $include_path = $path_pre.'lib/lib.inc.php';
  47  include_once $include_path;
  48  
  49  $_SESSION['common']['module'] = 'chat';
  50  
  51  // ****************

  52  // check role

  53  if (check_role('chat') < 1) die('You are not allowed to do this!');
  54  
  55  
  56  // assign person to his group chat

  57  $alivefile = $user_group.'_'.PHPR_ALIVEFILE;
  58  $chatfile  = $user_group.'_'.PHPR_CHATFILE;
  59  
  60  if ($mode == 'write') {
  61      writetext();
  62      $content = '';
  63  }
  64  
  65  echo set_page_header();
  66  
  67  include_once ($path_pre.'lib/navigation.inc.php');
  68  
  69  $output = '
  70  <div class="outer_content">
  71      <div class="content">
  72  ';
  73  
  74  // tabs

  75  $tabs = array();
  76  $output .= get_tabs_area($tabs);
  77  
  78  // context menu

  79  include_once ($path_pre.'lib/contextmenu.inc.php');
  80  $menu3 = new contextmenu();
  81  $output .= $menu3->menu_page_chat();
  82  // end context menu

  83  
  84  // button bar

  85  $buttons = array();
  86  $buttons[] = array('type' => 'link', 'href' => '../index.php?'.session_name().'='.session_id().'&amp;chataction=logout', 'text' => __('Quit chat'), 'active' => false);
  87  $output .= get_buttons_area($buttons, 'oncontextmenu="startMenu(\''.$menu3->menusysID.'\',\''.$field_name.'\',this)"');
  88  $output .= '
  89          <div class="hline"></div>
  90          <div class="inner_content">
  91              <a name="content"></a>
  92              <div class="chatUsers">'.alive().'</div>
  93              <div class="chatContent">'.chat().'</div>
  94              <div class="chatInput">'.input().'</div>
  95          </div>
  96      </div>
  97  </div>
  98  
  99  </body>
 100  </html>
 101  ';
 102  
 103  echo $output;
 104  
 105  /* TODO: remove this, should be obsolete now

 106  // Menu

 107  if      ($mode == 'input') input();

 108  else if ($mode == 'chat')  chat();

 109  else if ($mode == 'alive') alive();

 110  else if ($mode == 'check') check();

 111  */
 112  
 113  
 114  function input () {
 115      global $css_style, $chat_entry_type, $content;
 116  
 117  /*

 118      $onload[] = 'document.frm.content.focus();';

 119      echo set_page_header();

 120  */
 121  
 122      if (check_role('chat') > 1) {
 123          $output1 = "<form action='chat.php' method='post' name='frm'>\n";
 124          if ($chat_entry_type == 'textfield') {
 125              $output1 .= "<input type='text' name='content' size='70' />\n";
 126              $output1 .= get_buttons(array(array('type' => 'submit', 'name' => 'submit', 'value' => __('submit'), 'active' => false)));
 127          }
 128          else {
 129              $GLOBALS['show_html_editor']['chat'] > 0 ? $textarea_id = 'id="html_editor"' : $textareea_id = '';
 130              $output1 .= "<textarea name='content' rows='3' cols='70' $textarea_id>".xss(stripslashes($content))."</textarea>\n";
 131              $output1 .= get_buttons(array(array('type' => 'submit', 'name' => 'submit', 'value' => __('submit'), 'active' => false)));
 132          }
 133          $output1 .= "<input type='hidden' name='mode' value='write' />\n";
 134          $output1 .= "<input type='hidden' name='".session_name()."' value='".session_id()."' />\n";
 135          $output1 .= "</form>\n";
 136      }
 137      return $output1;
 138  }
 139  
 140  
 141  function writetext () {
 142      global $chatfile, $user_name, $user_firstname, $content, $chat_direction;
 143  
 144      // small irc hack - replace /me with the username

 145      $content = ereg_replace('/me', $user_firstname, $content);
 146      $content = ereg_replace("\r\n", "\n", $content);
 147      $content = ereg_replace("\n", "<br />", $content);
 148  
 149      // add time to new line

 150      $newcontent = '<tr valign="top"><td class="chats">';
 151      if (PHPR_CHAT_TIME == 2) $newcontent .= date('m-d H:i');
 152      else if (PHPR_CHAT_TIME) $newcontent .= date('H:i');
 153      $newcontent .= '</td><td> <b>';
 154      // first name and/or last name of the user depending on the setting inthe config

 155      switch (PHPR_CHAT_NAMES) {
 156          case '1':
 157              $newcontent .= $user_firstname;
 158              break;
 159          case '2':
 160              $newcontent .= $user_firstname.', '.$user_name;
 161              break;
 162          case '3':
 163              $newcontent .= $user_name.', '.$user_firstname;
 164              break;
 165          default:
 166              $newcontent .= $user_name;
 167      }
 168  
 169      $newcontent .= ":</b></td><td>".$content."</td></tr>\n";
 170  
 171      // fetch current chat file

 172      if (is_file($chatfile)) {
 173          $lines = file($chatfile);
 174          $lines2 = array_reverse($lines);
 175          //if ($chat_direction == 'bottom') $lines2[] = $newcontent;

 176          //else array_unshift ($lines2,$newcontent);

 177          array_unshift ($lines2,$newcontent);
 178          foreach ($lines2 as $line) $contents = $line.$contents;
 179          $contents = ereg_replace("\r\n", "\n", $contents);
 180          //$contents = ereg_replace("\n", "<br />\n", $contents);

 181          $deleted = unlink($chatfile);
 182      }
 183      // oh, first message?

 184      else $contents = $newcontent;
 185      // write whole message stuff to file

 186      $fp = fopen($chatfile, 'a+');
 187      flock($fp, 2);
 188      $fw = fwrite($fp, xss($contents));
 189      fclose($fp);
 190      // show input form

 191      //input();

 192  }
 193  
 194  
 195  function chat () {
 196      global $chatfile, $chatfreq, $css_style;
 197  /*

 198      if (eregi("gecko", $_SERVER["HTTP_USER_AGENT"])) {

 199          echo "<script language=\"JavaScript\">window.setTimeout(\"location.reload()\",$chatfreq)</script>\n";

 200      }

 201      // for all other browsers

 202      else {

 203          $chatfreq = $chatfreq/1000;

 204          echo"<meta http-equiv=\"refresh\" content=\"$chatfreq; URL=chat.php?mode=chat".'&'.session_name()."=".session_id()."\" />\n";

 205      }

 206      echo "<link rel='stylesheet' type='text/css' href='$css_style'>\n</head>\n";

 207      echo set_body_tag();

 208  */
 209      // Here's start of the table

 210      $output1 .= "<table class='chat' width='95%'>\n";
 211      // no chat file? exit this frame in this moment and wait, until the first posting has been made.

 212      if (!file_exists($chatfile)) return '';
 213  
 214      // read the file into a array - one line one element

 215      $lines = file($chatfile);
 216      // put the lines in a reverse order and remove the backslashes

 217      for ($i = count($lines); $i >= (count($lines)-PHPR_MAX_LINES);$i--) {
 218          $output1 .= stripslashes($lines[$i]);
 219      }
 220      $output1 .= '</table>';/*and here the end of the table :-) */
 221      return  $output1;
 222  }
 223  
 224  
 225  function alive () {
 226      global $chatfile, $mode, $user_name, $user_firstname, $css_style;
 227  
 228      // workaround for gecko: use javascript

 229  /*

 230      if (eregi("gecko", $_SERVER["HTTP_USER_AGENT"])) {

 231          echo "<script language=\"JavaScript\">window.setTimeout(\"location.reload()\",".PHPR_ALIVEFREQ.")</script>\n";

 232      }

 233      // for all other browsers

 234      else {

 235          $alivefreq2 = PHPR_ALIVEFREQ/1000;

 236          echo "<meta http-equiv=\"refresh\" content=\"$alivefreq2; URL=chat.php?mode=alive".'&'.session_name()."=".session_id()."\">\n";

 237      }

 238  */
 239      $i = 0;
 240      $a = 0;
 241      // read file alive and put into array $lines

 242      if (file_exists(PHPR_ALIVEFILE)) {
 243          $lines = file(PHPR_ALIVEFILE);
 244          // scan all users online

 245          while ($lines[$i]) {
 246              // extract  names and record time

 247              $li = explode(':', $lines[$i]);
 248              $time = time();  // take current time

 249              // exclude old records (probably crap from older sessions)

 250              if (($li[1] + PHPR_ALIVEFREQ/1000 + 5) > $time) {
 251                  // entry for this user found?

 252                  if ($li[0] == ($user_firstname.' '.$user_name)) {
 253                      // take the record into the new array with the current time

 254                      $lines2[] = $li[0].':'.$time;
 255                      $drin = 1;
 256                  }
 257                  // take current records of other users into the new array

 258                  else {
 259                      $lines2[] = $li[0].':'.$li[1];
 260                  }
 261              }
 262              $i++;
 263          }
 264      }
 265  
 266      //

 267      if (!$drin ) { $lines2[] = $user_firstname.' '.$user_name.':'.$time; }
 268  
 269      $fp = fopen(PHPR_ALIVEFILE, 'w+');
 270      flock($fp, 2);
 271      for ($i=0; $i < count($lines2); $i++) {
 272          $line = "$lines2[$i]\n";
 273          $fw = fwrite($fp,$line);
 274          $li = explode(':', $line);
 275          $output1 .= "&nbsp;&nbsp;$li[0] <br />";
 276      }
 277      fclose($fp);
 278      // inittialize chat file if it doesn't exist

 279      if (!isset($lines2[0])) {
 280          $fr = fopen($chatfile, 'w');
 281          fclose($fr);
 282      }
 283      return $output1;
 284  }
 285  
 286  
 287  /* TODO: remove this, should be obsolete now */

 288  // // checks the chat file whether it has changed since the last refresh.

 289  // // If yes, trigger the chat window to refresh

 290  // function check() {

 291  //     global $chatfile, $chatfreq;

 292  //

 293  //     echo "<html>\n<head>\n";

 294  //     // reload this null frame

 295  //     // workaround for gecko: use javascript

 296  //     if (eregi("gecko", $_SERVER["HTTP_USER_AGENT"])) {

 297  //         echo "<script type=\"text/javascript\">\nwindow.setTimeout(\"location.reload()\",$chatfreq)\n</script>\n";

 298  //     }

 299  //     // for all other browsers

 300  //     else {

 301  //         $chatfreq = $chatfreq/1000;

 302  //         echo "<meta http-equiv=\"refresh\" content=\"$chatfreq; URL=chat.php?mode=check".'&'.session_name()."=".session_id()."\">\n";

 303  //     }

 304  //     clearstatcache();

 305  //     $load = array();

 306  //     // chek chatfile

 307  //     if (file_exists($chatfile)) {

 308  //         $stat = stat($chatfile);

 309  //         if (!isset($_SESSION["lm_chatfile"]) || $_SESSION["lm_chatfile"] <> $stat[9]) {

 310  //             // reload chat window

 311  //             $load[] = 'parent.l.location.reload();';

 312  //             // store new lastmod time in session

 313  //             $_SESSION["lm_chatfile"] = $stat[9];

 314  //         }

 315  // /*

 316  //         // check alivefile

 317  //         $stat = stat(PHPR_ALIVEFILE);

 318  //         if (!isset($_SESSION["lm_alivefile"]) || $_SESSION["lm_alivefile"] <> $stat[9]) {

 319  //             // reload chat window

 320  //             $load[] = 'parent.l.location.reload();';

 321  //             // store new lastmod time in session

 322  //             $_SESSION["lm_alivefile"] = $stat[9];

 323  //         }

 324  // */

 325  //     }

 326  //     echo "</head>\n";

 327  //     if (count($load) > 0) {

 328  //         echo "<body onload=\"".implode(' ', $load)."\">\n</body>\n";

 329  //     }

 330  //     echo "</html>\n";

 331  // }

 332  
 333  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]