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.

255 lines
8.1 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file search.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. define('IN_uF', true);
  11. //include files
  12. include('./config.php');
  13. include('./includes/constants.php');
  14. include('./includes/db.php');
  15. include('./includes/errors.php');
  16. //connect to database
  17. DataBase::db_connect();
  18. include('./includes/sessions.php');
  19. include('./includes/classes/class_user.php');
  20. include('./common.php');
  21. include('./includes/misc_functions.php');
  22. include('./includes/classes/class_forum.php');
  23. include('./includes/classes/class_topic.php');
  24. include('./includes/classes/secure.php');
  25. $default_lang = DefaultLang();
  26. include('./lngs/'.$default_lang.'/main.php');
  27. $start = TimeGeneration();
  28. $default_skin = ViewSkinName();
  29. SessDelInvalid();
  30. SessRegister();
  31. SessDeleteOld();
  32. $sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".u_id = ".POSTS_TABLE.".u_id ORDER BY `ptime`";
  33. $query = DataBase::sql_query($sql,'GENERAL', 'Could not obtain amout of posts in forum');
  34. while($result = @mysql_fetch_array($query))
  35. {
  36. $lastpost[$result['t_id']]['tp_id']=$result['tp_id'];
  37. $lastpost[$result['t_id']]['u_id']=$result['u_id'];
  38. $lastpost[$result['t_id']]['time']=$result['ptime'];
  39. $lastpost[$result['t_id']]['user_nick']=$result['nick'];
  40. $lastpost[$result['t_id']]['user_rank']=$result['rank'];
  41. }
  42. $sql = "SELECT COUNT(*) as `p_id`, `t_id` FROM ".POSTS_TABLE." GROUP BY `t_id`";
  43. $query = DataBase::sql_query($sql,'GENERAL', 'Could not obtain amout of posts in forum');
  44. while($result = @mysql_fetch_array($query))
  45. {
  46. $count_topic[$result['t_id']]=$result['p_id'];
  47. }
  48. if (!isset($_GET['content']))
  49. {
  50. header('Location: search.php?content=posts');
  51. }
  52. //
  53. //generate output pages
  54. //
  55. if ($_SESSION['uid']>0)
  56. {
  57. $limiter = $userdata['limit_ftid'];
  58. }
  59. else
  60. {
  61. $limiter = $forum_config['limit_ftid'];
  62. }
  63. if (isset($_GET['page'])&&($_GET['page']!=1))
  64. {
  65. if (!is_numeric($_GET['page']))
  66. {
  67. die('Hacking attempt');
  68. }
  69. $value = ($_GET['page']-1)*$limiter;
  70. $limit = 'LIMIT '.$value . ', '.$limiter;
  71. $page = $_GET['page'];
  72. }
  73. else
  74. {
  75. $limit = 'LIMIT 0, '.$limiter;
  76. $page=1;
  77. }
  78. //
  79. //end generating pages
  80. //
  81. if ((isset($_POST['keywords'])) || ($_GET['content']=='lastposts') || ($_GET['content']=='userposts'))
  82. {
  83. $errors = true;
  84. switch($_GET['content'])
  85. {
  86. case 'lastposts':
  87. {
  88. if ($_SESSION['uid']>0)
  89. {
  90. $time = time()-129600;
  91. $sql = "SELECT ".TOPICS_TABLE.".*, ".USERS_TABLE.".* FROM ".TOPICS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".TOPICS_TABLE.".author = ".USERS_TABLE.".u_id WHERE lastpost_time>$time ORDER BY `sticky` DESC, `lastpost_time` DESC LIMIT 60;";
  92. $errors = false;
  93. $window_title = $lng['showlast30posts'];
  94. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['showlast30posts'];
  95. break;
  96. }
  97. else
  98. {
  99. message_forum($lng['youarenotlogd'],'login.php?mode=login');
  100. break;
  101. }
  102. }
  103. case 'userposts':
  104. {
  105. if (isset($_GET['u']))
  106. {
  107. $count = @mysql_fetch_array(DataBase::sql_query("SELECT COUNT(`t_id`) as `t_id`
  108. FROM ".TOPICS_TABLE." WHERE `author`='".intval($_GET['u'])."'",'GENERAL','Could not obtain count amout of topics'));
  109. $count = $count['t_id'];
  110. $count = ceil($count / $limiter);
  111. if ($count==0)
  112. {
  113. $count +=1;
  114. }
  115. if(isset($_GET['page']) && ($_GET['page']>$count))
  116. {
  117. message_forum($lng['invalidpage'],'index.php');
  118. }
  119. $sql = "SELECT ".TOPICS_TABLE.".*, ".USERS_TABLE.".* FROM ".TOPICS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".TOPICS_TABLE.".author = ".USERS_TABLE.".u_id WHERE `u_id`='".intval($_GET['u'])."' ORDER BY `sticky` DESC, `lastpost_time` DESC $limit;";
  120. $errors = false;
  121. $window_title = $lng['view_user_topics'];
  122. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['view_user_topics'];
  123. break;
  124. }
  125. else
  126. {
  127. message_forum($lng['no_user'],'index.php');
  128. break;
  129. }
  130. }
  131. case 'posts':
  132. {
  133. if(strlen(trim($_POST['keywords']))>=3)
  134. {
  135. $keyword = explode(' ', strip_tags(addslashes($_POST['keywords'])));
  136. $like_where = ' `text` LIKE \'%'.$keyword[0].'%\'';
  137. for($i=1; $i<count($keyword);$i++)
  138. {
  139. $like_where .=' OR `text` LIKE \'%'.$keyword[$i].'%\'';
  140. }
  141. $sql = "SELECT COUNT(".TOPICS_TABLE.".t_id) as `count`, ".POSTS_TABLE.".* FROM ".TOPICS_TABLE." LEFT JOIN ".POSTS_TABLE." ON ".POSTS_TABLE.".t_id = ".TOPICS_TABLE.".t_id WHERE $like_where GROUP BY `t_id`";
  142. $count = @mysql_fetch_array(DataBase::sql_query($sql,'GENERAL','Could not obtain count amout of topics'));
  143. $count = $count['count'];
  144. $count = ceil($count / $limiter);
  145. if ($count==0)
  146. {
  147. $count +=1;
  148. }
  149. if(isset($_GET['page']) && ($_GET['page']>$count))
  150. {
  151. message_forum($lng['invalidpage'],'index.php');
  152. }
  153. $sql = "SELECT ".TOPICS_TABLE.".*, ".USERS_TABLE.".*, ".POSTS_TABLE.".* FROM ".TOPICS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".TOPICS_TABLE.".author = ".USERS_TABLE.".u_id LEFT JOIN ".POSTS_TABLE." ON ".POSTS_TABLE.".t_id = ".TOPICS_TABLE.".t_id WHERE $like_where ORDER BY `sticky` DESC, `lastpost_time` DESC $limit;";
  154. $window_title = $lng['search_results'];
  155. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['search_results'];
  156. $errors = false;
  157. }
  158. else
  159. {
  160. message_forum($lng['too_short_keywords'],'search.php?content=posts');
  161. }
  162. break;
  163. }
  164. }
  165. if (!$errors)
  166. {
  167. //add skin variables
  168. $skin = array(
  169. 'lposts'=>$lng['posts'],
  170. 'llastposts'=>$lng['lastpost'],
  171. 'lposts'=>$lng['posts'],
  172. 'lauthor'=>$lng['author'],
  173. 'llastpost'=>$lng['lastpost'],
  174. 'ltopicname'=>$lng['ltopicname'],
  175. 'lang'=> $default_lang
  176. );
  177. $skin = array_push_associative($skin,GenerateHeader($window_title,$navigator_title));
  178. include('./skins/'.$default_skin.'/overall_header.tpl');
  179. include('./skins/'.$default_skin.'/forum_body.tpl');
  180. $query = DataBase::sql_query($sql,'GENERAL', 'Could not obtain topics information');
  181. $value = mysql_num_rows($query);
  182. if ($value>0)
  183. {
  184. $isset_topics = array();
  185. while($record = mysql_fetch_array($query))
  186. {
  187. if (!in_array($record['t_id'], $isset_topics))
  188. {
  189. $skin = array(
  190. 't_id'=>$record['t_id'],
  191. 'fname'=>($record['sticky']=='1') ? '<b>'.$lng['sticky'].'</b>'.$record['name'] : $record['name'],
  192. 'author'=>Topic::TopicAuthor($record['author']),
  193. 'new_post'=>Topic::LastPostImg(),
  194. 'tposts'=>$count_topic[$record['t_id']],
  195. 'lastpost'=>Topic::LastPostInTopic($record['t_id'])
  196. );
  197. include('./skins/'.$default_skin.'/forum_forum_add.tpl');
  198. array_push($isset_topics, $record['t_id']);
  199. }
  200. }
  201. }
  202. else
  203. {
  204. echo '<tr><td width="'.TABLES_WIDTH.'" colspan="10" height="19" class="fitem"><p class="fstandard" align="center">'.$lng['nopost'].'!</p></td></tr>';
  205. }
  206. if ($_GET['content']=='lastposts')
  207. {
  208. echo '</table>';
  209. }
  210. else
  211. {
  212. $skin = array(
  213. 'option_pages' => AddPages(),
  214. 'lwith' => $lng['with'],
  215. 'lpage' => $lng['page'],
  216. 'lpages' => $count,
  217. );
  218. include('./skins/'.$default_skin.'/search_end_body.tpl');
  219. }
  220. }
  221. }
  222. else
  223. {
  224. $skin = array(
  225. 'mainpage'=>$lng['lsearch'],
  226. 'lsubmit'=>$lng['search'],
  227. 'lreset'=>$lng['reset'],
  228. 'insert_keywords'=>$lng['insert_keywords']
  229. );
  230. $window_title = $lng['lsearch'];
  231. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['lsearch'];
  232. $skin = array_push_associative($skin,GenerateHeader($window_title,$navigator_title));
  233. include('./skins/'.$default_skin.'/overall_header.tpl');
  234. include('./skins/'.$default_skin.'/search_body.tpl');
  235. }
  236. if ($_SESSION['uid']>0)
  237. {
  238. if(RANK=='2')
  239. {
  240. $skin['pa_link']='<a href="admin/index.php" class="fsmall"><b>'.$lng['pa_link'].'</b></a>';
  241. }
  242. else
  243. {
  244. $skin['pa_link']='';
  245. }
  246. }
  247. else
  248. {
  249. $skin['pa_link']='';
  250. }
  251. $stop = TimeGeneration();
  252. $skin['queries'] = ShowQueries($start, $stop);
  253. include('./skins/'.$default_skin.'/overall_footer.tpl');
  254. ?>