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.

455 lines
14 KiB

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