Просмотр файла minibb11/index.php

Размер файла: 9.43Kb
<?
/*
index.php : basic functions-calling file for miniBB.
Copyright (C) 2001-2002 miniBB.net.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

include ('./setup_options.php');
if ($langCook=${$cookiename.'Language'}) { if (file_exists("./lang/{$langCook}.php")) $lang=$langCook; }
include ('./setup_'.$DB.'.php');
include ("./skins/$skin.php");
include ('./bb_functions.php');
include ("./lang/$lang.php");
include ('./bb_specials.php');

/* Closed forums stuff */
if (!isset($allForums)) { $allForums = $HTTP_COOKIE_VARS[$cookiename.'allForumsPwd']; $allForumsCook=1; }
else { $allForums = md5($allForums); $allForumsCook=0; }

if ($protectWholeForum==1) {
if ($allForums != md5($protectWholeForumPwd)) {
$title = $sitename." :: ".$l_forumProtected;
$tpl = makeUp('protect_forums'); eval("\$tpl = \"$tpl\";"); echo stripslashes($tpl); exit;
}
else {
if ($allForumsCook==0) {
setcookie ($cookiename.'allForumsPwd');
setcookie($cookiename.'allForumsPwd', $allForums);
header("Location: ./index.php");
}
}
}

/* Banned IPs stuff */
$thisIp = getIP();
$cen = explode ('.', $thisIp);
$thisIpMask = $cen[0].'.'.$cen[1].'.'.$cen[2].'.+';

if (DB_query(89,0)) {
$title = $sitename." :: ".$l_accessDenied;
$tpl = makeUp('main_access_denied'); eval("\$tpl = \"$tpl\";"); echo stripslashes($tpl); exit;
}

/* Main stuff */
$starttime = get_microtime();
$logged = 0;
$loginError = 0;
$title = $sitename." :: ";

$forum+=0;
$user_id+=0;
$topic+=0;
$page+=0;


$l_adminpanel_link = '';

/* Predefining variables */

$mode = $HTTP_POST_VARS["mode"];
if ($mode == "") $mode = $HTTP_GET_VARS["mode"];
$action = $HTTP_POST_VARS["action"];
if ($action == "") $action = $HTTP_GET_VARS["action"];
$sortBy = $HTTP_GET_VARS["sortBy"];
$$cookiename = $HTTP_COOKIE_VARS[$cookiename];

if (!($sortBy==1 or $sortBy==0)) $sortBy=0;

if (($action == 'deltopic' or $action == 'delmsg2' or $action == 'movetopic2') and $dy==2) $action = 'vthread';

if ($mode == 'login') {
if ($user_usr == $admin_usr) {
if ($user_pwd == $admin_pwd) {
$logged_admin = 1;
$cook = $user_usr."|".md5($user_pwd)."|".$cookieexptime;
setcookie ($cookiename);
setcookie ($cookiename, $cook, $cookieexptime, $cookiepath, $cookiedomain, $cookiesecure);
if ($action=='') { header("Location: ./index.php"); }
}
else {
$errorMSG = $l_loginpasswordincorrect; $correctErr = "<a href=\"JavaScript:history.back(-1)\">$l_correctLoginpassword</a>";
$loginError = 1;
$tpl = makeUp('main_warning'); eval("\$tpl = \"$tpl\";"); echo load_header().stripslashes($tpl);
}
// if this is not admin, this is anonymous or registered user; check registered first
}
else {
if ($row = DB_query(1,0)) 
{
// It means that username exists in database; so let's check a password
$username = $row[0]; $userpassword = $row[1];
if ($username == $user_usr and $userpassword == md5($user_pwd)) 
{
$logged_user = 1;
$cook = $user_usr."|".md5($user_pwd)."|".$cookieexptime;
setcookie ($cookiename);
setcookie ($cookiename, $cook, $cookieexptime, $cookiepath, $cookiedomain, $cookiesecure);
if ($action=='') { header("Location: ./index.php"); }
}
else {
$errorMSG = $l_loginpasswordincorrect; $correctErr = "<a href=\"JavaScript:history.back(-1)\">$l_correctLoginpassword</a>";
$loginError = 1;
$tpl = makeUp('main_warning'); eval("\$tpl = \"$tpl\";"); echo load_header().stripslashes($tpl);
}
}
else {
// There are now rows - this is Anonymous
$user_usr=htmlspecialchars($user_usr, ENT_QUOTES);
$user_usr=str_replace('|', '', $user_usr);
if ($minimalistBB != FALSE) {
$cookievalue = explode ("|", $minimalistBB);
$user_usrOLD = $cookievalue[0];
} else { $user_usrOLD = ""; }
if ($user_usr != $user_usrOLD) {
// We don't need to set a cookie if the same 'anonymous name' specified
$cook = $user_usr."||".$cookieexptime;
setcookie ($cookiename);
setcookie ($cookiename, $cook, $cookieexptime, $cookiepath, $cookiedomain, $cookiesecure);
}
}
}
}

if ($loginError == 0) {

if ($mode == 'logout') {
setcookie ($cookiename);
header("Location: ./index.php");
}

if ($minimalistBB != FALSE and !$mode) {
$cookievalue = explode ("|", $minimalistBB);
$user_usr = $cookievalue[0]; $user_pwd = $cookievalue[1];
}

if (!isset($logged_admin)) $logged_admin = (user_logged_in("admin")?1:0);
if (!isset($logged_user)) $logged_user = (user_logged_in("user")?1:0);

if ($logged_user==1 or $logged_admin==1) $logged = 1;

if ($logged==1) {
$loginLogout = makeUp('user_logged_in'); eval("\$loginLogout = \"$loginLogout\";"); $loginLogout = stripslashes($loginLogout);
$user_logging = $loginLogout;
$user_data = get_user_id_and_sort($user_usr);
$user_id=$user_data[0];
if ($sortBy=="") $user_sort=$user_data[1]; else $user_sort=$sortBy;
if ($user_sort == 1) { $sortByNew = 0; $sortedByT = $l_newTopics; $sortByT = $l_newAnswers; }
if ($user_sort == 0) { $sortByNew = 1; $sortedByT = $l_newAnswers; $sortByT = $l_newTopics; }
}
else {
if ($sortBy=="") $user_sort=0; else $user_sort = $sortBy;
if ($user_sort == 1) { $sortByNew = 0; $sortedByT = $l_newTopics; $sortByT = $l_newAnswers; }
if ($user_sort == 0) { $sortByNew = 1; $sortedByT = $l_newAnswers; $sortByT = $l_newTopics; }
$loginLogout = makeUp('user_login_form'); eval("\$loginLogout = \"$loginLogout\";"); $loginLogout = stripslashes($loginLogout);
$user_logging = makeUp('user_login_only_form'); eval("\$user_logging = \"$user_logging\";"); $user_logging = stripslashes($user_logging);
}

if ($user_sort==0) $l_author=$l_lastAuthor;

if ($logged_admin==1) {
$l_adminpanel_link = "<p><a href=\"$bb_admin\">".$l_adminpanel."</a><br><br>";
$user_id = 1;
}
else {
$l_adminpanel_link = '';
}

/* Private and archive forums stuff */
$forb=0;
if ($user_id!=1) {
if (in_array($forum, $clForums)) {
if (!in_array($user_id,$clForumsUsers[$forum])) {
$forb=1;
}
}
elseif (in_array($forum, $roForums)) {
$disallowAction=array('pthread', 'ptopic', 'editmsg', 'editmsg2', 'delmsg', 'delmsg2', 'locktopic', 'unlocktopic', 'deltopic', 'movetopic', 'movetopic2');
if (in_array($action, $disallowAction)) $forb=1;
}
}
if ($forb==1) {
$title.=$l_accessDenied;
echo load_header();
$errorMSG = $l_privateForum; $l_returntoforums = ""; $correctErr="";
$tpl = makeUp('main_warning'); eval("\$tpl = \"$tpl\";"); echo stripslashes($tpl); 
$l_loadingtime='';
$tpl = makeUp('main_footer'); eval("\$tpl = \"$tpl\";"); echo stripslashes($tpl);
exit;
}
/* End stuff */

if($action=='pthread') postThread();
elseif($action=='ptopic') postTopic();


if($action=='pthread') {
$page=-1;
if (!isset($errorMSG)) header("Location: ./index.php?action=vthread&forum=$forum&topic=$topic&page=$page#$anchor");
}

elseif($action=='vthread') viewThread();

elseif($action=='vtopic') viewTopic();

elseif($action=='ptopic') {
$page=0;
if (!isset($errorMSG)) header("Location: ./index.php?action=vthread&forum=$forum&topic=$topic");
}

elseif($action=='search') search();

elseif($action=='deltopic') deltopic();

elseif($action=='locktopic') locktopic(1);

elseif($action=='unlocktopic') locktopic(0);

elseif($action=='editmsg') editMsg(0);

elseif($action=='editmsg2') editMsg(1);

elseif($action=='delmsg') deleteMsg(0);

elseif($action=='delmsg2') deleteMsg(1);

elseif($action=='movetopic') moveTopic(0);

elseif($action=='movetopic2') moveTopic(1);

elseif($action=='userinfo') userInfo($user);

elseif($action=='sendpass') send_password(0);

elseif($action=='sendpass2') send_password(1);

elseif($action=='confirmpasswd') {
if (!isset($confirmCode)) $confirmCode='';
confirm_password($confirmCode);
}

elseif($action=='stats') statistics();

elseif($action=='manual') manual();

elseif($action=='registernew') registerUser(0);

elseif($action=='register') registerUser(1);

elseif($action=='prefs') editPrefs(0);

elseif($action=='editprefs') editPrefs(1);

elseif($action=='viewipuser') viewipuser($postip);

elseif($action=='language') changeLang(0);

elseif($action=='language2') changeLang(1);

elseif($action=='unsubscribe') unsubscribeFromTopic($topic, $usrid);

elseif($action=='tpl') {
if (isset($tplName) and $tplName!=''){
$tpl = makeUp($tplName);
eval("\$tpl = \"$tpl\";"); echo load_header().stripslashes($tpl);
}
else header("Location: ./index.php");
}

elseif(DB_query(28,0)>=1){
if ($viewTopicsIfOnlyOneForum!=1) {
viewForum();
if (DB_query(38,0) and $viewlastdiscussions!=0) {
$listTopics = lastDiscussions(); 
$tpl = makeUp('main_last_discussions');
eval("\$tpl = \"$tpl\";");
echo stripslashes ($tpl);
}
}
else viewTopic();
}
else{
$errorMSG = $l_stillNoForums; $l_returntoforums = ""; $correctErr="";
$tpl = makeUp('main_warning'); eval("\$tpl = \"$tpl\";"); echo load_header().stripslashes($tpl);
}
}

//Loading footer
$endtime = get_microtime();
$totaltime = sprintf ("%01.3f", ($endtime - $starttime));
$tpl = makeUp('main_footer'); eval("\$tpl = \"$tpl\";"); echo stripslashes($tpl);

?>