A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
4.2 KiB

<?php
/**
* @package uForum
* @file includes/classes/class_posting.php
* @version $Id$
* @copyright 2007-2010 (c) PioDer <[email protected]>
* @link http://www.pioder.pl/
* @license see LICENSE.txt
**/
if ( !defined('IN_uF') )
{
die('Hacking attempt');
}
class Post
{
function NewPost($tid, $post, $uid)
{
#read last post
$last = DataBase::new_id(POSTS_TABLE);
#read last post in topic
$sql = "SELECT * FROM ".POSTS_TABLE." WHERE t_id='$tid' ORDER BY tp_id DESC LIMIT 1;";
$query = DataBase::sql_query($sql,GENERAL,'Could not last post information.');
$result = DataBase::fetch($query);
$forum = $result['f_id'];//forum id
$moderate = Forum::ForumInformation($forum,'moderate');
$tpid = $result['tp_id'];//post in topic id
$tpid = $tpid+1;
#
$time = $_SERVER['REQUEST_TIME'];
#add new post
$sql = "INSERT INTO `".POSTS_TABLE."` VALUES ('$last','$tid', '$uid', '$post', '".$_SERVER['HTTP_USER_AGENT']."', '$time', '$tpid', '$forum','$moderate','".$_SERVER['REMOTE_ADDR']."')";
$query = DataBase::sql_query($sql,GENERAL,'Could not add new post.');
$result=User::UserInformation($uid,'posts');
$result = $result+1;
TriggerStats($forum, 1);
TriggerStats($tid, 2);
$sql="UPDATE ".USERS_TABLE." SET posts='$result' WHERE u_id='$uid' ";
$query = DataBase::sql_query($sql,GENERAL,'Could not update user information.');
return $tpid;
}
function EditPost($postid, $text)
{
$sql = "UPDATE `".POSTS_TABLE."` SET text='$text' WHERE `p_id`='$postid';";
$query = DataBase::sql_query($sql,GENERAL,'Could not edit post.');
}
function NewTopic($posttext, $ntopic, $forum, $uid, $sticky)
{
//Select last topic
$moderate = Forum::ForumInformation($forum,'moderate');
$time = $_SERVER['REQUEST_TIME'];
$lastt=DataBase::new_id(TOPICS_TABLE);
$sql = "INSERT INTO ".TOPICS_TABLE." VALUES ('$lastt', '$forum', '0', '$sticky', '$ntopic', '$uid','$time', '', '')";
$query = DataBase::sql_query($sql,GENERAL,'Could not add new topic');
//add post
//select last post
$last = DataBase::new_id(POSTS_TABLE);
//add post
$sql = "INSERT INTO ".POSTS_TABLE." VALUES ('$last','$lastt', '$uid', '$posttext','".$_SERVER['HTTP_USER_AGENT']."', '$time', '1', '$forum', '$moderate','".$_SERVER['REMOTE_ADDR']."');";
$query = DataBase::sql_query($sql,GENERAL,'Could not add new post.');
$sql = "SELECT * FROM ".USERS_TABLE." WHERE u_id='$uid';";
$query = DataBase::sql_query($sql,GENERAL,'Could not obtain user information.');
$result = DataBase::fetch($query);
$result = $result['posts'];
$result = $result+1;
TriggerStats($forum, 1);
TriggerStats($lastt, 2);
$sql = "UPDATE ".USERS_TABLE." SET posts='$result' WHERE u_id='$uid' ";
$query = DataBase::sql_query($sql,GENERAL,'Could not update user information.');
return $lastt;
}
function SmilesShow()
{
$text ='';
$result='';
$sql = "SELECT * FROM ".SMILES_TABLE."";
$query = DataBase::sql_query($sql,GENERAL,'Cold not obtain smiles information.');
$i = 1;
while($smile = DataBase::fetch($query))
{
$action = "insertSmile('".$smile['url']."','".$smile['smile']."')";
$mouse = "this.style.cursor='hand';";
$text = "\n".'<img src="'.$smile['url'].'" onmouseover="'.$mouse.'" onclick="'.$action.'" alt="'.$smile['smile'].'">&nbsp;'."\n";
$result = $result.$text;
if ($i%5==0)
{
$i = 1;
$result=$result.'<br>';
}
else
{
$i +=1;
}
}
return $result;
}
function SmilesReplace($text)
{
$sql = "SELECT * FROM ".SMILES_TABLE."";
$query = DataBase::sql_query($sql,GENERAL,'Could not obtain emoticons information.');
$i = 1;
while($result = DataBase::fetch($query))
{
$smile[$i]['smile'] = $result['smile'];
$smile[$i]['url'] = $result['url'];
$i +=1;
}
$smile = (!isset($smile)) ? array() : $smile;
$i = 1;
for($i=1;$i<=count($smile);$i++)
{
$text = str_replace(' '.$smile[$i]['smile'],'<img src="'.$smile[$i]['url'].'" alt="'.$smile[$i]['smile'].'">', $text);
$text = str_replace('&nbsp;'.$smile[$i]['smile'],'<img src="'.$smile[$i]['url'].'" alt="'.$smile[$i]['smile'].'">', $text);
}
return $text;
}
}
?>