<?php // forum.php :: Foro interno del juego.Version 1.0
define('INSIDE', true);
$ugamela_root_path = './';
include($ugamela_root_path . 'extension.inc');
include($ugamela_root_path . 'common.'.$phpEx);
check_user();
$dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"];
include($ugamela_root_path . 'includes/planet_toggle.'.$phpEx);
function showthread($forum, $start=0) {
global $controlrow;
//старый запрос
//$query = doquery("SELECT * FROM {{table}} WHERE id='$id' OR parent='$id' ORDER BY id LIMIT $start,15", "forum");
//$TreathCount = count(mysql_fetch_array($query));
//новый запрос
$query = doquery("SELECT * FROM {{table}} WHERE topic_id=$forum ORDER BY `post_time` ASC", "forum_posts");
$page = "<table width=\"100%\"><tr><td colspan=2 align=right><a href=\"?new=reply&t=$forum\"><img src=\"images/reply.gif\"></a></td></tr>";
$i=0;$u = 0;
while ($t = mysql_fetch_array($query)) {
if($i==0){$page .= "<tr><td class=c>Автор</td><td class=c>сообщения</td></tr>"; $f=$t['forum_id'];}
$p = doquery("SELECT * FROM {{table}} WHERE post_id='".$t['post_id']."' LIMIT 1", "forum_posts_text",true);
/*
pequeсa preparacion del texto...
solo hay que hacer unos cuantos remplaze, etc...
"pequeсa подготовке текста ...
вы просто должны сделать несколько замены, и т.д. ..."
*/
//$p['post_text'] = str_replace(":".$p['bbcode_uid'],'',$p['post_text']);
//$p['post_text'] = str_replace(":".$p['bbcode_uid'],'',$p['post_text']);
/*
$p['post_text'] = str_replace('',"<font color=\"red\">",$p['post_text']);
$p['post_text'] = str_replace('[color=blue]',"<font color=\"#AFCCFF\">",$p['post_text']);
$p['post_text'] = str_replace('[color=green]',"<font color=\"green\">",$p['post_text']);
$p['post_text'] = str_replace('',"</font>",$p['post_text']);
$p['post_text'] = str_replace('[img]',"<img src=\"",$p['post_text']);
$p['post_text'] = str_replace('[/img]',"\">",$p['post_text']);
$p['post_text'] = str_replace('[i]',"[i]",$p['post_text']);
$p['post_text'] = str_replace('[/i]',"[/i]",$p['post_text']);
$p['post_text'] = str_replace('[b]',"[b]",$p['post_text']);
$p['post_text'] = str_replace('[/b]',"[/b]",$p['post_text']);
$p['post_text'] = str_replace('[u]',"[u]",$p['post_text']);
$p['post_text'] = str_replace('[/u]',"[/u]",$p['post_text']);
$p['post_text'] = str_replace('[list]',"<lu>[*]",$p['post_text']);
$p['post_text'] = str_replace('[/list:u]',"</lu>",$p['post_text']);
$p['post_text'] = str_replace('[url=',"<a href=",$p['post_text']);
$p['post_text'] = str_replace('[/url]',"</a>",$p['post_text']);
$p['post_text'] = str_replace('[QUOTE]',"</td></table>",$p['post_text']);
$p['post_text'] = str_replace(']',">",$p['post_text']);
$p['post_text'] = str_replace('[',"<",$p['post_text']);
*/
//Смайлы!
if($t['enable_smilies'] == 1){ $p['post_text'] = iconnize($p['post_text']);}
if($u != $t['poster_id'] || $controlrow['flood_avatar']){
$page .= "<tr><td class=l width=100 valign=top align=left>";
//}elseif($i==1){$page .= "<tr><td class=l width=100 valign=top align=left>";
}else{$page .= "<tr><td>";}
if($u != $t['poster_id'] || $controlrow['flood_avatar']){
//запрос
$userquery = doquery("SELECT * FROM {{table}} WHERE id=".$t['poster_id']." LIMIT 1", "users",true);
$avatar = "<img src=\"".$userquery['avatar']."\" width=100 class=\"avatar\">";
//имя пользователя
$username = "<a href=\"search.php?searchtext=".$userquery['username']."\">".$userquery['username']."</a>";
//Значёк пола
if($userquery['sex'] == 'M'){$username .= " <img src=\"images/male.gif\">";}
elseif($userquery['sex'] == 'F'){$username .= " <img src=\"images/female.gif\">";}
$page .= "$username
";
$page .= ($userquery['avatar'] != '') ? $avatar : "";
$page .= "
".date("M d Y",$userquery['register_time']);
}
if($i==1){$page .= "</td><td class=b valign=top align=left>";}else{$page .= "</td><td class=f valign=top align=left>";}
$page .= nl2br($p['post_text'])."</td></tr>";
if($i==1){$i=2;}else{$i=1;}
//Предотвращение флуда
$u = $t['poster_id'];
}
if($i==0){message("Темы не существует","Просмотр темы", 'forum.php');}
//Мы добавляем вразрез с table_forum_topics
doquery("UPDATE {{table}} SET `topic_views` = `topic_views`+ 1 WHERE `topic_id`=$forum;", "forum_topics");
$page .= "<tr><td class=c colspan=4><a id=last href=?f=$f>Назад</a></td></tr></table>";
display($page, "Форум",true,true,false);
}
function reply($topic) {
global $user;
if(!$user){message("Для ответа на сообщение, вам необходимо войти в игру.","Ответить");}
$topic_id = doquery("SELECT * FROM {{table}} WHERE topic_id=$topic", "forum_topics",true);
if(!$topic_id){message("Темы не существует","Создать новую тему","forum.php");}
if(isset($_POST["post"])) {
extract($_POST);
/*
Мы делаем "заказ"
*/
$postnumber = doquery("SELECT MAX(post_id) AS post_id FROM {{table}};","forum_posts_text",true);
$post_id = $postnumber["post_id"] + 1;
$forum_id = $topic_id['forum_id'];
//$topicnumber = doquery("SELECT MAX(topic_id) AS topic_id FROM {{table}};","forum_topics",true);
$topic_id = $topic;
//Преобразование текста, который будет в безопасности во время запроса ...
$content = CleanStr($content);
//это будет текст
doquery("INSERT INTO {{table}} SET `post_id`=$post_id, `bbcode_uid`='', `post_subject`='$title', `post_text`=\"$content\";","forum_posts_text");
//это будет индекс
doquery("INSERT INTO {{table}} SET `post_id`=$post_id, `topic_id`=$topic_id, `forum_id`=$forum_id, `poster_id`=".$user['id'].", `post_time`=".time().", `poster_ip`='be5577eb', `post_username`='', `enable_bbcode`=1, `enable_html`=0, `enable_smilies`=1, `enable_sig`=1, `post_edit_count`=0;","forum_posts");
//обновления темы
doquery("UPDATE {{table}} SET `topic_time`=".time().", topic_replies=topic_replies+1, `topic_last_post_id`=$post_id WHERE `topic_id`=$topic_id;","forum_topics");
message("Тема была успешно создана. Сейчас вы будете перемещены.","Создать новую тему","forum.php?t=$topic_id#last");
}
$topic_title = $topic_id["topic_title"];
//formulario
form($page,$topic_title,"forum.php?new=reply&t=$topic");
display($page, "Forum");
}
function newthread($forum_id) {
global $user;
if(!$user){message("Чтобы создать тему, вам необходимо Войти.","Создать тему");}
$forum_cat = doquery("SELECT * FROM {{table}} WHERE forum_id=$forum_id", "forum_cat",true);
if(!$forum_cat){message("Форум не существует","Создать новую тему","forum.php");}
/*
Форма для создания новой темы
*/
if(isset($_POST["post"])) {
extract($_POST);
/*
Мы делаем заказ
*/
$postnumber = doquery("SELECT MAX(post_id) AS post_id FROM {{table}};","forum_posts_text",true);
$post_id = $postnumber["post_id"] + 1;
$topicnumber = doquery("SELECT MAX(topic_id) AS topic_id FROM {{table}};","forum_topics",true);
$topic_id = $topicnumber["topic_id"] + 1;
//это будет индекс
doquery("INSERT INTO {{table}} SET `post_id`=$post_id, `topic_id`=$topic_id, `forum_id`=$forum_id, `poster_id`=".$user['id'].", `post_time`=".time().", `poster_ip`='be5577eb', `post_username`='', `enable_bbcode`=1, `enable_html`=0, `enable_smilies`=1, `enable_sig`=1, `post_edit_count`=0;","forum_posts");
//это будет текст
doquery("INSERT INTO {{table}} SET `post_id`=$post_id, `bbcode_uid`='', `post_subject`='$title', `post_text`='$content';","forum_posts_text");
//это тема
doquery("INSERT INTO {{table}} SET `topic_id`=$topic_id, `forum_id`=$forum_id, `topic_title`='$title', `topic_poster`=".$user['id'].", `topic_time`=".time().", topic_first_post_id=$topic_id","forum_topics");
doquery("UPDATE {{table}} SET forum_topics=forum_topics+1, `forum_last_post_id`=$post_id WHERE `forum_id`=$forum_id;","forum_cat");
message("Новая тема была успешно добавлена. В момент, когда вы будете перенаправлены.","Создать новую тему","forum.php?f=$forum_id");
}
$page = $forum_cat["forum_name"];
form($page,"Nuevo tema - ".$forum_cat['forum_name'],"forum.php?new=thread&f=$forum_id");
display($page, "Forum");
}
function showtopic($forum){
$query_cat = doquery("SELECT forum_name FROM {{table}} WHERE forum_id=$forum", "forum_cat",true);
$query = doquery("SELECT * FROM {{table}} WHERE forum_id=$forum ORDER BY `topic_type` DESC, `topic_time` DESC ", "forum_topics");
//[url=".PHP_SELF."]Foro[/url] -> ".$query_cat['forum_name']."</th>
$page = "<table width=\"100%\"><tr><td style=\"font-size:14px;\" colspan=5>".$query_cat['forum_name']."</td><td align=right><a href=\"?new=thread&f=$forum\"><img src=\"images/post.gif\"></a></tr>";
$i = 0;
while($t = mysql_fetch_array($query)){
if($i == 0){$page .= "<tr><td class=\"c\" colspan=2 align=center>Темы</td><td class=c align=center>Ответов</td><td class=c align=center>Автор</td><td class=c align=center>Просмотров</td><td class=c align=center>Последнее сообщение</td></tr>";}
//просмотров последнему сообщению
$query_user = doquery("SELECT username FROM {{table}} WHERE id=".$t['topic_poster'],"users",true);
$lastpost = date("M d, h:m a",$t['topic_time'])."
";
$lastpost .= "<a href=\"search.php?searchtext=".$query_user['username']."\">";
$lastpost .= $query_user["username"]."</a> <a href=?t=".$t['topic_id']."#last";
$lastpost .= " title=\"Ver ъltimo mensaje\"><img src=\"images/icon_latest_reply.gif\" alt=\">\"></a>";
$page .= "<tr><th width=20><a href=\"?t=".$t['topic_id']."\">";
//Зависит от значка
if($t['topic_type'] == 0){
$page .= "<img src=\"images/topicnew.gif\" title=\"Post\">";
}elseif($t['topic_vote'] == 1){//голосовать
$page .= "<img src=\"images/vote.gif\" title=\"Votación\">";
}elseif($t['topic_type'] == 2){//объявление!
$page .= "<img width=25 src=\"images/anc.gif\" title=\"Anuncio\">";
}elseif($t['topic_type'] == 1){//объявление!
$page .= "<img src=\"images/topichot.gif\" title=\"Написать\">";
}else{$page .= "<img src=\"images/topicnew.gif\" title=\"Написать\">";}
$t["topic_title"] = ($t["topic_title"]=='')?'Без названия':$t["topic_title"];
$page .= "</a></th><th><a href=\"?t=".$t['topic_id']."\">".$t["topic_title"]."</a></th>";
$page .= "<th align=center>".$t['topic_replies']."</th>";
$page .= "<th align=center><a href=\"search.php?searchtext=".$query_user['username']."\">";
$page .= $query_user["username"]."</a></th>";
$page .= "<th align=center>".$t['topic_views']."</th>";
$page .= "<th align=center>$lastpost</th>";
$i++;
//$page .= "</table></td></tr>";
}
$page .= "<tr><td class=c colspan=6><a href=forum.php>Назад</a></td></tr></table></td></tr></table>";
display($page, "Форум",true,true,false);
/*
while($t = mysql_fetch_array($query)){
if($user["authlevel"] == 1 && $c["auth_read"] != 0 ){
$page .= "<tr><td class=c style=\"background-color:#3F0808;\"><img src=\"images/folder.gif\"></td><td style=\"background-color:#3F0808;\"><a href=?topic=".$t['forum_id'].">".$t["topic_title"]."</a>
";
$page .= "".$c["forum_desc"]."</td><td style=\"background-color:#3F0808;\"t>Post: ".$t["forum_posts"]."
Temas: ".$t["forum_topics"]."</td></tr>";
}*//*
}
$page .= "<tr><td colspan=4>[<a href=index.php>Назад</a>]</td></tr></table></td></tr></table>";
display($page, "Форум",true,true,false);
*/
}
function showcategories(){
global $user,$lang;
//el title del foro y head.
$page = "<table width=\"100%\"><tr><td class=c colspan=5>Внутренний форум ".$lang['TITLE_GAME']."</td></tr>";
$query_cat = doquery("SELECT * FROM {{table}}", "forum_categories");
$i = 0;
while($c_name = mysql_fetch_array($query_cat)){
if($i == 0){ $page .= "<tr><td colspan=2 class=\"c\">Форум</th><td class=\"c\">Темы</td><td class=\"c\">Сообщения</td><td class=\"c\">Последнее сообщение</td></tr>";}
$page .= "<tr><th colspan=5>".$c_name["cat_title"]."</th></tr>";
$query = doquery("SELECT * FROM {{table}} WHERE cat_id=".$c_name["cat_id"], "forum_cat");
while($c = mysql_fetch_array($query)){
//просмотров последнему сообщению
if($c['forum_last_post_id'] != 0){
//pedimos el post
$query_topic = doquery("SELECT `topic_poster`,`topic_title`,`topic_time`,`topic_first_post_id` FROM {{table}} WHERE forum_id=".$c['forum_id']." ORDER BY `topic_time` DESC LIMIT 1", "forum_topics",true);
$query_user = doquery("SELECT username FROM {{table}} WHERE id=".$query_topic['topic_poster'],"users",true);
/*
Текст для части, где он говорит Последнее сообщение
*/
$query_topic["topic_title"] = ($query_topic["topic_title"]=='')?'Sin titulo':$query_topic["topic_title"];
$lastpost = "<a href=\"?t=".$query_topic['topic_first_post_id']."\" title=\"".$query_topic['topic_title']."\">";
$lastpost .= substr($query_topic['topic_title'],0,10)." ...</a>
";
$lastpost .= date("M d, h:m a",$query_topic['topic_time']);
$lastpost .= "
<a href=\"search.php?searchtext=".$query_user['username']."\">";
$lastpost .= $query_user["username"]."</a>";
$lastpost .= " <a href=?t=".$query_topic['topic_first_post_id']."#last title=\"Ver ъltimo mensaje\">";
$lastpost .= "<img src=\"images/icon_latest_reply.gif\" alt=\">\"></a>";
}else{$lastpost = "Нету сообщений";}
if($c["auth_read"] == 0 ||($user["authlevel"] == 1 && $c["auth_read"] != 0)){
$page .= "<tr><td width=20 class=l><a href=?f=".$c['forum_id']."><img src=\"";
//чтобы показать, как новое сообщение темы
if(isset($c["topic_status"]) && $c["topic_status"] == 0 && $c["forum_topics"] != 0 && $query_topic['topic_time'] >= time() - 60*60*6){
$page .= "images/new_2.gif";
}elseif(isset($c["topic_status"]) && $c["topic_status"] == 0){
$page .= "images/old_2.gif";
}else{
$page .= "images/lock.gif";
}
$page .= "\"></a></td><td class=l><a href=?f=".$c['forum_id'].">".$c["forum_name"]."</a>
";
$page .= "".$c["forum_desc"]."</td>";
$page .= "<td class=l width=50 align=center>".$c["forum_topics"]."</td>";
$page .= "<td class=l width=50 align=center>".$c["forum_posts"]."</td>";
$page .= "<td class=l width=110 align=center>$lastpost</td></tr>";
}
}
$i++;
$page .= "";
}
$page .= "</td></tr></table>";
display($page, "Форум");
}
function form(&$page, $title,$dest=''){
$page .= <<<END
<form action="$dest" name="post" method=post>
<table width="100%">
<tr>
<td colspan=2>$title</td>
</tr>
<tr>
<td colspan=2 class="c">Ответить</td>
</tr>
<tr>
<td>
<div align="right">[b]Тема:[/quote]
</td>
<td >
<div align="left">
<input type=text name=title size=50 maxlength=50 />
[/QUOTE]
</td>
</tr>
<tr>
<td class="l"><table border="0" cellpadding="2" cellspacing="0" width="100" align="center">
<tbody><tr align="center">
<td colspan="4">Смайлы</td>
</tr>
<tr align="center">
<td>[url="java script:emoticon(':D')"][img]images/smiles/icon_biggrin.gif[/img][/url]</td>
<td>[url="java script:emoticon(':)')"][img]images/smiles/icon_smile.gif[/img][/url]</td>
<td>[url="java script:emoticon(':(')"][img]images/smiles/icon_sad.gif[/img][/url]</td>
<td>[url="java script:emoticon(':o')"][img]images/smiles/icon_surprised.gif[/img][/url]</td>
</tr>
<tr align="center">
<td>[url="java script:emoticon(':shock:')"][img]images/smiles/icon_eek.gif[/img][/url]</td>
<td>[url="java script:emoticon(':?')"][img]images/smiles/icon_confused.gif[/img][/url]</td>
<td>[url="java script:emoticon('8)')"][img]images/smiles/icon_cool.gif[/img][/url]</td>
<td>[url="java script:emoticon(':lol:')"][img]images/smiles/icon_lol.gif[/img][/url]</td>
</tr>
<tr align="center">
<td>[url="java script:emoticon(':x')"][img]images/smiles/icon_mad.gif[/img][/url]</td>
<td>[url="java script:emoticon(':P')"][img]images/smiles/icon_razz.gif[/img][/url]</td>
<td>[url="java script:emoticon(':oops:')"][img]images/smiles/icon_redface.gif[/img][/url]</td>
<td>[url="java script:emoticon(':cry:')"][img]images/smiles/icon_cry.gif[/img][/url]</td>
</tr>
<tr align="center">
<td>[url="java script:emoticon(':evil:')"][img]images/smiles/icon_evil.gif[/img][/url]</td>
<td>[url="java script:emoticon(':twisted:')"][img]images/smiles/icon_twisted.gif[/img][/url]</td>
<td>[url="java script:emoticon(':roll:')"][img]images/smiles/icon_rolleyes.gif[/img][/url]</td>
<td>[url="java script:emoticon(':wink:')"][img]images/smiles/icon_wink.gif[/img][/url]</td>
</tr>
<tr align="center">
<td>[url="java script:emoticon(':!:')"][img]images/smiles/icon_exclaim.gif[/img][/url]</td>
<td>[url="java script:emoticon(':?:')"][img]images/smiles/icon_question.gif[/img][/url]</td>
<td>[url="java script:emoticon(':idea:')"][img]images/smiles/icon_idea.gif[/img][/url]</td>
<td>[url="java script:emoticon(':arrow:')"][img]images/smiles/icon_arrow.gif[/img][/url]</td>
</tr>
<tr align="center">
<td colspan="4" class="nav">[url="forum.php?mode=smilies"]Версия мас смайлики[/url]</td>
</tr>
</tbody></table></td>
<td>
<table border="0" cellpadding="2" cellspacing="0" width="450">
<tbody><tr align="center">
</tr>
<tr>
<td colspan="9">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td colspan="9">
</td>
</tr>
<tr>
<td colspan="9">
<textarea name="content" rows="15" cols="35" style="width: 450px;" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);">
</textarea>
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td class=c colspan=1>[url="java script:history.back(1);"]Назад[/url]</td>
<td class=c colspan=2><input accesskey="s" tabindex="6" name="post" class="mainoption" value="Послать" type="submit"></td>
</tr>
</table>
</form>
<script>
function emoticon(text) {
var txtarea = document.post.content;
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}
</script>
END;
}
function CleanStr($str){
//global $admin;
$str = trim($str);//ђж“Є‚Ж––”ц‚М‹у”’Џњ‹Ћ
if (get_magic_quotes_gpc()) {//ЃЏ‚рЌнЏњ
$str = stripslashes($str);
}
//if($admin!=ADMIN_PASS){//ЉЗ—ќЋТ‚Нѓ^ѓO‰В”\
$str = htmlspecialchars($str);//ѓ^ѓO‚Б‹ЦЋ~
$str = str_replace("&", "&", $str);//“БЋк•¶Ћљ
//}
str_replace("\"", "\"", $str);
str_replace("\n", "\\n", $str);
return str_replace(",", ",", $str);//ѓJѓ“ѓ}‚р•ПЉ·
}
function iconnize($str){
global $phpEx;
//Este archivo contiene la lista de emoticos y demas graficos
include($ugamela_root_path . 'images/smiles/list.'.$phpEx);
foreach($array as $a => $b) {
$str = str_replace($a," <img src=\"$b\" alt=\"$a\">", $str);
}
return $str;
}
function smilies(){
global $phpEx;
$page = '<a name="top" id="top"></a><script language="javascript" type="text/javascript">
<!--
function emoticon(text) {
text = \' \' + text + \' \';
if (opener.document.forms[\'post\'].content.createTextRange && opener.document.forms[\'post\'].content.caretPos) {
var caretPos = opener.document.forms[\'post\'].content.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == \' \' ? text + \' \' : text;
opener.document.forms[\'post\'].content.focus();
} else {
opener.document.forms[\'post\'].content.value += text;
opener.document.forms[\'post\'].content.focus();
}
}
//-->
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="10"><tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="c">Emoticons</td>
</tr><tr><th class="c"><table width="100" border="0" cellspacing="0" cellpadding="5">';
/*
Los iconos se leen desde el list.php
Ahi se encuentra el catalogo de emoticons
*/
include($ugamela_root_path . 'images/smiles/list.'.$phpEx);
$i = 0;
foreach($array as $a => $b) {
if($i==0){$page .= "<tr align=\"center\">\n";}
$i++;
$page .= "<td><a href=\"java script:emoticon('$a')\"><img src=\"$b\" alt=\"$c\" width=\"15\" height=\"15\" border=\"0\" title=\"$c\" /></a></td>\n";
if($i==8){$i=0;$page .= "</tr>\n";}
}
if($i!=0){$page .= "</tr>\n";}
//Cierra los dos tables
$page .= "</table>\n</td>\n</tr>\n<tr>\n<td class=\"c\" align=\"center\">";
$page .= "<a href=\"java script:window.close();\">Cerrar Ventana</a>\n";
$page .= "</td>\n</tr>\n</table>\n</td>\n</tr>\n</table>";
display($page,'Смайлы',false);
die();
}
/*
Форум!!!
*/
if (isset($f) && isset($new) && is_numeric($f) && $new == "thread"){ newthread($f);}
elseif(isset($t) && isset($new) && is_numeric($t) && $new == "reply"){ reply($t);}
elseif(isset($f) && is_numeric($f)){ showtopic($f);}
elseif(isset($t) && is_numeric($t)){ showthread($t);}
elseif(isset($mode) && $mode == 'smilies'){smilies();}
else { showcategories(); }
?>