#
#-----[ SQL ЗАПРОС ]------------------------------------------
#
CREATE TABLE IF NOT EXISTS `bb_shout` (
  `shout_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `shout_username` varchar(25) CHARACTER SET utf8 NOT NULL DEFAULT '',
  `shout_user_id` mediumint(8) NOT NULL DEFAULT '0',
  `shout_active` mediumint(8) NOT NULL DEFAULT '0',
  `shout_session_time` int(11) NOT NULL DEFAULT '0',
  `shout_ip` char(8) CHARACTER SET utf8 NOT NULL DEFAULT '',
  `shout_text` varchar(1000) CHARACTER SET utf8 NOT NULL,
  KEY `shout_id` (`shout_id`)
); 

#
#-----[ ОТКРЫТЬ ]------------------------------------------
#
index.php

#
#-----[ НАЙТИ ]------------------------------------------
#
$page_cfg['load_tpl_vars'] = array(
    'post_icons',
);

#
#-----[ ПОСЛЕ ДОБАВИТЬ ]------------------------------------------
#
$page_cfg['include_bbcode_js'] = true; 

#
#-----[ ОТКРЫТЬ ]------------------------------------------
#
 ajax.php
 
#
#-----[ НАЙТИ ]------------------------------------------
#
    case 'group_membership':
		require(INC_DIR .'functions_group.php');
	break;
	
#
#-----[ ПОСЛЕ ДОБАВИТЬ ]------------------------------------------
#
    case 'chat_message':
        require(INC_DIR .'functions_post.php');
        require(INC_DIR .'bbcode.php');
    break;
	
#
#-----[ НАЙТИ ]------------------------------------------
#
        'group_membership'  => array('mod'),
		
#
#-----[ ПОСЛЕ ДОБАВИТЬ ]------------------------------------------
#
        'shout_del'         => array('mod'),
        'chat_message'      => array('user'),
		
#
#-----[ НАЙТИ ]------------------------------------------
#
	function index_data()
    {
		require(AJAX_DIR .'index_data.php');
	}
	
#
#-----[ ПОСЛЕ ДОБАВИТЬ ]------------------------------------------
#
	function chat_message()
    {
        global $bb_cache, $userdata, $bb_cfg, $lang;
        $mode = (int) $this->request['mode'];
        $message = (string) @$this->request['message'];
 
        if($mode==1)
        {
            if(!$message) $this->ajax_die($lang['SHOUTBOX_ERR']);
            $bbcode_on = $bb_cfg['allow_bbcode'];
            $smilies_on = $bb_cfg['allow_smilies'];
            if(!IS_ADMIN)
            {
                $chk = DB()->fetch_row('SELECT MAX(shout_session_time) AS last_post_time FROM bb_shout WHERE shout_user_id = '.$userdata['user_id']);
                if ( $chk['last_post_time'] > 0 && ( time() - $chk['last_post_time'] ) < $bb_cfg['flood_interval'] ) $this->ajax_die($lang['FLOOD_ERROR']);
            }
            if (!empty($message))
            {
                DB()->query('INSERT INTO bb_shout (shout_text, shout_session_time, shout_user_id, shout_ip, shout_username) VALUES ("'.DB()->escape($message).'", '.time().', '.$userdata['user_id'].', "'.USER_IP.'", "'.DB()->escape($userdata['username']).'")');
                CACHE('bb_cache')->rm('shout_data', 60);
            }
        }
        if(!$shout_data = CACHE('bb_cache')->get('shout_data', 60))
        {
            $shout_rows = DB()->fetch_rowset("SELECT s.*, u.username, u.user_level, u.user_rank, u.user_avatar, u.user_avatar_type
                FROM bb_shout s, ".BB_USERS." u
                WHERE s.shout_user_id=u.user_id AND u.user_id = u.user_id
                ORDER BY s.shout_session_time DESC LIMIT 50");
            $i=0;
            $shout_data = '';
            foreach ($shout_rows AS $shout_row)
            {
                $row_class = !($i % 2) ? 'row1' : 'row2';
                $user_level =  $shout_row['user_level'];
                if($user_level) $username = profile_url($shout_row);
				else $username = '<span>'.$shout_row['username'].'</span>';
				$avatar_img = '<img class="avatars_chat" align="left" style="max-height: 32px; max-width: 32px;" src="./images/avatars/gallery/noavatar.png" alt="" border="0" />';
				$post_delete =($userdata['user_level'] == ADMIN || $userdata['user_level'] == IS_AM) ? '<img src="templates/default/images/shout/shout_delete.png" title="Удалить сообщение" class="clickable" onclick="ajax.shout_del('.$shout_row['shout_id'].'); ajax.chat_message(2); return false;" style="float:right">&nbsp;' : '';
				$pm_link = '<a href="privmsg.php?mode=post&u='.$shout_row['shout_user_id'].'" target="_blank"><img title="Послать личное сообщение"  align="absmiddle" src="templates/default/images/shout/shout_mail.png" /></a>';
				if ($shout_row['user_avatar_type'])
                {
                switch($shout_row['user_avatar_type'] )
                {
                case USER_AVATAR_UPLOAD:
                $avatar_img = ( $bb_cfg['allow_avatar_upload'] ) ? '<img class="avatars_chat" align="left" style="max-height:35px;max-width:35px;" src="' . $bb_cfg['avatar_path'] . '/' . $shout_row['user_avatar'] . '" alt="" border="0" />' : '';
                break;
                case USER_AVATAR_REMOTE:
                $avatar_img = ( $bb_cfg['allow_avatar_remote'] ) ? '<img class="avatars_chat" align="left" style="max-height:35px;max-width:35px;" src="' . $shout_row['user_avatar'] . '" alt="" border="0" />' : '';
                break;
                case USER_AVATAR_GALLERY:
                $avatar_img = ( $bb_cfg['allow_avatar_local'] ) ? '<img class="avatars_chat" align="left" style="max-height:35px;max-width:35px;" src="' . $bb_cfg['avatar_gallery_path'] . '/' . $shout_row['user_avatar'] . '" alt="" border="0" />' : '';
                break;
                }
                }
				$shout = (!$shout_row['shout_active']) ? $shout_row['shout_text'] : $lang['Shout_censor'];
                $shout = str_replace("\n", "\n<br />\n", $shout);
                $shout = ($user_level == ADMIN) ? '<span>'.$shout.'</span>' : $shout;
				$shout_data .= '<div id="shout_'.$shout_row['shout_id'].'" class="chat-comment '.$row_class.'">
                <div style="min-height:40px; min-width: 150px; float: left; border-right: 1px solid #AED7FF;; margin-right: 6px;">
				<a href="profile.php?mode=viewprofile&u='.$shout_row['shout_user_id'].'" target="_blank" title="Посмотреть профиль">'.$avatar_img.'</a>&nbsp;
				<span><a class="bold" title="'.$lang['SHOUTBOX_INSERT_NAME'].'" style="text-decoration: none;" href="javascript:add_nick(\'[b]'.addslashes($shout_row['shout_username']).'[/b],\')">'.$username.' </a></span>&nbsp;
				'.$pm_link.'
				<div class="small" style="font-size: 9px; padding-left: 45px;">'.bb_date($shout_row['shout_session_time'], $bb_cfg['last_post_date_format']).'</div>
				</div>
                <div style="float: right;">'.$post_delete.'</div>
                <span style="font-size: 11px;">'.bbcode2html($shout).'</span>
				</div>';
                ++$i;
            }
          CACHE('bb_cache')->set('shout_data', $shout_data);
        }
        $this->response['message'] = $shout_data;
    }
 
	function shout_del()
	{
		global $bb_cache;
		$id = (int) $this->request['id'];
		DB()->query("DELETE FROM bb_shout WHERE shout_id = $id");
		$this->response['id'] = $id;
		CACHE('bb_cache')->rm('shout_data');
	}
	
#
#-----[ ОТКРЫТЬ ]------------------------------------------
#
 templates/default/index.tpl
 
#
#-----[ НАЙТИ ]------------------------------------------
#
<!-- IF TORHELP_TOPICS -->
    <!-- INCLUDE torhelp.tpl -->
    <div class="spacer_6"></div>
<!-- ENDIF / TORHELP_TOPICS -->

#
#-----[ ПОСЛЕ ДОБАВИТЬ ]------------------------------------------
#
<!-- IF LOGGED_IN -->
<script type="text/javascript">
    ajax.chat_message = function(mode) {
      ajax.exec({
        action : 'chat_message',
        mode : mode,
        message : $('#message').val()
      });
    };
    ajax.callback.chat_message = function(data) {
      if(data.message)
      {
        $('#chat').show();
        $('#chat').html(data.message);
        initPostBBCode('#chat');
      }
    };
    function submit_click(e) {
      e = e || window.event;
      if (e.keyCode == 13 && e.ctrlKey) {
        submit_chat();
      };
    }
    function add_nick(text){
      $('#message').attr('value', $('#message').val() + text +' ');
      $('#message').focus();
    }
    $(document).ready(function(){ajax.chat_message(2);});
    setInterval(function(){ajax.chat_message(2);}, 60000);
 
ajax.shout_del = function(id) {
  ajax.exec({
  action : 'shout_del',
  id : id
  });
  };
  ajax.callback.shout_del = function(data) {
  var id = data.id;
  $('td#shout_'+id).hide("slow");
  };
  </script>

<div class="category">
    <h3 class="cat_title">{L_MINI_CHAT}</h3>
	  <div class="f_tbl_wrap pad_4 tCenter">
        <form name="post">
<div class="buttons mrg_4 tLeft">
  <input class="button" type="button" value=" B " name="codeB" title="Bold (Ctrl+B)"  />&nbsp;
  <input class="button" type="button" value=" i " name="codeI" title="Italic (Ctrl+I)" style="font-style: italic;" />&nbsp;
  <input class="button" type="button" value=" u " name="codeU" title="Underline (Ctrl+U)" style="text-decoration: underline;" />&nbsp;
  <input type="button" value="{L_QUOTE}" name="codeQuote" title="Quote (Ctrl+Q)" style="width: 60px;" />
  <input type="button" value="Img" name="codeImg" title="Image (Ctrl+R)" style="width: 40px;" />
  <input type="button" value="{L_SPOILER}" name="codeSpoiler" title="{L_SPOILER}" style="width: 65px;" />
  <input type="button" name="usersubmit" class="lite"  title="Вставить смайлик" style="background: url(images/smiles/ab.gif) no-repeat; border: 0; width: 22px; height: 25px; cursor: pointer;" onclick="window.open('posting.php?mode=smilies', '_phpbbsmilies', 'height=540, resizable=yes, scrollbars=yes ,width=620'); return false;" />

<select name="fontFace">
	<option style="font-family: Verdana" value="-1" selected="selected">{L_QR_FONT_SEL}:</option>
	<option style="font-family: Courier" value="Courier">&nbsp;Courier</option>
	<option style="font-family: Courier New" value="Courier New">&nbsp;Courier New</option>
	<option style="font-family: monospace" value="monospace">&nbsp;monospace</option>
	<option style="font-family: Fixedsys" value="Fixedsys">&nbsp;Fixedsys</option>
	<option style="font-family: Arial" value="Arial">&nbsp;Arial</option>
	<option style="font-family: Comic Sans MS" value="Comic Sans MS">&nbsp;Comic Sans</option>
	<option style="font-family: Georgia" value="Georgia">&nbsp;Georgia</option>
	<option style="font-family: Tahoma" value="Tahoma">&nbsp;Tahoma</option>
	<option style="font-family: Times New Roman" value="Times New Roman">&nbsp;Times</option>
	<option style="font-family: serif" value="serif">&nbsp;serif</option>
	<option style="font-family: sans-serif" value="sans-serif">&nbsp;sans-serif</option>
	<option style="font-family: cursive" value="cursive">&nbsp;cursive</option>
	<option style="font-family: fantasy" value="fantasy">&nbsp;fantasy</option>
	<option style="font-family: Monotype Corsiva" value="Monotype Corsiva">&nbsp;Monotype</option>
</select>
&nbsp; 
<select name="codeColor" class="text_color">
  <option style="color: black; background: #fff;" value="black" selected="selected">{L_QR_COLOR_SEL}:</option>
  <option style="color: darkred;" value="darkred">{L_COLOR_DARK_RED}</option>
  <option style="color: brown;" value="brown">&nbsp;{L_COLOR_BROWN}</option>
  <option style="color: #996600;" value="#996600">&nbsp;{L_COLOR_ORANGE}</option>
  <option style="color: red;" value="red">&nbsp;{L_COLOR_RED}</option>
  <option style="color: #993399;" value="#993399">&nbsp;{L_COLOR_VIOLET}</option>
  <option style="color: green;" value="green">&nbsp;{L_COLOR_GREEN}</option>
  <option style="color: darkgreen;" value="darkgreen">&nbsp;{L_COLOR_DARK_GREEN}</option>
  <option style="color: gray;" value="gray">&nbsp;{L_COLOR_GRAY}</option>
  <option style="color: olive;" value="olive">&nbsp;{L_COLOR_OLIVE}</option>
  <option style="color: blue;" value="blue">&nbsp;{L_COLOR_BLUE}</option>
  <option style="color: darkblue;" value="darkblue">&nbsp;{L_COLOR_DARK_BLUE}</option>
  <option style="color: indigo;" value="indigo">&nbsp;{L_COLOR_INDIGO}</option>
  <option style="color: #006699;" value="#006699">&nbsp;{L_COLOR_STEEL_BLUE}</option>
</select>&nbsp;
<select name="codeSize" class="text_size">
	<option value="12" selected="selected">{L_QR_SIZE_SEL}:</option>
	<option value="9" class="em">{L_FONT_SMALL}</option>
	<option value="10">&nbsp;size=10</option>
	<option value="11">&nbsp;size=11</option>
	<option value="12" class="em" disabled="disabled">{L_FONT_NORMAL}</option>
	<option value="14">&nbsp;size=14</option>
	<option value="16">&nbsp;size=16</option>
	<option value="18" class="em">{L_FONT_LARGE}</option>
</select>
&nbsp; 
 
   <hr><textarea placeholder="Напишите сообщение..." onkeydown="submit_click(event)" id="message" class="chat_message"></textarea>
 
<input type="submit"  name="usersubmit" class="lite" value="{L_UPDATE}" onclick="ajax.chat_message(2); return false;" title="{L_CHAT_UPDATE}"/>
<input type="button" name="usersubmit" class="lite" value="X" onclick="$('#message').attr('value', ''); $('#message').focus();" title="{L_MINI_CHAT_DROP}" />
<input type="submit"  name="preview" class="lite" value="{L_SUBMIT}" onclick="ajax.chat_message(1); $('#message').attr('value', '');return false;" title="{L_SUBMIT}" />
      </div>
 
        <div class="clear"></div>
        <div class="spacer_2"></div>
        <div id="chat" class="tLeft hidden"></div>
        </form>
      </div>
<script type="text/javascript">
var bbcode = new BBCode("message");
var ctrl = "ctrl";
 
bbcode.addTag("codeB", "b", null, "B", ctrl);
bbcode.addTag("codeI", "i", null, "I", ctrl);
bbcode.addTag("codeU", "u", null, "U", ctrl);
bbcode.addTag("codeQuote", "quote", null, "Q", ctrl);
bbcode.addTag("codeImg", "img", null, "R", ctrl);
bbcode.addTag("codeSpoiler", "spoiler", null, "",  ctrl);

bbcode.addTag("fontFace", function(e) { var v=e.value; e.selectedIndex=0; return "font=\""+v+"\"" }, "/font");
bbcode.addTag("codeSize", function(e) { var v=e.value; e.selectedIndex=0; return "size="+v }, "/size");  
bbcode.addTag("codeColor", function(e) { var v=e.value; e.selectedIndex=0; return "color="+v }, "/color");
  
</script>
  </div>
<!-- ENDIF -->

#
#-----[ ОТКРЫТЬ ]------------------------------------------
#
 templates/default/css/main.css
 
#
#-----[ В САМЫЙ НИЗ ДОБАВИТЬ ]------------------------------------------
#
/*###### МИНИ ЧАТ ######*/
#chat { overflow: auto; width: 100%; height: 350px; }
.chat-comment{
    min-height: 38px;
    height: auto;
    margin: 3px;
    padding: 4px;
    border: solid 1px #AED7FF;
    background-color: #F9FCFF;
	-webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
}
textarea.chat_message{
    height: 40px; 
	width: 99.8%;
	border: 1px solid #AED7FF;
    border-radius: 5px;
    -moz-border-radius: 5px;
    font-size: 11px;
	margin-bottom: 7px;
}
.avatars_chat{
    background-color:#fcfcff;
    padding:2px;
    border:1px solid #c4cad4;
    border-radius:4px;-webkit-border-radius:4px;-moz-border-radius:4px;-khtml-border-radius:4px;
}
/*###### МИНИ ЧАТ/КОНЕЦ ######*/

#
#-----[ ОТКРЫТЬ ]------------------------------------------
#
 language/lang_russian/lang_main.php
 
#
#-----[ В САМЫЙ НИЗ ДОБАВИТЬ ]------------------------------------------
#
// ###### МИНИ ЧАТ ######
$lang['SHOUTBOX_INSERT_NAME'] = 'Вставить имя пользователя';
$lang['SHOUTBOX_ERR'] = 'Нужно ввести сообщение';
$lang['FLOOD_ERROR'] = 'Флуд запрещен!';
$lang['MINI_CHAT'] = 'Мини чат';
$lang['MINI_CHAT_DROP'] = 'Отчистить поле ввода';
$lang['CHAT_UPDATE'] = 'Обновить чат';
// ###### МИНИ ЧАТ/КОНЕЦ ######

#
#-----[ ОТКРЫТЬ ]------------------------------------------
#
 posting.php
 
#
#-----[ НАЙТИ ]------------------------------------------
#
			include(INC_DIR .'functions_torrent.php');
			
#
#-----[ ПЕРЕД ДОБАВИТЬ ]------------------------------------------
#
            // Мини Чат на аякс
            if($mode == 'newtopic'){
            $shoutbox_date = time();
            $link_post = '<b style="color:red;">На трекере новый релиз!!!</b></br><a href="viewtopic.php?t='.$topic_id.'"><b>'.str_replace("\'", "''", $subject).'</b></a>';
            $link_post = DB()->escape($link_post);
            CACHE('bb_cache')->rm('shout_data');
            DB()->query("INSERT bb_shout
                        SET
                        shout_username = 'Bot',
                        shout_user_id = -746,
                        shout_session_time = $shoutbox_date,
                        shout_ip = '',
                        shout_text = '$link_post',
                        shout_active = 0
                        ");}
            // Мини Чат на аякс
			
################################################################
#															   #
#--------------[ СОХРАНИТЬ/ЗАКРЫТЬ ВСЕ ФАЙЛЫ ]-----------------#
#															   #
################################################################