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

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file includes/classes/class_posting.php
  5. * @version $Id$
  6. * @copyright 2007-2010 (c) PioDer <pioder@wp.pl>
  7. * @link http://www.pioder.pl/
  8. * @license see LICENSE.txt
  9. **/
  10. if ( !defined('IN_uF') )
  11. {
  12. die('Hacking attempt');
  13. }
  14. class Post
  15. {
  16. function NewPost($tid, $post, $uid)
  17. {
  18. #read last post
  19. $last = DataBase::new_id(POSTS_TABLE);
  20. #read last post in topic
  21. $sql = "SELECT * FROM ".POSTS_TABLE." WHERE t_id='$tid' ORDER BY tp_id DESC LIMIT 1;";
  22. $query = DataBase::sql_query($sql,GENERAL,'Could not last post information.');
  23. $result = DataBase::fetch($query);
  24. $forum = $result['f_id'];//forum id
  25. $moderate = Forum::ForumInformation($forum,'moderate');
  26. $tpid = $result['tp_id'];//post in topic id
  27. $tpid = $tpid+1;
  28. #
  29. $time = $_SERVER['REQUEST_TIME'];
  30. #add new post
  31. $sql = "INSERT INTO `".POSTS_TABLE."` VALUES ('$last','$tid', '$uid', '$post', '".$_SERVER['HTTP_USER_AGENT']."', '$time', '$tpid', '$forum','$moderate','".$_SERVER['REMOTE_ADDR']."')";
  32. $query = DataBase::sql_query($sql,GENERAL,'Could not add new post.');
  33. $result=User::UserInformation($uid,'posts');
  34. $result = $result+1;
  35. TriggerStats($forum, 1);
  36. TriggerStats($tid, 2);
  37. $sql="UPDATE ".USERS_TABLE." SET posts='$result' WHERE u_id='$uid' ";
  38. $query = DataBase::sql_query($sql,GENERAL,'Could not update user information.');
  39. return $tpid;
  40. }
  41. function EditPost($postid, $text)
  42. {
  43. $sql = "UPDATE `".POSTS_TABLE."` SET text='$text' WHERE `p_id`='$postid';";
  44. $query = DataBase::sql_query($sql,GENERAL,'Could not edit post.');
  45. }
  46. function NewTopic($posttext, $ntopic, $forum, $uid, $sticky)
  47. {
  48. //Select last topic
  49. $moderate = Forum::ForumInformation($forum,'moderate');
  50. $time = $_SERVER['REQUEST_TIME'];
  51. $lastt=DataBase::new_id(TOPICS_TABLE);
  52. $sql = "INSERT INTO ".TOPICS_TABLE." VALUES ('$lastt', '$forum', '0', '$sticky', '$ntopic', '$uid','$time', '', '')";
  53. $query = DataBase::sql_query($sql,GENERAL,'Could not add new topic');
  54. //add post
  55. //select last post
  56. $last = DataBase::new_id(POSTS_TABLE);
  57. //add post
  58. $sql = "INSERT INTO ".POSTS_TABLE." VALUES ('$last','$lastt', '$uid', '$posttext','".$_SERVER['HTTP_USER_AGENT']."', '$time', '1', '$forum', '$moderate','".$_SERVER['REMOTE_ADDR']."');";
  59. $query = DataBase::sql_query($sql,GENERAL,'Could not add new post.');
  60. $sql = "SELECT * FROM ".USERS_TABLE." WHERE u_id='$uid';";
  61. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain user information.');
  62. $result = DataBase::fetch($query);
  63. $result = $result['posts'];
  64. $result = $result+1;
  65. TriggerStats($forum, 1);
  66. TriggerStats($lastt, 2);
  67. $sql = "UPDATE ".USERS_TABLE." SET posts='$result' WHERE u_id='$uid' ";
  68. $query = DataBase::sql_query($sql,GENERAL,'Could not update user information.');
  69. return $lastt;
  70. }
  71. function SmilesShow()
  72. {
  73. $text ='';
  74. $result='';
  75. $sql = "SELECT * FROM ".SMILES_TABLE."";
  76. $query = DataBase::sql_query($sql,GENERAL,'Cold not obtain smiles information.');
  77. $i = 1;
  78. while($smile = DataBase::fetch($query))
  79. {
  80. $action = "insertSmile('".$smile['url']."','".$smile['smile']."')";
  81. $mouse = "this.style.cursor='hand';";
  82. $text = "\n".'<img src="'.$smile['url'].'" onmouseover="'.$mouse.'" onclick="'.$action.'" alt="'.$smile['smile'].'">&nbsp;'."\n";
  83. $result = $result.$text;
  84. if ($i%5==0)
  85. {
  86. $i = 1;
  87. $result=$result.'<br>';
  88. }
  89. else
  90. {
  91. $i +=1;
  92. }
  93. }
  94. return $result;
  95. }
  96. function SmilesReplace($text)
  97. {
  98. $sql = "SELECT * FROM ".SMILES_TABLE."";
  99. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain emoticons information.');
  100. $i = 1;
  101. while($result = DataBase::fetch($query))
  102. {
  103. $smile[$i]['smile'] = $result['smile'];
  104. $smile[$i]['url'] = $result['url'];
  105. $i +=1;
  106. }
  107. $smile = (!isset($smile)) ? array() : $smile;
  108. $i = 1;
  109. for($i=1;$i<=count($smile);$i++)
  110. {
  111. $text = str_replace(' '.$smile[$i]['smile'],'<img src="'.$smile[$i]['url'].'" alt="'.$smile[$i]['smile'].'">', $text);
  112. $text = str_replace('&nbsp;'.$smile[$i]['smile'],'<img src="'.$smile[$i]['url'].'" alt="'.$smile[$i]['smile'].'">', $text);
  113. }
  114. return $text;
  115. }
  116. }
  117. ?>