Zeile 11 | Zeile 11 |
---|
/** * Outputs a page directly to the browser, parsing anything which needs to be parsed. *
|
/** * Outputs a page directly to the browser, parsing anything which needs to be parsed. *
|
* @param string The contents of the page.
| * @param string $contents The contents of the page.
|
*/ function output_page($contents) { global $db, $lang, $theme, $templates, $plugins, $mybb; global $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;
|
*/ function output_page($contents) { global $db, $lang, $theme, $templates, $plugins, $mybb; global $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;
|
| $contents = $plugins->run_hooks("pre_parse_page", $contents);
|
$contents = parse_page($contents); $totaltime = format_time_duration($maintimer->stop()); $contents = $plugins->run_hooks("pre_output_page", $contents);
| $contents = parse_page($contents); $totaltime = format_time_duration($maintimer->stop()); $contents = $plugins->run_hooks("pre_output_page", $contents);
|
Zeile 101 | Zeile 102 |
---|
/** * Adds a function or class to the list of code to run on shutdown. *
|
/** * Adds a function or class to the list of code to run on shutdown. *
|
* @param mixed The name of the function. * @param mixed An array of arguments for the function
| * @param string|array $name The name of the function. * @param mixed $arguments Either an array of arguments for the function or one argument
|
* @return boolean True if function exists, otherwise false. */ function add_shutdown($name, $arguments=array())
| * @return boolean True if function exists, otherwise false. */ function add_shutdown($name, $arguments=array())
|
Zeile 173 | Zeile 174 |
---|
if(isset($config)) {
|
if(isset($config)) {
|
| // Load DB interface require_once MYBB_ROOT."inc/db_base.php"; require_once MYBB_ROOT . 'inc/AbstractPdoDbDriver.php';
|
require_once MYBB_ROOT."inc/db_".$config['database']['type'].".php"; switch($config['database']['type']) { case "sqlite": $db = new DB_SQLite;
|
require_once MYBB_ROOT."inc/db_".$config['database']['type'].".php"; switch($config['database']['type']) { case "sqlite": $db = new DB_SQLite;
|
break;
| break;
|
case "pgsql": $db = new DB_PgSQL;
|
case "pgsql": $db = new DB_PgSQL;
|
break;
| break; case "pgsql_pdo": $db = new PostgresPdoDbDriver(); break;
|
case "mysqli": $db = new DB_MySQLi;
|
case "mysqli": $db = new DB_MySQLi;
|
| break; case "mysql_pdo": $db = new MysqlPdoDbDriver();
|
break; default: $db = new DB_MySQL;
| break; default: $db = new DB_MySQL;
|
Zeile 195 | Zeile 206 |
---|
define("TABLE_PREFIX", $config['database']['table_prefix']); } $db->set_table_prefix(TABLE_PREFIX);
|
define("TABLE_PREFIX", $config['database']['table_prefix']); } $db->set_table_prefix(TABLE_PREFIX);
|
}
| }
|
}
// Cache object deconstructed? reconstruct
| }
// Cache object deconstructed? reconstruct
|
Zeile 220 | Zeile 231 |
---|
// Loop through and run them all foreach($shutdown_queries as $query) {
|
// Loop through and run them all foreach($shutdown_queries as $query) {
|
$db->query($query);
| $db->write_query($query);
|
} }
| } }
|
Zeile 239 | Zeile 250 |
---|
/** * Sends a specified amount of messages from the mail queue *
|
/** * Sends a specified amount of messages from the mail queue *
|
* @param int The number of messages to send (Defaults to 10)
| * @param int $count The number of messages to send (Defaults to 10)
|
*/ function send_mail_queue($count=10) {
| */ function send_mail_queue($count=10) {
|
Zeile 249 | Zeile 260 |
---|
// Check to see if the mail queue has messages needing to be sent $mailcache = $cache->read("mailqueue");
|
// 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_NOW-300))
| if($mailcache !== false && $mailcache['queue_size'] > 0 && ($mailcache['locked'] == 0 || $mailcache['locked'] < TIME_NOW-300))
|
{ // Lock the queue so no other messages can be sent whilst these are (for popular boards) $cache->update_mailqueue(0, TIME_NOW);
| { // Lock the queue so no other messages can be sent whilst these are (for popular boards) $cache->update_mailqueue(0, TIME_NOW);
|
Zeile 265 | Zeile 276 |
---|
if($db->affected_rows() == 1) { my_mail($email['mailto'], $email['subject'], $email['message'], $email['mailfrom'], "", $email['headers'], true);
|
if($db->affected_rows() == 1) { my_mail($email['mailto'], $email['subject'], $email['message'], $email['mailfrom'], "", $email['headers'], true);
|
}
| }
|
} // Update the mailqueue cache and remove the lock $cache->update_mailqueue(TIME_NOW, 0);
| } // Update the mailqueue cache and remove the lock $cache->update_mailqueue(TIME_NOW, 0);
|
Zeile 277 | Zeile 288 |
---|
/** * Parses the contents of a page before outputting it. *
|
/** * Parses the contents of a page before outputting it. *
|
* @param string The contents of the page.
| * @param string $contents The contents of the page.
|
* @return string The parsed page. */ function parse_page($contents)
| * @return string The parsed page. */ function parse_page($contents)
|
Zeile 309 | Zeile 320 |
---|
}
if($error_handler->warnings)
|
}
if($error_handler->warnings)
|
{
| {
|
$contents = str_replace("<body>", "<body>\n".$error_handler->show_warnings(), $contents); }
| $contents = str_replace("<body>", "<body>\n".$error_handler->show_warnings(), $contents); }
|
Zeile 319 | Zeile 330 |
---|
/** * Turn a unix timestamp in to a "friendly" date/time format for the user. *
|
/** * 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. * @param boolean Whether or not to use the adodb time class for < 1970 or > 2038 times
| * @param string $format A date format (either relative, normal or PHP's date() structure). * @param int $stamp The unix timestamp the date should be generated for. * @param int|string $offset The offset in hours that should be applied to times. (timezones) Or an empty string to determine that automatically * @param int $ty Whether or not to use today/yesterday formatting. * @param boolean $adodb Whether or not to use the adodb time class for < 1970 or > 2038 times
|
* @return string The formatted timestamp. */
|
* @return string The formatted timestamp. */
|
function my_date($format, $stamp="", $offset="", $ty=1, $adodb=false)
| function my_date($format, $stamp=0, $offset="", $ty=1, $adodb=false)
|
{
|
{
|
global $mybb, $lang, $mybbadmin, $plugins;
| global $mybb, $lang, $plugins;
|
// If the stamp isn't set, use TIME_NOW if(empty($stamp))
| // If the stamp isn't set, use TIME_NOW if(empty($stamp))
|
Zeile 340 | Zeile 351 |
---|
{ if(isset($mybb->user['uid']) && $mybb->user['uid'] != 0 && array_key_exists("timezone", $mybb->user)) {
|
{ if(isset($mybb->user['uid']) && $mybb->user['uid'] != 0 && array_key_exists("timezone", $mybb->user)) {
|
$offset = $mybb->user['timezone'];
| $offset = (float)$mybb->user['timezone'];
|
$dstcorrection = $mybb->user['dst'];
|
$dstcorrection = $mybb->user['dst'];
|
} elseif(defined("IN_ADMINCP")) { $offset = $mybbadmin['timezone']; $dstcorrection = $mybbadmin['dst'];
| |
} else {
|
} else {
|
$offset = $mybb->settings['timezoneoffset'];
| $offset = (float)$mybb->settings['timezoneoffset'];
|
$dstcorrection = $mybb->settings['dstcorrection']; }
| $dstcorrection = $mybb->settings['dstcorrection']; }
|
Zeile 368 | Zeile 374 |
---|
if($offset == "-") { $offset = 0;
|
if($offset == "-") { $offset = 0;
|
}
| }
|
// Using ADOdb? if($adodb == true && !function_exists('adodb_date'))
|
// Using ADOdb? if($adodb == true && !function_exists('adodb_date'))
|
{
| {
|
$adodb = false; }
$todaysdate = $yesterdaysdate = '';
|
$adodb = false; }
$todaysdate = $yesterdaysdate = '';
|
if($ty && ($format == $mybb->settings['dateformat'] || $format == 'relative'))
| if($ty && ($format == $mybb->settings['dateformat'] || $format == 'relative' || $format == 'normal'))
|
{ $_stamp = TIME_NOW;
|
{ $_stamp = TIME_NOW;
|
if($adodb == true) {
| if($adodb == true) {
|
$date = adodb_date($mybb->settings['dateformat'], $stamp + ($offset * 3600)); $todaysdate = adodb_date($mybb->settings['dateformat'], $_stamp + ($offset * 3600)); $yesterdaysdate = adodb_date($mybb->settings['dateformat'], ($_stamp - 86400) + ($offset * 3600));
| $date = adodb_date($mybb->settings['dateformat'], $stamp + ($offset * 3600)); $todaysdate = adodb_date($mybb->settings['dateformat'], $_stamp + ($offset * 3600)); $yesterdaysdate = adodb_date($mybb->settings['dateformat'], ($_stamp - 86400) + ($offset * 3600));
|
Zeile 397 | Zeile 403 |
---|
if($format == 'relative') { // Relative formats both date and time
|
if($format == 'relative') { // Relative formats both date and time
|
if($ty != 2 && (TIME_NOW - $stamp) < 3600)
| $real_date = $real_time = ''; if($adodb == true) { $real_date = adodb_date($mybb->settings['dateformat'], $stamp + ($offset * 3600)); $real_time = $mybb->settings['datetimesep']; $real_time .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600)); } else { $real_date = gmdate($mybb->settings['dateformat'], $stamp + ($offset * 3600)); $real_time = $mybb->settings['datetimesep']; $real_time .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600)); }
if($ty != 2 && abs(TIME_NOW - $stamp) < 3600)
|
{ $diff = TIME_NOW - $stamp; $relative = array('prefix' => '', 'minute' => 0, 'plural' => $lang->rel_minutes_plural, 'suffix' => $lang->rel_ago);
|
{ $diff = TIME_NOW - $stamp; $relative = array('prefix' => '', 'minute' => 0, 'plural' => $lang->rel_minutes_plural, 'suffix' => $lang->rel_ago);
|
if($diff < 0) { $diff = abs($diff);
| if($diff < 0) { $diff = abs($diff);
|
$relative['suffix'] = ''; $relative['prefix'] = $lang->rel_in; }
| $relative['suffix'] = ''; $relative['prefix'] = $lang->rel_in; }
|
Zeile 414 | Zeile 434 |
---|
if($relative['minute'] <= 1) { $relative['minute'] = 1;
|
if($relative['minute'] <= 1) { $relative['minute'] = 1;
|
$relative['plural'] = $lang->rel_minutes_single; }
| $relative['plural'] = $lang->rel_minutes_single; }
|
if($diff <= 60) {
| if($diff <= 60) {
|
Zeile 423 | Zeile 443 |
---|
$relative['prefix'] = $lang->rel_less_than; }
|
$relative['prefix'] = $lang->rel_less_than; }
|
$date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['minute'], $relative['plural'], $relative['suffix']);
| $date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['minute'], $relative['plural'], $relative['suffix'], $real_date, $real_time);
|
}
|
}
|
elseif($ty != 2 && (TIME_NOW - $stamp) >= 3600 && (TIME_NOW - $stamp) < 43200)
| elseif($ty != 2 && abs(TIME_NOW - $stamp) < 43200)
|
{ $diff = TIME_NOW - $stamp;
|
{ $diff = TIME_NOW - $stamp;
|
$relative = array('prefix' => '', 'hour' => 0, 'plural' => $lang->rel_hours_plural, 'suffix' => $lang->rel_ago);
| $relative = array('prefix' => '', 'hour' => 0, 'plural' => $lang->rel_hours_plural, 'suffix' => $lang->rel_ago);
|
if($diff < 0) { $diff = abs($diff); $relative['suffix'] = ''; $relative['prefix'] = $lang->rel_in; }
|
if($diff < 0) { $diff = abs($diff); $relative['suffix'] = ''; $relative['prefix'] = $lang->rel_in; }
|
|
|
$relative['hour'] = floor($diff / 3600);
if($relative['hour'] <= 1)
|
$relative['hour'] = floor($diff / 3600);
if($relative['hour'] <= 1)
|
{
| {
|
$relative['hour'] = 1; $relative['plural'] = $lang->rel_hours_single; }
|
$relative['hour'] = 1; $relative['plural'] = $lang->rel_hours_single; }
|
$date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['hour'], $relative['plural'], $relative['suffix']);
| $date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['hour'], $relative['plural'], $relative['suffix'], $real_date, $real_time);
|
} else { if($ty) { if($todaysdate == $date)
|
} else { if($ty) { if($todaysdate == $date)
|
{ $date = $lang->today;
| { $date = $lang->sprintf($lang->today_rel, $real_date);
|
} else if($yesterdaysdate == $date) {
|
} else if($yesterdaysdate == $date) {
|
$date = $lang->yesterday;
| $date = $lang->sprintf($lang->yesterday_rel, $real_date);
|
} }
| } }
|
Zeile 465 | Zeile 485 |
---|
if($adodb == true) { $date .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));
|
if($adodb == true) { $date .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));
|
}
| }
|
else
|
else
|
{
| {
|
$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600)); }
|
$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600)); }
|
| } } elseif($format == 'normal') { // Normal format both date and time if($ty != 2) { if($todaysdate == $date) { $date = $lang->today; } else if($yesterdaysdate == $date) { $date = $lang->yesterday; } }
$date .= $mybb->settings['datetimesep']; if($adodb == true) { $date .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600)); } else { $date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));
|
} } else
| } } else
|
Zeile 486 | Zeile 531 |
---|
} } else
|
} } else
|
{
| {
|
if($adodb == true)
|
if($adodb == true)
|
{
| {
|
$date = adodb_date($format, $stamp + ($offset * 3600));
|
$date = adodb_date($format, $stamp + ($offset * 3600));
|
}
| }
|
else { $date = gmdate($format, $stamp + ($offset * 3600));
|
else { $date = gmdate($format, $stamp + ($offset * 3600));
|
} } }
| } } }
|
if(is_object($plugins))
|
if(is_object($plugins))
|
{
| {
|
$date = $plugins->run_hooks("my_date", $date); }
|
$date = $plugins->run_hooks("my_date", $date); }
|
return $date;
| return $date; }
/** * Get a mail handler instance, a MyBB's built-in SMTP / PHP mail hander or one created by a plugin. * @param bool $use_buitlin Whether to use MyBB's built-in mail handler. * * @return object A MyBB built-in mail handler or one created by plugin(s). */ function &get_my_mailhandler($use_buitlin = false) { global $mybb, $plugins; static $my_mailhandler; static $my_mailhandler_builtin;
if($use_buitlin) { // If our built-in mail handler doesn't exist, create it. if(!is_object($my_mailhandler_builtin)) { require_once MYBB_ROOT . "inc/class_mailhandler.php";
// Using SMTP. if(isset($mybb->settings['mail_handler']) && $mybb->settings['mail_handler'] == 'smtp') { require_once MYBB_ROOT . "inc/mailhandlers/smtp.php"; $my_mailhandler_builtin = new SmtpMail(); } // Using PHP mail(). else { require_once MYBB_ROOT . "inc/mailhandlers/php.php"; $my_mailhandler_builtin = new PhpMail(); if(!empty($mybb->config['mail_parameters'])) { $my_mailhandler_builtin->additional_parameters = $mybb->config['mail_parameters']; } } }
if(isset($plugins) && is_object($plugins)) { $plugins->run_hooks('my_mailhandler_builtin_after_init', $my_mailhandler_builtin); }
return $my_mailhandler_builtin; }
// If our mail handler doesn't exist, create it. if(!is_object($my_mailhandler)) { require_once MYBB_ROOT . "inc/class_mailhandler.php";
if(isset($plugins) && is_object($plugins)) { $plugins->run_hooks('my_mailhandler_init', $my_mailhandler); }
// If no plugin has ever created the mail handler, resort to use the built-in one. if(!is_object($my_mailhandler) || !($my_mailhandler instanceof MailHandler)) { $my_mailhandler = &get_my_mailhandler(true); } }
return $my_mailhandler;
|
}
/** * Sends an email using PHP's mail function, formatting it appropriately. *
|
}
/** * 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. * @param boolean Do we wish to keep the connection to the mail server alive to send more than one message (SMTP only) * @param string The format of the email to be sent (text or html). text is default * @param string The text message of the email if being sent in html format, for email clients that don't support html * @param string The email address to return to. Defaults to admin return email address.
| * @param string $to Address the email should be addressed to. * @param string $subject The subject of the email being sent. * @param string $message The message being sent. * @param string $from The from address of the email, if blank, the board name will be used. * @param string $charset The chracter set being used to send this email. * @param string $headers * @param boolean $keep_alive Do we wish to keep the connection to the mail server alive to send more than one message (SMTP only) * @param string $format The format of the email to be sent (text or html). text is default * @param string $message_text The text message of the email if being sent in html format, for email clients that don't support html * @param string $return_email The email address to return to. Defaults to admin return email address. * @return bool True if the mail is sent, false otherwise.
|
*/ function my_mail($to, $subject, $message, $from="", $charset="", $headers="", $keep_alive=false, $format="text", $message_text="", $return_email="") {
|
*/ function my_mail($to, $subject, $message, $from="", $charset="", $headers="", $keep_alive=false, $format="text", $message_text="", $return_email="") {
|
global $mybb; static $mail;
| global $mybb, $plugins;
// Get our mail handler. $mail = &get_my_mailhandler();
|
|
|
// Does our object not exist? Create it if(!is_object($mail))
| // If MyBB's built-in SMTP mail handler is used, set the keep alive bit accordingly. if($keep_alive == true && isset($mail->keep_alive) && isset($mybb->settings['mail_handler']) && $mybb->settings['mail_handler'] == 'smtp')
|
{
|
{
|
require_once MYBB_ROOT."inc/class_mailhandler.php";
if($mybb->settings['mail_handler'] == 'smtp') { require_once MYBB_ROOT."inc/mailhandlers/smtp.php"; $mail = new SmtpMail(); } else { require_once MYBB_ROOT."inc/mailhandlers/php.php"; $mail = new PhpMail(); } }
// Using SMTP based mail if($mybb->settings['mail_handler'] == 'smtp') { if($keep_alive == true)
| require_once MYBB_ROOT . "inc/class_mailhandler.php"; require_once MYBB_ROOT . "inc/mailhandlers/smtp.php"; if($mail instanceof MailHandler && $mail instanceof SmtpMail)
|
{ $mail->keep_alive = true; } }
|
{ $mail->keep_alive = true; } }
|
// Using PHP based mail() else { if($mybb->settings['mail_parameters'] != '') { $mail->additional_parameters = $mybb->settings['mail_parameters']; } }
// Build and send $mail->build_message($to, $subject, $message, $from, $charset, $headers, $format, $message_text, $return_email); return $mail->send();
| // Following variables will help sequential plugins to determine how to process plugin hooks. // Mark this variable true if the hooked plugin has sent the mail, otherwise don't modify it. $is_mail_sent = false; // Mark this variable false if the hooked plugin doesn't suggest sequential plugins to continue processing. $continue_process = true;
$my_mail_parameters = array( 'to' => &$to, 'subject' => &$subject, 'message' => &$message, 'from' => &$from, 'charset' => &$charset, 'headers' => &$headers, 'keep_alive' => &$keep_alive, 'format' => &$format, 'message_text' => &$message_text, 'return_email' => &$return_email, 'is_mail_sent' => &$is_mail_sent, 'continue_process' => &$continue_process, );
if(isset($plugins) && is_object($plugins)) { $plugins->run_hooks('my_mail_pre_build_message', $my_mail_parameters); }
// Build the mail message. $mail->build_message($to, $subject, $message, $from, $charset, $headers, $format, $message_text, $return_email);
if(isset($plugins) && is_object($plugins)) { $plugins->run_hooks('my_mail_pre_send', $my_mail_parameters); }
// Check if the hooked plugins still suggest to send the mail. if($continue_process) { $is_mail_sent = $mail->send(); }
if(isset($plugins) && is_object($plugins)) { $plugins->run_hooks('my_mail_post_send', $my_mail_parameters); }
return $is_mail_sent;
|
}
/**
|
}
/**
|
* Generates a unique code for POST requests to prevent XSS/CSRF attacks
| * Generates a code for POST requests to prevent XSS/CSRF attacks. * Unique for each user or guest session and rotated every 6 hours.
|
*
|
*
|
| * @param int $rotation_shift Adjustment of the rotation number to generate a past/future code
|
* @return string The generated code */
|
* @return string The generated code */
|
function generate_post_check()
| function generate_post_check($rotation_shift=0)
|
{ global $mybb, $session;
|
{ global $mybb, $session;
|
| $rotation_interval = 6 * 3600; $rotation = floor(TIME_NOW / $rotation_interval) + $rotation_shift;
$seed = $rotation;
|
if($mybb->user['uid'])
|
if($mybb->user['uid'])
|
{ return md5($mybb->user['loginkey'].$mybb->user['salt'].$mybb->user['regdate']); } // Guests get a special string
| { $seed .= $mybb->user['loginkey'].$mybb->user['salt'].$mybb->user['regdate']; }
|
else {
|
else {
|
return md5($session->useragent.$mybb->config['database']['username'].$mybb->settings['internal']['encryption_key']);
| $seed .= $session->sid; }
if(defined('IN_ADMINCP')) { $seed .= 'ADMINCP';
|
}
|
}
|
| $seed .= $mybb->settings['internal']['encryption_key'];
return md5($seed);
|
}
/**
|
}
/**
|
* Verifies a POST check code is valid, if not shows an error (silently returns false on silent parameter)
| * Verifies a POST check code is valid (i.e. generated using a rotation number from the past 24 hours)
|
*
|
*
|
* @param string The incoming POST check code * @param boolean Silent mode or not (silent mode will not show the error to the user but returns false)
| * @param string $code The incoming POST check code * @param boolean $silent Don't show an error to the user * @return bool|void Result boolean if $silent is true, otherwise shows an error to the user
|
*/ function verify_post_check($code, $silent=false) { global $lang;
|
*/ function verify_post_check($code, $silent=false) { global $lang;
|
if(generate_post_check() != $code)
| if( generate_post_check() !== $code && generate_post_check(-1) !== $code && generate_post_check(-2) !== $code && generate_post_check(-3) !== $code )
|
{ if($silent == true) {
| { if($silent == true) {
|
Zeile 619 | Zeile 774 |
---|
/** * Return a parent list for the specified forum. *
|
/** * Return a parent list for the specified forum. *
|
* @param int The forum id to get the parent list for.
| * @param int $fid The forum id to get the parent list for.
|
* @return string The comma-separated parent list. */ function get_parent_list($fid)
| * @return string The comma-separated parent list. */ function get_parent_list($fid)
|
Zeile 627 | Zeile 782 |
---|
global $forum_cache; static $forumarraycache;
|
global $forum_cache; static $forumarraycache;
|
if($forumarraycache[$fid])
| if(!empty($forumarraycache[$fid]))
|
{ return $forumarraycache[$fid]['parentlist']; }
|
{ return $forumarraycache[$fid]['parentlist']; }
|
elseif($forum_cache[$fid])
| elseif(!empty($forum_cache[$fid]))
|
{ return $forum_cache[$fid]['parentlist']; }
| { return $forum_cache[$fid]['parentlist']; }
|
Zeile 645 | Zeile 800 |
---|
/** * Build a parent list of a specific forum, suitable for querying *
|
/** * 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
| * @param int $fid The forum ID * @param string $column The column name to add to the query * @param string $joiner The joiner for each forum for querying (OR | AND | etc) * @param string $parentlist 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="")
| * @return string The query string generated */ function build_parent_list($fid, $column="fid", $joiner="OR", $parentlist="")
|
Zeile 676 | Zeile 831 |
---|
/** * Load the forum cache in to memory *
|
/** * Load the forum cache in to memory *
|
* @param boolean True to force a reload of the cache
| * @param boolean $force True to force a reload of the cache * @return array The forum cache
|
*/ function cache_forums($force=false) {
| */ function cache_forums($force=false) {
|
Zeile 703 | Zeile 859 |
---|
/** * Generate an array of all child and descendant forums for a specific forum. *
|
/** * Generate an array of all child and descendant forums for a specific forum. *
|
* @param int The forum ID * @param return Array of descendants
| * @param int $fid The forum ID * @return Array of descendants
|
*/ function get_child_list($fid) {
| */ function get_child_list($fid) {
|
Zeile 722 | Zeile 878 |
---|
} } }
|
} } }
|
if(!is_array($forums_by_parent[$fid]))
| if(isset($forums_by_parent[$fid]))
|
{
|
{
|
return; }
| if(!is_array($forums_by_parent[$fid])) { return $forums; }
|
|
|
foreach($forums_by_parent[$fid] as $forum) { $forums[] = $forum['fid']; $children = get_child_list($forum['fid']); if(is_array($children))
| foreach($forums_by_parent[$fid] as $forum)
|
{
|
{
|
$forums = array_merge($forums, $children);
| $forums[] = (int)$forum['fid']; $children = get_child_list($forum['fid']); if(is_array($children)) { $forums = array_merge($forums, $children); }
|
} } return $forums;
| } } return $forums;
|
Zeile 741 | Zeile 900 |
---|
/** * Produce a friendly error message page
|
/** * 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
| * * @param string $error The error message to be shown * @param string $title The title of the message shown in the title of the page and the error table
|
*/ function error($error="", $title="") {
| */ function error($error="", $title="") {
|
Zeile 756 | Zeile 915 |
---|
}
// AJAX error message?
|
}
// AJAX error message?
|
if($mybb->get_input('ajax', 1))
| if($mybb->get_input('ajax', MyBB::INPUT_INT))
|
{ // Send our headers. @header("Content-type: application/json; charset={$lang->settings['charset']}"); echo json_encode(array("errors" => array($error))); exit;
|
{ // Send our headers. @header("Content-type: application/json; charset={$lang->settings['charset']}"); echo json_encode(array("errors" => array($error))); exit;
|
}
if(!$title) {
| }
if(!$title) {
|
$title = $mybb->settings['bbname']; }
$timenow = my_date('relative', TIME_NOW); reset_breadcrumb(); add_breadcrumb($lang->error);
|
$title = $mybb->settings['bbname']; }
$timenow = my_date('relative', TIME_NOW); reset_breadcrumb(); add_breadcrumb($lang->error);
|
|
|
eval("\$errorpage = \"".$templates->get("error")."\";"); output_page($errorpage);
| eval("\$errorpage = \"".$templates->get("error")."\";"); output_page($errorpage);
|
Zeile 782 | Zeile 941 |
---|
/** * Produce an error message for displaying inline on a page *
|
/** * 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 * @param string JSON data to be encoded (we may want to send more data; e.g. newreply.php uses this for CAPTCHA)
| * @param array $errors Array of errors to be shown * @param string $title The title of the error message * @param array $json_data JSON data to be encoded (we may want to send more data; e.g. newreply.php uses this for CAPTCHA)
|
* @return string The inline error HTML */ function inline_error($errors, $title="", $json_data=array()) { global $theme, $mybb, $db, $lang, $templates;
|
* @return string The inline error HTML */ function inline_error($errors, $title="", $json_data=array()) { global $theme, $mybb, $db, $lang, $templates;
|
if(!$title) {
| if(!$title) {
|
$title = $lang->please_correct_errors; }
| $title = $lang->please_correct_errors; }
|
Zeile 802 | Zeile 961 |
---|
}
// AJAX error message?
|
}
// AJAX error message?
|
if($mybb->get_input('ajax', 1))
| if($mybb->get_input('ajax', MyBB::INPUT_INT))
|
{ // Send our headers. @header("Content-type: application/json; charset={$lang->settings['charset']}");
| { // Send our headers. @header("Content-type: application/json; charset={$lang->settings['charset']}");
|
Zeile 814 | Zeile 973 |
---|
else { echo json_encode(array_merge(array("errors" => $errors), $json_data));
|
else { echo json_encode(array_merge(array("errors" => $errors), $json_data));
|
} exit; }
| } exit; }
|
$errorlist = '';
foreach($errors as $error) {
|
$errorlist = '';
foreach($errors as $error) {
|
$errorlist .= "<li>".$error."</li>\n";
| eval("\$errorlist .= \"".$templates->get("error_inline_item")."\";");
|
}
eval("\$errors = \"".$templates->get("error_inline")."\";");
| }
eval("\$errors = \"".$templates->get("error_inline")."\";");
|
Zeile 839 | Zeile 998 |
---|
$time = TIME_NOW; $plugins->run_hooks("no_permission");
|
$time = TIME_NOW; $plugins->run_hooks("no_permission");
|
|
|
$noperm_array = array ( "nopermission" => '1', "location1" => 0,
| $noperm_array = array ( "nopermission" => '1', "location1" => 0,
|
Zeile 848 | Zeile 1007 |
---|
$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'");
|
$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'");
|
if($mybb->get_input('ajax', 1))
| if($mybb->get_input('ajax', MyBB::INPUT_INT))
|
{ // Send our headers. header("Content-type: application/json; charset={$lang->settings['charset']}");
| { // Send our headers. header("Content-type: application/json; charset={$lang->settings['charset']}");
|
Zeile 858 | Zeile 1017 |
---|
if($mybb->user['uid']) {
|
if($mybb->user['uid']) {
|
$lang->error_nopermission_user_username = $lang->sprintf($lang->error_nopermission_user_username, $mybb->user['username']);
| $lang->error_nopermission_user_username = $lang->sprintf($lang->error_nopermission_user_username, htmlspecialchars_uni($mybb->user['username']));
|
eval("\$errorpage = \"".$templates->get("error_nopermission_loggedin")."\";"); } else
| eval("\$errorpage = \"".$templates->get("error_nopermission_loggedin")."\";"); } else
|
Zeile 875 | Zeile 1034 |
---|
switch($mybb->settings['username_method']) { case 0:
|
switch($mybb->settings['username_method']) { case 0:
|
$lang_username = $lang->username;
| $lang_username = $lang->username;
|
break; case 1: $lang_username = $lang->username1; break; case 2: $lang_username = $lang->username2;
|
break; case 1: $lang_username = $lang->username1; break; case 2: $lang_username = $lang->username2;
|
break;
| break;
|
default: $lang_username = $lang->username; break;
|
default: $lang_username = $lang->username; break;
|
}
| }
|
eval("\$errorpage = \"".$templates->get("error_nopermission")."\";"); }
|
eval("\$errorpage = \"".$templates->get("error_nopermission")."\";"); }
|
|
|
error($errorpage); }
/** * Redirect the user to a given URL with a given message *
|
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 * @param string The title of the redirection page * @param boolean Force the redirect page regardless of settings
| * @param string $url The URL to redirect the user to * @param string $message The redirection message to be shown * @param string $title The title of the redirection page * @param boolean $force_redirect Force the redirect page regardless of settings
|
*/ function redirect($url, $message="", $title="", $force_redirect=false)
|
*/ function redirect($url, $message="", $title="", $force_redirect=false)
|
{
| {
|
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;
$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);
$plugins->run_hooks("redirect", $redirect_args);
|
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;
$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);
$plugins->run_hooks("redirect", $redirect_args);
|
if($mybb->get_input('ajax', 1))
| if($mybb->get_input('ajax', MyBB::INPUT_INT))
|
{ // Send our headers. //@header("Content-type: text/html; charset={$lang->settings['charset']}");
| { // Send our headers. //@header("Content-type: text/html; charset={$lang->settings['charset']}");
|
Zeile 944 | Zeile 1103 |
---|
}
// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest, or they are forced.
|
}
// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest, or they are forced.
|
if($force_redirect == true || ($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] == 1 || !$mybb->user['uid'])))
| if($force_redirect == true || ($mybb->settings['redirects'] == 1 && (!$mybb->user['uid'] || $mybb->user['showredirect'] == 1)))
|
{ $url = str_replace("&", "&", $url); $url = htmlspecialchars_uni($url);
| { $url = str_replace("&", "&", $url); $url = htmlspecialchars_uni($url);
|
Zeile 959 | Zeile 1118 |
---|
run_shutdown();
|
run_shutdown();
|
if(my_substr($url, 0, 7) !== 'http://' && my_substr($url, 0, 8) !== 'https://' && my_substr($url, 0, 1) !== '/')
| if(!my_validate_url($url, true, true))
|
{ header("Location: {$mybb->settings['bburl']}/{$url}"); }
| { header("Location: {$mybb->settings['bburl']}/{$url}"); }
|
Zeile 975 | Zeile 1134 |
---|
/** * Generate a listing of page - pagination *
|
/** * 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 (If {page} is specified, the value will be replaced with the page #) * @param boolean Whether or not the multipage is being shown in the navigation breadcrumb
| * @param int $count The number of items * @param int $perpage The number of items to be shown per page * @param int $page The current page number * @param string $url The URL to have page numbers tacked on to (If {page} is specified, the value will be replaced with the page #) * @param boolean $breadcrumb Whether or not the multipage is being shown in the navigation breadcrumb
|
* @return string The generated pagination */ function multipage($count, $perpage, $page, $url, $breadcrumb=false) {
|
* @return string The generated pagination */ function multipage($count, $perpage, $page, $url, $breadcrumb=false) {
|
global $theme, $templates, $lang, $mybb;
| global $theme, $templates, $lang, $mybb, $plugins;
|
if($count <= $perpage) {
|
if($count <= $perpage) {
|
return;
| return '';
|
}
|
}
|
| $args = array( 'count' => &$count, 'perpage' => &$perpage, 'page' => &$page, 'url' => &$url, 'breadcrumb' => &$breadcrumb, ); $plugins->run_hooks('multipage', $args);
$page = (int)$page;
|
$url = str_replace("&", "&", $url); $url = htmlspecialchars_uni($url);
| $url = str_replace("&", "&", $url); $url = htmlspecialchars_uni($url);
|
Zeile 1095 | Zeile 1265 |
---|
eval("\$jumptopage = \"".$templates->get("multipage_jump_page")."\";"); }
|
eval("\$jumptopage = \"".$templates->get("multipage_jump_page")."\";"); }
|
$lang->multipage_pages = $lang->sprintf($lang->multipage_pages, $pages);
| $multipage_pages = $lang->sprintf($lang->multipage_pages, $pages);
|
if($breadcrumb == true) {
| if($breadcrumb == true) {
|
Zeile 1112 | Zeile 1282 |
---|
/** * Generate a page URL for use by the multipage function *
|
/** * Generate a page URL for use by the multipage function *
|
* @param string The URL being passed * @param int The page number
| * @param string $url The URL being passed * @param int $page The page number * @return string
|
*/ function fetch_page_url($url, $page) {
| */ function fetch_page_url($url, $page) {
|
Zeile 1154 | Zeile 1325 |
---|
/** * Fetch the permissions for a specific user *
|
/** * Fetch the permissions for a specific user *
|
* @param int The user ID
| * @param int $uid The user ID, if no user ID is provided then current user's ID will be considered.
|
* @return array Array of user permissions for the specified user */
|
* @return array Array of user permissions for the specified user */
|
function user_permissions($uid=0)
| function user_permissions($uid=null)
|
{ global $mybb, $cache, $groupscache, $user_cache;
// If no user id is specified, assume it is the current user
|
{ global $mybb, $cache, $groupscache, $user_cache;
// If no user id is specified, assume it is the current user
|
if($uid == 0) {
| if($uid === null) {
|
$uid = $mybb->user['uid'];
|
$uid = $mybb->user['uid'];
|
| }
// Its a guest. Return the group permissions directly from cache if($uid == 0) { return $groupscache[1];
|
}
// User id does not match current user, fetch permissions if($uid != $mybb->user['uid']) { // We've already cached permissions for this user, return them.
|
}
// 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'])
| if(!empty($user_cache[$uid]['permissions']))
|
{ return $user_cache[$uid]['permissions'];
|
{ return $user_cache[$uid]['permissions'];
|
}
| }
|
// This user was not already cached, fetch their user information.
|
// This user was not already cached, fetch their user information.
|
if(!$user_cache[$uid])
| if(empty($user_cache[$uid]))
|
{ $user_cache[$uid] = get_user($uid); }
|
{ $user_cache[$uid] = get_user($uid); }
|
|
|
// Collect group permissions. $gid = $user_cache[$uid]['usergroup'].",".$user_cache[$uid]['additionalgroups']; $groupperms = usergroup_permissions($gid);
| // Collect group permissions. $gid = $user_cache[$uid]['usergroup'].",".$user_cache[$uid]['additionalgroups']; $groupperms = usergroup_permissions($gid);
|
Zeile 1189 | Zeile 1366 |
---|
// Store group permissions in user cache. $user_cache[$uid]['permissions'] = $groupperms; return $groupperms;
|
// 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; } }
|
// 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
| * Fetch the usergroup permissions for a specific 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
| * @param int|string $gid 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, containing also a list of comma-separated checked groups under 'all_usergroups' index
|
*/ function usergroup_permissions($gid=0)
|
*/ 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]; }
| { global $cache, $groupscache, $grouppermignore, $groupzerogreater, $groupzerolesser, $groupxgreater, $grouppermbyswitch;
if(!is_array($groupscache)) { $groupscache = $cache->read("usergroups"); }
$groups = explode(",", $gid);
if(count($groups) == 1) { $groupscache[$gid]['all_usergroups'] = $gid; return $groupscache[$gid]; }
$usergroup = array(); $usergroup['all_usergroups'] = $gid;
// Get those switch permissions from the first valid group. $permswitches_usergroup = array(); $grouppermswitches = array(); foreach(array_values($grouppermbyswitch) as $permvalue) { if(is_array($permvalue)) { foreach($permvalue as $perm) { $grouppermswitches[] = $perm; } } else { $grouppermswitches[] = $permvalue; } } $grouppermswitches = array_unique($grouppermswitches); foreach($groups as $gid) { if(trim($gid) == "" || empty($groupscache[$gid])) { continue; } foreach($grouppermswitches as $perm) { $permswitches_usergroup[$perm] = $groupscache[$gid][$perm]; } break; // Only retieve the first available group's permissions as how following action does. }
|
foreach($groups as $gid) {
|
foreach($groups as $gid) {
|
if(trim($gid) == "" || !$groupscache[$gid])
| if(trim($gid) == "" || empty($groupscache[$gid]))
|
{ continue; }
| { continue; }
|
Zeile 1240 | Zeile 1451 |
---|
$permbit = ""; }
|
$permbit = ""; }
|
// 0 represents unlimited for numerical group permissions (i.e. private message limit) so take that into account. if(in_array($perm, $groupzerogreater) && ($access == 0 || $permbit === 0))
| // permission type: 0 not a numerical permission, otherwise a numerical permission. // Positive value is for `greater is more` permission, negative for `lesser is more`. $perm_is_numerical = 0; $perm_numerical_lowerbound = 0;
// 0 represents unlimited for most numerical group permissions (i.e. private message limit) so take that into account. if(in_array($perm, $groupzerogreater)) { // 1 means a `0 or greater` permission. Value 0 means unlimited. $perm_is_numerical = 1; } // Less is more for some numerical group permissions (i.e. post count required for using signature) so take that into account, too. else if(in_array($perm, $groupzerolesser)) { // -1 means a `0 or lesser` permission. Value 0 means unlimited. $perm_is_numerical = -1; } // Greater is more, but with a lower bound. else if(array_key_exists($perm, $groupxgreater)) { // 2 means a general `greater` permission. Value 0 just means 0. $perm_is_numerical = 2; $perm_numerical_lowerbound = $groupxgreater[$perm]; }
if($perm_is_numerical != 0)
|
{
|
{
|
$usergroup[$perm] = 0;
| $update_current_perm = true;
// Ensure it's an integer. $access = (int)$access; // Check if this permission should be activatived by another switch permission in current group. if(array_key_exists($perm, $grouppermbyswitch)) { if(!is_array($grouppermbyswitch[$perm])) { $grouppermbyswitch[$perm] = array($grouppermbyswitch[$perm]); }
$update_current_perm = $group_current_perm_enabled = $group_perm_enabled = false; foreach($grouppermbyswitch[$perm] as $permswitch) { if(!isset($groupscache[$gid][$permswitch])) { continue; } $permswitches_current = $groupscache[$gid][$permswitch];
// Determin if the permission is enabled by switches from current group. if($permswitches_current == 1 || $permswitches_current == "yes") // Keep yes/no for compatibility? { $group_current_perm_enabled = true; } // Determin if the permission is enabled by switches from previously handled groups. if($permswitches_usergroup[$permswitch] == 1 || $permswitches_usergroup[$permswitch] == "yes") // Keep yes/no for compatibility? { $group_perm_enabled = true; } }
// Set this permission if not set yet. if(!isset($usergroup[$perm])) { $usergroup[$perm] = $access; }
// If current group's setting enables the permission, we may need to update the user's permission. if($group_current_perm_enabled) { // Only update this permission if both its switch and current group switch are on. if($group_perm_enabled) { $update_current_perm = true; } // Override old useless value with value from current group. else { $usergroup[$perm] = $access; } } }
// No switch controls this permission, or permission needs an update. if($update_current_perm) { switch($perm_is_numerical) { case 1: case -1: if($access == 0 || $permbit === 0) { $usergroup[$perm] = 0; break; } default: if($perm_is_numerical > 0 && $access > $permbit || $perm_is_numerical < 0 && $access < $permbit) { $usergroup[$perm] = $access; } break; } }
// Maybe oversubtle, database uses Unsigned on them, but enables usage of permission value with a lower bound. if($usergroup[$perm] < $perm_numerical_lowerbound) { $usergroup[$perm] = $perm_numerical_lowerbound; }
// Work is done for numerical permissions.
|
continue; }
| continue; }
|
Zeile 1252 | Zeile 1569 |
---|
$usergroup[$perm] = $access; } }
|
$usergroup[$perm] = $access; } }
|
| }
foreach($permswitches_usergroup as $perm => $value) { $permswitches_usergroup[$perm] = $usergroup[$perm];
|
} }
| } }
|
Zeile 1261 | Zeile 1583 |
---|
/** * Fetch the display group properties for a specific display group *
|
/** * Fetch the display group properties for a specific display group *
|
* @param int The group ID to fetch the display properties for
| * @param int $gid The group ID to fetch the display properties for
|
* @return array Array of display properties for the group */ function usergroup_displaygroup($gid)
| * @return array Array of display properties for the group */ function usergroup_displaygroup($gid)
|
Zeile 1275 | Zeile 1597 |
---|
$displaygroup = array(); $group = $groupscache[$gid];
|
$displaygroup = array(); $group = $groupscache[$gid];
|
|
|
foreach($displaygroupfields as $field) { $displaygroup[$field] = $group[$field]; }
|
foreach($displaygroupfields as $field) { $displaygroup[$field] = $group[$field]; }
|
|
|
return $displaygroup; }
/** * Build the forum permissions for a specific forum, user or group
|
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 will select the uid automatically) * @param int The group of the user to build permissions for (0 will fetch it)
| * * @param int $fid The forum ID to build permissions for (0 builds for all forums) * @param int $uid The user to build the permissions for (0 will select the uid automatically) * @param int $gid 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)
| * @return array Forum permissions for the specific forum or forums */ function forum_permissions($fid=0, $uid=0, $gid=0)
|
Zeile 1324 | Zeile 1646 |
---|
}
if(!is_array($forum_cache))
|
}
if(!is_array($forum_cache))
|
{
| {
|
$forum_cache = cache_forums();
|
$forum_cache = cache_forums();
|
|
|
if(!$forum_cache) { return false; }
|
if(!$forum_cache) { return false; }
|
}
| }
|
if(!is_array($fpermcache)) { $fpermcache = $cache->read("forumpermissions");
|
if(!is_array($fpermcache)) { $fpermcache = $cache->read("forumpermissions");
|
}
| }
|
if($fid) // Fetch the permissions for a single forum {
| if($fid) // Fetch the permissions for a single forum {
|
Zeile 1347 | Zeile 1669 |
---|
return $cached_forum_permissions_permissions[$gid][$fid]; } else
|
return $cached_forum_permissions_permissions[$gid][$fid]; } else
|
{
| {
|
if(empty($cached_forum_permissions[$gid])) { foreach($forum_cache as $forum)
| if(empty($cached_forum_permissions[$gid])) { foreach($forum_cache as $forum)
|
Zeile 1363 | Zeile 1685 |
---|
* Fetches the permissions for a specific forum/group applying the inheritance scheme. * Called by forum_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
| * @param int $fid The forum ID * @param string $gid A comma separated list of usergroups * @param array $groupperms Group permissions
|
* @return array Permissions for this forum */ function fetch_forum_permissions($fid, $gid, $groupperms) { global $groupscache, $forum_cache, $fpermcache, $mybb, $fpermfields;
|
* @return array Permissions for this forum */ function fetch_forum_permissions($fid, $gid, $groupperms) { global $groupscache, $forum_cache, $fpermcache, $mybb, $fpermfields;
|
$groups = explode(",", $gid);
if(empty($fpermcache[$fid])) // This forum has no custom or inherited permissions so lets just return the group permissions { return $groupperms; }
| if(isset($gid)) { $groups = explode(",", $gid); } else { $groups = array(); }
|
$current_permissions = array();
|
$current_permissions = array();
|
$only_view_own_threads = 1;
foreach($groups as $gid) { if(!empty($groupscache[$gid])) { // If our permissions arn't inherited we need to figure them out if(empty($fpermcache[$fid][$gid])) { $parents = explode(',', $forum_cache[$fid]['parentlist']); rsort($parents); if(!empty($parents)) { foreach($parents as $parent_id) { if(!empty($fpermcache[$parent_id][$gid])) { $level_permissions = $fpermcache[$parent_id][$gid]; break; } } } } else { $level_permissions = $fpermcache[$fid][$gid]; }
// If we STILL don't have forum permissions we use the usergroup itself if(empty($level_permissions))
| $only_view_own_threads = 1; $only_reply_own_threads = 1;
if(empty($fpermcache[$fid])) // This forum has no custom or inherited permissions so lets just return the group permissions { $current_permissions = $groupperms; } else { foreach($groups as $gid) { // If this forum has custom or inherited permissions for the currently looped group. if(!empty($fpermcache[$fid][$gid])) { $level_permissions = $fpermcache[$fid][$gid]; } // Or, use the group permission instead, if available. Some forum permissions not existing here will be added back later. else if(!empty($groupscache[$gid]))
|
{ $level_permissions = $groupscache[$gid];
|
{ $level_permissions = $groupscache[$gid];
|
| } // No permission is available for the currently looped group, probably we have bad data here. else { continue;
|
}
foreach($level_permissions as $permission => $access)
| }
foreach($level_permissions as $permission => $access)
|
Zeile 1420 | Zeile 1737 |
---|
{ $current_permissions[$permission] = $access; }
|
{ $current_permissions[$permission] = $access; }
|
}
| }
|
if($level_permissions["canview"] && empty($level_permissions["canonlyviewownthreads"])) { $only_view_own_threads = 0;
|
if($level_permissions["canview"] && empty($level_permissions["canonlyviewownthreads"])) { $only_view_own_threads = 0;
|
| }
if($level_permissions["canpostreplys"] && empty($level_permissions["canonlyreplyownthreads"])) { $only_reply_own_threads = 0;
|
}
|
}
|
| }
if(count($current_permissions) == 0) { $current_permissions = $groupperms;
|
} }
// Figure out if we can view more than our own threads
|
} }
// Figure out if we can view more than our own threads
|
if($only_view_own_threads == 0)
| if($only_view_own_threads == 0 || !isset($current_permissions["canonlyviewownthreads"]))
|
{ $current_permissions["canonlyviewownthreads"] = 0;
|
{ $current_permissions["canonlyviewownthreads"] = 0;
|
}
if(count($current_permissions) == 0)
| }
// Figure out if we can reply more than our own threads if($only_reply_own_threads == 0 || !isset($current_permissions["canonlyreplyownthreads"])) { $current_permissions["canonlyreplyownthreads"] = 0; }
return $current_permissions; }
/** * Check whether password for given forum was validated for the current user * * @param array $forum The forum data * @param bool $ignore_empty Whether to treat forum password configured as an empty string as validated * @param bool $check_parents Whether to check parent forums using `parentlist` * @return bool */ function forum_password_validated($forum, $ignore_empty=false, $check_parents=false) { global $mybb, $forum_cache;
if($check_parents && isset($forum['parentlist']))
|
{
|
{
|
$current_permissions = $groupperms;
| if(!is_array($forum_cache)) { $forum_cache = cache_forums(); if(!$forum_cache) { return false; } }
$parents = explode(',', $forum['parentlist']); rsort($parents);
foreach($parents as $parent_id) { if($parent_id != $forum['fid'] && !forum_password_validated($forum_cache[$parent_id], true)) { return false; } }
|
}
|
}
|
return $current_permissions;
| return ($ignore_empty && $forum['password'] === '') || ( isset($mybb->cookies['forumpass'][$forum['fid']]) && my_hash_equals( md5($mybb->user['uid'].$forum['password']), $mybb->cookies['forumpass'][$forum['fid']] ) );
|
}
/** * Check the password given on a certain forum for validity *
|
}
/** * Check the password given on a certain forum for validity *
|
* @param int The forum ID * @param boolean The Parent ID
| * @param int $fid The forum ID * @param int $pid The Parent ID * @param bool $return * @return bool
|
*/
|
*/
|
function check_forum_password($fid, $pid=0)
| function check_forum_password($fid, $pid=0, $return=false)
|
{ global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang, $forum_cache;
| { global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang, $forum_cache;
|
Zeile 1476 | Zeile 1851 |
---|
if($parent_id == $fid || $parent_id == $pid) { continue;
|
if($parent_id == $fid || $parent_id == $pid) { continue;
|
}
| }
|
|
|
if($forum_cache[$parent_id]['password'] != "")
| if($forum_cache[$parent_id]['password'] !== "")
|
{ check_forum_password($parent_id, $fid); } } }
|
{ check_forum_password($parent_id, $fid); } } }
|
if(!empty($forum_cache[$fid]['password']))
| if($forum_cache[$fid]['password'] !== '')
|
{
|
{
|
$password = $forum_cache[$fid]['password'];
| |
if(isset($mybb->input['pwverify']) && $pid == 0) {
|
if(isset($mybb->input['pwverify']) && $pid == 0) {
|
if($password == $mybb->get_input('pwverify'))
| if(my_hash_equals($forum_cache[$fid]['password'], $mybb->get_input('pwverify')))
|
{ my_setcookie("forumpass[$fid]", md5($mybb->user['uid'].$mybb->get_input('pwverify')), null, true); $showform = false;
| { my_setcookie("forumpass[$fid]", md5($mybb->user['uid'].$mybb->get_input('pwverify')), null, true); $showform = false;
|
Zeile 1499 | Zeile 1873 |
---|
{ eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";"); $showform = true;
|
{ eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";"); $showform = true;
|
} } else { if(!$mybb->cookies['forumpass'][$fid] || ($mybb->cookies['forumpass'][$fid] && md5($mybb->user['uid'].$password) != $mybb->cookies['forumpass'][$fid])) { $showform = true; }
| } } else { if(!forum_password_validated($forum_cache[$fid])) { $showform = true; }
|
else { $showform = false;
| else { $showform = false;
|
Zeile 1516 | Zeile 1890 |
---|
else { $showform = false;
|
else { $showform = false;
|
| }
if($return) { return $showform;
|
}
if($showform)
|
}
if($showform)
|
{
| {
|
if($pid) { header("Location: ".$mybb->settings['bburl']."/".get_forum_link($fid));
| if($pid) { header("Location: ".$mybb->settings['bburl']."/".get_forum_link($fid));
|
Zeile 1537 | Zeile 1916 |
---|
/** * Return the permissions for a moderator in a specific forum *
|
/** * 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)
| * @param int $fid The forum ID * @param int $uid The user ID to fetch permissions for (0 assumes current logged in user) * @param string $parentslist The parent list for the forum (if blank, will be fetched)
|
* @return array Array of moderator permissions for the specific forum */
|
* @return array Array of moderator permissions for the specific forum */
|
function get_moderator_permissions($fid, $uid="0", $parentslist="")
| function get_moderator_permissions($fid, $uid=0, $parentslist="")
|
{ global $mybb, $cache, $db; static $modpermscache;
| { global $mybb, $cache, $db; static $modpermscache;
|
Zeile 1560 | Zeile 1939 |
---|
if(isset($modpermscache[$fid][$uid])) { return $modpermscache[$fid][$uid];
|
if(isset($modpermscache[$fid][$uid])) { return $modpermscache[$fid][$uid];
|
}
| }
|
if(!$parentslist) { $parentslist = explode(',', get_parent_list($fid)); }
|
if(!$parentslist) { $parentslist = explode(',', get_parent_list($fid)); }
|
|
|
// Get user groups $perms = array(); $user = get_user($uid);
|
// Get user groups $perms = array(); $user = get_user($uid);
|
|
|
$groups = array($user['usergroup']);
if(!empty($user['additionalgroups']))
|
$groups = array($user['usergroup']);
if(!empty($user['additionalgroups']))
|
{
| {
|
$extra_groups = explode(",", $user['additionalgroups']);
|
$extra_groups = explode(",", $user['additionalgroups']);
|
|
|
foreach($extra_groups as $extra_group) { $groups[] = $extra_group;
| foreach($extra_groups as $extra_group) { $groups[] = $extra_group;
|
Zeile 1587 | Zeile 1966 |
---|
foreach($mod_cache as $forumid => $forum) {
|
foreach($mod_cache as $forumid => $forum) {
|
if(!is_array($forum) || !in_array($forumid, $parentslist)) {
| if(empty($forum) || !is_array($forum) || !in_array($forumid, $parentslist)) {
|
// No perms or we're not after this forum continue; }
// User settings override usergroup settings
|
// No perms or we're not after this forum continue; }
// User settings override usergroup settings
|
if(is_array($forum['users'][$uid]))
| if(!empty($forum['users'][$uid]))
|
{ $perm = $forum['users'][$uid]; foreach($perm as $action => $value)
| { $perm = $forum['users'][$uid]; foreach($perm as $action => $value)
|
Zeile 1602 | Zeile 1981 |
---|
if(strpos($action, "can") === false) { continue;
|
if(strpos($action, "can") === false) { continue;
|
}
| }
|
|
|
| if(!isset($perms[$action])) { $perms[$action] = $value; }
|
// Figure out the user permissions
|
// Figure out the user permissions
|
if($value == 0) {
| else if($value == 0) {
|
// The user doesn't have permission to set this action $perms[$action] = 0;
|
// The user doesn't have permission to set this action $perms[$action] = 0;
|
} else { $perms[$action] = max($perm[$action], $perms[$action]); } } }
| } else { $perms[$action] = max($perm[$action], $perms[$action]); } } }
|
foreach($groups as $group) {
|
foreach($groups as $group) {
|
if(!is_array($forum['usergroups'][$group])) {
| if(empty($forum['usergroups'][$group]) || !is_array($forum['usergroups'][$group])) {
|
// There are no permissions set for this group continue; }
| // There are no permissions set for this group continue; }
|
Zeile 1629 | Zeile 2012 |
---|
foreach($perm as $action => $value) { if(strpos($action, "can") === false)
|
foreach($perm as $action => $value) { if(strpos($action, "can") === false)
|
{
| {
|
continue; }
|
continue; }
|
$perms[$action] = max($perm[$action], $perms[$action]);
| if(!isset($perms[$action])) { $perms[$action] = $value; } else { $perms[$action] = max($perm[$action], $perms[$action]); }
|
} } }
|
} } }
|
|
|
$modpermscache[$fid][$uid] = $perms;
return $perms;
|
$modpermscache[$fid][$uid] = $perms;
return $perms;
|
}
/**
| }
/**
|
* Checks if a moderator has permissions to perform an action in a specific forum *
|
* 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)
| * @param int $fid The forum ID (0 assumes global) * @param string $action The action tyring to be performed. (blank assumes any action at all) * @param int $uid The user ID (0 assumes current user)
|
* @return bool Returns true if the user has permission, false if they do not
|
* @return bool Returns true if the user has permission, false if they do not
|
*/ function is_moderator($fid="0", $action="", $uid="0") { global $mybb, $cache;
if($uid == 0) { $uid = $mybb->user['uid']; }
if($uid == 0)
| */ function is_moderator($fid=0, $action="", $uid=0) { global $mybb, $cache, $plugins;
if($uid == 0) { $uid = $mybb->user['uid']; }
if($uid == 0)
|
{ return false; }
|
{ return false; }
|
$user_perms = user_permissions($uid); if($user_perms['issupermod'] == 1)
| $user_perms = user_permissions($uid);
$hook_args = array( 'fid' => $fid, 'action' => $action, 'uid' => $uid, );
$plugins->run_hooks("is_moderator", $hook_args); if(isset($hook_args['is_moderator'])) { return (boolean) $hook_args['is_moderator']; }
if(!empty($user_perms['issupermod']) && $user_perms['issupermod'] == 1)
|
{ if($fid) { $forumpermissions = forum_permissions($fid);
|
{ if($fid) { $forumpermissions = forum_permissions($fid);
|
if($forumpermissions['canview'] && $forumpermissions['canviewthreads'] && !$forumpermissions['canonlyviewownthreads']) { return true; }
| if(!empty($forumpermissions['canview']) && !empty($forumpermissions['canviewthreads']) && empty($forumpermissions['canonlyviewownthreads'])) { return true; }
|
return false; } return true;
| return false; } return true;
|
Zeile 1687 | Zeile 2091 |
---|
if(!empty($modcache)) { foreach($modcache as $modusers)
|
if(!empty($modcache)) { foreach($modcache as $modusers)
|
{ if(isset($modusers['users'][$uid]) && $modusers['users'][$uid]['mid']) {
| { if(isset($modusers['users'][$uid]) && $modusers['users'][$uid]['mid'] && (!$action || !empty($modusers['users'][$uid][$action]))) {
|
return true; }
|
return true; }
|
elseif(isset($user_perms['gid']) && isset($modusers['usergroups'][$user_perms['gid']]))
| $groups = explode(',', $user_perms['all_usergroups']);
foreach($groups as $group)
|
{
|
{
|
// Moderating usergroup return true;
| if(trim($group) != '' && isset($modusers['usergroups'][$group]) && (!$action || !empty($modusers['usergroups'][$group][$action]))) { return true; }
|
} } }
| } } }
|
Zeile 1716 | Zeile 2125 |
---|
return true; } else
|
return true; } else
|
{
| {
|
return false; } } } }
|
return false; } } } }
|
| }
/** * Get an array of fids that the forum moderator has access to. * Do not use for administraotrs or global moderators as they moderate any forum and the function will return false. * * @param int $uid The user ID (0 assumes current user) * @return array|bool an array of the fids the user has moderator access to or bool if called incorrectly. */ function get_moderated_fids($uid=0) { global $mybb, $cache;
if($uid == 0) { $uid = $mybb->user['uid']; }
if($uid == 0) { return array(); }
$user_perms = user_permissions($uid);
if($user_perms['issupermod'] == 1) { return false; }
$fids = array();
$modcache = $cache->read('moderators'); if(!empty($modcache)) { $groups = explode(',', $user_perms['all_usergroups']);
foreach($modcache as $fid => $forum) { if(isset($forum['users'][$uid]) && $forum['users'][$uid]['mid']) { $fids[] = $fid; continue; }
foreach($groups as $group) { if(trim($group) != '' && isset($forum['usergroups'][$group])) { $fids[] = $fid; } } } }
return $fids;
|
}
/** * Generate a list of the posticons. * * @return string The template of posticons.
|
}
/** * Generate a list of the posticons. * * @return string The template of posticons.
|
*/
| */
|
function get_post_icons() { global $mybb, $cache, $icon, $theme, $templates, $lang;
| function get_post_icons() { global $mybb, $cache, $icon, $theme, $templates, $lang;
|
Zeile 1741 | Zeile 2206 |
---|
$iconlist = ''; $no_icons_checked = " checked=\"checked\""; // read post icons from cache, and sort them accordingly
|
$iconlist = ''; $no_icons_checked = " checked=\"checked\""; // read post icons from cache, and sort them accordingly
|
$posticons_cache = $cache->read("posticons");
| $posticons_cache = (array)$cache->read("posticons");
|
$posticons = array(); foreach($posticons_cache as $posticon) {
| $posticons = array(); foreach($posticons_cache as $posticon) {
|
Zeile 1752 | Zeile 2217 |
---|
foreach($posticons as $dbicon) { $dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);
|
foreach($posticons as $dbicon) { $dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);
|
$dbicon['path'] = htmlspecialchars_uni($dbicon['path']);
| $dbicon['path'] = htmlspecialchars_uni($mybb->get_asset_url($dbicon['path']));
|
$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);
if($icon == $dbicon['iid'])
|
$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);
if($icon == $dbicon['iid'])
|
{
| {
|
$checked = " checked=\"checked\""; $no_icons_checked = '';
|
$checked = " checked=\"checked\""; $no_icons_checked = '';
|
}
| }
|
else { $checked = ''; }
eval("\$iconlist .= \"".$templates->get("posticons_icon")."\";");
|
else { $checked = ''; }
eval("\$iconlist .= \"".$templates->get("posticons_icon")."\";");
|
}
| }
|
|
|
eval("\$posticons = \"".$templates->get("posticons")."\";");
| if(!empty($iconlist)) { eval("\$posticons = \"".$templates->get("posticons")."\";"); } else { $posticons = ''; }
|
return $posticons; }
| return $posticons; }
|
Zeile 1776 | Zeile 2248 |
---|
/** * MyBB setcookie() wrapper. *
|
/** * 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)
| * @param string $name The cookie identifier. * @param string $value The cookie value. * @param int|string $expires The timestamp of the expiry date. * @param boolean $httponly True if setting a HttpOnly cookie (supported by the majority of web browsers) * @param string $samesite The samesite attribute to prevent CSRF.
|
*/
|
*/
|
function my_setcookie($name, $value="", $expires="", $httponly=false)
| function my_setcookie($name, $value="", $expires="", $httponly=false, $samesite="")
|
{ global $mybb;
| { global $mybb;
|
Zeile 1813 | Zeile 2286 |
---|
if($expires > 0) { $cookie .= "; expires=".@gmdate('D, d-M-Y H:i:s \\G\\M\\T', $expires);
|
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['cookiepath'])) { $cookie .= "; path={$mybb->settings['cookiepath']}";
|
}
| }
|
if(!empty($mybb->settings['cookiedomain'])) {
| if(!empty($mybb->settings['cookiedomain'])) {
|
Zeile 1826 | Zeile 2299 |
---|
}
if($httponly == true)
|
}
if($httponly == true)
|
{
| {
|
$cookie .= "; HttpOnly"; }
|
$cookie .= "; HttpOnly"; }
|
$mybb->cookies[$name] = $value;
| if($samesite != "" && $mybb->settings['cookiesamesiteflag']) { $samesite = strtolower($samesite);
if($samesite == "lax" || $samesite == "strict") { $cookie .= "; SameSite=".$samesite; } }
if($mybb->settings['cookiesecureflag']) { $cookie .= "; Secure"; }
$mybb->cookies[$name] = $value;
|
header($cookie, false); }
/** * Unset a cookie set by MyBB.
|
header($cookie, false); }
/** * Unset a cookie set by MyBB.
|
* * @param string The cookie identifier. */
| * * @param string $name The cookie identifier. */
|
function my_unsetcookie($name) { global $mybb;
|
function my_unsetcookie($name) { global $mybb;
|
|
|
$expires = -3600; my_setcookie($name, "", $expires);
|
$expires = -3600; my_setcookie($name, "", $expires);
|
|
|
unset($mybb->cookies[$name]); }
/** * Get the contents from a serialised cookie array.
|
unset($mybb->cookies[$name]); }
/** * Get the contents from a serialised cookie array.
|
* * @param string The cookie identifier. * @param int The cookie content id.
| * * @param string $name The cookie identifier. * @param int $id 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)
| * @return array|boolean The cookie id's content array or false when non-existent. */ function my_get_array_cookie($name, $id)
|
Zeile 1866 | Zeile 2354 |
---|
return false; }
|
return false; }
|
$cookie = my_unserialize($mybb->cookies['mybb'][$name]);
| $cookie = my_unserialize($mybb->cookies['mybb'][$name], false);
|
if(is_array($cookie) && isset($cookie[$id])) {
| if(is_array($cookie) && isset($cookie[$id])) {
|
Zeile 1880 | Zeile 2368 |
---|
/** * Set a serialised cookie array.
|
/** * 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. * @param int The timestamp of the expiry date. */
| * * @param string $name The cookie identifier. * @param int $id The cookie content id. * @param string $value The value to set the cookie to. * @param int|string $expires The timestamp of the expiry date. */
|
function my_set_array_cookie($name, $id, $value, $expires="") { global $mybb;
|
function my_set_array_cookie($name, $id, $value, $expires="") { global $mybb;
|
$cookie = $mybb->cookies['mybb']; if(isset($cookie[$name]))
| if(isset($mybb->cookies['mybb'][$name]))
|
{
|
{
|
$newcookie = my_unserialize($cookie[$name]);
| $newcookie = my_unserialize($mybb->cookies['mybb'][$name], false);
|
} else {
| } else {
|
Zeile 1901 | Zeile 2388 |
---|
}
$newcookie[$id] = $value;
|
}
$newcookie[$id] = $value;
|
$newcookie = serialize($newcookie);
| $newcookie = my_serialize($newcookie);
|
my_setcookie("mybb[$name]", addslashes($newcookie), $expires);
|
my_setcookie("mybb[$name]", addslashes($newcookie), $expires);
|
| if(isset($mybb->cookies['mybb']) && !is_array($mybb->cookies['mybb'])) { $mybb->cookies['mybb'] = array(); }
|
// Make sure our current viarables are up-to-date as well $mybb->cookies['mybb'][$name] = $newcookie;
|
// Make sure our current viarables are up-to-date as well $mybb->cookies['mybb'][$name] = $newcookie;
|
| }
/* * Arbitrary limits for _safe_unserialize() */ define('MAX_SERIALIZED_INPUT_LENGTH', 10240); define('MAX_SERIALIZED_ARRAY_LENGTH', 256); define('MAX_SERIALIZED_ARRAY_DEPTH', 5);
/** * Credits go to https://github.com/piwik * Safe unserialize() replacement * - accepts a strict subset of PHP's native my_serialized representation * - does not unserialize objects * * @param string $str * @param bool $unlimited Whether to apply limits defined in MAX_SERIALIZED_* constants * @return mixed * @throw Exception if $str is malformed or contains unsupported types (e.g., resources, objects) */ function _safe_unserialize($str, $unlimited = true) { if(!$unlimited && strlen($str) > MAX_SERIALIZED_INPUT_LENGTH) { // input exceeds MAX_SERIALIZED_INPUT_LENGTH return false; }
if(empty($str) || !is_string($str)) { return false; }
$stack = $list = $expected = array();
/* * states: * 0 - initial state, expecting a single value or array * 1 - terminal state * 2 - in array, expecting end of array or a key * 3 - in array, expecting value or another array */ $state = 0; while($state != 1) { $type = isset($str[0]) ? $str[0] : '';
if($type == '}') { $str = substr($str, 1); } else if($type == 'N' && $str[1] == ';') { $value = null; $str = substr($str, 2); } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) { $value = $matches[1] == '1' ? true : false; $str = substr($str, 4); } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) { $value = (int)$matches[1]; $str = $matches[2]; } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) { $value = (float)$matches[1]; $str = $matches[3]; } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') { $value = substr($matches[2], 0, (int)$matches[1]); $str = substr($matches[2], (int)$matches[1] + 2); } else if( $type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches) && ($unlimited || $matches[1] < MAX_SERIALIZED_ARRAY_LENGTH) ) { $expectedLength = (int)$matches[1]; $str = $matches[2]; } else { // object or unknown/malformed type return false; }
switch($state) { case 3: // in array, expecting value or another array if($type == 'a') { if(!$unlimited && count($stack) >= MAX_SERIALIZED_ARRAY_DEPTH) { // array nesting exceeds MAX_SERIALIZED_ARRAY_DEPTH return false; }
$stack[] = &$list; $list[$key] = array(); $list = &$list[$key]; $expected[] = $expectedLength; $state = 2; break; } if($type != '}') { $list[$key] = $value; $state = 2; break; }
// missing array value return false;
case 2: // in array, expecting end of array or a key if($type == '}') { if(count($list) < end($expected)) { // array size less than expected return false; }
unset($list); $list = &$stack[count($stack)-1]; array_pop($stack);
// go to terminal state if we're at the end of the root array array_pop($expected); if(count($expected) == 0) { $state = 1; } break; } if($type == 'i' || $type == 's') { if(!$unlimited && count($list) >= MAX_SERIALIZED_ARRAY_LENGTH) { // array size exceeds MAX_SERIALIZED_ARRAY_LENGTH return false; } if(count($list) >= end($expected)) { // array size exceeds expected length return false; }
$key = $value; $state = 3; break; }
// illegal array index type return false;
case 0: // expecting array or value if($type == 'a') { if(!$unlimited && count($stack) >= MAX_SERIALIZED_ARRAY_DEPTH) { // array nesting exceeds MAX_SERIALIZED_ARRAY_DEPTH return false; }
$data = array(); $list = &$data; $expected[] = $expectedLength; $state = 2; break; } if($type != '}') { $data = $value; $state = 1; break; }
// not in array return false; } }
if(!empty($str)) { // trailing data in input return false; } return $data; }
/** * Credits go to https://github.com/piwik * Wrapper for _safe_unserialize() that handles exceptions and multibyte encoding issue * * @param string $str * @param bool $unlimited * @return mixed */ function my_unserialize($str, $unlimited = true) { // Ensure we use the byte count for strings even when strlen() is overloaded by mb_strlen() if(function_exists('mb_internal_encoding') && (((int)ini_get('mbstring.func_overload')) & 2)) { $mbIntEnc = mb_internal_encoding(); mb_internal_encoding('ASCII'); }
$out = _safe_unserialize($str, $unlimited);
if(isset($mbIntEnc)) { mb_internal_encoding($mbIntEnc); }
return $out; }
/** * Unserializes data using PHP's `unserialize()`, and its safety options if possible. * This function should only be used for values from trusted sources. * * @param string $str * @return mixed */ function native_unserialize($str) { if(version_compare(PHP_VERSION, '7.0.0', '>=')) { return unserialize($str, array('allowed_classes' => false)); } else { return unserialize($str); } }
/** * Credits go to https://github.com/piwik * Safe serialize() replacement * - output a strict subset of PHP's native serialized representation * - does not my_serialize objects * * @param mixed $value * @return string * @throw Exception if $value is malformed or contains unsupported types (e.g., resources, objects) */ function _safe_serialize( $value ) { if(is_null($value)) { return 'N;'; }
if(is_bool($value)) { return 'b:'.(int)$value.';'; }
if(is_int($value)) { return 'i:'.$value.';'; }
if(is_float($value)) { return 'd:'.str_replace(',', '.', $value).';'; }
if(is_string($value)) { return 's:'.strlen($value).':"'.$value.'";'; }
if(is_array($value)) { $out = ''; foreach($value as $k => $v) { $out .= _safe_serialize($k) . _safe_serialize($v); }
return 'a:'.count($value).':{'.$out.'}'; }
// safe_serialize cannot my_serialize resources or objects return false;
|
}
/**
|
}
/**
|
* Verifies that data passed is an array
| * Credits go to https://github.com/piwik * Wrapper for _safe_serialize() that handles exceptions and multibyte encoding issue
|
*
|
*
|
* @param array Data to unserialize * @return array Unserialized data array */ function my_unserialize($data)
| * @param mixed $value * @return string */ function my_serialize($value)
|
{
|
{
|
$array = unserialize($data);
| // ensure we use the byte count for strings even when strlen() is overloaded by mb_strlen() if(function_exists('mb_internal_encoding') && (((int)ini_get('mbstring.func_overload')) & 2)) { $mbIntEnc = mb_internal_encoding(); mb_internal_encoding('ASCII'); }
|
|
|
if(!is_array($array))
| $out = _safe_serialize($value); if(isset($mbIntEnc))
|
{
|
{
|
$array = array();
| mb_internal_encoding($mbIntEnc);
|
}
|
}
|
return $array;
| return $out;
|
}
/**
| }
/**
|
Zeile 1944 | Zeile 2734 |
---|
{ // sys_getloadavg() will return an array with [0] being load within the last minute. $serverload = sys_getloadavg();
|
{ // sys_getloadavg() will return an array with [0] being load within the last minute. $serverload = sys_getloadavg();
|
| if(!is_array($serverload)) { return $lang->unknown; }
|
$serverload[0] = round($serverload[0], 4); } else if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))
| $serverload[0] = round($serverload[0], 4); } else if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))
|
Zeile 1960 | Zeile 2756 |
---|
// Suhosin likes to throw a warning if exec is disabled then die - weird if($func_blacklist = @ini_get('suhosin.executor.func.blacklist'))
|
// Suhosin likes to throw a warning if exec is disabled then die - weird if($func_blacklist = @ini_get('suhosin.executor.func.blacklist'))
|
{
| {
|
if(strpos(",".$func_blacklist.",", 'exec') !== false) { return $lang->unknown;
| if(strpos(",".$func_blacklist.",", 'exec') !== false) { return $lang->unknown;
|
Zeile 1982 | Zeile 2778 |
---|
{ return $lang->unknown; }
|
{ return $lang->unknown; }
|
} } else
| } } else
|
{ return $lang->unknown; }
| { return $lang->unknown; }
|
Zeile 2015 | Zeile 2811 |
---|
/** * Updates the forum statistics with specific values (or addition/subtraction of the previous value) *
|
/** * Updates the forum statistics with specific values (or addition/subtraction of the previous value) *
|
* @param array Array of items being updated (numthreads,numposts,numusers,numunapprovedthreads,numunapprovedposts,numdeletedposts,numdeletedthreads) * @param boolean Force stats update?
| * @param array $changes Array of items being updated (numthreads,numposts,numusers,numunapprovedthreads,numunapprovedposts,numdeletedposts,numdeletedthreads) * @param boolean $force Force stats update?
|
*/ function update_stats($changes=array(), $force=false) {
| */ function update_stats($changes=array(), $force=false) {
|
Zeile 2061 | Zeile 2857 |
---|
$new_stats = array(); $counters = array('numthreads', 'numunapprovedthreads', 'numposts', 'numunapprovedposts', 'numusers', 'numdeletedposts', 'numdeletedthreads');
|
$new_stats = array(); $counters = array('numthreads', 'numunapprovedthreads', 'numposts', 'numunapprovedposts', 'numusers', 'numdeletedposts', 'numdeletedthreads');
|
foreach($counters as $counter) { if(array_key_exists($counter, $changes)) {
| foreach($counters as $counter) { if(array_key_exists($counter, $changes)) { if(substr($changes[$counter], 0, 2) == "+-") { $changes[$counter] = substr($changes[$counter], 1); }
|
// Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-") {
| // Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-") {
|
Zeile 2084 | Zeile 2884 |
---|
{ $new_stats[$counter] = 0; }
|
{ $new_stats[$counter] = 0; }
|
} }
| } }
|
else { $new_stats[$counter] = $changes[$counter];
| else { $new_stats[$counter] = $changes[$counter];
|
Zeile 2093 | Zeile 2893 |
---|
if($new_stats[$counter] < 0) { $new_stats[$counter] = 0;
|
if($new_stats[$counter] < 0) { $new_stats[$counter] = 0;
|
} } } }
| } } } }
|
if(!$force)
|
if(!$force)
|
{
| {
|
$stats_changes = array_merge($stats, $new_stats); // Overwrite changed values return; }
| $stats_changes = array_merge($stats, $new_stats); // Overwrite changed values return; }
|
Zeile 2110 | Zeile 2910 |
---|
$query = $db->simple_select("users", "uid, username", "", array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit' => 1)); $lastmember = $db->fetch_array($query); $new_stats['lastuid'] = $lastmember['uid'];
|
$query = $db->simple_select("users", "uid, username", "", array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit' => 1)); $lastmember = $db->fetch_array($query); $new_stats['lastuid'] = $lastmember['uid'];
|
$new_stats['lastusername'] = $lastmember['username']; }
| $new_stats['lastusername'] = $lastmember['username'] = htmlspecialchars_uni($lastmember['username']); }
|
if(!empty($new_stats)) { if(is_array($stats))
| if(!empty($new_stats)) { if(is_array($stats))
|
Zeile 2124 | Zeile 2924 |
---|
$stats = $new_stats; } }
|
$stats = $new_stats; } }
|
|
|
// Update stats row for today in the database $todays_stats = array( "dateline" => mktime(0, 0, 0, date("m"), date("j"), date("Y")),
|
// Update stats row for today in the database $todays_stats = array( "dateline" => mktime(0, 0, 0, date("m"), date("j"), date("Y")),
|
"numusers" => $stats['numusers'], "numthreads" => $stats['numthreads'], "numposts" => $stats['numposts']
| "numusers" => (int)$stats['numusers'], "numthreads" => (int)$stats['numthreads'], "numposts" => (int)$stats['numposts']
|
); $db->replace_query("stats", $todays_stats, "dateline");
| ); $db->replace_query("stats", $todays_stats, "dateline");
|
Zeile 2141 | Zeile 2941 |
---|
/** * Updates the forum counters with a specific value (or addition/subtraction of the previous value) *
|
/** * 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, deletedposts, deletedthreads) and their value (ex, 1, +1, -1)
| * @param int $fid The forum ID * @param array $changes Array of items being updated (threads, posts, unapprovedthreads, unapprovedposts, deletedposts, deletedthreads) and their value (ex, 1, +1, -1)
|
*/ function update_forum_counters($fid, $changes=array()) {
| */ function update_forum_counters($fid, $changes=array()) {
|
Zeile 2155 | Zeile 2955 |
---|
// Fetch above counters for this forum $query = $db->simple_select("forums", implode(",", $counters), "fid='{$fid}'"); $forum = $db->fetch_array($query);
|
// Fetch above counters for this forum $query = $db->simple_select("forums", implode(",", $counters), "fid='{$fid}'"); $forum = $db->fetch_array($query);
|
|
|
foreach($counters as $counter) { if(array_key_exists($counter, $changes)) {
|
foreach($counters as $counter) { if(array_key_exists($counter, $changes)) {
|
| if(substr($changes[$counter], 0, 2) == "+-") { $changes[$counter] = substr($changes[$counter], 1); }
|
// Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
|
// Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
|
{
| {
|
if((int)$changes[$counter] != 0) { $update_query[$counter] = $forum[$counter] + $changes[$counter];
|
if((int)$changes[$counter] != 0) { $update_query[$counter] = $forum[$counter] + $changes[$counter];
|
} } else { $update_query[$counter] = $changes[$counter]; }
// Less than 0? That's bad if(isset($update_query[$counter]) && $update_query[$counter] < 0) { $update_query[$counter] = 0; }
| } } else { $update_query[$counter] = $changes[$counter]; }
// Less than 0? That's bad if(isset($update_query[$counter]) && $update_query[$counter] < 0) { $update_query[$counter] = 0; }
|
} }
| } }
|
Zeile 2276 | Zeile 3080 |
---|
/** * Update the last post information for a specific forum *
|
/** * Update the last post information for a specific forum *
|
* @param int The forum ID
| * @param int $fid The forum ID
|
*/ function update_forum_lastpost($fid) {
| */ function update_forum_lastpost($fid) {
|
Zeile 2290 | Zeile 3094 |
---|
ORDER BY lastpost DESC LIMIT 0, 1 ");
|
ORDER BY lastpost DESC LIMIT 0, 1 ");
|
$lastpost = $db->fetch_array($query);
| |
|
|
$updated_forum = array( "lastpost" => (int)$lastpost['lastpost'], "lastposter" => $db->escape_string($lastpost['lastposter']), "lastposteruid" => (int)$lastpost['lastposteruid'], "lastposttid" => (int)$lastpost['tid'], "lastpostsubject" => $db->escape_string($lastpost['subject']) );
| if($db->num_rows($query) > 0) { $lastpost = $db->fetch_array($query);
$updated_forum = array( "lastpost" => (int)$lastpost['lastpost'], "lastposter" => $db->escape_string($lastpost['lastposter']), "lastposteruid" => (int)$lastpost['lastposteruid'], "lastposttid" => (int)$lastpost['tid'], "lastpostsubject" => $db->escape_string($lastpost['subject']), ); } else { $updated_forum = array( "lastpost" => 0, "lastposter" => '', "lastposteruid" => 0, "lastposttid" => 0, "lastpostsubject" => '', ); }
|
$db->update_query("forums", $updated_forum, "fid='{$fid}'"); }
| $db->update_query("forums", $updated_forum, "fid='{$fid}'"); }
|
Zeile 2306 | Zeile 3123 |
---|
/** * Updates the thread counters with a specific value (or addition/subtraction of the previous value) *
|
/** * 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, deletedposts, attachmentcount) and their value (ex, 1, +1, -1)
| * @param int $tid The thread ID * @param array $changes Array of items being updated (replies, unapprovedposts, deletedposts, attachmentcount) and their value (ex, 1, +1, -1)
|
*/ function update_thread_counters($tid, $changes=array()) { global $db;
$update_query = array();
|
*/ function update_thread_counters($tid, $changes=array()) { global $db;
$update_query = array();
|
$tid = (int)$tid;
| $tid = (int)$tid;
|
$counters = array('replies', 'unapprovedposts', 'attachmentcount', 'deletedposts', 'attachmentcount');
// Fetch above counters for this thread
| $counters = array('replies', 'unapprovedposts', 'attachmentcount', 'deletedposts', 'attachmentcount');
// Fetch above counters for this thread
|
Zeile 2326 | Zeile 3143 |
---|
{ if(array_key_exists($counter, $changes)) {
|
{ if(array_key_exists($counter, $changes)) {
|
| if(substr($changes[$counter], 0, 2) == "+-") { $changes[$counter] = substr($changes[$counter], 1); }
|
// Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-") {
| // Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-") {
|
Zeile 2333 | Zeile 3154 |
---|
{ $update_query[$counter] = $thread[$counter] + $changes[$counter]; }
|
{ $update_query[$counter] = $thread[$counter] + $changes[$counter]; }
|
}
| }
|
else { $update_query[$counter] = $changes[$counter];
| else { $update_query[$counter] = $changes[$counter];
|
Zeile 2351 | Zeile 3172 |
---|
// Only update if we're actually doing something if(count($update_query) > 0)
|
// Only update if we're actually doing something if(count($update_query) > 0)
|
{
| {
|
$db->update_query("threads", $update_query, "tid='{$tid}'"); } }
| $db->update_query("threads", $update_query, "tid='{$tid}'"); } }
|
Zeile 2359 | Zeile 3180 |
---|
/** * Update the first post and lastpost data for a specific thread *
|
/** * Update the first post and lastpost data for a specific thread *
|
* @param int The thread ID
| * @param int $tid The thread ID
|
*/ function update_thread_data($tid) {
| */ function update_thread_data($tid) {
|
Zeile 2370 | Zeile 3191 |
---|
// If this is a moved thread marker, don't update it - we need it to stay as it is if(strpos($thread['closed'], 'moved|') !== false) {
|
// If this is a moved thread marker, don't update it - we need it to stay as it is if(strpos($thread['closed'], 'moved|') !== false) {
|
return false;
| return;
|
}
$query = $db->query("
| }
$query = $db->query("
|
Zeile 2378 | Zeile 3199 |
---|
FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) WHERE p.tid='$tid' AND p.visible='1'
|
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
| ORDER BY p.dateline DESC, p.pid DESC
|
LIMIT 1" ); $lastpost = $db->fetch_array($query);
| LIMIT 1" ); $lastpost = $db->fetch_array($query);
|
Zeile 2390 | Zeile 3211 |
---|
FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) WHERE p.tid='$tid'
|
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
| ORDER BY p.dateline ASC, p.pid ASC
|
LIMIT 1 "); $firstpost = $db->fetch_array($query);
| LIMIT 1 "); $firstpost = $db->fetch_array($query);
|
Zeile 2432 | Zeile 3253 |
---|
/** * Updates the user counters with a specific value (or addition/subtraction of the previous value) *
|
/** * Updates the user counters with a specific value (or addition/subtraction of the previous value) *
|
* @param int The user ID * @param array Array of items being updated (postnum, threadnum) and their value (ex, 1, +1, -1)
| * @param int $uid The user ID * @param array $changes Array of items being updated (postnum, threadnum) and their value (ex, 1, +1, -1)
|
*/ function update_user_counters($uid, $changes=array()) {
| */ function update_user_counters($uid, $changes=array()) {
|
Zeile 2447 | Zeile 3268 |
---|
// Fetch above counters for this user $query = $db->simple_select("users", implode(",", $counters), "uid='{$uid}'"); $user = $db->fetch_array($query);
|
// Fetch above counters for this user $query = $db->simple_select("users", implode(",", $counters), "uid='{$uid}'"); $user = $db->fetch_array($query);
|
foreach($counters as $counter)
| if($user)
|
{
|
{
|
if(array_key_exists($counter, $changes))
| foreach($counters as $counter)
|
{
|
{
|
// Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
| if(array_key_exists($counter, $changes))
|
{
|
{
|
if((int)$changes[$counter] != 0)
| if(substr($changes[$counter], 0, 2) == "+-")
|
{
|
{
|
$update_query[$counter] = $user[$counter] + $changes[$counter];
| $changes[$counter] = substr($changes[$counter], 1); } // Adding or subtracting from previous value? if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-") { if((int)$changes[$counter] != 0) { $update_query[$counter] = $user[$counter] + $changes[$counter]; } } else { $update_query[$counter] = $changes[$counter]; }
// Less than 0? That's bad if(isset($update_query[$counter]) && $update_query[$counter] < 0) { $update_query[$counter] = 0;
|
}
|
}
|
} else { $update_query[$counter] = $changes[$counter]; }
// Less than 0? That's bad if(isset($update_query[$counter]) && $update_query[$counter] < 0) { $update_query[$counter] = 0;
| |
} } }
$db->free_result($query);
|
} } }
$db->free_result($query);
|
|
|
// Only update if we're actually doing something if(count($update_query) > 0) { $db->update_query("users", $update_query, "uid='{$uid}'");
|
// Only update if we're actually doing something if(count($update_query) > 0) { $db->update_query("users", $update_query, "uid='{$uid}'");
|
} }
| } }
|
/** * Deletes a thread from the database *
|
/** * Deletes a thread from the database *
|
* @param int The thread ID
| * @param int $tid The thread ID * @return bool
|
*/ function delete_thread($tid)
|
*/ function delete_thread($tid)
|
{ global $moderation;
| { global $moderation;
|
if(!is_object($moderation)) {
| if(!is_object($moderation)) {
|
Zeile 2503 | Zeile 3332 |
---|
/** * Deletes a post from the database *
|
/** * Deletes a post from the database *
|
* @param int The thread ID
| * @param int $pid The thread ID * @return bool
|
*/ function delete_post($pid) {
| */ function delete_post($pid) {
|
Zeile 2513 | Zeile 3343 |
---|
{ require_once MYBB_ROOT."inc/class_moderation.php"; $moderation = new Moderation;
|
{ require_once MYBB_ROOT."inc/class_moderation.php"; $moderation = new Moderation;
|
}
| }
|
return $moderation->delete_post($pid); }
|
return $moderation->delete_post($pid); }
|
|
|
/** * Builds a forum jump menu *
|
/** * 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 boolean Ignore the showinjump setting and show all forums (for moderation pages) * @param array Array of permissions * @param string The name of the forum jump
| * @param int $pid The parent forum to start with * @param int $selitem The selected item ID * @param int $addselect If we need to add select boxes to this cal or not * @param string $depth The current depth of forums we're at * @param int $showextras Whether or not to show extra items such as User CP, Forum home * @param boolean $showall Ignore the showinjump setting and show all forums (for moderation pages) * @param mixed $permissions deprecated * @param string $name The name of the forum jump
|
* @return string Forum jump items
|
* @return string Forum jump items
|
*/ function build_forum_jump($pid="0", $selitem="", $addselect="1", $depth="", $showextras="1", $showall=false, $permissions="", $name="fid") { global $forum_cache, $jumpfcache, $permissioncache, $mybb, $selecteddone, $forumjump, $forumjumpbits, $gobutton, $theme, $templates, $lang;
| */ function build_forum_jump($pid=0, $selitem=0, $addselect=1, $depth="", $showextras=1, $showall=false, $permissions="", $name="fid") { global $forum_cache, $jumpfcache, $permissioncache, $mybb, $forumjump, $forumjumpbits, $gobutton, $theme, $templates, $lang;
|
$pid = (int)$pid;
|
$pid = (int)$pid;
|
$jumpsel['default'] = '';
if($permissions) { $permissions = $mybb->usergroup; }
| |
if(!is_array($jumpfcache)) {
| if(!is_array($jumpfcache)) {
|
Zeile 2578 | Zeile 3402 |
---|
if($selitem == $forum['fid']) {
|
if($selitem == $forum['fid']) {
|
$optionselected = "selected=\"selected\""; $selecteddone = 1;
| $optionselected = 'selected="selected"';
|
}
$forum['name'] = htmlspecialchars_uni(strip_tags($forum['name']));
| }
$forum['name'] = htmlspecialchars_uni(strip_tags($forum['name']));
|
Zeile 2598 | Zeile 3421 |
---|
if($addselect) {
|
if($addselect) {
|
if(!$selecteddone) { if(!$selitem) { $selitem = "default"; }
$jumpsel[$selitem] = 'selected="selected"'; }
| |
if($showextras == 0) { $template = "special";
| if($showextras == 0) { $template = "special";
|
Zeile 2618 | Zeile 3431 |
---|
if(strpos(FORUM_URL, '.html') !== false) {
|
if(strpos(FORUM_URL, '.html') !== false) {
|
$forum_link = "'".str_replace('{fid}', "'+this.options[this.selectedIndex].value+'", FORUM_URL)."'";
| $forum_link = "'".str_replace('{fid}', "'+option+'", FORUM_URL)."'";
|
} else {
|
} else {
|
$forum_link = "'".str_replace('{fid}', "'+this.options[this.selectedIndex].value", FORUM_URL);
| $forum_link = "'".str_replace('{fid}', "'+option", FORUM_URL);
|
} }
| } }
|
Zeile 2635 | Zeile 3448 |
---|
/** * Returns the extension of a file. *
|
/** * Returns the extension of a file. *
|
* @param string The filename.
| * @param string $file The filename.
|
* @return string The extension of the file. */ function get_extension($file)
|
* @return string The extension of the file. */ function get_extension($file)
|
{ return my_strtolower(my_substr(strrchr($file, "."), 1)); }
| { return my_strtolower(my_substr(strrchr($file, "."), 1)); }
|
/** * Generates a random string. *
|
/** * Generates a random string. *
|
* @param int The length of the string to generate.
| * @param int $length The length of the string to generate. * @param bool $complex Whether to return complex string. Defaults to false
|
* @return string The random string.
|
* @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 = my_rand(0, count($set)-1); $str .= $set[$ch]; }
return $str; }
| */ function random_str($length=8, $complex=false) { $set = array_merge(range(0, 9), range('A', 'Z'), range('a', 'z')); $str = array();
// Complex strings have always at least 3 characters, even if $length < 3 if($complex == true) { // At least one number $str[] = $set[my_rand(0, 9)];
// At least one big letter $str[] = $set[my_rand(10, 35)];
// At least one small letter $str[] = $set[my_rand(36, 61)];
$length -= 3; }
for($i = 0; $i < $length; ++$i) { $str[] = $set[my_rand(0, 61)]; }
// Make sure they're in random order and convert them to a string shuffle($str);
return implode($str); }
|
/** * Formats a username based on their display group *
|
/** * 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)
| * @param string $username The username * @param int $usergroup The usergroup for the user * @param int $displaygroup The display group for the user
|
* @return string The formatted username
|
* @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)
| */ function format_name($username, $usergroup, $displaygroup=0) { global $groupscache, $cache, $plugins;
static $formattednames = array();
if(!isset($formattednames[$username]))
|
{
|
{
|
$usergroup = $displaygroup; }
$ugroup = $groupscache[$usergroup]; $format = $ugroup['namestyle']; $userin = substr_count($format, "{username}");
| if(!is_array($groupscache)) { $groupscache = $cache->read("usergroups"); }
|
|
|
if($userin == 0) { $format = "{username}"; }
| if($displaygroup != 0) { $usergroup = $displaygroup; }
|
|
|
$format = stripslashes($format);
return str_replace("{username}", $username, $format);
| $format = "{username}";
if(isset($groupscache[$usergroup])) { $ugroup = $groupscache[$usergroup];
if(strpos($ugroup['namestyle'], "{username}") !== false) { $format = $ugroup['namestyle']; } }
$format = stripslashes($format);
$parameters = compact('username', 'usergroup', 'displaygroup', 'format');
$parameters = $plugins->run_hooks('format_name', $parameters);
$format = $parameters['format'];
$formattednames[$username] = str_replace("{username}", $username, $format); }
return $formattednames[$username];
|
}
/** * Formats an avatar to a certain dimension *
|
}
/** * Formats an avatar to a certain dimension *
|
* @param string The avatar file name * @param string Dimensions of the avatar, width x height (e.g. 44|44) * @param string The maximum dimensions of the formatted avatar
| * @param string $avatar The avatar file name * @param string $dimensions Dimensions of the avatar, width x height (e.g. 44|44) * @param string $max_dimensions The maximum dimensions of the formatted avatar
|
* @return array Information for the formatted avatar */ function format_avatar($avatar, $dimensions = '', $max_dimensions = '') {
|
* @return array Information for the formatted avatar */ function format_avatar($avatar, $dimensions = '', $max_dimensions = '') {
|
global $mybb;
| global $mybb, $theme;
|
static $avatars;
if(!isset($avatars)) { $avatars = array();
|
static $avatars;
if(!isset($avatars)) { $avatars = array();
|
| }
if(my_strpos($avatar, '://') !== false && !$mybb->settings['allowremoteavatars']) { // Remote avatar, but remote avatars are disallowed. $avatar = null;
|
}
if(!$avatar) { // Default avatar
|
}
if(!$avatar) { // Default avatar
|
$avatar = $mybb->settings['useravatar'];
| if(defined('IN_ADMINCP')) { $theme['imgdir'] = '../images'; }
$avatar = str_replace('{theme}', $theme['imgdir'], $mybb->settings['useravatar']);
|
$dimensions = $mybb->settings['useravatardims'];
|
$dimensions = $mybb->settings['useravatardims'];
|
}
if(isset($avatars[$avatar])) { return $avatars[$avatar]; }
| }
|
if(!$max_dimensions)
|
if(!$max_dimensions)
|
{
| {
|
$max_dimensions = $mybb->settings['maxavatardims']; }
|
$max_dimensions = $mybb->settings['maxavatardims']; }
|
| // An empty key wouldn't work so we need to add a fall back $key = $dimensions; if(empty($key)) { $key = 'default'; } $key2 = $max_dimensions; if(empty($key2)) { $key2 = 'default'; }
if(isset($avatars[$avatar][$key][$key2])) { return $avatars[$avatar][$key][$key2]; }
$avatar_width_height = '';
|
if($dimensions) {
|
if($dimensions) {
|
$dimensions = explode("|", $dimensions);
| $dimensions = preg_split('/[|x]/', $dimensions);
|
if($dimensions[0] && $dimensions[1]) {
|
if($dimensions[0] && $dimensions[1]) {
|
list($max_width, $max_height) = explode('x', $max_dimensions);
| list($max_width, $max_height) = preg_split('/[|x]/', $max_dimensions);
|
|
|
if($dimensions[0] > $max_width || $dimensions[1] > $max_height)
| if(!empty($max_dimensions) && ($dimensions[0] > $max_width || $dimensions[1] > $max_height))
|
{ require_once MYBB_ROOT."inc/functions_image.php"; $scaled_dimensions = scale_image($dimensions[0], $dimensions[1], $max_width, $max_height);
| { require_once MYBB_ROOT."inc/functions_image.php"; $scaled_dimensions = scale_image($dimensions[0], $dimensions[1], $max_width, $max_height);
|
Zeile 2755 | Zeile 3627 |
---|
} }
|
} }
|
$avatars[$avatar] = array( 'image' => $mybb->get_asset_url($avatar),
| $avatars[$avatar][$key][$key2] = array( 'image' => htmlspecialchars_uni($mybb->get_asset_url($avatar)),
|
'width_height' => $avatar_width_height );
|
'width_height' => $avatar_width_height );
|
return $avatars[$avatar];
| return $avatars[$avatar][$key][$key2];
|
}
/**
|
}
/**
|
* Build the javascript based MyCode inserter
| * Build the javascript based MyCode inserter. * * @param string $bind The ID of the textarea to bind to. Defaults to "message". * @param bool $smilies Whether to include smilies. Defaults to true.
|
* * @return string The MyCode inserter */
| * * @return string The MyCode inserter */
|
Zeile 2834 | Zeile 3709 |
---|
"editor_invalidyoutube" => "Invalid YouTube video", "editor_dailymotion" => "Dailymotion", "editor_metacafe" => "MetaCafe",
|
"editor_invalidyoutube" => "Invalid YouTube video", "editor_dailymotion" => "Dailymotion", "editor_metacafe" => "MetaCafe",
|
"editor_veoh" => "Veoh",
| "editor_mixer" => "Mixer",
|
"editor_vimeo" => "Vimeo", "editor_youtube" => "Youtube", "editor_facebook" => "Facebook",
| "editor_vimeo" => "Vimeo", "editor_youtube" => "Youtube", "editor_facebook" => "Facebook",
|
Zeile 2876 | Zeile 3751 |
---|
// Smilies $emoticon = ""; $emoticons_enabled = "false";
|
// Smilies $emoticon = ""; $emoticons_enabled = "false";
|
if($smilies && $mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
| if($smilies)
|
{
|
{
|
$emoticon = ",emoticon"; $emoticons_enabled = "true";
| |
if(!$smiliecache) {
|
if(!$smiliecache) {
|
if(!is_array($smilie_cache)) {
| if(!isset($smilie_cache) || !is_array($smilie_cache)) {
|
$smilie_cache = $cache->read("smilies");
|
$smilie_cache = $cache->read("smilies");
|
}
| }
|
foreach($smilie_cache as $smilie)
|
foreach($smilie_cache as $smilie)
|
{ if($smilie['showclickable'] != 0) { $smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']); $smiliecache[$smilie['sid']] = $smilie; } } }
unset($smilie);
| { $smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']); $smiliecache[$smilie['sid']] = $smilie; } }
if($mybb->settings['smilieinserter'] && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'] && !empty($smiliecache)) { $emoticon = ",emoticon"; } $emoticons_enabled = "true";
unset($smilie);
|
if(is_array($smiliecache)) { reset($smiliecache);
|
if(is_array($smiliecache)) { reset($smiliecache);
|
|
|
$dropdownsmilies = $moresmilies = $hiddensmilies = ""; $i = 0;
| $dropdownsmilies = $moresmilies = $hiddensmilies = ""; $i = 0;
|
Zeile 2910 | Zeile 3785 |
---|
{ $finds = explode("\n", $smilie['find']); $finds_count = count($finds);
|
{ $finds = explode("\n", $smilie['find']); $finds_count = count($finds);
|
|
|
// Only show the first text to replace in the box $smilie['find'] = $finds[0];
|
// Only show the first text to replace in the box $smilie['find'] = $finds[0];
|
$find = htmlspecialchars_uni($smilie['find']); $image = htmlspecialchars_uni($smilie['image']); if($i < $mybb->settings['smilieinsertertot'])
| $find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($smilie['find'])); $image = htmlspecialchars_uni($mybb->get_asset_url($smilie['image'])); $image = str_replace(array('\\', '"'), array('\\\\', '\"'), $image);
if(!$mybb->settings['smilieinserter'] || !$mybb->settings['smilieinsertercols'] || !$mybb->settings['smilieinsertertot'] || !$smilie['showclickable']) { $hiddensmilies .= '"'.$find.'": "'.$image.'",'; } elseif($i < $mybb->settings['smilieinsertertot'])
|
{ $dropdownsmilies .= '"'.$find.'": "'.$image.'",';
|
{ $dropdownsmilies .= '"'.$find.'": "'.$image.'",';
|
| ++$i;
|
} else {
| } else {
|
Zeile 2927 | Zeile 3809 |
---|
for($j = 1; $j < $finds_count; ++$j) {
|
for($j = 1; $j < $finds_count; ++$j) {
|
$find = htmlspecialchars_uni($finds[$j]);
| $find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($finds[$j]));
|
$hiddensmilies .= '"'.$find.'": "'.$image.'",'; }
|
$hiddensmilies .= '"'.$find.'": "'.$image.'",'; }
|
++$i;
| |
} } }
| } } }
|
Zeile 2966 | Zeile 3847 |
---|
if($mybb->settings['allowfontmycode'] == 1 || $mybb->settings['allowsizemycode'] == 1 || $mybb->settings['allowcolormycode'] == 1) { $removeformat = "removeformat|";
|
if($mybb->settings['allowfontmycode'] == 1 || $mybb->settings['allowsizemycode'] == 1 || $mybb->settings['allowcolormycode'] == 1) { $removeformat = "removeformat|";
|
}
| }
|
if($mybb->settings['allowemailmycode'] == 1) { $email = "email,";
| if($mybb->settings['allowemailmycode'] == 1) { $email = "email,";
|
Zeile 2998 | Zeile 3879 |
---|
}
return $codeinsert;
|
}
return $codeinsert;
|
| }
/** * @param int $tid * @param array $postoptions The options carried with form submit * * @return string Predefined / updated subscription method of the thread for the user */ function get_subscription_method($tid = 0, $postoptions = array()) { global $mybb;
$subscription_methods = array('', 'none', 'email', 'pm'); // Define methods $subscription_method = (int)$mybb->user['subscriptionmethod']; // Set user default
// If no user default method available then reset method if(!$subscription_method) { $subscription_method = 0; }
// Return user default if no thread id available, in case if(!(int)$tid || (int)$tid <= 0) { return $subscription_methods[$subscription_method]; }
// If method not predefined set using data from database if(isset($postoptions['subscriptionmethod'])) { $method = trim($postoptions['subscriptionmethod']); return (in_array($method, $subscription_methods)) ? $method : $subscription_methods[0]; } else { global $db;
$query = $db->simple_select("threadsubscriptions", "tid, notification", "tid='".(int)$tid."' AND uid='".$mybb->user['uid']."'", array('limit' => 1)); $subscription = $db->fetch_array($query);
if($subscription) { $subscription_method = (int)$subscription['notification'] + 1; } }
return $subscription_methods[$subscription_method];
|
}
/**
| }
/**
|
Zeile 3006 | Zeile 3934 |
---|
* @return string The clickable smilies list */ function build_clickable_smilies()
|
* @return string The clickable smilies list */ function build_clickable_smilies()
|
{
| {
|
global $cache, $smiliecache, $theme, $templates, $lang, $mybb, $smiliecount;
if($mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot']) { if(!$smiliecount)
|
global $cache, $smiliecache, $theme, $templates, $lang, $mybb, $smiliecount;
if($mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot']) { if(!$smiliecount)
|
{
| {
|
$smilie_cache = $cache->read("smilies"); $smiliecount = count($smilie_cache); }
if(!$smiliecache)
|
$smilie_cache = $cache->read("smilies"); $smiliecount = count($smilie_cache); }
if(!$smiliecache)
|
{
| {
|
if(!is_array($smilie_cache))
|
if(!is_array($smilie_cache))
|
{
| {
|
$smilie_cache = $cache->read("smilies");
|
$smilie_cache = $cache->read("smilies");
|
}
| }
|
foreach($smilie_cache as $smilie)
|
foreach($smilie_cache as $smilie)
|
{ if($smilie['showclickable'] != 0) { $smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']); $smiliecache[$smilie['sid']] = $smilie; } }
| { $smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']); $smiliecache[$smilie['sid']] = $smilie; }
|
}
unset($smilie);
| }
unset($smilie);
|
Zeile 3043 | Zeile 3968 |
---|
if($mybb->settings['smilieinsertertot'] >= $smiliecount) { $mybb->settings['smilieinsertertot'] = $smiliecount;
|
if($mybb->settings['smilieinsertertot'] >= $smiliecount) { $mybb->settings['smilieinsertertot'] = $smiliecount;
|
}
| }
|
else if($mybb->settings['smilieinsertertot'] < $smiliecount) { $smiliecount = $mybb->settings['smilieinsertertot']; eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";"); }
|
else if($mybb->settings['smilieinsertertot'] < $smiliecount) { $smiliecount = $mybb->settings['smilieinsertertot']; eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";"); }
|
$smilies = "";
| $smilies = $smilie_icons = '';
|
$counter = 0; $i = 0;
$extra_class = ''; foreach($smiliecache as $smilie) {
|
$counter = 0; $i = 0;
$extra_class = ''; foreach($smiliecache as $smilie) {
|
if($i < $mybb->settings['smilieinsertertot'])
| if($i < $mybb->settings['smilieinsertertot'] && $smilie['showclickable'] != 0)
|
{
|
{
|
if($counter == 0) { $smilies .= "<tr>\n"; }
| $smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']); $smilie['image'] = htmlspecialchars_uni($mybb->get_asset_url($smilie['image'])); $smilie['name'] = htmlspecialchars_uni($smilie['name']);
|
// Only show the first text to replace in the box $temp = explode("\n", $smilie['find']); // assign to temporary variable for php 5.3 compatibility $smilie['find'] = $temp[0];
|
// Only show the first text to replace in the box $temp = explode("\n", $smilie['find']); // assign to temporary variable for php 5.3 compatibility $smilie['find'] = $temp[0];
|
$find = htmlspecialchars_uni($smilie['find']);
| |
|
|
$onclick = ' onclick="MyBBEditor.insertText(\' '.$smilie['find'].' \');"';
| $find = str_replace(array('\\', "'"), array('\\\\', "\'"), htmlspecialchars_uni($smilie['find']));
$onclick = " onclick=\"MyBBEditor.insertText(' $find ');\"";
|
$extra_class = ' smilie_pointer'; eval('$smilie = "'.$templates->get('smilie', 1, 0).'";');
|
$extra_class = ' smilie_pointer'; eval('$smilie = "'.$templates->get('smilie', 1, 0).'";');
|
eval("\$smilies .= \"".$templates->get("smilieinsert_smilie")."\";");
| eval("\$smilie_icons .= \"".$templates->get("smilieinsert_smilie")."\";");
|
++$i; ++$counter;
if($counter == $mybb->settings['smilieinsertercols']) { $counter = 0;
|
++$i; ++$counter;
if($counter == $mybb->settings['smilieinsertercols']) { $counter = 0;
|
$smilies .= "</tr>\n";
| eval("\$smilies .= \"".$templates->get("smilieinsert_row")."\";"); $smilie_icons = '';
|
} } }
| } } }
|
Zeile 3088 | Zeile 4013 |
---|
if($counter != 0) { $colspan = $mybb->settings['smilieinsertercols'] - $counter;
|
if($counter != 0) { $colspan = $mybb->settings['smilieinsertercols'] - $counter;
|
$smilies .= "<td colspan=\"{$colspan}\"> </td>\n</tr>\n";
| eval("\$smilies .= \"".$templates->get("smilieinsert_row_empty")."\";");
|
}
eval("\$clickablesmilies = \"".$templates->get("smilieinsert")."\";");
| }
eval("\$clickablesmilies = \"".$templates->get("smilieinsert")."\";");
|
Zeile 3109 | Zeile 4034 |
---|
/** * Builds thread prefixes and returns a selected prefix (or all) *
|
/** * Builds thread prefixes and returns a selected prefix (or all) *
|
* @param int The prefix ID (0 to return all)
| * @param int $pid The prefix ID (0 to return all)
|
* @return array The thread prefix's values (or all thread prefixes) */ function build_prefixes($pid=0)
| * @return array The thread prefix's values (or all thread prefixes) */ function build_prefixes($pid=0)
|
Zeile 3159 | Zeile 4084 |
---|
}
/**
|
}
/**
|
* Build the thread prefix selection menu
| * Build the thread prefix selection menu for the current user
|
*
|
*
|
* @param mixed The forum ID (integer ID or string all) * @param mixed The selected prefix ID (integer ID or string any) * @param int Allow multiple prefix selection
| * @param int|string $fid The forum ID (integer ID or string all) * @param int|string $selected_pid The selected prefix ID (integer ID or string any) * @param int $multiple Allow multiple prefix selection * @param int $previous_pid The previously selected prefix ID
|
* @return string The thread prefix selection menu */
|
* @return string The thread prefix selection menu */
|
function build_prefix_select($fid, $selected_pid=0, $multiple=0)
| function build_prefix_select($fid, $selected_pid=0, $multiple=0, $previous_pid=0)
|
{ global $cache, $db, $lang, $mybb, $templates;
| { global $cache, $db, $lang, $mybb, $templates;
|
Zeile 3178 | Zeile 4104 |
---|
$prefix_cache = build_prefixes(0); if(empty($prefix_cache)) {
|
$prefix_cache = build_prefixes(0); if(empty($prefix_cache)) {
|
return false; // We've got no prefixes to show }
$groups = array($mybb->user['usergroup']); if($mybb->user['additionalgroups']) { $exp = explode(",", $mybb->user['additionalgroups']);
foreach($exp as $group) { $groups[] = $group; }
| // We've got no prefixes to show return '';
|
}
// Go through each of our prefixes and decide which ones we can use
| }
// Go through each of our prefixes and decide which ones we can use
|
Zeile 3197 | Zeile 4113 |
---|
foreach($prefix_cache as $prefix) { if($fid != "all" && $prefix['forums'] != "-1")
|
foreach($prefix_cache as $prefix) { if($fid != "all" && $prefix['forums'] != "-1")
|
{
| {
|
// Decide whether this prefix can be used in our forum $forums = explode(",", $prefix['forums']);
|
// Decide whether this prefix can be used in our forum $forums = explode(",", $prefix['forums']);
|
if(!in_array($fid, $forums))
| if(!in_array($fid, $forums) && $prefix['pid'] != $previous_pid)
|
{ // This prefix is not in our forum list continue; } }
|
{ // This prefix is not in our forum list continue; } }
|
if($prefix['groups'] != "-1")
| if(is_member($prefix['groups']) || $prefix['pid'] == $previous_pid)
|
{
|
{
|
$prefix_groups = explode(",", $prefix['groups']);
foreach($groups as $group) { if(in_array($group, $prefix_groups) && !isset($prefixes[$prefix['pid']])) { // Our group can use this prefix! $prefixes[$prefix['pid']] = $prefix; } } } else { // This prefix is for anybody to use...
| // The current user can use this prefix
|
$prefixes[$prefix['pid']] = $prefix; } }
if(empty($prefixes))
|
$prefixes[$prefix['pid']] = $prefix; } }
if(empty($prefixes))
|
{ return false;
| { return '';
|
}
$prefixselect = $prefixselect_prefix = '';
| }
$prefixselect = $prefixselect_prefix = '';
|
Zeile 3246 | Zeile 4149 |
---|
$default_selected = ""; if(((int)$selected_pid == 0) && $selected_pid != 'any')
|
$default_selected = ""; if(((int)$selected_pid == 0) && $selected_pid != 'any')
|
{ $default_selected = " selected=\"selected\""; }
foreach($prefixes as $prefix) {
| { $default_selected = " selected=\"selected\""; }
foreach($prefixes as $prefix) {
|
$selected = ""; if($prefix['pid'] == $selected_pid) {
| $selected = ""; if($prefix['pid'] == $selected_pid) {
|
Zeile 3260 | Zeile 4163 |
---|
$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']); eval("\$prefixselect_prefix .= \"".$templates->get("post_prefixselect_prefix")."\";");
|
$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']); eval("\$prefixselect_prefix .= \"".$templates->get("post_prefixselect_prefix")."\";");
|
}
| }
|
if($multiple != 0)
|
if($multiple != 0)
|
{
| {
|
eval("\$prefixselect = \"".$templates->get("post_prefixselect_multiple")."\";");
|
eval("\$prefixselect = \"".$templates->get("post_prefixselect_multiple")."\";");
|
}
| }
|
else { eval("\$prefixselect = \"".$templates->get("post_prefixselect_single")."\";");
|
else { eval("\$prefixselect = \"".$templates->get("post_prefixselect_single")."\";");
|
}
| }
|
return $prefixselect; }
/**
|
return $prefixselect; }
/**
|
* Build the thread prefix selection menu for a forum
| * Build the thread prefix selection menu for a forum without group permission checks
|
*
|
*
|
* @param mixed The forum ID (integer ID) * @param mixed The selected prefix ID (integer ID)
| * @param int $fid The forum ID (integer ID) * @param int $selected_pid The selected prefix ID (integer ID) * @return string The thread prefix selection menu
|
*/ function build_forum_prefix_select($fid, $selected_pid=0) {
| */ function build_forum_prefix_select($fid, $selected_pid=0) {
|
Zeile 3289 | Zeile 4193 |
---|
$prefix_cache = build_prefixes(0); if(empty($prefix_cache)) {
|
$prefix_cache = build_prefixes(0); if(empty($prefix_cache)) {
|
return false; // We've got no prefixes to show
| // We've got no prefixes to show return '';
|
}
// Go through each of our prefixes and decide which ones we can use
| }
// Go through each of our prefixes and decide which ones we can use
|
Zeile 3316 | Zeile 4221 |
---|
if(empty($prefixes)) {
|
if(empty($prefixes)) {
|
return false; }
$prefixselect = $prefixselect_prefix = '';
| return ''; }
|
|
|
$default_selected = ''; if((int)$selected_pid == 0)
| $default_selected = array('all' => '', 'none' => '', 'any' => ''); $selected_pid = (int)$selected_pid;
if($selected_pid == 0) { $default_selected['all'] = ' selected="selected"'; } else if($selected_pid == -1)
|
{
|
{
|
$default_selected = " selected=\"selected\"";
| $default_selected['none'] = ' selected="selected"'; } else if($selected_pid == -2) { $default_selected['any'] = ' selected="selected"';
|
}
|
}
|
| $prefixselect_prefix = '';
|
foreach($prefixes as $prefix) { $selected = ''; if($prefix['pid'] == $selected_pid) {
|
foreach($prefixes as $prefix) { $selected = ''; if($prefix['pid'] == $selected_pid) {
|
$selected = " selected=\"selected\"";
| $selected = ' selected="selected"';
|
}
$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']);
|
}
$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']);
|
eval("\$prefixselect_prefix .= \"".$templates->get("forumdisplay_threadlist_prefixes_prefix")."\";");
| eval('$prefixselect_prefix .= "'.$templates->get("forumdisplay_threadlist_prefixes_prefix").'";');
|
}
|
}
|
eval("\$prefixselect = \"".$templates->get("forumdisplay_threadlist_prefixes")."\";");
| eval('$prefixselect = "'.$templates->get("forumdisplay_threadlist_prefixes").'";');
|
return $prefixselect; }
/** * Gzip encodes text to a specified level *
|
return $prefixselect; }
/** * Gzip encodes text to a specified level *
|
* @param string The string to encode * @param int The level (1-9) to encode at
| * @param string $contents The string to encode * @param int $level The level (1-9) to encode at
|
* @return string The encoded string */ function gzip_encode($contents, $level=1)
| * @return string The encoded string */ function gzip_encode($contents, $level=1)
|
Zeile 3398 | Zeile 4312 |
---|
/** * Log the actions of a moderator. *
|
/** * Log the actions of a moderator. *
|
* @param array The data of the moderator's action. * @param string The message to enter for the action the moderator performed.
| * @param array $data The data of the moderator's action. * @param string $action The message to enter for the action the moderator performed.
|
*/ function log_moderator_action($data, $action="") {
| */ function log_moderator_action($data, $action="") {
|
Zeile 3418 | Zeile 4332 |
---|
$tid = (int)$data['tid']; unset($data['tid']); }
|
$tid = (int)$data['tid']; unset($data['tid']); }
|
|
|
$pid = 0; if(isset($data['pid'])) {
| $pid = 0; if(isset($data['pid'])) {
|
Zeile 3426 | Zeile 4340 |
---|
unset($data['pid']); }
|
unset($data['pid']); }
|
// Any remaining extra data - we serialize and insert in to its own column
| $tids = array(); if(isset($data['tids'])) { $tids = (array)$data['tids']; unset($data['tids']); }
// Any remaining extra data - we my_serialize and insert in to its own column
|
if(is_array($data))
|
if(is_array($data))
|
{ $data = serialize($data); }
| { $data = my_serialize($data); }
|
$sql_array = array( "uid" => (int)$mybb->user['uid'],
| $sql_array = array( "uid" => (int)$mybb->user['uid'],
|
Zeile 3442 | Zeile 4363 |
---|
"data" => $db->escape_string($data), "ipaddress" => $db->escape_binary($session->packedip) );
|
"data" => $db->escape_string($data), "ipaddress" => $db->escape_binary($session->packedip) );
|
$db->insert_query("moderatorlog", $sql_array);
| if($tids) { $multiple_sql_array = array();
foreach($tids as $tid) { $sql_array['tid'] = (int)$tid; $multiple_sql_array[] = $sql_array; }
$db->insert_query_multiple("moderatorlog", $multiple_sql_array); } else { $db->insert_query("moderatorlog", $sql_array); }
|
}
/** * Get the formatted reputation for a user. *
|
}
/** * Get the formatted reputation for a user. *
|
* @param int The reputation value * @param int The user ID (if not specified, the generated reputation will not be a link)
| * @param int $reputation The reputation value * @param int $uid The user ID (if not specified, the generated reputation will not be a link)
|
* @return string The formatted repuation */ function get_reputation($reputation, $uid=0)
| * @return string The formatted repuation */ function get_reputation($reputation, $uid=0)
|
Zeile 3469 | Zeile 4406 |
---|
{ $reputation_class = "reputation_neutral"; }
|
{ $reputation_class = "reputation_neutral"; }
|
| $reputation = my_number_format($reputation);
|
if($uid != 0) {
| if($uid != 0) {
|
Zeile 3485 | Zeile 4424 |
---|
/** * Fetch a color coded version of a warning level (based on it's percentage) *
|
/** * Fetch a color coded version of a warning level (based on it's percentage) *
|
* @param int The warning level (percentage of 100)
| * @param int $level The warning level (percentage of 100)
|
* @return string Formatted warning level */ function get_colored_warning_level($level)
|
* @return string Formatted warning level */ function get_colored_warning_level($level)
|
{
| {
|
global $templates;
$warning_class = '';
| global $templates;
$warning_class = '';
|
Zeile 3498 | Zeile 4437 |
---|
$warning_class = "high_warning"; } else if($level >= 50)
|
$warning_class = "high_warning"; } else if($level >= 50)
|
{
| {
|
$warning_class = "moderate_warning"; } else if($level >= 25)
| $warning_class = "moderate_warning"; } else if($level >= 25)
|
Zeile 3523 | Zeile 4462 |
---|
{ global $mybb, $plugins;
|
{ global $mybb, $plugins;
|
$ip = $_SERVER['REMOTE_ADDR'];
| $ip = strtolower($_SERVER['REMOTE_ADDR']);
|
if($mybb->settings['ip_forwarded_check']) {
| if($mybb->settings['ip_forwarded_check']) {
|
Zeile 3531 | Zeile 4470 |
---|
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
$addresses = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
| $addresses = explode(',', strtolower($_SERVER['HTTP_X_FORWARDED_FOR']));
|
} elseif(isset($_SERVER['HTTP_X_REAL_IP'])) {
|
} elseif(isset($_SERVER['HTTP_X_REAL_IP'])) {
|
$addresses = explode(',', $_SERVER['HTTP_X_REAL_IP']);
| $addresses = explode(',', strtolower($_SERVER['HTTP_X_REAL_IP']));
|
}
if(is_array($addresses))
| }
if(is_array($addresses))
|
Zeile 3548 | Zeile 4487 |
---|
{ $ip = $val; break;
|
{ $ip = $val; break;
|
} } } }
| } } } }
|
if(!$ip) { if(isset($_SERVER['HTTP_CLIENT_IP'])) {
|
if(!$ip) { if(isset($_SERVER['HTTP_CLIENT_IP'])) {
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
| $ip = strtolower($_SERVER['HTTP_CLIENT_IP']);
|
} }
| } }
|
Zeile 3573 | Zeile 4512 |
---|
/** * Fetch the friendly size (GB, MB, KB, B) for a specified file size. *
|
/** * Fetch the friendly size (GB, MB, KB, B) for a specified file size. *
|
* @param int The size in bytes
| * @param int $size The size in bytes
|
* @return string The friendly file size */ function get_friendly_size($size)
| * @return string The friendly file size */ function get_friendly_size($size)
|
Zeile 3640 | Zeile 4579 |
---|
/** * Format a decimal number in to microseconds, milliseconds, or seconds. *
|
/** * Format a decimal number in to microseconds, milliseconds, or seconds. *
|
* @param int The time in microseconds
| * @param int $time The time in microseconds
|
* @return string The friendly time duration */ function format_time_duration($time)
| * @return string The friendly time duration */ function format_time_duration($time)
|
Zeile 3671 | Zeile 4610 |
---|
/** * Get the attachment icon for a specific file extension *
|
/** * Get the attachment icon for a specific file extension *
|
* @param string The file extension
| * @param string $ext The file extension
|
* @return string The attachment icon */ function get_attachment_icon($ext) {
|
* @return string The attachment icon */ function get_attachment_icon($ext) {
|
global $cache, $attachtypes, $theme, $templates, $lang;
| global $cache, $attachtypes, $theme, $templates, $lang, $mybb;
|
if(!$attachtypes) {
| if(!$attachtypes) {
|
Zeile 3687 | Zeile 4626 |
---|
if($attachtypes[$ext]['icon']) {
|
if($attachtypes[$ext]['icon']) {
|
if(defined("IN_ADMINCP"))
| static $attach_icons_schemes = array(); if(!isset($attach_icons_schemes[$ext]))
|
{
|
{
|
$icon = str_replace("{theme}", "", $attachtypes[$ext]['icon']); if(my_substr($icon, 0, 1) != "/" && my_substr($icon, 0, 7) != "http://")
| $attach_icons_schemes[$ext] = parse_url($attachtypes[$ext]['icon']); if(!empty($attach_icons_schemes[$ext]['scheme']))
|
{
|
{
|
$icon = "../".$icon;
| $attach_icons_schemes[$ext] = $attachtypes[$ext]['icon']; } elseif(defined("IN_ADMINCP")) { $attach_icons_schemes[$ext] = str_replace("{theme}", "", $attachtypes[$ext]['icon']); if(my_substr($attach_icons_schemes[$ext], 0, 1) != "/") { $attach_icons_schemes[$ext] = "../".$attach_icons_schemes[$ext]; } } elseif(defined("IN_PORTAL")) { global $change_dir; $attach_icons_schemes[$ext] = $change_dir."/".str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']); $attach_icons_schemes[$ext] = $mybb->get_asset_url($attach_icons_schemes[$ext]); } else { $attach_icons_schemes[$ext] = str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']); $attach_icons_schemes[$ext] = $mybb->get_asset_url($attach_icons_schemes[$ext]);
|
}
|
}
|
} elseif(defined("IN_PORTAL")) { global $change_dir; $icon = $change_dir."/".str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']); } else { $icon = str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']);
| |
}
|
}
|
| $icon = $attach_icons_schemes[$ext];
|
$name = htmlspecialchars_uni($attachtypes[$ext]['name']); } else
|
$name = htmlspecialchars_uni($attachtypes[$ext]['name']); } else
|
{
| {
|
if(defined("IN_ADMINCP")) { $theme['imgdir'] = "../images";
| if(defined("IN_ADMINCP")) { $theme['imgdir'] = "../images";
|
Zeile 3720 | Zeile 4672 |
---|
}
$icon = "{$theme['imgdir']}/attachtypes/unknown.png";
|
}
$icon = "{$theme['imgdir']}/attachtypes/unknown.png";
|
|
|
$name = $lang->unknown; }
|
$name = $lang->unknown; }
|
| $icon = htmlspecialchars_uni($icon);
|
eval("\$attachment_icon = \"".$templates->get("attachment_icon")."\";"); return $attachment_icon; }
| eval("\$attachment_icon = \"".$templates->get("attachment_icon")."\";"); return $attachment_icon; }
|
Zeile 3730 | Zeile 4684 |
---|
/** * Get a list of the unviewable forums for the current user *
|
/** * Get a list of the unviewable forums for the current user *
|
* @param boolean Set to true to only fetch those forums for which users can actually read a thread in.
| * @param boolean $only_readable_threads Set to true to only fetch those forums for which users can actually read a thread in.
|
* @return string Comma separated values list of the forum IDs which the user cannot view */ function get_unviewable_forums($only_readable_threads=false) {
|
* @return string Comma separated values list of the forum IDs which the user cannot view */ function get_unviewable_forums($only_readable_threads=false) {
|
global $forum_cache, $permissioncache, $mybb, $unviewable, $templates, $forumpass;
if(!isset($permissions)) { $permissions = $mybb->usergroup; }
| global $forum_cache, $permissioncache, $mybb;
|
if(!is_array($forum_cache)) {
| if(!is_array($forum_cache)) {
|
Zeile 3752 | Zeile 4701 |
---|
$permissioncache = forum_permissions(); }
|
$permissioncache = forum_permissions(); }
|
$unviewableforums = ''; $password_forums = array();
| $unviewable = array();
|
foreach($forum_cache as $fid => $forum) { if($permissioncache[$forum['fid']])
| foreach($forum_cache as $fid => $forum) { if($permissioncache[$forum['fid']])
|
Zeile 3763 | Zeile 4711 |
---|
else { $perms = $mybb->usergroup;
|
else { $perms = $mybb->usergroup;
|
}
| }
|
$pwverified = 1;
|
$pwverified = 1;
|
if($forum['password'] != "") { if($mybb->cookies['forumpass'][$forum['fid']] != md5($mybb->user['uid'].$forum['password'])) { $pwverified = 0; }
$password_forums[$forum['fid']] = $forum['password'];
| if(!forum_password_validated($forum, true)) { $pwverified = 0;
|
} else { // Check parents for passwords $parents = explode(",", $forum['parentlist']); foreach($parents as $parent)
|
} else { // Check parents for passwords $parents = explode(",", $forum['parentlist']); foreach($parents as $parent)
|
{ if(isset($password_forums[$parent]) && $mybb->cookies['forumpass'][$parent] != md5($mybb->user['uid'].$password_forums[$parent])) {
| { if(!forum_password_validated($forum_cache[$parent], true)) {
|
$pwverified = 0;
|
$pwverified = 0;
|
| break;
|
}
|
}
|
} }
| } }
|
if($perms['canview'] == 0 || $pwverified == 0 || ($only_readable_threads == true && $perms['canviewthreads'] == 0)) {
|
if($perms['canview'] == 0 || $pwverified == 0 || ($only_readable_threads == true && $perms['canviewthreads'] == 0)) {
|
if($unviewableforums) { $unviewableforums .= ","; }
| $unviewable[] = $forum['fid']; } }
|
|
|
$unviewableforums .= "'".$forum['fid']."'"; } }
if(isset($unviewableforums)) { return $unviewableforums; }
| $unviewableforums = implode(',', $unviewable);
return $unviewableforums;
|
}
/** * Fixes mktime for dates earlier than 1970 *
|
}
/** * Fixes mktime for dates earlier than 1970 *
|
* @param string The date format to use * @param int The year of the date
| * @param string $format The date format to use * @param int $year The year of the date
|
* @return string The correct date format */ function fix_mktime($format, $year)
| * @return string The correct date format */ function fix_mktime($format, $year)
|
Zeile 3826 | Zeile 4765 |
---|
/** * Build the breadcrumb navigation trail from the specified items *
|
/** * Build the breadcrumb navigation trail from the specified items *
|
* @return The formatted breadcrumb navigation trail
| * @return string The formatted breadcrumb navigation trail
|
*/ function build_breadcrumb() {
| */ function build_breadcrumb() {
|
Zeile 3861 | Zeile 4800 |
---|
{ $mybb->settings['threadsperpage'] = 20; }
|
{ $mybb->settings['threadsperpage'] = 20; }
|
|
|
$multipage = multipage($navbit['multipage']['num_threads'], $mybb->settings['threadsperpage'], $navbit['multipage']['current_page'], $navbit['multipage']['url'], true); if($multipage) {
| $multipage = multipage($navbit['multipage']['num_threads'], $mybb->settings['threadsperpage'], $navbit['multipage']['current_page'], $navbit['multipage']['url'], true); if($multipage) {
|
Zeile 3878 | Zeile 4817 |
---|
eval("\$nav .= \"".$templates->get("nav_bit")."\";"); } }
|
eval("\$nav .= \"".$templates->get("nav_bit")."\";"); } }
|
| $navsize = count($navbits); $navbit = $navbits[$navsize-1];
|
}
|
}
|
$activesep = ''; $navsize = count($navbits); $navbit = $navbits[$navsize-1];
| |
if($nav) {
| if($nav) {
|
Zeile 3898 | Zeile 4835 |
---|
/** * Add a breadcrumb menu item to the list. *
|
/** * Add a breadcrumb menu item to the list. *
|
* @param string The name of the item to add * @param string The URL of the item to add
| * @param string $name The name of the item to add * @param string $url The URL of the item to add
|
*/ function add_breadcrumb($name, $url="") {
| */ function add_breadcrumb($name, $url="") {
|
Zeile 3913 | Zeile 4850 |
---|
/** * Build the forum breadcrumb nagiation (the navigation to a specific forum including all parent forums) *
|
/** * Build the forum breadcrumb nagiation (the navigation to a specific forum including all parent forums) *
|
* @param int The forum ID to build the navigation for * @param array The multipage drop down array of information
| * @param int $fid The forum ID to build the navigation for * @param array $multipage The multipage drop down array of information * @return int Returns 1 in every case. Kept for compatibility
|
*/ function build_forum_breadcrumb($fid, $multipage=array()) {
| */ function build_forum_breadcrumb($fid, $multipage=array()) {
|
Zeile 3999 | Zeile 4937 |
---|
/** * Builds a URL to an archive mode page *
|
/** * Builds a URL to an archive mode page *
|
* @param string The type of page (thread|announcement|forum) * @param int The ID of the item
| * @param string $type The type of page (thread|announcement|forum) * @param int $id The ID of the item
|
* @return string The URL */
|
* @return string The URL */
|
function build_archive_link($type="", $id="")
| function build_archive_link($type="", $id=0)
|
{ global $mybb;
| { global $mybb;
|
Zeile 4191 | Zeile 5129 |
---|
if($mybb->settings['nocacheheaders'] == 1) {
|
if($mybb->settings['nocacheheaders'] == 1) {
|
header("Expires: Sat, 1 Jan 2000 01:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");
| header("Cache-Control: no-cache, private");
|
} }
/** * Mark specific reported posts of a certain type as dealt with *
|
} }
/** * Mark specific reported posts of a certain type as dealt with *
|
* @param mixed An array or int of the ID numbers you're marking as dealt with * @param string The type of item the above IDs are for - post, posts, thread, threads, forum, all
| * @param array|int $id An array or int of the ID numbers you're marking as dealt with * @param string $type The type of item the above IDs are for - post, posts, thread, threads, forum, all
|
*/ function mark_reports($id, $type="post") {
| */ function mark_reports($id, $type="post") {
|
Zeile 4213 | Zeile 5148 |
---|
case "posts": if(is_array($id)) {
|
case "posts": if(is_array($id)) {
|
$rids = implode($id, "','");
| $rids = implode("','", $id);
|
$rids = "'0','$rids'"; $db->update_query("reportedcontent", array('reportstatus' => 1), "id IN($rids) AND reportstatus='0' AND (type = 'post' OR type = '')"); }
| $rids = "'0','$rids'"; $db->update_query("reportedcontent", array('reportstatus' => 1), "id IN($rids) AND reportstatus='0' AND (type = 'post' OR type = '')"); }
|
Zeile 4224 | Zeile 5159 |
---|
case "threads": if(is_array($id)) {
|
case "threads": if(is_array($id)) {
|
$rids = implode($id, "','");
| $rids = implode("','", $id);
|
$rids = "'0','$rids'"; $db->update_query("reportedcontent", array('reportstatus' => 1), "id2 IN($rids) AND reportstatus='0' AND (type = 'post' OR type = '')"); }
| $rids = "'0','$rids'"; $db->update_query("reportedcontent", array('reportstatus' => 1), "id2 IN($rids) AND reportstatus='0' AND (type = 'post' OR type = '')"); }
|
Zeile 4248 | Zeile 5183 |
---|
/** * Fetch a friendly x days, y months etc date stamp from a timestamp *
|
/** * Fetch a friendly x days, y months etc date stamp from a timestamp *
|
* @param int The timestamp * @param array Array of options
| * @param int $stamp The timestamp * @param array $options Array of options
|
* @return string The friendly formatted timestamp */ function nice_time($stamp, $options=array())
| * @return string The friendly formatted timestamp */ function nice_time($stamp, $options=array())
|
Zeile 4312 | Zeile 5247 |
---|
$stamp %= $msecs; $seconds = $stamp;
|
$stamp %= $msecs; $seconds = $stamp;
|
if($years == 1)
| // Prevent gross over accuracy ($options parameter will override these) if($years > 0)
|
{
|
{
|
$nicetime['years'] = "1".$lang_year;
| $options = array_merge(array( 'days' => false, 'hours' => false, 'minutes' => false, 'seconds' => false ), $options);
|
}
|
}
|
else if($years > 1)
| elseif($months > 0)
|
{
|
{
|
$nicetime['years'] = $years.$lang_years;
| $options = array_merge(array( 'hours' => false, 'minutes' => false, 'seconds' => false ), $options);
|
}
|
}
|
if($months == 1) { $nicetime['months'] = "1".$lang_month; } else if($months > 1) { $nicetime['months'] = $months.$lang_months; }
if($weeks == 1) { $nicetime['weeks'] = "1".$lang_week; } else if($weeks > 1) { $nicetime['weeks'] = $weeks.$lang_weeks; }
if($days == 1) { $nicetime['days'] = "1".$lang_day; } else if($days > 1) { $nicetime['days'] = $days.$lang_days; }
| elseif($weeks > 0) { $options = array_merge(array( 'minutes' => false, 'seconds' => false ), $options); } elseif($days > 0) { $options = array_merge(array( 'seconds' => false ), $options); }
$nicetime = array();
if(!isset($options['years']) || $options['years'] !== false) { if($years == 1) { $nicetime['years'] = "1".$lang_year; } else if($years > 1) { $nicetime['years'] = $years.$lang_years; } }
if(!isset($options['months']) || $options['months'] !== false) { if($months == 1) { $nicetime['months'] = "1".$lang_month; } else if($months > 1) { $nicetime['months'] = $months.$lang_months; } }
if(!isset($options['weeks']) || $options['weeks'] !== false) { if($weeks == 1) { $nicetime['weeks'] = "1".$lang_week; } else if($weeks > 1) { $nicetime['weeks'] = $weeks.$lang_weeks; } }
if(!isset($options['days']) || $options['days'] !== false) { if($days == 1) { $nicetime['days'] = "1".$lang_day; } else if($days > 1) { $nicetime['days'] = $days.$lang_days; } }
|
if(!isset($options['hours']) || $options['hours'] !== false) { if($hours == 1)
| if(!isset($options['hours']) || $options['hours'] !== false) { if($hours == 1)
|
Zeile 4355 | Zeile 5336 |
---|
$nicetime['hours'] = "1".$lang_hour; } else if($hours > 1)
|
$nicetime['hours'] = "1".$lang_hour; } else if($hours > 1)
|
{
| {
|
$nicetime['hours'] = $hours.$lang_hours; } }
| $nicetime['hours'] = $hours.$lang_hours; } }
|
Zeile 4369 | Zeile 5350 |
---|
else if($minutes > 1) { $nicetime['minutes'] = $minutes.$lang_minutes;
|
else if($minutes > 1) { $nicetime['minutes'] = $minutes.$lang_minutes;
|
} }
| } }
|
if(!isset($options['seconds']) || $options['seconds'] !== false) {
| if(!isset($options['seconds']) || $options['seconds'] !== false) {
|
Zeile 4384 | Zeile 5365 |
---|
} }
|
} }
|
if(is_array($nicetime))
| if(!empty($nicetime))
|
{ return implode(", ", $nicetime); }
| { return implode(", ", $nicetime); }
|
Zeile 4393 | Zeile 5374 |
---|
/** * Select an alternating row colour based on the previous call to this function *
|
/** * Select an alternating row colour based on the previous call to this function *
|
* @param int 1 to reset the row to trow1.
| * @param int $reset 1 to reset the row to trow1.
|
* @return string trow1 or trow2 depending on the previous call
|
* @return string trow1 or trow2 depending on the previous call
|
*/
| */
|
function alt_trow($reset=0) { global $alttrow;
| function alt_trow($reset=0) { global $alttrow;
|
Zeile 4407 | Zeile 5388 |
---|
else { $trow = "trow1";
|
else { $trow = "trow1";
|
}
$alttrow = $trow;
| }
$alttrow = $trow;
|
return $trow; }
/** * Add a user to a specific additional user group.
|
return $trow; }
/** * Add a user to a specific additional user group.
|
* * @param int The user ID * @param int The user group ID to join
| * * @param int $uid The user ID * @param int $joingroup The user group ID to join * @return bool
|
*/ function join_usergroup($uid, $joingroup) { global $db, $mybb;
if($uid == $mybb->user['uid'])
|
*/ function join_usergroup($uid, $joingroup) { global $db, $mybb;
if($uid == $mybb->user['uid'])
|
{
| {
|
$user = $mybb->user;
|
$user = $mybb->user;
|
}
| }
|
else { $query = $db->simple_select("users", "additionalgroups, usergroup", "uid='".(int)$uid."'"); $user = $db->fetch_array($query);
|
else { $query = $db->simple_select("users", "additionalgroups, usergroup", "uid='".(int)$uid."'"); $user = $db->fetch_array($query);
|
}
| }
|
// Build the new list of additional groups for this user and make sure they're in the right format
|
// Build the new list of additional groups for this user and make sure they're in the right format
|
$usergroups = ""; $usergroups = $user['additionalgroups'].",".$joingroup; $groupslist = ""; $groups = explode(",", $usergroups);
| $groups = array_map( 'intval', explode(',', $user['additionalgroups']) );
if(!in_array((int)$joingroup, $groups)) { $groups[] = (int)$joingroup; $groups = array_diff($groups, array($user['usergroup'])); $groups = array_unique($groups);
$groupslist = implode(',', $groups);
|
|
|
if(is_array($groups)) { $comma = ''; foreach($groups as $gid) { if(trim($gid) != "" && $gid != $user['usergroup'] && !isset($donegroup[$gid])) { $groupslist .= $comma.$gid; $comma = ","; $donegroup[$gid] = 1; } } }
// What's the point in updating if they're the same? if($groupslist != $user['additionalgroups']) {
| |
$db->update_query("users", array('additionalgroups' => $groupslist), "uid='".(int)$uid."'"); return true; }
| $db->update_query("users", array('additionalgroups' => $groupslist), "uid='".(int)$uid."'"); return true; }
|
Zeile 4469 | Zeile 5442 |
---|
/** * Remove a user from a specific additional user group *
|
/** * Remove a user from a specific additional user group *
|
* @param int The user ID * @param int The user group ID
| * @param int $uid The user ID * @param int $leavegroup The user group ID
|
*/ function leave_usergroup($uid, $leavegroup)
|
*/ function leave_usergroup($uid, $leavegroup)
|
{
| {
|
global $db, $mybb, $cache;
|
global $db, $mybb, $cache;
|
if($uid == $mybb->user['uid']) { $user = $mybb->user; } else { $user = get_user($uid); }
$groupslist = $comma = ''; $usergroups = $user['additionalgroups'].","; $donegroup = array();
$groups = explode(",", $user['additionalgroups']);
if(is_array($groups)) { foreach($groups as $gid) { if(trim($gid) != "" && $leavegroup != $gid && empty($donegroup[$gid])) { $groupslist .= $comma.$gid; $comma = ","; $donegroup[$gid] = 1; } }
| $user = get_user($uid);
if($user['usergroup'] == $leavegroup) { return false;
|
}
|
}
|
| $groups = array_map( 'intval', explode(',', $user['additionalgroups']) ); $groups = array_diff($groups, array($leavegroup)); $groups = array_unique($groups);
$groupslist = implode(',', $groups);
|
$dispupdate = "";
|
$dispupdate = "";
|
if($leavegroup == $user['displaygroup']) { $dispupdate = ", displaygroup=usergroup";
| if($leavegroup == $user['displaygroup']) { $dispupdate = ", displaygroup=usergroup";
|
}
$db->write_query("
| }
$db->write_query("
|
Zeile 4522 | Zeile 5483 |
---|
/** * Get the current location taking in to account different web serves and systems *
|
/** * Get the current location taking in to account different web serves and systems *
|
* @param boolean True to return as "hidden" fields * @param array Array of fields to ignore if first argument is true * @return string The current URL being accessed
| * @param boolean $fields True to return as "hidden" fields * @param array $ignore Array of fields to ignore for returning "hidden" fields or URL being accessed * @param boolean $quick True to skip all inputs and return only the file path part of the URL * @return string|array The current URL being accessed or form data if $fields is true
|
*/
|
*/
|
function get_current_location($fields=false, $ignore=array())
| function get_current_location($fields=false, $ignore=array(), $quick=false)
|
{
|
{
|
| global $mybb;
|
if(defined("MYBB_LOCATION"))
|
if(defined("MYBB_LOCATION"))
|
{
| {
|
return MYBB_LOCATION; }
|
return MYBB_LOCATION; }
|
if(!empty($_SERVER['PATH_INFO'])) { $location = htmlspecialchars_uni($_SERVER['PATH_INFO']); } elseif(!empty($_ENV['PATH_INFO'])) { $location = htmlspecialchars_uni($_ENV['PATH_INFO']);
| if(!empty($_SERVER['SCRIPT_NAME'])) { $location = htmlspecialchars_uni($_SERVER['SCRIPT_NAME']); } elseif(!empty($_SERVER['PHP_SELF'])) { $location = htmlspecialchars_uni($_SERVER['PHP_SELF']);
|
} elseif(!empty($_ENV['PHP_SELF'])) { $location = htmlspecialchars_uni($_ENV['PHP_SELF']);
|
} elseif(!empty($_ENV['PHP_SELF'])) { $location = htmlspecialchars_uni($_ENV['PHP_SELF']);
|
}
| } elseif(!empty($_SERVER['PATH_INFO'])) { $location = htmlspecialchars_uni($_SERVER['PATH_INFO']); }
|
else {
|
else {
|
$location = htmlspecialchars_uni($_SERVER['PHP_SELF']);
| $location = htmlspecialchars_uni($_ENV['PATH_INFO']); }
if($quick) { return $location; }
if(!is_array($ignore)) { $ignore = array($ignore);
|
}
if($fields == true)
|
}
if($fields == true)
|
{ global $mybb;
if(!is_array($ignore)) { $ignore = array($ignore); }
| {
|
$form_html = ''; if(!empty($mybb->input))
|
$form_html = ''; if(!empty($mybb->input))
|
{
| {
|
foreach($mybb->input as $name => $value) { if(in_array($name, $ignore) || is_array($name) || is_array($value))
| foreach($mybb->input as $name => $value) { if(in_array($name, $ignore) || is_array($name) || is_array($value))
|
Zeile 4570 | Zeile 5542 |
---|
}
$form_html .= "<input type=\"hidden\" name=\"".htmlspecialchars_uni($name)."\" value=\"".htmlspecialchars_uni($value)."\" />\n";
|
}
$form_html .= "<input type=\"hidden\" name=\"".htmlspecialchars_uni($name)."\" value=\"".htmlspecialchars_uni($value)."\" />\n";
|
} }
| } }
|
return array('location' => $location, 'form_html' => $form_html, 'form_method' => $mybb->request_method); } else {
|
return array('location' => $location, 'form_html' => $form_html, 'form_method' => $mybb->request_method); } else {
|
| $parameters = array();
|
if(isset($_SERVER['QUERY_STRING'])) {
|
if(isset($_SERVER['QUERY_STRING'])) {
|
$location .= "?".htmlspecialchars_uni($_SERVER['QUERY_STRING']);
| $current_query_string = $_SERVER['QUERY_STRING'];
|
} else if(isset($_ENV['QUERY_STRING'])) {
|
} else if(isset($_ENV['QUERY_STRING'])) {
|
$location .= "?".htmlspecialchars_uni($_ENV['QUERY_STRING']);
| $current_query_string = $_ENV['QUERY_STRING']; } else { $current_query_string = '';
|
}
|
}
|
if((isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "POST") || (isset($_ENV['REQUEST_METHOD']) && $_ENV['REQUEST_METHOD'] == "POST"))
| parse_str($current_query_string, $current_parameters);
foreach($current_parameters as $name => $value) { if(!in_array($name, $ignore)) { $parameters[$name] = $value; } }
if($mybb->request_method === 'post')
|
{ $post_array = array('action', 'fid', 'pid', 'tid', 'uid', 'eid');
|
{ $post_array = array('action', 'fid', 'pid', 'tid', 'uid', 'eid');
|
|
|
foreach($post_array as $var) {
|
foreach($post_array as $var) {
|
if(isset($_POST[$var])) { $addloc[] = urlencode($var).'='.urlencode($_POST[$var]); } }
if(isset($addloc) && is_array($addloc)) { if(strpos($location, "?") === false) { $location .= "?"; } else
| if(isset($_POST[$var]) && !in_array($var, $ignore))
|
{
|
{
|
$location .= "&";
| $parameters[$var] = $_POST[$var];
|
}
|
}
|
$location .= implode("&", $addloc);
| |
} }
|
} }
|
if(strlen($location) > 150)
| if(!empty($parameters))
|
{
|
{
|
$location = substr($location, 0, 150);
| $location .= '?'.http_build_query($parameters, '', '&');
|
}
return $location;
| }
return $location;
|
Zeile 4624 | Zeile 5598 |
---|
/** * Build a theme selection menu *
|
/** * Build a theme selection menu *
|
* @param string The name of the menu * @param int The ID of the selected theme * @param int The ID of the parent theme to select from * @param int The current selection depth * @param boolean Whether or not to override usergroup permissions (true to override) * @param boolean Whether or not theme select is in the footer (true if it is) * @param boolean Whether or not to override output based on theme count (true to override)
| * @param string $name The name of the menu * @param int $selected The ID of the selected theme * @param int $tid The ID of the parent theme to select from * @param string $depth The current selection depth * @param boolean $usergroup_override Whether or not to override usergroup permissions (true to override) * @param boolean $footer Whether or not theme select is in the footer (true if it is) * @param boolean $count_override Whether or not to override output based on theme count (true to override)
|
* @return string The theme selection list */
|
* @return string The theme selection list */
|
function build_theme_select($name, $selected="", $tid=0, $depth="", $usergroup_override=false, $footer=false, $count_override=false)
| function build_theme_select($name, $selected=-1, $tid=0, $depth="", $usergroup_override=false, $footer=false, $count_override=false)
|
{ global $db, $themeselect, $tcache, $lang, $mybb, $limit, $templates, $num_themes, $themeselect_option;
| { global $db, $themeselect, $tcache, $lang, $mybb, $limit, $templates, $num_themes, $themeselect_option;
|
Zeile 4642 | Zeile 5616 |
---|
$tid = 1; $num_themes = 0; $themeselect_option = '';
|
$tid = 1; $num_themes = 0; $themeselect_option = '';
|
if(!isset($lang->use_default)) { $lang->use_default = $lang->lang_select_default; }
| |
}
if(!is_array($tcache)) {
|
}
if(!is_array($tcache)) {
|
$query = $db->simple_select("themes", "name, pid, tid, allowedgroups", "pid != '0'", array('order_by' => 'pid, name'));
| $query = $db->simple_select('themes', 'tid, name, pid, allowedgroups', "pid!='0'");
|
while($theme = $db->fetch_array($query)) { $tcache[$theme['pid']][$theme['tid']] = $theme;
|
while($theme = $db->fetch_array($query)) { $tcache[$theme['pid']][$theme['tid']] = $theme;
|
} }
| } }
|
if(is_array($tcache[$tid])) {
|
if(is_array($tcache[$tid])) {
|
// Figure out what groups this user is in if(isset($mybb->user['additionalgroups'])) { $in_groups = explode(",", $mybb->user['additionalgroups']); } $in_groups[] = $mybb->user['usergroup'];
| |
foreach($tcache[$tid] as $theme) { $sel = "";
|
foreach($tcache[$tid] as $theme) { $sel = "";
|
// Make theme allowed groups into array $is_allowed = false; if($theme['allowedgroups'] != "all") { $allowed_groups = explode(",", $theme['allowedgroups']); // See if groups user is in is allowed foreach($allowed_groups as $agid) { if(in_array($agid, $in_groups)) { $is_allowed = true; break; } } }
| |
// Show theme if allowed, or if override is on
|
// Show theme if allowed, or if override is on
|
if($is_allowed || $theme['allowedgroups'] == "all" || $usergroup_override == true)
| if(is_member($theme['allowedgroups']) || $theme['allowedgroups'] == "all" || $usergroup_override == true)
|
{ if($theme['tid'] == $selected) {
| { if($theme['tid'] == $selected) {
|
Zeile 4701 | Zeile 5647 |
---|
eval("\$themeselect_option .= \"".$templates->get("usercp_themeselector_option")."\";"); ++$num_themes; $depthit = $depth."--";
|
eval("\$themeselect_option .= \"".$templates->get("usercp_themeselector_option")."\";"); ++$num_themes; $depthit = $depth."--";
|
}
| }
|
if(array_key_exists($theme['tid'], $tcache)) {
|
if(array_key_exists($theme['tid'], $tcache)) {
|
build_theme_select($name, $selected, $theme['tid'], $depthit, $usergroup_override, $footer);
| build_theme_select($name, $selected, $theme['tid'], $depthit, $usergroup_override, $footer, $count_override);
|
} } }
| } } }
|
Zeile 4714 | Zeile 5660 |
---|
if($tid == 1 && ($num_themes > 1 || $count_override == true)) { if($footer == true)
|
if($tid == 1 && ($num_themes > 1 || $count_override == true)) { if($footer == true)
|
{
| {
|
eval("\$themeselect = \"".$templates->get("footer_themeselector")."\";"); } else
| eval("\$themeselect = \"".$templates->get("footer_themeselector")."\";"); } else
|
Zeile 4727 | Zeile 5673 |
---|
else { return false;
|
else { return false;
|
} }
/**
| } }
/** * Get the theme data of a theme id. * * @param int $tid The theme id of the theme. * @return boolean|array False if no valid theme, Array with the theme data otherwise */ function get_theme($tid) { global $tcache, $db;
if(!is_array($tcache)) { $query = $db->simple_select('themes', 'tid, name, pid, allowedgroups', "pid!='0'");
while($theme = $db->fetch_array($query)) { $tcache[$theme['pid']][$theme['tid']] = $theme; } }
$s_theme = false;
foreach($tcache as $themes) { foreach($themes as $theme) { if($tid == $theme['tid']) { $s_theme = $theme; break 2; } } }
return $s_theme; }
/**
|
* Custom function for htmlspecialchars which takes in to account unicode *
|
* Custom function for htmlspecialchars which takes in to account unicode *
|
* @param string The string to format
| * @param string $message The string to format
|
* @return string The string with htmlspecialchars applied */ function htmlspecialchars_uni($message)
| * @return string The string with htmlspecialchars applied */ function htmlspecialchars_uni($message)
|
Zeile 4748 | Zeile 5731 |
---|
/** * Custom function for formatting numbers. *
|
/** * Custom function for formatting numbers. *
|
* @param int The number to format.
| * @param int $number The number to format.
|
* @return int The formatted number. */ function my_number_format($number)
| * @return int The formatted number. */ function my_number_format($number)
|
Zeile 4766 | Zeile 5749 |
---|
} else {
|
} else {
|
$parts = explode('.', $number);
| if(isset($number)) { $parts = explode('.', $number); } else { $parts = array(); }
|
if(isset($parts[1])) {
| if(isset($parts[1])) {
|
Zeile 4778 | Zeile 5768 |
---|
}
return number_format((double)$number, $decimals, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);
|
}
return number_format((double)$number, $decimals, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);
|
} }
| } }
|
/** * Converts a string of text to or from UTF-8. *
|
/** * Converts a string of text to or from UTF-8. *
|
* @param string The string of text to convert * @param boolean Whether or not the string is being converted to or from UTF-8 (true if converting to)
| * @param string $str The string of text to convert * @param boolean $to Whether or not the string is being converted to or from UTF-8 (true if converting to)
|
* @return string The converted string */ function convert_through_utf8($str, $to=true)
| * @return string The converted string */ function convert_through_utf8($str, $to=true)
|
Zeile 4828 | Zeile 5818 |
---|
$to_charset = $lang->settings['charset']; } if($use_iconv)
|
$to_charset = $lang->settings['charset']; } if($use_iconv)
|
{
| {
|
return iconv($from_charset, $to_charset."//IGNORE", $str); } else
| return iconv($from_charset, $to_charset."//IGNORE", $str); } else
|
Zeile 4843 | Zeile 5833 |
---|
return utf8_encode($str); } else
|
return utf8_encode($str); } else
|
{
| {
|
return utf8_decode($str); } } else
|
return utf8_decode($str); } } else
|
{
| {
|
return $str;
|
return $str;
|
} }
/** * Replacement function for PHP's wordwrap(). This version does not break up HTML tags, URLs or unicode references.
| } }
/** * DEPRECATED! Please use other alternatives. * * @deprecated * @param string $message
|
*
|
*
|
* @param string The string to be word wrapped * @return string The word wraped string
| * @return string
|
*/ function my_wordwrap($message) {
|
*/ function my_wordwrap($message) {
|
global $mybb;
if($mybb->settings['wordwrap'] > 0) { $message = convert_through_utf8($message);
if(!($new_message = @preg_replace("#(((?>[^\s&/<>\"\\-\[\]])|(&\#[a-z0-9]{1,10};)){{$mybb->settings['wordwrap']}})#u", "$0​", $message))) { $new_message = preg_replace("#(((?>[^\s&/<>\"\\-\[\]])|(&\#[a-z0-9]{1,10};)){{$mybb->settings['wordwrap']}})#", "$0​", $message); }
$new_message = convert_through_utf8($new_message, false);
return $new_message; }
| |
return $message;
|
return $message;
|
}
| }
|
/** * Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme) *
|
/** * Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme) *
|
* @param int The month of the birthday * @param int The day of the birthday * @param int The year of the bithday
| * @param int $month The month of the birthday * @param int $day The day of the birthday * @param int $year The year of the bithday
|
* @return int The numeric day of the week for the birthday */ function get_weekday($month, $day, $year)
| * @return int The numeric day of the week for the birthday */ function get_weekday($month, $day, $year)
|
Zeile 4899 | Zeile 5875 |
---|
for($k = 11; $k >= 0; $k--) { $l = ($k + 1);
|
for($k = 11; $k >= 0; $k--) { $l = ($k + 1);
|
|
|
for($m = $j[$k]; $m >= 1; $m--) { $h--;
if($i == $year && $l == $month && $m == $day)
|
for($m = $j[$k]; $m >= 1; $m--) { $h--;
if($i == $year && $l == $month && $m == $day)
|
{
| {
|
return $h;
|
return $h;
|
}
| }
|
if($h == 0) { $h = 7;
|
if($h == 0) { $h = 7;
|
} } } } }
| } } } } }
|
/** * Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme) *
|
/** * Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme) *
|
* @param int The year.
| * @param int $in The year.
|
* @return array The number of days in each month of that year */ function get_bdays($in)
| * @return array The number of days in each month of that year */ function get_bdays($in)
|
Zeile 4934 | Zeile 5910 |
---|
31, 30, 31,
|
31, 30, 31,
|
31, 30, 31,
| 31, 30, 31,
|
30, 31 ); }
/**
|
30, 31 ); }
/**
|
| * DEPRECATED! Please use mktime()!
|
* Formats a birthday appropriately *
|
* Formats a birthday appropriately *
|
* @param string The PHP date format string * @param int The month of the birthday * @param int The day of the birthday * @param int The year of the birthday * @param int The weekday of the birthday
| * @deprecated * @param string $display The PHP date format string * @param int $bm The month of the birthday * @param int $bd The day of the birthday * @param int $by The year of the birthday * @param int $wd The weekday of the birthday
|
* @return string The formatted birthday */ function format_bdays($display, $bm, $bd, $by, $wd)
| * @return string The formatted birthday */ function format_bdays($display, $bm, $bd, $by, $wd)
|
Zeile 4980 | Zeile 5958 |
---|
$lang->month_11, $lang->month_12 );
|
$lang->month_11, $lang->month_12 );
|
| |
// This needs to be in this specific order $find = array( 'm',
|
// This needs to be in this specific order $find = array( 'm',
|
| 'n',
|
'd', 'D', 'y',
| 'd', 'D', 'y',
|
Zeile 4998 | Zeile 5976 |
---|
$html = array( 'm',
|
$html = array( 'm',
|
| 'n',
|
'c', 'D', 'y',
| 'c', 'D', 'y',
|
Zeile 5014 | Zeile 5993 |
---|
$replace = array( sprintf('%02s', $bm),
|
$replace = array( sprintf('%02s', $bm),
|
| $bm,
|
sprintf('%02s', $bd), ($wd == 2 ? my_substr($bdays[$wd], 0, 4) : ($wd == 4 ? my_substr($bdays[$wd], 0, 5) : my_substr($bdays[$wd], 0, 3))), my_substr($by, 2),
| sprintf('%02s', $bd), ($wd == 2 ? my_substr($bdays[$wd], 0, 4) : ($wd == 4 ? my_substr($bdays[$wd], 0, 5) : my_substr($bdays[$wd], 0, 3))), my_substr($by, 2),
|
Zeile 5039 | Zeile 6019 |
---|
/** * Returns the age of a user with specified birthday. *
|
/** * Returns the age of a user with specified birthday. *
|
* @param string The birthday of a user. * @return float The age of a user with that birthday.
| * @param string $birthday The birthday of a user. * @return int The age of a user with that birthday.
|
*/ function get_age($birthday) {
| */ function get_age($birthday) {
|
Zeile 5064 | Zeile 6044 |
---|
/** * Updates the first posts in a thread. *
|
/** * Updates the first posts in a thread. *
|
* @param int The thread id for which to update the first post id.
| * @param int $tid The thread id for which to update the first post id.
|
*/ function update_first_post($tid) {
| */ function update_first_post($tid) {
|
Zeile 5075 | Zeile 6055 |
---|
FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) WHERE p.tid='$tid'
|
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
| ORDER BY p.dateline ASC, p.pid ASC
|
LIMIT 1 "); $firstpost = $db->fetch_array($query);
| LIMIT 1 "); $firstpost = $db->fetch_array($query);
|
Zeile 5098 | Zeile 6078 |
---|
/** * Updates the last posts in a thread. *
|
/** * Updates the last posts in a thread. *
|
* @param int The thread id for which to update the last post id.
| * @param int $tid The thread id for which to update the last post id.
|
*/ function update_last_post($tid) {
| */ function update_last_post($tid) {
|
Zeile 5109 | Zeile 6089 |
---|
FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) WHERE p.tid='$tid' AND p.visible='1'
|
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
| ORDER BY p.dateline DESC, p.pid DESC
|
LIMIT 1" ); $lastpost = $db->fetch_array($query);
|
LIMIT 1" ); $lastpost = $db->fetch_array($query);
|
| if(!$lastpost) { return false; }
|
if(empty($lastpost['username'])) {
| if(empty($lastpost['username'])) {
|
Zeile 5126 | Zeile 6111 |
---|
FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) WHERE p.tid='$tid'
|
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
| ORDER BY p.dateline ASC, p.pid ASC
|
LIMIT 1 "); $firstpost = $db->fetch_array($query);
| LIMIT 1 "); $firstpost = $db->fetch_array($query);
|
Zeile 5149 | Zeile 6134 |
---|
/** * Checks for the length of a string, mb strings accounted for *
|
/** * Checks for the length of a string, mb strings accounted for *
|
* @param string The string to check the length of.
| * @param string $string The string to check the length of.
|
* @return int The length of the string. */ function my_strlen($string)
| * @return int The length of the string. */ function my_strlen($string)
|
Zeile 5158 | Zeile 6143 |
---|
$string = preg_replace("#&\#([0-9]+);#", "-", $string);
|
$string = preg_replace("#&\#([0-9]+);#", "-", $string);
|
if(strtolower($lang->settings['charset']) == "utf-8")
| if(isset($lang->settings['charset']) && strtolower($lang->settings['charset']) == "utf-8")
|
{ // Get rid of any excess RTL and LTR override for they are the workings of the devil $string = str_replace(dec_to_utf8(8238), "", $string);
| { // Get rid of any excess RTL and LTR override for they are the workings of the devil $string = str_replace(dec_to_utf8(8238), "", $string);
|
Zeile 5184 | Zeile 6169 |
---|
/** * Cuts a string at a specified point, mb strings accounted for *
|
/** * Cuts a string at a specified point, mb strings accounted for *
|
* @param string The string to cut. * @param int Where to cut * @param int (optional) How much to cut * @param bool (optional) Properly handle HTML entities? * @return int The cut part of the string.
| * @param string $string The string to cut. * @param int $start Where to cut * @param int $length (optional) How much to cut * @param bool $handle_entities (optional) Properly handle HTML entities? * @return string The cut part of the string.
|
*/
|
*/
|
function my_substr($string, $start, $length="", $handle_entities = false)
| function my_substr($string, $start, $length=null, $handle_entities = false)
|
{ if($handle_entities) {
| { if($handle_entities) {
|
Zeile 5198 | Zeile 6183 |
---|
} if(function_exists("mb_substr")) {
|
} if(function_exists("mb_substr")) {
|
if($length != "")
| if($length != null)
|
{ $cut_string = mb_substr($string, $start, $length); }
| { $cut_string = mb_substr($string, $start, $length); }
|
Zeile 5209 | Zeile 6194 |
---|
} else {
|
} else {
|
if($length != "")
| if($length != null)
|
{ $cut_string = substr($string, $start, $length); }
| { $cut_string = substr($string, $start, $length); }
|
Zeile 5229 | Zeile 6214 |
---|
/** * Lowers the case of a string, mb strings accounted for *
|
/** * Lowers the case of a string, mb strings accounted for *
|
* @param string The string to lower. * @return int The lowered string.
| * @param string $string The string to lower. * @return string The lowered string.
|
*/ function my_strtolower($string) {
| */ function my_strtolower($string) {
|
Zeile 5244 | Zeile 6229 |
---|
}
return $string;
|
}
return $string;
|
| }
/** * Finds a needle in a haystack and returns it position, mb strings accounted for, case insensitive * * @param string $haystack String to look in (haystack) * @param string $needle What to look for (needle) * @param int $offset (optional) How much to offset * @return int|bool false on needle not found, integer position if found */ function my_stripos($haystack, $needle, $offset=0) { if($needle == '') { return false; }
if(function_exists("mb_stripos")) { $position = mb_stripos($haystack, $needle, $offset); } else { $position = stripos($haystack, $needle, $offset); }
return $position;
|
}
/** * Finds a needle in a haystack and returns it position, mb strings accounted for *
|
}
/** * Finds a needle in a haystack and returns it position, mb strings accounted for *
|
* @param string String to look in (haystack) * @param string What to look for (needle) * @param int (optional) How much to offset * @return int false on needle not found, integer position if found
| * @param string $haystack String to look in (haystack) * @param string $needle What to look for (needle) * @param int $offset (optional) How much to offset * @return int|bool false on needle not found, integer position if found
|
*/ function my_strpos($haystack, $needle, $offset=0) {
| */ function my_strpos($haystack, $needle, $offset=0) {
|
Zeile 5262 | Zeile 6274 |
---|
}
if(function_exists("mb_strpos"))
|
}
if(function_exists("mb_strpos"))
|
{ $position = mb_strpos($haystack, $needle, $offset); } else {
| { $position = mb_strpos($haystack, $needle, $offset); } else {
|
$position = strpos($haystack, $needle, $offset); }
| $position = strpos($haystack, $needle, $offset); }
|
Zeile 5276 | Zeile 6288 |
---|
/** * Ups the case of a string, mb strings accounted for *
|
/** * Ups the case of a string, mb strings accounted for *
|
* @param string The string to up. * @return int The uped string.
| * @param string $string The string to up. * @return string The uped string.
|
*/ function my_strtoupper($string) { if(function_exists("mb_strtoupper"))
|
*/ function my_strtoupper($string) { if(function_exists("mb_strtoupper"))
|
{
| {
|
$string = mb_strtoupper($string);
|
$string = mb_strtoupper($string);
|
}
| }
|
else { $string = strtoupper($string); }
|
else { $string = strtoupper($string); }
|
|
|
return $string; }
/** * Returns any html entities to their original character
|
return $string; }
/** * Returns any html entities to their original character
|
* * @param string The string to un-htmlentitize. * @return int The un-htmlentitied' string.
| * * @param string $string The string to un-htmlentitize. * @return string The un-htmlentitied' string.
|
*/ function unhtmlentities($string) { // Replace numeric entities
|
*/ function unhtmlentities($string) { // Replace numeric entities
|
$string = preg_replace_callback('~&#x([0-9a-f]+);~i', create_function('$matches', 'return unichr(hexdec($matches[1]));'), $string); $string = preg_replace_callback('~&#([0-9]+);~', create_function('$matches', 'return unichr($matches[1]);'), $string);
| $string = preg_replace_callback('~&#x([0-9a-f]+);~i', 'unichr_callback1', $string); $string = preg_replace_callback('~&#([0-9]+);~', 'unichr_callback2', $string);
|
// Replace literal entities $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl);
|
// Replace literal entities $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl);
|
|
|
return strtr($string, $trans_tbl);
|
return strtr($string, $trans_tbl);
|
}
/**
| }
/**
|
* Returns any ascii to it's character (utf-8 safe). *
|
* Returns any ascii to it's character (utf-8 safe). *
|
* @param string The ascii to characterize. * @return int The characterized ascii.
| * @param int $c The ascii to characterize. * @return string|bool The characterized ascii. False on failure
|
*/ function unichr($c) { if($c <= 0x7F)
|
*/ function unichr($c) { if($c <= 0x7F)
|
{
| {
|
return chr($c); } else if($c <= 0x7FF) { return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
|
return chr($c); } else if($c <= 0x7FF) { return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
|
}
| }
|
else if($c <= 0xFFFF) { return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
| else if($c <= 0xFFFF) { return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
|
Zeile 5343 | Zeile 6355 |
---|
{ return false; }
|
{ return false; }
|
| }
/** * Returns any ascii to it's character (utf-8 safe). * * @param array $matches Matches. * @return string|bool The characterized ascii. False on failure */ function unichr_callback1($matches) { return unichr(hexdec($matches[1])); }
/** * Returns any ascii to it's character (utf-8 safe). * * @param array $matches Matches. * @return string|bool The characterized ascii. False on failure */ function unichr_callback2($matches) { return unichr($matches[1]);
|
}
/** * Get the event poster. *
|
}
/** * Get the event poster. *
|
* @param array The event data array.
| * @param array $event The event data array.
|
* @return string The link to the event poster. */ function get_event_poster($event) {
|
* @return string The link to the event poster. */ function get_event_poster($event) {
|
| $event['username'] = htmlspecialchars_uni($event['username']);
|
$event['username'] = format_name($event['username'], $event['usergroup'], $event['displaygroup']); $event_poster = build_profile_link($event['username'], $event['author']); return $event_poster;
| $event['username'] = format_name($event['username'], $event['usergroup'], $event['displaygroup']); $event_poster = build_profile_link($event['username'], $event['author']); return $event_poster;
|
Zeile 5361 | Zeile 6396 |
---|
/** * Get the event date. *
|
/** * Get the event date. *
|
* @param array The event data array.
| * @param array $event The event data array.
|
* @return string The event date. */ function get_event_date($event)
| * @return string The event date. */ function get_event_date($event)
|
Zeile 5369 | Zeile 6404 |
---|
global $mybb;
$event_date = explode("-", $event['date']);
|
global $mybb;
$event_date = explode("-", $event['date']);
|
$event_date = mktime(0, 0, 0, $event_date[1], $event_date[0], $event_date[2]);
| $event_date = gmmktime(0, 0, 0, $event_date[1], $event_date[0], $event_date[2]);
|
$event_date = my_date($mybb->settings['dateformat'], $event_date);
return $event_date;
| $event_date = my_date($mybb->settings['dateformat'], $event_date);
return $event_date;
|
Zeile 5378 | Zeile 6413 |
---|
/** * Get the profile link. *
|
/** * Get the profile link. *
|
* @param int The user id of the profile.
| * @param int $uid The user id of the profile.
|
* @return string The url to the profile. */ function get_profile_link($uid=0) { $link = str_replace("{uid}", $uid, PROFILE_URL);
|
* @return string The url to the profile. */ function get_profile_link($uid=0) { $link = str_replace("{uid}", $uid, PROFILE_URL);
|
return htmlspecialchars_uni($link);
| return htmlspecialchars_uni($link);
|
}
/** * Get the announcement link. *
|
}
/** * Get the announcement link. *
|
* @param int The announement id of the announcement.
| * @param int $aid The announement id of the announcement.
|
* @return string The url to the announcement. */ function get_announcement_link($aid=0) { $link = str_replace("{aid}", $aid, ANNOUNCEMENT_URL); return htmlspecialchars_uni($link);
|
* @return string The url to the announcement. */ function get_announcement_link($aid=0) { $link = str_replace("{aid}", $aid, ANNOUNCEMENT_URL); return htmlspecialchars_uni($link);
|
}
| }
|
/** * Build the profile link. *
|
/** * Build the profile link. *
|
* @param string The Username of the profile. * @param int The user id of the profile. * @param string The target frame * @param string Any onclick javascript.
| * @param string $username The Username of the profile. * @param int $uid The user id of the profile. * @param string $target The target frame * @param string $onclick Any onclick javascript.
|
* @return string The complete profile link. */ function build_profile_link($username="", $uid=0, $target="", $onclick="")
| * @return string The complete profile link. */ function build_profile_link($username="", $uid=0, $target="", $onclick="")
|
Zeile 5415 | Zeile 6450 |
---|
if(!$username && $uid == 0) { // Return Guest phrase for no UID, no guest nickname
|
if(!$username && $uid == 0) { // Return Guest phrase for no UID, no guest nickname
|
return $lang->guest;
| return htmlspecialchars_uni($lang->guest);
|
} elseif($uid == 0) {
| } elseif($uid == 0) {
|
Zeile 5428 | Zeile 6463 |
---|
if(!empty($target)) { $target = " target=\"{$target}\"";
|
if(!empty($target)) { $target = " target=\"{$target}\"";
|
}
| }
|
if(!empty($onclick)) { $onclick = " onclick=\"{$onclick}\""; }
|
if(!empty($onclick)) { $onclick = " onclick=\"{$onclick}\""; }
|
|
|
return "<a href=\"{$mybb->settings['bburl']}/".get_profile_link($uid)."\"{$target}{$onclick}>{$username}</a>"; } }
/** * Build the forum link.
|
return "<a href=\"{$mybb->settings['bburl']}/".get_profile_link($uid)."\"{$target}{$onclick}>{$username}</a>"; } }
/** * Build the forum link.
|
* * @param int The forum id of the forum. * @param int (Optional) The page number of the forum.
| * * @param int $fid The forum id of the forum. * @param int $page (Optional) The page number of the forum.
|
* @return string The url to the forum. */ function get_forum_link($fid, $page=0)
| * @return string The url to the forum. */ function get_forum_link($fid, $page=0)
|
Zeile 5464 | Zeile 6499 |
---|
/** * Build the thread link. *
|
/** * Build the thread link. *
|
* @param int The thread id of the thread. * @param int (Optional) The page number of the thread. * @param string (Optional) The action we're performing (ex, lastpost, newpost, etc)
| * @param int $tid The thread id of the thread. * @param int $page (Optional) The page number of the thread. * @param string $action (Optional) The action we're performing (ex, lastpost, newpost, etc)
|
* @return string The url to the thread. */ function get_thread_link($tid, $page=0, $action='') { if($page > 1)
|
* @return string The url to the thread. */ function get_thread_link($tid, $page=0, $action='') { if($page > 1)
|
{
| {
|
if($action)
|
if($action)
|
{
| {
|
$link = THREAD_URL_ACTION; $link = str_replace("{action}", $action, $link);
|
$link = THREAD_URL_ACTION; $link = str_replace("{action}", $action, $link);
|
}
| }
|
else { $link = THREAD_URL_PAGED; } $link = str_replace("{tid}", $tid, $link); $link = str_replace("{page}", $page, $link);
|
else { $link = THREAD_URL_PAGED; } $link = str_replace("{tid}", $tid, $link); $link = str_replace("{page}", $page, $link);
|
return htmlspecialchars_uni($link); }
| return htmlspecialchars_uni($link); }
|
else { if($action)
| else { if($action)
|
Zeile 5498 | Zeile 6533 |
---|
$link = THREAD_URL; } $link = str_replace("{tid}", $tid, $link);
|
$link = THREAD_URL; } $link = str_replace("{tid}", $tid, $link);
|
return htmlspecialchars_uni($link); } }
/**
| return htmlspecialchars_uni($link); } }
/**
|
* Build the post link. *
|
* Build the post link. *
|
* @param int The post ID of the post * @param int The thread id of the post.
| * @param int $pid The post ID of the post * @param int $tid The thread id of the post.
|
* @return string The url to the post. */ function get_post_link($pid, $tid=0)
| * @return string The url to the post. */ function get_post_link($pid, $tid=0)
|
Zeile 5515 | Zeile 6550 |
---|
{ $link = str_replace("{tid}", $tid, THREAD_URL_POST); $link = str_replace("{pid}", $pid, $link);
|
{ $link = str_replace("{tid}", $tid, THREAD_URL_POST); $link = str_replace("{pid}", $pid, $link);
|
return htmlspecialchars_uni($link); } else {
| return htmlspecialchars_uni($link); } else {
|
$link = str_replace("{pid}", $pid, POST_URL); return htmlspecialchars_uni($link); }
| $link = str_replace("{pid}", $pid, POST_URL); return htmlspecialchars_uni($link); }
|
Zeile 5527 | Zeile 6562 |
---|
/** * Build the event link. *
|
/** * Build the event link. *
|
* @param int The event ID of the event
| * @param int $eid The event ID of the event
|
* @return string The URL of the event */ function get_event_link($eid)
| * @return string The URL of the event */ function get_event_link($eid)
|
Zeile 5539 | Zeile 6574 |
---|
/** * Build the link to a specified date on the calendar *
|
/** * Build the link to a specified date on the calendar *
|
* @param int The ID of the calendar * @param int The year * @param int The month * @param int The day (optional)
| * @param int $calendar The ID of the calendar * @param int $year The year * @param int $month The month * @param int $day The day (optional)
|
* @return string The URL of the calendar */ function get_calendar_link($calendar, $year=0, $month=0, $day=0)
| * @return string The URL of the calendar */ function get_calendar_link($calendar, $year=0, $month=0, $day=0)
|
Zeile 5576 | Zeile 6611 |
---|
/** * Build the link to a specified week on the calendar *
|
/** * Build the link to a specified week on the calendar *
|
* @param int The ID of the calendar * @param int The year * @param int The week
| * @param int $calendar The ID of the calendar * @param int $week The week
|
* @return string The URL of the calendar */ function get_calendar_week_link($calendar, $week)
| * @return string The URL of the calendar */ function get_calendar_week_link($calendar, $week)
|
Zeile 5595 | Zeile 6629 |
---|
/** * Get the user data of an user id. *
|
/** * Get the user data of an user id. *
|
* @param int The user id of the user.
| * @param int $uid The user id of the user.
|
* @return array The users data */ function get_user($uid)
| * @return array The users data */ function get_user($uid)
|
Zeile 5606 | Zeile 6640 |
---|
$uid = (int)$uid;
if(!empty($mybb->user) && $uid == $mybb->user['uid'])
|
$uid = (int)$uid;
if(!empty($mybb->user) && $uid == $mybb->user['uid'])
|
{
| {
|
return $mybb->user;
|
return $mybb->user;
|
}
| }
|
elseif(isset($user_cache[$uid]))
|
elseif(isset($user_cache[$uid]))
|
{ return $user_cache[$uid];
| { return $user_cache[$uid];
|
} elseif($uid > 0) {
| } elseif($uid > 0) {
|
Zeile 5619 | Zeile 6653 |
---|
$user_cache[$uid] = $db->fetch_array($query);
return $user_cache[$uid];
|
$user_cache[$uid] = $db->fetch_array($query);
return $user_cache[$uid];
|
}
| }
|
return array(); }
/** * Get the user data of an user username. *
|
return array(); }
/** * Get the user data of an user username. *
|
* @param string The user username of the user.
| * @param string $username The user username of the user. * @param array $options
|
* @return array The users data */ function get_user_by_username($username, $options=array()) { global $mybb, $db;
|
* @return array The users data */ function get_user_by_username($username, $options=array()) { global $mybb, $db;
|
$username = $db->escape_string(my_strtolower($username));
| $username = $db->escape_string(my_strtolower($username));
|
if(!isset($options['username_method']))
|
if(!isset($options['username_method']))
|
{
| {
|
$options['username_method'] = 0;
|
$options['username_method'] = 0;
|
| }
switch($db->type) { case 'mysql': case 'mysqli': $field = 'username'; $efield = 'email'; break; default: $field = 'LOWER(username)'; $efield = 'LOWER(email)'; break;
|
}
switch($options['username_method']) { case 1:
|
}
switch($options['username_method']) { case 1:
|
$sqlwhere = 'LOWER(email)=\''.$username.'\'';
| $sqlwhere = "{$efield}='{$username}'";
|
break; case 2:
|
break; case 2:
|
$sqlwhere = 'LOWER(username)=\''.$username.'\' OR LOWER(email)=\''.$username.'\'';
| $sqlwhere = "{$field}='{$username}' OR {$efield}='{$username}'";
|
break; default:
|
break; default:
|
$sqlwhere = 'LOWER(username)=\''.$username.'\'';
| $sqlwhere = "{$field}='{$username}'";
|
break; }
| break; }
|
Zeile 5659 | Zeile 6707 |
---|
$fields = array_merge((array)$options['fields'], $fields); }
|
$fields = array_merge((array)$options['fields'], $fields); }
|
$fields = array_flip($fields);
$query = $db->simple_select('users', implode(',', array_keys($fields)), $sqlwhere, array('limit' => 1));
| $query = $db->simple_select('users', implode(',', array_unique($fields)), $sqlwhere, array('limit' => 1));
|
if(isset($options['exists'])) { return (bool)$db->num_rows($query);
|
if(isset($options['exists'])) { return (bool)$db->num_rows($query);
|
}
| }
|
return $db->fetch_array($query); }
| return $db->fetch_array($query); }
|
Zeile 5674 | Zeile 6720 |
---|
/** * Get the forum of a specific forum id. *
|
/** * Get the forum of a specific forum id. *
|
* @param int The forum id of the forum. * @param int (Optional) If set to 1, will override the active forum status * @return array The database row of a forum.
| * @param int $fid The forum id of the forum. * @param int $active_override (Optional) If set to 1, will override the active forum status * @return array|bool The database row of a forum. False on failure
|
*/ function get_forum($fid, $active_override=0) { global $cache; static $forum_cache;
|
*/ function get_forum($fid, $active_override=0) { global $cache; static $forum_cache;
|
if(!isset($forum_cache) || is_array($forum_cache))
| if(!isset($forum_cache) || !is_array($forum_cache))
|
{ $forum_cache = $cache->read("forums"); }
| { $forum_cache = $cache->read("forums"); }
|
Zeile 5710 | Zeile 6756 |
---|
return $forum_cache[$fid]; }
|
return $forum_cache[$fid]; }
|
|
|
/** * Get the thread of a thread id. *
|
/** * Get the thread of a thread id. *
|
* @param int The thread id of the thread. * @param boolean Whether or not to recache the thread. * @return string The database row of the thread.
| * @param int $tid The thread id of the thread. * @param boolean $recache Whether or not to recache the thread. * @return array|bool The database row of the thread. False on failure
|
*/ function get_thread($tid, $recache = false) { global $db; static $thread_cache;
|
*/ function get_thread($tid, $recache = false) { global $db; static $thread_cache;
|
|
|
$tid = (int)$tid;
if(isset($thread_cache[$tid]) && !$recache)
|
$tid = (int)$tid;
if(isset($thread_cache[$tid]) && !$recache)
|
{
| {
|
return $thread_cache[$tid]; } else
| return $thread_cache[$tid]; } else
|
Zeile 5738 | Zeile 6784 |
---|
{ $thread_cache[$tid] = $thread; return $thread;
|
{ $thread_cache[$tid] = $thread; return $thread;
|
} else
| } else
|
{ $thread_cache[$tid] = false; return false;
| { $thread_cache[$tid] = false; return false;
|
Zeile 5750 | Zeile 6796 |
---|
/** * Get the post of a post id. *
|
/** * Get the post of a post id. *
|
* @param int The post id of the post. * @param boolean Whether or not to recache the post. * @param array An array of fields to gather from the database * @return string The database row of the post.
| * @param int $pid The post id of the post. * @return array|bool The database row of the post. False on failure
|
*/ function get_post($pid) {
| */ function get_post($pid) {
|
Zeile 5770 | Zeile 6814 |
---|
{ $query = $db->simple_select("posts", "*", "pid = '{$pid}'"); $post = $db->fetch_array($query);
|
{ $query = $db->simple_select("posts", "*", "pid = '{$pid}'"); $post = $db->fetch_array($query);
|
|
|
if($post)
|
if($post)
|
{
| {
|
$post_cache[$pid] = $post; return $post; }
| $post_cache[$pid] = $post; return $post; }
|
Zeile 5780 | Zeile 6824 |
---|
{ $post_cache[$pid] = false; return false;
|
{ $post_cache[$pid] = false; return false;
|
} } }
| } } }
|
/** * Get inactivate forums. *
| /** * Get inactivate forums. *
|
Zeile 5791 | Zeile 6835 |
---|
*/ function get_inactive_forums() {
|
*/ function get_inactive_forums() {
|
global $forum_cache, $cache, $inactiveforums;
| global $forum_cache, $cache;
|
if(!$forum_cache) { cache_forums();
|
if(!$forum_cache) { cache_forums();
|
}
| }
|
$inactive = array();
foreach($forum_cache as $fid => $forum)
| $inactive = array();
foreach($forum_cache as $fid => $forum)
|
Zeile 5814 | Zeile 6858 |
---|
} } }
|
} } }
|
$inactiveforums = implode(",", $inactive);
| $inactiveforums = implode(",", $inactive);
|
return $inactiveforums; }
| return $inactiveforums; }
|
Zeile 5822 | Zeile 6867 |
---|
/** * Checks to make sure a user has not tried to login more times than permitted *
|
/** * Checks to make sure a user has not tried to login more times than permitted *
|
* @param bool (Optional) Stop execution if it finds an error with the login. Default is True * @return bool Number of logins when success, false if failed.
| * @param bool $fatal (Optional) Stop execution if it finds an error with the login. Default is True * @return bool|int Number of logins when success, false if failed.
|
*/
|
*/
|
function login_attempt_check($fatal = true)
| function login_attempt_check($uid = 0, $fatal = true)
|
{
|
{
|
global $mybb, $lang, $session, $db;
if($mybb->settings['failedlogincount'] == 0) { return 1; } // Note: Number of logins is defaulted to 1, because using 0 seems to clear cookie data. Not really a problem as long as we account for 1 being default.
| global $mybb, $lang, $db;
|
|
|
// Use cookie if possible, otherwise use session // Find better solution to prevent clearing cookies $loginattempts = 0; $failedlogin = 0;
| $attempts = array(); $uid = (int)$uid; $now = TIME_NOW;
// Get this user's login attempts and eventual lockout, if a uid is provided if($uid > 0) { $query = $db->simple_select("users", "loginattempts, loginlockoutexpiry", "uid='{$uid}'", 1); $attempts = $db->fetch_array($query);
if($attempts['loginattempts'] <= 0) { return 0; } } // This user has a cookie lockout, show waiting time elseif(!empty($mybb->cookies['lockoutexpiry']) && $mybb->cookies['lockoutexpiry'] > $now) { if($fatal) { $secsleft = (int)($mybb->cookies['lockoutexpiry'] - $now); $hoursleft = floor($secsleft / 3600); $minsleft = floor(($secsleft / 60) % 60); $secsleft = floor($secsleft % 60);
error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft)); }
|
|
|
if(!empty($mybb->cookies['loginattempts'])) { $loginattempts = $mybb->cookies['loginattempts'];
| return false;
|
}
|
}
|
if(!empty($mybb->cookies['failedlogin']))
| if($mybb->settings['failedlogincount'] > 0 && isset($attempts['loginattempts']) && $attempts['loginattempts'] >= $mybb->settings['failedlogincount'])
|
{
|
{
|
$failedlogin = $mybb->cookies['failedlogin']; }
// Work out if the user has had more than the allowed number of login attempts if($loginattempts > $mybb->settings['failedlogincount']) { // If so, then we need to work out if they can try to login again // Some maths to work out how long they have left and display it to them $now = TIME_NOW;
if(empty($mybb->cookies['failedlogin'])) { $failedtime = $now;
| // Set the expiry dateline if not set yet if($attempts['loginlockoutexpiry'] == 0) { $attempts['loginlockoutexpiry'] = $now + ((int)$mybb->settings['failedlogintime'] * 60);
// Add a cookie lockout. This is used to prevent access to the login page immediately. // A deep lockout is issued if he tries to login into a locked out account my_setcookie('lockoutexpiry', $attempts['loginlockoutexpiry']);
$db->update_query("users", array( "loginlockoutexpiry" => $attempts['loginlockoutexpiry'] ), "uid='{$uid}'"); }
if(empty($mybb->cookies['lockoutexpiry'])) { $failedtime = $attempts['loginlockoutexpiry'];
|
} else {
|
} else {
|
$failedtime = $mybb->cookies['failedlogin'];
| $failedtime = $mybb->cookies['lockoutexpiry'];
|
}
|
}
|
$secondsleft = $mybb->settings['failedlogintime'] * 60 + $failedtime - $now; $hoursleft = floor($secondsleft / 3600); $minsleft = floor(($secondsleft / 60) % 60); $secsleft = floor($secondsleft % 60);
// This value will be empty the first time the user doesn't login in, set it if(empty($failedlogin))
| // Are we still locked out? if($attempts['loginlockoutexpiry'] > $now)
|
{
|
{
|
my_setcookie('failedlogin', $now);
| |
if($fatal) {
|
if($fatal) {
|
error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft)); }
| $secsleft = (int)($attempts['loginlockoutexpiry'] - $now); $hoursleft = floor($secsleft / 3600); $minsleft = floor(($secsleft / 60) % 60); $secsleft = floor($secsleft % 60);
|
|
|
return false; }
| error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft)); }
return false; } // Unlock if enough time has passed else {
|
|
|
// Work out if the user has waited long enough before letting them login again if($mybb->cookies['failedlogin'] < ($now - $mybb->settings['failedlogintime'] * 60)) { my_setcookie('loginattempts', 1); my_unsetcookie('failedlogin'); if($mybb->user['uid'] != 0) { $update_array = array( 'loginattempts' => 1 ); $db->update_query("users", $update_array, "uid = '{$mybb->user['uid']}'"); } return 1; } // Not waited long enough else if($mybb->cookies['failedlogin'] > ($now - $mybb->settings['failedlogintime'] * 60)) { if($fatal)
| if($uid > 0)
|
{
|
{
|
error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));
| $db->update_query("users", array( "loginattempts" => 0, "loginlockoutexpiry" => 0 ), "uid='{$uid}'");
|
}
|
}
|
return false; } }
| // Wipe the cookie, no matter if a guest or a member my_unsetcookie('lockoutexpiry');
return 0; } }
if(!isset($attempts['loginattempts'])) { $attempts['loginattempts'] = 0; }
|
// User can attempt another login
|
// User can attempt another login
|
return $loginattempts;
| return $attempts['loginattempts'];
|
}
/** * Validates the format of an email address. *
|
}
/** * Validates the format of an email address. *
|
* @param string The string to check.
| * @param string $email The string to check.
|
* @return boolean True when valid, false when invalid. */ function validate_email_format($email) {
|
* @return boolean True when valid, false when invalid. */ function validate_email_format($email) {
|
if(strpos($email, ' ') !== false) { return false; } // Valid local characters for email addresses: http://www.remote.org/jochen/mail/info/chars.html return preg_match("/^[a-zA-Z0-9&*+\-_.{}~^\?=\/]+@[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,}$/si", $email);
| return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
|
}
/** * Checks to see if the email is already in use by another *
|
}
/** * Checks to see if the email is already in use by another *
|
* @param string The email to check. * @param string User ID of the user (updating only)
| * @param string $email The email to check. * @param int $uid User ID of the user (updating only)
|
* @return boolean True when in use, false when not. */
|
* @return boolean True when in use, false when not. */
|
function email_already_in_use($email, $uid="")
| function email_already_in_use($email, $uid=0)
|
{ global $db;
| { global $db;
|
Zeile 5948 | Zeile 7002 |
---|
$query = $db->simple_select("users", "COUNT(email) as emails", "email = '".$db->escape_string($email)."'{$uid_string}");
if($db->fetch_field($query, "emails") > 0)
|
$query = $db->simple_select("users", "COUNT(email) as emails", "email = '".$db->escape_string($email)."'{$uid_string}");
if($db->fetch_field($query, "emails") > 0)
|
{
| {
|
return true; }
| return true; }
|
Zeile 5963 | Zeile 7017 |
---|
{ global $db, $mybb;
|
{ global $db, $mybb;
|
if(!file_exists(MYBB_ROOT."inc/settings.php")) { $mode = "x"; } else { $mode = "w"; }
$options = array( "order_by" => "title", "order_dir" => "ASC" ); $query = $db->simple_select("settings", "value, name", "", $options);
| $query = $db->simple_select("settings", "value, name", "", array( 'order_by' => 'title', 'order_dir' => 'ASC', ));
|
|
|
$settings = null;
| $settings = '';
|
while($setting = $db->fetch_array($query)) { $mybb->settings[$setting['name']] = $setting['value'];
|
while($setting = $db->fetch_array($query)) { $mybb->settings[$setting['name']] = $setting['value'];
|
| $setting['name'] = addcslashes($setting['name'], "\\'");
|
$setting['value'] = addcslashes($setting['value'], '\\"$'); $settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n"; }
|
$setting['value'] = addcslashes($setting['value'], '\\"$'); $settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n"; }
|
|
|
$settings = "<"."?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n";
|
$settings = "<"."?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n";
|
$file = @fopen(MYBB_ROOT."inc/settings.php", $mode); @fwrite($file, $settings); @fclose($file);
| file_put_contents(MYBB_ROOT.'inc/settings.php', $settings, LOCK_EX);
|
$GLOBALS['settings'] = &$mybb->settings; }
|
$GLOBALS['settings'] = &$mybb->settings; }
|
|
|
/** * Build a PREG compatible array of search highlight terms to replace in posts. *
|
/** * Build a PREG compatible array of search highlight terms to replace in posts. *
|
* @param string Incoming terms to highlight
| * @param string $terms Incoming terms to highlight
|
* @return array PREG compatible array of terms */ function build_highlight_array($terms) { global $mybb;
|
* @return array PREG compatible array of terms */ function build_highlight_array($terms) { global $mybb;
|
|
|
if($mybb->settings['minsearchword'] < 1) { $mybb->settings['minsearchword'] = 3;
| if($mybb->settings['minsearchword'] < 1) { $mybb->settings['minsearchword'] = 3;
|
Zeile 6023 | Zeile 7068 |
---|
"~" ); $terms = str_replace($bad_characters, '', $terms);
|
"~" ); $terms = str_replace($bad_characters, '', $terms);
|
| $words = array();
|
// Check if this is a "series of words" - should be treated as an EXACT match if(my_strpos($terms, "\"") !== false) { $inquote = false; $terms = explode("\"", $terms);
|
// Check if this is a "series of words" - should be treated as an EXACT match if(my_strpos($terms, "\"") !== false) { $inquote = false; $terms = explode("\"", $terms);
|
$words = array();
| |
foreach($terms as $phrase) { $phrase = htmlspecialchars_uni($phrase);
| foreach($terms as $phrase) { $phrase = htmlspecialchars_uni($phrase);
|
Zeile 6057 | Zeile 7102 |
---|
} } $inquote = !$inquote;
|
} } $inquote = !$inquote;
|
} }
| } }
|
// Otherwise just a simple search query with no phrases else {
| // Otherwise just a simple search query with no phrases else {
|
Zeile 6074 | Zeile 7119 |
---|
} $words[] = trim($word); }
|
} $words[] = trim($word); }
|
} }
if(!is_array($words)) { return false;
| }
|
}
|
}
|
|
|
// Sort the word array by length. Largest terms go first and work their way down to the smallest term. // This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html
|
// Sort the word array by length. Largest terms go first and work their way down to the smallest term. // This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html
|
usort($words, create_function('$a,$b', 'return strlen($b) - strlen($a);'));
| usort($words, 'build_highlight_array_sort');
$highlight_cache = array();
|
// Loop through our words to build the PREG compatible strings foreach($words as $word)
|
// Loop through our words to build the PREG compatible strings foreach($words as $word)
|
{
| {
|
$word = trim($word);
$word = my_strtolower($word);
| $word = trim($word);
$word = my_strtolower($word);
|
Zeile 6100 | Zeile 7142 |
---|
}
// Now make PREG compatible
|
}
// Now make PREG compatible
|
$find = "#(?!<.*?)(".preg_quote($word, "#").")(?![^<>]*?>)#ui"; $replacement = "<span class=\"highlight\" style=\"padding-left: 0px; padding-right: 0px;\">$1</span>";
| $find = "/(?<!&|&#)\b([[:alnum:]]*)(".preg_quote($word, "/").")(?![^<>]*?>)/ui"; $replacement = "$1<span class=\"highlight\" style=\"padding-left: 0px; padding-right: 0px;\">$2</span>";
|
$highlight_cache[$find] = $replacement; }
return $highlight_cache;
|
$highlight_cache[$find] = $replacement; }
return $highlight_cache;
|
| }
/** * Sort the word array by length. Largest terms go first and work their way down to the smallest term. * * @param string $a First word. * @param string $b Second word. * @return integer Result of comparison function. */ function build_highlight_array_sort($a, $b) { return strlen($b) - strlen($a);
|
}
/** * Converts a decimal reference of a character to its UTF-8 equivalent * (Code by Anne van Kesteren, http://annevankesteren.nl/2005/05/character-references) *
|
}
/** * Converts a decimal reference of a character to its UTF-8 equivalent * (Code by Anne van Kesteren, http://annevankesteren.nl/2005/05/character-references) *
|
* @param string Decimal value of a character reference
| * @param int $src Decimal value of a character reference * @return string|bool
|
*/ function dec_to_utf8($src) {
| */ function dec_to_utf8($src) {
|
Zeile 6127 | Zeile 7182 |
---|
$dest .= chr($src); } elseif($src <= 0x07ff)
|
$dest .= chr($src); } elseif($src <= 0x07ff)
|
{
| {
|
$dest .= chr(0xc0 | ($src >> 6));
|
$dest .= chr(0xc0 | ($src >> 6));
|
$dest .= chr(0x80 | ($src & 0x003f));
| $dest .= chr(0x80 | ($src & 0x003f));
|
} elseif($src <= 0xffff) { $dest .= chr(0xe0 | ($src >> 12)); $dest .= chr(0x80 | (($src >> 6) & 0x003f)); $dest .= chr(0x80 | ($src & 0x003f));
|
} elseif($src <= 0xffff) { $dest .= chr(0xe0 | ($src >> 12)); $dest .= chr(0x80 | (($src >> 6) & 0x003f)); $dest .= chr(0x80 | ($src & 0x003f));
|
}
| }
|
elseif($src <= 0x10ffff) { $dest .= chr(0xf0 | ($src >> 18));
| elseif($src <= 0x10ffff) { $dest .= chr(0xf0 | ($src >> 18));
|
Zeile 6156 | Zeile 7211 |
---|
/** * Checks if a username has been disallowed for registration/use. *
|
/** * Checks if a username has been disallowed for registration/use. *
|
* @param string The username * @param boolean True if the 'last used' dateline should be updated if a match is found.
| * @param string $username The username * @param boolean $update_lastuse True if the 'last used' dateline should be updated if a match is found.
|
* @return boolean True if banned, false if not banned */ function is_banned_username($username, $update_lastuse=false)
| * @return boolean True if banned, false if not banned */ function is_banned_username($username, $update_lastuse=false)
|
Zeile 6185 | Zeile 7240 |
---|
/** * Check if a specific email address has been banned. *
|
/** * Check if a specific email address has been banned. *
|
* @param string The email address. * @param boolean True if the 'last used' dateline should be updated if a match is found.
| * @param string $email The email address. * @param boolean $update_lastuse True if the 'last used' dateline should be updated if a match is found.
|
* @return boolean True if banned, false if not banned */ function is_banned_email($email, $update_lastuse=false)
| * @return boolean True if banned, false if not banned */ function is_banned_email($email, $update_lastuse=false)
|
Zeile 6228 | Zeile 7283 |
---|
/** * Checks if a specific IP address has been banned. *
|
/** * Checks if a specific IP address has been banned. *
|
* @param string The IP address. * @param boolean True if the 'last used' dateline should be updated if a match is found.
| * @param string $ip_address The IP address. * @param boolean $update_lastuse True if the 'last used' dateline should be updated if a match is found.
|
* @return boolean True if banned, false if not banned. */ function is_banned_ip($ip_address, $update_lastuse=false)
| * @return boolean True if banned, false if not banned. */ function is_banned_ip($ip_address, $update_lastuse=false)
|
Zeile 6255 | Zeile 7310 |
---|
$ip_range = fetch_ip_range($banned_ip['filter']); if(is_array($ip_range)) {
|
$ip_range = fetch_ip_range($banned_ip['filter']); if(is_array($ip_range)) {
|
if(strcmp($ip_range[0], $ip_address) >= 0 && strcmp($ip_range[1], $ip_address) <= 0)
| if(strcmp($ip_range[0], $ip_address) <= 0 && strcmp($ip_range[1], $ip_address) >= 0)
|
{ $banned = true; }
| { $banned = true; }
|
Zeile 6280 | Zeile 7335 |
---|
}
/**
|
}
/**
|
* Build a time zone selection list.
| * Returns an array of supported timezones
|
*
|
*
|
* @param string The name of the select * @param int The selected time zone (defaults to GMT) * @param boolean True to generate a "short" list with just timezone and current time
| * @return string[] Key is timezone offset, Value the language description
|
*/
|
*/
|
function build_timezone_select($name, $selected=0, $short=false)
| function get_supported_timezones()
|
{
|
{
|
global $mybb, $lang, $templates;
| global $lang;
|
$timezones = array( "-12" => $lang->timezone_gmt_minus_1200, "-11" => $lang->timezone_gmt_minus_1100,
| $timezones = array( "-12" => $lang->timezone_gmt_minus_1200, "-11" => $lang->timezone_gmt_minus_1100,
|
Zeile 6320 | Zeile 7372 |
---|
"6.5" => $lang->timezone_gmt_650, "7" => $lang->timezone_gmt_700, "8" => $lang->timezone_gmt_800,
|
"6.5" => $lang->timezone_gmt_650, "7" => $lang->timezone_gmt_700, "8" => $lang->timezone_gmt_800,
|
| "8.5" => $lang->timezone_gmt_850, "8.75" => $lang->timezone_gmt_875,
|
"9" => $lang->timezone_gmt_900, "9.5" => $lang->timezone_gmt_950, "10" => $lang->timezone_gmt_1000,
| "9" => $lang->timezone_gmt_900, "9.5" => $lang->timezone_gmt_950, "10" => $lang->timezone_gmt_1000,
|
Zeile 6331 | Zeile 7385 |
---|
"13" => $lang->timezone_gmt_1300, "14" => $lang->timezone_gmt_1400 );
|
"13" => $lang->timezone_gmt_1300, "14" => $lang->timezone_gmt_1400 );
|
| return $timezones; }
/** * Build a time zone selection list. * * @param string $name The name of the select * @param int $selected The selected time zone (defaults to GMT) * @param boolean $short True to generate a "short" list with just timezone and current time * @return string */ function build_timezone_select($name, $selected=0, $short=false) { global $mybb, $lang, $templates;
$timezones = get_supported_timezones();
|
$selected = str_replace("+", "", $selected);
|
$selected = str_replace("+", "", $selected);
|
| $timezone_option = '';
|
foreach($timezones as $timezone => $label) { $selected_add = "";
| foreach($timezones as $timezone => $label) { $selected_add = "";
|
Zeile 6347 | Zeile 7418 |
---|
{ $label = $timezone; if($timezone > 0)
|
{ $label = $timezone; if($timezone > 0)
|
{
| {
|
$label = "+{$label}"; } if(strpos($timezone, ".") !== false)
|
$label = "+{$label}"; } if(strpos($timezone, ".") !== false)
|
{
| {
|
$label = str_replace(".", ":", $label); $label = str_replace(":5", ":30", $label); $label = str_replace(":75", ":45", $label);
|
$label = str_replace(".", ":", $label); $label = str_replace(":5", ":30", $label); $label = str_replace(":75", ":45", $label);
|
}
| }
|
else { $label .= ":00";
| else { $label .= ":00";
|
Zeile 6363 | Zeile 7434 |
---|
} $time_in_zone = my_date($mybb->settings['timeformat'], TIME_NOW, $timezone); $label = $lang->sprintf($lang->timezone_gmt_short, $label." ", $time_in_zone);
|
} $time_in_zone = my_date($mybb->settings['timeformat'], TIME_NOW, $timezone); $label = $lang->sprintf($lang->timezone_gmt_short, $label." ", $time_in_zone);
|
}
| }
|
eval("\$timezone_option .= \"".$templates->get("usercp_options_timezone_option")."\";"); }
| eval("\$timezone_option .= \"".$templates->get("usercp_options_timezone_option")."\";"); }
|
Zeile 6373 | Zeile 7444 |
---|
}
/**
|
}
/**
|
* Fetch the contents of a remote fle.
| * Fetch the contents of a remote file.
|
*
|
*
|
* @param string The URL of the remote file * @param array The array of post data * @return string The remote file contents.
| * @param string $url The URL of the remote file * @param array $post_data The array of post data * @param int $max_redirects Number of maximum redirects * @return string|bool The remote file contents. False on failure
|
*/
|
*/
|
function fetch_remote_file($url, $post_data=array())
| function fetch_remote_file($url, $post_data=array(), $max_redirects=20)
|
{
|
{
|
| global $mybb, $config;
if(!my_validate_url($url, true)) { return false; }
$url_components = @parse_url($url);
if(!isset($url_components['scheme'])) { $url_components['scheme'] = 'https'; } if(!isset($url_components['port'])) { $url_components['port'] = $url_components['scheme'] == 'https' ? 443 : 80; }
if( !$url_components || empty($url_components['host']) || (!empty($url_components['scheme']) && !in_array($url_components['scheme'], array('http', 'https'))) || (!in_array($url_components['port'], array(80, 8080, 443))) || (!empty($config['disallowed_remote_hosts']) && in_array($url_components['host'], $config['disallowed_remote_hosts'])) ) { return false; }
$addresses = get_ip_by_hostname($url_components['host']); $destination_address = $addresses[0];
if(!empty($config['disallowed_remote_addresses'])) { foreach($config['disallowed_remote_addresses'] as $disallowed_address) { $ip_range = fetch_ip_range($disallowed_address);
$packed_address = my_inet_pton($destination_address);
if(is_array($ip_range)) { if(strcmp($ip_range[0], $packed_address) <= 0 && strcmp($ip_range[1], $packed_address) >= 0) { return false; } } elseif($destination_address == $disallowed_address) { return false; } } }
|
$post_body = ''; if(!empty($post_data)) {
| $post_body = ''; if(!empty($post_data)) {
|
Zeile 6392 | Zeile 7518 |
---|
}
if(function_exists("curl_init"))
|
}
if(function_exists("curl_init"))
|
{
| { $fetch_header = $max_redirects > 0;
|
$ch = curl_init();
|
$ch = curl_init();
|
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
| $curlopt = array( CURLOPT_URL => $url, CURLOPT_HEADER => $fetch_header, CURLOPT_TIMEOUT => 10, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 0, );
if($ca_bundle_path = get_ca_bundle_path()) { $curlopt[CURLOPT_SSL_VERIFYPEER] = 1; $curlopt[CURLOPT_CAINFO] = $ca_bundle_path; } else { $curlopt[CURLOPT_SSL_VERIFYPEER] = 0; }
$curl_version_info = curl_version(); $curl_version = $curl_version_info['version'];
if(version_compare(PHP_VERSION, '7.0.7', '>=') && version_compare($curl_version, '7.49', '>=')) { // CURLOPT_CONNECT_TO $curlopt[10243] = array( $url_components['host'].':'.$url_components['port'].':'.$destination_address ); } elseif(version_compare(PHP_VERSION, '5.5', '>=') && version_compare($curl_version, '7.21.3', '>=')) { // CURLOPT_RESOLVE $curlopt[10203] = array( $url_components['host'].':'.$url_components['port'].':'.$destination_address ); }
if(defined('CURLOPT_DISALLOW_USERNAME_IN_URL')) { $curlopt[CURLOPT_DISALLOW_USERNAME_IN_URL] = true; }
|
if(!empty($post_body)) {
|
if(!empty($post_body)) {
|
curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);
| $curlopt[CURLOPT_POST] = 1; $curlopt[CURLOPT_POSTFIELDS] = $post_body; }
curl_setopt_array($ch, $curlopt);
$response = curl_exec($ch);
if($fetch_header) { $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size);
if(in_array(curl_getinfo($ch, CURLINFO_HTTP_CODE), array(301, 302))) { preg_match('/^Location:(.*?)(?:\n|$)/im', $header, $matches);
if($matches) { $data = fetch_remote_file(trim(array_pop($matches)), $post_data, --$max_redirects); } } else { $data = $body; } } else { $data = $response;
|
}
|
}
|
$data = curl_exec($ch);
|
|
curl_close($ch); return $data; } else if(function_exists("fsockopen")) {
|
curl_close($ch); return $data; } else if(function_exists("fsockopen")) {
|
$url = @parse_url($url); if(!$url['host']) { return false; } if(!$url['port'])
| if(!isset($url_components['path']))
|
{
|
{
|
$url['port'] = 80;
| $url_components['path'] = "/";
|
}
|
}
|
if(!$url['path'])
| if(isset($url_components['query']))
|
{
|
{
|
$url['path'] = "/";
| $url_components['path'] .= "?{$url_components['query']}";
|
}
|
}
|
if($url['query'])
| $scheme = '';
if($url_components['scheme'] == 'https') { $scheme = 'ssl://'; if($url_components['port'] == 80) { $url_components['port'] = 443; } }
if(function_exists('stream_context_create')) { if($url_components['scheme'] == 'https' && $ca_bundle_path = get_ca_bundle_path()) { $context = stream_context_create(array( 'ssl' => array( 'verify_peer' => true, 'verify_peer_name' => true, 'peer_name' => $url_components['host'], 'cafile' => $ca_bundle_path, ), )); } else { $context = stream_context_create(array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'peer_name' => $url_components['host'], ), )); }
$fp = @stream_socket_client($scheme.$destination_address.':'.(int)$url_components['port'], $error_no, $error, 10, STREAM_CLIENT_CONNECT, $context); } else
|
{
|
{
|
$url['path'] .= "?{$url['query']}";
| $fp = @fsockopen($scheme.$url_components['host'], (int)$url_components['port'], $error_no, $error, 10);
|
}
|
}
|
$fp = @fsockopen($url['host'], $url['port'], $error_no, $error, 10); @stream_set_timeout($fp, 10);
|
|
if(!$fp) { return false; }
|
if(!$fp) { return false; }
|
| @stream_set_timeout($fp, 10);
|
$headers = array(); if(!empty($post_body)) {
|
$headers = array(); if(!empty($post_body)) {
|
$headers[] = "POST {$url['path']} HTTP/1.0";
| $headers[] = "POST {$url_components['path']} HTTP/1.0";
|
$headers[] = "Content-Length: ".strlen($post_body); $headers[] = "Content-Type: application/x-www-form-urlencoded"; } else {
|
$headers[] = "Content-Length: ".strlen($post_body); $headers[] = "Content-Type: application/x-www-form-urlencoded"; } else {
|
$headers[] = "GET {$url['path']} HTTP/1.0";
| $headers[] = "GET {$url_components['path']} HTTP/1.0";
|
}
|
}
|
$headers[] = "Host: {$url['host']}";
| $headers[] = "Host: {$url_components['host']}";
|
$headers[] = "Connection: Close"; $headers[] = '';
| $headers[] = "Connection: Close"; $headers[] = '';
|
Zeile 6463 | Zeile 7691 |
---|
{ return false; }
|
{ return false; }
|
| $data = null;
|
while(!feof($fp)) { $data .= fgets($fp, 12800); } fclose($fp);
|
while(!feof($fp)) { $data .= fgets($fp, 12800); } fclose($fp);
|
|
|
$data = explode("\r\n\r\n", $data, 2);
|
$data = explode("\r\n\r\n", $data, 2);
|
return $data[1]; } else if(empty($post_data)) { return @implode("", @file($url)); }
| $header = $data[0]; $status_line = current(explode("\n\n", $header, 1)); $body = $data[1];
if($max_redirects > 0 && (strstr($status_line, ' 301 ') || strstr($status_line, ' 302 '))) { preg_match('/^Location:(.*?)(?:\n|$)/im', $header, $matches);
if($matches) { $data = fetch_remote_file(trim(array_pop($matches)), $post_data, --$max_redirects); } } else { $data = $body; }
return $data; }
|
else
|
else
|
{
| {
|
return false; }
|
return false; }
|
| }
/** * Resolves a hostname into a set of IP addresses. * * @param string $hostname The hostname to be resolved * @return array|bool The resulting IP addresses. False on failure */ function get_ip_by_hostname($hostname) { $addresses = @gethostbynamel($hostname);
if(!$addresses) { $result_set = @dns_get_record($hostname, DNS_A | DNS_AAAA);
if($result_set) { $addresses = array_column($result_set, 'ip'); } else { return false; } }
return $addresses; }
/** * Returns the location of the CA bundle defined in the PHP configuration. * * @return string|bool The location of the CA bundle, false if not set */ function get_ca_bundle_path() { if($path = ini_get('openssl.cafile')) { return $path; } if($path = ini_get('curl.cainfo')) { return $path; }
return false;
|
}
/** * Checks if a particular user is a super administrator.
|
}
/** * Checks if a particular user is a super administrator.
|
* * @param int The user ID to check against the list of super admins
| * * @param int $uid The user ID to check against the list of super admins
|
* @return boolean True if a super admin, false if not */ function is_super_admin($uid)
| * @return boolean True if a super admin, false if not */ function is_super_admin($uid)
|
Zeile 6492 | Zeile 7785 |
---|
static $super_admins;
if(!isset($super_admins))
|
static $super_admins;
if(!isset($super_admins))
|
{
| {
|
global $mybb; $super_admins = str_replace(" ", "", $mybb->config['super_admins']); }
| global $mybb; $super_admins = str_replace(" ", "", $mybb->config['super_admins']); }
|
Zeile 6512 | Zeile 7805 |
---|
* Originates from frostschutz's PluginLibrary * github.com/frostschutz *
|
* Originates from frostschutz's PluginLibrary * github.com/frostschutz *
|
* @param mixed A selection of groups to check * @param mixed User to check selection against * @return mixed Array of groups this user belongs to
| * @param array|int|string A selection of groups (as array or comma seperated) to check or -1 for any group * @param bool|array|int False assumes the current user. Otherwise an user array or an id can be passed * @return array Array of groups specified in the first param to which the user belongs
|
*/ function is_member($groups, $user = false) { global $mybb;
|
*/ function is_member($groups, $user = false) { global $mybb;
|
if($user == false)
| if(empty($groups)) { return array(); }
if($user == false)
|
{ $user = $mybb->user; }
| { $user = $mybb->user; }
|
Zeile 6535 | Zeile 7833 |
---|
if(!is_array($groups)) {
|
if(!is_array($groups)) {
|
if(is_string($groups))
| if((int)$groups == -1)
|
{
|
{
|
$groups = explode(',', $groups);
| return $memberships;
|
} else {
|
} else {
|
$groups = (array)$groups;
| if(is_string($groups)) { $groups = explode(',', $groups); } else { $groups = (array)$groups; }
|
} }
| } }
|
Zeile 6554 | Zeile 7859 |
---|
* Split a string based on the specified delimeter, ignoring said delimeter in escaped strings. * Ex: the "quick brown fox" jumped, could return 1 => the, 2 => quick brown fox, 3 => jumped *
|
* Split a string based on the specified delimeter, ignoring said delimeter in escaped strings. * Ex: the "quick brown fox" jumped, could return 1 => the, 2 => quick brown fox, 3 => jumped *
|
* @param string The delimeter to split by * @param string The string to split * @param string The escape character or string if we have one.
| * @param string $delimeter The delimeter to split by * @param string $string The string to split * @param string $escape The escape character or string if we have one.
|
* @return array Array of split string */ function escaped_explode($delimeter, $string, $escape="")
| * @return array Array of split string */ function escaped_explode($delimeter, $string, $escape="")
|
Zeile 6615 | Zeile 7920 |
---|
* DEPRECATED! Please use IPv6 compatible fetch_ip_range! * Fetch an IPv4 long formatted range for searching IPv4 IP addresses. *
|
* DEPRECATED! Please use IPv6 compatible fetch_ip_range! * Fetch an IPv4 long formatted range for searching IPv4 IP addresses. *
|
* @param string The IP address to convert to a range based LONG * @rturn mixed If a full IP address is provided, the ip2long equivalent, otherwise an array of the upper & lower extremities of the IP
| * @deprecated * @param string $ip The IP address to convert to a range based LONG * @return string|array If a full IP address is provided, the ip2long equivalent, otherwise an array of the upper & lower extremities of the IP
|
*/ function fetch_longipv4_range($ip) {
| */ function fetch_longipv4_range($ip) {
|
Zeile 6701 | Zeile 8007 |
---|
/** * Format a ban length in to a UNIX timestamp. *
|
/** * Format a ban length in to a UNIX timestamp. *
|
* @param string The ban length string * @param int The optional UNIX timestamp, if 0, current time is used.
| * @param string $date The ban length string * @param int $stamp The optional UNIX timestamp, if 0, current time is used.
|
* @return int The UNIX timestamp when the ban will be lifted */ function ban_date2timestamp($date, $stamp=0)
| * @return int The UNIX timestamp when the ban will be lifted */ function ban_date2timestamp($date, $stamp=0)
|
Zeile 6717 | Zeile 8023 |
---|
$n[1] += $d[0]; $n[2] += $d[1]; $n[3] += $d[2];
|
$n[1] += $d[0]; $n[2] += $d[1]; $n[3] += $d[2];
|
return mktime(date("G"), date("i"), 0, $n[2], $n[1], $n[3]);
| return mktime(date("G", $stamp), date("i", $stamp), 0, $n[2], $n[1], $n[3]);
|
}
/** * Expire old warnings in the database. *
|
}
/** * Expire old warnings in the database. *
|
| * @return bool
|
*/ function expire_warnings() {
| */ function expire_warnings() {
|
Zeile 6740 | Zeile 8047 |
---|
/** * Custom chmod function to fix problems with hosts who's server configurations screw up umasks *
|
/** * Custom chmod function to fix problems with hosts who's server configurations screw up umasks *
|
* @param string The file to chmod * @param string The mode to chmod(i.e. 0666)
| * @param string $file The file to chmod * @param string $mode The mode to chmod(i.e. 0666) * @return bool
|
*/ function my_chmod($file, $mode) {
| */ function my_chmod($file, $mode) {
|
Zeile 6762 | Zeile 8070 |
---|
/** * Custom rmdir function to loop through an entire directory and delete all files/folders within *
|
/** * Custom rmdir function to loop through an entire directory and delete all files/folders within *
|
* @param string The path to the directory * @param array Any files you wish to ignore (optional)
| * @param string $path The path to the directory * @param array $ignore Any files you wish to ignore (optional) * @return bool
|
*/ function my_rmdir_recursive($path, $ignore=array()) {
| */ function my_rmdir_recursive($path, $ignore=array()) {
|
Zeile 6803 | Zeile 8112 |
---|
/** * Counts the number of subforums in a array([pid][disporder][fid]) starting from the pid *
|
/** * Counts the number of subforums in a array([pid][disporder][fid]) starting from the pid *
|
* @param array The array of forums
| * @param array $array The array of forums
|
* @return integer The number of sub forums */
|
* @return integer The number of sub forums */
|
function subforums_count($array)
| function subforums_count($array=array())
|
{ $count = 0; foreach($array as $array2)
| { $count = 0; foreach($array as $array2)
|
Zeile 6822 | Zeile 8131 |
---|
* Fix for PHP's ip2long to guarantee a 32-bit signed integer value is produced (this is aimed * at 64-bit versions of PHP) *
|
* Fix for PHP's ip2long to guarantee a 32-bit signed integer value is produced (this is aimed * at 64-bit versions of PHP) *
|
* @param string The IP to convert
| * @deprecated * @param string $ip The IP to convert
|
* @return integer IP in 32-bit signed format */ function my_ip2long($ip)
| * @return integer IP in 32-bit signed format */ function my_ip2long($ip)
|
Zeile 6851 | Zeile 8161 |
---|
* DEPRECATED! Please use IPv6 compatible my_inet_ntop! * As above, fix for PHP's long2ip on 64-bit versions *
|
* DEPRECATED! Please use IPv6 compatible my_inet_ntop! * As above, fix for PHP's long2ip on 64-bit versions *
|
* @param integer The IP to convert (will accept 64-bit IPs as well)
| * @deprecated * @param integer $long The IP to convert (will accept 64-bit IPs as well)
|
* @return string IP in IPv4 format */ function my_long2ip($long)
| * @return string IP in IPv4 format */ function my_long2ip($long)
|
Zeile 6868 | Zeile 8179 |
---|
/** * Converts a human readable IP address to its packed in_addr representation *
|
/** * Converts a human readable IP address to its packed in_addr representation *
|
* @param string The IP to convert
| * @param string $ip The IP to convert
|
* @return string IP in 32bit or 128bit binary format */ function my_inet_pton($ip)
| * @return string IP in 32bit or 128bit binary format */ function my_inet_pton($ip)
|
Zeile 6921 | Zeile 8232 |
---|
/** * Converts a packed internet address to a human readable representation *
|
/** * Converts a packed internet address to a human readable representation *
|
* @param string IP in 32bit or 128bit binary format
| * @param string $ip IP in 32bit or 128bit binary format
|
* @return string IP in human readable format */ function my_inet_ntop($ip)
| * @return string IP in human readable format */ function my_inet_ntop($ip)
|
Zeile 6963 | Zeile 8274 |
---|
/** * Fetch an binary formatted range for searching IPv4 and IPv6 IP addresses. *
|
/** * Fetch an binary formatted range for searching IPv4 and IPv6 IP addresses. *
|
* @param string The IP address to convert to a range * @rturn mixed If a full IP address is provided, the in_addr representation, otherwise an array of the upper & lower extremities of the IP
| * @param string $ipaddress The IP address to convert to a range * @return string|array|bool If a full IP address is provided, the in_addr representation, otherwise an array of the upper & lower extremities of the IP. False on failure
|
*/ function fetch_ip_range($ipaddress) {
| */ function fetch_ip_range($ipaddress) {
|
Zeile 6980 | Zeile 8291 |
---|
else { // IPv4
|
else { // IPv4
|
| $ip_bits = count(explode('.', $ipaddress)); if($ip_bits < 4) { // Support for 127.0.* $replacement = str_repeat('.*', 4-$ip_bits); $ipaddress = substr_replace($ipaddress, $replacement, strrpos($ipaddress, '*')+1, 0); }
|
$upper = str_replace('*', '255', $ipaddress); $lower = str_replace('*', '0', $ipaddress);
|
$upper = str_replace('*', '255', $ipaddress); $lower = str_replace('*', '0', $ipaddress);
|
}
| }
|
$upper = my_inet_pton($upper); $lower = my_inet_pton($lower); if($upper === false || $lower === false)
|
$upper = my_inet_pton($upper); $lower = my_inet_pton($lower); if($upper === false || $lower === false)
|
{ return false; }
| { return false; }
|
return array($lower, $upper); } // CIDR notation
| return array($lower, $upper); } // CIDR notation
|
Zeile 6999 | Zeile 8317 |
---|
$ip_range = (int)$ipaddress[1];
if(empty($ip_address) || empty($ip_range))
|
$ip_range = (int)$ipaddress[1];
if(empty($ip_address) || empty($ip_range))
|
{
| {
|
// Invalid input return false; }
| // Invalid input return false; }
|
Zeile 7032 | Zeile 8350 |
---|
$bit = decbin(ord($ip_pack[$i])); $bit = str_pad($bit, 8, '0', STR_PAD_LEFT); $ip_bits .= $bit;
|
$bit = decbin(ord($ip_pack[$i])); $bit = str_pad($bit, 8, '0', STR_PAD_LEFT); $ip_bits .= $bit;
|
}
| }
|
// Significative bits (from the ip range) $ip_bits = substr($ip_bits, 0, $ip_range);
|
// Significative bits (from the ip range) $ip_bits = substr($ip_bits, 0, $ip_range);
|
|
|
// Some calculations $ip_lower_bits = str_pad($ip_bits, $ip_bits_size, '0', STR_PAD_RIGHT); $ip_higher_bits = str_pad($ip_bits, $ip_bits_size, '1', STR_PAD_RIGHT);
// Lower IP $ip_lower_pack = '';
|
// Some calculations $ip_lower_bits = str_pad($ip_bits, $ip_bits_size, '0', STR_PAD_RIGHT); $ip_higher_bits = str_pad($ip_bits, $ip_bits_size, '1', STR_PAD_RIGHT);
// Lower IP $ip_lower_pack = '';
|
for($i=0; $i < $ip_bits_size; $i=$i+8)
| for($i=0; $i < $ip_bits_size; $i=$i+8)
|
{ $chr = substr($ip_lower_bits, $i, 8); $chr = chr(bindec($chr));
| { $chr = substr($ip_lower_bits, $i, 8); $chr = chr(bindec($chr));
|
Zeile 7065 | Zeile 8383 |
---|
else { return my_inet_pton($ipaddress);
|
else { return my_inet_pton($ipaddress);
|
} }
/**
| } }
/**
|
* Time how long it takes for a particular piece of code to run. Place calls above & below the block of code. * * @return float The time taken
| * Time how long it takes for a particular piece of code to run. Place calls above & below the block of code. * * @return float The time taken
|
Zeile 7078 | Zeile 8396 |
---|
static $time_start;
$time = microtime(true);
|
static $time_start;
$time = microtime(true);
|
|
|
// Just starting timer, init and return if(!$time_start) {
| // Just starting timer, init and return if(!$time_start) {
|
Zeile 7099 | Zeile 8416 |
---|
/** * Processes a checksum list on MyBB files and returns a result set *
|
/** * Processes a checksum list on MyBB files and returns a result set *
|
* @param array The array of checksums and their corresponding files * @param int The count of files
| * @param string $path The base path * @param int $count The count of files
|
* @return array The bad files */ function verify_files($path=MYBB_ROOT, $count=0)
| * @return array The bad files */ function verify_files($path=MYBB_ROOT, $count=0)
|
Zeile 7108 | Zeile 8425 |
---|
global $mybb, $checksums, $bad_verify_files;
// We don't need to check these types of files
|
global $mybb, $checksums, $bad_verify_files;
// We don't need to check these types of files
|
$ignore = array(".", "..", ".svn", "config.php", "settings.php", "Thumb.db", "config.default.php", "lock", "htaccess.txt", "logo.gif", "logo.png");
| $ignore = array(".", "..", ".svn", "config.php", "settings.php", "Thumb.db", "config.default.php", "lock", "htaccess.txt", "htaccess-nginx.txt", "logo.gif", "logo.png");
|
$ignore_ext = array("attach");
if(substr($path, -1, 1) == "/") { $path = substr($path, 0, -1);
|
$ignore_ext = array("attach");
if(substr($path, -1, 1) == "/") { $path = substr($path, 0, -1);
|
}
| }
|
if(!is_array($bad_verify_files)) { $bad_verify_files = array();
| if(!is_array($bad_verify_files)) { $bad_verify_files = array();
|
Zeile 7149 | Zeile 8466 |
---|
{ $filename = $path."/".$file; $handle = fopen($filename, "rb");
|
{ $filename = $path."/".$file; $handle = fopen($filename, "rb");
|
$contents = '';
| $hashingContext = hash_init('sha512');
|
while(!feof($handle)) {
|
while(!feof($handle)) {
|
$contents .= fread($handle, 8192);
| hash_update($hashingContext, fread($handle, 8192));
|
} fclose($handle);
|
} fclose($handle);
|
$md5 = md5($contents);
| $checksum = hash_final($hashingContext);
|
// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)
|
// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)
|
if(!in_array($md5, $checksums[$file_path]))
| if(!in_array($checksum, $checksums[$file_path]))
|
{ $bad_verify_files[] = array("status" => "changed", "path" => $file_path);
|
{ $bad_verify_files[] = array("status" => "changed", "path" => $file_path);
|
} }
| } }
|
unset($checksums[$file_path]); } @closedir($dh);
| unset($checksums[$file_path]); } @closedir($dh);
|
Zeile 7175 | Zeile 8492 |
---|
if(!empty($checksums)) { foreach($checksums as $file_path => $hashes)
|
if(!empty($checksums)) { foreach($checksums as $file_path => $hashes)
|
{
| {
|
if(in_array(basename($file_path), $ignore)) { continue;
| if(in_array(basename($file_path), $ignore)) { continue;
|
Zeile 7195 | Zeile 8512 |
---|
/** * Returns a signed value equal to an integer *
|
/** * Returns a signed value equal to an integer *
|
* @param int The integer
| * @param int $int The integer
|
* @return string The signed equivalent */ function signed($int)
| * @return string The signed equivalent */ function signed($int)
|
Zeile 7209 | Zeile 8526 |
---|
return "+$int"; } }
|
return "+$int"; } }
|
|
|
/**
|
/**
|
* Returns a securely generated seed for PHP's RNG (Random Number Generator)
| * Returns a securely generated seed
|
*
|
*
|
* @param int Length of the seed bytes (8 is default. Provides good cryptographic variance) * @return int An integer equivalent of a secure hexadecimal seed
| * @return string A secure binary seed
|
*/
|
*/
|
function secure_seed_rng($count=8)
| function secure_binary_seed_rng($bytes)
|
{
|
{
|
$output = ''; // DIRECTORY_SEPARATOR checks if running windows if(DIRECTORY_SEPARATOR != '\\') { // Unix/Linux // Use OpenSSL when available if(function_exists('openssl_random_pseudo_bytes')) { $output = openssl_random_pseudo_bytes($count); } // Try mcrypt elseif(function_exists('mcrypt_create_iv')) { $output = mcrypt_create_iv($count, MCRYPT_DEV_URANDOM); } // Try /dev/urandom elseif(@is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb'))) { $output = @fread($handle, $count); @fclose($handle); }
| $output = null;
if(version_compare(PHP_VERSION, '7.0', '>=')) { try { $output = random_bytes($bytes); } catch (Exception $e) { }
|
}
|
}
|
else
| if(strlen($output) < $bytes)
|
{
|
{
|
// Windows // Use OpenSSL when available // PHP <5.3.4 had a bug which makes that function unusable on Windows if(function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>='))
| if(@is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb')))
|
{
|
{
|
$output = openssl_random_pseudo_bytes($count); } // Try mcrypt elseif(function_exists('mcrypt_create_iv')) { $output = mcrypt_create_iv($count, MCRYPT_RAND);
| $output = @fread($handle, $bytes); @fclose($handle);
|
}
|
}
|
// Try Windows CAPICOM before using our own generator elseif(class_exists('COM'))
| } else { return $output; }
if(strlen($output) < $bytes) { if(function_exists('mcrypt_create_iv')) { if (DIRECTORY_SEPARATOR == '/') { $source = MCRYPT_DEV_URANDOM; } else { $source = MCRYPT_RAND; }
$output = @mcrypt_create_iv($bytes, $source); } } else { return $output; }
if(strlen($output) < $bytes) { if(function_exists('openssl_random_pseudo_bytes')) { // PHP <5.3.4 had a bug which makes that function unusable on Windows if ((DIRECTORY_SEPARATOR == '/') || version_compare(PHP_VERSION, '5.3.4', '>=')) { $output = openssl_random_pseudo_bytes($bytes, $crypto_strong); if ($crypto_strong == false) { $output = null; } } } } else { return $output; }
if(strlen($output) < $bytes) { if(class_exists('COM'))
|
{ try { $CAPI_Util = new COM('CAPICOM.Utilities.1'); if(is_callable(array($CAPI_Util, 'GetRandom'))) {
|
{ try { $CAPI_Util = new COM('CAPICOM.Utilities.1'); if(is_callable(array($CAPI_Util, 'GetRandom'))) {
|
$output = $CAPI_Util->GetRandom($count, 0);
| $output = $CAPI_Util->GetRandom($bytes, 0);
|
} } catch (Exception $e) { } }
|
} } catch (Exception $e) { } }
|
| } else { return $output;
|
}
|
}
|
// Didn't work? Do we still not have enough bytes? Use our own (less secure) rng generator if(strlen($output) < $count)
| if(strlen($output) < $bytes)
|
{
|
{
|
$output = '';
| |
// Close to what PHP basically uses internally to seed, but not quite. $unique_state = microtime().@getmypid();
|
// Close to what PHP basically uses internally to seed, but not quite. $unique_state = microtime().@getmypid();
|
for($i = 0; $i < $count; $i += 16)
| $rounds = ceil($bytes / 16);
for($i = 0; $i < $rounds; $i++)
|
{ $unique_state = md5(microtime().$unique_state);
|
{ $unique_state = md5(microtime().$unique_state);
|
$output .= pack('H*', md5($unique_state)); } }
| $output .= md5($unique_state); }
$output = substr($output, 0, ($bytes * 2));
|
|
|
// /dev/urandom and openssl will always be twice as long as $count. base64_encode will roughly take up 33% more space but crc32 will put it to 32 characters $output = hexdec(substr(dechex(crc32(base64_encode($output))), 0, $count));
| $output = pack('H*', $output);
|
|
|
return $output;
| return $output; } else { return $output; }
|
}
/**
|
}
/**
|
* Wrapper function for mt_rand. Automatically seeds using a secure seed once.
| * Returns a securely generated seed integer
|
*
|
*
|
* @param int Optional lowest value to be returned (default: 0) * @param int Optional highest value to be returned (default: mt_getrandmax()) * @param boolean True forces it to reseed the RNG first
| |
* @return int An integer equivalent of a secure hexadecimal seed
|
* @return int An integer equivalent of a secure hexadecimal seed
|
*/ function my_rand($min=null, $max=null, $force_seed=false) { static $seeded = false; static $obfuscator = 0;
if($seeded == false || $force_seed == true) { mt_srand(secure_seed_rng()); $seeded = true;
$obfuscator = abs((int) secure_seed_rng());
// Ensure that $obfuscator is <= mt_getrandmax() for 64 bit systems. if($obfuscator > mt_getrandmax()) { $obfuscator -= mt_getrandmax(); } }
if($min !== null && $max !== null) { $distance = $max - $min; if($distance > 0) { return $min + (int)((float)($distance + 1) * (float)(mt_rand() ^ $obfuscator) / (mt_getrandmax() + 1)); } else
| */ function secure_seed_rng() { $bytes = PHP_INT_SIZE;
do {
$output = secure_binary_seed_rng($bytes);
// convert binary data to a decimal number if ($bytes == 4) { $elements = unpack('i', $output); $output = abs($elements[1]); } else { $elements = unpack('N2', $output); $output = abs($elements[1] << 32 | $elements[2]); }
} while($output > PHP_INT_MAX);
return $output; }
/** * Generates a cryptographically secure random number. * * @param int $min Optional lowest value to be returned (default: 0) * @param int $max Optional highest value to be returned (default: PHP_INT_MAX) */ function my_rand($min=0, $max=PHP_INT_MAX) { // backward compatibility if($min === null || $max === null || $max < $min) { $min = 0; $max = PHP_INT_MAX; }
if(version_compare(PHP_VERSION, '7.0', '>=')) { try { $result = random_int($min, $max); } catch (Exception $e) { }
if(isset($result))
|
{
|
{
|
return mt_rand($min, $max);
| return $result;
|
} }
|
} }
|
else { $val = mt_rand() ^ $obfuscator; return $val; }
| $seed = secure_seed_rng();
$distance = $max - $min; return $min + floor($distance * ($seed / PHP_INT_MAX) );
|
}
/**
|
}
/**
|
* More robust version of PHP's trim() function. It includes a list of UTF-16 blank characters
| * More robust version of PHP's trim() function. It includes a list of UTF-8 blank characters
|
* from http://kb.mozillazine.org/Network.IDN.blacklist_chars *
|
* from http://kb.mozillazine.org/Network.IDN.blacklist_chars *
|
* @param string The string to trim from * @param string Optional. The stripped characters can also be specified using the charlist parameter
| * @param string $string The string to trim from * @param string $charlist Optional. The stripped characters can also be specified using the charlist parameter
|
* @return string The trimmed string */
|
* @return string The trimmed string */
|
function trim_blank_chrs($string, $charlist=false)
| function trim_blank_chrs($string, $charlist="")
|
{ $hex_chrs = array(
|
{ $hex_chrs = array(
|
0x20 => 1, 0x09 => 1, 0x0A => 1, 0x0D => 1, 0x0B => 1, 0xAD => 1, 0xA0 => 1, 0xAD => 1, 0xBF => 1, 0x81 => 1, 0x8D => 1, 0x90 => 1, 0x9D => 1, 0xCC => array(0xB7 => 1, 0xB8 => 1), // \x{0337} or \x{0338} 0xE1 => array(0x85 => array(0x9F => 1, 0xA0 => 1)), // \x{115F} or \x{1160} 0xE2 => array(0x80 => array(0x80 => 1, 0x81 => 1, 0x82 => 1, 0x83 => 1, 0x84 => 1, 0x85 => 1, 0x86 => 1, 0x87 => 1, 0x88 => 1, 0x89 => 1, 0x8A => 1, 0x8B => 1, // \x{2000} to \x{200B} 0xA8 => 1, 0xA9 => 1, 0xAA => 1, 0xAB => 1, 0xAC => 1, 0xAD => 1, 0xAE => 1, 0xAF => 1), // \x{2028} to \x{202F} 0x81 => array(0x9F => 1)), // \x{205F}
| 0x09 => 1, // \x{0009} 0x0A => 1, // \x{000A} 0x0B => 1, // \x{000B} 0x0D => 1, // \x{000D} 0x20 => 1, // \x{0020} 0xC2 => array(0x81 => 1, 0x8D => 1, 0x90 => 1, 0x9D => 1, 0xA0 => 1, 0xAD => 1), // \x{0081}, \x{008D}, \x{0090}, \x{009D}, \x{00A0}, \x{00AD} 0xCC => array(0xB7 => 1, 0xB8 => 1), // \x{0337}, \x{0338} 0xE1 => array(0x85 => array(0x9F => 1, 0xA0 => 1), 0x9A => array(0x80 => 1), 0xA0 => array(0x8E => 1)), // \x{115F}, \x{1160}, \x{1680}, \x{180E} 0xE2 => array(0x80 => array(0x80 => 1, 0x81 => 1, 0x82 => 1, 0x83 => 1, 0x84 => 1, 0x85 => 1, 0x86 => 1, 0x87 => 1, 0x88 => 1, 0x89 => 1, 0x8A => 1, 0x8B => 1, 0x8C => 1, 0x8D => 1, 0x8E => 1, 0x8F => 1, // \x{2000} - \x{200F} 0xA8 => 1, 0xA9 => 1, 0xAA => 1, 0xAB => 1, 0xAC => 1, 0xAD => 1, 0xAE => 1, 0xAF => 1), // \x{2028} - \x{202F} 0x81 => array(0x9F => 1)), // \x{205F}
|
0xE3 => array(0x80 => array(0x80 => 1), // \x{3000}
|
0xE3 => array(0x80 => array(0x80 => 1), // \x{3000}
|
0x85 => array(0xA4 => 1)), // \x{3164}
| 0x85 => array(0xA4 => 1)), // \x{3164}
|
0xEF => array(0xBB => array(0xBF => 1), // \x{FEFF}
|
0xEF => array(0xBB => array(0xBF => 1), // \x{FEFF}
|
0xBE => array(0xA0 => 1), // \x{FFA0} 0xBF => array(0xB9 => 1, 0xBA => 1, 0xBB => 1)), // \x{FFF9} to \x{FFFB}
| 0xBE => array(0xA0 => 1), // \x{FFA0} 0xBF => array(0xB9 => 1, 0xBA => 1, 0xBB => 1)), // \x{FFF9} - \x{FFFB}
|
);
$hex_chrs_rev = array(
|
);
$hex_chrs_rev = array(
|
0x20 => 1, 0x09 => 1, 0x0A => 1, 0x0D => 1, 0x0B => 1, 0xA0 => array(0xC2 => 1), 0xAD => array(0xC2 => 1), 0xBF => array(0xC2 => 1), 0x81 => array(0xC2 => 1), 0x8D => array(0xC2 => 1), 0x90 => array(0xC2 => 1), 0x9D => array(0xC2 => 1),
| 0x09 => 1, // \x{0009} 0x0A => 1, // \x{000A} 0x0B => 1, // \x{000B} 0x0D => 1, // \x{000D} 0x20 => 1, // \x{0020} 0x81 => array(0xC2 => 1, 0x80 => array(0xE2 => 1)), // \x{0081}, \x{2001} 0x8D => array(0xC2 => 1, 0x80 => array(0xE2 => 1)), // \x{008D}, \x{200D} 0x90 => array(0xC2 => 1), // \x{0090} 0x9D => array(0xC2 => 1), // \x{009D} 0xA0 => array(0xC2 => 1, 0x85 => array(0xE1 => 1), 0x81 => array(0xE2 => 1), 0xBE => array(0xEF => 1)), // \x{00A0}, \x{1160}, \x{2060}, \x{FFA0} 0xAD => array(0xC2 => 1, 0x80 => array(0xE2 => 1)), // \x{00AD}, \x{202D}
|
0xB8 => array(0xCC => 1), // \x{0338} 0xB7 => array(0xCC => 1), // \x{0337}
|
0xB8 => array(0xCC => 1), // \x{0338} 0xB7 => array(0xCC => 1), // \x{0337}
|
0xA0 => array(0x85 => array(0xE1 => 1)), // \x{1160} 0x9F => array(0x85 => array(0xE1 => 1), // \x{115F} 0x81 => array(0xE2 => 1)), // \x{205F} 0x80 => array(0x80 => array(0xE3 => 1, 0xE2 => 1)), // \x{3000}, \x{2000} 0x81 => array(0x80 => array(0xE2 => 1)), // \x{2001}
| 0x9F => array(0x85 => array(0xE1 => 1), 0x81 => array(0xE2 => 1)), // \x{115F}, \x{205F} 0x80 => array(0x9A => array(0xE1 => 1), 0x80 => array(0xE2 => 1, 0xE3 => 1)), // \x{1680}, \x{2000}, \x{3000} 0x8E => array(0xA0 => array(0xE1 => 1), 0x80 => array(0xE2 => 1)), // \x{180E}, \x{200E}
|
0x82 => array(0x80 => array(0xE2 => 1)), // \x{2002} 0x83 => array(0x80 => array(0xE2 => 1)), // \x{2003} 0x84 => array(0x80 => array(0xE2 => 1)), // \x{2004}
| 0x82 => array(0x80 => array(0xE2 => 1)), // \x{2002} 0x83 => array(0x80 => array(0xE2 => 1)), // \x{2003} 0x84 => array(0x80 => array(0xE2 => 1)), // \x{2004}
|
Zeile 7402 | Zeile 8766 |
---|
0x89 => array(0x80 => array(0xE2 => 1)), // \x{2009} 0x8A => array(0x80 => array(0xE2 => 1)), // \x{200A} 0x8B => array(0x80 => array(0xE2 => 1)), // \x{200B}
|
0x89 => array(0x80 => array(0xE2 => 1)), // \x{2009} 0x8A => array(0x80 => array(0xE2 => 1)), // \x{200A} 0x8B => array(0x80 => array(0xE2 => 1)), // \x{200B}
|
| 0x8C => array(0x80 => array(0xE2 => 1)), // \x{200C} 0x8F => array(0x80 => array(0xE2 => 1)), // \x{200F}
|
0xA8 => array(0x80 => array(0xE2 => 1)), // \x{2028} 0xA9 => array(0x80 => array(0xE2 => 1)), // \x{2029} 0xAA => array(0x80 => array(0xE2 => 1)), // \x{202A} 0xAB => array(0x80 => array(0xE2 => 1)), // \x{202B} 0xAC => array(0x80 => array(0xE2 => 1)), // \x{202C}
|
0xA8 => array(0x80 => array(0xE2 => 1)), // \x{2028} 0xA9 => array(0x80 => array(0xE2 => 1)), // \x{2029} 0xAA => array(0x80 => array(0xE2 => 1)), // \x{202A} 0xAB => array(0x80 => array(0xE2 => 1)), // \x{202B} 0xAC => array(0x80 => array(0xE2 => 1)), // \x{202C}
|
0xAD => array(0x80 => array(0xE2 => 1)), // \x{202D}
| |
0xAE => array(0x80 => array(0xE2 => 1)), // \x{202E} 0xAF => array(0x80 => array(0xE2 => 1)), // \x{202F} 0xA4 => array(0x85 => array(0xE3 => 1)), // \x{3164} 0xBF => array(0xBB => array(0xEF => 1)), // \x{FEFF}
|
0xAE => array(0x80 => array(0xE2 => 1)), // \x{202E} 0xAF => array(0x80 => array(0xE2 => 1)), // \x{202F} 0xA4 => array(0x85 => array(0xE3 => 1)), // \x{3164} 0xBF => array(0xBB => array(0xEF => 1)), // \x{FEFF}
|
0xA0 => array(0xBE => array(0xEF => 1)), // \x{FFA0}
| |
0xB9 => array(0xBF => array(0xEF => 1)), // \x{FFF9} 0xBA => array(0xBF => array(0xEF => 1)), // \x{FFFA} 0xBB => array(0xBF => array(0xEF => 1)), // \x{FFFB} );
// Start from the beginning and work our way in
|
0xB9 => array(0xBF => array(0xEF => 1)), // \x{FFF9} 0xBA => array(0xBF => array(0xEF => 1)), // \x{FFFA} 0xBB => array(0xBF => array(0xEF => 1)), // \x{FFFB} );
// Start from the beginning and work our way in
|
| $i = 0;
|
do {
|
do {
|
// Check to see if we have matched a first character in our utf-16 array
| // Check to see if we have matched a first character in our utf-8 array
|
$offset = match_sequence($string, $hex_chrs); if(!$offset) {
| $offset = match_sequence($string, $hex_chrs); if(!$offset) {
|
Zeile 7434 | Zeile 8799 |
---|
// Start from the end and work our way in $string = strrev($string);
|
// Start from the end and work our way in $string = strrev($string);
|
| $i = 0;
|
do {
|
do {
|
// Check to see if we have matched a first character in our utf-16 array
| // Check to see if we have matched a first character in our utf-8 array
|
$offset = match_sequence($string, $hex_chrs_rev); if(!$offset)
|
$offset = match_sequence($string, $hex_chrs_rev); if(!$offset)
|
{
| {
|
// If not, then we must have a "good" character and we don't need to do anymore processing break; }
| // If not, then we must have a "good" character and we don't need to do anymore processing break; }
|
Zeile 7448 | Zeile 8814 |
---|
while(++$i); $string = strrev($string);
|
while(++$i); $string = strrev($string);
|
if($charlist !== false)
| if($charlist)
|
{ $string = trim($string, $charlist); }
| { $string = trim($string, $charlist); }
|
Zeile 7463 | Zeile 8829 |
---|
/** * Match a sequence *
|
/** * Match a sequence *
|
* @param string The string to match from * @param array The array to match from * @param int Number in the string * @param int Number of matches
| * @param string $string The string to match from * @param array $array The array to match from * @param int $i Number in the string * @param int $n Number of matches
|
* @return int The number matched */ function match_sequence($string, $array, $i=0, $n=0)
| * @return int The number matched */ function match_sequence($string, $array, $i=0, $n=0)
|
Zeile 7487 | Zeile 8853 |
---|
return match_sequence($string, $level, $i, $n); } return $n;
|
return match_sequence($string, $level, $i, $n); } return $n;
|
}
| }
|
return 0; }
| return 0; }
|
Zeile 7495 | Zeile 8861 |
---|
/** * Obtain the version of GD installed. *
|
/** * Obtain the version of GD installed. *
|
* @return float Version of GD
| * @return float|null Version of GD
|
*/ function gd_version() {
| */ function gd_version() {
|
Zeile 7505 | Zeile 8871 |
---|
{ return $gd_version; }
|
{ return $gd_version; }
|
|
|
if(!extension_loaded('gd')) {
|
if(!extension_loaded('gd')) {
|
return;
| return null;
|
}
if(function_exists("gd_info"))
| }
if(function_exists("gd_info"))
|
Zeile 7532 | Zeile 8899 |
---|
/* * Validates an UTF-8 string.
|
/* * Validates an UTF-8 string.
|
* * @param string The string to be checked * @param boolean Allow 4 byte UTF-8 characters? * @param boolean Return the cleaned string? * @return string/boolean Cleaned string or boolean */
| * * @param string $input The string to be checked * @param boolean $allow_mb4 Allow 4 byte UTF-8 characters? * @param boolean $return Return the cleaned string? * @return string|boolean Cleaned string or boolean */
|
function validate_utf8_string($input, $allow_mb4=true, $return=true) { // Valid UTF-8 sequence?
| function validate_utf8_string($input, $allow_mb4=true, $return=true) { // Valid UTF-8 sequence?
|
Zeile 7546 | Zeile 8913 |
---|
$string = ''; $len = strlen($input); for($i = 0; $i < $len; $i++)
|
$string = ''; $len = strlen($input); for($i = 0; $i < $len; $i++)
|
{
| {
|
$c = ord($input[$i]); if($c > 128) {
| $c = ord($input[$i]); if($c > 128) {
|
Zeile 7556 | Zeile 8923 |
---|
{ $string .= '?'; continue;
|
{ $string .= '?'; continue;
|
} else
| } else
|
{ return false; }
|
{ return false; }
|
}
| }
|
elseif($c > 239)
|
elseif($c > 239)
|
{
| {
|
$bytes = 4;
|
$bytes = 4;
|
} elseif($c > 223) { $bytes = 3;
| } elseif($c > 223) { $bytes = 3;
|
} elseif($c > 191) {
| } elseif($c > 191) {
|
Zeile 7624 | Zeile 8991 |
---|
$input = $string; } if($return)
|
$input = $string; } if($return)
|
{ if($allow_mb4) {
| { if($allow_mb4) {
|
return $input;
|
return $input;
|
}
| }
|
else { return preg_replace("#[^\\x00-\\x7F][\\x80-\\xBF]{3,}#", '?', $input);
| else { return preg_replace("#[^\\x00-\\x7F][\\x80-\\xBF]{3,}#", '?', $input);
|
Zeile 7637 | Zeile 9004 |
---|
else { if($allow_mb4)
|
else { if($allow_mb4)
|
{
| {
|
return true; } else
| return true; } else
|
Zeile 7650 | Zeile 9017 |
---|
/** * Send a Private Message to a user. *
|
/** * Send a Private Message to a user. *
|
* @param array Array containing: 'subject', 'message', 'touid' and 'receivepms' (the latter should reflect the value found in the users table: receivepms and receivefrombuddy) * @param int Sender UID (0 if you want to use $mybb->user['uid'] or -1 to use MyBB Engine) * @param bool Whether or not do override user defined options for receiving PMs
| * @param array $pm Array containing: 'subject', 'message', 'touid' and 'receivepms' (the latter should reflect the value found in the users table: receivepms and receivefrombuddy) * @param int $fromid Sender UID (0 if you want to use $mybb->user['uid'] or -1 to use MyBB Engine) * @param bool $admin_override Whether or not do override user defined options for receiving PMs
|
* @return bool True if PM sent */ function send_pm($pm, $fromid = 0, $admin_override=false)
| * @return bool True if PM sent */ function send_pm($pm, $fromid = 0, $admin_override=false)
|
Zeile 7660 | Zeile 9027 |
---|
global $lang, $mybb, $db, $session;
if($mybb->settings['enablepms'] == 0)
|
global $lang, $mybb, $db, $session;
if($mybb->settings['enablepms'] == 0)
|
{ return false; }
| { return false; }
|
if(!is_array($pm)) {
| if(!is_array($pm)) {
|
Zeile 7682 | Zeile 9049 |
---|
foreach(array('subject', 'message') as $key) {
|
foreach(array('subject', 'message') as $key) {
|
$lang_string = $pm[$key];
| |
if(is_array($pm[$key])) {
|
if(is_array($pm[$key])) {
|
| $lang_string = $lang->{$pm[$key][0]};
|
$num_args = count($pm[$key]);
for($i = 1; $i < $num_args; $i++) {
|
$num_args = count($pm[$key]);
for($i = 1; $i < $num_args; $i++) {
|
$lang->{$pm[$key][0]} = str_replace('{'.$i.'}', $pm[$key][$i], $lang->{$pm[$key][0]});
| $lang_string = str_replace('{'.$i.'}', $pm[$key][$i], $lang_string);
|
}
|
}
|
$lang_string = $pm[$key][0];
| } else { $lang_string = $lang->{$pm[$key]};
|
}
|
}
|
$pm[$key] = $lang->{$lang_string};
| $pm[$key] = $lang_string;
|
}
if(isset($revert))
| }
if(isset($revert))
|
Zeile 7706 | Zeile 9075 |
---|
} }
|
} }
|
if(!$pm['subject'] ||!$pm['message'] || !$pm['touid'] || (!$pm['receivepms'] && !$admin_override))
| if(empty($pm['subject']) || empty($pm['message']) || empty($pm['touid']) || (empty($pm['receivepms']) && !$admin_override))
|
{ return false; }
|
{ return false; }
|
$lang->load('messages');
require_once MYBB_ROOT."inc/datahandlers/pm.php";
| require_once MYBB_ROOT."inc/datahandlers/pm.php";
|
$pmhandler = new PMDataHandler();
$subject = $pm['subject'];
| $pmhandler = new PMDataHandler();
$subject = $pm['subject'];
|
Zeile 7723 | Zeile 9090 |
---|
// Our recipients if(is_array($toid))
|
// Our recipients if(is_array($toid))
|
{
| {
|
$recipients_to = $toid;
|
$recipients_to = $toid;
|
}
| }
|
else
|
else
|
{
| {
|
$recipients_to = array($toid);
|
$recipients_to = array($toid);
|
}
| }
|
$recipients_bcc = array();
|
$recipients_bcc = array();
|
| // Workaround for eliminating PHP warnings in PHP 8. Ref: https://github.com/mybb/mybb/issues/4630#issuecomment-1369144163 if(isset($pm['sender']['uid']) && $pm['sender']['uid'] === -1 && $fromid === -1) { $sender = array( "uid" => 0, "username" => '' ); }
|
// Determine user ID if((int)$fromid == 0)
| // Determine user ID if((int)$fromid == 0)
|
Zeile 7755 | Zeile 9131 |
---|
"pmid" => '' );
|
"pmid" => '' );
|
if(isset($session))
| // (continued) Workaround for eliminating PHP warnings in PHP 8. Ref: https://github.com/mybb/mybb/issues/4630#issuecomment-1369144163 if(isset($sender)) { $pm['sender'] = $sender; }
if(isset($session))
|
{ $pm['ipaddress'] = $session->packedip; }
|
{ $pm['ipaddress'] = $session->packedip; }
|
|
|
$pm['options'] = array(
|
$pm['options'] = array(
|
"signature" => 0,
| |
"disablesmilies" => 0, "savecopy" => 0, "readreceipt" => 0
|
"disablesmilies" => 0, "savecopy" => 0, "readreceipt" => 0
|
);
$pm['saveasdraft'] = 0;
| );
$pm['saveasdraft'] = 0;
|
// Admin override $pmhandler->admin_override = (int)$admin_override;
|
// Admin override $pmhandler->admin_override = (int)$admin_override;
|
|
|
$pmhandler->set_data($pm);
if($pmhandler->validate_pm()) { $pmhandler->insert_pm();
|
$pmhandler->set_data($pm);
if($pmhandler->validate_pm()) { $pmhandler->insert_pm();
|
return true; }
| return true; }
|
return false; }
| return false; }
|
Zeile 7788 | Zeile 9169 |
---|
* * @param string $username The username that the user was using. * @param string $email The email address the user was using.
|
* * @param string $username The username that the user was using. * @param string $email The email address the user was using.
|
* @param string $ip_address THe IP addres of the user.
| * @param string $ip_address The IP addres of the user.
|
* @param array $data An array of extra data to go with the block (eg: confidence rating). * @return bool Whether the action was logged successfully.
|
* @param array $data An array of extra data to go with the block (eg: confidence rating). * @return bool Whether the action was logged successfully.
|
*/
| */
|
function log_spam_block($username = '', $email = '', $ip_address = '', $data = array()) { global $db, $session;
| function log_spam_block($username = '', $email = '', $ip_address = '', $data = array()) { global $db, $session;
|
Zeile 7802 | Zeile 9183 |
---|
}
if(!$ip_address)
|
}
if(!$ip_address)
|
{
| {
|
$ip_address = get_ip();
|
$ip_address = get_ip();
|
$session->packedip; }
$ip_address = my_inet_pton($ip_address);
| }
$ip_address = my_inet_pton($ip_address);
|
$insert_array = array( 'username' => $db->escape_string($username), 'email' => $db->escape_string($email), 'ipaddress' => $db->escape_binary($ip_address), 'dateline' => (int)TIME_NOW,
|
$insert_array = array( 'username' => $db->escape_string($username), 'email' => $db->escape_string($email), 'ipaddress' => $db->escape_binary($ip_address), 'dateline' => (int)TIME_NOW,
|
'data' => $db->escape_string(@serialize($data)),
| 'data' => $db->escape_string(@my_serialize($data)),
|
);
|
);
|
return (bool)$db->insert_array('spamlog', $insert_array);
| return (bool)$db->insert_query('spamlog', $insert_array); }
/** * Copy a file to the CDN. * * @param string $file_path The path to the file to upload to the CDN. * * @param string $uploaded_path The path the file was uploaded to, reference parameter for when this may be needed. * * @return bool Whether the file was copied successfully. */ function copy_file_to_cdn($file_path = '', &$uploaded_path = null) { global $mybb, $plugins;
$success = false;
$file_path = (string)$file_path;
$real_file_path = realpath($file_path);
$file_dir_path = dirname($real_file_path); $file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path); $file_dir_path = ltrim($file_dir_path, './\\');
$file_name = basename($real_file_path);
if(file_exists($file_path)) {
if(is_object($plugins)) { $hook_args = array( 'file_path' => &$file_path, 'real_file_path' => &$real_file_path, 'file_name' => &$file_name, 'file_dir_path' => &$file_dir_path ); $plugins->run_hooks('copy_file_to_cdn_start', $hook_args); }
if(!empty($mybb->settings['usecdn']) && !empty($mybb->settings['cdnpath'])) { $cdn_path = rtrim($mybb->settings['cdnpath'], '/\\');
if(substr($file_dir_path, 0, my_strlen(MYBB_ROOT)) == MYBB_ROOT) { $file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path); }
$cdn_upload_path = $cdn_path . DIRECTORY_SEPARATOR . $file_dir_path;
if(!($dir_exists = is_dir($cdn_upload_path))) { $dir_exists = @mkdir($cdn_upload_path, 0777, true); }
if($dir_exists) { if(($cdn_upload_path = realpath($cdn_upload_path)) !== false) { $success = @copy($file_path, $cdn_upload_path.DIRECTORY_SEPARATOR.$file_name);
if($success) { $uploaded_path = $cdn_upload_path; } } } }
if(is_object($plugins)) { $hook_args = array( 'file_path' => &$file_path, 'real_file_path' => &$real_file_path, 'file_name' => &$file_name, 'uploaded_path' => &$uploaded_path, 'success' => &$success, );
$plugins->run_hooks('copy_file_to_cdn_end', $hook_args); } }
return $success; }
/** * Validate an url * * @param string $url The url to validate. * @param bool $relative_path Whether or not the url could be a relative path. * @param bool $allow_local Whether or not the url could be pointing to local networks. * * @return bool Whether this is a valid url. */ function my_validate_url($url, $relative_path=false, $allow_local=false) { if($allow_local) { $regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:localhost|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?))(?::\d{2,5})?(?:[/?#]\S*)?$_iuS'; } else { $regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$_iuS'; }
if($relative_path && my_substr($url, 0, 1) == '/' || preg_match($regex, $url)) { return true; } return false; }
/** * Strip html tags from string, also removes <script> and <style> contents. * * @deprecated * @param string $string String to stripe * @param string $allowable_tags Allowed html tags * * @return string Striped string */ function my_strip_tags($string, $allowable_tags = '') { $pattern = array( '@(<)style[^(>)]*?(>).*?(<)/style(>)@siu', '@(<)script[^(>)]*?.*?(<)/script(>)@siu', '@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu', ); $string = preg_replace($pattern, '', $string); return strip_tags($string, $allowable_tags); }
/** * Escapes a RFC 4180-compliant CSV string. * Based on https://github.com/Automattic/camptix/blob/f80725094440bf09861383b8f11e96c177c45789/camptix.php#L2867 * * @param string $string The string to be escaped * @param boolean $escape_active_content Whether or not to escape active content trigger characters * @return string The escaped string */ function my_escape_csv($string, $escape_active_content=true) { if($escape_active_content) { $active_content_triggers = array('=', '+', '-', '@'); $delimiters = array(',', ';', ':', '|', '^', "\n", "\t", " ");
$first_character = mb_substr($string, 0, 1);
if( in_array($first_character, $active_content_triggers, true) || in_array($first_character, $delimiters, true) ) { $string = "'".$string; }
foreach($delimiters as $delimiter) { foreach($active_content_triggers as $trigger) { $string = str_replace($delimiter.$trigger, $delimiter."'".$trigger, $string); } } }
$string = str_replace('"', '""', $string);
return $string; }
// Fallback function for 'array_column', PHP < 5.5.0 compatibility if(!function_exists('array_column')) { function array_column($input, $column_key) { $values = array(); if(!is_array($input)) { $input = array($input); } foreach($input as $val) { if(is_array($val) && isset($val[$column_key])) { $values[] = $val[$column_key]; } elseif(is_object($val) && isset($val->$column_key)) { $values[] = $val->$column_key; } } return $values; } }
/** * Performs a timing attack safe string comparison. * * @param string $known_string The first string to be compared. * @param string $user_string The second, user-supplied string to be compared. * @return bool Result of the comparison. */ function my_hash_equals($known_string, $user_string) { if(version_compare(PHP_VERSION, '5.6.0', '>=')) { return hash_equals($known_string, $user_string); } else { $known_string_length = my_strlen($known_string); $user_string_length = my_strlen($user_string);
if($user_string_length != $known_string_length) { return false; }
$result = 0;
for($i = 0; $i < $known_string_length; $i++) { $result |= ord($known_string[$i]) ^ ord($user_string[$i]); }
return $result === 0; } }
/** * Retrieves all referrals for a specified user * * @param int uid * @param int start position * @param int total entries * @param bool false (default) only return display info, true for all info * @return array */ function get_user_referrals($uid, $start=0, $limit=0, $full=false) { global $db;
$referrals = $query_options = array(); $uid = (int) $uid;
if($uid === 0) { return $referrals; }
if($start && $limit) { $query_options['limit_start'] = $start; }
if($limit) { $query_options['limit'] = $limit; }
$fields = 'uid, username, usergroup, displaygroup, regdate'; if($full === true) { $fields = '*'; }
$query = $db->simple_select('users', $fields, "referrer='{$uid}'", $query_options);
while($referral = $db->fetch_array($query)) { $referrals[] = $referral; }
return $referrals; }
/** * Initialize the parser and store the XML data to be parsed. * * @param string $data * @return MyBBXMLParser The constructed XML parser. */ function create_xml_parser($data) { if(version_compare(PHP_VERSION, '8.0', '>=')) { require_once MYBB_ROOT."inc/class_xmlparser.php";
return new MyBBXMLParser($data); } else { require_once MYBB_ROOT."inc/class_xml.php";
return new XMLParser($data); } }
/** * Make a filesystem path absolute. * * Returns as-is paths which are already absolute. * * @param string $path The input path. Can be either absolute or relative. * @param string $base The absolute base to which to append $path if $path is * relative. Must end in DIRECTORY_SEPARATOR or a forward * slash. * @return string An absolute filesystem path corresponding to the input path. */ function mk_path_abs($path, $base = MYBB_ROOT) { $iswin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; $char1 = my_substr($path, 0, 1); if($char1 != '/' && !($iswin && ($char1 == '\\' || preg_match('(^[a-zA-Z]:\\\\)', $path)))) { $path = $base.$path; }
return $path;
|
}
| }
|