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

<?php
/**
* @package uForum
* @file includes/class_overall.php
* @version $Id$
* @copyright 2009(c) PioDer <[email protected]>
* @link http://pioder.gim2przemysl.int.pl/
* @license GNU GPL v3
**/
if ( !defined('IN_uF') )
{
die('Hacking attempt');
}
function SetCounter()
{
global $forum_config;
if (!isset($_COOKIE['forum_visited']))
{
setcookie('forum_visited','1');
$visit_count = $forum_config['forum_counter'] +1;
DataBase::sql_query("UPDATE `".CONFIG_TABLE."` SET `value`='$visit_count' WHERE `name`='forum_counter'",GENERAL,'Could not update forum counter');
}
else
{
$visit_count = $forum_config['forum_counter'];
}
return $visit_count;
}
function GenerateHeader($title, $navigator)
{
global $lng;
global $forum_config;
$skin = array(
'forumname' => $forum_config['forumname'],
'forumdesc' => $forum_config['forumdesc'],
'users' => $lng['lusers'],
'pm' => $lng['lpm'],
'register' => $lng['lregister'],
'search' => $lng['lsearch'],
'eprofile' => $lng['leprofile'],
'groups' => $lng['lgroups'],
'keywords' => $forum_config['meta_keywords'],
'description' => $forum_config['meta_description'],
'mainpage' => $title,
'lmainpage' => $navigator,
'lactual_time'=>$lng['lactualtime'],
'modelogin' => ($_SESSION['uid']>0) ? 'logout' : 'login',
'llogin' => ($_SESSION['uid']>0) ? $lng['lunlogin'] : $lng['llogin']
);
return $skin;
}
function UserAgent($agent)
{
global $lng;
/*This original function is in phpBB 1.12.5 modified by Przemo*/
/*Modified by PioDer: added new browsers and systems and other replaces*/
$agent_tst = ' ' . strtolower($agent);
$system = $browser = '';
if (
strpos($agent_tst, 'windows') ||
strpos($agent_tst, 'win9') ||
strpos($agent_tst, 'win32') ||
strpos($agent_tst, 'nt 5.') ||
strpos($agent_tst, 'nt 4') )
{
$system = ( strpos($agent_tst, 'windows 9') || strpos($agent_tst, 'nt 4') || strpos($agent_tst, 'windows') || strpos($agent_tst, 'win32') ) ? 'windows_98_nt_2000' : $system;
$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;
$system = (strpos($agent_tst, 'nt 5.0')) ? 'windows_98_nt_2000' : $system;
$system = (strpos($agent_tst, 'nt 6.0')) ? 'windows_vista' : $system;
}
else
{
$system = (strpos($agent_tst, 'linux')) ? 'linux' : $system;
$system = (strpos($agent_tst, 'suse')) ? 'linux_suse' : $system;
$system = (strpos($agent_tst, 'knoppix')) ? 'linux_knoppix' : $system;
$system = (strpos($agent_tst, 'turbolinux')) ? 'linux_turbolinux' : $system;
$system = (strpos($agent_tst, 'slackware')) ? 'linux_slackware' : $system;
$system = (strpos($agent_tst, 'gentoo')) ? 'linux_gentoo' : $system;
$system = (strpos($agent_tst, 'lycoris')) ? 'linux_lycoris' : $system;
$system = (strpos($agent_tst, 'debian')) ? 'linux_debian' : $system;
$system = (strpos($agent_tst, 'redhat')) ? 'linux_redhat' : $system;
$system = (strpos($agent_tst, 'archlinux')) ? 'linux_arch' : $system;
$system = (strpos($agent_tst, 'ubuntu')) ? 'linux_ubuntu' : $system;
$system = (strpos($agent_tst, 'cdlinux')) ? 'linux_cdlinux' : $system;
$system = (strpos($agent_tst, 'mandriva')) ? 'linux_mandriva' : $system;
$system = (strpos($agent_tst, 'kateos')) ? 'linux_kateos' : $system;
$system = (strpos($agent_tst, 'bsd')) ? 'linux_freebsd' : $system;
}
if ( $system == '')
{
$system = (strpos($agent_tst, 'mac')) ? 'macos' : $system;
$system = (strpos($agent_tst, 'aix')) ? 'aix' : $system;
$system = (strpos($agent_tst, 'lindows')) ? 'lindows' : $system;
$system = (strpos($agent_tst, 'amiga')) ? 'amiga' : $system;
$system = (strpos($agent_tst, 'athe')) ? 'athe' : $system;
$system = (strpos($agent_tst, 'beos')) ? 'beos' : $system;
$system = (strpos($agent_tst, 'zeta')) ? 'beos' : $system;
$system = (strpos($agent_tst, 'BlueEyed')) ? 'beos' : $system;
$system = (strpos($agent_tst, 'nextstep')) ? 'nextstep' : $system;
$system = (strpos($agent_tst, 'warp')) ? 'warp' : $system;
$system = (strpos($agent_tst, 'qnx')) ? 'qnx' : $system;
$system = (strpos($agent_tst, 'risc')) ? 'risc' : $system;
$system = (strpos($agent_tst, 'solaris')) ? 'solaris' : $system;
$system = (strpos($agent_tst, 'unix')) ? 'unix' : $system;
$system = (strpos($agent_tst, 'macos')) ? 'macos' : $system;
$system = (strpos($agent_tst, 'mac os')) ? 'macos' : $system;
$system = (strpos($agent_tst, 'symbian')) ? 'symbian' : $system;
$system = ($system == '' && strpos($agent_tst, 'win9') || strpos($agent_tst, 'win3') || strpos($agent_tst, 'windows') ) ? 'windows_98_nt_2000' : $system;
}
$browser = (strpos($agent_tst, 'mozilla')) ? 'mozilla' : $browser;
$browser = (strpos($agent_tst, 'msie')) ? 'ie' : $browser;
$browser = (strpos($agent_tst, 'msie 7')) ? 'ie7' : $browser;
$browser = (strpos($agent_tst, 'netscape')) ? 'netscape' : $browser;
$browser = (strpos($agent_tst, 'opera')) ? 'opera' : $browser;
$browser = (strpos($agent_tst, 'konqueror')) ? 'konqueror' : $browser;
$browser = (strpos($agent_tst, 'galeon')) ? 'galeon' : $browser;
$browser = (strpos($agent_tst, 'firefox')) ? 'firefox' : $browser;
$browser = (strpos($agent_tst, 'netsprint')) ? 'netsprint' : $browser;
$browser = (strpos($agent_tst, 'firebird')) ? 'firebird' : $browser;
$browser = (strpos($agent_tst, 'links')) ? 'links' : $browser;
$browser = (strpos($agent_tst, 'dillo')) ? 'dillo' : $browser;
$browser = (strpos($agent_tst, 'omniweb')) ? 'omniweb' : $browser;
$browser = (strpos($agent_tst, 'avant')) ? 'avant' : $browser;
$browser = (strpos($agent_tst, 'myie2')) ? 'myie2' : $browser;
$browser = (strpos($agent_tst, 'seamonkey')) ? 'seamonkey' : $browser;
$browser = (strpos($agent_tst, 'maxthon')) ? 'maxthon' : $browser;
$browser = ($browser == '') ? 'unknown' : $browser;
$system = ($system == '') ? 'unknown' : $system;
return array('icon_' . $system . '.gif', 'icon_' . $browser . '.gif', ($system=='unknown') ? $lng['unknown'] : $system, ($browser=='unknown') ? $lng['unknown'] : $browser);
}
function GenerateTime($request_time)
{
global $lng;
if (date('d M Y',$request_time)== date('d M Y',time()))
{
$date = $lng['today'].', '.date('G:i', $request_time);
}
else
{
if ((date('d',$request_time))== (date('d',time())-1) && (date('m-Y',$request_time)== date('m-Y',time())))
{
$date = $lng['yesterday'].', '.date('G:i', $request_time);
}
else
{
$date = date('d M Y, G:i',$request_time);
}
}
return $date;
}
function AddPages()
{
global $count;
global $page;
$content = '';
for ($i=1;$i<=$count;$i++)
{
if ($i==$page)
{
$content .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
}
else
{
$content .= '<option value="'.$i.'">'.$i.'</option>';
}
}
return $content;
unset($content);
}
function AddPages2($page)//for edit profile, not used in limit!
{
$content = '';
for ($i=1;$i<=50;$i++)
{
if ($i==$page)
{
$content .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
}
else
{
$content .= '<option value="'.$i.'">'.$i.'</option>';
}
}
return $content;
unset($content);
}
function AddSkins()
{
global $forum_config;
global $default_skin;
$all='';
$query = DataBase::sql_query("SELECT `name`, `s_id` FROM `".SKINS_TABLE."`",GENERAL,'Could not obtain skins information');
while($t = DataBase::fetch($query))
{
if ($t['name']==$default_skin)
{
$all .= '<option value="'.$t['s_id'].'" selected="selected">'.$t['name'].'</option>';
}
else
{
$all .= '<option value="'.$t['s_id'].'">'.$t['name'].'</option>';
}
}
return $all;
unset($t, $all);
}
function AddLangs()
{
global $forum_config;
global $default_lang;
$result='';
$rep=opendir('./lngs');
$browseruMoinsUnRepertoire = false;
while ($file = readdir($rep))
{
if($file != '..' && $file !='.' && $file !='')
{
if (is_dir('./lngs/'.$file)){
$browseruMoinsUnRepertoire = true;
if ($file==$default_lang)
{
$result .='<option value="'.$file.'" selected="selected">'.$file.'</option>';
}
else
{
$result .='<option value="'.$file.'">'.$file.'</option>';
}
}
}
}
return $result;
unset($rep, $browseruMoinsUnRepertoire, $file, $result);
}
function TimeGeneration()
{
list($usec, $sec ) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function IfModGroup($guid)
{
global $lng;
$uid = $_SESSION['uid'];
if ($guid==$uid)
{
return'
<tr>
<td class="fitem">
<span class="fstandard">'.$lng['addusrtogrp'].':</span><input type="text" name="nick" style="widtfh:100px; height:15px" value="'.$_POST['nick'].'">
</td>
<td class="fitem">
<span class="fstandard">'.$lng['delusrforgrp'].':</span><input type="text" name="delnick" style="widtfh:100px; height:15px" value="'.$_POST['nick'].'">
</td>
<td class="fitem">
<input type="submit" class="fbutton" value="'.$lng['lgo'].'">
</tr>
';
}
}
function TotalPosts()
{
$sql = "SELECT count(*) as `p_id` FROM ".POSTS_TABLE."";
$query = DataBase::sql_query($sql,GENERAL,'Could not obtain total posts information');
$result = DataBase::fetch($query);
$result = $result['p_id'];
return($result);
}
function DefaultLang($active = false)
{
global $forum_config;
global $userdata;
if ($_SESSION['uid']>0 && !$active)
{
return $userdata['lang'];
}
else
{
return $forum_config['defaultlang'];
}
}
function ShowQueries($start, $stop)
{
global $forum_config;
global $lng;
if ($forum_config['show_time_generation'])
{
$result = $stop - $start;
$result = round($result,3);
if (extension_loaded('xdebug'))
{
return $lng['script_generated'].$result.' '.$lng['seconds'].'. SQL: '.$_COOKIE['queries'].'.<br>
Wersja Xdebug: '.phpversion('xdebug').', Użycie pamięci: '.round((xdebug_memory_usage()/1024),2).'KB.';
}
else
{
return $lng['script_generated'].$result.' '.$lng['seconds'].'. SQL: '.$_COOKIE['queries'].'.';
}
}
else
{
return '';
}
}
function ViewSkinName()
{
global $forum_config;
global $userdata;
if ($_SESSION['uid']>0)
{
$result = $userdata['skin'];
}
else
{
$result = $forum_config['defaultskin'];
}
$sql = "SELECT * FROM `".SKINS_TABLE."` WHERE `s_id`='$result'";
$result = DataBase::fetch(DataBase::sql_query($sql,CRITICAL,'Could not obtain skin information.'));
return $result['name'];
}
function GenerateLastPost($id, $type)
{
$last_post = '';
switch ($type)
{
/** field lastpost in forum format
tp_id:u_id:t_id:ptime:rank:nick
*/
case 1: //for forum
{
$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";
$query = DataBase::sql_query($sql,GENERAL,'Could not obtain last post in forum', true);
$post_count = DataBase::num_rows($query);
$result = DataBase::fetch($query);
$last_post .= $result['tp_id'];
$last_post .= ':';
$last_post .= $result['u_id'];
$last_post .= ':';
$last_post .= $result['t_id'];
$last_post .= ':';
$last_post .= $result['ptime'];
$last_post .= ':';
$last_post .= $result['rank'];
$last_post .= ':';
$last_post .= $result['nick'];
$sql = "UPDATE ".FORUMS_TABLE." SET
`lastpost`='$last_post'
WHERE `f_id`='$id'";
DataBase::sql_query($sql,GENERAL,'Could not update lastpost in forum');
break;
}
/** field lastpost in topic format
tp_id:u_id:ptime:rank:nick
*/
case 2: //for topic
{
$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";
$query = DataBase::sql_query($sql,GENERAL, 'Could not obtain amout of posts in topic');
$result = DataBase::fetch($query);
$last_post .= $result['tp_id'];
$last_post .= ':';
$last_post .= $result['u_id'];
$last_post .= ':';
$last_post .= $result['ptime'];
$last_post .= ':';
$last_post .= $result['rank'];
$last_post .= ':';
$last_post .= $result['nick'];
$sql = "UPDATE ".TOPICS_TABLE." SET
`lastpost_time`='".$result['ptime']."',
`lastpost`='$last_post'
WHERE `t_id`='$id'";
DataBase::sql_query($sql,GENERAL,'Could not update lastpost in topic');
break;
}
}
}
function GeneratePosts($id, $type)
{
switch ($type)
{
case 1: //for forum
{
$sql = "SELECT COUNT(p_id) AS cnt, `f_id` FROM ".POSTS_TABLE." WHERE `f_id`='$id'";
$query = DataBase::sql_query($sql,GENERAL,'Could not obtain posts in forum', true);
$post_count = DataBase::num_rows($query);
$result = DataBase::fetch($query);
$posts = $result['cnt'];
$sql = "UPDATE ".FORUMS_TABLE." SET
`posts`='$posts'
WHERE `f_id`='$id'";
DataBase::sql_query($sql,GENERAL,'Could not update lastpost in forum');
break;
}
case 2: //for topic
{
$sql = "SELECT COUNT(p_id) AS cnt, t_id FROM ".POSTS_TABLE." WHERE `t_id`='$id'";
$query = DataBase::sql_query($sql,GENERAL, 'Could not obtain posts count in topic');
$result = DataBase::fetch($query);
$posts = $result['cnt'];
$sql = "UPDATE ".TOPICS_TABLE." SET
`posts`='$posts'
WHERE `t_id`='$id'";
DataBase::sql_query($sql,GENERAL,'Could not update post count in topic');
break;
}
}
}
function UpdateConfigPosts()
{
$sql = "SELECT count(`p_id`) AS `count` FROM ".POSTS_TABLE;
$query = DataBase::sql_query($sql, GENERAL, 'Could not obtain posts count.');
$result = DataBase::fetch($query);
$cnt = $result['count'];
unset ($sql, $query, $result);
$sql = "UPDATE ".CONFIG_TABLE." SET
`value`='$cnt'
WHERE `name`='posts'";
DataBase::sql_query($sql, GENERAL, 'Could not update posts count in config table');
}
function TriggerStats($id, $type)
{
GeneratePosts($id, $type);
GenerateLastPost($id, $type);
UpdateConfigPosts();
}
function array_push_assoc(&$arr)
{
$ret = '';
$args = func_get_args();
foreach ($args as $arg)
{
if (is_array($arg))
{
foreach ($arg as $key => $value)
{
$arr[$key] = $value;
$ret++;
}
}
else
{
$arr[$arg] = "";
}
}
return $arr;
}
?>