Hallo,
Ich habe ein Forum (myBB) aber wenn man z.B das PW Vergessen hat schickt er keine E-Mail da steht nur
Warning: mail() has been disabled for security reasons in /var/www/users/flash/inc/functions.php on line 371
In der Datai steht:
[code:1:e28dc915ab]<?php
/**
* MyBB 1.2
* Copyright © 2006 MyBB Group, All Rights Reserved
*
* Website: http://www.mybboard.net
* License: http://www.mybboard.net/eula.html
*
* $Id: functions.php 3058 2007-05-15 02:00:38Z Tikitiki $
*/
/**
* Outputs a page directly to the browser, parsing anything which needs to be parsed.
*
* @param string The contents of the page.
*/
function output_page($contents)
{
global $db, $lang, $theme, $plugins, $mybb;
global $querytime, $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;
$contents = parse_page($contents);
$totaltime = $maintimer->stop();
if($mybb->usergroup['cancp'] == "yes")
{
$phptime = $maintimer->format($maintimer->totaltime - $querytime);
$querytime = $maintimer->format($querytime);
$percentphp = number_format((($phptime/$maintimer->totaltime)*100), 2);
$percentsql = number_format((($querytime/$maintimer->totaltime)*100), 2);
$phpversion = phpversion();
$serverload = get_server_load();
if(strstr(getenv("REQUEST_URI"), "?"))
{
$debuglink = htmlspecialchars(getenv("REQUEST_URI")) . "&debug=1";
}
else
{
$debuglink = htmlspecialchars(getenv("REQUEST_URI")) . "?debug=1";
}
if($mybb->settings['gzipoutput'] != "no")
{
$gzipen = "Enabled";
}
else
{
$gzipen = "Disabled";
}
if($mybb->settings['extraadmininfo'] != "no")
{
if(function_exists("memory_get_usage"))
{
$memory_usage = " / Memory Usage: ".get_friendly_size(memory_get_usage());
}
$other = "PHP version: $phpversion / Server Load: $serverload / GZip Compression: $gzipen";
$debugstuff = "Generated in $totaltime seconds ($percentphp% PHP / $percentsql% MySQL)
MySQL Queries: $db->query_count / Global Parsing Time: $globaltime$memory_usage
$other
[<a href=\"$debuglink\" target=\"_blank\">advanced details</a>]
";
$contents = str_replace("<debugstuff>", $debugstuff, $contents);
}
if(isset($mybb->input['debug']))
{
debug_page();
}
}
$contents = str_replace("<debugstuff>", "", $contents);
$contents = $plugins->run_hooks("pre_output_page", $contents);
if($mybb->settings['gzipoutput'] != "no")
{
if(version_compare(PHP_VERSION, '4.2.0', '>='))
{
$contents = gzip_encode($contents, $mybb->settings['gziplevel']);
}
else
{
$contents = gzip_encode($contents);
}
}
echo $contents;
$plugins->run_hooks("post_output_page");
// If the use shutdown functionality is turned off, run any shutdown related items now.
if(($mybb->settings['useshutdownfunc'] == "no"|| phpversion() >= '5.0.5') && $mybb->use_shutdown != true)
{
run_shutdown();
}
}
/**
* Adds a function to the list of functions to run on shutdown.
*
* @param string The name of the function.
*/
function add_shutdown($name)
{
global $shutdown_functions;
if(function_exists($name))
{
$shutdown_functions[$name] = $name;
}
}
/**
* Runs the shutdown items after the page has been sent to the browser.
*
*/
function run_shutdown()
{
global $db, $cache, $plugins, $shutdown_functions, $done_shutdown;
if($done_shutdown == true)
{
return;
}
// If our DB has been deconstructed already (bad PHP 5.2.0), reconstruct
if(!is_object($db))
{
require MYBB_ROOT."inc/config.php";
if(isset($config))
{
require_once MYBB_ROOT."inc/db_".$config['dbtype'].".php";
$db = new databaseEngine;
$db->connect($config['hostname'], $config['username'], $config['password']);
$db->select_db($config['database']);
}
}
// Cache object deconstructed? reconstruct
if(!is_object($cache))
{
require_once MYBB_ROOT."inc/class_datacache.php";
$cache = new datacache;
}
// And finaly.. we have the PHP developers to thank for this "hack" which fixes a problem THEY created
if(!is_object($plugins) && !defined("NO_PLUGINS"))
{
require_once MYBB_ROOT."inc/class_plugins.php";
$plugins = new pluginSystem;
$plugins->load();
}
// We have some shutdown queries needing to be run
if(is_array($db->shutdown_queries))
{
// Loop through and run them all
foreach($db->shutdown_queries as $query)
{
$db->query($query);
}
}
// Run any shutdown functions if we have them
if(is_array($shutdown_functions))
{
foreach($shutdown_functions as $function)
{
$function();
}
}
$done_shutdown = true;
}
/**
* Sends a specified amount of messages from the mail queue
*
* @param int The number of messages to send (Defaults to 20)
*/
function send_mail_queue($count=10)
{
global $db, $cache, $plugins;
$plugins->run_hooks("send_mail_queue_start");
// Check to see if the mail queue has messages needing to be sent
$mailcache = $cache->read("mailqueue");
if($mailcache['queue_size'] > 0 && ($mailcache['locked'] == 0 $mailcache['locked'] < time()-300))
{
// Lock the queue so no other messages can be sent whilst these are (for popular boards)
$cache->updatemailqueue(0, time());
// Fetch emails for this page view - and send them
$query = $db->simple_select(TABLE_PREFIX."mailqueue", "*", "", array("order_by" => "mid", "order_dir" => "asc", "limit_start" => 0, "limit" => $count));
$plugins->run_hooks_by_ref("send_mail_queue_mail", $query);
while($email = $db->fetch_array($query))
{
// Delete the message from the queue
$db->delete_query(TABLE_PREFIX."mailqueue", "mid='{$email['mid']}'");
my_mail($email['mailto'], $email['subject'], $email['message'], $email['mailfrom'], "", $email['headers']);
}
// Update the mailqueue cache and remove the lock
$cache->updatemailqueue(time(), 0);
}
$plugins->run_hooks("send_mail_queue_end");
}
/**
* Parses the contents of a page before outputting it.
*
* @param string The contents of the page.
* @return string The parsed page.
*/
function parse_page($contents)
{
global $db, $lang, $theme, $mybb, $htmldoctype, $loadpmpopup, $archive_url;
$contents = str_replace('<navigation>', build_breadcrumb(1), $contents);
$contents = str_replace('<archive_url>', $archive_url, $contents);
if($htmldoctype)
{
$contents = $htmldoctype.$contents;
}
else
{
$contents = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".$contents;
}
if($lang->settings['rtl'] == 1)
{
$contents = str_replace("<html", "<html dir=\"rtl\"", $contents);
}
if($lang->settings['htmllang'])
{
$contents = str_replace("<html", "<html lang=\"".$lang->settings['htmllang']."\"", $contents);
}
if($loadpmpopup)
{
if(my_substr($_SERVER['PHP_SELF'], -strlen("private.php")) != "private.php")
{
$contents = str_replace("<body", "<body onload=\"Javascript:MyBB.newPM()\"", $contents);
}
}
return $contents;
}
/**
* Turn a unix timestamp in to a "friendly" date/time format for the user.
*
* @param string A date format according to PHP's date structure.
* @param int The unix timestamp the date should be generated for.
* @param int The offset in hours that should be applied to times. (timezones)
* @param int Whether or not to use today/yesterday formatting.
* @return string The formatted timestamp.
*/
function my_date($format, $stamp="", $offset="", $ty=1)
{
global $mybb, $lang, $mybbadmin, $plugins;
// If the stamp isn't set, use time()
if(empty($stamp))
{
$stamp = time();
}
if(!$offset && $offset != '0')
{
if($mybb->user['uid'] != 0 && array_key_exists("timezone", $mybb->user))
{
$offset = $mybb->user['timezone'];
$dstcorrection = $mybb->user['dst'];
}
elseif(defined("IN_ADMINCP"))
{
$offset = $mybbadmin['timezone'];
$dstcorrection = $mybbadmin['dst'];
}
else
{
$offset = $mybb->settings['timezoneoffset'];
$dstcorrection = $mybb->settings['dstcorrection'];
}
// If DST correction is enabled, add an additional hour to the timezone.
if($dstcorrection == "yes")
{
$offset++;
if(my_substr($offset, 0, 1) != "-")
{
$offset = "+".$offset;
}
}
}
if($offset == "-")
{
$offset = 0;
}
$date = gmdate($format, $stamp + ($offset * 3600));
if($mybb->settings['dateformat'] == $format && $ty)
{
$stamp = time();
$todaysdate = gmdate($format, $stamp + ($offset * 3600));
$yesterdaysdate = gmdate($format, ($stamp - 86400) + ($offset * 3600));
if($todaysdate == $date)
{
$date = $lang->today;
}
elseif($yesterdaysdate == $date)
{
$date = $lang->yesterday;
}
}
$plugins->run_hooks_by_ref("my_date", $date);
return $date;
}
/**
* Sends an email using PHP's mail function, formatting it appropriately.
*
* @param string Address the email should be addressed to.
* @param string The subject of the email being sent.
* @param string The message being sent.
* @param string The from address of the email, if blank, the board name will be used.
* @param string The chracter set being used to send this email.
*/
function my_mail($to, $subject, $message, $from="", $charset="", $headers="")
{
global $db, $mybb, $lang;
if(empty($charset))
{
$charset = $lang->settings['charset'];
}
// Build mail headers
if(my_strlen(trim($from)) == 0)
{
$from = "\"".$mybb->settings['bbname']." Mailer\" <".$mybb->settings['adminemail'].">";
}
$headers .= "From: {$from}\n";
$headers .= "Return-Path: {$mybb->settings['adminemail']}\n";
if($_SERVER['SERVER_NAME'])
{
$http_host = $_SERVER['SERVER_NAME'];
}
else if($_SERVER['HTTP_HOST'])
{
$http_host = $_SERVER['HTTP_HOST'];
}
else
{
$http_host = "unknown.local";
}
$headers .= "Message-ID: <". md5(uniqid(time()))."@{$http_host}>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=\"{$charset}\"\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: MyBB\n";
$headers .= "X-MyBB-Script: {$http_host}/{$_SERVER['PHP_SELF']}\n";
// For some reason sendmail/qmail doesn't like \r\n
$sendmail = @ini_get('sendmail_path');
if($sendmail)
{
$headers = preg_replace("#(\r\n|\r|\n)#s", "\n", $headers);
$message = preg_replace("#(\r\n|\r|\n)#s", "\n", $message);
}
else
{
$headers = preg_replace("#(\r\n|\r|\n)#s", "\r\n", $headers);
$message = preg_replace("#(\r\n|\r|\n)#s", "\r\n", $message);
}
mail($to, $subject, $message, $headers);
}
/**
* Return a parent list for the specified forum.
*
* @param int The forum id to get the parent list for.
* @return string The comma-separated parent list.
*/
function get_parent_list($fid)
{
global $db, $forum_cache;
static $forumarraycache;
if($forumarraycache[$fid])
{
return $forumarraycache[$fid]['parentlist'];
}
elseif($forum_cache[$fid])
{
return $forum_cache[$fid]['parentlist'];
}
else
{
cache_forums();
return $forum_cache[$fid]['parentlist'];
}
}
/**
* Build a parent list of a specific forum, suitable for querying
*
* @param int The forum ID
* @param string The column name to add to the query
* @param string The joiner for each forum for querying (OR | AND | etc)
* @param string The parent list of the forum - if you have it
* @return string The query string generated
*/
function build_parent_list($fid, $column="fid", $joiner="OR", $parentlist="")
{
if(!$parentlist)
{
$parentlist = get_parent_list($fid);
}
$parentsexploded = explode(",", $parentlist);
$builtlist = "(";
$sep = '';
foreach($parentsexploded as $key => $val)
{
$builtlist .= "$sep$column='$val'";
$sep = " $joiner ";
}
$builtlist .= ")";
return $builtlist;
}
/**
* Load the forum cache in to memory
*
* @param boolean True to force a reload of the cache
*/
function cache_forums($force=false)
{
global $forum_cache, $db, $cache;
if($force == true)
{
$forum_cache = $cache->read("forums", 1);
return $forum_cache;
}
if(!$forum_cache)
{
$forum_cache = $cache->read("forums");
if(!$forum_cache)
{
$cache->updateforums();
$forum_cache = $cache->read("forums", 1);
}
}
return $forum_cache;
}
/**
* Produce a friendly error message page
*
* @param string The error message to be shown
* @param string The title of the message shown in the title of the page and the error table
*/
function error($error="", $title="")
{
global $header, $footer, $theme, $headerinclude, $db, $templates, $lang, $mybb;
if(!$error)
{
$error = $lang->unknown_error;
}
if(!$title)
{
$title = $mybb->settings['bbname'];
}
$timenow = my_date($mybb->settings['dateformat'], time()) . " " . my_date($mybb->settings['timeformat'], time());
reset_breadcrumb();
add_breadcrumb($lang->error);
eval("\$errorpage = \"".$templates->get("error")."\";");
output_page($errorpage);
exit;
}
/**
* Produce an error message for displaying inline on a page
*
* @param array Array of errors to be shown
* @param string The title of the error message
* @return string The inline error HTML
*/
function inline_error($errors, $title="")
{
global $theme, $mybb, $db, $lang, $templates;
if(!$title)
{
$title = $lang->please_correct_errors;
}
if(!is_array($errors))
{
$errors = array($errors);
}
foreach($errors as $error)
{
$errorlist .= "[*]".$error."\n";
}
eval("\$errors = \"".$templates->get("error_inline")."\";");
return $errors;
}
/**
* Presents the user with a "no permission" page
*/
function error_no_permission()
{
global $mybb, $theme, $templates, $db, $lang, $plugins, $session;
$time = time();
$plugins->run_hooks("no_permission");
$noperm_array = array (
"nopermission" => '1',
"location1" => 0,
"location2" => 0
);
$db->update_query(TABLE_PREFIX."sessions", $noperm_array, "sid='".$session->sid."'");
$url = htmlspecialchars_uni($_SERVER['REQUEST_URI']);
if($mybb->user['uid'])
{
$lang->error_nopermission_user_5 = sprintf($lang->error_nopermission_user_5, $mybb->user['username']);
eval("\$errorpage = \"".$templates->get("error_nopermission_loggedin")."\";");
}
else
{
eval("\$errorpage = \"".$templates->get("error_nopermission")."\";");
}
error($errorpage);
}
/**
* Redirect the user to a given URL with a given message
*
* @param string The URL to redirect the user to
* @param string The redirection message to be shown
*/
function redirect($url, $message="", $title="")
{
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;
$loadpmpopup = false;
if(!$message)
{
$message = $lang->redirect;
}
$timenow = my_date($mybb->settings['dateformat'], time()) . " " . my_date($mybb->settings['timeformat'], time());
$plugins->run_hooks("redirect");
if(!$title)
{
$title = $mybb->settings['bbname'];
}
if($mybb->settings['redirects'] == "on" && $mybb->user['showredirect'] != "no")
{
$url = str_replace("&", "&", $url);
$url = htmlspecialchars($url);
eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
}
else
{
$url = str_replace("#", "&#", $url);
$url = str_replace("&", "&", $url);
$url = str_replace(array("\n","\r",";"), "", $url);
header("Location: $url");
}
exit;
}
/**
* Generate a listing of page - pagination
*
* @param int The number of items
* @param int The number of items to be shown per page
* @param int The current page number
* @param string The URL to have page numbers tacked on to
* @return string The generated pagination
*/
function multipage($count, $perpage, $page, $url)
{
global $theme, $templates, $lang, $mybb;
if($count > $perpage)
{
$pages = $count / $perpage;
$pages = ceil($pages);
if($page > 1)
{
$prev = $page - 1;
eval("\$prevpage = \"".$templates->get("multipage_prevpage")."\";");
}
if($page < $pages)
{
$next = $page + 1;
eval("\$nextpage = \"".$templates->get("multipage_nextpage")."\";");
}
$from = ($page>4) ? ($page-4):1;
if($page == $pages)
{
$to = $pages;
}
elseif($page == $pages-1)
{
$to = $page+1;
}
elseif($page == $pages-2)
{
$to = $page+2;
}
elseif($page == $pages-3)
{
$to = $page+3;
}
else
{
$to = $page+4;
}
for($i = $from; $i <= $to; $i++)
{
$plate = "multipage_page".(($i==$page) ? "_current":"");
eval("\$mppage .= \"".$templates->get($plate)."\";");
}
$lang->multipage_pages = sprintf($lang->multipage_pages, $pages);
eval("\$start = \"".$templates->get("multipage_start")."\";");
eval("\$end = \"".$templates->get("multipage_end")."\";");
eval("\$multipage = \"".$templates->get("multipage")."\";");
return $multipage;
}
}
/**
* Fetch the permissions for a specific user
*
* @param int The user ID
* @return array Array of user permissions for the specified user
*/
function user_permissions($uid=0)
{
global $mybb, $cache, $groupscache, $user_cache;
// If no user id is specified, assume it is the current user
if($uid == 0)
{
$uid = $mybb->user['uid'];
}
// User id does not match current user, fetch permissions
if($uid != $mybb->user['uid'])
{
// We've already cached permissions for this user, return them.
if($user_cache[$uid]['permissions'])
{
return $user_cache[$uid]['permissions'];
}
// This user was not already cached, fetch their user information.
if(!$user_cache[$uid])
{
$user_cache[$uid] = get_user($uid);
}
// Collect group permissions.
$gid = $user_cache[$uid]['usergroup'].",".$user_cache[$uid]['additionalgroups'];
$groupperms = usergroup_permissions($gid);
// Store group permissions in user cache.
$user_cache[$uid]['permissions'] = $groupperms;
return $groupperms;
}
// This user is the current user, return their permissions
else
{
return $mybb->usergroup;
}
}
/**
* Fetch the usergroup permissions for a specic group or series of groups combined
*
* @param mixed A list of groups (Can be a single integer, or a list of groups separated by a comma)
* @return array Array of permissions generated for the groups
*/
function usergroup_permissions($gid=0)
{
global $cache, $groupscache, $grouppermignore, $groupzerogreater;
if(!is_array($groupscache))
{
$groupscache = $cache->read("usergroups");
}
$groups = explode(",", $gid);
if(count($groups) == 1)
{
return $groupscache[$gid];
}
foreach($groups as $gid)
{
if(trim($gid) == "" !$groupscache[$gid])
{
continue;
}
foreach($groupscache[$gid] as $perm => $access)
{
if(!in_array($perm, $grouppermignore))
{
if(isset($usergroup[$perm]))
{
$permbit = $usergroup[$perm];
}
else
{
$permbit = "";
}
$zerogreater = 0;
if(in_array($perm, $groupzerogreater))
{
if($access == 0)
{
$usergroup[$perm] = 0;
$zerogreater = 1;
}
}
if(($access > $permbit ($access == "yes" && $permbit == "no")
!$permbit) && $zerogreater != 1)
{
$usergroup[$perm] = $access;
}
}
}
}
return $usergroup;
}
/**
* Fetch the display group properties for a specific display group
*
* @param int The group ID to fetch the display properties for
* @return array Array of display properties for the group
*/
function usergroup_displaygroup($gid)
{
global $cache, $groupscache, $displaygroupfields;
if(!is_array($groupscache))
{
$groupscache = $cache->read("usergroups");
}
$displaygroup = array();
$group = $groupscache[$gid];
foreach($displaygroupfields as $field)
{
$displaygroup[$field] = $group[$field];
}
return $displaygroup;
}
/**
* Build the forum permissions for a specific forum, user or group
*
* @param int The forum ID to build permissions for (0 builds for all forums)
* @param int The user to build the permissions for (0 assumes current logged in user)
* @param int The group of the user to build permissions for (0 will fetch it)
* @return array Forum permissions for the specific forum or forums
*/
function forum_permissions($fid=0, $uid=0, $gid=0)
{
global $db, $cache, $groupscache, $forum_cache, $fpermcache, $mybb, $usercache, $fpermissionscache;
if($uid == 0)
{
$uid = $mybb->user['uid'];
}
if(!$gid $gid == 0) // If no group, we need to fetch it
{
if($uid != $mybb->user['uid'])
{
if($usercache[$uid])
{
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid='$uid'");
$usercache[$uid] = $db->fetch_array($query);
}
$gid = $usercache[$uid]['usergroup'].",".$usercache[$uid]['additionalgroups'];
$groupperms = usergroup_permissions($gid);
}
else
{
$gid = $mybb->user['usergroup'];
if(isset($mybb->user['additionalgroups']))
{
$gid .= ",".$mybb->user['additionalgroups'];
}
$groupperms = $mybb->usergroup;
}
}
if(!is_array($forum_cache))
{
$forum_cache = cache_forums();
if(!$forum_cache)
{
return false;
}
}
if(!is_array($fpermcache))
{
$fpermcache = $cache->read("forumpermissions");
}
if($fid) // Fetch the permissions for a single forum
{
$permissions = fetch_forum_permissions($fid, $gid, $groupperms);
}
else
{
foreach($forum_cache as $forum)
{
$permissions[$forum['fid']] = fetch_forum_permissions($forum['fid'], $gid, $groupperms);
}
}
return $permissions;
}
/**
* Fetches the permissions for a specific forum/group applying the inheritance scheme.
* Called by forum_permissions()
*
* @param int The forum ID
* @param string A comma separated list of usergroups
* @param array Group permissions
* @return array Permissions for this forum
*/
function fetch_forum_permissions($fid, $gid, $groupperms)
{
global $groupscache, $forum_cache, $fpermcache, $mybb, $fpermfields;
$groups = explode(",", $gid);
if(!$fpermcache[$fid]) // This forum has no custom or inherited permisssions so lets just return the group permissions
{
return $groupperms;
}
$current_permissions = array();
foreach($groups as $gid)
{
if($groupscache[$gid])
{
// If this forum has permissions set
if($fpermcache[$fid][$gid])
{
$level_permissions = $fpermcache[$fid][$gid];
foreach($level_permissions as $permission => $access)
{
if($access >= $current_permissions[$permission] ($access == "yes" && $current_permissions[$permission] == "no")
!$current_permissions[$permission])
{
$current_permissions[$permission] = $access;
}
}
}
}
}
if(count($current_permissions) == 0)
{
$current_permissions = $groupperms;
}
return $current_permissions;
}
/**
* Check the password given on a certain forum for validity
*
* @param int The forum ID
* @param string The plain text password for the forum
*/
function check_forum_password($fid, $password="")
{
global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang;
$showform = 1;
if($password)
{
if($mybb->input['pwverify'])
{
if($password == $mybb->input['pwverify'])
{
my_setcookie("forumpass[$fid]", md5($mybb->user['uid'].$mybb->input['pwverify']), null, true);
$showform = 0;
}
else
{
eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";");
$showform = 1;
}
}
else
{
if(!$_COOKIE['forumpass'][$fid] ($_COOKIE['forumpass'][$fid] && md5($mybb->user['uid'].$password) != $_COOKIE['forumpass'][$fid]))
{
$showform = 1;
}
else
{
$showform = 0;
}
}
}
else
{
$showform = 0;
}
if($showform)
{
$_SERVER['REQUEST_URI'] = htmlspecialchars_uni($_SERVER['REQUEST_URI']);
eval("\$pwform = \"".$templates->get("forumdisplay_password")."\";");
output_page($pwform);
exit;
}
}
/**
* Return the permissions for a moderator in a specific forum
*
* @param fid The forum ID
* @param uid The user ID to fetch permissions for (0 assumes current logged in user)
* @param string The parent list for the forum (if blank, will be fetched)
* @return array Array of moderator permissions for the specific forum
*/
function get_moderator_permissions($fid, $uid="0", $parentslist="")
{
global $mybb, $db;
static $modpermscache;
if($uid < 1)
{
$uid = $mybb->user['uid'];
}
if(!isset($modpermscache[$fid][$uid]))
{
if(!$parentslist)
{
$parentslist = get_parent_list($fid);
}
$sql = build_parent_list($fid, "fid", "OR", $parentslist);
$query = $db->simple_select(TABLE_PREFIX."moderators", "*", "uid='{$uid}' AND {$sql}");
$perms = $db->fetch_array($query);
$modpermscache[$fid][$uid] = $perms;
}
else
{
$perms = $modpermscache[$fid][$uid];
}
return $perms;
}
/**
* Checks if a moderator has permissions to perform an action in a specific forum
*
* @param int The forum ID (0 assumes global)
* @param string The action tyring to be performed. (blank assumes any action at all)
* @param int The user ID (0 assumes current user)
* @return yes|no Returns yes if the user has permission, no if they do not
*/
function is_moderator($fid="0", $action="", $uid="0")
{
global $mybb, $db;
if($uid == 0)
{
$uid = $mybb->user['uid'];
}
$user_perms = user_permissions($uid);
if($user_perms['issupermod'] == "yes")
{
return "yes";
}
else
{
if(!$fid)
{
$query = $db->simple_select(TABLE_PREFIX.'moderators', 'COUNT(*) as count', "uid={$uid}", array('limit' => 1));
$modcheck = $db->fetch_array($query);
if($modcheck['count'] > 0)
{
return "yes";
}
else
{
return "no";
}
}
else
{
$modperms = get_moderator_permissions($fid, $uid);
if(!$action && $modperms)
{
return "yes";
}
else
{
if($modperms[$action] == "yes")
{
return "yes";
}
else
{
return "no";
}
}
}
}
}
/**
* Generate a list of the posticons.
*
* @return string The template of posticons.
*/
function get_post_icons()
{
global $mybb, $db, $icon, $theme, $templates, $lang;
$listed = 0;
if($mybb->input['icon'])
{
$icon = $mybb->input['icon'];
}
$no_icons_checked = " checked=\"checked\"";
$query = $db->query("
SELECT *
FROM ".TABLE_PREFIX."icons
ORDER BY name DESC
");
while($dbicon = $db->fetch_array($query))
{
if($icon == $dbicon['iid'])
{
$iconlist .= "<input type=\"radio\" name=\"icon\" value=\"".$dbicon['iid']."\" checked=\"checked\" /> <img src=\"".$dbicon['path']."\" alt=\"".$dbicon['name']."\" />";
$no_icons_checked = "";
}
else
{
$iconlist .= "<input type=\"radio\" name=\"icon\" value=\"".$dbicon['iid']."\" /> <img src=\"".$dbicon['path']."\" alt=\"".$dbicon['name']."\" />";
}
$listed++;
if($listed == 9)
{
$iconlist .= "
";
$listed = 0;
}
}
eval("\$posticons = \"".$templates->get("posticons")."\";");
return $posticons;
}
/**
* MyBB setcookie() wrapper.
*
* @param string The cookie identifier.
* @param string The cookie value.
* @param int The timestamp of the expiry date.
* @param boolean True if setting a HttpOnly cookie (supported by IE, Opera 9, Konqueror)
*/
function my_setcookie($name, $value="", $expires="", $httponly=false)
{
global $mybb;
if(!$mybb->settings['cookiepath'])
{
$mybb->settings['cookiepath'] = "/";
}
if($expires == -1)
{
$expires = 0;
}
else if($expires == "" $expires == null)
{
if($mybb->user['remember'] == "no")
{
$expires = 0;
}
else
{
$expires = time() + (60*60*24*365); // Make the cookie expire in a years time
}
}
else
{
$expires = time() + intval($expires);
}
$mybb->settings['cookiepath'] = str_replace(array("\n","\r"), "", $mybb->settings['cookiepath']);
$mybb->settings['cookiedomain'] = str_replace(array("\n","\r"), "", $mybb->settings['cookiedomain']);
// Versions of PHP prior to 5.2 do not support HttpOnly cookies and IE is buggy when specifying a blank domain so set the cookie manually
$cookie = "Set-Cookie: {$name}=".urlencode($value);
if($expires > 0)
{
$cookie .= "; expires=".gmdate('D, d-M-Y H:i:s \\G\\M\\T', $expires);
}
if(!empty($mybb->settings['cookiepath']))
{
$cookie .= "; path={$mybb->settings['cookiepath']}";
}
if(!empty($mybb->settings['cookiedomain']))
{
$cookie .= "; domain={$mybb->settings['cookiedomain']}";
}
if($httponly == true)
{
$cookie .= "; HttpOnly";
}
header($cookie, false);
}
/**
* Unset a cookie set by MyBB.
*
* @param string The cookie identifier.
*/
function my_unsetcookie($name)
{
global $mybb;
$expires = -3600;
my_setcookie($name, "", $expires);
}
/**
* Get the contents from a serialised cookie array.
*
* @param string The cookie identifier.
* @param int The cookie content id.
* @return array|boolean The cookie id's content array or false when non-existent.
*/
function my_get_array_cookie($name, $id)
{
if(!isset($_COOKIE['mybb'][$name]))
{
return false;
}
$cookie = unserialize($_COOKIE['mybb'][$name]);
if(isset($cookie[$id]))
{
return $cookie[$id];
}
else
{
return 0;
}
}
/**
* Set a serialised cookie array.
*
* @param string The cookie identifier.
* @param int The cookie content id.
* @param string The value to set the cookie to.
*/
function my_set_array_cookie($name, $id, $value)
{
$cookie = $_COOKIE['mybb'];
$newcookie = unserialize($cookie[$name]);
$newcookie[$id] = $value;
$newcookie = addslashes(serialize($newcookie));
my_setcookie("mybb[$name]", $newcookie);
}
/**
* Returns the serverload of the system.
*
* @return int The serverload of the system.
*/
function get_server_load()
{
global $lang;
if(strtolower(substr(PHP_OS, 0, 3)) === 'win')
{
return $lang->unknown;
}
elseif(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))
{
$serverload = explode(" ", $load);
$serverload[0] = round($serverload[0], 4);
if(!$serverload)
{
$load = @exec("uptime");
$load = split("load averages?: ", $load);
$serverload = explode(",", $load[1]);
}
}
else if(function_exists("shell_exec"))
{
$load = explode(' ', `uptime`);
$serverload[0] = $load[count($load)-1];
}
else
{
$load = @exec("uptime");
$load = split("load averages?: ", $load);
$serverload = explode(",", $load[1]);
}
$returnload = trim($serverload[0]);
if(!$returnload)
{
$returnload = $lang->unknown;
}
return $returnload;
}
/**
* Updates the forum statistics with specific values (or addition/subtraction of the previous value)
*
* @param array Array of items being updated (numthreads,numposts,numusers)
*/
function update_stats($changes=array())
{
global $cache, $db;
$stats = $cache->read("stats");
$counters = array('numthreads','numposts','numusers');
$update = array();
foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))
{
// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" substr($changes[$counter], 0, 1) == "-")
{
$new_stats[$counter] = $stats[$counter] + $changes[$counter];
}
else
{
$new_stats[$counter] = $changes[$counter];
}
// Less than 0? That's bad
if($new_stats[$counter] < 0)
{
$new_stats[$counter] = 0;
}
}
}
// Fetch latest user if the user count is changing
if(array_key_exists('numusers', $changes))
{
$query = $db->simple_select(TABLE_PREFIX."users", "uid, username", "", array('order_by' => 'uid', 'order_dir' => 'DESC', 'limit' => 1));
$lastmember = $db->fetch_array($query);
$new_stats['lastuid'] = $lastmember['uid'];
$new_stats['lastusername'] = $lastmember['username'];
}
if(is_array($stats))
{
$stats = array_merge($stats, $new_stats);
}
else
{
$stats = $new_stats;
}
$cache->update("stats", $stats);
}
/**
* Updates the forum counters with a specific value (or addition/subtraction of the previous value)
*
* @param int The forum ID
* @param array Array of items being updated (threads, posts, unapprovedthreads, unapprovedposts) and their value (ex, 1, +1, -1)
*/
function update_forum_counters($fid, $changes=array())
{
global $db, $cache;
$update_query = array();
$counters = array('threads', 'unapprovedthreads', 'posts', 'unapprovedposts');
// Fetch above counters for this forum
$query = $db->simple_select(TABLE_PREFIX."forums", implode(",", $counters), "fid='{$fid}'");
$forum = $db->fetch_array($query);
foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))
{
// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" substr($changes[$counter], 0, 1) == "-")
{
$update_query[$counter] = $forum[$counter] + $changes[$counter];
}
else
{
$update_query[$counter] = $changes[$counter];
}
// Less than 0? That's bad
if($update_query[$counter] < 0)
{
$update_query[$counter] = 0;
}
}
}
// Only update if we're actually doing something
if(count($update_query) > 0)
{
$db->update_query(TABLE_PREFIX."forums", $update_query, "fid='".intval($fid)."'");
}
// Guess we should update the statistics too?
if($update_query['threads'] $update_query['posts'])
{
$new_stats = array();
if(array_key_exists('threads', $update_query))
{
$threads_diff = $update_query['threads'] - $forum['threads'];
if($threads_diff > -1)
{
$new_stats['numthreads'] = "+{$threads_diff}";
}
else
{
$new_stats['numthreads'] = "{$threads_diff}";
}
}
if(array_key_exists('posts', $update_query))
{
$posts_diff = $update_query['posts'] - $forum['posts'];
if($posts_diff > -1)
{
$new_stats['numposts'] = "+{$posts_diff}";
}
else
{
$new_stats['numposts'] = "{$posts_diff}";
}
}
update_stats($new_stats);
}
// Update last post info
update_forum_lastpost($fid);
}
/**
* Update the last post information for a specific forum
*
* @param int The forum ID
*/
function update_forum_lastpost($fid)
{
global $db;
// Fetch the last post for this forum
$query = $db->query("
SELECT tid, lastpost, lastposter, lastposteruid, subject
FROM ".TABLE_PREFIX."threads
WHERE fid='{$fid}' AND visible='1' AND closed NOT LIKE 'moved|%'
ORDER BY lastpost DESC
LIMIT 0, 1
");
$lastpost = $db->fetch_array($query);
$updated_forum = array(
"lastpost" => intval($lastpost['lastpost']),
"lastposter" => $db->escape_string($lastpost['lastposter']),
"lastposteruid" => intval($lastpost['lastposteruid']),
"lastposttid" => intval($lastpost['tid']),
"lastpostsubject" => $db->escape_string($lastpost['subject'])
);
$db->update_query(TABLE_PREFIX."forums", $updated_forum, "fid='{$fid}'");
}
/**
* Updates the thread counters with a specific value (or addition/subtraction of the previous value)
*
* @param int The thread ID
* @param array Array of items being updated (replies, unapprovedposts, attachmentcount) and their value (ex, 1, +1, -1)
*/
function update_thread_counters($tid, $changes=array())
{
global $db;
$update_query = array();
$counters = array('replies', 'unapprovedposts', 'attachmentcount');
// Fetch above counters for this thread
$query = $db->simple_select(TABLE_PREFIX."threads", implode(",", $counters), "tid='{$tid}'");
$thread = $db->fetch_array($query);
foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))
{
// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" substr($changes[$counter], 0, 1) == "-")
{
$update_query[$counter] = $thread[$counter] + $changes[$counter];
}
else
{
$update_query[$counter] = $changes[$counter];
}
// Less than 0? That's bad
if($update_query[$counter] < 0)
{
$update_query[$counter] = 0;
}
}
}
// Only update if we're actually doing something
if(count($update_query) > 0)
{
$db->update_query(TABLE_PREFIX."threads", $update_query, "tid='".intval($tid)."'");
}
update_thread_data($tid);
}
/**
* Update the first post and lastpost data for a specific thread
*
* @param int The thread ID
*/
function update_thread_data($tid)
{
global $db;
$query = $db->query("
SELECT u.uid, u.username, p.username AS postusername, p.dateline
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
WHERE p.tid='$tid' AND p.visible='1'
ORDER BY p.dateline DESC
LIMIT 1"
);
$lastpost = $db->fetch_array($query);
$query = $db->query("
SELECT u.uid, u.username, p.username AS postusername, p.dateline
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
WHERE p.tid='$tid'
ORDER BY p.dateline ASC
LIMIT 1
");
$firstpost = $db->fetch_array($query);
if(!$firstpost['username'])
{
$firstpost['username'] = $firstpost['postusername'];
}
if(!$lastpost['username'])
{
$lastpost['username'] = $lastpost['postusername'];
}
if(!$lastpost['dateline'])
{
$lastpost['username'] = $firstpost['username'];
$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];
}
$lastpost['username'] = $db->escape_string($lastpost['username']);
$firstpost['username'] = $db->escape_string($firstpost['username']);
$update_array = array(
'username' => $firstpost['username'],
'uid' => intval($firstpost['uid']),
'lastpost' => intval($lastpost['dateline']),
'lastposter' => $lastpost['username'],
'lastposteruid' => intval($lastpost['uid']),
);
$db->update_query(TABLE_PREFIX."threads", $update_array, "tid='{$tid}'");
}
function update_forum_count($fid)
{
die("Depreciated function call: update_forum_count");
}
function update_thread_count($tid)
{
die("Depreciated function call: update_thread_count");
}
function update_thread_attachment_count($tid)
{
die("Depreciated function call: update_thread_attachment_count");
}
/**
* Deletes a thread from the database
*
* @param int The thread ID
*/
function delete_thread($tid)
{
global $moderation;
if(!is_object($moderation))
{
require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
}
return $moderation->delete_thread($tid);
}
/**
* Deletes a post from the database
*
* @param int The thread ID
*/
function delete_post($pid, $tid="")
{
global $moderation;
if(!is_object($moderation))
{
require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
}
return $moderation->delete_post($pid);
}
/**
* Builds a forum jump menu
*
* @param int The parent forum to start with
* @param int The selected item ID
* @param int If we need to add select boxes to this cal or not
* @param int The current depth of forums we're at
* @param int Whether or not to show extra items such as User CP, Forum home
* @param array Array of permissions
* @param string The name of the forum jump
* @return string Forum jump items
*/
function build_forum_jump($pid="0", $selitem="", $addselect="1", $depth="", $showextras="1", $permissions="", $name="fid")
{
global $db, $forum_cache, $fjumpcache, $permissioncache, $mybb, $selecteddone, $forumjump, $forumjumpbits, $gobutton, $theme, $templates, $lang;
$pid = intval($pid);
if($permissions)
{
$permissions = $mybb->usergroup;
}
if(!is_array($jumpfcache))
{
if(!is_array($forum_cache))
{
cache_forums();
}
foreach($forum_cache as $fid => $forum)
{
if($forum['active'] != "no")
{
$jumpfcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
}
}
}
if(!is_array($permissioncache))
{
$permissioncache = forum_permissions();
}
if(is_array($jumpfcache[$pid]))
{
foreach($jumpfcache[$pid] as $main)
{
foreach($main as $forum)
{
$perms = $permissioncache[$forum['fid']];
if($forum['fid'] != "0" && ($perms['canview'] != "no" $mybb->settings['hideprivateforums'] == "no") && $forum['linkto'] == '' && $forum['showinjump'] != "no")
{
$optionselected = "";
if($selitem == $forum['fid'])
{
$optionselected = "selected=\"selected\"";
$selecteddone = 1;
}
eval("\$forumjumpbits .= \"".$templates->get("forumjump_bit")."\";");
if($forum_cache[$forum['fid']])
{
$newdepth = $depth."--";
$forumjumpbits .= build_forum_jump($forum['fid'], $selitem, 0, $newdepth, $showextras);
}
}
}
}
}
if($addselect)
{
if(!$selecteddone)
{
if(!$selitem)
{
$selitem = "default";
}
$jumpsel[$selitem] = "selected";
}
if($showextras == 0)
{
$template = "special";
}
else
{
$template = "advanced";
}
eval("\$forumjump = \"".$templates->get("forumjump_".$template)."\";");
}
return $forumjump;
}
/**
* Returns the extension of a file.
*
* @param string The filename.
* @return string The extension of the file.
*/
function get_extension($file)
{
return strtolower(my_substr(strrchr($file, "."), 1));
}
/**
* Generates a random string.
*
* @param int The length of the string to generate.
* @return string The random string.
*/
function random_str($length="8")
{
$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;
for($i = 1; $i <= $length; $i++)
{
$ch = rand(0, count($set)-1);
$str .= $set[$ch];
}
return $str;
}
/**
* Formats a username based on their display group
*
* @param string The username
* @param int The usergroup for the user (if not specified, will be fetched)
* @param int The display group for the user (if not specified, will be fetched)
* @return string The formatted username
*/
function format_name($username, $usergroup, $displaygroup="")
{
global $groupscache, $cache;
if(!is_array($groupscache))
{
$groupscache = $cache->read("usergroups");
}
if($displaygroup != 0)
{
$usergroup = $displaygroup;
}
$ugroup = $groupscache[$usergroup];
$format = $ugroup['namestyle'];
$userin = substr_count($format, "{username}");
if($userin == 0)
{
$format = "{username}";
}
$format = stripslashes($format);
return str_replace("{username}", $username, $format);
}
/**
* Build the javascript based MyCode inserter
*
* @return string The MyCode inserter
*/
function build_mycode_inserter()
{
global $db, $mybb, $theme, $templates, $lang;
if($mybb->settings['bbcodeinserter'] != "off")
{
$editor_lang_strings = array(
"editor_title_bold",
"editor_title_italic",
"editor_title_underline",
"editor_title_left",
"editor_title_center",
"editor_title_right",
"editor_title_justify",
"editor_title_numlist",
"editor_title_bulletlist",
"editor_title_image",
"editor_title_hyperlink",
"editor_title_email",
"editor_title_quote",
"editor_title_code",
"editor_title_php",
"editor_title_close_tags",
"editor_enter_list_item",
"editor_enter_url",
"editor_enter_url_title",
"editor_enter_email",
"editor_enter_email_title",
"editor_enter_image",
"editor_size_xx_small",
"editor_size_x_small",
"editor_size_small",
"editor_size_medium",
"editor_size_x_large",
"editor_size_xx_large",
"editor_color_white",
"editor_color_black",
"editor_color_red",
"editor_color_yellow",
"editor_color_pink",
"editor_color_green",
"editor_color_orange",
"editor_color_purple",
"editor_color_blue",
"editor_color_beige",
"editor_color_brown",
"editor_color_teal",
"editor_color_navy",
"editor_color_maroon",
"editor_color_limegreen",
"editor_font",
"editor_size",
"editor_color"
);
$editor_language = "var editor_language = {\n";
foreach($editor_lang_strings as $key => $lang_string)
{
// Strip initial editor_ off language string if it exists - ensure case sensitivity does not matter.
$js_lang_string = preg_replace("#^editor_#i", "", $lang_string);
$string = str_replace("\"", "\\\"", $lang->$lang_string);
$editor_language .= "\t{$js_lang_string}: \"{$string}\"";
if($editor_lang_strings[$key+1])
{
$editor_language .= ",";
}
$editor_language .= "\n";
}
$editor_language .= "};";
eval("\$codeinsert = \"".$templates->get("codebuttons")."\";");
}
return $codeinsert;
}
/**
* Build the javascript clickable smilie inserter
*
* @return string The clickable smilies list
*/
function build_clickable_smilies()
{
global $db, $smiliecache, $theme, $templates, $lang, $mybb, $smiliecount;
if($mybb->settings['smilieinserter'] != "off" && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
{
if(!$smiliecount)
{
$query = $db->simple_select(TABLE_PREFIX."smilies", "COUNT(*) as smilies");
$smiliecount = $db->fetch_field($query, "smilies");
}
if(!$smiliecache)
{
$query = $db->simple_select(TABLE_PREFIX."smilies", "*", "showclickable != 'no'", array('order_by' => 'disporder'));
while($smilie = $db->fetch_array($query))
{
$smiliecache[$smilie['find']] = $smilie['image'];
}
}
unset($smilie);
if(is_array($smiliecache))
{
reset($smiliecache);
if($mybb->settings['smilieinsertertot'] >= $smiliecount)
{
$mybb->settings['smilieinsertertot'] = $smiliecount;
}
elseif ($mybb->settings['smilieinsertertot'] < $smiliecount)
{
$smiliecount = $mybb->settings['smilieinsertertot'];
eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";");
}
$smilies = "";
$counter = 0;
$i = 0;
foreach($smiliecache as $find => $image)
{
if($i < $mybb->settings['smilieinsertertot'])
{
if($counter == 0)
{
$smilies .= "<tr>\n";
}
$find = htmlspecialchars_uni($find);
$smilies .= "<td><img src=\"{$image}\" border=\"0\" class=\"smilie\" alt=\"{$find}\" /></td>\n";
$i++;
$counter++;
if($counter == $mybb->settings['smilieinsertercols'])
{
$counter = 0;
$smilies .= "</tr>\n";
}
}
}
if($counter != 0)
{
$colspan = $mybb->settings['smilieinsertercols'] - $counter;
$smilies .= "<td colspan=\"{$colspan}\"></td>\n</tr>\n";
}
eval("\$clickablesmilies = \"".$templates->get("smilieinsert")."\";");
}
else
{
$clickablesmilies = "";
}
}
else
{
$clickablesmilies = "";
}
return $clickablesmilies;
}
/**
* Gzip encodes text to a specified level
*
* @param string The string to encode
* @param int The level (1-9) to encode at
* @return string The encoded string
*/
function gzip_encode($contents, $level=1)
{
if(function_exists("gzcompress") && function_exists("crc32") && !headers_sent() && !(ini_get('output_buffering') && strpos(' '.ini_get('output_handler'), 'ob_gzhandler')))
{
$httpaccept_encoding = '';
if(isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
$httpaccept_encoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
}
if(strpos(" ".$httpaccept_encoding, "x-gzip"))
{
$encoding = "x-gzip";
}
if(