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.

308 lines
9.2 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 = DataBase::fetch($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 = DataBase::fetch($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 ($_GET['content'] == 'userposts' || $_GET['content'] == 'lastposts')
  64. {
  65. if (isset($_GET['page'])&&($_GET['page']!=1))
  66. {
  67. if (!is_numeric($_GET['page']))
  68. {
  69. die('Hacking attempt');
  70. }
  71. $value = ($_GET['page']-1)*$limiter;
  72. $limit = 'LIMIT '.$value . ', '.$limiter;
  73. $page = $_GET['page'];
  74. }
  75. else
  76. {
  77. $limit = 'LIMIT 0, '.$limiter;
  78. $page=1;
  79. }
  80. }
  81. else
  82. {
  83. if (isset($_POST['page'])&&($_POST['page']!=1))
  84. {
  85. if (!is_numeric($_POST['page']))
  86. {
  87. die('Hacking attempt');
  88. }
  89. $value = ($_POST['page']-1)*$limiter;
  90. $limit = 'LIMIT '.$value . ', '.$limiter;
  91. $page = $_POST['page'];
  92. }
  93. else
  94. {
  95. $limit = 'LIMIT 0, '.$limiter;
  96. $page=1;
  97. }
  98. }
  99. //
  100. //end generating pages
  101. //
  102. if ((isset($_POST['keywords'])) || ($_GET['content']=='lastposts') || ($_GET['content']=='userposts'))
  103. {
  104. $errors = true;
  105. switch($_GET['content'])
  106. {
  107. case 'lastposts':
  108. {
  109. if ($_SESSION['uid']>0)
  110. {
  111. $time = time()-129600;
  112. $sql = "SELECT COUNT(`t_id`) as `cnt` FROM ".TOPICS_TABLE." WHERE lastpost_time>$time";
  113. $count = DataBase::fetch(DataBase::sql_query($sql,GENERAL,'Could not obtain count amout of topics'));
  114. $count = $count['cnt'];
  115. $count = ceil($count / $limiter);
  116. if ($count==0)
  117. {
  118. $count +=1;
  119. }
  120. if(isset($_GET['page']) && ($_GET['page']>$count))
  121. {
  122. message_forum($lng['invalidpage'],'index.php');
  123. }
  124. $sql = "SELECT ".TOPICS_TABLE.".*, ".USERS_TABLE.".*, ".TOPICS_TABLE.".posts AS posts
  125. FROM ".TOPICS_TABLE."
  126. LEFT JOIN ".USERS_TABLE." ON ".TOPICS_TABLE.".author = ".USERS_TABLE.".u_id
  127. WHERE lastpost_time>$time
  128. ORDER BY `sticky` DESC, `lastpost_time` DESC $limit";
  129. $errors = false;
  130. $window_title = $lng['showlastposts'];
  131. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['showlastposts'];
  132. break;
  133. }
  134. else
  135. {
  136. message_forum($lng['youarenotlogd'],'login.php?mode=login');
  137. break;
  138. }
  139. }
  140. case 'userposts':
  141. {
  142. if (isset($_GET['u']))
  143. {
  144. $count = DataBase::fetch(DataBase::sql_query("SELECT COUNT(`t_id`) as `t_id`
  145. FROM ".TOPICS_TABLE." WHERE `author`='".intval($_GET['u'])."'",GENERAL,'Could not obtain count amout of topics'));
  146. $count = $count['t_id'];
  147. $count = ceil($count / $limiter);
  148. if ($count==0)
  149. {
  150. $count +=1;
  151. }
  152. if(isset($_GET['page']) && ($_GET['page']>$count))
  153. {
  154. message_forum($lng['invalidpage'],'index.php');
  155. }
  156. $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;";
  157. $errors = false;
  158. $window_title = $lng['view_user_topics'];
  159. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['view_user_topics'];
  160. break;
  161. }
  162. else
  163. {
  164. message_forum($lng['no_user'],'index.php');
  165. break;
  166. }
  167. }
  168. case 'posts':
  169. {
  170. if(strlen(trim($_POST['keywords']))>=3)
  171. {
  172. $keyword = explode(' ', strip_tags(addslashes($_POST['keywords'])));
  173. $like_where = ' `text` LIKE \'%'.$keyword[0].'%\'';
  174. for($i=1; $i<count($keyword);$i++)
  175. {
  176. $like_where .=' OR `text` LIKE \'%'.$keyword[$i].'%\'';
  177. }
  178. $sql = "SELECT ".POSTS_TABLE.".t_id, ".POSTS_TABLE.".text
  179. FROM ".TOPICS_TABLE."
  180. LEFT JOIN ".POSTS_TABLE." ON ".POSTS_TABLE.".t_id = ".TOPICS_TABLE.".t_id
  181. WHERE $like_where GROUP BY `t_id`";
  182. echo $sql;
  183. $count = DataBase::sql_query($sql,GENERAL,'Could not obtain count amout of topics');
  184. $count = DataBase::num_rows($count);//$count['count'];
  185. $count = ceil($count / $limiter);
  186. if ($count==0)
  187. {
  188. $count +=1;
  189. }
  190. if(isset($_GET['page']) && ($_GET['page']>$count))
  191. {
  192. message_forum($lng['invalidpage'],'index.php');
  193. }
  194. $sql = "SELECT ".TOPICS_TABLE.".*, ".USERS_TABLE.".*, ".POSTS_TABLE.".*, ".TOPICS_TABLE.".posts AS posts
  195. FROM ".TOPICS_TABLE."
  196. LEFT JOIN ".USERS_TABLE." ON ".TOPICS_TABLE.".author = ".USERS_TABLE.".u_id
  197. LEFT JOIN ".POSTS_TABLE." ON ".POSTS_TABLE.".t_id = ".TOPICS_TABLE.".t_id
  198. WHERE $like_where
  199. ORDER BY `sticky` DESC, `lastpost_time` DESC $limit;";
  200. $window_title = $lng['search_results'];
  201. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['search_results'];
  202. $errors = false;
  203. }
  204. else
  205. {
  206. message_forum($lng['too_short_keywords'],'search.php?content=posts');
  207. }
  208. break;
  209. }
  210. }
  211. if (!$errors)
  212. {
  213. //add skin variables
  214. $skin = array(
  215. 'lposts'=>$lng['posts'],
  216. 'llastposts'=>$lng['lastpost'],
  217. 'lposts'=>$lng['posts'],
  218. 'lauthor'=>$lng['author'],
  219. 'llastpost'=>$lng['lastpost'],
  220. 'ltopicname'=>$lng['ltopicname'],
  221. 'lang'=> $default_lang
  222. );
  223. $skin = array_push_assoc($skin,GenerateHeader($window_title,$navigator_title));
  224. include('./skins/'.$default_skin.'/overall_header.tpl');
  225. include('./skins/'.$default_skin.'/forum_body.tpl');
  226. $query = DataBase::sql_query($sql,GENERAL, 'Could not obtain topics information');
  227. $value = DataBase::num_rows($query);
  228. if ($value>0)
  229. {
  230. $isset_topics = array();
  231. while($record = DataBase::fetch($query))
  232. {
  233. if (!in_array($record['t_id'], $isset_topics))
  234. {
  235. $last_post = explode(':', $record['lastpost']);
  236. $skin = array(
  237. 't_id'=>$record['t_id'],
  238. 'fname'=>($record['sticky']=='1') ? '<b>'.$lng['sticky'].'</b>'.$record['name'] : $record['name'],
  239. 'author'=>Topic::TopicAuthor($record['author']),
  240. 'new_post'=>Topic::LastPostImg(),
  241. 'tposts'=>$record['posts'],
  242. 'lastpost'=>Topic::LastPostInTopic($record['t_id'])
  243. );
  244. include('./skins/'.$default_skin.'/forum_forum_add.tpl');
  245. array_push($isset_topics, $record['t_id']);
  246. }
  247. }
  248. }
  249. else
  250. {
  251. echo '<tr><td width="'.TABLES_WIDTH.'" colspan="10" height="19" class="fitem"><p class="fstandard" align="center">'.$lng['nopost'].'!</p></td></tr>';
  252. }
  253. $skin = array(
  254. 'option_pages' => ListPages($page, $count),
  255. 'lwith' => $lng['with'],
  256. 'lpage' => $lng['page'],
  257. 'lpages' => $count,
  258. );
  259. if ($_GET['content']=='posts')
  260. {
  261. $skin['keywords'] = $_POST['keywords'];
  262. }
  263. include('./skins/'.$default_skin.'/search_end_body.tpl');
  264. }
  265. }
  266. else
  267. {
  268. $skin = array(
  269. 'mainpage'=>$lng['lsearch'],
  270. 'lsubmit'=>$lng['search'],
  271. 'lreset'=>$lng['reset'],
  272. 'insert_keywords'=>$lng['insert_keywords']
  273. );
  274. $window_title = $lng['lsearch'];
  275. $navigator_title = '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['lsearch'];
  276. $skin = array_push_assoc($skin,GenerateHeader($window_title,$navigator_title));
  277. include('./skins/'.$default_skin.'/overall_header.tpl');
  278. include('./skins/'.$default_skin.'/search_body.tpl');
  279. }
  280. if ($_SESSION['uid']>0)
  281. {
  282. if(RANK=='2')
  283. {
  284. $skin['pa_link']='<a href="admin/index.php" class="fsmall"><b>'.$lng['pa_link'].'</b></a>';
  285. }
  286. else
  287. {
  288. $skin['pa_link']='';
  289. }
  290. }
  291. else
  292. {
  293. $skin['pa_link']='';
  294. }
  295. $stop = TimeGeneration();
  296. $skin['queries'] = ShowQueries($start, $stop);
  297. include('./skins/'.$default_skin.'/overall_footer.tpl');
  298. ?>