/**
     * InitContent.
     */
    function pmxc_InitContent()
    {
        global $user_info, $modSettings, $txt;
        if ($this->visible) {
            // show current time as realtime?
            if (!empty($this->cfg['config']['settings']['show_time']) && !empty($this->cfg['config']['settings']['show_realtime'])) {
                $cdate = date('Y,n-1,j,G,', Forum_Time()) . intval(date('i', Forum_Time())) . ',' . intval(date('s', Forum_Time()));
                if (empty($modSettings['pmxUserLoginLoaded'])) {
                    addInlineJavascript('
	var pmx_rtcFormat = {};');
                }
                if (empty($this->cfg['config']['settings']['rtc_format'])) {
                    addInlineJavascript('
	pmx_rtcFormat[' . $this->cfg['id'] . '] = "' . (empty($user_info['time_format']) ? $modSettings['time_format'] : $user_info['time_format']) . '";');
                } else {
                    addInlineJavascript('
	pmx_rtcFormat[' . $this->cfg['id'] . '] = "' . $this->cfg['config']['settings']['rtc_format'] . '";');
                }
                if (empty($modSettings['pmxUserLoginLoaded'])) {
                    addInlineJavascript('
	var pmx_rctMonths = new Array("' . implode('","', $txt['months']) . '");
	var pmx_rctShortMonths = new Array("' . implode('","', $txt['months_short']) . '");
	var pmx_rctDays = new Array("' . implode('","', $txt['days']) . '");
	var pmx_rctShortDays = new Array("' . implode('","', $txt['days_short']) . '");
	var pmx_rtcFormatTypes = new Array("%a", "%A", "%d", "%b", "%B", "%m", "%Y", "%y", "%H", "%I", "%M", "%S", "%p", "%%", "%D", "%e", "%R", "%T");
	var pmx_rtcOffset = new Date(' . $cdate . ') - new Date();');
                    loadJavascriptFile(PortaMx_loadCompressed('PortaMxUser.js'), array('external' => true));
                    $modSettings['pmxUserLoginLoaded'] = true;
                }
            }
        }
        // return the visibility flag (true/false)
        return $this->visible;
    }
Exemplo n.º 2
0
/**
 * This function basically is the home page of the moderation center.
 */
function ModerationHome()
{
    global $txt, $context, $scripturl, $modSettings, $user_info, $user_settings;
    loadTemplate('ModerationCenter');
    loadJavascriptFile('admin.js', array('default_theme' => true), 'admin.js');
    $context['page_title'] = $txt['moderation_center'];
    $context['sub_template'] = 'moderation_center';
    // Load what blocks the user actually can see...
    $valid_blocks = array('n' => 'LatestNews', 'p' => 'Notes');
    if ($context['can_moderate_groups']) {
        $valid_blocks['g'] = 'GroupRequests';
    }
    if ($context['can_moderate_boards']) {
        $valid_blocks['r'] = 'ReportedPosts';
        $valid_blocks['w'] = 'WatchedUsers';
    }
    if (empty($user_settings['mod_prefs'])) {
        $user_blocks = 'n' . ($context['can_moderate_boards'] ? 'wr' : '') . ($context['can_moderate_groups'] ? 'g' : '');
    } else {
        list(, $user_blocks) = explode('|', $user_settings['mod_prefs']);
    }
    $user_blocks = str_split($user_blocks);
    $context['mod_blocks'] = array();
    foreach ($valid_blocks as $k => $block) {
        if (in_array($k, $user_blocks)) {
            $block = 'ModBlock' . $block;
            if (function_exists($block)) {
                $context['mod_blocks'][] = $block();
            }
        }
    }
}
Exemplo n.º 3
0
 public function showVerification($isNew, $force_refresh = true)
 {
     loadTemplate('reCaptcha');
     loadTemplate('VerificationControls');
     loadJavascriptFile('https://www.google.com/recaptcha/api.js');
     return true;
 }
 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');
 }
Exemplo n.º 5
0
/**
 * 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');
}
Exemplo n.º 6
0
/**
 * ibb_gist_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_gist_button(&$bbc_tags)
{
    global $context;
    // This is the group we intend to modify
    $where = $bbc_tags['row2'][0];
    // And here we insert the new value after code
    $bbc_tags['row2'][0] = elk_array_insert($where, 'code', array('gist'), 'after', false);
    // Add the javascript, this tells the editor what to do with the new button
    loadJavascriptFile('GistButton.js', array(), 'GistButton');
    // We need to supply the css for the button image, here we use a data-url to save an image call
    $context['html_headers'] .= '<style>.sceditor-button-gist div {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAVpJREFUeNqM0s0rRGEUx/F7x0RKxob4A6bZKBYWFkLZqIkkC7FUsrCwoCxsZcN/IFmIP4E9ZWnyurBR3krZeH8b1/dMv5vTpDue+szzzL33nJ5znieIoihIGCGmMIt0+ctSbIUETbhHEbm/EqSD5PGOC2TwgHo04xaPv9tIHhbUoPUMXjAcx4aln9BKDcYxgRR20IJNDKEO69hCFie2JnYx3sGYJcQ5jrU2PTjEDbpwpeeXWPZN3NOLnLb8hm1UoaBAG3P6btR26pt4rblDDarRs6KOMh7fmr/idZxgAW3Y0H/r/IqCfYKU5o/yB1b7kY5tGp04Uwmh++5Vcx59PoGNWtV3pznQXK2SbLf76s8kVv09yLpGRro0SwoawIgrt1fNzPtT2FVd/WjVCdiL9qQb5k8ho3Ia8eTKea50TeMd2LZOXQmfmP9PrL/K3RjURTrAmk4lMcGPAAMAEvmJGW+ZZPAAAAAASUVORK5CYII=)}</style>';
}
Exemplo n.º 7
0
/**
 * The main admin handling function.
 * It initialises all the basic context required for the admin center.
 * It passes execution onto the relevant admin section.
 * If the passed section is not found it shows the admin home page.
 */
function AdminMain()
{
    global $txt, $context, $scripturl, $sc, $modSettings, $user_info, $settings, $sourcedir, $options, $smcFunc, $boarddir;
    // Load the language and templates....
    loadLanguage('Admin');
    loadTemplate('Admin', 'admin');
    loadJavascriptFile('admin.js', array('default_theme' => true), 'admin.js');
    // No indexing evil stuff.
    $context['robot_no_index'] = true;
    require_once $sourcedir . '/Subs-Menu.php';
    // Some preferences.
    $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
    // Define all the menu structure - see Subs-Menu.php for details!
    $admin_areas = array('forum' => array('title' => $txt['admin_main'], 'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'), 'areas' => array('index' => array('label' => $txt['admin_center'], 'function' => 'AdminHome', 'icon' => 'administration.png'), 'credits' => array('label' => $txt['support_credits_title'], 'function' => 'AdminHome', 'icon' => 'support.png'), 'news' => array('label' => $txt['news_title'], 'file' => 'ManageNews.php', 'function' => 'ManageNews', 'icon' => 'news.png', 'permission' => array('edit_news', 'send_mail', 'admin_forum'), 'subsections' => array('editnews' => array($txt['admin_edit_news'], 'edit_news'), 'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'), 'settings' => array($txt['settings'], 'admin_forum'))), 'packages' => array('label' => $txt['package'], 'file' => 'Packages.php', 'function' => 'Packages', 'permission' => array('admin_forum'), 'icon' => 'packages.png', 'subsections' => array('browse' => array($txt['browse_packages']), 'packageget' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packages;sa=packageget;get'), 'installed' => array($txt['installed_packages']), 'perms' => array($txt['package_file_perms']), 'options' => array($txt['package_settings']))), 'search' => array('function' => 'AdminSearch', 'permission' => array('admin_forum'), 'select' => 'index'), 'adminlogoff' => array('label' => $txt['admin_logoff'], 'function' => 'AdminEndSession', 'enabled' => empty($modSettings['securityDisable']), 'icon' => 'exit.png'))), 'config' => array('title' => $txt['admin_config'], 'permission' => array('admin_forum'), 'areas' => array('corefeatures' => array('label' => $txt['core_settings_title'], 'file' => 'ManageSettings.php', 'function' => 'ModifyCoreFeatures', 'icon' => 'corefeatures.png'), 'featuresettings' => array('label' => $txt['modSettings_title'], 'file' => 'ManageSettings.php', 'function' => 'ModifyFeatureSettings', 'icon' => 'features.png', 'subsections' => array('basic' => array($txt['mods_cat_features']), 'layout' => array($txt['mods_cat_layout']), 'karma' => array($txt['karma'], 'enabled' => in_array('k', $context['admin_features'])), 'sig' => array($txt['signature_settings_short']), 'profile' => array($txt['custom_profile_shorttitle'], 'enabled' => in_array('cp', $context['admin_features'])))), 'securitysettings' => array('label' => $txt['admin_security_moderation'], 'file' => 'ManageSettings.php', 'function' => 'ModifySecuritySettings', 'icon' => 'security.png', 'subsections' => array('general' => array($txt['mods_cat_security_general']), 'spam' => array($txt['antispam_title']), 'moderation' => array($txt['moderation_settings_short'], 'enabled' => substr($modSettings['warning_settings'], 0, 1) == 1))), 'languages' => array('label' => $txt['language_configuration'], 'file' => 'ManageLanguages.php', 'function' => 'ManageLanguages', 'icon' => 'languages.png', 'subsections' => array('edit' => array($txt['language_edit']), 'add' => array($txt['language_add']), 'settings' => array($txt['language_settings']))), 'serversettings' => array('label' => $txt['admin_server_settings'], 'file' => 'ManageServer.php', 'function' => 'ModifySettings', 'icon' => 'server.png', 'subsections' => array('general' => array($txt['general_settings']), 'database' => array($txt['database_paths_settings']), 'cookie' => array($txt['cookies_sessions_settings']), 'cache' => array($txt['caching_settings']), 'loads' => array($txt['load_balancing_settings']), 'phpinfo' => array($txt['phpinfo_settings']))), 'current_theme' => array('label' => $txt['theme_current_settings'], 'file' => 'Themes.php', 'function' => 'ThemesMain', 'custom_url' => $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'], 'icon' => 'current_theme.png'), 'theme' => array('label' => $txt['theme_admin'], 'file' => 'Themes.php', 'function' => 'ThemesMain', 'custom_url' => $scripturl . '?action=admin;area=theme', 'icon' => 'themes.png', 'subsections' => array('admin' => array($txt['themeadmin_admin_title']), 'list' => array($txt['themeadmin_list_title']), 'reset' => array($txt['themeadmin_reset_title']), 'edit' => array($txt['themeadmin_edit_title']))), 'modsettings' => array('label' => $txt['admin_modifications'], 'file' => 'ManageSettings.php', 'function' => 'ModifyModSettings', 'icon' => 'modifications.png', 'subsections' => array('hooks' => array($txt['hooks_title_list']), 'general' => array($txt['mods_cat_modifications_misc']))))), 'layout' => array('title' => $txt['layout_controls'], 'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'), 'areas' => array('manageboards' => array('label' => $txt['admin_boards'], 'file' => 'ManageBoards.php', 'function' => 'ManageBoards', 'icon' => 'boards.png', 'permission' => array('manage_boards'), 'subsections' => array('main' => array($txt['boardsEdit']), 'newcat' => array($txt['mboards_new_cat']), 'settings' => array($txt['settings'], 'admin_forum'))), 'postsettings' => array('label' => $txt['manageposts'], 'file' => 'ManagePosts.php', 'function' => 'ManagePostSettings', 'permission' => array('admin_forum'), 'icon' => 'posts.png', 'subsections' => array('posts' => array($txt['manageposts_settings']), 'bbc' => array($txt['manageposts_bbc_settings']), 'censor' => array($txt['admin_censored_words']), 'topics' => array($txt['manageposts_topic_settings']))), 'managedrafts' => array('label' => $txt['manage_drafts'], 'file' => 'Drafts.php', 'function' => 'ModifyDraftSettings', 'icon' => 'logs.png', 'permission' => array('admin_forum'), 'enabled' => in_array('dr', $context['admin_features'])), 'managecalendar' => array('label' => $txt['manage_calendar'], 'file' => 'ManageCalendar.php', 'function' => 'ManageCalendar', 'icon' => 'calendar.png', 'permission' => array('admin_forum'), 'enabled' => in_array('cd', $context['admin_features']), 'subsections' => array('holidays' => array($txt['manage_holidays'], 'admin_forum', 'enabled' => !empty($modSettings['cal_enabled'])), 'settings' => array($txt['calendar_settings'], 'admin_forum'))), 'managesearch' => array('label' => $txt['manage_search'], 'file' => 'ManageSearch.php', 'function' => 'ManageSearch', 'icon' => 'search.png', 'permission' => array('admin_forum'), 'subsections' => array('weights' => array($txt['search_weights']), 'method' => array($txt['search_method']), 'settings' => array($txt['settings']))), 'smileys' => array('label' => $txt['smileys_manage'], 'file' => 'ManageSmileys.php', 'function' => 'ManageSmileys', 'icon' => 'smiley.png', 'permission' => array('manage_smileys'), 'subsections' => array('editsets' => array($txt['smiley_sets']), 'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])), 'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])), 'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])), 'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])), 'settings' => array($txt['settings']))), 'manageattachments' => array('label' => $txt['attachments_avatars'], 'file' => 'ManageAttachments.php', 'function' => 'ManageAttachments', 'icon' => 'attachment.png', 'permission' => array('manage_attachments'), 'subsections' => array('browse' => array($txt['attachment_manager_browse']), 'attachments' => array($txt['attachment_manager_settings']), 'avatars' => array($txt['attachment_manager_avatar_settings']), 'attachpaths' => array($txt['attach_directories']), 'maintenance' => array($txt['attachment_manager_maintenance']))))), 'members' => array('title' => $txt['admin_manage_members'], 'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'), 'areas' => array('viewmembers' => array('label' => $txt['admin_users'], 'file' => 'ManageMembers.php', 'function' => 'ViewMembers', 'icon' => 'members.png', 'permission' => array('moderate_forum'), 'subsections' => array('all' => array($txt['view_all_members']), 'search' => array($txt['mlist_search']))), 'membergroups' => array('label' => $txt['admin_groups'], 'file' => 'ManageMembergroups.php', 'function' => 'ModifyMembergroups', 'icon' => 'membergroups.png', 'permission' => array('manage_membergroups'), 'subsections' => array('index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'), 'add' => array($txt['membergroups_new_group'], 'manage_membergroups'), 'settings' => array($txt['settings'], 'admin_forum'))), 'permissions' => array('label' => $txt['edit_permissions'], 'file' => 'ManagePermissions.php', 'function' => 'ModifyPermissions', 'icon' => 'permissions.png', 'permission' => array('manage_permissions'), 'subsections' => array('index' => array($txt['permissions_groups'], 'manage_permissions'), 'board' => array($txt['permissions_boards'], 'manage_permissions'), 'profiles' => array($txt['permissions_profiles'], 'manage_permissions'), 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']), 'settings' => array($txt['settings'], 'admin_forum'))), 'regcenter' => array('label' => $txt['registration_center'], 'file' => 'ManageRegistration.php', 'function' => 'RegCenter', 'icon' => 'regcenter.png', 'permission' => array('admin_forum', 'moderate_forum'), 'subsections' => array('register' => array($txt['admin_browse_register_new'], 'moderate_forum'), 'agreement' => array($txt['registration_agreement'], 'admin_forum'), 'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'), 'settings' => array($txt['settings'], 'admin_forum'))), 'ban' => array('label' => $txt['ban_title'], 'file' => 'ManageBans.php', 'function' => 'Ban', 'icon' => 'ban.png', 'permission' => 'manage_bans', 'subsections' => array('list' => array($txt['ban_edit_list']), 'add' => array($txt['ban_add_new']), 'browse' => array($txt['ban_trigger_browse']), 'log' => array($txt['ban_log']))), 'paidsubscribe' => array('label' => $txt['paid_subscriptions'], 'enabled' => in_array('ps', $context['admin_features']), 'file' => 'ManagePaid.php', 'icon' => 'paid.png', 'function' => 'ManagePaidSubscriptions', 'permission' => 'admin_forum', 'subsections' => array('view' => array($txt['paid_subs_view']), 'settings' => array($txt['settings']))), 'sengines' => array('label' => $txt['search_engines'], 'enabled' => in_array('sp', $context['admin_features']), 'file' => 'ManageSearchEngines.php', 'icon' => 'engines.png', 'function' => 'SearchEngines', 'permission' => 'admin_forum', 'subsections' => array('stats' => array($txt['spider_stats']), 'logs' => array($txt['spider_logs']), 'spiders' => array($txt['spiders']), 'settings' => array($txt['settings']))))), 'maintenance' => array('title' => $txt['admin_maintenance'], 'permission' => array('admin_forum'), 'areas' => array('maintain' => array('label' => $txt['maintain_title'], 'file' => 'ManageMaintenance.php', 'icon' => 'maintain.png', 'function' => 'ManageMaintenance', 'subsections' => array('routine' => array($txt['maintain_sub_routine'], 'admin_forum'), 'database' => array($txt['maintain_sub_database'], 'admin_forum'), 'members' => array($txt['maintain_sub_members'], 'admin_forum'), 'topics' => array($txt['maintain_sub_topics'], 'admin_forum'))), 'scheduledtasks' => array('label' => $txt['maintain_tasks'], 'file' => 'ManageScheduledTasks.php', 'icon' => 'scheduled.png', 'function' => 'ManageScheduledTasks', 'subsections' => array('tasks' => array($txt['maintain_tasks'], 'admin_forum'), 'tasklog' => array($txt['scheduled_log'], 'admin_forum'))), 'mailqueue' => array('label' => $txt['mailqueue_title'], 'file' => 'ManageMail.php', 'function' => 'ManageMail', 'icon' => 'mail.png', 'subsections' => array('browse' => array($txt['mailqueue_browse'], 'admin_forum'), 'settings' => array($txt['mailqueue_settings'], 'admin_forum'))), 'reports' => array('enabled' => in_array('rg', $context['admin_features']), 'label' => $txt['generate_reports'], 'file' => 'Reports.php', 'function' => 'ReportsMain', 'icon' => 'reports.png'), 'logs' => array('label' => $txt['logs'], 'function' => 'AdminLogs', 'icon' => 'logs.png', 'subsections' => array('errorlog' => array($txt['errlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'), 'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), 'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), 'banlog' => array($txt['ban_log'], 'manage_bans'), 'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => in_array('sp', $context['admin_features'])), 'tasklog' => array($txt['scheduled_log'], 'admin_forum'), 'pruning' => array($txt['pruning_title'], 'admin_forum'))), 'repairboards' => array('label' => $txt['admin_repair'], 'file' => 'RepairBoards.php', 'function' => 'RepairBoards', 'select' => 'maintain', 'hidden' => true))));
    // Any files to include for administration?
    if (!empty($modSettings['integrate_admin_include'])) {
        $admin_includes = explode(',', $modSettings['integrate_admin_include']);
        foreach ($admin_includes as $include) {
            $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
            if (file_exists($include)) {
                require_once $include;
            }
        }
    }
    // Make sure the administrator has a valid session...
    validateSession();
    // Actually create the menu!
    $admin_include_data = createMenu($admin_areas);
    unset($admin_areas);
    // Nothing valid?
    if ($admin_include_data == false) {
        fatal_lang_error('no_access', false);
    }
    // Build the link tree.
    $context['linktree'][] = array('url' => $scripturl . '?action=admin', 'name' => $txt['admin_center']);
    if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') {
        $context['linktree'][] = array('url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'name' => $admin_include_data['label']);
    }
    if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) {
        $context['linktree'][] = array('url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0]);
    }
    // Make a note of the Unique ID for this menu.
    $context['admin_menu_id'] = $context['max_menu_id'];
    $context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id'];
    // Where in the admin are we?
    $context['admin_area'] = $admin_include_data['current_area'];
    // Now - finally - call the right place!
    if (isset($admin_include_data['file'])) {
        require_once $sourcedir . '/' . $admin_include_data['file'];
    }
    $admin_include_data['function']();
}
 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;
 }
Exemplo n.º 9
0
 /**
  * The main admin handling function.
  *
  * What it does:
  * - It initialises all the basic context required for the admin center.
  * - It passes execution onto the relevant admin section.
  * - If the passed section is not found it shows the admin home page.
  * - Accessed by ?action=admin.
  */
 public function action_index()
 {
     global $txt, $context, $scripturl, $modSettings, $settings;
     // Make sure the administrator has a valid session...
     validateSession();
     // Load the language and templates....
     loadLanguage('Admin');
     loadTemplate('Admin', 'admin');
     loadJavascriptFile('admin.js', array(), 'admin_script');
     // The Admin functions require Jquery UI ....
     $modSettings['jquery_include_ui'] = true;
     // No indexing evil stuff.
     $context['robot_no_index'] = true;
     // Need these to do much
     require_once SUBSDIR . '/Menu.subs.php';
     require_once SUBSDIR . '/Action.class.php';
     // Define the menu structure - see subs/Menu.subs.php for details!
     $admin_areas = array('forum' => array('title' => $txt['admin_main'], 'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'), 'areas' => array('index' => array('label' => $txt['admin_center'], 'controller' => 'Admin_Controller', 'function' => 'action_home', 'icon' => 'transparent.png', 'class' => 'admin_img_administration'), 'credits' => array('label' => $txt['support_credits_title'], 'controller' => 'Admin_Controller', 'function' => 'action_credits', 'icon' => 'transparent.png', 'class' => 'admin_img_support'), 'maillist' => array('label' => $txt['mail_center'], 'file' => 'ManageMaillist.controller.php', 'controller' => 'ManageMaillist_Controller', 'function' => 'action_index', 'icon' => 'mail.png', 'class' => 'admin_img_mail', 'permission' => array('approve_emails', 'admin_forum'), 'enabled' => in_array('pe', $context['admin_features']), 'subsections' => array('emaillist' => array($txt['mm_emailerror'], 'approve_emails'), 'emailfilters' => array($txt['mm_emailfilters'], 'admin_forum'), 'emailparser' => array($txt['mm_emailparsers'], 'admin_forum'), 'emailtemplates' => array($txt['mm_emailtemplates'], 'approve_emails'), 'emailsettings' => array($txt['mm_emailsettings'], 'admin_forum'))), 'news' => array('label' => $txt['news_title'], 'file' => 'ManageNews.controller.php', 'controller' => 'ManageNews_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_news', 'permission' => array('edit_news', 'send_mail', 'admin_forum'), 'subsections' => array('editnews' => array($txt['admin_edit_news'], 'edit_news'), 'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'), 'settings' => array($txt['settings'], 'admin_forum'))), 'packages' => array('label' => $txt['package'], 'file' => 'Packages.controller.php', 'controller' => 'Packages_Controller', 'function' => 'action_index', 'permission' => array('admin_forum'), 'icon' => 'transparent.png', 'class' => 'admin_img_packages', 'subsections' => array('browse' => array($txt['browse_packages']), 'installed' => array($txt['installed_packages']), 'perms' => array($txt['package_file_perms']), 'options' => array($txt['package_settings']), 'servers' => array($txt['download_packages']), 'upload' => array($txt['upload_packages']))), 'packageservers' => array('label' => $txt['package_servers'], 'file' => 'PackageServers.controller.php', 'controller' => 'PackageServers_Controller', 'function' => 'action_index', 'permission' => array('admin_forum'), 'icon' => 'transparent.png', 'class' => 'admin_img_packages', 'hidden' => true), 'search' => array('controller' => 'Admin_Controller', 'function' => 'action_search', 'permission' => array('admin_forum'), 'select' => 'index'), 'adminlogoff' => array('controller' => 'Admin_Controller', 'function' => 'action_endsession', 'label' => $txt['admin_logoff'], 'enabled' => empty($modSettings['securityDisable']), 'icon' => 'transparent.png', 'class' => 'admin_img_exit'))), 'config' => array('title' => $txt['admin_config'], 'permission' => array('admin_forum'), 'areas' => array('corefeatures' => array('label' => $txt['core_settings_title'], 'file' => 'CoreFeatures.controller.php', 'controller' => 'CoreFeatures_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_corefeatures'), 'featuresettings' => array('label' => $txt['modSettings_title'], 'file' => 'ManageFeatures.controller.php', 'controller' => 'ManageFeatures_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_features', 'subsections' => array('basic' => array($txt['mods_cat_features']), 'layout' => array($txt['mods_cat_layout']), 'pmsettings' => array($txt['personal_messages']), 'karma' => array($txt['karma'], 'enabled' => in_array('k', $context['admin_features'])), 'likes' => array($txt['likes'], 'enabled' => in_array('l', $context['admin_features'])), 'mention' => array($txt['mention']), 'sig' => array($txt['signature_settings_short']), 'profile' => array($txt['custom_profile_shorttitle'], 'enabled' => in_array('cp', $context['admin_features'])))), 'serversettings' => array('label' => $txt['admin_server_settings'], 'file' => 'ManageServer.controller.php', 'controller' => 'ManageServer_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_server', 'subsections' => array('general' => array($txt['general_settings']), 'database' => array($txt['database_paths_settings']), 'cookie' => array($txt['cookies_sessions_settings']), 'cache' => array($txt['caching_settings']), 'loads' => array($txt['load_balancing_settings']), 'phpinfo' => array($txt['phpinfo_settings']))), 'securitysettings' => array('label' => $txt['admin_security_moderation'], 'file' => 'ManageSecurity.controller.php', 'controller' => 'ManageSecurity_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_security', 'subsections' => array('general' => array($txt['mods_cat_security_general']), 'spam' => array($txt['antispam_title']), 'badbehavior' => array($txt['badbehavior_title']), 'moderation' => array($txt['moderation_settings_short'], 'enabled' => !empty($modSettings['warning_enable'])))), 'theme' => array('label' => $txt['theme_admin'], 'file' => 'ManageThemes.controller.php', 'controller' => 'ManageThemes_Controller', 'function' => 'action_index', 'custom_url' => $scripturl . '?action=admin;area=theme', 'icon' => 'transparent.png', 'class' => 'admin_img_themes', 'subsections' => array('admin' => array($txt['themeadmin_admin_title']), 'list' => array($txt['themeadmin_list_title']), 'reset' => array($txt['themeadmin_reset_title']), 'themelist' => array($txt['themeadmin_edit_title'], 'active' => array('edit', 'browse')), 'edit' => array($txt['themeadmin_edit_title'], 'enabled' => false), 'browse' => array($txt['themeadmin_edit_title'], 'enabled' => false))), 'current_theme' => array('label' => $txt['theme_current_settings'], 'file' => 'ManageThemes.controller.php', 'controller' => 'ManageThemes_Controller', 'function' => 'action_index', 'custom_url' => $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'], 'icon' => 'transparent.png', 'class' => 'admin_img_current_theme'), 'languages' => array('label' => $txt['language_configuration'], 'file' => 'ManageLanguages.controller.php', 'controller' => 'ManageLanguages_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_languages', 'subsections' => array('edit' => array($txt['language_edit']), 'settings' => array($txt['language_settings']))), 'addonsettings' => array('label' => $txt['admin_modifications'], 'file' => 'AddonSettings.controller.php', 'controller' => 'AddonSettings_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_modifications', 'subsections' => array('general' => array($txt['mods_cat_modifications_misc']))))), 'layout' => array('title' => $txt['layout_controls'], 'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'), 'areas' => array('manageboards' => array('label' => $txt['admin_boards'], 'file' => 'ManageBoards.controller.php', 'controller' => 'ManageBoards_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_boards', 'permission' => array('manage_boards'), 'subsections' => array('main' => array($txt['boardsEdit']), 'newcat' => array($txt['mboards_new_cat']), 'settings' => array($txt['settings'], 'admin_forum'))), 'postsettings' => array('label' => $txt['manageposts'], 'file' => 'ManagePosts.controller.php', 'controller' => 'ManagePosts_Controller', 'function' => 'action_index', 'permission' => array('admin_forum'), 'icon' => 'transparent.png', 'class' => 'admin_img_posts', 'subsections' => array('posts' => array($txt['manageposts_settings']), 'bbc' => array($txt['manageposts_bbc_settings']), 'censor' => array($txt['admin_censored_words']), 'topics' => array($txt['manageposts_topic_settings']))), 'smileys' => array('label' => $txt['smileys_manage'], 'file' => 'ManageSmileys.controller.php', 'controller' => 'ManageSmileys_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_smiley', 'permission' => array('manage_smileys'), 'subsections' => array('editsets' => array($txt['smiley_sets']), 'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])), 'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])), 'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])), 'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])), 'settings' => array($txt['settings']))), 'manageattachments' => array('label' => $txt['attachments_avatars'], 'file' => 'ManageAttachments.controller.php', 'controller' => 'ManageAttachments_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_attachment', 'permission' => array('manage_attachments'), 'subsections' => array('browse' => array($txt['attachment_manager_browse']), 'attachments' => array($txt['attachment_manager_settings']), 'avatars' => array($txt['attachment_manager_avatar_settings']), 'attachpaths' => array($txt['attach_directories']), 'maintenance' => array($txt['attachment_manager_maintenance']))), 'managesearch' => array('label' => $txt['manage_search'], 'file' => 'ManageSearch.controller.php', 'controller' => 'ManageSearch_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_search', 'permission' => array('admin_forum'), 'subsections' => array('weights' => array($txt['search_weights']), 'method' => array($txt['search_method']), 'managesphinx' => array($txt['search_sphinx']), 'settings' => array($txt['settings']))), 'managecalendar' => array('label' => $txt['manage_calendar'], 'file' => 'ManageCalendar.controller.php', 'controller' => 'ManageCalendar_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_calendar', 'permission' => array('admin_forum'), 'enabled' => in_array('cd', $context['admin_features']), 'subsections' => array('holidays' => array($txt['manage_holidays'], 'admin_forum', 'enabled' => !empty($modSettings['cal_enabled'])), 'settings' => array($txt['calendar_settings'], 'admin_forum'))), 'managedrafts' => array('label' => $txt['manage_drafts'], 'file' => 'ManageDrafts.controller.php', 'controller' => 'ManageDrafts_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_logs', 'permission' => array('admin_forum'), 'enabled' => in_array('dr', $context['admin_features'])))), 'members' => array('title' => $txt['admin_manage_members'], 'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'), 'areas' => array('viewmembers' => array('label' => $txt['admin_users'], 'file' => 'ManageMembers.controller.php', 'controller' => 'ManageMembers_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_members', 'permission' => array('moderate_forum'), 'subsections' => array('all' => array($txt['view_all_members']), 'search' => array($txt['mlist_search']))), 'membergroups' => array('label' => $txt['admin_groups'], 'file' => 'ManageMembergroups.controller.php', 'controller' => 'ManageMembergroups_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_membergroups', 'permission' => array('manage_membergroups'), 'subsections' => array('index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'), 'add' => array($txt['membergroups_new_group'], 'manage_membergroups'), 'settings' => array($txt['settings'], 'admin_forum'))), 'permissions' => array('label' => $txt['edit_permissions'], 'file' => 'ManagePermissions.controller.php', 'controller' => 'ManagePermissions_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_permissions', 'permission' => array('manage_permissions'), 'subsections' => array('index' => array($txt['permissions_groups'], 'manage_permissions'), 'board' => array($txt['permissions_boards'], 'manage_permissions'), 'profiles' => array($txt['permissions_profiles'], 'manage_permissions'), 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']), 'settings' => array($txt['settings'], 'admin_forum'))), 'ban' => array('label' => $txt['ban_title'], 'file' => 'ManageBans.controller.php', 'controller' => 'ManageBans_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_ban', 'permission' => 'manage_bans', 'subsections' => array('list' => array($txt['ban_edit_list']), 'add' => array($txt['ban_add_new']), 'browse' => array($txt['ban_trigger_browse']), 'log' => array($txt['ban_log']))), 'regcenter' => array('label' => $txt['registration_center'], 'file' => 'ManageRegistration.controller.php', 'controller' => 'ManageRegistration_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_regcenter', 'permission' => array('admin_forum', 'moderate_forum'), 'subsections' => array('register' => array($txt['admin_browse_register_new'], 'moderate_forum'), 'agreement' => array($txt['registration_agreement'], 'admin_forum'), 'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'), 'settings' => array($txt['settings'], 'admin_forum'))), 'sengines' => array('label' => $txt['search_engines'], 'enabled' => in_array('sp', $context['admin_features']), 'file' => 'ManageSearchEngines.controller.php', 'controller' => 'ManageSearchEngines_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_engines', 'permission' => 'admin_forum', 'subsections' => array('stats' => array($txt['spider_stats']), 'logs' => array($txt['spider_logs']), 'spiders' => array($txt['spiders']), 'settings' => array($txt['settings']))), 'paidsubscribe' => array('label' => $txt['paid_subscriptions'], 'enabled' => in_array('ps', $context['admin_features']), 'file' => 'ManagePaid.controller.php', 'controller' => 'ManagePaid_Controller', 'icon' => 'transparent.png', 'class' => 'admin_img_paid', 'function' => 'action_index', 'permission' => 'admin_forum', 'subsections' => array('view' => array($txt['paid_subs_view']), 'settings' => array($txt['settings']))))), 'maintenance' => array('title' => $txt['admin_maintenance'], 'permission' => array('admin_forum'), 'areas' => array('maintain' => array('label' => $txt['maintain_title'], 'file' => 'Maintenance.controller.php', 'controller' => 'Maintenance_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_maintain', 'subsections' => array('routine' => array($txt['maintain_sub_routine'], 'admin_forum'), 'database' => array($txt['maintain_sub_database'], 'admin_forum'), 'members' => array($txt['maintain_sub_members'], 'admin_forum'), 'topics' => array($txt['maintain_sub_topics'], 'admin_forum'), 'hooks' => array($txt['maintain_sub_hooks_list'], 'admin_forum'), 'attachments' => array($txt['maintain_sub_attachments'], 'admin_forum'))), 'logs' => array('label' => $txt['logs'], 'file' => 'AdminLog.controller.php', 'controller' => 'AdminLog_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_logs', 'subsections' => array('errorlog' => array($txt['errlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'), 'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), 'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), 'banlog' => array($txt['ban_log'], 'manage_bans'), 'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => in_array('sp', $context['admin_features'])), 'tasklog' => array($txt['scheduled_log'], 'admin_forum'), 'badbehaviorlog' => array($txt['badbehavior_log'], 'admin_forum', 'enabled' => !empty($modSettings['badbehavior_enabled']), 'url' => $scripturl . '?action=admin;area=logs;sa=badbehaviorlog;desc'), 'pruning' => array($txt['pruning_title'], 'admin_forum'))), 'scheduledtasks' => array('label' => $txt['maintain_tasks'], 'file' => 'ManageScheduledTasks.controller.php', 'controller' => 'ManageScheduledTasks_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_scheduled', 'subsections' => array('tasks' => array($txt['maintain_tasks'], 'admin_forum'), 'tasklog' => array($txt['scheduled_log'], 'admin_forum'))), 'mailqueue' => array('label' => $txt['mailqueue_title'], 'file' => 'ManageMail.controller.php', 'controller' => 'ManageMail_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_mail', 'subsections' => array('browse' => array($txt['mailqueue_browse'], 'admin_forum'), 'settings' => array($txt['mailqueue_settings'], 'admin_forum'))), 'reports' => array('enabled' => in_array('rg', $context['admin_features']), 'label' => $txt['generate_reports'], 'file' => 'Reports.controller.php', 'controller' => 'Reports_Controller', 'function' => 'action_index', 'icon' => 'transparent.png', 'class' => 'admin_img_reports'), 'repairboards' => array('label' => $txt['admin_repair'], 'file' => 'RepairBoards.controller.php', 'controller' => 'RepairBoards_Controller', 'function' => 'action_repairboards', 'select' => 'maintain', 'hidden' => true))));
     // Any files to include for administration?
     call_integration_include_hook('integrate_admin_include');
     $menuOptions = array('hook' => 'admin', 'default_include_dir' => ADMINDIR);
     // Actually create the menu!
     $admin_include_data = createMenu($admin_areas, $menuOptions);
     unset($admin_areas);
     // Nothing valid?
     if ($admin_include_data == false) {
         fatal_lang_error('no_access', false);
     }
     // Build the link tree.
     $context['linktree'][] = array('url' => $scripturl . '?action=admin', 'name' => $txt['admin_center']);
     if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') {
         $context['linktree'][] = array('url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'name' => $admin_include_data['label']);
     }
     if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) {
         $context['linktree'][] = array('url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0]);
     }
     // Make a note of the Unique ID for this menu.
     $context['admin_menu_id'] = $context['max_menu_id'];
     $context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id'];
     // Where in the admin are we?
     $context['admin_area'] = $admin_include_data['current_area'];
     // Now - finally - call the right place!
     if (isset($admin_include_data['file'])) {
         require_once $admin_include_data['file'];
     }
     callMenu($admin_include_data);
 }
/**
* 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';
    }
}
    /**
     * InitContent.
     */
    function pmxc_InitContent()
    {
        global $context, $user_info, $modSettings, $pmxCacheFunc;
        // if visible init the content
        if ($this->visible) {
            $cbtopic = isset($_GET['topic']) ? $_GET['topic'] : 0;
            if ($this->cfg['cache'] > 0) {
                // check the block cache
                if (($cachedata = $pmxCacheFunc['get']($this->cache_key, $this->cache_mode)) !== null) {
                    list($this->topics, $isRead, $this->boards, $this->cat_board) = $cachedata;
                    if (isset($isRead[$user_info['id']]) && array_key_exists($cbtopic, $isRead[$user_info['id']]) && empty($isRead[$user_info['id']][$cbtopic])) {
                        $isRead[$user_info['id']][$cbtopic] = 1;
                        $cachedata = array($this->topics, $isRead, $this->boards, $this->cat_board);
                        $pmxCacheFunc['put']($this->cache_key, $cachedata, $this->cache_time, $this->cache_mode);
                    }
                } else {
                    $cachedata = $this->cbt_fetchdata();
                    $pmxCacheFunc['put']($this->cache_key, $cachedata, $this->cache_time, $this->cache_mode);
                    list($this->topics, $isRead, $this->boards, $this->cat_board) = $cachedata;
                }
            } else {
                $cachedata = $this->cbt_fetchdata();
                list($this->topics, $isRead, $this->boards, $this->cat_board) = $cachedata;
            }
            unset($cachedata);
            $this->isRead = isset($isRead[$user_info['id']]) ? $isRead[$user_info['id']] : null;
            // no boards .. disable the block
            if (!empty($this->boards)) {
                if (empty($modSettings['pmxCBTNavLoaded'])) {
                    addInlineJavascript('
	var pmxCBTimages = new Array("' . $context['pmx_imageurl'] . 'minus.png", "' . $context['pmx_imageurl'] . 'plus.png");
	var pmxCBTallBoards = {};');
                    loadJavascriptFile(PortaMx_loadCompressed('PortaMxCBTNav.js'), array('external' => true));
                    $modSettings['pmxCBTNavLoaded'] = true;
                }
                addInlineJavascript('
	pmxCBTallBoards[' . $this->cfg['id'] . '] = new Array("' . implode('", "', $this->boards) . '");');
            } else {
                $this->visible = false;
            }
        }
        // return the visibility flag (true/false)
        return $this->visible;
    }
 /**
  * Entrance point for the registration center, it checks permisions and forwards
  * to the right method based on the subaction.
  *
  * - Accessed by ?action=admin;area=regcenter.
  * - Requires either the moderate_forum or the admin_forum permission.
  *
  * @uses Login language file
  * @uses Register template.
  * @see Action_Controller::action_index()
  */
 public function action_index()
 {
     global $context, $txt;
     // Loading, always loading.
     loadLanguage('Login');
     loadTemplate('Register');
     loadJavascriptFile('register.js');
     $subActions = array('register' => array('controller' => $this, 'function' => 'action_register', 'permission' => 'moderate_forum'), 'agreement' => array('controller' => $this, 'function' => 'action_agreement', 'permission' => 'admin_forum'), 'reservednames' => array('controller' => $this, 'function' => 'action_reservednames', 'permission' => 'admin_forum'), 'settings' => array('controller' => $this, 'function' => 'action_registerSettings_display', 'permission' => 'admin_forum'));
     // Action controller
     $action = new Action('manage_registrations');
     // Next create the tabs for the template.
     $context[$context['admin_menu_name']]['tab_data'] = array('title' => $txt['registration_center'], 'help' => 'registrations', 'description' => $txt['admin_settings_desc'], 'tabs' => array('register' => array('description' => $txt['admin_register_desc']), 'agreement' => array('description' => $txt['registration_agreement_desc']), 'reservednames' => array('description' => $txt['admin_reserved_desc']), 'settings' => array('description' => $txt['admin_settings_desc'])));
     // Work out which to call... call integrate_sa_manage_registrations
     $subAction = $action->initialize($subActions, 'register');
     // Final bits
     $context['page_title'] = $txt['maintain_title'];
     $context['sub_action'] = $subAction;
     // Call the right function for this sub-action.
     $action->dispatch($subAction);
 }
Exemplo n.º 13
0
/**
 * Images cache
 *
 * @name      Images cache
 * @copyright Images cache contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * @version 0.1
 *
 */
function imageNeedsCache($img)
{
    global $boardurl, $txt;
    static $js_loaded = false;
    $parseboard = parse_url($boardurl);
    $parseimg = parse_url($img);
    if (!($parseboard['scheme'] === 'https') || $parseboard['scheme'] === $parseimg['scheme']) {
        return false;
    }
    if ($js_loaded === false) {
        $js_loaded = true;
        loadJavascriptFile('imgcache.js', array('defer' => true));
        loadLanguage('imgcache');
    }
    require_once SUBSDIR . '/Graphics.subs.php';
    $destination = CACHEDIR . '/img_cache_' . md5($img);
    if (!file_exists($destination)) {
        resizeImageFile($img, $destination, 200, 200, 3);
    }
    return $boardurl . '/imgcache.php?id=' . md5($img) . '" rel="cached" data-warn="' . Util::htmlspecialchars($txt['httpimgcache_warn_ext']) . '" data-url="' . Util::htmlspecialchars($img);
}
Exemplo n.º 14
0
 /**
  * InitContent.
  * Checks the cache status and create the content.
  */
 function pmxc_InitContent()
 {
     global $pmxCacheFunc, $modSettings;
     // if visible init the content
     if ($this->visible) {
         if ($this->cfg['cache'] > 0) {
             // check the block cache
             if (($this->faderdata = $pmxCacheFunc['get']($this->cache_key, $this->cache_mode)) === null) {
                 $this->getFaderData();
                 $pmxCacheFunc['put']($this->cache_key, $this->faderdata, $this->cache_time, $this->cache_mode);
             }
         } else {
             $this->getFaderData();
         }
         if (empty($modSettings['pmxFaderLoaded'])) {
             loadJavascriptFile(PortaMx_loadCompressed('PortaMxFader.js'), array('external' => true));
             $modSettings['pmxFaderLoaded'] = true;
         }
     }
     // return the visibility flag (true/false)
     return $this->visible;
 }
 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);
 }
/**
* Receive all the posts from the articles manager, check it, then save it.
* Finally the articles are prepared and the template loaded.
*/
function PortaMx_AdminArticles()
{
    global $smcFunc, $pmxCacheFunc, $context, $sourcedir, $scripturl, $modSettings, $user_info, $txt;
    $admMode = isset($_GET['action']) ? $_GET['action'] : '';
    // fix the linktree
    if ($admMode == 'admin') {
        foreach ($context['linktree'] as $key => $data) {
            if (strpos($data['url'], 'pmx_articles') !== false) {
                $context['linktree'] = array_merge(array_slice($context['linktree'], 0, $key), array(array('url' => $scripturl . '?action=admin;area=pmx_center;' . $context['session_var'] . '=' . $context['session_id'], 'name' => $txt['pmx_extension'])), array_slice($context['linktree'], $key, count($context['linktree']) - $key));
                break;
            }
        }
    }
    if (($admMode == 'admin' || $admMode == 'portamx') && isset($_GET['area']) && $_GET['area'] == 'pmx_articles') {
        if (allowPmx('pmx_admin, pmx_articles, pmx_create')) {
            require_once $context['pmx_sourcedir'] . 'AdminSubs.php';
            $context['pmx']['subaction'] = !empty($_POST['sa']) ? $_POST['sa'] : 'overview';
            // From template ?
            if (PortaMx_checkPOST()) {
                // Make sure we have a valid session...
                checkSession('post');
                // get current pageindex
                if (isset($_POST['articlestart'])) {
                    $context['pmx']['articlestart'] = $_POST['articlestart'];
                }
                // actions from overview?
                if ($context['pmx']['subaction'] == 'overview' && empty($_POST['cancel_overview'])) {
                    // from xml on overview?
                    if (isset($_POST['xml'])) {
                        $xmlResult = '';
                    }
                    // filter set ?
                    if (isset($_POST['filter'])) {
                        $_SESSION['PortaMx']['filter'] = $_POST['filter'];
                    }
                    // Row pos updates from overview?
                    if (!empty($_POST['upd_rowpos'])) {
                        list($fromID, $place, $idto) = Pmx_StrToArray($_POST['upd_rowpos']);
                        $request = $smcFunc['db_query']('', '
							SELECT id
							FROM {db_prefix}portamx_articles
							WHERE id ' . ($place == 'before' ? '<' : '>') . ' {int:id}
							LIMIT 1', array('id' => $idto));
                        list($toID) = $smcFunc['db_fetch_row']($request);
                        $smcFunc['db_free_result']($request);
                        $toID = is_null($toID) ? $place == 'before' ? -1 : 0 : $toID;
                        $request = $smcFunc['db_query']('', '
							SELECT MAX(id) +1
							FROM {db_prefix}portamx_articles', array());
                        list($maxID) = $smcFunc['db_fetch_row']($request);
                        $smcFunc['db_free_result']($request);
                        // create the query...
                        if ($toID == -1) {
                            // move from to first
                            $query = array('SET id = 0 WHERE id = ' . $fromID, 'SET id = id + 1 WHERE id >= 1 AND id <= ' . $fromID, 'SET id = 1 WHERE id = 0');
                        } elseif ($toID == 0) {
                            // move from to end
                            $query = array('SET id = ' . $maxID . ' WHERE id = ' . $fromID, 'SET id = id - 1 WHERE id >= ' . $fromID);
                        } elseif ($toID > $fromID) {
                            // to > from - move to after from
                            $query = array('SET id = id + 1 WHERE id >= ' . $toID, 'SET id = ' . $toID . ' WHERE id = ' . $fromID, 'SET id = id - 1 WHERE id >= ' . $fromID);
                        } else {
                            // to < from - move to before from
                            $query = array('SET id = 0 WHERE id = ' . $fromID, 'SET id = id + 1 WHERE id >= ' . $toID . ' AND id <= ' . $fromID, 'SET id = ' . $toID . ' WHERE id = 0');
                        }
                        // execute
                        foreach ($query as $qdata) {
                            $smcFunc['db_query']('', 'UPDATE {db_prefix}portamx_articles ' . $qdata, array());
                        }
                    }
                    // updates from overview popups ?
                    if (!empty($_POST['upd_overview'])) {
                        $updates = array();
                        foreach ($_POST['upd_overview'] as $updkey => $updvalues) {
                            foreach ($updvalues as $id => $values) {
                                if ($updkey == 'title') {
                                    foreach ($values as $key => $val) {
                                        if ($key == 'lang') {
                                            foreach ($val as $langname => $langvalue) {
                                                $updates[$id]['config'][$updkey][$langname] = $langvalue;
                                            }
                                        } else {
                                            $updates[$id]['config'][$updkey . '_' . $key] = $val;
                                        }
                                    }
                                } else {
                                    $updates[$id][$updkey] = $values;
                                }
                            }
                        }
                        // save all updates
                        $idList = array();
                        $catList = array();
                        foreach ($updates as $id => $values) {
                            $idList[] = $id;
                            foreach ($values as $rowname => $data) {
                                $request = $smcFunc['db_query']('', '
									SELECT config, catid, acsgrp
									FROM {db_prefix}portamx_articles
									WHERE id = {int:id}', array('id' => $id));
                                $row = $smcFunc['db_fetch_assoc']($request);
                                $smcFunc['db_free_result']($request);
                                $catList[] = $row['catid'];
                                // update config
                                if ($rowname == 'config') {
                                    $cfg = unserialize($row['config']);
                                    foreach ($data as $ckey => $cval) {
                                        if ($ckey == 'title') {
                                            foreach ($cval as $lang => $val) {
                                                $cfg[$ckey][$lang] = $val;
                                            }
                                        } else {
                                            $cfg[$ckey] = $cval;
                                        }
                                    }
                                    $smcFunc['db_query']('', '
										UPDATE {db_prefix}portamx_articles
										SET config = {string:config}
										WHERE id = {int:id}', array('id' => $id, 'config' => serialize($cfg)));
                                } elseif ($rowname == 'category') {
                                    $smcFunc['db_query']('', '
										UPDATE {db_prefix}portamx_articles
										SET catid = {int:val}
										WHERE id = {int:id}', array('id' => $id, 'val' => $data));
                                } else {
                                    $mode = substr($rowname, 0, 3);
                                    // update (replace)
                                    if ($mode == 'upd') {
                                        $newacs = explode(',', $data);
                                    } elseif ($mode == 'add') {
                                        $newacs = array_unique(array_merge(explode(',', $row['acsgrp']), explode(',', $data)));
                                    } else {
                                        $newacs = array_unique(array_diff(explode(',', $row['acsgrp']), explode(',', $data)));
                                    }
                                    $smcFunc['db_query']('', '
										UPDATE {db_prefix}portamx_articles
										SET acsgrp = {string:val}
										WHERE id = {int:id}', array('id' => $id, 'val' => implode(',', $newacs)));
                                    // send by xml?
                                    if (isset($_POST['xml'])) {
                                        $request = $smcFunc['db_query']('', '
											SELECT active
											FROM {db_prefix}portamx_articles
											WHERE id = {int:id}', array('id' => $id));
                                        list($active) = $smcFunc['db_fetch_row']($request);
                                        $smcFunc['db_free_result']($request);
                                        $acsnew = implode(',', $newacs);
                                        $xmlResult .= (!empty($xmlResult) ? '&' : '') . $id . '|' . $acsnew . '|' . count($newacs) . '|' . intval(allowPmxGroup($newacs)) . '|' . (!empty($active) ? '1' : '0');
                                    }
                                }
                            }
                        }
                        // clear cached blocks && Cat/Art Session Keys
                        $pmxCacheFunc['clean']();
                        if (isset($_SESSION['PortaMx'])) {
                            foreach ($_SESSION['PortaMx'] as $key => $val) {
                                if (strpos($key, 'pmxpost_') !== false) {
                                    unset($_SESSION['PortaMx'][$key]);
                                }
                            }
                        }
                        if (isset($_POST['xml'])) {
                            // return update result
                            ob_start();
                            if (!empty($_POST['result'])) {
                                echo $_POST['result'];
                            } else {
                                echo $xmlResult;
                            }
                            ob_end_flush();
                            exit;
                        }
                    }
                    // add a new article
                    if (!empty($_POST['add_new_article'])) {
                        $article = PortaMx_getDefaultArticle($_POST['add_new_article']);
                        $context['pmx']['subaction'] = 'editnew';
                    } elseif (!empty($_POST['edit_article']) || !empty($_POST['clone_article'])) {
                        $id = !empty($_POST['clone_article']) ? $_POST['clone_article'] : $_POST['edit_article'];
                        // load the article for edit/clone
                        $request = $smcFunc['db_query']('', '
							SELECT *
							FROM {db_prefix}portamx_articles
							WHERE id = {int:id}', array('id' => $id));
                        $row = $smcFunc['db_fetch_assoc']($request);
                        $article = array('id' => $row['id'], 'name' => $row['name'], 'catid' => $row['catid'], 'acsgrp' => $row['acsgrp'], 'ctype' => $row['ctype'], 'config' => $row['config'], 'content' => $row['content'], 'active' => $row['active'], 'owner' => $row['owner'], 'created' => $row['created'], 'approved' => $row['approved'], 'approvedby' => $row['approvedby'], 'updated' => $row['updated'], 'updatedby' => $row['updatedby']);
                        $smcFunc['db_free_result']($request);
                        if (!empty($_POST['clone_article'])) {
                            $article['id'] = 0;
                            $article['active'] = 0;
                            $article['approved'] = 0;
                            $article['owner'] = $user_info['id'];
                            $article['created'] = 0;
                            $article['updated'] = 0;
                            $article['updatedby'] = 0;
                            $context['pmx']['subaction'] = 'editnew';
                        } else {
                            $context['pmx']['subaction'] = 'edit';
                        }
                    } elseif (!empty($_POST['delete_article'])) {
                        $delid = $_POST['delete_article'];
                        // get the current page
                        $context['pmx']['articlestart'] = getCurrentPage($delid, $context['pmx']['settings']['manager']['artpage'], true);
                        $smcFunc['db_query']('', '
							DELETE FROM {db_prefix}portamx_articles
							WHERE id = {int:id}', array('id' => $delid));
                        // clear cached blocks
                        $pmxCacheFunc['clean']();
                    } elseif (!empty($_POST['chg_approved'])) {
                        $smcFunc['db_query']('', '
							UPDATE {db_prefix}portamx_articles
							SET approved = CASE WHEN approved = 0 THEN {int:apptime} ELSE 0 END, approvedby = {int:appmember}
							WHERE id = {int:id}', array('id' => $_POST['chg_approved'], 'apptime' => forum_time(), 'appmember' => $user_info['id']));
                        // clear cached blocks
                        $pmxCacheFunc['clean']();
                    } elseif (!empty($_POST['chg_active'])) {
                        $smcFunc['db_query']('', '
							UPDATE {db_prefix}portamx_articles
							SET active = CASE WHEN active = 0 THEN {int:apptime} ELSE 0 END
							WHERE id = {int:id}', array('id' => $_POST['chg_active'], 'apptime' => forum_time()));
                        // clear cached blocks
                        $pmxCacheFunc['clean']();
                    }
                    if (isset($_POST['xml']) && (!empty($_POST['chg_active']) || !empty($_POST['chg_approved']))) {
                        $id = !empty($_POST['chg_active']) ? $_POST['chg_active'] : $_POST['chg_approved'];
                        $request = $smcFunc['db_query']('', '
							SELECT active, approved
							FROM {db_prefix}portamx_articles
							WHERE id = {int:id}', array('id' => $id));
                        list($active, $approved) = $smcFunc['db_fetch_row']($request);
                        $smcFunc['db_free_result']($request);
                        // return update result
                        ob_start();
                        echo $id . ',' . (!empty($_POST['chg_active']) ? intval(!empty($active)) : intval(!empty($approved)));
                        ob_end_flush();
                        exit;
                    }
                } elseif (!empty($_POST['cancel_edit']) || !empty($_POST['cancel_overview'])) {
                    // called fron blocks move/clone ?
                    if (!empty($_POST['fromblock'])) {
                        // on cancel after saved remove the article
                        if ($_POST['sa'] == 'edit' && !empty($_POST['id'])) {
                            $smcFunc['db_query']('', '
								DELETE FROM {db_prefix}portamx_articles
								WHERE id = {int:id}', array('id' => $_POST['id']));
                            $pmxCacheFunc['clean']();
                        }
                        // redirect back to the blocks manager
                        @(list($mode, $side, $bid) = explode('.', $_POST['fromblock']));
                        redirectexit('action=' . $admMode . ';area=pmx_blocks;sa=' . $side . ';' . $context['session_var'] . '=' . $context['session_id']);
                    }
                    // Otherwise let's load the overview
                    $context['pmx']['subaction'] = 'overview';
                } elseif ($context['pmx']['subaction'] == 'editnew' || $context['pmx']['subaction'] == 'edit') {
                    $context['pmx']['fromblock'] = $_POST['fromblock'];
                    // check defined numeric vars (check_num_vars holds the posted array to check like [varname][varname] ...)
                    if (isset($_POST['check_num_vars'])) {
                        foreach ($_POST['check_num_vars'] as $val) {
                            $data = explode(',', $val);
                            $post = '$_POST' . str_replace(array('[', ']'), array('[\'', '\']'), $data[0]);
                            if (eval("return isset({$post});") && eval("return !is_numeric({$post});")) {
                                eval("{$post} = {$data['1']};");
                            }
                        }
                    }
                    if (isset($_POST['content']) && PortaMx_makeSafeContent($_POST['content']) != '') {
                        // convert html/script to bbc
                        if ($_POST['ctype'] == 'bbc_script' && in_array($_POST['contenttype'], array('html', 'script'))) {
                            $_POST['content'] = PortaMx_SmileyToBBC($_POST['content']);
                            if (preg_match_all('/<img.*(style[^\\"]*\\"([^\\"]*\\"))[^>]*>/U', $_POST['content'], $match) > 0) {
                                foreach ($match[0] as $key => $val) {
                                    $repl = ' ' . str_replace(array('"', ': ', ':', 'px;'), array('', '="', '="', '" '), $match[2][$key]);
                                    $_POST['content'] = str_replace($val, str_replace($match[1][$key], $repl, $val), $_POST['content']);
                                }
                            }
                            require_once $sourcedir . '/Subs-Editor.php';
                            $modSettings['smiley_enable'] = true;
                            $user_info['smiley_set'] = 'PortaMx';
                            $_POST['content'] = html_to_bbc($_POST['content']);
                        } elseif ($_POST['contenttype'] == 'bbc_script' && in_array($_POST['ctype'], array('html', 'script'))) {
                            $_POST['content'] = PortaMx_BBCsmileys(parse_bbc(PortaMx_makeSafeContent($_POST['content'], $_POST['contenttype']), false));
                            $_POST['content'] = str_replace(array('<hr>', '<br>'), array('<hr />', '<br />'), $_POST['content']);
                            $_POST['content'] = preg_replace_callback('/<\\/[^>]*>|<[^\\/]*\\/>|<ul[^>]*>|<ol[^>]*>/', create_function('$matches', 'return $matches[0] ."\\n";'), $_POST['content']);
                            if (preg_match_all('/<img[^w]*(width=\\"([0-9]+)\\")(\\sheight=\\"([\\s0-9]+)\\")[^>]*>/', $_POST['content'], $match) > 0) {
                                foreach ($match[0] as $key => $val) {
                                    $_POST['content'] = str_replace($match[1][$key], '', $_POST['content']);
                                    $_POST['content'] = str_replace($match[3][$key], 'style="width: ' . $match[2][$key] . 'px;height: ' . $match[4][$key] . 'px;"', $_POST['content']);
                                }
                                $_POST['content'] = preg_replace('/px;"[^c]*class=/', 'px;" class=', $_POST['content']);
                            }
                        } elseif ($_POST['ctype'] == 'php' && $_POST['contenttype'] == 'php') {
                            pmxPHP_convert();
                        } elseif ($_POST['ctype'] == 'html' && $_POST['contenttype'] == 'html') {
                            $_POST['content'] = str_replace('/ckeditor/../Smileys/', '/Smileys/', $_POST['content']);
                            if (preg_match_all('~<img.*(class[^r]*resized[^\\"]*\\")[^>]*>~', $_POST['content'], $match) > 0) {
                                foreach ($match[0] as $key => $val) {
                                    $endChr = substr($val, -2) !== '/>' ? array('>', '/>') : array(' />', '/>');
                                    $repl = str_replace($match[1][$key], '', $val);
                                    $_POST['content'] = str_replace($val, str_replace($endChr[0], ' class="bbc_img resized"' . $endChr[1], $repl), $_POST['content']);
                                }
                            } elseif (preg_match_all('~<img[^>]*>~', $_POST['content'], $match) > 0) {
                                foreach ($match[0] as $key => $val) {
                                    $endChr = substr($val, -2) !== ' />' ? array('>', '/>') : array(' />', '/>');
                                    if (strpos($val, '/Smileys/') === false) {
                                        $_POST['content'] = str_replace($val, str_replace($endChr[0], ' class="bbc_img resized"' . $endChr[1], $val), $_POST['content']);
                                    }
                                }
                            }
                        }
                    }
                    // get all data
                    $article = array('id' => $_POST['id'], 'name' => $_POST['name'], 'catid' => $_POST['catid'], 'acsgrp' => !empty($_POST['acsgrp']) ? implode(',', $_POST['acsgrp']) : '', 'ctype' => $_POST['ctype'], 'config' => serialize($_POST['config']), 'content' => $_POST['content'], 'active' => $_POST['active'], 'owner' => $_POST['owner'], 'created' => $_POST['created'], 'approved' => $_POST['approved'], 'approvedby' => $_POST['approvedby'], 'updated' => $_POST['updated'], 'updatedby' => $_POST['updatedby']);
                    // save article if have content..
                    if (!empty($article['content']) && empty($_POST['edit_change']) && (!empty($_POST['save_edit']) || !empty($article['content']) && !empty($_POST['save_edit_continue']))) {
                        // if new article get the last id
                        if ($context['pmx']['subaction'] == 'editnew') {
                            $request = $smcFunc['db_query']('', '
								SELECT MAX(id)
								FROM {db_prefix}portamx_articles', array());
                            list($dbid) = $smcFunc['db_fetch_row']($request);
                            $smcFunc['db_free_result']($request);
                            $article['id'] = strval(1 + ($dbid === null ? $article['id'] : $dbid));
                            $article['created'] = forum_time();
                            // auto approve for admins
                            if (allowPmx('pmx_admin')) {
                                $article['approved'] = forum_time();
                                $article['approvedby'] = $user_info['id'];
                            }
                            // insert new article
                            $smcFunc['db_insert']('ignore', '
								{db_prefix}portamx_articles', array('id' => 'int', 'name' => 'string', 'catid' => 'int', 'acsgrp' => 'string', 'ctype' => 'string', 'config' => 'string', 'content' => 'string', 'active' => 'int', 'owner' => 'int', 'created' => 'int', 'approved' => 'int', 'approvedby' => 'int', 'updated' => 'int', 'updatedby' => 'int'), $article, array());
                            // clear cache
                            $pmxCacheFunc['clean']();
                        } else {
                            $article['updated'] = forum_time();
                            $article['updatedby'] = $user_info['id'];
                            // update the article
                            $smcFunc['db_query']('', '
								UPDATE {db_prefix}portamx_articles
								SET name = {string:name}, catid = {int:catid}, acsgrp = {string:acsgrp}, ctype = {string:ctype}, config = {string:config},
										content = {string:content}, active = {int:active}, owner = {int:owner}, created = {int:created}, approved = {int:approved},
										approvedby = {int:approvedby}, updated = {int:updated}, updatedby = {int:updatedby}
								WHERE id = {int:id}', array('id' => $article['id'], 'name' => $article['name'], 'catid' => $article['catid'], 'acsgrp' => $article['acsgrp'], 'ctype' => $article['ctype'], 'config' => $article['config'], 'content' => $article['content'], 'active' => $article['active'], 'owner' => $article['owner'], 'created' => $article['created'], 'approved' => $article['approved'], 'approvedby' => $article['approvedby'], 'updated' => $article['updated'], 'updatedby' => $article['updatedby']));
                        }
                        // clear cache
                        $pmxCacheFunc['clean']();
                        $context['pmx']['subaction'] = 'edit';
                    }
                    // continue edit ?
                    if (!empty($_POST['save_edit']) || !empty($_POST['save_edit_continue'])) {
                        if (empty($_POST['save_edit_continue'])) {
                            // edit done, is it a move/clone from blocks?
                            if (!empty($context['pmx']['fromblock'])) {
                                @(list($mode, $side, $bid) = explode('.', $context['pmx']['fromblock']));
                                // was block moved?
                                if ($mode == 'move') {
                                    $request = $smcFunc['db_query']('', '
										SELECT pos, blocktype
										FROM {db_prefix}portamx_blocks
										WHERE id = {int:bid}', array('bid' => $bid));
                                    $block = $smcFunc['db_fetch_assoc']($request);
                                    $smcFunc['db_free_result']($request);
                                    // update all pos >= moved id
                                    $smcFunc['db_query']('', '
										UPDATE {db_prefix}portamx_blocks
										SET pos = pos - 1
										WHERE side = {string:side} AND pos >= {int:pos}', array('side' => $side, 'pos' => $block['pos']));
                                    // delete the block
                                    $smcFunc['db_query']('', '
										DELETE FROM {db_prefix}portamx_blocks
										WHERE id = {int:id}', array('id' => $bid));
                                    // clear cache and SEF pages list
                                    $pmxCacheFunc['clean']();
                                }
                            }
                            // go to article overview
                            $context['pmx']['subaction'] = 'overview';
                            $context['pmx']['articlestart'] = getCurrentPage($article['id'], $context['pmx']['settings']['manager']['artpage']);
                        }
                    }
                    // clear cached blocks
                    $pmxCacheFunc['clean']();
                }
                if ($context['pmx']['subaction'] == 'overview') {
                    if (!isset($context['pmx']['articlestart'])) {
                        $context['pmx']['articlestart'] = 0;
                    }
                    redirectexit('action=' . $admMode . ';area=pmx_articles;' . $context['session_var'] . '=' . $context['session_id'] . ';pg=' . $context['pmx']['articlestart']);
                }
            }
            // load the template, initialize the page title
            loadTemplate($context['pmx_templatedir'] . 'AdminArticles');
            $context['page_title'] = $txt['pmx_articles'];
            $context['pmx']['AdminMode'] = $admMode;
            $context['pmx']['RegBlocks'] = eval($context['pmx']['registerblocks']);
            // direct edit request?
            if (isset($_GET['sa']) && PortaMx_makeSafe($_GET['sa']) == 'edit' && !empty($_GET['id'])) {
                // move or clone from blocks?
                if (isset($_GET['from'])) {
                    $context['pmx']['fromblock'] = PortaMx_makeSafe($_GET['from']) . '.' . PortaMx_makeSafe($_GET['id']);
                    // load the block
                    $request = $smcFunc['db_query']('', '
						SELECT *
						FROM {db_prefix}portamx_blocks
						WHERE id = {int:id}', array('id' => PortaMx_makeSafe($_GET['id'])));
                    $row = $smcFunc['db_fetch_assoc']($request);
                    $smcFunc['db_free_result']($request);
                    // modify the config array
                    $cfg = unserialize($row['config']);
                    if (isset($cfg['pagename'])) {
                        $pgname = $cfg['pagename'];
                        unset($cfg['pagename']);
                    } else {
                        $pgname = '';
                    }
                    unset($cfg['ext_opts']);
                    if (isset($cfg['frontmode'])) {
                        unset($cfg['frontmode']);
                    }
                    $cfg['can_moderate'] = allowedTo('admin_forum') ? 0 : 1;
                    $article = array('id' => 0, 'name' => $pgname, 'catid' => 0, 'acsgrp' => $row['acsgrp'], 'ctype' => $row['blocktype'], 'config' => serialize($cfg), 'content' => $row['content'], 'active' => 0, 'owner' => $user_info['id'], 'created' => 0, 'approved' => 0, 'approvedby' => 0, 'updated' => 0, 'updatedby' => 0);
                    $context['pmx']['subaction'] = 'editnew';
                    $context['pmx']['articlestart'] = 0;
                } else {
                    $context['pmx']['fromblock'] = '';
                    $request = $smcFunc['db_query']('', '
						SELECT *
						FROM {db_prefix}portamx_articles
						WHERE id = {int:id}', array('id' => PortaMx_makeSafe($_GET['id'])));
                    if ($smcFunc['db_num_rows']($request) > 0) {
                        $row = $smcFunc['db_fetch_assoc']($request);
                        $article = array('id' => $row['id'], 'name' => $row['name'], 'catid' => $row['catid'], 'acsgrp' => $row['acsgrp'], 'ctype' => $row['ctype'], 'config' => $row['config'], 'content' => $row['content'], 'active' => $row['active'], 'owner' => $row['owner'], 'created' => $row['created'], 'approved' => $row['approved'], 'approvedby' => $row['approvedby'], 'updated' => $row['updated'], 'updatedby' => $row['updatedby']);
                        $smcFunc['db_free_result']($request);
                        $context['pmx']['subaction'] = 'edit';
                        $context['pmx']['articlestart'] = 0;
                    }
                }
            }
            // continue edit or overview?
            if ($context['pmx']['subaction'] == 'overview') {
                // load article data for overview
                if (!allowPmx('pmx_articles') && allowPmx('pmx_create', true)) {
                    $where = 'WHERE a.owner = {int:owner}';
                } else {
                    $where = '';
                }
                if (!isset($_SESSION['PortaMx']['filter'])) {
                    $_SESSION['PortaMx']['filter'] = array('category' => '', 'approved' => 0, 'active' => 0, 'myown' => 0, 'member' => '');
                }
                if ($_SESSION['PortaMx']['filter']['category'] != '') {
                    $where .= (empty($where) ? 'WHERE ' : ' AND ') . 'a.catid IN ({array_int:catfilter})';
                }
                if ($_SESSION['PortaMx']['filter']['approved'] != 0) {
                    $where .= empty($where) ? 'WHERE ' : ' AND ';
                    if ($_SESSION['PortaMx']['filter']['active'] != 0) {
                        $where .= '(a.approved = 0 OR a.active = 0)';
                    } else {
                        $where .= 'a.approved = 0';
                    }
                }
                if ($_SESSION['PortaMx']['filter']['active'] != 0) {
                    $where .= empty($where) ? 'WHERE ' : ' AND ';
                    if ($_SESSION['PortaMx']['filter']['approved'] != 0) {
                        $where .= '(a.active = 0 OR a.approved = 0)';
                    } else {
                        $where .= 'a.active = 0';
                    }
                }
                if ($_SESSION['PortaMx']['filter']['myown'] != 0) {
                    $where .= (empty($where) ? 'WHERE ' : ' AND ') . 'a.owner = {int:owner}';
                }
                if ($_SESSION['PortaMx']['filter']['member'] != '') {
                    $where .= (empty($where) ? 'WHERE ' : ' AND ') . 'm.member_name LIKE {string:memname}';
                }
                if (isset($_GET['pg']) && !is_array($_GET['pg'])) {
                    $context['pmx']['articlestart'] = PortaMx_makeSafe($_GET['pg']);
                    unset($_GET['pg']);
                } elseif (!isset($context['pmx']['articlestart'])) {
                    $context['pmx']['articlestart'] = 0;
                }
                $cansee = allowPmx('pmx_articles, pmx_create', true);
                $isadmin = allowPmx('pmx_admin');
                $memerIDs = array();
                $context['pmx']['articles'] = array();
                $context['pmx']['article_rows'] = array();
                $context['pmx']['totalarticles'] = 0;
                $result = null;
                $request = $smcFunc['db_query']('', '
					SELECT a.id, a.name, a.catid, a.acsgrp, a.ctype, a.config, a.active, a.owner, a.created, a.approved, a.approvedby, a.updated, a.updatedby, a.content, c.artsort, c.level, c.name AS catname
					FROM {db_prefix}portamx_articles AS a' . ($_SESSION['PortaMx']['filter']['member'] != '' ? '
					LEFT JOIN {db_prefix}members AS m ON (a.owner = m.id_member)' : '') . '
					LEFT JOIN {db_prefix}portamx_categories AS c ON (a.catid = c.id)
					' . $where . '
					ORDER BY a.id', array('catfilter' => Pmx_StrToArray($_SESSION['PortaMx']['filter']['category']), 'memname' => str_replace('*', '%', $_SESSION['PortaMx']['filter']['member']), 'owner' => $user_info['id']));
                if ($smcFunc['db_num_rows']($request) > 0) {
                    while ($row = $smcFunc['db_fetch_assoc']($request)) {
                        $cfg = unserialize($row['config']);
                        if (!empty($isadmin) || $cansee && !empty($cfg['can_moderate'])) {
                            $memerIDs[] = $row['owner'];
                            $memerIDs[] = $row['approvedby'];
                            $memerIDs[] = $row['updatedby'];
                            $context['pmx']['article_rows'][$row['id']] = array('name' => $row['name'], 'cat' => str_repeat('&bull;', $row['level']) . $row['catname']);
                            $result[] = array('id' => $row['id'], 'name' => $row['name'], 'catid' => $row['catid'], 'cat' => str_repeat('&bull;', $row['level']) . $row['catname'], 'acsgrp' => $row['acsgrp'], 'ctype' => $row['ctype'], 'config' => $cfg, 'active' => $row['active'], 'owner' => $row['owner'], 'created' => $row['created'], 'approved' => $row['approved'], 'approvedby' => $row['approvedby'], 'updated' => $row['updated'], 'updatedby' => $row['updatedby'], 'content' => $row['content']);
                        }
                    }
                    $smcFunc['db_free_result']($request);
                    if (!empty($result)) {
                        foreach ($result as $st => $data) {
                            $context['pmx']['articles'][$st] = $data;
                        }
                        $context['pmx']['totalarticles'] = count($result);
                        if ($context['pmx']['totalarticles'] <= $context['pmx']['articlestart']) {
                            $context['pmx']['articlestart'] = 0;
                        }
                        // get all members names
                        $request = $smcFunc['db_query']('', '
							SELECT id_member, member_name
							FROM {db_prefix}members
							WHERE id_member IN ({array_int:members})', array('members' => array_unique($memerIDs)));
                        if ($smcFunc['db_num_rows']($request) > 0) {
                            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                                $context['pmx']['articles_member'][$row['id_member']] = $row['member_name'];
                            }
                            $smcFunc['db_free_result']($request);
                        }
                    }
                }
                // load popup js for overview
                loadJavascriptFile(PortaMx_loadCompressed('PortaMxPopup.js'), array('external' => true));
            } elseif (empty($_POST['save_edit'])) {
                // prepare the editor
                PortaMx_EditArticle($article['ctype'], 'content', $article['content']);
                // load the class file and create the object
                require_once $context['pmx_sysclassdir'] . 'PortaMx_AdminArticlesClass.php';
                $context['pmx']['editarticle'] = new PortaMxC_SystemAdminArticle($article);
                $context['pmx']['editarticle']->pmxc_AdmArticle_loadinit();
            }
        } else {
            fatal_error($txt['pmx_acces_error']);
        }
    }
}
Exemplo n.º 17
0
/**
 * 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);
    }
}
Exemplo n.º 18
0
    /**
     * Configuration settings for the admin template
     *
     * @return string
     */
    public function settings()
    {
        global $txt, $scripturl, $modSettings;
        // Generate a sample registration image.
        $verification_image = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand());
        // Visual verification.
        $config_vars = array(array('title', 'configure_verification_means'), array('desc', 'configure_verification_means_desc'), array('int', 'visual_verification_num_chars'), 'vv' => array('select', 'visual_verification_type', array($txt['setting_image_verification_off'], $txt['setting_image_verification_vsimple'], $txt['setting_image_verification_simple'], $txt['setting_image_verification_medium'], $txt['setting_image_verification_high'], $txt['setting_image_verification_extreme']), 'subtext' => $txt['setting_visual_verification_type_desc']));
        // Save it
        if (isset($_GET['save'])) {
            if (isset($_POST['visual_verification_num_chars']) && $_POST['visual_verification_num_chars'] < 6) {
                $_POST['visual_verification_num_chars'] = 5;
            }
        }
        $_SESSION['visual_verification_code'] = '';
        for ($i = 0; $i < $this->_num_chars; $i++) {
            $_SESSION['visual_verification_code'] .= $this->_standard_captcha_range[array_rand($this->_standard_captcha_range)];
        }
        // Some javascript for CAPTCHA.
        if ($this->_use_graphic_library) {
            loadJavascriptFile('jquery.captcha.js');
            addInlineJavascript('
		$(\'#visual_verification_type\').Elk_Captcha({
			\'imageURL\': ' . JavaScriptEscape($verification_image) . ',
			\'useLibrary\': true,
			\'letterCount\': ' . $this->_num_chars . ',
			\'refreshevent\': \'change\',
			\'admin\': true
		});', true);
        }
        // Show the image itself, or text saying we can't.
        if ($this->_use_graphic_library) {
            $config_vars['vv']['postinput'] = '<br /><img src="' . $verification_image . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image" /><br />';
        } else {
            $config_vars['vv']['postinput'] = '<br /><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
        }
        return $config_vars;
    }
Exemplo n.º 19
0
function char_template_list()
{
    global $smcFunc, $context, $txt;
    $context['char_templates'] = [];
    $request = $smcFunc['db_query']('', '
		SELECT id_template, template_name, position
		FROM {db_prefix}character_sheet_templates
		ORDER BY position ASC');
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['char_templates'][$row['id_template']] = $row;
    }
    $smcFunc['db_free_result']($request);
    loadTemplate('Admin-Chars');
    $context['page_title'] = $txt['char_templates'];
    $context['sub_template'] = 'char_templates';
    loadJavascriptFile('chars-jquery-ui-1.11.4.js', ['default_theme' => true], 'chars_jquery');
    addInlineJavascript('
	$(\'.sortable\').sortable({handle: ".handle"});', true);
}
Exemplo n.º 20
0
    /**
     * Verify the activation code, and activate the user if correct.
     * Accessed by ?action=activate
     */
    public function action_activate()
    {
        global $context, $txt, $modSettings, $scripturl, $language, $user_info;
        require_once SUBSDIR . '/Auth.subs.php';
        // Logged in users should not bother to activate their accounts
        if (!empty($user_info['id'])) {
            redirectexit();
        }
        loadLanguage('Login');
        loadTemplate('Login');
        loadJavascriptFile('sha256.js', array('defer' => true));
        if (empty($_REQUEST['u']) && empty($_POST['user'])) {
            if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
                fatal_lang_error('no_access', false);
            }
            $context['member_id'] = 0;
            $context['sub_template'] = 'resend';
            $context['page_title'] = $txt['invalid_activation_resend'];
            $context['can_activate'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] == '1';
            $context['default_username'] = isset($_GET['user']) ? $_GET['user'] : '';
            return;
        }
        // Get the code from the database...
        $row = findUser(empty($_REQUEST['u']) ? '
			member_name = {string:email_address} OR email_address = {string:email_address}' : '
			id_member = {int:id_member}', array('id_member' => isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, 'email_address' => isset($_POST['user']) ? $_POST['user'] : ''), false);
        // Does this user exist at all?
        if (empty($row)) {
            $context['sub_template'] = 'retry_activate';
            $context['page_title'] = $txt['invalid_userid'];
            $context['member_id'] = 0;
            return;
        }
        // Change their email address? (they probably tried a fake one first :P.)
        require_once SUBSDIR . '/Auth.subs.php';
        if (isset($_POST['new_email'], $_REQUEST['passwd']) && validateLoginPassword($_REQUEST['passwd'], $row['passwd'], $row['member_name'], true) && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) {
            if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
                fatal_lang_error('no_access', false);
            }
            // @todo Separate the sprintf?
            require_once SUBSDIR . '/DataValidator.class.php';
            if (!Data_Validator::is_valid($_POST, array('new_email' => 'valid_email|required|max_length[255]'), array('new_email' => 'trim'))) {
                fatal_error(sprintf($txt['valid_email_needed'], htmlspecialchars($_POST['new_email'], ENT_COMPAT, 'UTF-8')), false);
            }
            // Make sure their email isn't banned.
            isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
            // Ummm... don't even dare try to take someone else's email!!
            // @todo Separate the sprintf?
            if (userByEmail($_POST['new_email'])) {
                fatal_lang_error('email_in_use', false, array(htmlspecialchars($_POST['new_email'], ENT_COMPAT, 'UTF-8')));
            }
            updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
            $row['email_address'] = $_POST['new_email'];
            $email_change = true;
        }
        // Resend the password, but only if the account wasn't activated yet.
        if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'resend' && ($row['is_activated'] == 0 || $row['is_activated'] == 2) && (!isset($_REQUEST['code']) || $_REQUEST['code'] == '')) {
            require_once SUBSDIR . '/Mail.subs.php';
            $replacements = array('REALNAME' => $row['real_name'], 'USERNAME' => $row['member_name'], 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $row['id_member'] . ';code=' . $row['validation_code'], 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $row['id_member'], 'ACTIVATIONCODE' => $row['validation_code'], 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder');
            $emaildata = loadEmailTemplate('resend_activate_message', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
            sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
            $context['page_title'] = $txt['invalid_activation_resend'];
            // This will ensure we don't actually get an error message if it works!
            $context['error_title'] = '';
            fatal_lang_error(!empty($email_change) ? 'change_email_success' : 'resend_email_success', false);
        }
        // Quit if this code is not right.
        if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) {
            if (!empty($row['is_activated'])) {
                fatal_lang_error('already_activated', false);
            } elseif ($row['validation_code'] == '') {
                loadLanguage('Profile');
                fatal_error($txt['registration_not_approved'] . ' <a href="' . $scripturl . '?action=activate;user='******'member_name'] . '">' . $txt['here'] . '</a>.', false);
            }
            $context['sub_template'] = 'retry_activate';
            $context['page_title'] = $txt['invalid_activation_code'];
            $context['member_id'] = $row['id_member'];
            return;
        }
        // Let the integration know that they've been activated!
        call_integration_hook('integrate_activate', array($row['member_name']));
        // Validation complete - update the database!
        updateMemberData($row['id_member'], array('is_activated' => 1, 'validation_code' => ''));
        // Also do a proper member stat re-evaluation.
        updateStats('member', false);
        if (!isset($_POST['new_email'])) {
            require_once SUBSDIR . '/Notification.subs.php';
            sendAdminNotifications('activation', $row['id_member'], $row['member_name']);
        }
        $context += array('page_title' => $txt['registration_successful'], 'sub_template' => 'login', 'default_username' => $row['member_name'], 'default_password' => '', 'never_expire' => false, 'description' => $txt['activate_success']);
    }
Exemplo n.º 21
0
 /**
  * Display a message about the forum being in maintenance mode.
  *
  * What it does:
  * - Displays a login screen with sub template 'maintenance'.
  * - It sends a 503 header, so search engines don't index while we're in maintenance mode.
  */
 public function action_maintenance_mode()
 {
     global $txt, $mtitle, $mmessage, $context;
     loadLanguage('Login');
     loadTemplate('Login');
     loadJavascriptFile('sha256.js', array('defer' => true));
     createToken('login');
     // Send a 503 header, so search engines don't bother indexing while we're in maintenance mode.
     header('HTTP/1.1 503 Service Temporarily Unavailable');
     // Basic template stuff..
     $context['sub_template'] = 'maintenance';
     $context['title'] =& $mtitle;
     $context['description'] =& $mmessage;
     $context['page_title'] = $txt['maintain_mode'];
 }
Exemplo n.º 22
0
 /**
  * Allows the user to select the messages to be split.
  * is accessed with ?action=splittopics;sa=selectTopics.
  * uses 'select' sub template of the SplitTopics template or (for
  * XMLhttp) the 'split' sub template of the Xml template.
  * supports XMLhttp for adding/removing a message to the selection.
  * uses a session variable to store the selected topics.
  * shows two independent page indexes for both the selected and
  * not-selected messages (;topic=1.x;start2=y).
  */
 public function action_splitSelectTopics()
 {
     global $txt, $scripturl, $topic, $context, $modSettings, $options;
     $context['page_title'] = $txt['split_topic'] . ' - ' . $txt['select_split_posts'];
     $context['destination_board'] = !empty($_POST['move_to_board']) ? (int) $_POST['move_to_board'] : 0;
     // Haven't selected anything have we?
     $_SESSION['split_selection'][$topic] = empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic];
     // This is a special case for split topics from quick-moderation checkboxes
     if (isset($_REQUEST['subname_enc'])) {
         $this->_new_topic_subject = urldecode($_REQUEST['subname_enc']);
         $this->_set_session_values();
     }
     require_once SUBSDIR . '/Topic.subs.php';
     require_once SUBSDIR . '/Messages.subs.php';
     $context['not_selected'] = array('num_messages' => 0, 'start' => empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'], 'messages' => array());
     $context['selected'] = array('num_messages' => 0, 'start' => empty($_REQUEST['start2']) ? 0 : (int) $_REQUEST['start2'], 'messages' => array());
     $context['topic'] = array('id' => $topic, 'subject' => urlencode($_SESSION['new_topic_subject']));
     // Some stuff for our favorite template.
     $context['new_subject'] = $_SESSION['new_topic_subject'];
     // Using the "select" sub template.
     $context['sub_template'] = isset($_REQUEST['xml']) ? 'split' : 'select';
     // All of the js for topic split selection is needed
     if (!isset($_REQUEST['xml'])) {
         loadJavascriptFile('topic.js');
     }
     // Are we using a custom messages per page?
     $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
     // Get the message ID's from before the move.
     if (isset($_REQUEST['xml'])) {
         $original_msgs = array('not_selected' => messageAt($context['not_selected']['start'], $topic, array('not_in' => empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic], 'only_approved' => !$modSettings['postmod_active'] || !allowedTo('approve_posts'), 'limit' => $context['messages_per_page'])), 'selected' => array());
         // You can't split the last message off.
         if (empty($context['not_selected']['start']) && count($original_msgs['not_selected']) <= 1 && $_REQUEST['move'] == 'down') {
             $_REQUEST['move'] = '';
         }
         if (!empty($_SESSION['split_selection'][$topic])) {
             $original_msgs['selected'] = messageAt($context['selected']['start'], $topic, array('include' => empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic], 'only_approved' => !$modSettings['postmod_active'] || !allowedTo('approve_posts'), 'limit' => $context['messages_per_page']));
         }
     }
     // (De)select a message..
     if (!empty($_REQUEST['move'])) {
         $_REQUEST['msg'] = (int) $_REQUEST['msg'];
         if ($_REQUEST['move'] == 'reset') {
             $_SESSION['split_selection'][$topic] = array();
         } elseif ($_REQUEST['move'] == 'up') {
             $_SESSION['split_selection'][$topic] = array_diff($_SESSION['split_selection'][$topic], array($_REQUEST['msg']));
         } else {
             $_SESSION['split_selection'][$topic][] = $_REQUEST['msg'];
         }
     }
     // Make sure the selection is still accurate.
     if (!empty($_SESSION['split_selection'][$topic])) {
         $_SESSION['split_selection'][$topic] = messageAt(0, $topic, array('include' => empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic], 'only_approved' => !$modSettings['postmod_active'] || !allowedTo('approve_posts'), 'limit' => false));
         $selection = $_SESSION['split_selection'][$topic];
     } else {
         $selection = array();
     }
     // Get the number of messages (not) selected to be split.
     $split_counts = countSplitMessages($topic, !$modSettings['postmod_active'] || allowedTo('approve_posts'), $selection);
     foreach ($split_counts as $key => $num_messages) {
         $context[$key]['num_messages'] = $num_messages;
     }
     // Fix an oversized starting page (to make sure both pageindexes are properly set).
     if ($context['selected']['start'] >= $context['selected']['num_messages']) {
         $context['selected']['start'] = $context['selected']['num_messages'] <= $context['messages_per_page'] ? 0 : $context['selected']['num_messages'] - ($context['selected']['num_messages'] % $context['messages_per_page'] == 0 ? $context['messages_per_page'] : $context['selected']['num_messages'] % $context['messages_per_page']);
     }
     $page_index_url = $scripturl . '?action=splittopics;sa=selectTopics;subname=' . strtr(urlencode($_SESSION['new_topic_subject']), array('%' => '%%')) . ';topic=' . $topic;
     // Build a page list of the not-selected topics...
     $context['not_selected']['page_index'] = constructPageIndex($page_index_url . '.%1$d;start2=' . $context['selected']['start'], $context['not_selected']['start'], $context['not_selected']['num_messages'], $context['messages_per_page'], true);
     // ...and one of the selected topics.
     $context['selected']['page_index'] = constructPageIndex($page_index_url . '.' . $context['not_selected']['start'] . ';start2=%1$d', $context['selected']['start'], $context['selected']['num_messages'], $context['messages_per_page'], true);
     // Retrieve the unselected messages.
     $context['not_selected']['messages'] = selectMessages($topic, $context['not_selected']['start'], $context['messages_per_page'], empty($_SESSION['split_selection'][$topic]) ? array() : array('excluded' => $_SESSION['split_selection'][$topic]), $modSettings['postmod_active'] && !allowedTo('approve_posts'));
     // Now retrieve the selected messages.
     if (!empty($_SESSION['split_selection'][$topic])) {
         $context['selected']['messages'] = selectMessages($topic, $context['selected']['start'], $context['messages_per_page'], array('included' => $_SESSION['split_selection'][$topic]), $modSettings['postmod_active'] && !allowedTo('approve_posts'));
     }
     // The XMLhttp method only needs the stuff that changed, so let's compare.
     if (isset($_REQUEST['xml'])) {
         $changes = array('remove' => array('not_selected' => array_diff($original_msgs['not_selected'], array_keys($context['not_selected']['messages'])), 'selected' => array_diff($original_msgs['selected'], array_keys($context['selected']['messages']))), 'insert' => array('not_selected' => array_diff(array_keys($context['not_selected']['messages']), $original_msgs['not_selected']), 'selected' => array_diff(array_keys($context['selected']['messages']), $original_msgs['selected'])));
         $context['changes'] = array();
         foreach ($changes as $change_type => $change_array) {
             foreach ($change_array as $section => $msg_array) {
                 if (empty($msg_array)) {
                     continue;
                 }
                 foreach ($msg_array as $id_msg) {
                     $context['changes'][$change_type . $id_msg] = array('id' => $id_msg, 'type' => $change_type, 'section' => $section);
                     if ($change_type == 'insert') {
                         $context['changes']['insert' . $id_msg]['insert_value'] = $context[$section]['messages'][$id_msg];
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 23
0
    /**
     * 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('&amp;' => '&')), 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');
    }
Exemplo n.º 24
0
 /**
  * Edit or add a user subscription.
  *
  * - Accessed from ?action=admin;area=paidsubscribe;sa=modifyuser
  */
 public function action_modifyuser()
 {
     global $context, $txt, $modSettings;
     require_once SUBSDIR . '/PaidSubscriptions.subs.php';
     loadSubscriptions();
     $context['log_id'] = isset($_REQUEST['lid']) ? (int) $_REQUEST['lid'] : 0;
     $context['sub_id'] = isset($_REQUEST['sid']) ? (int) $_REQUEST['sid'] : 0;
     $context['action_type'] = $context['log_id'] ? 'edit' : 'add';
     // Setup the template.
     $context['sub_template'] = 'modify_user_subscription';
     $context['page_title'] = $txt[$context['action_type'] . '_subscriber'];
     loadJavascriptFile('suggest.js', array('defer' => true));
     // If we haven't been passed the subscription ID get it.
     if ($context['log_id'] && !$context['sub_id']) {
         $context['sub_id'] = validateSubscriptionID($context['log_id']);
     }
     if (!isset($context['subscriptions'][$context['sub_id']])) {
         fatal_lang_error('no_access', false);
     }
     $context['current_subscription'] = $context['subscriptions'][$context['sub_id']];
     // Searching?
     if (isset($_POST['ssearch'])) {
         return $this->action_viewsub();
     } elseif (isset($_REQUEST['save_sub'])) {
         checkSession();
         // Work out the dates...
         $starttime = mktime($_POST['hour'], $_POST['minute'], 0, $_POST['month'], $_POST['day'], $_POST['year']);
         $endtime = mktime($_POST['hourend'], $_POST['minuteend'], 0, $_POST['monthend'], $_POST['dayend'], $_POST['yearend']);
         // Status.
         $status = $_POST['status'];
         // New one?
         if (empty($context['log_id'])) {
             // Find the user...
             require_once SUBSDIR . '/Members.subs.php';
             $member = getMemberByName($_POST['name']);
             if (empty($member)) {
                 fatal_lang_error('error_member_not_found');
             }
             if (alreadySubscribed($context['sub_id'], $member['id_member'])) {
                 fatal_lang_error('member_already_subscribed');
             }
             // Actually put the subscription in place.
             if ($status == 1) {
                 addSubscription($context['sub_id'], $member['id_member'], 0, $starttime, $endtime);
             } else {
                 $details = array('id_subscribe' => $context['sub_id'], 'id_member' => $member['id_member'], 'id_group' => $member['id_group'], 'start_time' => $starttime, 'end_time' => $endtime, 'status' => $status);
                 logSubscription($details);
             }
         } else {
             $subscription_status = getSubscriptionStatus($context['log_id']);
             // Pick the right permission stuff depending on what the status is changing from/to.
             if ($subscription_status['old_status'] == 1 && $status != 1) {
                 removeSubscription($context['sub_id'], $subscription_status['id_member']);
             } elseif ($status == 1 && $subscription_status['old_status'] != 1) {
                 addSubscription($context['sub_id'], $subscription_status['id_member'], 0, $starttime, $endtime);
             } else {
                 $item = array('start_time' => $starttime, 'end_time' => $endtime, 'status' => $status, 'current_log_item' => $context['log_id']);
                 updateSubscriptionItem($item);
             }
         }
         // Done - redirect...
         redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']);
     } elseif (isset($_REQUEST['delete']) || isset($_REQUEST['finished'])) {
         checkSession();
         // Do the actual deletes!
         if (!empty($_REQUEST['delsub'])) {
             $toDelete = array();
             foreach ($_REQUEST['delsub'] as $id => $dummy) {
                 $toDelete[] = (int) $id;
             }
             $deletes = prepareDeleteSubscriptions($toDelete);
             foreach ($deletes as $id_subscribe => $id_member) {
                 removeSubscription($id_subscribe, $id_member, isset($_REQUEST['delete']));
             }
         }
         redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']);
     }
     // Default attributes.
     if ($context['action_type'] == 'add') {
         $context['sub'] = array('id' => 0, 'start' => array('year' => (int) strftime('%Y', time()), 'month' => (int) strftime('%m', time()), 'day' => (int) strftime('%d', time()), 'hour' => (int) strftime('%H', time()), 'min' => (int) strftime('%M', time()) < 10 ? '0' . (int) strftime('%M', time()) : (int) strftime('%M', time()), 'last_day' => 0), 'end' => array('year' => (int) strftime('%Y', time()), 'month' => (int) strftime('%m', time()), 'day' => (int) strftime('%d', time()), 'hour' => (int) strftime('%H', time()), 'min' => (int) strftime('%M', time()) < 10 ? '0' . (int) strftime('%M', time()) : (int) strftime('%M', time()), 'last_day' => 0), 'status' => 1);
         $context['sub']['start']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['start']['month'] == 12 ? 1 : $context['sub']['start']['month'] + 1, 0, $context['sub']['start']['month'] == 12 ? $context['sub']['start']['year'] + 1 : $context['sub']['start']['year']));
         $context['sub']['end']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['end']['month'] == 12 ? 1 : $context['sub']['end']['month'] + 1, 0, $context['sub']['end']['month'] == 12 ? $context['sub']['end']['year'] + 1 : $context['sub']['end']['year']));
         if (isset($_GET['uid'])) {
             require_once SUBSDIR . '/Members.subs.php';
             // Get the latest activated member's display name.
             $result = getBasicMemberData((int) $_GET['uid']);
             $context['sub']['username'] = $result['real_name'];
         } else {
             $context['sub']['username'] = '';
         }
     } else {
         $row = getPendingSubscriptions($context['log_id']);
         if (empty($row)) {
             fatal_lang_error('no_access', false);
         }
         // Any pending payments?
         $context['pending_payments'] = array();
         if (!empty($row['pending_details'])) {
             $pending_details = @unserialize($row['pending_details']);
             foreach ($pending_details as $id => $pending) {
                 // Only this type need be displayed.
                 if ($pending[3] == 'payback') {
                     // Work out what the options were.
                     $costs = @unserialize($context['current_subscription']['real_cost']);
                     if ($context['current_subscription']['real_length'] == 'F') {
                         foreach ($costs as $duration => $cost) {
                             if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) {
                                 $context['pending_payments'][$id] = array('desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration]));
                             }
                         }
                     } elseif ($costs['fixed'] == $pending[1]) {
                         $context['pending_payments'][$id] = array('desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed']));
                     }
                 }
             }
             // Check if we are adding/removing any.
             if (isset($_GET['pending'])) {
                 foreach ($pending_details as $id => $pending) {
                     // Found the one to action?
                     if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id])) {
                         // Flexible?
                         if (isset($_GET['accept'])) {
                             addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
                         }
                         unset($pending_details[$id]);
                         $new_details = serialize($pending_details);
                         // Update the entry.
                         updatePendingSubscription($context['log_id'], $new_details);
                         // Reload
                         redirectexit('action=admin;area=paidsubscribe;sa=modifyuser;lid=' . $context['log_id']);
                     }
                 }
             }
         }
         $context['sub_id'] = $row['id_subscribe'];
         $context['sub'] = array('id' => 0, 'start' => array('year' => (int) strftime('%Y', $row['start_time']), 'month' => (int) strftime('%m', $row['start_time']), 'day' => (int) strftime('%d', $row['start_time']), 'hour' => (int) strftime('%H', $row['start_time']), 'min' => (int) strftime('%M', $row['start_time']) < 10 ? '0' . (int) strftime('%M', $row['start_time']) : (int) strftime('%M', $row['start_time']), 'last_day' => 0), 'end' => array('year' => (int) strftime('%Y', $row['end_time']), 'month' => (int) strftime('%m', $row['end_time']), 'day' => (int) strftime('%d', $row['end_time']), 'hour' => (int) strftime('%H', $row['end_time']), 'min' => (int) strftime('%M', $row['end_time']) < 10 ? '0' . (int) strftime('%M', $row['end_time']) : (int) strftime('%M', $row['end_time']), 'last_day' => 0), 'status' => $row['status'], 'username' => $row['username']);
         $context['sub']['start']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['start']['month'] == 12 ? 1 : $context['sub']['start']['month'] + 1, 0, $context['sub']['start']['month'] == 12 ? $context['sub']['start']['year'] + 1 : $context['sub']['start']['year']));
         $context['sub']['end']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['end']['month'] == 12 ? 1 : $context['sub']['end']['month'] + 1, 0, $context['sub']['end']['month'] == 12 ? $context['sub']['end']['year'] + 1 : $context['sub']['end']['year']));
     }
 }
/**
* load the article editor by article type.
* field: name of a input element.
* content: the content in the editor or empty.
*/
function PortaMx_EditArticle($type, $field, $content)
{
    global $context, $sourcedir, $boardurl, $modSettings, $user_info, $options, $smcFunc, $txt;
    // for html blocks
    if ($type == 'html') {
        loadJavascriptFile($boardurl . '/ckeditor/ckeditor.js', array('external' => true));
        $context['pmx']['htmledit'] = array('id' => 'content', 'content' => $content);
    } else {
        if ($type == 'script') {
            addInlineCss('
	textarea{min-height:100px;resize:vertical;}');
            $context['pmx']['script'] = array('id' => 'content', 'value' => !empty($content) ? $content : '', 'width' => '100%', 'height' => '150px');
        } elseif ($type == 'php') {
            addInlineCss('
	textarea{min-height:100px;}');
            if (preg_match('~\\[\\?pmx_initphp(.*)pmx_initphp\\?\\]~is', $content, $match)) {
                $cont = trim($match[1]);
            } else {
                $cont = '';
            }
            $context['pmx']['phpInit'] = array('id' => 'content_init', 'value' => $smcFunc['htmlspecialchars']($cont, ENT_NOQUOTES), 'width' => '100%', 'height' => '150px', 'havecont' => !empty($cont));
            if (preg_match('~\\[\\?pmx_showphp(.*)pmx_showphp\\?\\]~is', $content, $match)) {
                $cont = trim($match[1]);
            } else {
                $cont = $content;
            }
            $context['pmx']['phpShow'] = array('id' => 'content', 'value' => $smcFunc['htmlspecialchars']($cont, ENT_NOQUOTES), 'width' => '100%', 'height' => '150px', 'havecont' => !empty($cont));
        } else {
            // Let's load the SMF editor.
            require_once $sourcedir . '/Subs-Editor.php';
            $user_info['smiley_set'] = 'PortaMx';
            $modSettings['smiley_enable'] = true;
            $options['wysiwyg_default'] = true;
            $editorOptions = array('id' => 'content', 'value' => !empty($content) ? $content : '&#8;', 'width' => '100%', 'height' => '200px', 'labels' => array(), 'preview_type' => 0, 'bbc_level' => 'full', 'disable_smiley_box' => 0, 'locale' => !empty($txt['lang_locale']) && substr($txt['lang_locale'], 0, 5) != 'en_US' ? $txt['lang_locale'] : '', 'form' => 'pxmedit');
            create_control_richedit($editorOptions);
            $context['pmx']['editorID'] = $editorOptions['id'];
        }
    }
}
Exemplo n.º 26
0
/**
 * Load a theme, by ID.
 *
 * What it does:
 * - identify the theme to be loaded.
 * - validate that the theme is valid and that the user has permission to use it
 * - load the users theme settings and site setttings into $options.
 * - prepares the list of folders to search for template loading.
 * - identify what smiley set to use.
 * - sets up $context['user']
 * - detects the users browser and sets a mobile friendly enviroment if needed
 * - loads default JS variables for use in every theme
 * - loads default JS scripts for use in every theme
 *
 * @param int $id_theme = 0
 * @param bool $initialize = true
 */
function loadTheme($id_theme = 0, $initialize = true)
{
    global $user_info, $user_settings, $board_info;
    global $txt, $boardurl, $scripturl, $mbname, $modSettings;
    global $context, $settings, $options, $ssi_theme;
    $db = database();
    // The theme was specified by parameter.
    if (!empty($id_theme)) {
        $id_theme = (int) $id_theme;
    } elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $id_theme = (int) $_REQUEST['theme'];
        $_SESSION['id_theme'] = $id_theme;
    } elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $id_theme = (int) $_SESSION['id_theme'];
    } elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $id_theme = $user_info['theme'];
    } elseif (!empty($board_info['theme'])) {
        $id_theme = $board_info['theme'];
    } else {
        $id_theme = $modSettings['theme_guests'];
    }
    // Verify the id_theme... no foul play.
    // Always allow the board specific theme, if they are overriding.
    if (!empty($board_info['theme']) && $board_info['override_theme']) {
        $id_theme = $board_info['theme'];
    } elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
        $id_theme = (int) $id_theme;
    } elseif (!empty($modSettings['knownThemes']) && !allowedTo('admin_forum')) {
        $themes = explode(',', $modSettings['knownThemes']);
        if (!in_array($id_theme, $themes)) {
            $id_theme = $modSettings['theme_guests'];
        } else {
            $id_theme = (int) $id_theme;
        }
    } else {
        $id_theme = (int) $id_theme;
    }
    $member = empty($user_info['id']) ? -1 : $user_info['id'];
    // Do we already have this members theme data and specific options loaded (for agressive cache settings)
    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) {
        $themeData = $temp;
        $flag = true;
    } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
        $themeData = $temp + array($member => array());
    } else {
        $themeData = array(-1 => array(), 0 => array(), $member => array());
    }
    if (empty($flag)) {
        // Load variables from the current or default theme, global or this user's.
        $result = $db->query('', '
			SELECT variable, value, id_member, id_theme
			FROM {db_prefix}themes
			WHERE id_member' . (empty($themeData[0]) ? ' IN (-1, 0, {int:id_member})' : ' = {int:id_member}') . '
				AND id_theme' . ($id_theme == 1 ? ' = {int:id_theme}' : ' IN ({int:id_theme}, 1)'), array('id_theme' => $id_theme, 'id_member' => $member));
        // Pick between $settings and $options depending on whose data it is.
        while ($row = $db->fetch_assoc($result)) {
            // There are just things we shouldn't be able to change as members.
            if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
                continue;
            }
            // If this is the theme_dir of the default theme, store it.
            if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
                $themeData[0]['default_' . $row['variable']] = $row['value'];
            }
            // If this isn't set yet, is a theme option, or is not the default theme..
            if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
                $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
            }
        }
        $db->free_result($result);
        // Set the defaults if the user has not chosen on their own
        if (!empty($themeData[-1])) {
            foreach ($themeData[-1] as $k => $v) {
                if (!isset($themeData[$member][$k])) {
                    $themeData[$member][$k] = $v;
                }
            }
        }
        // If being aggressive we save the site wide and member theme settings
        if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
            cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
        } elseif (!isset($temp)) {
            cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
        }
    }
    $settings = $themeData[0];
    $options = $themeData[$member];
    $settings['theme_id'] = $id_theme;
    $settings['actual_theme_url'] = $settings['theme_url'];
    $settings['actual_images_url'] = $settings['images_url'];
    $settings['actual_theme_dir'] = $settings['theme_dir'];
    $settings['template_dirs'] = array();
    // This theme first.
    $settings['template_dirs'][] = $settings['theme_dir'];
    // Based on theme (if there is one).
    if (!empty($settings['base_theme_dir'])) {
        $settings['template_dirs'][] = $settings['base_theme_dir'];
    }
    // Lastly the default theme.
    if ($settings['theme_dir'] != $settings['default_theme_dir']) {
        $settings['template_dirs'][] = $settings['default_theme_dir'];
    }
    if (!$initialize) {
        return;
    }
    // Check to see if they're accessing it from the wrong place.
    if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) {
        $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
        $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
        $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
        if ($temp != '/') {
            $detected_url .= $temp;
        }
    }
    if (isset($detected_url) && $detected_url != $boardurl) {
        // Try #1 - check if it's in a list of alias addresses.
        if (!empty($modSettings['forum_alias_urls'])) {
            $aliases = explode(',', $modSettings['forum_alias_urls']);
            foreach ($aliases as $alias) {
                // Rip off all the boring parts, spaces, etc.
                if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
                    $do_fix = true;
                }
            }
        }
        // Hmm... check #2 - is it just different by a www?  Send them to the correct place!!
        if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && ELK != 'SSI') {
            // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
            if (empty($_GET)) {
                redirectexit('wwwRedirect');
            } else {
                list($k, $v) = each($_GET);
                if ($k != 'wwwRedirect') {
                    redirectexit('wwwRedirect;' . $k . '=' . $v);
                }
            }
        }
        // #3 is just a check for SSL...
        if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
            $do_fix = true;
        }
        // Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
        if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\\d\\.:]+|\\[[\\d:]+\\](?::\\d+)?)(?:$|/)~', $detected_url) == 1) {
            // Caching is good ;).
            $oldurl = $boardurl;
            // Fix $boardurl and $scripturl.
            $boardurl = $detected_url;
            $scripturl = strtr($scripturl, array($oldurl => $boardurl));
            $_SERVER['REQUEST_URL'] = strtr($_SERVER['REQUEST_URL'], array($oldurl => $boardurl));
            // Fix the theme urls...
            $settings['theme_url'] = strtr($settings['theme_url'], array($oldurl => $boardurl));
            $settings['default_theme_url'] = strtr($settings['default_theme_url'], array($oldurl => $boardurl));
            $settings['actual_theme_url'] = strtr($settings['actual_theme_url'], array($oldurl => $boardurl));
            $settings['images_url'] = strtr($settings['images_url'], array($oldurl => $boardurl));
            $settings['default_images_url'] = strtr($settings['default_images_url'], array($oldurl => $boardurl));
            $settings['actual_images_url'] = strtr($settings['actual_images_url'], array($oldurl => $boardurl));
            // And just a few mod settings :).
            $modSettings['smileys_url'] = strtr($modSettings['smileys_url'], array($oldurl => $boardurl));
            $modSettings['avatar_url'] = strtr($modSettings['avatar_url'], array($oldurl => $boardurl));
            // Clean up after loadBoard().
            if (isset($board_info['moderators'])) {
                foreach ($board_info['moderators'] as $k => $dummy) {
                    $board_info['moderators'][$k]['href'] = strtr($dummy['href'], array($oldurl => $boardurl));
                    $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
                }
            }
            foreach ($context['linktree'] as $k => $dummy) {
                $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
            }
        }
    }
    // Set up the contextual user array.
    $context['user'] = array('id' => $user_info['id'], 'is_logged' => !$user_info['is_guest'], 'is_guest' => &$user_info['is_guest'], 'is_admin' => &$user_info['is_admin'], 'is_mod' => &$user_info['is_mod'], 'is_moderator' => &$user_info['is_moderator'], 'can_mod' => allowedTo('access_mod_center') || !$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'username' => $user_info['username'], 'language' => $user_info['language'], 'email' => $user_info['email'], 'ignoreusers' => $user_info['ignoreusers']);
    // Something for the guests
    if (!$context['user']['is_guest']) {
        $context['user']['name'] = $user_info['name'];
    } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
        $context['user']['name'] = $txt['guest_title'];
    }
    // Set up some additional interface preference context
    $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
    if (!$user_info['is_guest']) {
        $context['minmax_preferences'] = !empty($options['minmax_preferences']) ? unserialize($options['minmax_preferences']) : array();
    } elseif ($user_info['is_guest'] && isset($_COOKIE['upshrink'])) {
        $context['minmax_preferences'] = array('upshrink' => $_COOKIE['upshrink']);
    }
    // Determine the current smiley set.
    $user_info['smiley_set'] = !in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none' || empty($modSettings['smiley_sets_enable']) ? !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'] : $user_info['smiley_set'];
    $context['user']['smiley_set'] = $user_info['smiley_set'];
    // Some basic information...
    if (!isset($context['html_headers'])) {
        $context['html_headers'] = '';
    }
    if (!isset($context['links'])) {
        $context['links'] = array();
    }
    if (!isset($context['javascript_files'])) {
        $context['javascript_files'] = array();
    }
    if (!isset($context['css_files'])) {
        $context['css_files'] = array();
    }
    if (!isset($context['javascript_inline'])) {
        $context['javascript_inline'] = array('standard' => array(), 'defer' => array());
    }
    if (!isset($context['javascript_vars'])) {
        $context['javascript_vars'] = array();
    }
    $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
    $context['session_var'] = $_SESSION['session_var'];
    $context['session_id'] = $_SESSION['session_value'];
    $context['forum_name'] = $mbname;
    $context['forum_name_html_safe'] = $context['forum_name'];
    $context['current_action'] = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
    $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
    foreach (array('theme_header', 'upper_content') as $call) {
        if (!isset($context[$call . '_callbacks'])) {
            $context[$call . '_callbacks'] = array();
        }
    }
    // Set some permission related settings.
    if ($user_info['is_guest'] && !empty($modSettings['enableVBStyleLogin'])) {
        $context['show_login_bar'] = true;
        $context['theme_header_callbacks'][] = 'login_bar';
        loadJavascriptFile('sha256.js', array('defer' => true));
    }
    // This determines the server... not used in many places, except for login fixing.
    detectServer();
    // Detect the browser. This is separated out because it's also used in attachment downloads
    detectBrowser();
    // Set the top level linktree up.
    array_unshift($context['linktree'], array('url' => $scripturl, 'name' => $context['forum_name']));
    // This allows sticking some HTML on the page output - useful for controls.
    $context['insert_after_template'] = '';
    // Just some mobile-friendly settings
    if ($context['browser_body_id'] == 'mobile') {
        // Disable the preview text.
        $modSettings['message_index_preview'] = 0;
        // Force the usage of click menu instead of a hover menu.
        $options['use_click_menu'] = 1;
        // No space left for a sidebar
        $options['use_sidebar_menu'] = false;
        // Disable the search dropdown.
        $modSettings['search_dropdown'] = false;
    }
    if (!isset($txt)) {
        $txt = array();
    }
    $simpleActions = array('findmember', 'quickhelp', 'printpage', 'quotefast', 'spellcheck');
    call_integration_hook('integrate_simple_actions', array(&$simpleActions));
    // Output is fully XML, so no need for the index template.
    if (isset($_REQUEST['xml'])) {
        loadLanguage('index+Addons');
        // @todo added because some $settings in template_init are necessary even in xml mode. Maybe move template_init to a settings file?
        loadTemplate('index');
        loadTemplate('Xml');
        Template_Layers::getInstance()->removeAll();
    } elseif (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $simpleActions)) {
        loadLanguage('index+Addons');
        Template_Layers::getInstance()->removeAll();
    } else {
        // Custom templates to load, or just default?
        if (isset($settings['theme_templates'])) {
            $templates = explode(',', $settings['theme_templates']);
        } else {
            $templates = array('index');
        }
        // Load each template...
        foreach ($templates as $template) {
            loadTemplate($template);
        }
        // ...and attempt to load their associated language files.
        $required_files = implode('+', array_merge($templates, array('Addons')));
        loadLanguage($required_files, '', false);
        // Custom template layers?
        if (isset($settings['theme_layers'])) {
            $layers = explode(',', $settings['theme_layers']);
        } else {
            $layers = array('html', 'body');
        }
        $template_layers = Template_Layers::getInstance(true);
        foreach ($layers as $layer) {
            $template_layers->addBegin($layer);
        }
    }
    // Initialize the theme.
    if (function_exists('template_init')) {
        $settings = array_merge($settings, template_init());
    }
    // Call initialization theme integration functions.
    call_integration_hook('integrate_init_theme', array($id_theme, &$settings));
    // Guests may still need a name.
    if ($context['user']['is_guest'] && empty($context['user']['name'])) {
        $context['user']['name'] = $txt['guest_title'];
    }
    // Any theme-related strings that need to be loaded?
    if (!empty($settings['require_theme_strings'])) {
        loadLanguage('ThemeStrings', '', false);
    }
    // Load font Awesome fonts
    loadCSSFile('font-awesome.min.css');
    // We allow theme variants, because we're cool.
    $context['theme_variant'] = '';
    $context['theme_variant_url'] = '';
    if (!empty($settings['theme_variants'])) {
        // Overriding - for previews and that ilk.
        if (!empty($_REQUEST['variant'])) {
            $_SESSION['id_variant'] = $_REQUEST['variant'];
        }
        // User selection?
        if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
            $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
        }
        // If not a user variant, select the default.
        if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
            $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
        }
        // Do this to keep things easier in the templates.
        $context['theme_variant'] = '_' . $context['theme_variant'];
        $context['theme_variant_url'] = $context['theme_variant'] . '/';
        // The most efficient way of writing multi themes is to use a master index.css plus variant.css files.
        if (!empty($context['theme_variant'])) {
            loadCSSFile($context['theme_variant'] . '/index' . $context['theme_variant'] . '.css');
        }
    }
    // A bit lonely maybe, though I think it should be set up *after* teh theme variants detection
    $context['header_logo_url_html_safe'] = empty($settings['header_logo_url']) ? $settings['images_url'] . '/' . $context['theme_variant_url'] . 'logo_elk.png' : Util::htmlspecialchars($settings['header_logo_url']);
    // Allow overriding the board wide time/number formats.
    if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
        $user_info['time_format'] = $txt['time_format'];
    }
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'always') {
        $settings['theme_url'] = $settings['default_theme_url'];
        $settings['images_url'] = $settings['default_images_url'];
        $settings['theme_dir'] = $settings['default_theme_dir'];
    }
    // Make a special URL for the language.
    $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
    // Set a couple of bits for the template.
    $context['right_to_left'] = !empty($txt['lang_rtl']);
    $context['tabindex'] = 1;
    // RTL languages require an additional stylesheet.
    if ($context['right_to_left']) {
        loadCSSFile('rtl.css');
    }
    if (!empty($context['theme_variant']) && $context['right_to_left']) {
        loadCSSFile($context['theme_variant'] . '/rtl' . $context['theme_variant'] . '.css');
    }
    // Compatibility.
    if (!isset($settings['theme_version'])) {
        $modSettings['memberCount'] = $modSettings['totalMembers'];
    }
    // This allows us to change the way things look for the admin.
    $context['admin_features'] = isset($modSettings['admin_features']) ? explode(',', $modSettings['admin_features']) : array('cd,cp,k,w,rg,ml,pm');
    if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged'])) {
        $context['newsfeed_urls'] = array('rss' => $scripturl . '?action=.xml;type=rss2;limit=' . (!empty($modSettings['xmlnews_limit']) ? $modSettings['xmlnews_limit'] : 5), 'atom' => $scripturl . '?action=.xml;type=atom;limit=' . (!empty($modSettings['xmlnews_limit']) ? $modSettings['xmlnews_limit'] : 5));
    }
    // Default JS variables for use in every theme
    addJavascriptVar(array('elk_theme_url' => JavaScriptEscape($settings['theme_url']), 'elk_default_theme_url' => JavaScriptEscape($settings['default_theme_url']), 'elk_images_url' => JavaScriptEscape($settings['images_url']), 'elk_smiley_url' => JavaScriptEscape($modSettings['smileys_url']), 'elk_scripturl' => '\'' . $scripturl . '\'', 'elk_iso_case_folding' => $context['server']['iso_case_folding'] ? 'true' : 'false', 'elk_charset' => '"UTF-8"', 'elk_session_id' => JavaScriptEscape($context['session_id']), 'elk_session_var' => JavaScriptEscape($context['session_var']), 'elk_member_id' => $context['user']['id'], 'ajax_notification_text' => JavaScriptEscape($txt['ajax_in_progress']), 'ajax_notification_cancel_text' => JavaScriptEscape($txt['modify_cancel']), 'help_popup_heading_text' => JavaScriptEscape($txt['help_popup']), 'use_click_menu' => !empty($options['use_click_menu']) ? 'true' : 'false', 'todayMod' => !empty($modSettings['todayMod']) ? (int) $modSettings['todayMod'] : 0));
    // Auto video embeding enabled, then load the needed JS
    if (!empty($modSettings['enableVideoEmbeding'])) {
        addInlineJavascript('
		var oEmbedtext = ({
			preview_image : ' . JavaScriptEscape($txt['preview_image']) . ',
			ctp_video : ' . JavaScriptEscape($txt['ctp_video']) . ',
			hide_video : ' . JavaScriptEscape($txt['hide_video']) . ',
			youtube : ' . JavaScriptEscape($txt['youtube']) . ',
			vimeo : ' . JavaScriptEscape($txt['vimeo']) . ',
			dailymotion : ' . JavaScriptEscape($txt['dailymotion']) . '
		});', true);
        loadJavascriptFile('elk_jquery_embed.js', array('defer' => true));
    }
    // Prettify code tags? Load the needed JS and CSS.
    if (!empty($modSettings['enableCodePrettify'])) {
        loadCSSFile('prettify.css');
        loadJavascriptFile('prettify.min.js', array('defer' => true));
        addInlineJavascript('
		$(document).ready(function(){
			prettyPrint();
		});', true);
    }
    // Relative times?
    if (!empty($modSettings['todayMod']) && $modSettings['todayMod'] > 2) {
        addInlineJavascript('
		var oRttime = ({
			referenceTime : ' . forum_time() * 1000 . ',
			now : ' . JavaScriptEscape($txt['rt_now']) . ',
			minute : ' . JavaScriptEscape($txt['rt_minute']) . ',
			minutes : ' . JavaScriptEscape($txt['rt_minutes']) . ',
			hour : ' . JavaScriptEscape($txt['rt_hour']) . ',
			hours : ' . JavaScriptEscape($txt['rt_hours']) . ',
			day : ' . JavaScriptEscape($txt['rt_day']) . ',
			days : ' . JavaScriptEscape($txt['rt_days']) . ',
			week : ' . JavaScriptEscape($txt['rt_week']) . ',
			weeks : ' . JavaScriptEscape($txt['rt_weeks']) . ',
			month : ' . JavaScriptEscape($txt['rt_month']) . ',
			months : ' . JavaScriptEscape($txt['rt_months']) . ',
			year : ' . JavaScriptEscape($txt['rt_year']) . ',
			years : ' . JavaScriptEscape($txt['rt_years']) . ',
		});
		updateRelativeTime();', true);
        $context['using_relative_time'] = true;
    }
    // Queue our Javascript
    loadJavascriptFile(array('elk_jquery_plugins.js', 'script.js', 'script_elk.js', 'theme.js'));
    // If we think we have mail to send, let's offer up some possibilities... robots get pain (Now with scheduled task support!)
    if (!empty($modSettings['mail_next_send']) && $modSettings['mail_next_send'] < time() && empty($modSettings['mail_queue_use_cron']) || empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
        if (isBrowser('possibly_robot')) {
            // @todo Maybe move this somewhere better?!
            require_once CONTROLLERDIR . '/ScheduledTasks.controller.php';
            $controller = new ScheduledTasks_Controller();
            // What to do, what to do?!
            if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
                $controller->action_autotask();
            } else {
                $controller->action_reducemailqueue();
            }
        } else {
            $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
            $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
            addInlineJavascript('
		function elkAutoTask()
		{
			var tempImage = new Image();
			tempImage.src = elk_scripturl + "?scheduled=' . $type . ';ts=' . $ts . '";
		}
		window.setTimeout("elkAutoTask();", 1);', true);
        }
    }
    // Any files to include at this point?
    call_integration_include_hook('integrate_theme_include');
    // Call load theme integration functions.
    call_integration_hook('integrate_load_theme');
    // We are ready to go.
    $context['theme_loaded'] = true;
}
Exemplo n.º 27
0
 /**
  * This function allows a user to select the membergroups to send their mailing to.
  *
  * What it does:
  * - Called by ?action=admin;area=news;sa=mailingmembers.
  * - Requires the send_mail permission.
  * - Form is submitted to ?action=admin;area=news;mailingcompose.
  *
  * @uses the ManageNews template and email_members sub template.
  */
 public function action_mailingmembers()
 {
     global $txt, $context;
     require_once SUBSDIR . '/Membergroups.subs.php';
     require_once SUBSDIR . '/News.subs.php';
     // Setup the template
     $context['page_title'] = $txt['admin_newsletters'];
     $context['sub_template'] = 'email_members';
     loadJavascriptFile('suggest.js', array('defer' => true));
     // We need group data, including which groups we have and who is in them
     $allgroups = getBasicMembergroupData(array('all'), array(), null, true);
     $groups = $allgroups['groups'];
     // All of the members in post based and member based groups
     $pg = array();
     foreach ($allgroups['postgroups'] as $postgroup) {
         $pg[] = $postgroup['id'];
     }
     $mg = array();
     foreach ($allgroups['membergroups'] as $membergroup) {
         $mg[] = $membergroup['id'];
     }
     // How many are in each group
     $mem_groups = membersInGroups($pg, $mg, true, true);
     foreach ($mem_groups as $id_group => $member_count) {
         if (isset($groups[$id_group]['member_count'])) {
             $groups[$id_group]['member_count'] += $member_count;
         } else {
             $groups[$id_group]['member_count'] = $member_count;
         }
     }
     // Generate the include and exclude group select lists for the template
     foreach ($groups as $group) {
         $groups[$group['id']]['status'] = 'on';
         $groups[$group['id']]['is_postgroup'] = in_array($group['id'], $pg);
     }
     $context['groups'] = array('select_group' => $txt['admin_newsletters_select_groups'], 'member_groups' => $groups);
     foreach ($groups as $group) {
         $groups[$group['id']]['status'] = 'off';
     }
     $context['exclude_groups'] = array('select_group' => $txt['admin_newsletters_exclude_groups'], 'member_groups' => $groups);
     // Needed if for the PM option in the mail to all
     $context['can_send_pm'] = allowedTo('pm_send');
 }
Exemplo n.º 28
0
/**
 * Deals with the initialization of SimplePortal headers.
 */
function sportal_init_headers()
{
    global $modSettings, $txt, $user_info, $scripturl;
    static $initialized;
    // If already loaded just return
    if (!empty($initialized)) {
        return $initialized;
    }
    // Generate a safe scripturl
    $safe_scripturl = $scripturl;
    $current_request = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'];
    if (strpos($scripturl, 'www.') !== false && strpos($current_request, 'www.') === false) {
        $safe_scripturl = str_replace('://www.', '://', $scripturl);
    } elseif (strpos($scripturl, 'www.') === false && strpos($current_request, 'www.') !== false) {
        $safe_scripturl = str_replace('://', '://www.', $scripturl);
    }
    // The shoutbox may fail to function in certain cases without using a safe scripturl
    addJavascriptVar(array('sp_script_url' => '\'' . $safe_scripturl . '\''));
    // Load up some javascript!
    loadJavascriptFile('portal.js?sp100');
    $javascript = '';
    // We use drag and sort blocks for the front page
    if ($modSettings['sp_portal_mode'] == 1) {
        $modSettings['jquery_include_ui'] = true;
        // Javascipt to allow D&D ordering of the front page blocks, not for guests
        if (empty($_REQUEST['action']) && !($user_info['is_guest'] || $user_info['id'] == 0)) {
            $javascript .= '
				// Set up our sortable call
				$().elkSortable({
					sa: "userblockorder",
					error: "' . $txt['portal_order_error'] . '",
					title: "' . $txt['portal_order_title'] . '",
					handle: ".sp_drag_header",
					tag: ".sp_column",
					opacity: 0.9,
					connect: ".sp_column",
					containment: "#main_content_section",
					tolerance: "pointer",
					href: "/",
					placeholder: "ui-state-highlight",
					axis: "",
				});';
        }
    }
    if ($modSettings['sp_resize_images']) {
        $javascript .= '
		createEventListener(window);
		window.addEventListener("load", sp_image_resize, false);';
    }
    // Let the template know we have some inline JS to display
    addInlineJavascript($javascript, true);
    $initialized = true;
    return $initialized;
}
    /**
     * 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'])));
        }
    }
/**
* 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();
}