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.

442 lines
13 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file includes/class_overall.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. if ( !defined('IN_uF') )
  11. {
  12. die('Hacking attempt');
  13. }
  14. function SetCounter()
  15. {
  16. global $forum_config;
  17. if (!isset($_COOKIE['forum_visited']))
  18. {
  19. setcookie('forum_visited','1');
  20. $visit_count = $forum_config['forum_counter'] +1;
  21. DataBase::sql_query("UPDATE `".CONFIG_TABLE."` SET `value`='$visit_count' WHERE `name`='forum_counter'",GENERAL,'Could not update forum counter');
  22. }
  23. else
  24. {
  25. $visit_count = $forum_config['forum_counter'];
  26. }
  27. return $visit_count;
  28. }
  29. function GenerateHeader($title, $navigator)
  30. {
  31. global $lng;
  32. global $forum_config;
  33. $skin = array(
  34. 'L.forumname' => $forum_config['forumname'],
  35. 'L.forumdesc' => $forum_config['forumdesc'],
  36. 'L.users' => $lng['lusers'],
  37. 'L.pm' => $lng['lpm'],
  38. 'L.register' => $lng['lregister'],
  39. 'L.search' => $lng['lsearch'],
  40. 'L.eprofile' => $lng['leprofile'],
  41. 'L.groups' => $lng['lgroups'],
  42. 'keywords' => $forum_config['meta_keywords'],
  43. 'description' => $forum_config['meta_description'],
  44. 'mainpage' => $title,
  45. 'L.mainpage' => $navigator,
  46. 'L.actual_time'=>$lng['lactualtime'],
  47. 'modelogin' => ($_SESSION['uid']>0) ? 'logout' : 'login',
  48. 'L.login' => ($_SESSION['uid']>0) ? $lng['lunlogin'] : $lng['llogin'],
  49. 'L.pa_link' => $lng['pa_link']
  50. );
  51. return $skin;
  52. }
  53. function UserAgent($agent)
  54. {
  55. global $lng;
  56. /*This original function is in phpBB 1.12.5 modified by Przemo*/
  57. /*Modified by PioDer: added new browsers and systems and other replaces*/
  58. $agent_tst = ' ' . strtolower($agent);
  59. $system = $browser = '';
  60. if (
  61. strpos($agent_tst, 'windows') ||
  62. strpos($agent_tst, 'win9') ||
  63. strpos($agent_tst, 'win32') ||
  64. strpos($agent_tst, 'nt 5.') ||
  65. strpos($agent_tst, 'nt 4') )
  66. {
  67. $system = ( strpos($agent_tst, 'windows 9') || strpos($agent_tst, 'nt 4') || strpos($agent_tst, 'windows') || strpos($agent_tst, 'win32') ) ? 'windows_98_nt_2000' : $system;
  68. $system = ( strpos($agent_tst, 'nt 5.') || strpos($agent_tst, 'nt 6.') || strpos($agent_tst, 'nt 7.') || strpos($agent_tst, 'nt 8.') ) ? 'windows_xp_2003' : $system;
  69. $system = (strpos($agent_tst, 'nt 5.0')) ? 'windows_98_nt_2000' : $system;
  70. $system = (strpos($agent_tst, 'nt 6.0')) ? 'windows_vista' : $system;
  71. }
  72. else
  73. {
  74. $system = (strpos($agent_tst, 'linux')) ? 'linux' : $system;
  75. $system = (strpos($agent_tst, 'suse')) ? 'linux_suse' : $system;
  76. $system = (strpos($agent_tst, 'knoppix')) ? 'linux_knoppix' : $system;
  77. $system = (strpos($agent_tst, 'turbolinux')) ? 'linux_turbolinux' : $system;
  78. $system = (strpos($agent_tst, 'slackware')) ? 'linux_slackware' : $system;
  79. $system = (strpos($agent_tst, 'gentoo')) ? 'linux_gentoo' : $system;
  80. $system = (strpos($agent_tst, 'lycoris')) ? 'linux_lycoris' : $system;
  81. $system = (strpos($agent_tst, 'debian')) ? 'linux_debian' : $system;
  82. $system = (strpos($agent_tst, 'redhat')) ? 'linux_redhat' : $system;
  83. $system = (strpos($agent_tst, 'archlinux')) ? 'linux_arch' : $system;
  84. $system = (strpos($agent_tst, 'ubuntu')) ? 'linux_ubuntu' : $system;
  85. $system = (strpos($agent_tst, 'cdlinux')) ? 'linux_cdlinux' : $system;
  86. $system = (strpos($agent_tst, 'mandriva')) ? 'linux_mandriva' : $system;
  87. $system = (strpos($agent_tst, 'kateos')) ? 'linux_kateos' : $system;
  88. $system = (strpos($agent_tst, 'bsd')) ? 'linux_freebsd' : $system;
  89. }
  90. if ( $system == '')
  91. {
  92. $system = (strpos($agent_tst, 'mac')) ? 'macos' : $system;
  93. $system = (strpos($agent_tst, 'aix')) ? 'aix' : $system;
  94. $system = (strpos($agent_tst, 'lindows')) ? 'lindows' : $system;
  95. $system = (strpos($agent_tst, 'amiga')) ? 'amiga' : $system;
  96. $system = (strpos($agent_tst, 'athe')) ? 'athe' : $system;
  97. $system = (strpos($agent_tst, 'beos')) ? 'beos' : $system;
  98. $system = (strpos($agent_tst, 'zeta')) ? 'beos' : $system;
  99. $system = (strpos($agent_tst, 'BlueEyed')) ? 'beos' : $system;
  100. $system = (strpos($agent_tst, 'nextstep')) ? 'nextstep' : $system;
  101. $system = (strpos($agent_tst, 'warp')) ? 'warp' : $system;
  102. $system = (strpos($agent_tst, 'qnx')) ? 'qnx' : $system;
  103. $system = (strpos($agent_tst, 'risc')) ? 'risc' : $system;
  104. $system = (strpos($agent_tst, 'solaris')) ? 'solaris' : $system;
  105. $system = (strpos($agent_tst, 'unix')) ? 'unix' : $system;
  106. $system = (strpos($agent_tst, 'macos')) ? 'macos' : $system;
  107. $system = (strpos($agent_tst, 'mac os')) ? 'macos' : $system;
  108. $system = (strpos($agent_tst, 'symbian')) ? 'symbian' : $system;
  109. $system = ($system == '' && strpos($agent_tst, 'win9') || strpos($agent_tst, 'win3') || strpos($agent_tst, 'windows') ) ? 'windows_98_nt_2000' : $system;
  110. }
  111. $browser = (strpos($agent_tst, 'mozilla')) ? 'mozilla' : $browser;
  112. $browser = (strpos($agent_tst, 'msie')) ? 'ie' : $browser;
  113. $browser = (strpos($agent_tst, 'msie 7')) ? 'ie7' : $browser;
  114. $browser = (strpos($agent_tst, 'netscape')) ? 'netscape' : $browser;
  115. $browser = (strpos($agent_tst, 'opera')) ? 'opera' : $browser;
  116. $browser = (strpos($agent_tst, 'konqueror')) ? 'konqueror' : $browser;
  117. $browser = (strpos($agent_tst, 'galeon')) ? 'galeon' : $browser;
  118. $browser = (strpos($agent_tst, 'firefox')) ? 'firefox' : $browser;
  119. $browser = (strpos($agent_tst, 'netsprint')) ? 'netsprint' : $browser;
  120. $browser = (strpos($agent_tst, 'firebird')) ? 'firebird' : $browser;
  121. $browser = (strpos($agent_tst, 'links')) ? 'links' : $browser;
  122. $browser = (strpos($agent_tst, 'dillo')) ? 'dillo' : $browser;
  123. $browser = (strpos($agent_tst, 'omniweb')) ? 'omniweb' : $browser;
  124. $browser = (strpos($agent_tst, 'avant')) ? 'avant' : $browser;
  125. $browser = (strpos($agent_tst, 'myie2')) ? 'myie2' : $browser;
  126. $browser = (strpos($agent_tst, 'seamonkey')) ? 'seamonkey' : $browser;
  127. $browser = (strpos($agent_tst, 'maxthon')) ? 'maxthon' : $browser;
  128. $browser = ($browser == '') ? 'unknown' : $browser;
  129. $system = ($system == '') ? 'unknown' : $system;
  130. return array('icon_' . $system . '.gif', 'icon_' . $browser . '.gif', ($system=='unknown') ? $lng['unknown'] : $system, ($browser=='unknown') ? $lng['unknown'] : $browser);
  131. }
  132. function GenerateTime($request_time)
  133. {
  134. global $lng;
  135. if (date('d M Y',$request_time)== date('d M Y',time()))
  136. {
  137. $date = $lng['today'].', '.date('G:i', $request_time);
  138. }
  139. else
  140. {
  141. if ((date('d',$request_time))== (date('d',time())-1) && (date('m-Y',$request_time)== date('m-Y',time())))
  142. {
  143. $date = $lng['yesterday'].', '.date('G:i', $request_time);
  144. }
  145. else
  146. {
  147. $date = date('d M Y, G:i',$request_time);
  148. }
  149. }
  150. return $date;
  151. }
  152. function ListPages($page, $count = 50)//for edit profile, not used in limit!
  153. {
  154. $content = '';
  155. for ($i=1;$i<=$count;$i++)
  156. {
  157. if ($i==$page)
  158. {
  159. $content .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
  160. }
  161. else
  162. {
  163. $content .= '<option value="'.$i.'">'.$i.'</option>';
  164. }
  165. }
  166. return $content;
  167. unset($content);
  168. }
  169. function ListDir($dir, $selection)
  170. {
  171. $result='';
  172. $rep=opendir('./'.$dir);
  173. while ($file = readdir($rep))
  174. {
  175. if($file != '..' && $file !='.' && $file !='' && $file[0] != '.')
  176. {
  177. if (is_dir('./'.$dir.'/'.$file)){
  178. if ($file==$selection)
  179. {
  180. $result .='<option value="'.$file.'" selected="selected">'.$file.'</option>';
  181. }
  182. else
  183. {
  184. $result .='<option value="'.$file.'">'.$file.'</option>';
  185. }
  186. }
  187. }
  188. }
  189. return $result;
  190. unset($rep, $file, $result);
  191. }
  192. function TimeGeneration()
  193. {
  194. list($usec, $sec ) = explode(" ",microtime());
  195. return ((float)$usec + (float)$sec);
  196. }
  197. function IfModGroup($guid)
  198. {
  199. global $lng;
  200. $uid = $_SESSION['uid'];
  201. if ($guid==$uid)
  202. {
  203. return'
  204. <tr>
  205. <td class="fitem">
  206. <span class="fstandard">'.$lng['addusrtogrp'].':</span><input type="text" name="nick" style="widtfh:100px; height:15px" value="'.$_POST['nick'].'">
  207. </td>
  208. <td class="fitem">
  209. <span class="fstandard">'.$lng['delusrforgrp'].':</span><input type="text" name="delnick" style="widtfh:100px; height:15px" value="'.$_POST['nick'].'">
  210. </td>
  211. <td class="fitem">
  212. <input type="submit" class="fbutton" value="'.$lng['lgo'].'">
  213. </tr>
  214. ';
  215. }
  216. }
  217. function TotalPosts()
  218. {
  219. $sql = "SELECT count(*) as `p_id` FROM ".POSTS_TABLE."";
  220. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain total posts information');
  221. $result = DataBase::fetch($query);
  222. $result = $result['p_id'];
  223. return($result);
  224. }
  225. function DefaultLang($active = false)
  226. {
  227. global $forum_config;
  228. global $userdata;
  229. if ($_SESSION['uid']>0 && !$active)
  230. {
  231. return $userdata['lang'];
  232. }
  233. else
  234. {
  235. return $forum_config['defaultlang'];
  236. }
  237. }
  238. function ShowQueries($start, $stop)
  239. {
  240. global $forum_config;
  241. global $lng;
  242. if ($forum_config['show_time_generation'])
  243. {
  244. $result = $stop - $start;
  245. $result = round($result,3);
  246. if (extension_loaded('xdebug'))
  247. {
  248. return $lng['script_generated'].$result.' '.$lng['seconds'].'. SQL: '.$_COOKIE['queries'].'.<br>
  249. Wersja Xdebug: '.phpversion('xdebug').', Użycie pamięci: '.round((xdebug_memory_usage()/1024),2).'KB.';
  250. }
  251. else
  252. {
  253. return $lng['script_generated'].$result.' '.$lng['seconds'].'. SQL: '.$_COOKIE['queries'].'.';
  254. }
  255. }
  256. else
  257. {
  258. return '';
  259. }
  260. }
  261. function ViewSkinName()
  262. {
  263. global $forum_config;
  264. global $userdata;
  265. if ($_SESSION['uid']>0)
  266. {
  267. $result = $userdata['skin'];
  268. }
  269. else
  270. {
  271. $result = $forum_config['defaultskin'];
  272. }
  273. return $result;
  274. }
  275. function GenerateLastPost($id, $type)
  276. {
  277. $last_post = '';
  278. switch ($type)
  279. {
  280. /** field lastpost in forum format
  281. tp_id:u_id:t_id:ptime:rank:nick
  282. */
  283. case 1: //for forum
  284. {
  285. $sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".POSTS_TABLE.".u_id = ".USERS_TABLE.".u_id WHERE `f_id`='$id' ORDER BY `ptime` DESC LIMIT 1";
  286. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain last post in forum', true);
  287. $post_count = DataBase::num_rows($query);
  288. $result = DataBase::fetch($query);
  289. $last_post .= $result['tp_id'];
  290. $last_post .= ':';
  291. $last_post .= $result['u_id'];
  292. $last_post .= ':';
  293. $last_post .= $result['t_id'];
  294. $last_post .= ':';
  295. $last_post .= $result['ptime'];
  296. $last_post .= ':';
  297. $last_post .= $result['rank'];
  298. $last_post .= ':';
  299. $last_post .= $result['nick'];
  300. $sql = "UPDATE ".FORUMS_TABLE." SET
  301. `lastpost`='$last_post'
  302. WHERE `f_id`='$id'";
  303. DataBase::sql_query($sql,GENERAL,'Could not update lastpost in forum');
  304. break;
  305. }
  306. /** field lastpost in topic format
  307. tp_id:u_id:ptime:rank:nick
  308. */
  309. case 2: //for topic
  310. {
  311. $sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".u_id = ".POSTS_TABLE.".u_id WHERE `t_id`='$id' ORDER BY `ptime` DESC LIMIT 1";
  312. $query = DataBase::sql_query($sql,GENERAL, 'Could not obtain amout of posts in topic');
  313. $result = DataBase::fetch($query);
  314. $last_post .= $result['tp_id'];
  315. $last_post .= ':';
  316. $last_post .= $result['u_id'];
  317. $last_post .= ':';
  318. $last_post .= $result['ptime'];
  319. $last_post .= ':';
  320. $last_post .= $result['rank'];
  321. $last_post .= ':';
  322. $last_post .= $result['nick'];
  323. $sql = "UPDATE ".TOPICS_TABLE." SET
  324. `lastpost_time`='".$result['ptime']."',
  325. `lastpost`='$last_post'
  326. WHERE `t_id`='$id'";
  327. DataBase::sql_query($sql,GENERAL,'Could not update lastpost in topic');
  328. break;
  329. }
  330. }
  331. }
  332. function GeneratePosts($id, $type)
  333. {
  334. switch ($type)
  335. {
  336. case 1: //for forum
  337. {
  338. $sql = "SELECT COUNT(p_id) AS cnt, `f_id` FROM ".POSTS_TABLE." WHERE `f_id`='$id'";
  339. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain posts in forum', true);
  340. $post_count = DataBase::num_rows($query);
  341. $result = DataBase::fetch($query);
  342. $posts = $result['cnt'];
  343. $sql = "UPDATE ".FORUMS_TABLE." SET
  344. `posts`='$posts'
  345. WHERE `f_id`='$id'";
  346. DataBase::sql_query($sql,GENERAL,'Could not update lastpost in forum');
  347. break;
  348. }
  349. case 2: //for topic
  350. {
  351. $sql = "SELECT COUNT(p_id) AS cnt, t_id FROM ".POSTS_TABLE." WHERE `t_id`='$id'";
  352. $query = DataBase::sql_query($sql,GENERAL, 'Could not obtain posts count in topic');
  353. $result = DataBase::fetch($query);
  354. $posts = $result['cnt'];
  355. $sql = "UPDATE ".TOPICS_TABLE." SET
  356. `posts`='$posts'
  357. WHERE `t_id`='$id'";
  358. DataBase::sql_query($sql,GENERAL,'Could not update post count in topic');
  359. break;
  360. }
  361. }
  362. }
  363. function UpdateConfigPosts()
  364. {
  365. $sql = "SELECT count(`p_id`) AS `count` FROM ".POSTS_TABLE;
  366. $query = DataBase::sql_query($sql, GENERAL, 'Could not obtain posts count.');
  367. $result = DataBase::fetch($query);
  368. $cnt = $result['count'];
  369. unset ($sql, $query, $result);
  370. $sql = "UPDATE ".CONFIG_TABLE." SET
  371. `value`='$cnt'
  372. WHERE `name`='posts'";
  373. DataBase::sql_query($sql, GENERAL, 'Could not update posts count in config table');
  374. }
  375. function TriggerStats($id, $type)
  376. {
  377. GeneratePosts($id, $type);
  378. GenerateLastPost($id, $type);
  379. UpdateConfigPosts();
  380. }
  381. function array_push_assoc(&$arr)
  382. {
  383. $ret = '';
  384. $args = func_get_args();
  385. foreach ($args as $arg)
  386. {
  387. if (is_array($arg))
  388. {
  389. foreach ($arg as $key => $value)
  390. {
  391. $arr[$key] = $value;
  392. $ret++;
  393. }
  394. }
  395. else
  396. {
  397. $arr[$arg] = "";
  398. }
  399. }
  400. return $arr;
  401. }
  402. ?>