Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Created February 7, 2010 00:49
Show Gist options
  • Save jamsesso/297091 to your computer and use it in GitHub Desktop.
Save jamsesso/297091 to your computer and use it in GitHub Desktop.
<?php
/* FrostBB - Open source bulletin board.
http://www.frostbb.net/
License: http://www.frostbb.net/about:license
File: /resources/class_core.php
Author: Sam Jesso (www.xiofire.com)
Handles the core class and functions of FrostBB. */
if(!defined("FROSTBB"))
die("Access to this file is disabled.");
//Start with the frost class.
class frost {
//Public variables.
public $user, $language, $lang;
//Private variables.
private $cookie;
function loadLanguage() {
global $db, $error;
$this->language = $db->fetch(PREFIX."languages", "WHERE `isset` = '1'");
if($db->num_rows($this->language) === 1) {
$this->lang = $this->getLangFile($this->language['lang']);
} else {
//There was more or less than one language file set.
$error->trigger("Please set one language file as a default.");
}
}
function getLoginCookies() {
if(isset($_COOKIE[$this->settings['cookiename']]) && isset($_COOKIE[$this->settings['cookieverify']])) {
foreach($_COOKIE as $key => $value) {
//Parse all cookies.
$this->cookie[$key] = $db->ready($value);
}
//The user appears to be logged in.
return true;
} else {
//The user is not logged in.
return false;
}
}
function loggedIn() {
//Are the cookies set?
if($this->getLoginCookies()) {
$this->user = $db->fetch(PREFIX."users", "WHERE `frost` = '".$this->cookie[$this->settings['cookiename']]."' AND `verification` = '".$this->cookie[$this->settings['cookieverify']]."' LIMIT 1");
if($db->num_rows($this->user) === 1) {
//If so, return true. $this->user is already set.
return true;
} else {
//The user doesn't exist. Exit and change $this->user.
$this->user = array('username' => 'Guest', 'id' => 0);
return false;
}
} else {
//No cookies are set, user isn't logged in.
$this->user = array('username' => 'Guest', 'id' => 0);
return false;
}
}
function useronly() {
//Useful for user-only pages. Acts as a redirect.
if($this->loggedIn()) {
//Call the function.
$this->loggedIn();
} else {
//Not logged in, grab the URI and redirect to login.
redirect($this->settings['url']."/login.php?next=".urlencode($_SERVER['REQUEST_URI']));
}
}
function loadSettings() {
global $db, $error;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment