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.

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