I did that and I'm still getting the errors. Here's my functions/functions.php
PHP Code:
<?php
// File ID: functions.php
// Purpose: Provides basic sitewide functions
if(defined("SUBDIR")) include("inc/config_forums.php");
else include("inc/config.php");
//Now connecting to the adoptables database
try{
$adopts = new Database(DBNAME, DBHOST, DBUSER, DBPASS, PREFIX);
}
catch(PDOException $pe){
die("Could not connect to database, the following error has occurred: <br><b>{$pe->getmessage()}</b>");
}
//Define the $adopts as super globals, this has to be done since one cannot define an object as constant.
$GLOBALS['adopts'] = $adopts;
startup();
session_start();
//define default attributes for html tables and other stuff...
$attr = getattributes();
// clean all our data
$_POST = array_map('secure',$_POST);
$_GET = array_map('secure',$_GET);
$session = session_id();
$time = time();
$time_check = $time - 300; // Time check, delete after 300 seconds (5 minutes)
if($isloggedin != "yes") $loggedinname = "Visitor";
$row = $adopts->select("online", array(), "username = '{$loggedinname}'")->fetchObject();
if(!is_object($row)) $adopts->insert("online", array("username" => $loggedinname, "session" => $session, "time" => $time));
else $adopts->update("online", array("time" => $time, "session" => $session, "username" => $loggedinname), "username = '{$loggedinname}'");
// if over 5 minute, delete session
$adopts->delete("online", "time < {$time_check}");
// Begin functions definition:
function __autoload($name) {
// The autoload function, a bit messy if you ask me
$classpath = strtolower("classes/class_{$name}");
if(defined("SUBDIR")) include_once ("../{$classpath}.php");
else include_once ("{$classpath}.php");
}
function is_assoc($arr) {
// From php.net, will help a lot in future
return (is_array($arr) && count(array_filter(array_keys($arr),'is_string')) == count($arr));
}
function checkrb($field, $value){
$button = ($field == $value)?" checked":"";
return $button;
}
function startup() {
// get all of our default settings, like title and stuff
$stmt = $GLOBALS['adopts']->select("settings", array());
while($row = $stmt->fetchObject()){
$GLOBALS['settings'][$row->name] = $row->value;
}
// set up our log in stuff so we always have it
logincheck();
}
function secure($data) {
//This function performs security checks on all incoming form data
if(is_array($data) and SUBDIR != "AdminCP") die("Hacking Attempt!");
$data = htmlentities($data);
$data = strip_tags($data, '');
return $data;
}
function getsitecontent($page) {
$row = $GLOBALS['adopts']->select("content", array(), "page = '{$page}'")->fetchObject();
$title = stripslashes($row->title);
$content = stripslashes($row->content);
$value[content] = $content;
$value[title] = $title;
return $value;
}
function replace($old, $new, $template) {
//This function replaces template values
$template = str_replace($old, $new, $template);
return $template;
}
function codegen($length, $symbols = 0){
$set = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v","V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
$str = '';
if($symbols == 1){
$symbols = array("~","`","!","@","$","#","%","^","+","-","*","/","_","(","[","{",")","]","}");
$set = array_merge($set, $symbols);
}
for($i = 1; $i <= $length; ++$i)
{
$ch = mt_rand(0, count($set)-1);
$str .= $set[$ch];
}
return $str;
}
function passencr($username, $password, $salt){
$pepper = grabanysetting("peppercode");
$password = md5($password);
$newpassword = sha1($username.$password);
$finalpassword = hash('sha512', $pepper.$newpassword.$salt);
return $finalpassword;
}
// NOTE - make sure this is only run once in a whole page load - not multiple times!
function logincheck() {
//Set up our login info...
$uid = "";
$password = "";
//Check for cookie
if (isset($_COOKIE['mysuid']) and isset($_COOKIE['myssession'])) {
$uid = $_COOKIE['mysuid'];
$session = $_COOKIE['myssession'];
$uid = secure($uid);
$password = secure($session);
//Run login operation
$GLOBALS['usersettings'] = $GLOBALS['adopts']->join("groups", "groups.gid = users.usergroup")
->join("users_options", "users_options.uid = users.uid")
->select("users", array(), constant("PREFIX")."users.uid = '{$uid}'")
->fetch(PDO::FETCH_ASSOC);
$luid=$GLOBALS['usersettings']['uid'];
$lsess=$GLOBALS['usersettings']['session'];
$usergroup=$GLOBALS['usersettings']['usergroup'];
if($uid == $luid and $session == $lsess) $isloggedin = "yes";
else{
if (isset($_COOKIE['mysuid'])) {
$past = time() - 10;
setcookie("mysuid", $uid, $past);
}
if (isset($_COOKIE['myssession'])) {
$past = time() - 10;
setcookie("myssession", $session, $past);
}
$isloggedin = "no";
}
}
else $isloggedin = "no";
// return our user data
$row = $GLOBALS['adopts']->select("users", array(), "uid = '{$uid}'")->fetchObject();
$username=$row->username;
$GLOBALS['isloggedin'] = $isloggedin;
$GLOBALS['username'] = $username;
$GLOBALS['loggedinname'] = $username;
$GLOBALS['money'] = $GLOBALS['usersettings']['money'];
$GLOBALS['group'] = $usergroup;
}
function ipgen($ip){
$ip_long = ip2long($ip);
if(!$ip_long){
$ip_long = sprintf("%u", ip2long($ip));
if(!$ip_long){
return 0;
}
}
if($ip_long >= 2147483648) $ip_long -= 4294967296;
return $ip_long;
}
function timeconverter($unit){
switch($unit){
case "secs":
$converter = 1;
break;
case "minutes":
$converter = 60;
break;
case "hours":
$converter = 3600;
break;
case "weeks":
$converter = 604800;
break;
case "months":
$converter = 2592000;
break;
case "years":
$converter = 31536000;
break;
default:
$converter = 86400;
}
return $converter;
}
function grabanysetting($where) {
$value = stripslashes($GLOBALS['settings'][$where]);
return $value;
}
function getlinks(){
//This function gets the links for the top bar from the database
// We will be getting our links from the database...
$links = "<div class='ddmenu'>\n
<ul>";
$stmt = $GLOBALS['adopts']->select("links", array(), "linkparent < 1 ORDER BY id ASC");
while ($category = $stmt->fetchObject()) {
$links .= "\n<li><a class='hide' href='{$category->linkurl}'>{$category->linktext}</a>
\n<ul>";
$stmt2 = $GLOBALS['adopts']->select("links", array(), "linkparent='{$category->id}' ORDER BY id ASC");
while($item = $stmt2->fetchObject()){
$links .= "<li><a href='{$item->linkurl}' title='{$item->linktext}'>{$item->linktext}</a></li>";
}
$links .= "</ul>
\n</li>";
}
$links .= "\n</ul>";
return $links;
}
function getsidebar() {
//This function determines what shows in the side bar of the template
$isloggedin = $GLOBALS['isloggedin'];
$loggedinname = $GLOBALS['loggedinname'];
if($isloggedin == "yes") {
$msgctr = "<a href='messages.php'>Messages</a>";
$data = $GLOBALS['adopts']->select("messages", array(), "touser='{$loggedinname}' and status='unread'")->fetchAll();
if(count($data) > 0) {
$msgctr = "<a href='messages.php'>Messages <b>(".count($data).")</b></a>";
}
$sidebar = "You have {$GLOBALS['money']} {$GLOBALS['settings']['cost']}.<br />
<a href='donate.php'>Donate money to friends</a><br />
<br /><strong>Your links:</strong><br />
<ul><li><a href='adopt.php'>Adopt New Pets</a></li>
<li><a href='pound.php'>Acquire Pounded Pets</a></li>
<li><a href='myadopts.php'>Manage Adoptables</a></li>
<li><a href='account.php'>Go to My Account</a></li>
<li>{$msgctr}
<li><a href='changestyle.php'>Change Theme</a></li>
<li><a href='logout.php'>Log Out</a></li>";
$row = $GLOBALS['adopts']->select("users", array(), "username='{$loggedinname}' and usergroup='1'")->fetchObject();
if(is_object($row)) $sidebar .= "<li><a href='admincp/index.php'>Admin Center</a></li><br />";
$row1 = $GLOBALS['adopts']->select("online", array(), "username != 'Visitor'")->fetchAll();
$total1 = count($row1);
$row2 = $GLOBALS['adopts']->select("online", array(), "username = 'Visitor'")->fetchAll();
$total2 = count($row2);
$sidebar .= "<a href='online.php'>This site has {$total1} members and {$total2} guests online.</a></ul>";
}
else {
$sidebar = "<b><u>Member Login:</u></b><br />
<form name='form1' method='post' action='login.php'>
<p>Username:
<input name='username' type='text' id='username'>
</p>
<p>Password:
<p> <input name='password' type='password' id='password'>
</p>
<p>
<input type='submit' name='Submit' value='Log In'>
</p>
</form>Don't have an account?<br /><a href='register.php'>Register Free</a><br /><a href='forgotpass.php'>Forgot Password?</a>";
$row1 = $GLOBALS['adopts']->select("online", array(), "username != 'Visitor'")->fetchAll();
$total1 = count($row1);
$row2 = $GLOBALS['adopts']->select("online", array(), "username = 'Visitor'")->fetchAll();
$total2 = count($row2);
$sidebar .= "<br />This site currently has {$total1} members and {$total2} guests.";
}
return $sidebar;
}
function dologin($username, $password, $session) {
$row = $GLOBALS['adopts']->select("users", array(), "username = '{$username}'")->fetchObject();
$uid=$row->uid;
$luser=$row->username;
$lpass=$row->password;
if($username == $luser and $password == $lpass) {
$status = "success";
//If the cookie already exists for some reason, delete it
if (isset($_COOKIE['mysuid']) and isset($_COOKIE['myssession'])) {
$past = time() - 10;
setcookie("mysuid", $uid, $past);
setcookie("myssession", $session, $past);
}
// Set the cookie
$Month = 2592000 + time();
setcookie("mysuid", $uid, $Month);
setcookie("myssession", $session, $Month);
$GLOBALS['adopts']->update("users", array("session" => $session), "username = '{$username}'");
//Now log our user into the forum account if forum integration is enabled...
include("../inc/config_forums.php");
if($mybbenabled == 1){
include_once("functions_forums.php");
$forums = new Database($mybbdbname, $mybbhost, $mybbuser, $mybbpass, $mybbprefix) or die("Cannot connect to forum database, please contact an admin immediately.");
$mybbuser = $forums->select("users", array("uid", "loginkey"), "username = '{$username}'")->fetchObject();
$cookiesettings = array();
$cookiesettings['cookiedomain'] = $forums->select("settings", array("value"), "name = 'cookiedomain'")->fetchColumn();
$cookiesettings['cookiepath'] = $forums->select("settings", array("value"), "name = 'cookiepath'")->fetchColumn();
$cookiesettings['cookieprefix'] = $forums->select("settings", array("value"), "name = 'cookieprefix'")->fetchColumn();
mybbsetcookie("mybbuser", $mybbuser->uid."_".$mybbuser->loginkey, NULL, true, $cookiesettings);
$mybbsid = mybb_random_str(32);
mybbsetcookie("sid", $mybbsid, -1, true);
}
}
else{
$status = "error";
}
return $status;
}
function getadmlinks() {
//This function shows special links to the site admin
$links = "<li><a href='index.php'>Home</a></li>
<li><a href='adopt.php'>Change Adoptables</a></li>
<li><a href='content.php'>Change Content</a></li>
<li><a href='users.php'>Change Users</a></li>
<li><a href='items.php'>Change Items</a></li>
<li><a href='settings.php'>Site Settings</a></li>
<li><a href='ads.php'>Manage Ads</a></li>";
return $links;
}
function getadmimages() {
$formcontent = "";
$stmt = $GLOBALS['adopts']->select("filesmap", array());
while($row = $stmt->fetchObject()) {
$wwwpath = $row->wwwpath;
$friendlyname= $row->friendlyname;
$formcontent .= "<option value='{$wwwpath}'>{$friendlyname}</option>";
}
return $formcontent;
}
// MESSY - I believe this still runs if there are no ads. There should be an option to turn it off.
function getads($page) {
// Function to display site advertisements
if($page == "any") $page = "";
$row = $GLOBALS['adopts']->select("ads", array(), "page = '{$page}' and status = 'active' ORDER BY RAND() LIMIT 1")->fetchObject();
if(is_object($row)) {
$value= $row->text;
$value = stripslashes($value);
$aid= $row->id;
$actualimpressions= $row->actualimpressions;
$impressions= $row->impressions;
if($impressions == "") $impressions = 0;
$actualimpressions = $actualimpressions + 1;
//Update the impressions count
$GLOBALS['adopts']->update("ads", array("actualimpressions" => $actualimpressions), "id='{$aid}'");
//Check that ad is not over max impressions...
if ($actualimpressions >= $impressions and $impressions != 0) $GLOBALS['adopts']->update("ads", array("status" => "inactive"), "id='{$aid}'");
}
else $value = "";
return $value;
}
function getlinkname($lid){
$row = $GLOBALS['adopts']->select("links", array(), "id='{$lid}'")->fetchObject();
$linkname= $row->linktext;
return $linkname;
}
// NEW - a function to get a page from the database
function getpage($name) {
$row = $GLOBALS['adopts']->select("content", array(), "page='{$name}' LIMIT 1")->fetchObject();
$GLOBALS['article_content'] = $row->content;
$GLOBALS['article_title'] = $row->title;
$GLOBALS['date'] = $row->date;
return;
}
function getattributes(){
// This function defines default attributes for html table, form and other stuff...
$attr = new stdclass;
// Get default attributes for html tables...
$attr->table = new stdclass;
$attr->table->align = "center";
$attr->table->style = "";
$attr->table->background = array();
$attr->table->border = 1;
$attr->table->cellpadding = "";
$attr->table->cellspacing = "";
$attr->table->frame = "";
$attr->table->rules = "";
$attr->table->summary = "";
$attr->table->width = "";
// Get default attributes for html forms...
$attr->form = new stdclass;
$attr->form->action = "index.php";
$attr->form->accept = "";
$attr->form->enctype = "";
$attr->form->method = "post";
$attr->form->name = "form";
$attr->form->target = "";
// All done, at least for this time being...
return $attr;
}
function getpoundsettings(){
// This function defines default attributes for html table, form and other stuff...
$settings = new stdclass;
$stmt = $GLOBALS['adopts']->select("pound_settings", array());
while($row = $stmt->fetchObject()){
$property = $row->varname;
foreach($row as $key => $val){
$settings->$property->$key = $val;
}
}
return $settings;
}
// NEW - a function to show the page
function showpage($title, $content, $date) {
$theme = $GLOBALS['usersettings']['theme'];
if ($theme == '') $theme = grabanysetting("theme");
$acpthemeurl = "../templates/acp/template.html";
$themeurl = "templates/{$theme}/template.html";
$patterns = array("/:ARTICLETITLE:/","/:ARTICLECONTENT:/", "/:ARTICLEDATE:/", "/:BROWSERTITLE:/", "/:SITENAME:/", "/:SLOGAN:/", "/:LINKSBAR:/", "/:SIDEFEED:/", "/:ADS:/");
// if we have said we are in an admin area, don't show ads and show admin links
if (defined("SUBDIR") and SUBDIR == "AdminCP") {
$replacements = array($title, $content, $date, grabanysetting("browsertitle")." ".$title, grabanysetting("sitename"), grabanysetting("slogan"), getadmlinks(), getsidebar(), "");
$template = file_get_contents($acpthemeurl);
}
else {
$replacements = array($title, $content, $date, grabanysetting("browsertitle")." ".$title, grabanysetting("sitename"), grabanysetting("slogan"), getlinks(), getsidebar(), getads("any"));
$template = file_get_contents($themeurl);
}
// now that we have our stuff, let's start making it all into a webpage
$template = preg_replace($patterns, $replacements, $template);
return $template;
}
function getpostbar ($name) {
$row = $GLOBALS['adopts']->join("users_profile", "users_profile.uid = users.uid")
->select("users", array(), constant("PREFIX")."users.username = '{$name}'")->fetchObject();
$postbar = "<table><tr>
<td>
<img src='{$row->avatar}'>
</td>
<td>
<b>Member Since: </b><br>{$row->membersince}<br>
<b>Bio:</b><br>{$row->bio}<br>
</td>
<td>
<b>Nickname:</b> {$row->nickname}<br>
<b>Gender:</b> {$row->gender}<br>
<b>Cash:</b> <a href='forum.php?do=donate&from={$row->uid}&am={$row->money}'>{$row->money}</a><br>
</td></table>";
return $postbar;
}
?>