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.

491 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. '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 AddPages()
  153. {
  154. global $count;
  155. global $page;
  156. $content = '';
  157. for ($i=1;$i<=$count;$i++)
  158. {
  159. if ($i==$page)
  160. {
  161. $content .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
  162. }
  163. else
  164. {
  165. $content .= '<option value="'.$i.'">'.$i.'</option>';
  166. }
  167. }
  168. return $content;
  169. unset($content);
  170. }
  171. function AddPages2($page)//for edit profile, not used in limit!
  172. {
  173. $content = '';
  174. for ($i=1;$i<=50;$i++)
  175. {
  176. if ($i==$page)
  177. {
  178. $content .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
  179. }
  180. else
  181. {
  182. $content .= '<option value="'.$i.'">'.$i.'</option>';
  183. }
  184. }
  185. return $content;
  186. unset($content);
  187. }
  188. function AddSkins()
  189. {
  190. global $forum_config;
  191. global $default_skin;
  192. $all='';
  193. $query = DataBase::sql_query("SELECT `name`, `s_id` FROM `".SKINS_TABLE."`",GENERAL,'Could not obtain skins information');
  194. while($t = DataBase::fetch($query))
  195. {
  196. if ($t['name']==$default_skin)
  197. {
  198. $all .= '<option value="'.$t['s_id'].'" selected="selected">'.$t['name'].'</option>';
  199. }
  200. else
  201. {
  202. $all .= '<option value="'.$t['s_id'].'">'.$t['name'].'</option>';
  203. }
  204. }
  205. return $all;
  206. unset($t, $all);
  207. }
  208. function AddLangs()
  209. {
  210. global $forum_config;
  211. global $default_lang;
  212. $result='';
  213. $rep=opendir('./lngs');
  214. $browseruMoinsUnRepertoire = false;
  215. while ($file = readdir($rep))
  216. {
  217. if($file != '..' && $file !='.' && $file !='')
  218. {
  219. if (is_dir('./lngs/'.$file)){
  220. $browseruMoinsUnRepertoire = true;
  221. if ($file==$default_lang)
  222. {
  223. $result .='<option value="'.$file.'" selected="selected">'.$file.'</option>';
  224. }
  225. else
  226. {
  227. $result .='<option value="'.$file.'">'.$file.'</option>';
  228. }
  229. }
  230. }
  231. }
  232. return $result;
  233. unset($rep, $browseruMoinsUnRepertoire, $file, $result);
  234. }
  235. function TimeGeneration()
  236. {
  237. list($usec, $sec ) = explode(" ",microtime());
  238. return ((float)$usec + (float)$sec);
  239. }
  240. function IfModGroup($guid)
  241. {
  242. global $lng;
  243. $uid = $_SESSION['uid'];
  244. if ($guid==$uid)
  245. {
  246. return'
  247. <tr>
  248. <td class="fitem">
  249. <span class="fstandard">'.$lng['addusrtogrp'].':</span><input type="text" name="nick" style="widtfh:100px; height:15px" value="'.$_POST['nick'].'">
  250. </td>
  251. <td class="fitem">
  252. <span class="fstandard">'.$lng['delusrforgrp'].':</span><input type="text" name="delnick" style="widtfh:100px; height:15px" value="'.$_POST['nick'].'">
  253. </td>
  254. <td class="fitem">
  255. <input type="submit" class="fbutton" value="'.$lng['lgo'].'">
  256. </tr>
  257. ';
  258. }
  259. }
  260. function TotalPosts()
  261. {
  262. $sql = "SELECT count(*) as `p_id` FROM ".POSTS_TABLE."";
  263. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain total posts information');
  264. $result = DataBase::fetch($query);
  265. $result = $result['p_id'];
  266. return($result);
  267. }
  268. function DefaultLang($active = false)
  269. {
  270. global $forum_config;
  271. global $userdata;
  272. if ($_SESSION['uid']>0 && !$active)
  273. {
  274. return $userdata['lang'];
  275. }
  276. else
  277. {
  278. return $forum_config['defaultlang'];
  279. }
  280. }
  281. function ShowQueries($start, $stop)
  282. {
  283. global $forum_config;
  284. global $lng;
  285. if ($forum_config['show_time_generation'])
  286. {
  287. $result = $stop - $start;
  288. $result = round($result,3);
  289. if (extension_loaded('xdebug'))
  290. {
  291. return $lng['script_generated'].$result.' '.$lng['seconds'].'. SQL: '.$_COOKIE['queries'].'.<br>
  292. Wersja Xdebug: '.phpversion('xdebug').', Użycie pamięci: '.round((xdebug_memory_usage()/1024),2).'KB.';
  293. }
  294. else
  295. {
  296. return $lng['script_generated'].$result.' '.$lng['seconds'].'. SQL: '.$_COOKIE['queries'].'.';
  297. }
  298. }
  299. else
  300. {
  301. return '';
  302. }
  303. }
  304. function ViewSkinName()
  305. {
  306. global $forum_config;
  307. global $userdata;
  308. if ($_SESSION['uid']>0)
  309. {
  310. $result = $userdata['skin'];
  311. }
  312. else
  313. {
  314. $result = $forum_config['defaultskin'];
  315. }
  316. $sql = "SELECT * FROM `".SKINS_TABLE."` WHERE `s_id`='$result'";
  317. $result = DataBase::fetch(DataBase::sql_query($sql,CRITICAL,'Could not obtain skin information.'));
  318. return $result['name'];
  319. }
  320. function GenerateLastPost($id, $type)
  321. {
  322. $last_post = '';
  323. switch ($type)
  324. {
  325. /** field lastpost in forum format
  326. tp_id:u_id:t_id:ptime:rank:nick
  327. */
  328. case 1: //for forum
  329. {
  330. $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";
  331. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain last post in forum', true);
  332. $post_count = DataBase::num_rows($query);
  333. $result = DataBase::fetch($query);
  334. $last_post .= $result['tp_id'];
  335. $last_post .= ':';
  336. $last_post .= $result['u_id'];
  337. $last_post .= ':';
  338. $last_post .= $result['t_id'];
  339. $last_post .= ':';
  340. $last_post .= $result['ptime'];
  341. $last_post .= ':';
  342. $last_post .= $result['rank'];
  343. $last_post .= ':';
  344. $last_post .= $result['nick'];
  345. $sql = "UPDATE ".FORUMS_TABLE." SET
  346. `lastpost`='$last_post'
  347. WHERE `f_id`='$id'";
  348. DataBase::sql_query($sql,GENERAL,'Could not update lastpost in forum');
  349. break;
  350. }
  351. /** field lastpost in topic format
  352. tp_id:u_id:ptime:rank:nick
  353. */
  354. case 2: //for topic
  355. {
  356. $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";
  357. $query = DataBase::sql_query($sql,GENERAL, 'Could not obtain amout of posts in topic');
  358. $result = DataBase::fetch($query);
  359. $last_post .= $result['tp_id'];
  360. $last_post .= ':';
  361. $last_post .= $result['u_id'];
  362. $last_post .= ':';
  363. $last_post .= $result['ptime'];
  364. $last_post .= ':';
  365. $last_post .= $result['rank'];
  366. $last_post .= ':';
  367. $last_post .= $result['nick'];
  368. $sql = "UPDATE ".TOPICS_TABLE." SET
  369. `lastpost_time`='".$result['ptime']."',
  370. `lastpost`='$last_post'
  371. WHERE `t_id`='$id'";
  372. DataBase::sql_query($sql,GENERAL,'Could not update lastpost in topic');
  373. break;
  374. }
  375. }
  376. }
  377. function GeneratePosts($id, $type)
  378. {
  379. switch ($type)
  380. {
  381. case 1: //for forum
  382. {
  383. $sql = "SELECT COUNT(p_id) AS cnt, `f_id` FROM ".POSTS_TABLE." WHERE `f_id`='$id'";
  384. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain posts in forum', true);
  385. $post_count = DataBase::num_rows($query);
  386. $result = DataBase::fetch($query);
  387. $posts = $result['cnt'];
  388. $sql = "UPDATE ".FORUMS_TABLE." SET
  389. `posts`='$posts'
  390. WHERE `f_id`='$id'";
  391. DataBase::sql_query($sql,GENERAL,'Could not update lastpost in forum');
  392. break;
  393. }
  394. case 2: //for topic
  395. {
  396. $sql = "SELECT COUNT(p_id) AS cnt, t_id FROM ".POSTS_TABLE." WHERE `t_id`='$id'";
  397. $query = DataBase::sql_query($sql,GENERAL, 'Could not obtain posts count in topic');
  398. $result = DataBase::fetch($query);
  399. $posts = $result['cnt'];
  400. $sql = "UPDATE ".TOPICS_TABLE." SET
  401. `posts`='$posts'
  402. WHERE `t_id`='$id'";
  403. DataBase::sql_query($sql,GENERAL,'Could not update post count in topic');
  404. break;
  405. }
  406. }
  407. }
  408. function UpdateConfigPosts()
  409. {
  410. $sql = "SELECT count(`p_id`) AS `count` FROM ".POSTS_TABLE;
  411. $query = DataBase::sql_query($sql, GENERAL, 'Could not obtain posts count.');
  412. $result = DataBase::fetch($query);
  413. $cnt = $result['count'];
  414. unset ($sql, $query, $result);
  415. $sql = "UPDATE ".CONFIG_TABLE." SET
  416. `value`='$cnt'
  417. WHERE `name`='posts'";
  418. DataBase::sql_query($sql, GENERAL, 'Could not update posts count in config table');
  419. }
  420. function TriggerStats($id, $type)
  421. {
  422. GeneratePosts($id, $type);
  423. GenerateLastPost($id, $type);
  424. UpdateConfigPosts();
  425. }
  426. function array_push_assoc(&$arr)
  427. {
  428. $ret = '';
  429. $args = func_get_args();
  430. foreach ($args as $arg)
  431. {
  432. if (is_array($arg))
  433. {
  434. foreach ($arg as $key => $value)
  435. {
  436. $arr[$key] = $value;
  437. $ret++;
  438. }
  439. }
  440. else
  441. {
  442. $arr[$arg] = "";
  443. }
  444. }
  445. return $arr;
  446. }
  447. ?>