public static function load_theme() { global $context, $modSettings, $txt, $settings, $user_info; if (($themes = cache_get_data('TS_themes_list', 3600)) === null) { loadLanguage('ManageThemes'); require_once SUBSDIR . '/Themes.subs.php'; $themes = availableThemes($user_info['theme'], $user_info['id']); cache_put_data('TS_themes_list', $themes, 3600); } foreach ($themes[0] as $theme_id => $theme) { $name = $theme['name']; $selected = !empty($user_info['theme']) && $user_info['theme'] == $theme_id; $context['ThemeSelector'][$theme_id] = array('name' => $name, 'selected' => $selected, 'variants' => array()); if (isset($theme['variants'])) { foreach ($theme['variants'] as $key => $variant) { $context['ThemeSelector'][$theme_id]['variants'][$key] = array('name' => $variant['label'], 'selected' => $context['theme_variant'] == '_' . $key); } } } if (!isset($context['theme_header_callbacks'])) { $context['theme_header_callbacks'] = array(); } $context['theme_header_callbacks'][] = 'themeselector'; loadTemplate('ThemeSelector'); loadJavascriptFile('ThemeSelector.js'); loadCSSFile('ThemeSelector.css'); }
/** * ibb_fa_button * * - Editor hook, integrate_bbc_buttons hook, Called from Editor.subs.php * - Used to add buttons to the editor menu bar * * @param mixed[] $bbc_tags */ function ibb_fa_button(&$bbc_tags) { // This is the group we intend to modify $where = $bbc_tags['row1'][2]; // And here we insert the new value after font $bbc_tags['row1'][2] = elk_array_insert($where, 'font', array('fontawesome'), 'after', false); // Add the javascript, this tells the editor what to do with the new button loadJavascriptFile('faButton.plugin.js', array(), 'faButton'); // CSS specific to this button presentation in the editor toolbar loadCSSFile('faButton.css', array(), 'fa44'); }
protected static function buildTemplate($notices) { global $context, $user_info; loadTemplate('DismissibleNotices'); loadLanguage('DismissibleNotices'); Template_Layers::getInstance()->addAfter('notices', 'body'); loadJavascriptFile('notify.js', array('defer' => true)); loadCSSFile('notify.css'); foreach ($notices as $key => $notice) { $notice['body'] = str_replace('{username}', $user_info['name'], $notice['body']); $context['notices'][$key] = $notice; } $context['notices'] = $notices; }
/** * System none modal ECL init */ function pmx_eclnonemodal() { global $context, $settings, $modSettings, $maintenance, $scripturl, $options, $txt; if (!empty($modSettings['pmx_eclmodal']) && !pmx_checkECL_Cookie()) { if (!empty($modSettings['pmxportal_disabled'])) { loadJavascriptFile(PortaMx_loadCompressed('PortaMx.js', array('dir' => $settings['default_theme_dir'] . '/PortaMx/Scripts/', 'url' => $settings['default_theme_url'] . '/PortaMx/Scripts/')), array('external' => true)); addInlineJavascript(' var pmxIsInit = true;'); loadLanguage('PortaMx/PortaMx'); } addInlineJavascript(' var eclOverlay = true; function Setlang(elm){window.location.href = elm.options[elm.selectedIndex].value;}'); loadCSSFile(PortaMx_loadCompressed('pmx_ecl.css', array('dir' => $settings['default_theme_dir'] . '/PortaMx/SysCss/', 'url' => $settings['default_theme_url'] . '/PortaMx/SysCss/')), array('external' => true)); loadtemplate('PortaMx/EclMain'); $context['template_layers'][] = 'eclmain'; } }
/** * Main dispatcher. * This function checks permissions and passes control through. * If the passed section is not found it shows the information page. */ public function action_index() { global $context, $txt; // You need to be an admin or have manage setting permissions to change anything if (!allowedTo('sp_admin')) { isAllowedTo('sp_manage_settings'); } // Some helpful friends require_once SUBSDIR . '/PortalAdmin.subs.php'; require_once SUBSDIR . '/Portal.subs.php'; require_once ADMINDIR . '/ManageServer.controller.php'; loadCSSFile('portal.css'); // Load the Simple Portal Help file. loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp')); $subActions = array('information' => array($this, 'action_sportal_information'), 'generalsettings' => array($this, 'action_sportal_admin_general_settings'), 'blocksettings' => array($this, 'action_sportal_admin_block_settings'), 'articlesettings' => array($this, 'action_sportal_admin_article_settings')); // Start up the controller, provide a hook since we can $action = new Action('portal_main'); $context[$context['admin_menu_name']]['tab_data'] = array('title' => $txt['sp-adminConfiguration'], 'help' => 'sp_ConfigurationArea', 'description' => $txt['sp-adminConfigurationDesc']); // Set the default to the information tab $subAction = $action->initialize($subActions, 'information'); // Right then, off you go $action->dispatch($subAction); }
public function action_list() { global $txt, $context, $scripturl, $modSettings, $settings; loadJavascriptFile('notify.js', array('defer' => true)); loadJavascriptFile('jquery.knob.js', array('defer' => true)); loadCSSFile('notify.css'); addInlineJavascript('dismissnotice_editable();', true); $modSettings['jquery_include_ui'] = true; loadCSSFile('dism/jquery.ui.theme.css'); loadCSSFile('dism/jquery.ui.datepicker.css'); loadCSSFile('dism/jquery.ui.d.theme.css'); loadCSSFile('dism/jquery.ui.core.css'); $possible_locals = array($txt['lang_locale']); $b = explode('_', $txt['lang_locale']); foreach ($b as $a) { $possible_locals[] = $a; } foreach ($possible_locals as $local) { if (file_exists($settings['default_theme_dir'] . '/scripts/datepicker-i18n/datepicker-' . $local . '.js')) { loadJavascriptFile('datepicker-i18n/datepicker-' . $local . '.js', array('defer' => true)); break; $context['datepicker_local'] = $local; } } $list_options = array('id' => 'list_dismissible_notices', 'title' => $txt['dismissnotices_title_list'], 'items_per_page' => 20, 'base_href' => $scripturl . '?action=admin;area=dismissnotice;sa=list' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'timeadded', 'get_items' => array('function' => array($this, 'getItems')), 'get_count' => array('function' => array($this, 'countItems')), 'data_check' => array('class' => function ($rowData) { return 'editable_' . $rowData['id_notice']; }), 'no_items_label' => $txt['hooks_no_hooks'], 'columns' => array('timeadded' => array('header' => array('value' => $txt['dismissnotices_time_added']), 'data' => array('function' => function ($rowData) { return standardTime($rowData['added']); }), 'sort' => array('default' => 'added', 'reverse' => 'added DESC')), 'body' => array('header' => array('value' => $txt['dismissnotices_body']), 'data' => array('db' => 'body')), 'class' => array('header' => array('value' => $txt['dismissnotices_class']), 'data' => array('db_htmlsafe' => 'class'), 'sort' => array('default' => 'class', 'reverse' => 'class DESC')), 'expire' => array('header' => array('value' => $txt['dismissnotices_expire']), 'data' => array('function' => function ($rowData) { return Dismissible_Notices_Integrate::formatExpireCol($rowData['expire']); }), 'sort' => array('default' => 'expire', 'reverse' => 'expire DESC')), 'edit' => array('header' => array('value' => ''), 'data' => array('function' => function ($rowData) { global $txt; return '<a data-idnotice="' . $rowData['id_notice'] . '" class="dismissnotice_editable" href="#">' . $txt['modify'] . '</a>'; }))), 'additional_rows' => array(array('position' => 'bottom_of_list', 'value' => '<a id="dismissnotice_new" class="floatright linkbutton" href="#">' . $txt['new'] . '</a>'))); require_once SUBSDIR . '/GenericList.class.php'; createList($list_options); }
/** * Creates a box that can be used for richedit stuff like BBC, Smileys etc. * @param mixed[] $editorOptions associative array of options => value * must contain: * - id => unique id for the css * - value => text for the editor or blank * Optionaly * - height => height of the intial box * - width => width of the box (100%) * - force_rich => force wysiwyg to be enabled * - disable_smiley_box => boolean to turn off the smiley box * - labels => array( * - 'post_button' => $txt['for post button'], * ), * - preview_type => 2 how to act on preview click, see template_control_richedit_buttons */ function create_control_richedit($editorOptions) { global $txt, $modSettings, $options, $context, $settings, $user_info, $scripturl; static $bbc_tags; $db = database(); // Load the Post language file... for the moment at least. loadLanguage('Post'); if (!empty($context['drafts_save']) || !empty($context['drafts_pm_save'])) { loadLanguage('Drafts'); } // Every control must have a ID! assert(isset($editorOptions['id'])); assert(isset($editorOptions['value'])); // Is this the first richedit - if so we need to ensure things are initialised and that we load all of the needed files if (empty($context['controls']['richedit'])) { // Store the name / ID we are creating for template compatibility. $context['post_box_name'] = $editorOptions['id']; // Some general stuff. $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; if (!empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled'])) { $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 30000 : $modSettings['drafts_autosave_frequency'] * 1000; } // This really has some WYSIWYG stuff. loadTemplate('GenericControls', 'jquery.sceditor'); if (!empty($context['theme_variant']) && file_exists($settings['theme_dir'] . '/css/' . $context['theme_variant'] . '/jquery.sceditor.elk' . $context['theme_variant'] . '.css')) { loadCSSFile($context['theme_variant'] . '/jquery.sceditor.elk' . $context['theme_variant'] . '.css'); } // JS makes the editor go round loadJavascriptFile(array('jquery.sceditor.min.js', 'jquery.sceditor.bbcode.min.js', 'jquery.sceditor.elkarte.js', 'post.js', 'splittag.plugin.js', 'dropAttachments.js')); addJavascriptVar(array('post_box_name' => $editorOptions['id'], 'elk_smileys_url' => $settings['smileys_url'], 'bbc_quote_from' => $txt['quote_from'], 'bbc_quote' => $txt['quote'], 'bbc_search_on' => $txt['search_on']), true); // Editor language file if (!empty($txt['lang_locale'])) { loadJavascriptFile($scripturl . '?action=jslocale;sa=sceditor', array('defer' => true), 'sceditor_language'); } // Drafts? if ((!empty($context['drafts_save']) || !empty($context['drafts_pm_save'])) && !empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled'])) { loadJavascriptFile('drafts.plugin.js'); } // Mentions? if (!empty($context['mentions_enabled'])) { loadJavascriptFile(array('jquery.atwho.js', 'jquery.caret.min.js', 'mentioning.plugin.js')); } // Our not so concise shortcut line $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) || !empty($context['drafts_pm_save']) ? '_drafts' : '') . (isBrowser('is_firefox') ? '_firefox' : '')]; // Spellcheck? $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new'); if ($context['show_spellchecking']) { // Some hidden information is needed in order to make spell check work. if (!isset($_REQUEST['xml'])) { $context['insert_after_template'] .= ' <form name="spell_form" id="spell_form" method="post" accept-charset="UTF-8" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> <input type="hidden" name="spellstring" value="" /> <input type="hidden" name="fulleditor" value="" /> </form>'; } loadJavascriptFile('spellcheck.js', array('defer' => true)); } } // Start off the editor... $context['controls']['richedit'][$editorOptions['id']] = array('id' => $editorOptions['id'], 'value' => $editorOptions['value'], 'rich_active' => !empty($options['wysiwyg_default']) || !empty($editorOptions['force_rich']) || !empty($_REQUEST[$editorOptions['id'] . '_mode']), 'disable_smiley_box' => !empty($editorOptions['disable_smiley_box']), 'columns' => isset($editorOptions['columns']) ? $editorOptions['columns'] : 60, 'rows' => isset($editorOptions['rows']) ? $editorOptions['rows'] : 18, 'width' => isset($editorOptions['width']) ? $editorOptions['width'] : '100%', 'height' => isset($editorOptions['height']) ? $editorOptions['height'] : '250px', 'form' => isset($editorOptions['form']) ? $editorOptions['form'] : 'postmodify', 'bbc_level' => !empty($editorOptions['bbc_level']) ? $editorOptions['bbc_level'] : 'full', 'preview_type' => isset($editorOptions['preview_type']) ? (int) $editorOptions['preview_type'] : 1, 'labels' => !empty($editorOptions['labels']) ? $editorOptions['labels'] : array(), 'locale' => !empty($txt['lang_locale']) ? $txt['lang_locale'] : 'en_US'); // Switch between default images and back... mostly in case you don't have an PersonalMessage template, but do have a Post template. if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) { $temp1 = $settings['theme_url']; $settings['theme_url'] = $settings['default_theme_url']; $temp2 = $settings['images_url']; $settings['images_url'] = $settings['default_images_url']; $temp3 = $settings['theme_dir']; $settings['theme_dir'] = $settings['default_theme_dir']; } if (empty($bbc_tags)) { // The below array is used to show a command button in the editor, the execution // and display details of any added buttons must be defined in the javascript files // see jquery.sceditor.elkarte.js under the $.sceditor.plugins.bbcode.bbcode area // for examples of how to use the .set command to add codes. Include your new // JS with addInlineJavascript() or loadJavascriptFile() $bbc_tags['row1'] = array(array('bold', 'italic', 'underline', 'strike', 'superscript', 'subscript'), array('left', 'center', 'right', 'pre', 'tt'), array('font', 'size', 'color')); $bbc_tags['row2'] = array(array('quote', 'code', 'table'), array('bulletlist', 'orderedlist', 'horizontalrule'), array('spoiler', 'footnote'), array('image', 'link', 'email')); // Allow mods to add BBC buttons to the toolbar, actions are defined in the JS call_integration_hook('integrate_bbc_buttons', array(&$bbc_tags)); // Show the wysiwyg format and toggle buttons? $bbc_tags['row2'][] = array('removeformat', 'source'); // Generate a list of buttons that shouldn't be shown $disabled_tags = array(); if (!empty($modSettings['disabledBBC'])) { $disabled_tags = explode(',', $modSettings['disabledBBC']); } // Map codes to tags $translate_tags_to_code = array('b' => 'bold', 'i' => 'italic', 'u' => 'underline', 's' => 'strike', 'img' => 'image', 'url' => 'link', 'sup' => 'superscript', 'sub' => 'subscript', 'hr' => 'horizontalrule'); // Remove the toolbar buttons for any bbc tags that have been turned off in the ACP foreach ($disabled_tags as $tag) { // list is special, its prevents two tags if ($tag === 'list') { $context['disabled_tags']['bulletlist'] = true; $context['disabled_tags']['orderedlist'] = true; } elseif (isset($translate_tags_to_code[$tag])) { $context['disabled_tags'][$translate_tags_to_code[$tag]] = true; } // Tag is the same as the code, like font, color, size etc $context['disabled_tags'][trim($tag)] = true; } // Build our toolbar, taking in to account any bbc codes from integration $context['bbc_toolbar'] = array(); foreach ($bbc_tags as $row => $tagRow) { if (!isset($context['bbc_toolbar'][$row])) { $context['bbc_toolbar'][$row] = array(); } $tagsRow = array(); // For each row of buttons defined, lets build our tags foreach ($tagRow as $tags) { foreach ($tags as $tag) { // Just add this code in the existing grouping if (!isset($context['disabled_tags'][$tag])) { $tagsRow[] = $tag; } } // If the row is not empty, and the last added tag is not a space, add a space. if (!empty($tagsRow) && $tagsRow[count($tagsRow) - 1] != 'space') { $tagsRow[] = 'space'; } } // Build that beautiful button row if (!empty($tagsRow)) { $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); } } } // Initialize smiley array... if not loaded before. if (empty($context['smileys']) && empty($editorOptions['disable_smiley_box'])) { $context['smileys'] = array('postform' => array(), 'popup' => array()); // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { $context['smileys']['postform'][] = array('smileys' => array(array('code' => ':)', 'filename' => 'smiley.gif', 'description' => $txt['icon_smiley']), array('code' => ';)', 'filename' => 'wink.gif', 'description' => $txt['icon_wink']), array('code' => ':D', 'filename' => 'cheesy.gif', 'description' => $txt['icon_cheesy']), array('code' => ';D', 'filename' => 'grin.gif', 'description' => $txt['icon_grin']), array('code' => '>:(', 'filename' => 'angry.gif', 'description' => $txt['icon_angry']), array('code' => ':))', 'filename' => 'laugh.gif', 'description' => $txt['icon_laugh']), array('code' => ':(', 'filename' => 'sad.gif', 'description' => $txt['icon_sad']), array('code' => ':o', 'filename' => 'shocked.gif', 'description' => $txt['icon_shocked']), array('code' => '8)', 'filename' => 'cool.gif', 'description' => $txt['icon_cool']), array('code' => '???', 'filename' => 'huh.gif', 'description' => $txt['icon_huh']), array('code' => '::)', 'filename' => 'rolleyes.gif', 'description' => $txt['icon_rolleyes']), array('code' => ':P', 'filename' => 'tongue.gif', 'description' => $txt['icon_tongue']), array('code' => ':-[', 'filename' => 'embarrassed.gif', 'description' => $txt['icon_embarrassed']), array('code' => ':-X', 'filename' => 'lipsrsealed.gif', 'description' => $txt['icon_lips']), array('code' => ':-\\', 'filename' => 'undecided.gif', 'description' => $txt['icon_undecided']), array('code' => ':-*', 'filename' => 'kiss.gif', 'description' => $txt['icon_kiss']), array('code' => 'O:)', 'filename' => 'angel.gif', 'description' => $txt['icon_angel']), array('code' => ':\'(', 'filename' => 'cry.gif', 'description' => $txt['icon_cry'], 'isLast' => true)), 'isLast' => true); } elseif ($user_info['smiley_set'] != 'none') { if (($temp = cache_get_data('posting_smileys', 480)) == null) { $request = $db->query('', ' SELECT code, filename, description, smiley_row, hidden FROM {db_prefix}smileys WHERE hidden IN (0, 2) ORDER BY smiley_row, smiley_order', array()); while ($row = $db->fetch_assoc($request)) { $row['filename'] = htmlspecialchars($row['filename'], ENT_COMPAT, 'UTF-8'); $row['description'] = htmlspecialchars($row['description'], ENT_COMPAT, 'UTF-8'); $context['smileys'][empty($row['hidden']) ? 'postform' : 'popup'][$row['smiley_row']]['smileys'][] = $row; } $db->free_result($request); foreach ($context['smileys'] as $section => $smileyRows) { $last_row = null; foreach ($smileyRows as $rowIndex => $smileys) { $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; $last_row = $rowIndex; } if ($last_row !== null) { $context['smileys'][$section][$last_row]['isLast'] = true; } } cache_put_data('posting_smileys', $context['smileys'], 480); } else { $context['smileys'] = $temp; } // The smiley popup may take advantage of Jquery UI .... if (!empty($context['smileys']['popup'])) { $modSettings['jquery_include_ui'] = true; } } } // Set a flag so the sub template knows what to do... $context['show_bbc'] = !empty($modSettings['enableBBC']) && !empty($settings['show_bbc']); // Switch the URLs back... now we're back to whatever the main sub template is. (like folder in PersonalMessage.) if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) { $settings['theme_url'] = $temp1; $settings['images_url'] = $temp2; $settings['theme_dir'] = $temp3; } if (!empty($editorOptions['live_errors'])) { loadLanguage('Errors'); addInlineJavascript(' error_txts[\'no_subject\'] = ' . JavaScriptEscape($txt['error_no_subject']) . '; error_txts[\'no_message\'] = ' . JavaScriptEscape($txt['error_no_message']) . '; var subject_err = new errorbox_handler({ self: \'subject_err\', error_box_id: \'post_error\', error_checks: [{ code: \'no_subject\', efunction: function(box_value) { if (box_value.length === 0) return true; else return false; } }], check_id: "post_subject" }); var body_err_' . $editorOptions['id'] . ' = new errorbox_handler({ self: \'body_err_' . $editorOptions['id'] . '\', error_box_id: \'post_error\', error_checks: [{ code: \'no_message\', efunction: function(box_value) { if (box_value.length === 0) return true; else return false; } }], editor_id: \'' . $editorOptions['id'] . '\', editor: ' . JavaScriptEscape(' (function () { return $editor_data[\'' . $editorOptions['id'] . '\'].val(); });') . ' });', true); } }
/** * The central part of the board - topic display. * * What it does: * - This function loads the posts in a topic up so they can be displayed. * - It uses the main sub template of the Display template. * - It requires a topic, and can go to the previous or next topic from it. * - It jumps to the correct post depending on a number/time/IS_MSG passed. * - It depends on the messages_per_page, defaultMaxMessages and enableAllMessages settings. * - It is accessed by ?topic=id_topic.START. */ public function action_display() { global $scripturl, $txt, $modSettings, $context, $settings; global $options, $user_info, $board_info, $topic, $board; global $attachments, $messages_request; // What are you gonna display if these are empty?! if (empty($topic)) { fatal_lang_error('no_board', false); } // Load the template loadTemplate('Display'); $context['sub_template'] = 'messages'; // And the topic functions require_once SUBSDIR . '/Topic.subs.php'; require_once SUBSDIR . '/Messages.subs.php'; // Not only does a prefetch make things slower for the server, but it makes it impossible to know if they read it. if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { @ob_end_clean(); header('HTTP/1.1 403 Prefetch Forbidden'); die; } // How much are we sticking on each page? $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; $template_layers = Template_Layers::getInstance(); $template_layers->addEnd('messages_informations'); $includeUnapproved = !$modSettings['postmod_active'] || allowedTo('approve_posts'); // Let's do some work on what to search index. if (count($_GET) > 2) { foreach ($_GET as $k => $v) { if (!in_array($k, array('topic', 'board', 'start', session_name()))) { $context['robot_no_index'] = true; } } } if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { $context['robot_no_index'] = true; } // Find the previous or next topic. Make a fuss if there are no more. if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next')) { // No use in calculating the next topic if there's only one. if ($board_info['num_topics'] > 1) { $includeStickies = !empty($modSettings['enableStickyTopics']); $topic = $_REQUEST['prev_next'] === 'prev' ? previousTopic($topic, $board, $user_info['id'], $includeUnapproved, $includeStickies) : nextTopic($topic, $board, $user_info['id'], $includeUnapproved, $includeStickies); $context['current_topic'] = $topic; } // Go to the newest message on this topic. $_REQUEST['start'] = 'new'; } // Add 1 to the number of views of this topic (except for robots). if (!$user_info['possibly_robot'] && (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)) { increaseViewCounter($topic); $_SESSION['last_read_topic'] = $topic; } $topic_selects = array(); $topic_tables = array(); $topic_parameters = array('topic' => $topic, 'member' => $user_info['id'], 'board' => (int) $board); // Allow addons to add additional details to the topic query call_integration_hook('integrate_topic_query', array(&$topic_selects, &$topic_tables, &$topic_parameters)); // Load the topic details $topicinfo = getTopicInfo($topic_parameters, 'all', $topic_selects, $topic_tables); if (empty($topicinfo)) { fatal_lang_error('not_a_topic', false); } // Is this a moved topic that we are redirecting to? if (!empty($topicinfo['id_redirect_topic']) && !isset($_GET['noredir'])) { markTopicsRead(array($user_info['id'], $topic, $topicinfo['id_last_msg'], 0), $topicinfo['new_from'] !== 0); redirectexit('topic=' . $topicinfo['id_redirect_topic'] . '.0;redirfrom=' . $topicinfo['id_topic']); } $context['real_num_replies'] = $context['num_replies'] = $topicinfo['num_replies']; $context['topic_first_message'] = $topicinfo['id_first_msg']; $context['topic_last_message'] = $topicinfo['id_last_msg']; $context['topic_unwatched'] = isset($topicinfo['unwatched']) ? $topicinfo['unwatched'] : 0; if (isset($_GET['redirfrom'])) { $redir_topics = topicsList(array((int) $_GET['redirfrom'])); if (!empty($redir_topics[(int) $_GET['redirfrom']])) { $context['topic_redirected_from'] = $redir_topics[(int) $_GET['redirfrom']]; $context['topic_redirected_from']['redir_href'] = $scripturl . '?topic=' . $context['topic_redirected_from']['id_topic'] . '.0;noredir'; } } // Add up unapproved replies to get real number of replies... if ($modSettings['postmod_active'] && allowedTo('approve_posts')) { $context['real_num_replies'] += $topicinfo['unapproved_posts'] - ($topicinfo['approved'] ? 0 : 1); } // If this topic was derived from another, set the followup details if (!empty($topicinfo['derived_from'])) { require_once SUBSDIR . '/FollowUps.subs.php'; $context['topic_derived_from'] = topicStartedHere($topic, $includeUnapproved); } // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing. if (!$includeUnapproved && $topicinfo['unapproved_posts'] && !$user_info['is_guest']) { $myUnapprovedPosts = unapprovedPosts($topic, $user_info['id']); $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($topicinfo['approved'] ? 1 : 0); } elseif ($user_info['is_guest']) { $context['total_visible_posts'] = $context['num_replies'] + ($topicinfo['approved'] ? 1 : 0); } else { $context['total_visible_posts'] = $context['num_replies'] + $topicinfo['unapproved_posts'] + ($topicinfo['approved'] ? 1 : 0); } // When was the last time this topic was replied to? Should we warn them about it? if (!empty($modSettings['oldTopicDays'])) { $mgsOptions = basicMessageInfo($topicinfo['id_last_msg'], true); $context['oldTopicError'] = $mgsOptions['poster_time'] + $modSettings['oldTopicDays'] * 86400 < time() && empty($topicinfo['is_sticky']); } else { $context['oldTopicError'] = false; } // The start isn't a number; it's information about what to do, where to go. if (!is_numeric($_REQUEST['start'])) { // Redirect to the page and post with new messages, originally by Omar Bazavilvazo. if ($_REQUEST['start'] == 'new') { // Guests automatically go to the last post. if ($user_info['is_guest']) { $context['start_from'] = $context['total_visible_posts'] - 1; $_REQUEST['start'] = $context['start_from']; } else { // Fall through to the next if statement. $_REQUEST['start'] = 'msg' . $topicinfo['new_from']; } } // Start from a certain time index, not a message. if (substr($_REQUEST['start'], 0, 4) == 'from') { $timestamp = (int) substr($_REQUEST['start'], 4); if ($timestamp === 0) { $_REQUEST['start'] = 0; } else { // Find the number of messages posted before said time... $context['start_from'] = countNewPosts($topic, $topicinfo, $timestamp); $_REQUEST['start'] = $context['start_from']; } } elseif (substr($_REQUEST['start'], 0, 3) == 'msg') { $virtual_msg = (int) substr($_REQUEST['start'], 3); if (!$topicinfo['unapproved_posts'] && $virtual_msg >= $topicinfo['id_last_msg']) { $context['start_from'] = $context['total_visible_posts'] - 1; } elseif (!$topicinfo['unapproved_posts'] && $virtual_msg <= $topicinfo['id_first_msg']) { $context['start_from'] = 0; } else { $only_approved = $modSettings['postmod_active'] && $topicinfo['unapproved_posts'] && !allowedTo('approve_posts'); $context['start_from'] = countMessagesBefore($topic, $virtual_msg, false, $only_approved, !$user_info['is_guest']); } // We need to reverse the start as well in this case. $_REQUEST['start'] = $context['start_from']; } } // Mark the mention as read if requested if (isset($_REQUEST['mentionread']) && !empty($virtual_msg)) { require_once CONTROLLERDIR . '/Mentions.controller.php'; $mentions = new Mentions_Controller(); $mentions->setData(array('id_mention' => $_REQUEST['item'], 'mark' => $_REQUEST['mark'])); $mentions->action_markread(); } // Create a previous next string if the selected theme has it as a selected option. if ($modSettings['enablePreviousNext']) { $context['links'] += array('go_prev' => $scripturl . '?topic=' . $topic . '.0;prev_next=prev#new', 'go_next' => $scripturl . '?topic=' . $topic . '.0;prev_next=next#new'); } // Derived from, set the link back if (!empty($context['topic_derived_from'])) { $context['links']['derived_from'] = $scripturl . '?msg=' . $context['topic_derived_from']['derived_from']; } // Check if spellchecking is both enabled and actually working. (for quick reply.) $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new'); if ($context['show_spellchecking']) { loadJavascriptFile('spellcheck.js', array('defer' => true)); } // Do we need to show the visual verification image? $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || $user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1); if ($context['require_verification']) { require_once SUBSDIR . '/VerificationControls.class.php'; $verificationOptions = array('id' => 'post'); $context['require_verification'] = create_control_verification($verificationOptions); $context['visual_verification_id'] = $verificationOptions['id']; } // Are we showing signatures - or disabled fields? $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1; $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); // Censor the title... censorText($topicinfo['subject']); $context['page_title'] = $topicinfo['subject']; // Is this topic sticky, or can it even be? $topicinfo['is_sticky'] = empty($modSettings['enableStickyTopics']) ? '0' : $topicinfo['is_sticky']; // Allow addons access to the topicinfo array call_integration_hook('integrate_display_topic', array($topicinfo)); // Default this topic to not marked for notifications... of course... $context['is_marked_notify'] = false; // Did we report a post to a moderator just now? $context['report_sent'] = isset($_GET['reportsent']); if ($context['report_sent']) { $template_layers->add('report_sent'); } // Let's get nosey, who is viewing this topic? if (!empty($settings['display_who_viewing'])) { require_once SUBSDIR . '/Who.subs.php'; formatViewers($topic, 'topic'); } // If all is set, but not allowed... just unset it. $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages']; if (isset($_REQUEST['all']) && !$can_show_all) { unset($_REQUEST['all']); } elseif (isset($_REQUEST['all'])) { $_REQUEST['start'] = -1; } // Construct the page index, allowing for the .START method... $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true, array('all' => $can_show_all, 'all_selected' => isset($_REQUEST['all']))); $context['start'] = $_REQUEST['start']; // This is information about which page is current, and which page we're on - in case you don't like the constructed page index. (again, wireles..) $context['page_info'] = array('current_page' => $_REQUEST['start'] / $context['messages_per_page'] + 1, 'num_pages' => floor(($context['total_visible_posts'] - 1) / $context['messages_per_page']) + 1); // Figure out all the link to the next/prev $context['links'] += array('prev' => $_REQUEST['start'] >= $context['messages_per_page'] ? $scripturl . '?topic=' . $topic . '.' . ($_REQUEST['start'] - $context['messages_per_page']) : '', 'next' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic . '.' . ($_REQUEST['start'] + $context['messages_per_page']) : ''); // If they are viewing all the posts, show all the posts, otherwise limit the number. if ($can_show_all && isset($_REQUEST['all'])) { // No limit! (actually, there is a limit, but...) $context['messages_per_page'] = -1; // Set start back to 0... $_REQUEST['start'] = 0; } // Build the link tree. $context['linktree'][] = array('url' => $scripturl . '?topic=' . $topic . '.0', 'name' => $topicinfo['subject']); // Build a list of this board's moderators. $context['moderators'] =& $board_info['moderators']; $context['link_moderators'] = array(); // Information about the current topic... $context['is_locked'] = $topicinfo['locked']; $context['is_sticky'] = $topicinfo['is_sticky']; $context['is_very_hot'] = $topicinfo['num_replies'] >= $modSettings['hotTopicVeryPosts']; $context['is_hot'] = $topicinfo['num_replies'] >= $modSettings['hotTopicPosts']; $context['is_approved'] = $topicinfo['approved']; $context['is_poll'] = $topicinfo['id_poll'] > 0 && !empty($modSettings['pollMode']) && allowedTo('poll_view'); determineTopicClass($context); // Did this user start the topic or not? $context['user']['started'] = $user_info['id'] == $topicinfo['id_member_started'] && !$user_info['is_guest']; $context['topic_starter_id'] = $topicinfo['id_member_started']; // Set the topic's information for the template. $context['subject'] = $topicinfo['subject']; $context['num_views'] = $topicinfo['num_views']; $context['num_views_text'] = $context['num_views'] == 1 ? $txt['read_one_time'] : sprintf($txt['read_many_times'], $context['num_views']); $context['mark_unread_time'] = !empty($virtual_msg) ? $virtual_msg : $topicinfo['new_from']; // Set a canonical URL for this page. $context['canonical_url'] = $scripturl . '?topic=' . $topic . '.' . $context['start']; // For quick reply we need a response prefix in the default forum language. $context['response_prefix'] = response_prefix(); // If we want to show event information in the topic, prepare the data. if (allowedTo('calendar_view') && !empty($modSettings['cal_showInTopic']) && !empty($modSettings['cal_enabled'])) { // We need events details and all that jazz require_once SUBSDIR . '/Calendar.subs.php'; // First, try create a better time format, ignoring the "time" elements. if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { $date_string = $user_info['time_format']; } else { $date_string = $matches[0]; } // Get event information for this topic. $events = eventInfoForTopic($topic); $context['linked_calendar_events'] = array(); foreach ($events as $event) { // Prepare the dates for being formatted. $start_date = sscanf($event['start_date'], '%04d-%02d-%02d'); $start_date = mktime(12, 0, 0, $start_date[1], $start_date[2], $start_date[0]); $end_date = sscanf($event['end_date'], '%04d-%02d-%02d'); $end_date = mktime(12, 0, 0, $end_date[1], $end_date[2], $end_date[0]); $context['linked_calendar_events'][] = array('id' => $event['id_event'], 'title' => $event['title'], 'can_edit' => allowedTo('calendar_edit_any') || $event['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own'), 'modify_href' => $scripturl . '?action=post;msg=' . $topicinfo['id_first_msg'] . ';topic=' . $topic . '.0;calendar;eventid=' . $event['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'can_export' => allowedTo('calendar_edit_any') || $event['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own'), 'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $event['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'start_date' => standardTime($start_date, $date_string, 'none'), 'start_timestamp' => $start_date, 'end_date' => standardTime($end_date, $date_string, 'none'), 'end_timestamp' => $end_date, 'is_last' => false); } if (!empty($context['linked_calendar_events'])) { $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; $template_layers->add('display_calendar'); } } // Create the poll info if it exists. if ($context['is_poll']) { $template_layers->add('display_poll'); require_once SUBSDIR . '/Poll.subs.php'; loadPollContext($topicinfo['id_poll']); // Build the poll moderation button array. $context['poll_buttons'] = array('vote' => array('test' => 'allow_return_vote', 'text' => 'poll_return_vote', 'image' => 'poll_options.png', 'lang' => true, 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']), 'results' => array('test' => 'allow_poll_view', 'text' => 'poll_results', 'image' => 'poll_results.png', 'lang' => true, 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'), 'change_vote' => array('test' => 'allow_change_vote', 'text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'lang' => true, 'url' => $scripturl . '?action=poll;sa=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']), 'lock' => array('test' => 'allow_lock_poll', 'text' => !$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock', 'image' => 'poll_lock.png', 'lang' => true, 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']), 'edit' => array('test' => 'allow_edit_poll', 'text' => 'poll_edit', 'image' => 'poll_edit.png', 'lang' => true, 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']), 'remove_poll' => array('test' => 'can_remove_poll', 'text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['poll_remove_warn'] . '\');"', 'url' => $scripturl . '?action=poll;sa=remove;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'])); // Allow mods to add additional buttons here call_integration_hook('integrate_poll_buttons'); } // Calculate the fastest way to get the messages! $ascending = true; $start = $_REQUEST['start']; $limit = $context['messages_per_page']; $firstIndex = 0; if ($start >= $context['total_visible_posts'] / 2 && $context['messages_per_page'] != -1) { $ascending = !$ascending; $limit = $context['total_visible_posts'] <= $start + $limit ? $context['total_visible_posts'] - $start : $limit; $start = $context['total_visible_posts'] <= $start + $limit ? 0 : $context['total_visible_posts'] - $start - $limit; $firstIndex = $limit - 1; } // Taking care of member specific settings $limit_settings = array('messages_per_page' => $context['messages_per_page'], 'start' => $start, 'offset' => $limit); // Get each post and poster in this topic. $topic_details = getTopicsPostsAndPoster($topic, $limit_settings, $ascending); $messages = $topic_details['messages']; $posters = array_unique($topic_details['all_posters']); $all_posters = $topic_details['all_posters']; unset($topic_details); call_integration_hook('integrate_display_message_list', array(&$messages, &$posters)); // Guests can't mark topics read or for notifications, just can't sorry. if (!$user_info['is_guest'] && !empty($messages)) { $mark_at_msg = max($messages); if ($mark_at_msg >= $topicinfo['id_last_msg']) { $mark_at_msg = $modSettings['maxMsgID']; } if ($mark_at_msg >= $topicinfo['new_from']) { markTopicsRead(array($user_info['id'], $topic, $mark_at_msg, $topicinfo['unwatched']), $topicinfo['new_from'] !== 0); } updateReadNotificationsFor($topic, $board); // Have we recently cached the number of new topics in this board, and it's still a lot? if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) { $_SESSION['topicseen_cache'][$board]--; } elseif (isset($_REQUEST['topicseen'])) { // Use the mark read tables... and the last visit to figure out if this should be read or not. $numNewTopics = getUnreadCountSince($board, empty($_SESSION['id_msg_last_visit']) ? 0 : $_SESSION['id_msg_last_visit']); // If there're no real new topics in this board, mark the board as seen. if (empty($numNewTopics)) { $_REQUEST['boardseen'] = true; } else { $_SESSION['topicseen_cache'][$board] = $numNewTopics; } } elseif (isset($_SESSION['topicseen_cache'][$board])) { $_SESSION['topicseen_cache'][$board]--; } // Mark board as seen if we came using last post link from BoardIndex. (or other places...) if (isset($_REQUEST['boardseen'])) { require_once SUBSDIR . '/Boards.subs.php'; markBoardsRead($board, false, false); } } $attachments = array(); // If there _are_ messages here... (probably an error otherwise :!) if (!empty($messages)) { require_once SUBSDIR . '/Attachments.subs.php'; // Fetch attachments. $includeUnapproved = !$modSettings['postmod_active'] || allowedTo('approve_posts'); if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments')) { $attachments = getAttachments($messages, $includeUnapproved, 'filter_accessible_attachment', $all_posters); } $msg_parameters = array('message_list' => $messages, 'new_from' => $topicinfo['new_from']); $msg_selects = array(); $msg_tables = array(); call_integration_hook('integrate_message_query', array(&$msg_selects, &$msg_tables, &$msg_parameters)); // What? It's not like it *couldn't* be only guests in this topic... if (!empty($posters)) { loadMemberData($posters); } // Load in the likes for this group of messages if (!empty($modSettings['likes_enabled'])) { require_once SUBSDIR . '/Likes.subs.php'; $context['likes'] = loadLikes($messages, true); // ajax controller for likes loadJavascriptFile('like_posts.js', array('defer' => true)); loadLanguage('Errors'); // Initiate likes and the tooltips for likes addInlineJavascript(' $(document).ready(function () { var likePostInstance = likePosts.prototype.init({ oTxt: ({ btnText : ' . JavaScriptEscape($txt['ok_uppercase']) . ', likeHeadingError : ' . JavaScriptEscape($txt['like_heading_error']) . ', error_occurred : ' . JavaScriptEscape($txt['error_occurred']) . ' }), }); $(".like_button, .unlike_button").SiteTooltip({ hoverIntent: { sensitivity: 10, interval: 150, timeout: 50 } }); });', true); } $messages_request = loadMessageRequest($msg_selects, $msg_tables, $msg_parameters); if (!empty($modSettings['enableFollowup'])) { require_once SUBSDIR . '/FollowUps.subs.php'; $context['follow_ups'] = followupTopics($messages, $includeUnapproved); } // Go to the last message if the given time is beyond the time of the last message. if (isset($context['start_from']) && $context['start_from'] >= $topicinfo['num_replies']) { $context['start_from'] = $topicinfo['num_replies']; } // Since the anchor information is needed on the top of the page we load these variables beforehand. $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0]; $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; } else { $messages_request = false; $context['first_message'] = 0; $context['first_new_message'] = false; } $context['jump_to'] = array('label' => addslashes(un_htmlspecialchars($txt['jump_to'])), 'board_name' => htmlspecialchars(strtr(strip_tags($board_info['name']), array('&' => '&')), ENT_COMPAT, 'UTF-8'), 'child_level' => $board_info['child_level']); // Set the callback. (do you REALIZE how much memory all the messages would take?!?) // This will be called from the template. $context['get_message'] = array($this, 'prepareDisplayContext_callback'); // Now set all the wonderful, wonderful permissions... like moderation ones... $common_permissions = array('can_approve' => 'approve_posts', 'can_ban' => 'manage_bans', 'can_sticky' => 'make_sticky', 'can_merge' => 'merge_any', 'can_split' => 'split_any', 'calendar_post' => 'calendar_post', 'can_mark_notify' => 'mark_any_notify', 'can_send_topic' => 'send_topic', 'can_send_pm' => 'pm_send', 'can_send_email' => 'send_email_to_members', 'can_report_moderator' => 'report_any', 'can_moderate_forum' => 'moderate_forum', 'can_issue_warning' => 'issue_warning', 'can_restore_topic' => 'move_any', 'can_restore_msg' => 'move_any'); foreach ($common_permissions as $contextual => $perm) { $context[$contextual] = allowedTo($perm); } // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. $anyown_permissions = array('can_move' => 'move', 'can_lock' => 'lock', 'can_delete' => 'remove', 'can_add_poll' => 'poll_add', 'can_remove_poll' => 'poll_remove', 'can_reply' => 'post_reply', 'can_reply_unapproved' => 'post_unapproved_replies'); foreach ($anyown_permissions as $contextual => $perm) { $context[$contextual] = allowedTo($perm . '_any') || $context['user']['started'] && allowedTo($perm . '_own'); } // Cleanup all the permissions with extra stuff... $context['can_mark_notify'] &= !$context['user']['is_guest']; $context['can_sticky'] &= !empty($modSettings['enableStickyTopics']); $context['calendar_post'] &= !empty($modSettings['cal_enabled']) && (allowedTo('modify_any') || $context['user']['started'] && allowedTo('modify_own')); $context['can_add_poll'] &= !empty($modSettings['pollMode']) && $topicinfo['id_poll'] <= 0; $context['can_remove_poll'] &= !empty($modSettings['pollMode']) && $topicinfo['id_poll'] > 0; $context['can_reply'] &= empty($topicinfo['locked']) || allowedTo('moderate_board'); $context['can_reply_unapproved'] &= $modSettings['postmod_active'] && (empty($topicinfo['locked']) || allowedTo('moderate_board')); $context['can_issue_warning'] &= in_array('w', $context['admin_features']) && !empty($modSettings['warning_enable']); // Handle approval flags... $context['can_reply_approved'] = $context['can_reply']; $context['can_reply'] |= $context['can_reply_unapproved']; $context['can_quote'] = $context['can_reply'] && (empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']))); $context['can_mark_unread'] = !$user_info['is_guest'] && $settings['show_mark_read']; $context['can_unwatch'] = !$user_info['is_guest'] && $modSettings['enable_unwatch']; $context['can_send_topic'] = (!$modSettings['postmod_active'] || $topicinfo['approved']) && allowedTo('send_topic'); $context['can_print'] = empty($modSettings['disable_print_topic']); // Start this off for quick moderation - it will be or'd for each post. $context['can_remove_post'] = allowedTo('delete_any') || allowedTo('delete_replies') && $context['user']['started']; // Can restore topic? That's if the topic is in the recycle board and has a previous restore state. $context['can_restore_topic'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_board']); $context['can_restore_msg'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_topic']); $context['can_follow_up'] = !empty($modSettings['enableFollowup']) && boardsallowedto('post_new') !== array(); // Check if the draft functions are enabled and that they have permission to use them (for quick reply.) $context['drafts_save'] = !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply']; $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('post_autosave_draft'); if (!empty($context['drafts_save'])) { loadLanguage('Drafts'); } if (!empty($context['drafts_autosave']) && empty($options['use_editor_quick_reply'])) { loadJavascriptFile('drafts.js'); } if (!empty($modSettings['mentions_enabled'])) { $context['mentions_enabled'] = true; // Just using the plain text quick reply and not the editor if (empty($options['use_editor_quick_reply'])) { loadJavascriptFile(array('jquery.atwho.js', 'jquery.caret.min.js', 'mentioning.js')); } loadCSSFile('jquery.atwho.css'); addInlineJavascript(' $(document).ready(function () { for (var i = 0, count = all_elk_mentions.length; i < count; i++) all_elk_mentions[i].oMention = new elk_mentions(all_elk_mentions[i].oOptions); });'); } // Load up the Quick ModifyTopic and Quick Reply scripts loadJavascriptFile('topic.js'); // Auto video embeding enabled? if (!empty($modSettings['enableVideoEmbeding'])) { addInlineJavascript(' $(document).ready(function() { $().linkifyvideo(oEmbedtext); });'); } // Load up the "double post" sequencing magic. if (!empty($options['display_quick_reply'])) { checkSubmitOnce('register'); $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : ''; $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : ''; if (!empty($options['use_editor_quick_reply']) && $context['can_reply']) { // Needed for the editor and message icons. require_once SUBSDIR . '/Editor.subs.php'; // Now create the editor. $editorOptions = array('id' => 'message', 'value' => '', 'labels' => array('post_button' => $txt['post']), 'height' => '250px', 'width' => '100%', 'preview_type' => 0); create_control_richedit($editorOptions); $context['attached'] = ''; $context['make_poll'] = isset($_REQUEST['poll']); // Message icons - customized icons are off? $context['icons'] = getMessageIcons($board); if (!empty($context['icons'])) { $context['icons'][count($context['icons']) - 1]['is_last'] = true; } } } addJavascriptVar(array('notification_topic_notice' => $context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']), true); if ($context['can_send_topic']) { addJavascriptVar(array('sendtopic_cancel' => $txt['modify_cancel'], 'sendtopic_back' => $txt['back'], 'sendtopic_close' => $txt['find_close'], 'sendtopic_error' => $txt['send_error_occurred'], 'required_field' => $txt['require_field']), true); } // Build the normal button array. $context['normal_buttons'] = array('reply' => array('test' => 'can_reply', 'text' => 'reply', 'image' => 'reply.png', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true), 'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 'unnotify' : 'notify', 'image' => ($context['is_marked_notify'] ? 'un' : '') . 'notify.png', 'lang' => true, 'custom' => 'onclick="return notifyButton(this);"', 'url' => $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']), 'mark_unread' => array('test' => 'can_mark_unread', 'text' => 'mark_unread', 'image' => 'markunread.png', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']), 'unwatch' => array('test' => 'can_unwatch', 'text' => ($context['topic_unwatched'] ? '' : 'un') . 'watch', 'image' => ($context['topic_unwatched'] ? '' : 'un') . 'watched.png', 'lang' => true, 'custom' => 'onclick="return unwatchButton(this);"', 'url' => $scripturl . '?action=unwatchtopic;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['topic_unwatched'] ? 'off' : 'on') . ';' . $context['session_var'] . '=' . $context['session_id']), 'send' => array('test' => 'can_send_topic', 'text' => 'send_topic', 'image' => 'sendtopic.png', 'lang' => true, 'url' => $scripturl . '?action=emailuser;sa=sendtopic;topic=' . $context['current_topic'] . '.0', 'custom' => 'onclick="return sendtopicOverlayDiv(this.href, \'' . $txt['send_topic'] . '\');"'), 'print' => array('test' => 'can_print', 'text' => 'print', 'image' => 'print.png', 'lang' => true, 'custom' => 'rel="nofollow"', 'class' => 'new_win', 'url' => $scripturl . '?action=topic;sa=printpage;topic=' . $context['current_topic'] . '.0')); // Build the mod button array $context['mod_buttons'] = array('move' => array('test' => 'can_move', 'text' => 'move_topic', 'image' => 'admin_move.png', 'lang' => true, 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'), 'delete' => array('test' => 'can_delete', 'text' => 'remove_topic', 'image' => 'admin_rem.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['are_sure_remove_topic'] . '\');"', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']), 'lock' => array('test' => 'can_lock', 'text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'lang' => true, 'url' => $scripturl . '?action=topic;sa=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']), 'sticky' => array('test' => 'can_sticky', 'text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'lang' => true, 'url' => $scripturl . '?action=topic;sa=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']), 'merge' => array('test' => 'can_merge', 'text' => 'merge', 'image' => 'merge.png', 'lang' => true, 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']), 'calendar' => array('test' => 'calendar_post', 'text' => 'calendar_link', 'image' => 'linktocal.png', 'lang' => true, 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0')); // Restore topic. eh? No monkey business. if ($context['can_restore_topic']) { $context['mod_buttons'][] = array('text' => 'restore_topic', 'image' => '', 'lang' => true, 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); } if ($context['can_reply'] && !empty($options['display_quick_reply'])) { $template_layers->add('quickreply'); } $template_layers->add('pages_and_buttons'); // Allow adding new buttons easily. call_integration_hook('integrate_display_buttons'); call_integration_hook('integrate_mod_buttons'); }
/** * Init all variables and load the settings from the database. * Check the requests and prepare the templates to load. */ function PortaMx($doinit = false) { global $context, $modSettings, $boardurl, $scripturl, $user_info, $maintenance, $language, $pmxCacheFunc, $sc, $cookiename, $txt; // we can exit on this... if (defined('PortaMx') || isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && empty($doinit)) { if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && !empty($user_info['possibly_robot'])) { redirectexit(); } else { return; } } define('PortaMx', 1); // no sign up for robots please !! if (!empty($user_info['possibly_robot']) && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'signup') { redirectexit(); } if (empty($user_info['possibly_robot'])) { // portal enable/disable request ? if ((isset($_REQUEST['pmxportal']) || isset($_REQUEST['pmxsef'])) && allowedTo('admin_forum')) { $mode = 'pmx' . (isset($_REQUEST['pmxportal']) ? 'portal' : 'sef'); updateSettings(array($mode . '_disabled' => $_REQUEST[$mode] == 'off' ? '1' : '0')); redirectexit(); } // clear PortaMx cache request ? if (isset($_GET['action']) && isset($_GET['area']) && (in_array($_GET['action'], array('admin', 'portamx')) && $_GET['area'] == 'pmx_cache')) { if (isset($_GET[$_SESSION['session_var']]) && $_GET[$_SESSION['session_var']] == $sc) { $pmxCacheFunc['clean'](); $_SESSION['pmx_cache_cleared'] = true; } if (isset($_SESSION['pmx_last_request'])) { redirectexit($_SESSION['pmx_last_request']); } } elseif (pmx_checkECL_Cookie() && strpos($_SERVER['REQUEST_URL'], 'viewsmfile') === false) { $_SESSION['pmx_last_request'] = $_SERVER['REQUEST_URL']; } $lang = $pmxCacheFunc['get']($user_info['ip'] . '-lang'); if (!pmx_checkECL_Cookie()) { if ($lang === null) { // get browser language $browserlang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']) : ''; if (preg_match_all('~en\\b|de\\b~i', $browserlang, $temp) > 0) { $avail = array_keys(PortaMx_getLanguages()); if (in_array('de', $temp[0])) { if (in_array('german', $avail)) { $lang = 'german'; } elseif (in_array('german-utf8', $avail)) { $lang = 'german-utf8'; } } else { $lang = $language; } $_POST['language'] = $lang; $_POST['redir'] = pmx_http_build_query($_GET); } } else { $context['pmx']['currlang'] = $context['user']['language'] = $user_info['language'] = $language = $lang; } // need to releoad base language loadLanguage('index+Modifications'); } else { if ($lang !== null) { $_POST['language'] = $lang; $_POST['redir'] = pmx_http_build_query($_GET); } } // check if a language change requested if (!empty($_POST['language'])) { $pmxCacheFunc['clean'](); $context['pmx']['currlang'] = $context['user']['language'] = $user_info['language'] = $language = $_POST['language']; if (pmx_checkECL_Cookie()) { // Make it permanent for members. if (!empty($user_info['id'])) { updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); } else { $_SESSION['language'] = $user_info['language']; } } else { $pmxCacheFunc['put']($user_info['ip'] . '-lang', $language, 360, false); $_POST['redir'] = pmx_http_build_query($_GET); } if (isset($_POST['redir'])) { redirectexit($_POST['redir']); } } } if (empty($modSettings['pmx_eclmodal']) && !pmx_checkECL_Cookie() && (!empty($_REQUEST['action']) && $_REQUEST['action'] != 'xml' || !empty($_REQUEST['page']) || !empty($_REQUEST['cat']) || !empty($_REQUEST['art']))) { if (empty($user_info['possibly_robot']) && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'login') { setupMenuContext(); pmx_ECL_Error($_REQUEST['action']); } else { redirectexit(); } } // redirect on illegal request if (!empty($_REQUEST['pmxportal']) || !empty($_REQUEST['pmxsef']) || !empty($_REQUEST['pmxerror']) && !empty($_REQUEST['action'])) { redirectexit('pmxerror=unknown'); } // check if a permanent theme change requested if (isset($_REQUEST['theme']) && isset($_REQUEST['pmxrd'])) { PortaMx_ChangeTheme($_REQUEST['theme'], $_REQUEST['pmxrd']); } // load all settings PortaMx_getSettings(); // shoutbox POST request? if (!empty($_POST['pmx_shout']) && !empty($_POST['shoutbox_id'])) { PortaMx_GetShoutbox($_POST['shoutbox_id']); if (pmx_checkECL_Cookie()) { $_SESSION['pmx_shoutreload'] = true; } exit; } // exit on follow actions $rqaction = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; if (isset($_REQUEST['xml']) || in_array($rqaction, array('jseditor', 'jsoption', '.xml', 'xmlhttp', 'verificationcode', 'printpage'))) { return; } // login with redirect .. correct SEF url if ($rqaction == 'login' && !empty($_SESSION['old_url']) && function_exists('pmxsef_query')) { $_SESSION['old_url'] = $scripturl . pmx_http_build_query(pmxsef_query(rawurldecode(ltrim(str_replace($boardurl, '', $_SESSION['old_url']), '/')))); } // check if a pmxscriptdebug/pmxspidertest requested $tmp = isset($_GET['pmxscriptdebug']) ? 'pmxscriptdebug' : (isset($_GET['pmxspidertest']) ? 'pmxspidertest' : ''); if (!empty($tmp) && in_array($_GET[$tmp], array('on', 'off'))) { if (allowPmx('pmx_admin')) { if ($tmp == 'pmxscriptdebug') { pmx_setcookie($tmp, $_GET[$tmp] == 'on' ? '1' : ''); unset($_GET[$tmp]); redirectexit(pmx_http_build_query($_GET)); } elseif ($tmp == 'pmxspidertest' && $_GET[$tmp] == 'on' && !empty($modSettings['pmx_ecl'])) { $logCook = pmx_getcookie($cookiename); pmx_setcookie($tmp, $logCook); pmx_setcookie($cookiename, ''); pmx_setcookie('pmx_eclauth', ''); pmx_setcookie('PHPSESSID', ''); unset($logCook); redirectexit(); } } elseif ($tmp == 'pmxspidertest' && $_GET[$tmp] == 'off' && pmx_getcookie('pmxspidertest')) { $udata = pmx_getcookie($tmp); if (isset($udata) && is_array($dtmp = unserialize($udata)) && count($dtmp == 4)) { pmx_setECL_Cookie(); pmx_setcookie($cookiename, $udata, $dtmp[2]); unset($dtmp); unset($udata); } pmx_setcookie('pmxspidertest', ''); redirectexit(); } } // load common javascript loadJavascriptFile(PortaMx_loadCompressed('PortaMx.js'), array('external' => true)); addInlineJavascript(' var pmx_restore_top = ' . intval(!empty($context['pmx']['settings']['restoretop'])) . ';'); if ($doinit || !empty($modSettings['pmxportal_disabled'])) { loadLanguage($context['pmx_templatedir'] . 'PortaMx'); loadCSSFile(PortaMx_loadCompressed('portamx.css'), array('external' => true)); return; } // on Admin or Moderate load admin language, css and javascript if (($rqaction == 'admin' || $rqaction == 'portamx') && isset($_REQUEST['area']) && in_array($_REQUEST['area'], explode(',', $context['pmx']['areas']))) { loadJavascriptFile(PortaMx_loadCompressed('PortaMxAdmin.js'), array('external' => true)); loadCSSFile(PortaMx_loadCompressed('portamx_admin.css'), array('external' => true)); loadLanguage($context['pmx_templatedir'] . 'Admin'); addInlineJavascript("\n\t" . 'BlockActive=\'' . $txt['pmx_status_activ'] . ' - ' . $txt['pmx_status_change'] . '\';' . "\n\t" . 'BlockInactive=\'' . $txt['pmx_status_inactiv'] . ' - ' . $txt['pmx_status_change'] . '\';'); } // Error request? if (!empty($_REQUEST['pmxerror'])) { return PmxError(); } // check Error request, Forum request $context['pmx']['forumReq'] = !empty($_REQUEST['action']) || !empty($context['current_board']) || !empty($context['current_topic']); if (empty($context['pmx']['forumReq']) && !empty($context['pmx']['settings']['other_actions'])) { $reqtyp = Pmx_StrToArray($context['pmx']['settings']['other_actions']); foreach ($reqtyp as $rtyp) { @(list($rtyp, $rval) = Pmx_StrToArray($rtyp, '=')); $context['pmx']['forumReq'] = $context['pmx']['forumReq'] || isset($_REQUEST[$rtyp]) && (is_null($rval) || $_REQUEST[$rtyp] == $rval); } } // check Page, category, article request $pmxRequestTypes = array('spage', 'art', 'cat', 'child'); $context['pmx']['pageReq'] = array(); foreach ($pmxRequestTypes as $type) { if (empty($_REQUEST['action']) && !empty($_REQUEST[$type])) { $context['pmx']['pageReq'][$type] = PortaMx_makeSafe($_REQUEST[$type]); } } // no request on forum or pages and no frontpage .. go to forum if (empty($context['pmx']['forumReq']) && empty($context['pmx']['pageReq']) && $context['pmx']['settings']['frontpage'] == 'none') { $_REQUEST['action'] = $_GET['action'] = 'community'; $context['pmx']['forumReq'] = true; } // Disable HighSlide on action? if (isset($_REQUEST['action']) && isset($context['pmx']['settings']['noHS_onaction'])) { $noHighSlide = isset($context['pmx']['settings']['noHS_onaction']) ? Pmx_StrToArray($context['pmx']['settings']['noHS_onaction']) : array(); if (in_array($_REQUEST['action'], $noHighSlide)) { $context['pmx']['settings']['disableHS'] = 1; } } // Admin panel/block hidding ? $hideRequest = array_intersect($context['pmx']['extracmd'], array_keys($_REQUEST)); if (!empty($hideRequest) && allowPmx('pmx_admin')) { @(list($hideRequest) = array_values($hideRequest)); $mode = substr($hideRequest, 5); $hidetyp = substr($hideRequest, 0, 5); $offparts = empty($modSettings['pmx_' . $hidetyp . 'off']) ? array() : Pmx_StrToArray($modSettings['pmx_' . $hidetyp . 'off']); if ($mode == 'off') { if ($hidetyp == 'panel') { $offparts = array_intersect($_REQUEST[$hideRequest] == 'all' ? $context['pmx']['block_sides'] : array_merge($offparts, Pmx_StrToArray($_REQUEST[$hideRequest])), $context['pmx']['block_sides']); } else { $offparts = array_merge($offparts, Pmx_StrToIntArray($_REQUEST[$hideRequest])); } } else { if ($hidetyp == 'panel') { $offparts = array_intersect($_REQUEST[$hideRequest] == 'all' ? array() : array_diff($offparts, Pmx_StrToArray($_REQUEST[$hideRequest])), $context['pmx']['block_sides']); } else { $offparts = $_REQUEST[$hideRequest] == 'all' ? array() : array_diff($offparts, Pmx_StrToIntArray($_REQUEST[$hideRequest])); } } updateSettings(array('pmx_' . $hidetyp . 'off' => implode(',', $offparts))); unset($_GET[$hideRequest]); redirectexit(pmx_http_build_query($_GET)); } // check all the actions and more... if (empty($context['pmx']['forumReq'])) { // if a redirect request, exit $requrl = strpos($_SERVER['REQUEST_URL'], substr($scripturl, 0, strrpos($scripturl, '/'))) === false ? $_SERVER['REQUEST_URL'] : $scripturl; if (substr($requrl, 0, strrpos($requrl, '/')) != substr($scripturl, 0, strrpos($scripturl, '/'))) { return; } // we use the frontpage ? $useFront = $context['pmx']['settings']['frontpage'] == 'none' && empty($context['pmx']['pageReq']) ? '' : 'frontpage'; // get all block on active panels they can view $context['pmx']['viewblocks'] = getPanelsToShow($useFront); // frontpage and/or Page blocks exist ? if (!empty($maintenance) && $context['pmx']['settings']['frontpage'] != 'none' || empty($useFront) || !empty($context['pmx']['show_pagespanel']) || !empty($context['pmx']['show_frontpanel']) && $context['pmx']['settings']['frontpage'] != 'none') { // setup headers PortaMx_headers('frontpage'); $context['robot_no_index'] = empty($context['pmx']['settings']['indexfront']); if ($context['pmx']['settings']['frontpage'] == 'fullsize') { loadTemplate($context['pmx_templatedir'] . 'Frontpage'); $context['template_layers'] = array('fronthtml', 'portamx'); call_integration_hook('integrate_load_theme'); } else { loadTemplate($context['pmx_templatedir'] . 'Mainindex'); $context['template_layers'][] = 'portamx'; } if (!empty($context['pmx']['pageReq']) || empty($context['pmx']['forumReq']) && $context['pmx']['settings']['frontpage'] != 'none') { loadTemplate($context['pmx_templatedir'] . 'PortaMx'); } } else { // page req error? if (!empty($context['pmx']['pageReq']) && empty($context['pmx']['show_pagespanel'])) { redirectexit('pmxerror=page'); } // else go to forum $_REQUEST['action'] = $_GET['action'] = !empty($maintenance) && empty($user_info['is_admin']) ? '' : 'community'; $context['pmx']['forumReq'] = true; $context['pmx']['viewblocks'] = null; } } if (!empty($context['pmx']['forumReq'])) { // get the action $action = isset($_REQUEST['action']) ? $_REQUEST['action'] == 'collapse' ? 'community' : $_REQUEST['action'] : (isset($_REQUEST['board']) ? 'boards' : (isset($_REQUEST['topic']) ? 'topics' : '')); // get all block on active panels they can view $context['pmx']['viewblocks'] = getPanelsToShow($action); // setup headers PortaMx_headers($action); // load the "Main" template on pages, cats or arts if (!empty($context['pmx']['pageReq'])) { loadTemplate($context['pmx_templatedir'] . 'PortaMx'); } loadTemplate($context['pmx_templatedir'] . 'Mainindex'); $context['template_layers'][] = 'portamx'; } // Load the Frame template loadTemplate($context['pmx_templatedir'] . 'Frames'); // supress these links if ECL not accepted if (!empty($rqaction) && !pmx_checkECL_Cookie() && isset($modSettings['pmx_eclmodalaction']) && in_array($rqaction, Pmx_StrToArray($modSettings['pmx_eclmodalaction']))) { pmx_ECL_Error('request'); } // Create the linktree return pmx_MakeLinktree(); }
/** * <b>Internal function! Do not use it, use loadTemplate instead</b> * * What it does: * - loads a template file with the name template_name from the current, default, or base theme. * - detects a wrong default theme directory and tries to work around it. * - can be used to only load style sheets by using false as the template name * loading of style sheets with this function is @deprecated, use loadCSSFile instead * * @uses the template_include() function to include the file. * @param string|false $template_name * @param string[]|string $style_sheets any style sheets to load with the template * @param bool $fatal = true if fatal is true, dies with an error message if the template cannot be found * * @return boolean|null */ function requireTemplate($template_name, $style_sheets, $fatal) { global $context, $settings, $txt, $scripturl, $db_show_debug; static $default_loaded = false; if (!is_array($style_sheets)) { $style_sheets = array($style_sheets); } if ($default_loaded === false) { loadCSSFile('index.css'); $default_loaded = true; } // Any specific template style sheets to load? if (!empty($style_sheets)) { $sheets = array(); foreach ($style_sheets as $sheet) { $sheets[] = stripos('.css', $sheet) !== false ? $sheet : $sheet . '.css'; if ($sheet == 'admin' && !empty($context['theme_variant'])) { $sheets[] = $context['theme_variant'] . '/admin' . $context['theme_variant'] . '.css'; } } loadCSSFile($sheets); } // No template to load? if ($template_name === false) { return true; } $loaded = false; foreach ($settings['template_dirs'] as $template_dir) { if (file_exists($template_dir . '/' . $template_name . '.template.php')) { $loaded = true; template_include($template_dir . '/' . $template_name . '.template.php', true); break; } } if ($loaded) { if ($db_show_debug === true) { $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; } // If they have specified an initialization function for this template, go ahead and call it now. if (function_exists('template_' . $template_name . '_init')) { call_user_func('template_' . $template_name . '_init'); } } elseif (!file_exists($settings['default_theme_dir']) && file_exists(BOARDDIR . '/themes/default')) { $settings['default_theme_dir'] = BOARDDIR . '/themes/default'; $settings['template_dirs'][] = $settings['default_theme_dir']; if (!empty($context['user']['is_admin']) && !isset($_GET['th'])) { loadLanguage('Errors'); if (!isset($context['security_controls_files']['title'])) { $context['security_controls_files']['title'] = $txt['generic_warning']; } $context['security_controls_files']['errors']['theme_dir'] = '<a href="' . $scripturl . '?action=admin;area=theme;sa=list;th=1;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['theme_dir_wrong'] . '</a>'; } loadTemplate($template_name); } elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); } elseif ($fatal) { die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load themes/default/%s.template.php!', (string) $template_name), 'template')); } else { return false; } }
/** * Sets up the basic theme context stuff. * * @param bool $forceload = false */ function setupThemeContext($forceload = false) { global $modSettings, $user_info, $scripturl, $context, $settings, $options, $txt; global $user_settings; static $loaded = false; // Under SSI this function can be called more then once. That can cause some problems. // So only run the function once unless we are forced to run it again. if ($loaded && !$forceload) { return; } $loaded = true; $context['current_time'] = standardTime(time(), false); $context['current_action'] = isset($_GET['action']) ? $_GET['action'] : ''; $context['show_quick_login'] = !empty($modSettings['enableVBStyleLogin']) && $user_info['is_guest']; // Get some news... $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) { if (trim($context['news_lines'][$i]) == '') { continue; } // Clean it up for presentation ;). $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); } if (!empty($context['news_lines'])) { $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; $context['upper_content_callbacks'][] = 'news_fader'; } if (!$user_info['is_guest']) { $context['user']['messages'] =& $user_info['messages']; $context['user']['unread_messages'] =& $user_info['unread_messages']; $context['user']['mentions'] =& $user_info['mentions']; // Personal message popup... if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { $context['user']['popup_messages'] = true; } else { $context['user']['popup_messages'] = false; } $_SESSION['unread_messages'] = $user_info['unread_messages']; $context['user']['avatar'] = array('href' => !empty($user_info['avatar']['href']) ? $user_info['avatar']['href'] : '', 'image' => !empty($user_info['avatar']['image']) ? $user_info['avatar']['image'] : ''); // @deprecated since 1.0.2 if (!empty($modSettings['avatar_max_width'])) { $context['user']['avatar']['width'] = $modSettings['avatar_max_width']; } // @deprecated since 1.0.2 if (!empty($modSettings['avatar_max_height'])) { $context['user']['avatar']['height'] = $modSettings['avatar_max_height']; } // Figure out how long they've been logged in. $context['user']['total_time_logged_in'] = array('days' => floor($user_info['total_time_logged_in'] / 86400), 'hours' => floor($user_info['total_time_logged_in'] % 86400 / 3600), 'minutes' => floor($user_info['total_time_logged_in'] % 3600 / 60)); } else { $context['user']['messages'] = 0; $context['user']['unread_messages'] = 0; $context['user']['mentions'] = 0; $context['user']['avatar'] = array(); $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); $context['user']['popup_messages'] = false; if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { $txt['welcome_guest'] .= $txt['welcome_guest_activate']; } $txt['welcome_guest'] = replaceBasicActionUrl($txt['welcome_guest']); // If we've upgraded recently, go easy on the passwords. if (!empty($modSettings['enable_password_conversion'])) { $context['disable_login_hashing'] = true; } } // Setup the main menu items. setupMenuContext(); if (empty($settings['theme_version'])) { $context['show_vBlogin'] = $context['show_quick_login']; } // This is here because old index templates might still use it. $context['show_news'] = !empty($settings['enable_news']); $context['additional_dropdown_search'] = prepareSearchEngines(); // This is done to allow theme authors to customize it as they want. $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); // Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. if ($context['show_pm_popup']) { addInlineJavascript(' $(document).ready(function(){ new smc_Popup({ heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', content: ' . JavaScriptEscape(sprintf($txt['show_personal_messages'], $context['user']['unread_messages'], $scripturl . '?action=pm')) . ', icon: elk_images_url + \'/im_sm_newmsg.png\' }); });', true); } // This looks weird, but it's because BoardIndex.controller.php references the variable. $context['common_stats']['latest_member'] = array('id' => $modSettings['latestMember'], 'name' => $modSettings['latestRealName'], 'href' => $scripturl . '?action=profile;u=' . $modSettings['latestMember'], 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $modSettings['latestMember'] . '">' . $modSettings['latestRealName'] . '</a>'); $context['common_stats'] = array('total_posts' => comma_format($modSettings['totalMessages']), 'total_topics' => comma_format($modSettings['totalTopics']), 'total_members' => comma_format($modSettings['totalMembers']), 'latest_member' => $context['common_stats']['latest_member']); $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); if (empty($settings['theme_version'])) { addJavascriptVar(array('elk_scripturl' => '\'' . $scripturl . '\'')); } if (!isset($context['page_title'])) { $context['page_title'] = ''; } // Set some specific vars. $context['page_title_html_safe'] = Util::htmlspecialchars(un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); $context['meta_keywords'] = !empty($modSettings['meta_keywords']) ? Util::htmlspecialchars($modSettings['meta_keywords']) : ''; // Load a custom CSS file? if (file_exists($settings['theme_dir'] . '/css/custom.css')) { loadCSSFile('custom.css'); } if (!empty($context['theme_variant']) && file_exists($settings['theme_dir'] . '/css/' . $context['theme_variant'] . '/custom' . $context['theme_variant'] . '.css')) { loadCSSFile($context['theme_variant'] . '/custom' . $context['theme_variant'] . '.css'); } }
/** * Initializes the portal, outputs all the blocks as needed * * @param boolean $standalone */ function sportal_init($standalone = false) { global $context, $scripturl, $modSettings, $settings, $maintenance, $sportal_version; $sportal_version = '1.0.0 Beta 1'; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') { return; } if ((isset($_REQUEST['xml']) || isset($_REQUEST['api'])) && (isset($_REQUEST['action']) && $_REQUEST['action'] !== 'shoutbox')) { return; } // Not running standalone then we need to load in some template information if (!$standalone) { // Load the portal css and the default css if its not yet loaded. loadCSSFile('portal.css'); // rtl css as well? if (!empty($context['right_to_left'])) { loadCSSFile('portal_rtl.css'); } if (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], array('admin'))) { loadLanguage('SPortalAdmin', sp_languageSelect('SPortalAdmin')); } if (!isset($settings['sp_images_url'])) { if (file_exists($settings['theme_dir'] . '/images/sp')) { $settings['sp_images_url'] = $settings['theme_url'] . '/images/sp'; } else { $settings['sp_images_url'] = $settings['default_theme_url'] . '/images/sp'; } } } // Portal not enabled, or mobile, or debug, or maintenance, or .... then bow out now if (!empty($modSettings['sp_disableMobile']) && empty($_GET['page']) && empty($_GET['article']) || !empty($settings['disable_sp']) || empty($modSettings['sp_portal_mode']) || (!empty($modSettings['sp_maintenance']) || !empty($maintenance)) && !allowedTo('admin_forum') || isset($_GET['debug']) || empty($modSettings['allow_guestAccess']) && $context['user']['is_guest']) { $context['disable_sp'] = true; if ($standalone) { $get_string = ''; foreach ($_GET as $get_var => $get_value) { $get_string .= $get_var . (!empty($get_value) ? '=' . $get_value : '') . ';'; } redirectexit(substr($get_string, 0, -1)); } return; } // Not standalone means we need to load some portal specific information in to context if (!$standalone) { require_once SUBSDIR . '/PortalBlocks.subs.php'; // Not running via ssi then we need to get SSI for its functions if (ELK !== 'SSI') { require_once BOARDDIR . '/SSI.php'; } // Portal specific templates and language loadTemplate('Portal'); loadLanguage('SPortal', sp_languageSelect('SPortal')); if (!empty($modSettings['sp_maintenance']) && !allowedTo('sp_admin')) { $modSettings['sp_portal_mode'] = 0; } if (empty($modSettings['sp_standalone_url'])) { $modSettings['sp_standalone_url'] = ''; } if ($modSettings['sp_portal_mode'] == 3) { $context += array('portal_url' => $modSettings['sp_standalone_url'], 'page_title' => $context['forum_name']); } else { $context += array('portal_url' => $scripturl); } if ($modSettings['sp_portal_mode'] == 1) { $context['linktree'][0] = array('url' => $scripturl . '?action=forum', 'name' => $context['forum_name']); } if (!empty($context['linktree']) && $modSettings['sp_portal_mode'] == 1) { foreach ($context['linktree'] as $key => $tree) { if (strpos($tree['url'], '#c') !== false && strpos($tree['url'], 'action=forum#c') === false) { $context['linktree'][$key]['url'] = str_replace('#c', '?action=forum#c', $tree['url']); } } } } else { $_GET['action'] = 'portal'; } // Load the headers if necessary. sportal_init_headers(); // Load permissions sportal_load_permissions(); // Play with our blocks $context['standalone'] = $standalone; sportal_load_blocks(); $context['SPortal']['on_portal'] = getShowInfo(0, 'portal', ''); if (!Template_Layers::getInstance()->hasLayers(true) && !in_array('portal', Template_Layers::getInstance()->getLayers())) { Template_Layers::getInstance()->add('portal'); } }
/** * Profile fields hook, integrate_' . $hook . '_profile_fields * integrate_account_profile_fields * * - Called from Profile.subs.php / setupProfileContext * - Used to add additional sections to the profile context areas * - Here we inject JS when the account page is loaded. * * @param mixed[] $fields */ function iapf_pwentropy(&$fields) { global $modSettings; if (empty($modSettings['pwentropy_enabled'])) { return; } // Attach our JS if they are changing authentication passwords loadJavascriptFile('pwentropy.js'); loadCSSFile('pwentropy.css'); load_pwentropy_js('passwrd1', 'passwrd1'); }
/** * Handles showing the post screen, loading the post to be modified, and loading any post quoted. * * - additionally handles previews of posts. * - requires different permissions depending on the actions, but most notably post_new, post_reply_own, and post_reply_any. * - shows options for the editing and posting of calendar events and attachments, as well as the posting of polls. * - accessed from ?action=post. * * @uses the Post template and language file, main sub template. */ public function action_post() { global $txt, $scripturl, $topic, $modSettings, $board, $user_info, $context, $options; loadLanguage('Post'); loadLanguage('Errors'); require_once SOURCEDIR . '/AttachmentErrorContext.class.php'; // You can't reply with a poll... hacker. if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) { unset($_REQUEST['poll']); } $post_errors = Error_Context::context('post', 1); $attach_errors = Attachment_Error_Context::context(); $attach_errors->activate(); $first_subject = ''; // Posting an event? $context['make_event'] = isset($_REQUEST['calendar']); $context['robot_no_index'] = true; $template_layers = Template_Layers::getInstance(); $template_layers->add('postarea'); // You must be posting to *some* board. if (empty($board) && !$context['make_event']) { fatal_lang_error('no_board', false); } if ($context['make_event']) { $template_layers->add('make_event'); } // All those wonderful modifiers and attachments $template_layers->add('additional_options', 200); require_once SUBSDIR . '/Post.subs.php'; require_once SUBSDIR . '/Messages.subs.php'; require_once SUBSDIR . '/Topic.subs.php'; if (isset($_REQUEST['xml'])) { $context['sub_template'] = 'post'; // Just in case of an earlier error... $context['preview_message'] = ''; $context['preview_subject'] = ''; } if (!empty($modSettings['mentions_enabled']) && !empty($_REQUEST['uid'])) { $context['member_ids'] = array_unique(array_map('intval', $_REQUEST['uid'])); } // No message is complete without a topic. if (empty($topic) && !empty($_REQUEST['msg'])) { $topic = associatedTopic((int) $_REQUEST['msg']); if (empty($topic)) { unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); } } // Check if it's locked. It isn't locked if no topic is specified. if (!empty($topic)) { list($locked, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $lastPostTime) = array_values(topicUserAttributes($topic, $user_info['id'])); // If this topic already has a poll, they sure can't add another. if (isset($_REQUEST['poll']) && $pollID > 0) { unset($_REQUEST['poll']); } if (empty($_REQUEST['msg'])) { if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) { is_not_guest(); } // By default the reply will be approved... $context['becomes_approved'] = true; if ($id_member_poster != $user_info['id']) { if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { $context['becomes_approved'] = false; } else { isAllowedTo('post_reply_any'); } } elseif (!allowedTo('post_reply_any')) { if ($modSettings['postmod_active']) { if (allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) { $context['becomes_approved'] = false; } elseif ($user_info['is_guest'] && allowedTo('post_unapproved_replies_any')) { $context['becomes_approved'] = false; } else { isAllowedTo('post_reply_own'); } } else { isAllowedTo('post_reply_own'); } } } else { $context['becomes_approved'] = true; } $context['can_lock'] = allowedTo('lock_any') || $user_info['id'] == $id_member_poster && allowedTo('lock_own'); $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']); $context['notify'] = !empty($context['notify']); $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; // It's a new reply if (empty($_REQUEST['msg'])) { $context['can_add_poll'] = false; } else { $context['can_add_poll'] = (allowedTo('poll_add_any') || !empty($_REQUEST['msg']) && $id_first_msg == $_REQUEST['msg'] && allowedTo('poll_add_own')) && !empty($modSettings['pollMode']) && $pollID <= 0; } } else { $context['becomes_approved'] = true; if (!$context['make_event'] || !empty($board)) { if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { $context['becomes_approved'] = false; } else { isAllowedTo('post_new'); } } $locked = 0; // @todo These won't work if you're making an event. $context['can_lock'] = allowedTo(array('lock_any', 'lock_own')); $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']); $context['notify'] = !empty($context['notify']); $context['sticky'] = !empty($_REQUEST['sticky']); $context['can_add_poll'] = (allowedTo('poll_add_any') || allowedTo('poll_add_own')) && !empty($modSettings['pollMode']); } // @todo These won't work if you're posting an event! $context['can_notify'] = allowedTo('mark_any_notify'); $context['can_move'] = allowedTo('move_any'); $context['move'] = !empty($_REQUEST['move']); $context['announce'] = !empty($_REQUEST['announce']); if ($context['can_add_poll']) { addJavascriptVar(array('poll_remove' => $txt['poll_remove'], 'poll_add' => $txt['add_poll']), true); } // You can only announce topics that will get approved... $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved']; $context['locked'] = !empty($locked) || !empty($_REQUEST['lock']); $context['can_quote'] = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); // Generally don't show the approval box... (Assume we want things approved) $context['show_approval'] = allowedTo('approve_posts') && $context['becomes_approved'] ? 2 : (allowedTo('approve_posts') ? 1 : 0); // An array to hold all the attachments for this topic. $context['attachments']['current'] = array(); // Don't allow a post if it's locked and you aren't all powerful. if ($locked && !allowedTo('moderate_board')) { fatal_lang_error('topic_locked', false); } // Check the users permissions - is the user allowed to add or post a poll? if (isset($_REQUEST['poll']) && !empty($modSettings['pollMode'])) { // New topic, new poll. if (empty($topic)) { isAllowedTo('poll_post'); } elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) { isAllowedTo('poll_add_own'); } else { isAllowedTo('poll_add_any'); } $context['can_moderate_poll'] = true; require_once SUBSDIR . '/Members.subs.php'; $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); // Set up the poll options. $context['poll'] = array('max_votes' => empty($_POST['poll_max_votes']) ? '1' : max(1, $_POST['poll_max_votes']), 'hide_results' => empty($_POST['poll_hide']) ? 0 : $_POST['poll_hide'], 'expiration' => !isset($_POST['poll_expire']) ? '' : $_POST['poll_expire'], 'change_vote' => isset($_POST['poll_change_vote']), 'guest_vote' => isset($_POST['poll_guest_vote']), 'guest_vote_allowed' => in_array(-1, $allowedVoteGroups['allowed'])); // Make all five poll choices empty. $context['choices'] = array(array('id' => 0, 'number' => 1, 'label' => '', 'is_last' => false), array('id' => 1, 'number' => 2, 'label' => '', 'is_last' => false), array('id' => 2, 'number' => 3, 'label' => '', 'is_last' => false), array('id' => 3, 'number' => 4, 'label' => '', 'is_last' => false), array('id' => 4, 'number' => 5, 'label' => '', 'is_last' => true)); $context['last_choice_id'] = 4; } if ($context['make_event']) { // They might want to pick a board. if (!isset($context['current_board'])) { $context['current_board'] = 0; } // Start loading up the event info. $context['event'] = array(); $context['event']['title'] = isset($_REQUEST['evtitle']) ? htmlspecialchars(stripslashes($_REQUEST['evtitle']), ENT_COMPAT, 'UTF-8') : ''; $context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1; $context['event']['new'] = $context['event']['id'] == -1; // Permissions check! isAllowedTo('calendar_post'); // Editing an event? (but NOT previewing!?) if (empty($context['event']['new']) && !isset($_REQUEST['subject'])) { // If the user doesn't have permission to edit the post in this topic, redirect them. if ((empty($id_member_poster) || $id_member_poster != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any')) { require_once CONTROLLERDIR . '/Calendar.controller.php'; $controller = new Calendar_Controller(); return $controller->action_post(); } // Get the current event information. require_once SUBSDIR . '/Calendar.subs.php'; $event_info = getEventProperties($context['event']['id']); // Make sure the user is allowed to edit this event. if ($event_info['member'] != $user_info['id']) { isAllowedTo('calendar_edit_any'); } elseif (!allowedTo('calendar_edit_any')) { isAllowedTo('calendar_edit_own'); } $context['event']['month'] = $event_info['month']; $context['event']['day'] = $event_info['day']; $context['event']['year'] = $event_info['year']; $context['event']['title'] = $event_info['title']; $context['event']['span'] = $event_info['span']; } else { // Posting a new event? (or preview...) $today = getdate(); // You must have a month and year specified! if (!isset($_REQUEST['month'])) { $_REQUEST['month'] = $today['mon']; } if (!isset($_REQUEST['year'])) { $_REQUEST['year'] = $today['year']; } $context['event']['month'] = (int) $_REQUEST['month']; $context['event']['year'] = (int) $_REQUEST['year']; $context['event']['day'] = isset($_REQUEST['day']) ? $_REQUEST['day'] : ($_REQUEST['month'] == $today['mon'] ? $today['mday'] : 0); $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1; // Make sure the year and month are in the valid range. if ($context['event']['month'] < 1 || $context['event']['month'] > 12) { fatal_lang_error('invalid_month', false); } if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) { fatal_lang_error('invalid_year', false); } // Get a list of boards they can post in. require_once SUBSDIR . '/Boards.subs.php'; $boards = boardsAllowedTo('post_new'); if (empty($boards)) { fatal_lang_error('cannot_post_new', 'user'); } // Load a list of boards for this event in the context. $boardListOptions = array('included_boards' => in_array(0, $boards) ? null : $boards, 'not_redirection' => true, 'selected_board' => empty($context['current_board']) ? $modSettings['cal_defaultboard'] : $context['current_board']); $context += getBoardList($boardListOptions); } // Find the last day of the month. $context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year'])); $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard']; } // See if any new replies have come along. if (empty($_REQUEST['msg']) && !empty($topic)) { if (empty($options['no_new_reply_warning']) && isset($_REQUEST['last_msg']) && $context['topic_last_message'] > $_REQUEST['last_msg']) { $context['new_replies'] = countMessagesSince($topic, (int) $_REQUEST['last_msg'], false, $modSettings['postmod_active'] && !allowedTo('approve_posts')); if (!empty($context['new_replies'])) { if ($context['new_replies'] == 1) { $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; } else { $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); } $post_errors->addError('new_replies', 0); $modSettings['topicSummaryPosts'] = $context['new_replies'] > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts']; } } } // Get a response prefix (like 'Re:') in the default forum language. $context['response_prefix'] = response_prefix(); // Previewing, modifying, or posting? // Do we have a body, but an error happened. if (isset($_REQUEST['message']) || $post_errors->hasErrors() || $attach_errors->hasErrors()) { // Validate inputs. if (!$post_errors->hasErrors() && !$attach_errors->hasErrors()) { // This means they didn't click Post and get an error. $really_previewing = true; } else { if (!isset($_REQUEST['subject'])) { $_REQUEST['subject'] = ''; } if (!isset($_REQUEST['message'])) { $_REQUEST['message'] = ''; } if (!isset($_REQUEST['icon'])) { $_REQUEST['icon'] = 'xx'; } // They are previewing if they asked to preview (i.e. came from quick reply). $really_previewing = !empty($_REQUEST['preview']); } // In order to keep the approval status flowing through, we have to pass it through the form... $context['becomes_approved'] = empty($_REQUEST['not_approved']); $context['show_approval'] = isset($_REQUEST['approve']) ? $_REQUEST['approve'] ? 2 : 1 : 0; $context['can_announce'] &= $context['becomes_approved']; // Set up the inputs for the form. $form_subject = strtr(Util::htmlspecialchars($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => '')); $form_message = Util::htmlspecialchars($_REQUEST['message'], ENT_QUOTES); // Make sure the subject isn't too long - taking into account special characters. if (Util::strlen($form_subject) > 100) { $form_subject = Util::substr($form_subject, 0, 100); } if (isset($_REQUEST['poll'])) { $context['poll']['question'] = isset($_REQUEST['question']) ? Util::htmlspecialchars(trim($_REQUEST['question'])) : ''; $context['choices'] = array(); $choice_id = 0; $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); foreach ($_POST['options'] as $option) { if (trim($option) == '') { continue; } $context['choices'][] = array('id' => $choice_id++, 'number' => $choice_id, 'label' => $option, 'is_last' => false); } // One empty option for those with js disabled...I know are few... :P $context['choices'][] = array('id' => $choice_id++, 'number' => $choice_id, 'label' => '', 'is_last' => false); if (count($context['choices']) < 2) { $context['choices'][] = array('id' => $choice_id++, 'number' => $choice_id, 'label' => '', 'is_last' => false); } $context['last_choice_id'] = $choice_id; $context['choices'][count($context['choices']) - 1]['is_last'] = true; } // Are you... a guest? if ($user_info['is_guest']) { $context['name'] = !isset($_REQUEST['guestname']) ? '' : Util::htmlspecialchars(trim($_REQUEST['guestname'])); $context['email'] = !isset($_REQUEST['email']) ? '' : Util::htmlspecialchars(trim($_REQUEST['email'])); $user_info['name'] = $context['name']; } // Only show the preview stuff if they hit Preview. if (($really_previewing === true || isset($_REQUEST['xml'])) && !isset($_REQUEST['save_draft'])) { // Set up the preview message and subject $context['preview_message'] = $form_message; preparsecode($form_message, true); // Do all bulletin board code thing on the message preparsecode($context['preview_message']); $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1); censorText($context['preview_message']); // Don't forget the subject $context['preview_subject'] = $form_subject; censorText($context['preview_subject']); // Any errors we should tell them about? if ($form_subject === '') { $post_errors->addError('no_subject'); $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; } if ($context['preview_message'] === '') { $post_errors->addError('no_message'); } elseif (!empty($modSettings['max_messageLength']) && Util::strlen($form_message) > $modSettings['max_messageLength']) { $post_errors->addError(array('long_message', array($modSettings['max_messageLength']))); } // Protect any CDATA blocks. if (isset($_REQUEST['xml'])) { $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); } } // Set up the checkboxes. $context['notify'] = !empty($_REQUEST['notify']); $context['use_smileys'] = !isset($_REQUEST['ns']); $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx'; // Set the destination action for submission. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : ''); $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post']; // Previewing an edit? if (isset($_REQUEST['msg']) && !empty($topic)) { require_once SUBSDIR . '/Messages.subs.php'; // Get the existing message. $message = messageDetails((int) $_REQUEST['msg'], $topic); // The message they were trying to edit was most likely deleted. // @todo Change this error message? if ($message === false) { fatal_lang_error('no_board', false); } $errors = checkMessagePermissions($message['message']); if (!empty($errors)) { foreach ($errors as $error) { $post_errors->addError($error); } } prepareMessageContext($message); } elseif (isset($_REQUEST['last_msg'])) { list($form_subject, ) = getFormMsgSubject(false, $topic, $first_subject); } // No check is needed, since nothing is really posted. checkSubmitOnce('free'); } elseif (isset($_REQUEST['msg']) && !empty($topic)) { $_REQUEST['msg'] = (int) $_REQUEST['msg']; $message = getFormMsgSubject(true, $topic); if (!empty($message['errors'])) { foreach ($errors as $error) { $post_errors->addError($error); } } // Get the stuff ready for the form. $form_subject = $message['message']['subject']; $form_message = un_preparsecode($message['message']['body']); censorText($form_message); censorText($form_subject); // Check the boxes that should be checked. $context['use_smileys'] = !empty($message['message']['smileys_enabled']); $context['icon'] = $message['message']['icon']; // Set the destination. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : ''); $context['submit_label'] = $txt['save']; } else { // By default.... $context['use_smileys'] = true; $context['icon'] = 'xx'; if ($user_info['is_guest']) { $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : ''; $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : ''; } $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : ''); $context['submit_label'] = $txt['post']; list($form_subject, $form_message) = getFormMsgSubject(false, $topic, $first_subject); } // Check whether this is a really old post being bumped... if (!empty($topic) && !empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) { $post_errors->addError(array('old_topic', array($modSettings['oldTopicDays'])), 0); } // Are we moving a discussion to its own topic? if (!empty($modSettings['enableFollowup']) && !empty($_REQUEST['followup'])) { $context['original_post'] = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : (int) $_REQUEST['followup']; $context['show_boards_dropdown'] = true; require_once SUBSDIR . '/Boards.subs.php'; $context += getBoardList(array('not_redirection' => true, 'allowed_to' => 'post_new')); $context['boards_current_disabled'] = false; if (!empty($board)) { foreach ($context['categories'] as $id => $values) { if (isset($values['boards'][$board])) { $context['categories'][$id]['boards'][$board]['selected'] = true; break; } } } } $context['attachments']['can']['post'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || $modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')); if ($context['attachments']['can']['post']) { // If there are attachments, calculate the total size and how many. $attachments = array(); $attachments['total_size'] = 0; $attachments['quantity'] = 0; // If this isn't a new post, check the current attachments. if (isset($_REQUEST['msg'])) { $attachments['quantity'] = count($context['attachments']['current']); foreach ($context['attachments']['current'] as $attachment) { $attachments['total_size'] += $attachment['size']; } } // A bit of house keeping first. if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { unset($_SESSION['temp_attachments']); } if (!empty($_SESSION['temp_attachments'])) { // Is this a request to delete them? if (isset($_GET['delete_temp'])) { foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { @unlink($attachment['tmp_name']); } } $attach_errors->addError('temp_attachments_gone'); $_SESSION['temp_attachments'] = array(); } elseif ($context['current_action'] != 'post2' || !empty($_POST['from_qr'])) { // Let's be nice and see if they belong here first. if (empty($_REQUEST['msg']) && empty($_SESSION['temp_attachments']['post']['msg']) && $_SESSION['temp_attachments']['post']['board'] == $board || !empty($_REQUEST['msg']) && $_SESSION['temp_attachments']['post']['msg'] == $_REQUEST['msg']) { // See if any files still exist before showing the warning message and the files attached. foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { continue; } if (file_exists($attachment['tmp_name'])) { $attach_errors->addError('temp_attachments_new'); $context['files_in_session_warning'] = $txt['attached_files_in_session']; unset($_SESSION['temp_attachments']['post']['files']); break; } } } else { // Since, they don't belong here. Let's inform the user that they exist.. if (!empty($topic)) { $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] : '') . (!empty($_REQUEST['last_msg']) ? ';last_msg=' . $_REQUEST['last_msg'] : '') . ';topic=' . $topic . ';delete_temp'; } else { $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; } // Compile a list of the files to show the user. $file_list = array(); foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { $file_list[] = $attachment['name']; } } $_SESSION['temp_attachments']['post']['files'] = $file_list; $file_list = '<div class="attachments">' . implode('<br />', $file_list) . '</div>'; if (!empty($_SESSION['temp_attachments']['post']['msg'])) { // We have a message id, so we can link back to the old topic they were trying to edit.. $goback_link = '<a href="' . $scripturl . '?action=post' . (!empty($_SESSION['temp_attachments']['post']['msg']) ? ';msg=' . $_SESSION['temp_attachments']['post']['msg'] : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? ';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg'] : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions">' . $txt['here'] . '</a>'; $attach_errors->addError(array('temp_attachments_found', array($delete_url, $goback_link, $file_list))); $context['ignore_temp_attachments'] = true; } else { $attach_errors->addError(array('temp_attachments_lost', array($delete_url, $file_list))); $context['ignore_temp_attachments'] = true; } } } foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { // Skipping over these if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) { break; } // Initial errors (such as missing directory), we can recover if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { continue; } if ($attachID == 'initial_error') { if ($context['current_action'] != 'post2') { $txt['error_attach_initial_error'] = $txt['attach_no_upload'] . '<div class="attachmenterrors">' . (is_array($attachment) ? vsprintf($txt[$attachment[0]], $attachment[1]) : $txt[$attachment]) . '</div>'; $attach_errors->addError('attach_initial_error'); } unset($_SESSION['temp_attachments']); break; } // Show any errors which might have occurred. if (!empty($attachment['errors'])) { if ($context['current_action'] != 'post2') { $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br />' : ''; $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div class="attachmenterrors">'; foreach ($attachment['errors'] as $error) { $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br />'; } $txt['error_attach_errors'] .= '</div>'; $attach_errors->addError('attach_errors'); } // Take out the trash. unset($_SESSION['temp_attachments'][$attachID]); @unlink($attachment['tmp_name']); continue; } // More house keeping. if (!file_exists($attachment['tmp_name'])) { unset($_SESSION['temp_attachments'][$attachID]); continue; } $attachments['quantity']++; $attachments['total_size'] += $attachment['size']; if (!isset($context['files_in_session_warning'])) { $context['files_in_session_warning'] = $txt['attached_files_in_session']; } $context['attachments']['current'][] = array('name' => '<u>' . htmlspecialchars($attachment['name'], ENT_COMPAT, 'UTF-8') . '</u>', 'size' => $attachment['size'], 'id' => $attachID, 'unchecked' => false, 'approved' => 1); } } } // Do we need to show the visual verification image? $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || $user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1); if ($context['require_verification']) { require_once SUBSDIR . '/VerificationControls.class.php'; $verificationOptions = array('id' => 'post'); $context['require_verification'] = create_control_verification($verificationOptions); $context['visual_verification_id'] = $verificationOptions['id']; } // If they came from quick reply, and have to enter verification details, give them some notice. if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) { $post_errors->addError('need_qr_verification'); } // Any errors occurred? $context['post_error'] = array('errors' => $post_errors->prepareErrors(), 'type' => $post_errors->getErrorType() == 0 ? 'minor' : 'serious', 'title' => $post_errors->getErrorType() == 0 ? $txt['warning_while_submitting'] : $txt['error_while_submitting']); // If there are attachment errors. Let's show a list to the user. if ($attach_errors->hasErrors()) { loadTemplate('Errors'); $errors = $attach_errors->prepareErrors(); foreach ($errors as $key => $error) { $context['attachment_error_keys'][] = $key . '_error'; $context[$key . '_error'] = $error; } } // What are you doing? Posting a poll, modifying, previewing, new post, or reply... if (isset($_REQUEST['poll'])) { $context['page_title'] = $txt['new_poll']; } elseif ($context['make_event']) { $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; } elseif (isset($_REQUEST['msg'])) { $context['page_title'] = $txt['modify_msg']; } elseif (isset($_REQUEST['subject'], $context['preview_subject'])) { $context['page_title'] = $txt['post_reply']; } elseif (empty($topic)) { $context['page_title'] = $txt['start_new_topic']; } else { $context['page_title'] = $txt['post_reply']; } // Update the topic summary, needed to show new posts in a preview if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) { $only_approved = $modSettings['postmod_active'] && !allowedTo('approve_posts'); if (isset($_REQUEST['xml'])) { $limit = empty($context['new_replies']) ? 0 : (int) $context['new_replies']; } else { $limit = $modSettings['topicSummaryPosts']; } $before = isset($_REQUEST['msg']) ? array('before' => (int) $_REQUEST['msg']) : array(); $counter = 0; $context['previous_posts'] = empty($limit) ? array() : selectMessages($topic, 0, $limit, $before, $only_approved); foreach ($context['previous_posts'] as &$post) { $post['is_new'] = !empty($context['new_replies']); $post['counter'] = $counter++; $post['is_ignored'] = !empty($modSettings['enable_buddylist']) && in_array($post['id_poster'], $user_info['ignoreusers']); if (!empty($context['new_replies'])) { $context['new_replies']--; } } } // Just ajax previewing then lets stop now if (isset($_REQUEST['xml'])) { obExit(); } // Build the link tree. if (empty($topic)) { $context['linktree'][] = array('name' => '<em>' . $txt['start_new_topic'] . '</em>'); } else { $context['linktree'][] = array('url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], 'name' => $form_subject, 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' ( </strong></span>', 'extra_after' => '<span><strong class="nav"> )</strong></span>'); } $context['subject'] = addcslashes($form_subject, '"'); $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); // Are post drafts enabled? $context['drafts_save'] = !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft'); $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('post_autosave_draft'); if (!empty($modSettings['mentions_enabled'])) { $context['mentions_enabled'] = true; loadCSSFile('jquery.atwho.css'); addInlineJavascript(' $(document).ready(function () { for (var i = 0, count = all_elk_mentions.length; i < count; i++) all_elk_mentions[i].oMention = new elk_mentions(all_elk_mentions[i].oOptions); });'); } // Build a list of drafts that they can load into the editor if (!empty($context['drafts_save'])) { $this->_prepareDraftsContext($user_info['id'], $topic); if (!empty($context['drafts'])) { $template_layers->add('load_drafts', 100); } } // Needed for the editor and message icons. require_once SUBSDIR . '/Editor.subs.php'; // Now create the editor. $editorOptions = array('id' => 'message', 'value' => $context['message'], 'labels' => array('post_button' => $context['submit_label']), 'height' => '275px', 'width' => '100%', 'preview_type' => 2); create_control_richedit($editorOptions); $context['attached'] = ''; $context['make_poll'] = isset($_REQUEST['poll']); if ($context['make_poll']) { loadTemplate('Poll'); $template_layers->add('poll_edit'); } // Message icons - customized or not, retrieve them... $context['icons'] = getMessageIcons($board); $context['icon_url'] = ''; if (!empty($context['icons'])) { $context['icons'][count($context['icons']) - 1]['is_last'] = true; $context['icons'][0]['selected'] = true; // $context['icon'] is set when editing a message if (!isset($context['icon'])) { $context['icon'] = $context['icons'][0]['value']; } $found = false; foreach ($context['icons'] as $icon) { if ($icon['value'] === $context['icon']) { $found = true; $context['icon_url'] = $icon['url']; break; } } // Failsafe if (!$found) { $context['icon'] = $context['icons'][0]['value']; $context['icon_url'] = $context['icons'][0]['url']; } } // Are we starting a poll? if set the poll icon as selected if its available if (isset($_REQUEST['poll'])) { for ($i = 0, $n = count($context['icons']); $i < $n; $i++) { if ($context['icons'][$i]['value'] == 'poll') { $context['icons'][$i]['selected'] = true; $context['icon'] = 'poll'; $context['icon_url'] = $context['icons'][$i]['url']; break; } } } // If the user can post attachments prepare the warning labels. if ($context['attachments']['can']['post']) { // If they've unchecked an attachment, they may still want to attach that many more files, but don't allow more than num_allowed_attachments. $context['attachments']['num_allowed'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['attachments']['current']), $modSettings['attachmentNumPerPostLimit']); $context['attachments']['can']['post_unapproved'] = allowedTo('post_attachment'); $context['attachments']['restrictions'] = array(); if (!empty($modSettings['attachmentCheckExtensions'])) { $context['attachments']['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); } else { $context['attachments']['allowed_extensions'] = ''; } $context['attachments']['templates'] = array('add_new' => 'template_add_new_attachments', 'existing' => 'template_show_existing_attachments'); $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); foreach ($attachmentRestrictionTypes as $type) { if (!empty($modSettings[$type])) { $context['attachments']['restrictions'][] = sprintf($txt['attach_restrict_' . $type], comma_format($modSettings[$type], 0)); // Show some numbers. If they exist. if ($type == 'attachmentNumPerPostLimit' && $attachments['quantity'] > 0) { $context['attachments']['restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $attachments['quantity']); } elseif ($type == 'attachmentPostLimit' && $attachments['total_size'] > 0) { $context['attachments']['restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - $attachments['total_size'] / 1028, 0)), 0)); } } } // Load up the drag and drop attachment magic addInlineJavascript(' var dropAttach = dragDropAttachment.prototype.init({ board: ' . $board . ', allowedExtensions: ' . JavaScriptEscape($context['attachments']['allowed_extensions']) . ', totalSizeAllowed: ' . JavaScriptEscape(empty($modSettings['attachmentPostLimit']) ? '' : $modSettings['attachmentPostLimit']) . ', individualSizeAllowed: ' . JavaScriptEscape(empty($modSettings['attachmentSizeLimit']) ? '' : $modSettings['attachmentSizeLimit']) . ', numOfAttachmentAllowed: ' . $context['attachments']['num_allowed'] . ', totalAttachSizeUploaded: ' . (isset($context['attachments']['total_size']) && !empty($context['attachments']['total_size']) ? $context['attachments']['total_size'] : 0) . ', numAttachUploaded: ' . (isset($context['attachments']['quantity']) && !empty($context['attachments']['quantity']) ? $context['attachments']['quantity'] : 0) . ', oTxt: ({ allowedExtensions : ' . JavaScriptEscape(sprintf($txt['cant_upload_type'], $context['attachments']['allowed_extensions'])) . ', totalSizeAllowed : ' . JavaScriptEscape($txt['attach_max_total_file_size']) . ', individualSizeAllowed : ' . JavaScriptEscape(sprintf($txt['file_too_big'], comma_format($modSettings['attachmentSizeLimit'], 0))) . ', numOfAttachmentAllowed : ' . JavaScriptEscape(sprintf($txt['attachments_limit_per_post'], $modSettings['attachmentNumPerPostLimit'])) . ', postUploadError : ' . JavaScriptEscape($txt['post_upload_error']) . ', }), });', true); } $context['back_to_topic'] = isset($_REQUEST['goback']) || isset($_REQUEST['msg']) && !isset($_REQUEST['subject']); $context['show_additional_options'] = !empty($_POST['additional_options']) || isset($_SESSION['temp_attachments']['post']) || isset($_GET['additionalOptions']); $context['is_new_topic'] = empty($topic); $context['is_new_post'] = !isset($_REQUEST['msg']); $context['is_first_post'] = $context['is_new_topic'] || isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg; $context['current_action'] = 'post'; // Register this form in the session variables. checkSubmitOnce('register'); // Finally, load the template. if (!isset($_REQUEST['xml'])) { loadTemplate('Post'); $context['sub_template'] = 'post_page'; } }
/** * Load a template - if the theme doesn't include it, use the default. * What this function does: * - loads a template file with the name template_name from the current, default, or base theme. * - detects a wrong default theme directory and tries to work around it. * * @uses the template_include() function to include the file. * @param string $template_name * @param array $style_sheets = array() * @param bool $fatal = true if fatal is true, dies with an error message if the template cannot be found * @return bool */ function loadTemplate($template_name, $style_sheets = array(), $fatal = true) { global $context, $settings, $txt, $scripturl, $boarddir, $db_show_debug; // Do any style sheets first, cause we're easy with those. if (!empty($style_sheets)) { if (!is_array($style_sheets)) { $style_sheets = array($style_sheets); } foreach ($style_sheets as $sheet) { loadCSSFile($sheet . '.css', array(), $sheet); } } // No template to load? if ($template_name === false) { return true; } $loaded = false; foreach ($settings['template_dirs'] as $template_dir) { if (file_exists($template_dir . '/' . $template_name . '.template.php')) { $loaded = true; template_include($template_dir . '/' . $template_name . '.template.php', true); break; } } if ($loaded) { // For compatibility reasons, if this is the index template without new functions, include compatible stuff. if (substr($template_name, 0, 5) == 'index' && !function_exists('template_button_strip')) { loadTemplate('Compat'); } if ($db_show_debug === true) { $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; } // If they have specified an initialization function for this template, go ahead and call it now. if (function_exists('template_' . $template_name . '_init')) { call_user_func('template_' . $template_name . '_init'); } } elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) { $settings['default_theme_dir'] = $boarddir . '/Themes/default'; $settings['template_dirs'][] = $settings['default_theme_dir']; if (!empty($context['user']['is_admin']) && !isset($_GET['th'])) { loadLanguage('Errors'); echo ' <div class="alert errorbox"> <a href="', $scripturl . '?action=admin;area=theme;sa=list;th=1;' . $context['session_var'] . '=' . $context['session_id'], '" class="alert">', $txt['theme_dir_wrong'], '</a> </div>'; } loadTemplate($template_name); } elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); } elseif ($fatal) { die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); } else { return false; } }
function integrate_chars_main_menu(&$buttons) { global $context, $scripturl, $txt, $settings; // While we're here in setupMenuContext, we might as well do other things we would // otherwise have done in that function. if (!$context['user']['is_guest']) { if (file_exists($settings['default_theme_dir'] . '/css/chars.css')) { loadCSSFile('chars.css', ['default_theme' => true], 'chars'); addInlineJavascript(' user_menus.add("characters", "' . $scripturl . '?action=profile;area=characters_popup");', true); } } // Now add a characters menu, to effectively replace the members menu. $temp_buttons = []; foreach ($buttons as $k => $v) { if ($k == 'mlist') { $temp_buttons['characters'] = ['title' => $txt['chars_menu_title'], 'icon' => 'mlist', 'href' => $scripturl . '?action=characters', 'show' => $context['allow_memberlist'], 'sub_buttons' => []]; $groups = get_main_menu_groups(); foreach ($groups as $id => $group_name) { $temp_buttons['characters']['sub_buttons']['group' . $id] = ['title' => $group_name, 'href' => $scripturl . '?action=characters;sa=sheets;group=' . $id, 'show' => true]; } continue; } $temp_buttons[$k] = $v; } $buttons = $temp_buttons; }
/** * Issue/manage an user's warning status. * @uses ProfileAccount template issueWarning sub template * @uses Profile template */ public function action_issuewarning() { global $txt, $scripturl, $modSettings, $mbname, $context, $cur_profile; $memID = currentMemberID(); // make sure the sub-template is set... loadTemplate('ProfileAccount'); $context['sub_template'] = 'issueWarning'; // We need this because of template_load_warning_variables loadTemplate('Profile'); loadJavascriptFile('profile.js'); // jQuery-UI FTW! $modSettings['jquery_include_ui'] = true; loadCSSFile('jquery.ui.slider.css'); loadCSSFile('jquery.ui.theme.css'); // Get all the actual settings. list($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']); // This stores any legitimate errors. $issueErrors = array(); // Doesn't hurt to be overly cautious. if (empty($modSettings['warning_enable']) || $context['user']['is_owner'] && !$cur_profile['warning'] || !allowedTo('issue_warning')) { fatal_lang_error('no_access', false); } // Get the base (errors related) stuff done. loadLanguage('Errors'); $context['custom_error_title'] = $txt['profile_warning_errors_occurred']; // Make sure things which are disabled stay disabled. $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110; $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110; $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110; $context['warning_limit'] = allowedTo('admin_forum') ? 0 : $modSettings['user_limit']; $context['member']['warning'] = $cur_profile['warning']; $context['member']['name'] = $cur_profile['real_name']; // What are the limits we can apply? $context['min_allowed'] = 0; $context['max_allowed'] = 100; if ($context['warning_limit'] > 0) { require_once SUBSDIR . '/Moderation.subs.php'; $current_applied = warningDailyLimit($memID); $context['min_allowed'] = max(0, $cur_profile['warning'] - $current_applied - $context['warning_limit']); $context['max_allowed'] = min(100, $cur_profile['warning'] - $current_applied + $context['warning_limit']); } // Defaults. $context['warning_data'] = array('reason' => '', 'notify' => '', 'notify_subject' => '', 'notify_body' => ''); // Are we saving? if (isset($_POST['save'])) { // Security is good here. checkSession('post'); // This cannot be empty! $_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : ''; if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) { $issueErrors[] = 'warning_no_reason'; } $_POST['warn_reason'] = Util::htmlspecialchars($_POST['warn_reason']); // If the value hasn't changed it's either no JS or a real no change (Which this will pass) if ($_POST['warning_level'] == 'SAME') { $_POST['warning_level'] = $_POST['warning_level_nojs']; } $_POST['warning_level'] = (int) $_POST['warning_level']; $_POST['warning_level'] = max(0, min(100, $_POST['warning_level'])); if ($_POST['warning_level'] < $context['min_allowed']) { $_POST['warning_level'] = $context['min_allowed']; } elseif ($_POST['warning_level'] > $context['max_allowed']) { $_POST['warning_level'] = $context['max_allowed']; } require_once SUBSDIR . '/Moderation.subs.php'; // Do we actually have to issue them with a PM? $id_notice = 0; if (!empty($_POST['warn_notify']) && empty($issueErrors)) { $_POST['warn_sub'] = trim($_POST['warn_sub']); $_POST['warn_body'] = trim($_POST['warn_body']); if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) { $issueErrors[] = 'warning_notify_blank'; } else { require_once SUBSDIR . '/PersonalMessage.subs.php'; $from = array('id' => 0, 'name' => $context['forum_name'], 'username' => $context['forum_name']); sendpm(array('to' => array($memID), 'bcc' => array()), $_POST['warn_sub'], $_POST['warn_body'], false, $from); // Log the notice. $id_notice = logWarningNotice($_POST['warn_sub'], $_POST['warn_body']); } } // Just in case - make sure notice is valid! $id_notice = (int) $id_notice; // What have we changed? $level_change = $_POST['warning_level'] - $cur_profile['warning']; // No errors? Proceed! Only log if you're not the owner. if (empty($issueErrors)) { // Log what we've done! if (!$context['user']['is_owner']) { logWarning($memID, $cur_profile['real_name'], $id_notice, $level_change, $_POST['warn_reason']); } // Make the change. updateMemberData($memID, array('warning' => $_POST['warning_level'])); // Leave a lovely message. $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success']; } else { // Try to remember some bits. $context['warning_data'] = array('reason' => $_POST['warn_reason'], 'notify' => !empty($_POST['warn_notify']), 'notify_subject' => isset($_POST['warn_sub']) ? $_POST['warn_sub'] : '', 'notify_body' => isset($_POST['warn_body']) ? $_POST['warn_body'] : ''); } // Show the new improved warning level. $context['member']['warning'] = $_POST['warning_level']; } // Taking a look first, good idea that one. if (isset($_POST['preview'])) { $warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : ''; $context['preview_subject'] = !empty($_POST['warn_sub']) ? trim(Util::htmlspecialchars($_POST['warn_sub'])) : ''; if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) { $issueErrors[] = 'warning_notify_blank'; } if (!empty($_POST['warn_body'])) { require_once SUBSDIR . '/Post.subs.php'; preparsecode($warning_body); $warning_body = parse_bbc($warning_body, true); } // Try to remember some bits. $context['warning_data'] = array('reason' => $_POST['warn_reason'], 'notify' => !empty($_POST['warn_notify']), 'notify_subject' => isset($_POST['warn_sub']) ? $_POST['warn_sub'] : '', 'notify_body' => isset($_POST['warn_body']) ? $_POST['warn_body'] : '', 'body_preview' => $warning_body); } if (!empty($issueErrors)) { // Fill in the suite of errors. $context['post_errors'] = array(); foreach ($issueErrors as $error) { $context['post_errors'][] = $txt[$error]; } } $context['page_title'] = $txt['profile_issue_warning']; // Let's use a generic list to get all the current warnings require_once SUBSDIR . '/GenericList.class.php'; require_once SUBSDIR . '/Profile.subs.php'; // Work our the various levels. $context['level_effects'] = array(0 => $txt['profile_warning_effect_none'], $modSettings['warning_watch'] => $txt['profile_warning_effect_watch'], $modSettings['warning_moderate'] => $txt['profile_warning_effect_moderation'], $modSettings['warning_mute'] => $txt['profile_warning_effect_mute']); $context['current_level'] = 0; foreach ($context['level_effects'] as $limit => $dummy) { if ($context['member']['warning'] >= $limit) { $context['current_level'] = $limit; } } // Build a list to view the warnings $listOptions = array('id' => 'issued_warnings', 'title' => $txt['profile_viewwarning_previous_warnings'], 'items_per_page' => $modSettings['defaultMaxMessages'], 'no_items_label' => $txt['profile_viewwarning_no_warnings'], 'base_href' => $scripturl . '?action=profile;area=issuewarning;sa=user;u=' . $memID, 'default_sort_col' => 'log_time', 'get_items' => array('function' => 'list_getUserWarnings', 'params' => array($memID)), 'get_count' => array('function' => 'list_getUserWarningCount', 'params' => array($memID)), 'columns' => array('issued_by' => array('header' => array('value' => $txt['profile_warning_previous_issued'], 'style' => 'width: 20%;'), 'data' => array('function' => create_function('$warning', ' return $warning[\'issuer\'][\'link\']; ')), 'sort' => array('default' => 'lc.member_name DESC', 'reverse' => 'lc.member_name')), 'log_time' => array('header' => array('value' => $txt['profile_warning_previous_time'], 'style' => 'width: 30%;'), 'data' => array('db' => 'time'), 'sort' => array('default' => 'lc.log_time DESC', 'reverse' => 'lc.log_time')), 'reason' => array('header' => array('value' => $txt['profile_warning_previous_reason']), 'data' => array('function' => create_function('$warning', ' global $scripturl, $txt, $settings; $ret = \' <div class="floatleft"> \' . $warning[\'reason\'] . \' </div>\'; // If a notice was sent, provide a way to view it if (!empty($warning[\'id_notice\'])) $ret .= \' <div class="floatright"> <a href="\' . $scripturl . \'?action=moderate;area=notice;nid=\' . $warning[\'id_notice\'] . \'" onclick="window.open(this.href, \\\'\\\', \\\'scrollbars=yes,resizable=yes,width=400,height=250\\\');return false;" target="_blank" class="new_win" title="\' . $txt[\'profile_warning_previous_notice\'] . \'"><img src="\' . $settings[\'images_url\'] . \'/filter.png" alt="" /></a> </div>\'; return $ret;'))), 'level' => array('header' => array('value' => $txt['profile_warning_previous_level'], 'style' => 'width: 6%;'), 'data' => array('db' => 'counter'), 'sort' => array('default' => 'lc.counter DESC', 'reverse' => 'lc.counter')))); // Create the list for viewing. createList($listOptions); $warning_for_message = isset($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : false; $warned_message_subject = ''; // Are they warning because of a message? if (isset($_REQUEST['msg']) && 0 < (int) $_REQUEST['msg']) { require_once SUBSDIR . '/Messages.subs.php'; $message = basicMessageInfo((int) $_REQUEST['msg']); if (!empty($message)) { $warned_message_subject = $message['subject']; } } require_once SUBSDIR . '/Maillist.subs.php'; // Any custom templates? $context['notification_templates'] = array(); $notification_templates = maillist_templates('warntpl'); foreach ($notification_templates as $row) { // If we're not warning for a message skip any that are. if (!$warning_for_message && strpos($row['body'], '{MESSAGE}') !== false) { continue; } $context['notification_templates'][] = array('title' => $row['title'], 'body' => $row['body']); } // Setup the "default" templates. foreach (array('spamming', 'offence', 'insulting') as $type) { $context['notification_templates'][] = array('title' => $txt['profile_warning_notify_title_' . $type], 'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($warning_for_message) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type])); } // Replace all the common variables in the templates. foreach ($context['notification_templates'] as $k => $name) { $context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $warning_for_message . ']' . un_htmlspecialchars($warned_message_subject) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => replaceBasicActionUrl($txt['regards_team']))); } }
function imgcache_integrate_loadCss() { loadCSSFile('imgcache.css'); }