Source for file index.php

Documentation is available at index.php

  1. <?php //-*-php-*-
  2. /* ******************************************************************** **
  3. ** Copyright notice **
  4. ** **
  5. ** (c) 1995-2003 PHPOpenChat Development Team **
  6. ** http://phpopenchat.sourceforge.net/ **
  7. ** **
  8. ** All rights reserved **
  9. ** **
  10. ** This script is part of the PHPOpenChat project. The PHPOpenChat **
  11. ** project is free software; you can redistribute it and/or modify **
  12. ** it under the terms of the GNU General Public License as published by **
  13. ** the Free Software Foundation; either version 2 of the License, or **
  14. ** (at your option) any later version. **
  15. ** **
  16. ** The GNU General Public License can be found at **
  17. ** http://www.gnu.org/copyleft/gpl.html. **
  18. ** A copy is found in the textfile GPL and important notices to the **
  19. ** license from the team is found in the textfile LICENSE distributed **
  20. ** with these scripts. **
  21. ** **
  22. ** This script is distributed in the hope that it will be useful, **
  23. ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
  24. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
  25. ** GNU General Public License for more details. **
  26. ** **
  27. ** This copyright notice MUST APPEAR in all copies of the script! **
  28. ** ******************************************************************** */
  29.  
  30. /*
  31. $Author: jjaeschke $
  32. $Date: 2003/10/14 14:43:17 $
  33. $Source: /cvsroot/phpopenchat/chat3/index.php,v $
  34. $Revision: 1.83 $
  35. */
  36.  
  37. //Get default values
  38. require_once('config.inc.php');
  39.  
  40. require_once(POC_INCLUDE_PATH.'/adodb/adodb.inc.php');
  41. require_once(POC_INCLUDE_PATH.'/class.Chat.inc');
  42. require_once(POC_INCLUDE_PATH.'/class.Chatter.inc');
  43. require_once(POC_INCLUDE_PATH.'/class.Line.inc');
  44. require_once(POC_INCLUDE_PATH.'/class.Channel.inc');
  45. require_once(POC_INCLUDE_PATH.'/class.Channel_Buffer_'.CHANNEL_BUFFER_TYPE.'.inc');
  46. require_once(POC_INCLUDE_PATH.'/class.Template.inc');
  47. require_once(POC_INCLUDE_PATH.'/class.Translator.inc');
  48. require_once(POC_INCLUDE_PATH.'/class.Logger.inc');
  49.  
  50. function POC_Error_Handler($errno, $errmsg, $filename, $linenum, $vars)
  51. {
  52. if( $errno == 2 ){
  53. //the webserver has no write access to the tmp dir
  54. Chat::display_error( $errmsg, $filename );
  55. exit;
  56. }
  57. }
  58.  
  59. //$old_error_handler = set_error_handler("Chat::POC_Error_Handler");
  60. //jj problems with this $old_error_handler = set_error_handler("POC_Error_Handler");
  61.  
  62.  
  63.  
  64. @session_start();
  65. //if ($old_error_handler) set_error_handler($old_error_handler);
  66. unset($old_error_handler);
  67.  
  68. $jScript = '';
  69. $operator_passwd = '';
  70. $chatters_online_list = '';
  71. $_tmp =( isset($_SESSION['chatter']) )? $_SESSION['chatter']->get_user():'';
  72. if(!isset($_GET['nickname']))
  73. $_GET['nickname']=( isset($_COOKIE['poc_nick']) )? $_COOKIE['poc_nick']:$_tmp;
  74. if(!isset($_GET['password']))
  75. $_GET['password']=( isset($_COOKIE['poc_password']) )? $_COOKIE['poc_password']:$_tmp;//it's a fake, only to show some stars in the password field
  76. unset($_tmp);
  77.  
  78. function check_private_icon( $nick )
  79. {
  80. global $ACCEPTED_MIME_TYPES;
  81. $smiley_dir = '/images/icons/chatter';
  82. for ($i=0;$i<count($ACCEPTED_MIME_TYPES);$i++)
  83. {
  84. preg_match('#image/[x\-]?(.*)#',$ACCEPTED_MIME_TYPES[$i], $parts);
  85. $file_extension = $parts[1];
  86. $smiley_path = $smiley_dir.'/'.strtolower($nick).'.'.$file_extension;
  87. if( file_exists($_SESSION['template']->get_tmpl_sys_path().$smiley_path) )
  88. return '<img src="'.$_SESSION['template']->get_tmpl_web_path().$smiley_path.'" align="middle" alt="'.$_SESSION['translator']->out('PRIVATE_IMAGE').'" />';
  89. }
  90. return '&nbsp;';
  91. }
  92.  
  93. if( !isset($_SESSION['chat']) || !is_object($_SESSION['chat']))
  94. {
  95. if( !isset($_SESSION['chatter']) && function_exists('session_register') ) {
  96. session_register('chatter');
  97. }
  98. if( !isset($_SESSION['template']) && function_exists('session_register') ) {
  99. session_register('template');
  100. }
  101. if(function_exists('session_register')) {
  102. session_register('chat','translator','channel','channel_buffer','lastRedLine','mailbox','current_mailbox_type','curr_mail_idx','inbox_count_new','outbox_count_new','trash_count_new','session_get','session_post','reload_count','poll_count','logger');
  103. }
  104.  
  105. $reload_count=0;$_SESSION['reload_count']=0;
  106. $poll_count=0;$_SESSION['poll_count']=0;
  107.  
  108. $session_get = session_name().'='.session_id();
  109. $_SESSION['session_get'] = $session_get;
  110. $session_post = '<input type="hidden" name="'.session_name().'" value="'.session_id().'" />';
  111. $_SESSION['session_post'] = $session_post;
  112. $logger = &new Logger();
  113. $_SESSION['logger'] = $logger;
  114. $chat = &new Chat( strval(CHAT_NAME), $supported_languages );
  115. $_SESSION['chat'] = $chat;
  116. $translator = &new Translator( $_SESSION['chat']->get_language() );
  117. $_SESSION['translator'] = $translator;
  118. $_SESSION['chat']->set_deathless_chatters( $DEATHLESS_CHATTERS );
  119. if( isset($_SERVER['HTTP_REFERER']) )
  120. $_SESSION['chat']->set_referer($_SERVER['HTTP_REFERER']);
  121. $_SESSION['chat']->connect();
  122. $_SESSION['chat']->alter_db_schema();
  123. $_SESSION['chat']->make_clean();
  124. //Set operator password
  125. $operator_passwd = $_SESSION['chat']->set_operator_passwd();
  126. $_SESSION['chat']->disconnect();
  127. }
  128.  
  129. if( isset($_GET['pnlogin']) )
  130. {
  131. //here a postnuke user has a chatter object already in the db
  132. //this object was created by the first request from postnuke enviroment
  133. //see below if( function_exists('pnUserGetVar') )...
  134. $_SESSION['chat']->connect();
  135. $_SESSION['chatter'] = $_SESSION['chat']->get_chatter_instance($_GET['pnlogin']);
  136. if( !is_object($_SESSION['chatter']) || $_SESSION['chatter']->db_instance_is_outdated() )
  137. unset($_SESSION['chatter']);
  138. else
  139. {
  140. $_SESSION['chatter']->mkinstance_clean();
  141. $_SESSION['chat']->set_show_profile(false);//profile data are managed by PN
  142. }
  143. $_SESSION['chat']->disconnect();
  144. }
  145. /*
  146. if( isset($_GET['language']) && in_array($_GET['language'], $supported_languages) )
  147. {
  148. $_SESSION['chat']->set_language($_GET['language']);
  149. $_SESSION['translator']->set_language($_GET['language']);
  150. }
  151. */
  152. if ( !isset($_SESSION['template']) )
  153. {
  154. $template = &new Template();
  155. $_SESSION['template'] = $template;
  156. if( isset($_SESSION['chatter']) )
  157. $_SESSION['template']->set_theme( $_SESSION['chatter']->get_theme() );
  158. unset($theme);
  159.  
  160. if( function_exists('pnUserGetVar') )
  161. {
  162. // this is a request from the postnuke enviroment
  163. if ( pnUserLoggedIn() )
  164. {
  165. //register or update POC userdata
  166. $_chatter = Chat::mkinstance_chatter( pnUserGetVar('uname'), true );
  167. $_chatter->set_user( pnUserGetVar('uname') );
  168. $_chatter->set_email( pnUserGetVar('email') );//is hidden by default
  169. $_chatter->set_name( pnUserGetVar('name') );
  170. $_chatter->set_homePageURL( pnUserGetVar('url') );
  171. $_chatter->set_aimNickname( pnUserGetVar('user_aim') );
  172. $_chatter->set_yimNickname( pnUserGetVar('user_yim') );
  173. $_chatter->set_interests( pnUserGetVar('user_intrest') );
  174. if(!$_chatter->is_registered()) $_chatter->register();
  175. $_chatter->update();
  176. $_chatter->set_db_instance_lifetime();
  177. $_chatter->mkinstance_persist();
  178. unset($_chatter);
  179. $poc_web_root = $_SESSION['template']->get_poc_web_root();
  180.  
  181. //clean PN session
  182. unset($_SESSION['chat']);
  183. //unset($_SESSION['chatter']);
  184. unset($_SESSION['reload_count']);
  185. unset($_SESSION['template']);
  186. unset($_SESSION['translator']);
  187. unset($_SESSION['logger']);
  188. unset($_SESSION['session_post']);
  189. unset($_SESSION['session_get']);
  190.  
  191. header('Status: 301');
  192. header('Location: '.$poc_web_root.'/index.php?pnlogin='.pnUserGetVar('uname'));
  193. exit;
  194. }
  195. else
  196. {
  197. $_SESSION['template']->get_template('pn_login_failure');
  198. }
  199. }
  200. }
  201. $TEMPLATE_OUT['lang_switch'] = $_SESSION['chat']->get_lang_switch();
  202.  
  203. if ( isset($_POST['account_data'])
  204. || ( isset($_SESSION['chatter']) && !$_SESSION['chatter']->is_kicked() && AUTOLOGIN_DIRECTLY ) )
  205. {
  206. /*
  207. * Create a new chatter to check account data
  208. * Object chatter has no nick, if
  209. * -the password doesn't match
  210. * -the nick contains incorrect characters
  211. * -the nick is too long
  212. */
  213. if(isset($_POST['nick'])
  214. && $_POST['nick'] == strval(STATUS_BOT_NAME))
  215. unset($_POST['nick']);
  216.  
  217. if( !isset($_SESSION['chatter']) || $_SESSION['chatter']->is_guest() )
  218. {
  219. if( !Chat::mkinstance_channel( $_POST['channel'] ) )
  220. die('Channel doesn\'t exists!');
  221. $_chatter = &new Chatter($_POST['nick'],$_POST['password']);
  222. }
  223. else
  224. {
  225. if( !isset($_POST['channel']) )
  226. $_POST['channel'] = ENTRY_CHANNEL;
  227. if( !Chat::mkinstance_channel( $_POST['channel'] ) )
  228. die('Channel doesn\'t exists!');
  229. $_chatter = $_SESSION['chatter'];
  230. }
  231.  
  232. if (!is_null($_chatter->get_nick()) || isset($_SESSION['chatter']) )
  233. {
  234. if ( !isset($_SESSION['chatter']) || $_SESSION['chatter']->is_guest() )
  235. $_SESSION['chatter'] = $_chatter;
  236. if ( isset($_POST['storeAccountData']) )
  237. {
  238. setcookie('poc_nick',$_POST['nick'],COOKIE_EXPIRE,COOKIE_PATH,COOKIE_DOMAIN,COOKIE_SECURE);
  239. setcookie('poc_password',$_POST['password'],COOKIE_EXPIRE,COOKIE_PATH,COOKIE_DOMAIN,COOKIE_SECURE);
  240. }
  241. //connect to the line buffer of choosen channel
  242. $channel_buffer = &new Channel_Buffer($_POST['channel']);
  243. $_SESSION['channel_buffer'] = $channel_buffer;
  244.  
  245. $_SESSION['channel_buffer']->connect();
  246. $lastRedLine = $_SESSION['channel_buffer']->get_cur_line_idx();
  247. $_SESSION['channel_buffer']->disconnect();
  248. $_SESSION['lastRedLine'] = $lastRedLine;
  249.  
  250. $_SESSION['chat']->connect();
  251. $_SESSION['chat']->create_private_channel( $_chatter->get_nick(true) );
  252. $_SESSION['chat']->disconnect();
  253.  
  254. $banned_msg = '';
  255. if( $_SESSION['chatter']->is_banned( $_POST['channel']) )
  256. {
  257. $banned_msg = ' ###BANNED_MSG###';
  258. $_SESSION['chatter']->join_channel( $_SESSION['chatter']->get_nick() );
  259. }
  260. if( !$_SESSION['chatter']->already_seen_today() )
  261. $_SESSION['chatter']->count_hit('login');
  262.  
  263. $_SESSION['chatter']->refresh();
  264. $_SESSION['chatter']->set_grade($GRADES);
  265. $_SESSION['template']->set_theme( $_SESSION['chatter']->get_theme() );
  266.  
  267. //hey, the chatter is authorized
  268. $_SESSION['chatter']->go_online( $_SESSION['channel']->get_name() );
  269. //$_SESSION['chatter']->get_db_groups( $_SESSION['channel']->get_name() );
  270. //we have to say hello in the current channel first»
  271. $bot = &new Chatter(strval(STATUS_BOT_NAME));
  272.  
  273. $said = $_SESSION['chatter']->get_nick().' ###JOINS_THE_CHAT###';
  274. $said .= $banned_msg;
  275. $line = &new Line($bot, $said);
  276. $line->set_login($_SESSION['chatter']->get_nick());
  277. $_SESSION['channel_buffer']->connect();
  278. //get current line number within channel buffer
  279. $_SESSION['channel_buffer']->put_line($line);
  280. $_SESSION['channel_buffer']->disconnect();
  281. if( $_SESSION['channel']->get_message() != '' ) {
  282. $_SESSION['chat']->write_sys_msg( '<br />'.$_SESSION['channel']->get_message(),$_SESSION['chatter'], true );
  283. }
  284.  
  285. unset($line);
  286. unset($line_message);
  287. unset($bot);
  288. unset($said);
  289. unset($_SESSION['in']);
  290.  
  291. header('Status: 301');
  292. header('Location: frameset.php?'.session_name().'='.session_id());
  293.  
  294. exit;
  295. }
  296. else
  297. {
  298. unset($_SESSION['channel']);
  299. unset($_chatter);
  300. }
  301. }
  302. else
  303. {
  304. header('Content-type: text/html; charset='.$_SESSION['translator']->out('CHARACTER_ENCODING'));
  305. $_SESSION['template']->get_cached_content( 60*2 );//get cached content with a max age of 2 minutes
  306. }
  307.  
  308. if( !$_SESSION['chat']->connect() )
  309. {
  310. unset($_SESSION['chat']);
  311. unset($_SESSION['chatter']);
  312. unset($_SESSION['channel_buffer']);
  313. unset($_SESSION['lastRedLine']);
  314. header('Status: 301');
  315. header('Location: test.php');
  316. exit;
  317. }
  318. $chatters_online = array();
  319. $chatters_online = $_SESSION['chat']->get_chatters('%');
  320. $count_chatters_online = count($chatters_online);
  321. if( $count_chatters_online > 0 )
  322. {
  323. $td_count = 0;
  324. for($i=0;$i<$count_chatters_online;$i++)
  325. {
  326. $td_count++;
  327. if($i==0 || ($i % COL_COUNT_CHATTER_LIST) == 0) $chatters_online_list .= NL.TAB.'<tr>';
  328. $chatters_online_list .= NL.TAB.TAB.'<td class="chatterTableImgCell">'.check_private_icon( $chatters_online[$i] ).'</td>
  329. <td class="chatterTable">&nbsp;'.preg_replace( "/\#{3}([^#]*)\#{3}/e", "htmlentities(\$_SESSION['translator']->out('\\1'))", $chatters_online[$i] ).'&nbsp;</td>';
  330. if($i > 0 && ($i % COL_COUNT_CHATTER_LIST) == 0)
  331. {
  332. $td_count = 0;
  333. $chatters_online_list .= NL.TAB.'</tr>';
  334. }
  335. }
  336. for ($i = $td_count; $i < COL_COUNT_CHATTER_LIST; $i++)
  337. {
  338. $chatters_online_list .= NL.TAB.TAB.'<td colspan="2"></td>';
  339. }
  340. if( $td_count > 0 ) $chatters_online_list .= NL.TAB.'</tr>';
  341. }
  342. else
  343. $chatters_online_list = '<tr><td>&nbsp;</td></tr>';
  344.  
  345. $TEMPLATE_OUT['count_chatters_online'] = $count_chatters_online;
  346. //get statistics
  347. $TEMPLATE_OUT['online_count_last24h'] = $_SESSION['chat']->get_online_count_last24h();
  348. $TEMPLATE_OUT['online_time_avg'] = round($_SESSION['chat']->get_online_time_avg()/(60*60*24),3);
  349. $TEMPLATE_OUT['registered_count'] = $_SESSION['chat']->get_registered_count();
  350. $TEMPLATE_OUT['last_registered'] = array();
  351. $last_registered_user = $_SESSION['chat']->get_last_registered();
  352. $TEMPLATE_OUT['last_registered']['NICK'] = $last_registered_user[0]['NICK'];
  353. $TEMPLATE_OUT['last_registered']['REGTIME'] = $last_registered_user[0]['REGTIME'];
  354. $TEMPLATE_OUT['mail_count'] = $_SESSION['chat']->get_mail_count();
  355. $TEMPLATE_OUT['mail_count_last_24h'] = $_SESSION['chat']->get_mail_count_last_24h();
  356. $TEMPLATE_OUT['option_list_of_channels'] = $_SESSION['chat']->get_channels_option_list(CHANNEL_SELECTED);
  357. $_SESSION['chat']->disconnect();
  358.  
  359. //unset objects in session
  360. //unset($_SESSION['chatter']);
  361.  
  362. unset($_SESSION['channel_buffer']);
  363. unset($_SESSION['lastRedLine']);
  364.  
  365. $jump = ( isset($_GET['jump']) )? $_GET['jump']:'index.php';
  366.  
  367. if( isset($_GET['onTop']) )
  368. $jScript .= '
  369. if( opener ) {
  370. /*click on exit within satellit*/
  371. opener.parent.location.href="'.$jump.'";
  372. window.close();
  373. }
  374. else {
  375. //alert(\'debug\');
  376. top.location.href="'.$jump.'";
  377. }
  378. ';
  379. if( isset($_GET['forceOnTop']) )
  380. $jScript .= '
  381. top.location.href="'.$jump.'";
  382. ';
  383.  
  384. $TEMPLATE_OUT['disable'] = '';
  385. if( isset($_SESSION['chatter']) && !AUTOLOGIN_DIRECTLY && !$_SESSION['chatter']->is_guest() )
  386. {
  387. $TEMPLATE_OUT['disable'] = 'disabled="disabled"';
  388. }
  389.  
  390. $TEMPLATE_OUT['nickname'] = '';
  391. $TEMPLATE_OUT['greeting'] = '';
  392. if( isset($_SESSION['chatter']) )
  393. {
  394. $TEMPLATE_OUT['nickname'] = $_SESSION['chatter']->get_nick().':';
  395. $TEMPLATE_OUT['greeting'] = $_SESSION['translator']->out('GREETING');
  396. }
  397. $TEMPLATE_OUT['jScript'] = $jScript;
  398. $TEMPLATE_OUT['operator_passwd'] = $operator_passwd;
  399. $TEMPLATE_OUT['chatters_online_list'] = $chatters_online_list;
  400. header('Content-type: text/html; charset='.$_SESSION['translator']->out('CHARACTER_ENCODING'));
  401. $_SESSION['template']->get_template('index');
  402. ?>

Documentation generated on Tue, 29 Jun 2004 14:42:29 +0200 by phpDocumentor 1.3.0RC3