function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false) { global $context, $settings, $modSettings, $txt, $smcFunc; static $header_done = false, $footer_done = false, $level = 0, $has_fatal_error = false; // Attempt to prevent a recursive loop. ++$level; if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { exit; } if ($from_fatal_error) { $has_fatal_error = true; } // Clear out the stat cache. trackStats(); // If we have mail to send, send it. if (!empty($context['flush_mail'])) { AddMailQueue(true); } $do_header = $header === null ? !$header_done : $header; if ($do_footer === null) { $do_footer = $do_header; } // Has the template/header been done yet? if ($do_header) { // Was the page title set last minute? Also update the HTML safe one. if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])); } // Start up the session URL fixer. ob_start('ob_sessrewrite'); if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { $buffers = explode(',', $settings['output_buffers']); } elseif (!empty($settings['output_buffers'])) { $buffers = $settings['output_buffers']; } else { $buffers = array(); } if (isset($modSettings['integrate_buffer'])) { $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); } if (!empty($buffers)) { foreach ($buffers as $function) { $function = trim($function); $call = strpos($function, '::') !== false ? explode('::', $function) : $function; // Is it valid? if (is_callable($call)) { ob_start($call); } } } // Display the screen in the logical order. template_header(); $header_done = true; } if ($do_footer) { if (WIRELESS && !isset($context['sub_template'])) { fatal_lang_error('wireless_error_notyet', false); } // Just show the footer, then. loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); // Anything special to put out? if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { echo $context['insert_after_template']; } // Just so we don't get caught in an endless loop of errors from the footer... if (!$footer_done) { $footer_done = true; template_footer(); // (since this is just debugging... it's okay that it's after </html>.) if (!isset($_REQUEST['xml'])) { db_debug_junk(); } } } // Remember this URL in case someone doesn't like sending HTTP_REFERER. if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; } // For session check verfication.... don't switch browsers... $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; if (!empty($settings['strict_doctype'])) { // The theme author wants to use the STRICT doctype (only God knows why). $temp = ob_get_contents(); if (function_exists('ob_clean')) { ob_clean(); } else { ob_end_clean(); ob_start('ob_sessrewrite'); } echo strtr($temp, array('var smf_iso_case_folding' => 'var target_blank = \'_blank\'; var smf_iso_case_folding', 'target="_blank"' => 'onclick="this.target=target_blank"')); } // Hand off the output to the portal, etc. we're integrated with. call_integration_hook('integrate_exit', array($do_footer && !WIRELESS)); // Don't exit if we're coming from index.php; that will pass through normally. if (!$from_index || WIRELESS) { exit; } }
function scheduled_birthdayemails() { global $modSettings, $sourcedir, $mbname, $txt, $smcFunc, $birthdayEmails; // Need this in order to load the language files. loadEssentialThemeData(); // Going to need this to send the emails. require_once $sourcedir . '/lib/Subs-Post.php'; $greeting = isset($modSettings['birthday_email']) ? $modSettings['birthday_email'] : 'happy_birthday'; // Get the month and day of today. $month = date('n'); // Month without leading zeros. $day = date('j'); // Day without leading zeros. // So who are the lucky ones? Don't include those who are banned and those who don't want them. $result = smf_db_query(' SELECT id_member, real_name, lngfile, email_address FROM {db_prefix}members WHERE is_activated < 10 AND MONTH(birthdate) = {int:month} AND DAYOFMONTH(birthdate) = {int:day} AND notify_announcements = {int:notify_announcements} AND YEAR(birthdate) > {int:year}', array('notify_announcements' => 1, 'year' => 1, 'month' => $month, 'day' => $day)); // Group them by languages. $birthdays = array(); while ($row = mysql_fetch_assoc($result)) { if (!isset($birthdays[$row['lngfile']])) { $birthdays[$row['lngfile']] = array(); } $birthdays[$row['lngfile']][$row['id_member']] = array('name' => $row['real_name'], 'email' => $row['email_address']); } mysql_free_result($result); // Send out the greetings! foreach ($birthdays as $lang => $recps) { // We need to do some shuffling to make this work properly. loadLanguage('EmailTemplates', $lang); $txt['emails']['happy_birthday'] = $birthdayEmails[$greeting]; foreach ($recps as $recp) { $replacements = array('REALNAME' => $recp['name']); $emaildata = loadEmailTemplate('happy_birthday', $replacements, $lang, false); sendmail($recp['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 4); // Try to stop a timeout, this would be bad... @set_time_limit(300); if (function_exists('apache_reset_timeout')) { @apache_reset_timeout(); } } } // Flush the mail queue, just in case. AddMailQueue(true); return true; }
function AddMailQueue($flush = false, $to_array = array(), $subject = '', $message = '', $headers = '', $send_html = false, $priority = 3, $is_private = false) { global $context; static $cur_insert = array(); static $cur_insert_len = 0; if ($cur_insert_len == 0) { $cur_insert = array(); } // If we're flushing, make the final inserts - also if we're near the MySQL length limit! if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) { // Only do these once. $cur_insert_len = 0; // Dump the data... smf_db_insert('', '{db_prefix}mail_queue', array('time_sent' => 'int', 'recipient' => 'string-255', 'body' => 'string-65534', 'subject' => 'string-255', 'headers' => 'string-65534', 'send_html' => 'int', 'priority' => 'int', 'private' => 'int'), $cur_insert, array('id_mail')); $cur_insert = array(); $context['flush_mail'] = false; } // If we're flushing we're done. if ($flush) { $nextSendTime = time() + 10; smf_db_query(' UPDATE {db_prefix}settings SET value = {string:nextSendTime} WHERE variable = {string:mail_next_send} AND value = {string:no_outstanding}', array('nextSendTime' => $nextSendTime, 'mail_next_send' => 'mail_next_send', 'no_outstanding' => '0')); return true; } // Ensure we tell obExit to flush. $context['flush_mail'] = true; foreach ($to_array as $to) { // Will this insert go over MySQL's limit? $this_insert_len = strlen($to) + strlen($message) + strlen($headers) + 700; // Insert limit of 1M (just under the safety) is reached? if ($this_insert_len + $cur_insert_len > 1000000) { // Flush out what we have so far. smf_db_insert('', '{db_prefix}mail_queue', array('time_sent' => 'int', 'recipient' => 'string-255', 'body' => 'string-65534', 'subject' => 'string-255', 'headers' => 'string-65534', 'send_html' => 'int', 'priority' => 'int', 'private' => 'int'), $cur_insert, array('id_mail')); // Clear this out. $cur_insert = array(); $cur_insert_len = 0; } // Now add the current insert to the array... $cur_insert[] = array(time(), (string) $to, (string) $message, (string) $subject, (string) $headers, $send_html ? 1 : 0, $priority, (int) $is_private); $cur_insert_len += $this_insert_len; } // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. if (SMF === 'SSI') { return AddMailQueue(true); } return true; }
public static function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false) { global $context, $modSettings; static $header_done = false, $footer_done = false, $level = 0, $has_fatal_error = false; // Attempt to prevent a recursive loop. ++$level; if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { exit; } if ($from_fatal_error) { $has_fatal_error = true; } // Clear out the stat cache. trackStats(); // If we have mail to send, send it. if (!empty($context['flush_mail'])) { AddMailQueue(true); } $do_header = $header === null ? !$header_done : $header; if ($do_footer === null) { $do_footer = $do_header; } // Has the template/header been done yet? if ($do_header) { // Was the page title set last minute? Also update the HTML safe one. if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { $context['page_title_html_safe'] = $context['forum_name_html_safe'] . ' - ' . commonAPI::htmlspecialchars(un_htmlspecialchars($context['page_title'])); } // Start up the session URL fixer. ob_start('ob_sessrewrite'); HookAPI::integrateOB(); //if(!empty($modSettings['simplesef_enable'])) // ob_start('SimpleSEF::ob_simplesef'); // Display the screen in the logical order. self::template_header(); $header_done = true; } if ($do_footer) { if (WIRELESS && !isset($context['sub_template'])) { fatal_lang_error('wireless_error_notyet', false); } self::Display(); // Just so we don't get caught in an endless loop of errors from the footer... if (!$footer_done) { $footer_done = true; // (since this is just debugging... it's okay that it's after </html>.) if (!isset($_REQUEST['xml'])) { db_debug_junk(); } } } // Remember this URL in case someone doesn't like sending HTTP_REFERER. if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; } // For session check verfication.... don't switch browsers... $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; // Hand off the output to the portal, etc. we're integrated with. HookAPI::callHook('integrate_exit', array($do_footer)); if (!empty($modSettings['simplesef_enable'])) { SimpleSEF::fixXMLOutput($do_footer); } // Don't exit if we're coming from index.php; that will pass through normally. if (!$from_index) { exit; } }
set_topic_and_board_by_message(); // Start the session. (assuming it hasn't already been.) loadSession(); $sc = $_SESSION['session_value']; $_GET[$_SESSION['session_var']] = $_SESSION['session_value']; $_POST[$_SESSION['session_var']] = $_SESSION['session_value']; define('WIRELESS', false); // What function shall we execute? (done like this for memory's sake.) call_user_func(smf_main()); // Call obExit specially; we're coming from the main area ;). //obExit(null, null, true); // Clear out the stat cache. trackStats(); // If we have mail to send, send it. if (!empty($context['flush_mail'])) { AddMailQueue(true); } //-------------do something after action-------------- if (function_exists('after_action_' . $request_name)) { call_user_func('after_action_' . $request_name); } if (!empty($settings['strict_doctype'])) { // The theme author wants to use the STRICT doctype (only God knows why). @ob_get_contents(); if (function_exists('ob_clean')) { @ob_clean(); } else { @ob_end_clean(); @ob_start(); } }
/** * Ends execution. * * What it does: * - Takes care of template loading and remembering the previous URL. * - Calls ob_start() with ob_sessrewrite to fix URLs if necessary. * * @param bool|null $header = null * @param bool|null $do_footer = null * @param bool $from_index = false * @param bool $from_fatal_error = false */ function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false) { global $context, $txt; static $header_done = false, $footer_done = false, $level = 0, $has_fatal_error = false; // Attempt to prevent a recursive loop. ++$level; if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { exit; } if ($from_fatal_error) { $has_fatal_error = true; } // Clear out the stat cache. trackStats(); // If we have mail to send, send it. if (!empty($context['flush_mail'])) { // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ AddMailQueue(true); } $do_header = $header === null ? !$header_done : $header; if ($do_footer === null) { $do_footer = $do_header; } // Has the template/header been done yet? if ($do_header) { // Was the page title set last minute? Also update the HTML safe one. if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { $context['page_title_html_safe'] = Util::htmlspecialchars(un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); } // Start up the session URL fixer. ob_start('ob_sessrewrite'); call_integration_buffer(); // Display the screen in the logical order. template_header(); $header_done = true; } if ($do_footer) { // Show the footer. loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); // Just so we don't get caught in an endless loop of errors from the footer... if (!$footer_done) { $footer_done = true; template_footer(); // (since this is just debugging... it's okay that it's after </html>.) if (!isset($_REQUEST['xml'])) { displayDebug(); } } } // Need user agent $req = request(); // Remember this URL in case someone doesn't like sending HTTP_REFERER. $invalid_old_url = array('action=dlattach', 'action=jsoption', 'action=viewadminfile', ';xml', ';api'); $make_old = true; foreach ($invalid_old_url as $url) { if (strpos($_SERVER['REQUEST_URL'], $url) !== false) { $make_old = false; break; } } if ($make_old === true) { $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; } // For session check verification.... don't switch browsers... $_SESSION['USER_AGENT'] = $req->user_agent(); // Hand off the output to the portal, etc. we're integrated with. call_integration_hook('integrate_exit', array($do_footer)); // Don't exit if we're coming from index.php; that will pass through normally. if (!$from_index) { exit; } }