Exemplo n.º 1
0
function sportal_credits()
{
    global $sourcedir, $context, $txt;
    require_once $sourcedir . '/PortalAdminMain.php';
    loadLanguage('SPortalAdmin', sp_languageSelect('SPortalAdmin'));
    sportal_information(false);
    $context['page_title'] = $txt['sp-info_title'];
    $context['sub_template'] = 'information';
}
 /**
  * Main dispatcher.
  * This function checks permissions and passes control through.
  * If the passed section is not found it shows the information page.
  */
 public function action_index()
 {
     global $context, $txt;
     // You need to be an admin or have manage setting permissions to change anything
     if (!allowedTo('sp_admin')) {
         isAllowedTo('sp_manage_settings');
     }
     // Some helpful friends
     require_once SUBSDIR . '/PortalAdmin.subs.php';
     require_once SUBSDIR . '/Portal.subs.php';
     require_once ADMINDIR . '/ManageServer.controller.php';
     loadCSSFile('portal.css');
     // Load the Simple Portal Help file.
     loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp'));
     $subActions = array('information' => array($this, 'action_sportal_information'), 'generalsettings' => array($this, 'action_sportal_admin_general_settings'), 'blocksettings' => array($this, 'action_sportal_admin_block_settings'), 'articlesettings' => array($this, 'action_sportal_admin_article_settings'));
     // Start up the controller, provide a hook since we can
     $action = new Action('portal_main');
     $context[$context['admin_menu_name']]['tab_data'] = array('title' => $txt['sp-adminConfiguration'], 'help' => 'sp_ConfigurationArea', 'description' => $txt['sp-adminConfigurationDesc']);
     // Set the default to the information tab
     $subAction = $action->initialize($subActions, 'information');
     // Right then, off you go
     $action->dispatch($subAction);
 }
Exemplo n.º 3
0
function ShowAdminHelp()
{
    global $txt, $helptxt, $context, $scripturl;
    if (!isset($_GET['help']) || !is_string($_GET['help'])) {
        fatal_lang_error('no_access', false);
    }
    if (!isset($helptxt)) {
        $helptxt = array();
    }
    // Load the admin help language file and template.
    loadLanguage('Help');
    // Load the Simple Portal Help file.
    loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp'));
    // Permission specific help?
    if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp') {
        loadLanguage('ManagePermissions');
    }
    loadTemplate('Help');
    // Set the page title to something relevant.
    $context['page_title'] = $context['forum_name'] . ' - ' . $txt['help'];
    // Don't show any template layers, just the popup sub template.
    $context['template_layers'] = array();
    $context['sub_template'] = 'popup';
    // What help string should be used?
    if (isset($helptxt[$_GET['help']])) {
        $context['help_text'] = $helptxt[$_GET['help']];
    } elseif (isset($txt[$_GET['help']])) {
        $context['help_text'] = $txt[$_GET['help']];
    } else {
        $context['help_text'] = $_GET['help'];
    }
    // Does this text contain a link that we should fill in?
    if (preg_match('~%([0-9]+\\$)?s\\?~', $context['help_text'], $match)) {
        $context['help_text'] = sprintf($context['help_text'], $scripturl, $context['session_id'], $context['session_var']);
    }
}
/**
 * Builds an sprite class tag for use in templates
 *
 * @param string $name
 * @param string $title
 * @param string $extraclass
 * @param string $spriteclass
 */
function sp_embed_class($name, $title = '', $extraclass = '', $spriteclass = 'dot')
{
    global $modSettings, $txt;
    static $default_title, $randomizer;
    loadLanguage('SPortal', sp_languageSelect('SPortal'));
    // Some default title text settings for our standard sprites
    if (!isset($default_title)) {
        $default_title = array('dot' => '', 'stars' => $txt['sp-star'], 'arrow' => $txt['sp-arrow'], 'modify' => $txt['modify'], 'delete' => $txt['delete'], 'delete_small' => $txt['delete'], 'history' => $txt['sp_shoutbox_history'], 'refresh' => $txt['sp_shoutbox_refresh'], 'smiley' => $txt['sp_shoutbox_smiley'], 'style' => $txt['sp_shoutbox_style'], 'bin' => $txt['sp_shoutbox_prune'], 'move' => $txt['sp_move'], 'given' => $txt['sp_likes_given'], 'received' => $txt['sp_likes_received']);
    }
    // Use a default title text if available and none was supplied
    if (empty($title) && isset($default_title[$name])) {
        $title = $default_title[$name];
    } else {
        $title = $name;
    }
    // dots / start using colors
    if (in_array($name, array('dot', 'star')) && empty($modSettings['sp_disable_random_bullets'])) {
        // Loop through the dot colors
        if (!isset($randomizer) || $randomizer > 7) {
            $randomizer = 0;
        }
        $randomizer++;
        $name = $name . $randomizer;
    }
    // Build the attributes
    return 'class="' . $spriteclass . ' ' . $name . (!empty($extraclass) ? ' ' . $extraclass : '') . '" title="' . $title . '"';
}
function sportal_init($standalone = false)
{
    global $context, $sourcedir, $scripturl, $modSettings, $txt;
    global $settings, $options, $boarddir, $maintenance, $sportal_version;
    $sportal_version = '2.3.5';
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
        return;
    }
    if (!$standalone) {
        loadTemplate(false, 'portal');
        if (!empty($context['right_to_left'])) {
            loadTemplate(false, 'portal_rtl');
        }
        if (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], array('admin', 'helpadmin'))) {
            loadLanguage('SPortalAdmin', sp_languageSelect('SPortalAdmin'));
        }
        if (!isset($settings['sp_images_url'])) {
            if (file_exists($settings['theme_dir'] . '/images/sp')) {
                $settings['sp_images_url'] = $settings['theme_url'] . '/images/sp';
            } else {
                $settings['sp_images_url'] = $settings['default_theme_url'] . '/images/sp';
            }
        }
        if (!empty($context['current_topic'])) {
            $context['can_add_article'] = allowedTo(array('sp_admin', 'sp_manage_articles', 'sp_add_article'));
            $context['can_remove_article'] = allowedTo(array('sp_admin', 'sp_manage_articles', 'sp_remove_article'));
        }
        $context['SPortal']['core_compat'] = $settings['name'] == 'Core Theme';
        $context['SPortal']['on_portal'] = getShowInfo(0, 'portal', '');
    }
    if (WIRELESS || $standalone && (isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode'])) || !empty($settings['disable_sp']) || empty($modSettings['sp_portal_mode']) || (!empty($modSettings['sp_maintenance']) || !empty($maintenance)) && !allowedTo('admin_forum') || isset($_GET['debug']) || empty($modSettings['allow_guestAccess']) && $context['user']['is_guest']) {
        $context['disable_sp'] = true;
        if ($standalone) {
            $get_string = '';
            foreach ($_GET as $get_var => $get_value) {
                $get_string .= $get_var . (!empty($get_value) ? '=' . $get_value : '') . ';';
            }
            redirectexit(substr($get_string, 0, -1));
        }
        return;
    }
    if (!$standalone) {
        require_once $sourcedir . '/PortalBlocks.php';
        if (SMF != 'SSI') {
            require_once $boarddir . '/SSI.php';
        }
        loadTemplate('Portal');
        loadLanguage('SPortal', sp_languageSelect('SPortal'));
        if (!empty($modSettings['sp_maintenance']) && !allowedTo('sp_admin')) {
            $modSettings['sp_portal_mode'] = 0;
        }
        if (empty($modSettings['sp_standalone_url'])) {
            $modSettings['sp_standalone_url'] = '';
        }
        if ($modSettings['sp_portal_mode'] == 3) {
            $context += array('portal_url' => $modSettings['sp_standalone_url'], 'page_title' => $context['forum_name']);
        } else {
            $context += array('portal_url' => $scripturl);
        }
        if ($modSettings['sp_portal_mode'] == 1) {
            $context['linktree'][0] = array('url' => $scripturl . '?action=forum', 'name' => $context['forum_name']);
        }
        // If you want to remove Forum link when it is
        // alone, take out the following two comment lines.
        //if (empty($context['linktree'][1]))
        //	$context['linktree'] = array();
        if (!empty($context['linktree']) && $modSettings['sp_portal_mode'] == 1) {
            foreach ($context['linktree'] as $key => $tree) {
                if (strpos($tree['url'], '#c') !== false && strpos($tree['url'], 'action=forum#c') === false) {
                    $context['linktree'][$key]['url'] = str_replace('#c', '?action=forum#c', $tree['url']);
                }
            }
        }
    }
    $context['standalone'] = $standalone;
    // Load the headers if necessary.
    sportal_init_headers();
    $context['SPortal']['sides'] = array(5 => array('id' => '5', 'name' => 'header', 'active' => true), 1 => array('id' => '1', 'name' => 'left', 'active' => !empty($modSettings['showleft'])), 2 => array('id' => '2', 'name' => 'top', 'active' => true), 3 => array('id' => '3', 'name' => 'bottom', 'active' => true), 4 => array('id' => '4', 'name' => 'right', 'active' => !empty($modSettings['showright'])), 6 => array('id' => '6', 'name' => 'footer', 'active' => true));
    $blocks = getBlockInfo(null, null, true, true, true);
    $context['SPortal']['blocks'] = array();
    foreach ($blocks as $block) {
        if (!$context['SPortal']['sides'][$block['column']]['active']) {
            continue;
        }
        $block['style'] = sportal_parse_style('explode', $block['style'], true);
        $context['SPortal']['sides'][$block['column']]['last'] = $block['id'];
        $context['SPortal']['blocks'][$block['column']][] = $block;
    }
    foreach ($context['SPortal']['sides'] as $side) {
        if (empty($context['SPortal']['blocks'][$side['id']])) {
            $context['SPortal']['sides'][$side['id']]['active'] = false;
        }
        $context['SPortal']['sides'][$side['id']]['collapsed'] = $context['user']['is_guest'] ? !empty($_COOKIE['sp_' . $side['name']]) : !empty($options['sp_' . $side['name']]);
    }
    if (!empty($context['template_layers']) && !in_array('portal', $context['template_layers'])) {
        $context['template_layers'][] = 'portal';
    }
}
function sp_gallery($parameters, $id, $return_parameters = false)
{
    global $smcFunc, $context, $modSettings, $scripturl;
    global $sourcedir, $txt, $settings, $boardurl, $galurl;
    static $mod, $GD_Installed;
    $block_parameters = array('limit' => 'int', 'type' => 'select', 'direction' => 'select');
    if ($return_parameters) {
        return $block_parameters;
    }
    $limit = empty($parameters['limit']) ? 1 : (int) $parameters['limit'];
    $type = empty($parameters['type']) ? 0 : 1;
    $direction = empty($parameters['direction']) ? 0 : 1;
    if (!isset($mod)) {
        if (file_exists($sourcedir . '/Aeva-Media.php')) {
            $mod = 'aeva_media';
        } elseif (file_exists($sourcedir . '/MGallery.php')) {
            $mod = 'smf_media_gallery';
        } elseif (file_exists($sourcedir . '/Gallery.php') || file_exists($sourcedir . '/Gallery2.php')) {
            $mod = 'smf_gallery';
        } else {
            $mod = '';
        }
    }
    if (empty($mod)) {
        echo '
								', $txt['error_sp_no_gallery_found'];
        return;
    } elseif ($mod == 'aeva_media') {
        require_once $sourcedir . '/Aeva-Subs.php';
        $items = aeva_getMediaItems(0, $limit, $type ? 'RAND()' : 'm.id_media DESC');
    } elseif ($mod == 'smf_media_gallery') {
        require_once $sourcedir . '/Subs-MGallery.php';
        loadMGal_Settings();
        loadLanguage('MGallery', sp_languageSelect('MGallery'));
        $items = getMediaItems(0, $limit, $type ? 'RAND()' : 'm.id_media DESC');
    } elseif ($mod == 'smf_gallery') {
        loadLanguage('Gallery', sp_languageSelect('Gallery'));
        if (!isset($GD_Installed)) {
            $GD_Installed = function_exists('imagecreate');
        }
        if (empty($modSettings['gallery_url'])) {
            $modSettings['gallery_url'] = $boardurl . '/gallery/';
        }
        $request = $smcFunc['db_query']('', '
			SELECT
				p.id_picture, p.commenttotal, p.filesize, p.views, p.thumbfilename,
				p.filename, p.height, p.width, p.title, p.id_member, m.member_name,
				m.real_name, p.date, p.description
			FROM {db_prefix}gallery_pic AS p
				LEFT JOIN {db_prefix}members AS m ON (m.id_member = p.id_member)
			WHERE p.approved = {int:is_approved}
			ORDER BY {raw:type}
			LIMIT {int:limit}', array('is_approved' => 1, 'type' => $type ? 'RAND()' : 'p.id_picture DESC', 'limit' => $limit));
        $items = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $items[] = array('id' => $row['id_picture'], 'title' => $row['title'], 'views' => $row['views'], 'poster_id' => $row['id_member'], 'poster_name' => $row['real_name'], 'poster_link' => empty($row['id_member']) ? $txt['gallery_guest'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', 'thumbfilename' => $row['thumbfilename'], 'filename' => $row['filename'], 'src' => $modSettings['gallery_url'] . ($GD_Installed ? $row['thumbfilename'] : $row['filename'] . '" width="120'));
        }
        $smcFunc['db_free_result']($request);
    }
    if (empty($items)) {
        echo '
								', $txt['error_sp_no_pictures_found'];
        return;
    }
    echo '
								<table class="sp_auto_align">', $direction ? '
									<tr>' : '';
    foreach ($items as $item) {
        echo !$direction ? '
									<tr>' : '', '
										<td>
											<div class="sp_image smalltext">';
        if ($mod == 'aeva_media') {
            echo '
												<a href="', $galurl, 'sa=item;id=', $item['id'], '">', $item['title'], '</a><br />
												<a href="', $galurl, 'sa=item;id=', $item['id'], '"><img src="', $galurl, 'sa=media;id=', $item['id'], ';thumb" alt="" /></a><br />
												', $txt['aeva_views'], ': ', $item['views'], '<br />
												', $txt['aeva_posted_by'], ': <a href="', $scripturl, '?action=profile;u=', $item['poster_id'], '">', $item['poster_name'], '</a><br />
												', $txt['aeva_in_album'], ': <a href="', $galurl, 'sa=album;id=', $item['id_album'], '">', $item['album_name'], '</a>', $item['is_new'] ? '<br /><img alt="" src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" border="0" />' : '';
        } elseif ($mod == 'smf_media_gallery') {
            echo '
												<a href="', $galurl, 'sa=item;id=', $item['id'], '">', $item['title'], '</a><br />
												<a href="', $galurl, 'sa=item;id=', $item['id'], '"><img src="', $galurl, 'sa=media;id=', $item['id'], ';thumb" alt="" /></a><br />
												', $txt['mgallery_views'], ': ', $item['views'], '<br />
												', $txt['mgallery_posted_by'], ': <a href="', $scripturl, '?action=profile;u=', $item['poster_id'], '">', $item['poster_name'], '</a><br />
												', $txt['mgallery_in_album'], ': <a href="', $galurl, 'sa=album;id=', $item['id_album'], '">', $item['album_name'], '</a>', $item['is_new'] ? '<br /><img alt="" src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" border="0" />' : '';
        } elseif ($mod == 'smf_gallery') {
            echo '
												<a href="', $scripturl, '?action=gallery;sa=view;id=', $item['id'], '">', $item['title'], '</a><br />
												<a href="', $scripturl, '?action=gallery;sa=view;id=', $item['id'], '"><img src="', $item['src'], '" alt="" /></a><br />
												', $txt['gallery_text_views'], $item['views'], '<br />
												', $txt['gallery_text_by'], ' ', $item['poster_link'], '<br />';
        }
        echo '
											</div>
										</td>', !$direction ? '
									</tr>' : '';
    }
    echo $direction ? '
									</tr>' : '', '
								</table>';
}
function prepareDBSettingContext(&$config_vars)
{
    global $txt, $helptxt, $context, $modSettings, $sourcedir;
    loadLanguage('Help');
    loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp'));
    $context['config_vars'] = array();
    $inlinePermissions = array();
    $bbcChoice = array();
    foreach ($config_vars as $config_var) {
        // HR?
        if (!is_array($config_var)) {
            $context['config_vars'][] = $config_var;
        } else {
            // If it has no name it doesn't have any purpose!
            if (empty($config_var[1])) {
                continue;
            }
            // Special case for inline permissions
            if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
                $inlinePermissions[] = $config_var[1];
            } elseif ($config_var[0] == 'permissions') {
                continue;
            }
            // Are we showing the BBC selection box?
            if ($config_var[0] == 'bbc') {
                $bbcChoice[] = $config_var[1];
            }
            $context['config_vars'][$config_var[1]] = array('label' => isset($config_var['text_label']) ? $config_var['text_label'] : (isset($txt[$config_var[1]]) ? $txt[$config_var[1]] : (isset($config_var[3]) && !is_array($config_var[3]) ? $config_var[3] : '')), 'help' => isset($helptxt[$config_var[1]]) ? $config_var[1] : '', 'type' => $config_var[0], 'size' => !empty($config_var[2]) && !is_array($config_var[2]) ? $config_var[2] : (in_array($config_var[0], array('int', 'float')) ? 6 : 0), 'data' => array(), 'name' => $config_var[1], 'value' => isset($modSettings[$config_var[1]]) ? $config_var[0] == 'select' ? $modSettings[$config_var[1]] : htmlspecialchars($modSettings[$config_var[1]]) : (in_array($config_var[0], array('int', 'float')) ? 0 : ''), 'disabled' => false, 'invalid' => !empty($config_var['invalid']), 'javascript' => '', 'var_message' => !empty($config_var['message']) && isset($txt[$config_var['message']]) ? $txt[$config_var['message']] : '', 'preinput' => isset($config_var['preinput']) ? $config_var['preinput'] : '', 'postinput' => isset($config_var['postinput']) ? $config_var['postinput'] : '');
            // If this is a select box handle any data.
            if (!empty($config_var[2]) && is_array($config_var[2])) {
                // If we allow multiple selections, we need to adjust a few things.
                if ($config_var[0] == 'select' && !empty($config_var['multiple'])) {
                    $context['config_vars'][$config_var[1]]['name'] .= '[]';
                    $context['config_vars'][$config_var[1]]['value'] = unserialize($context['config_vars'][$config_var[1]]['value']);
                }
                // If it's associative
                if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
                    $context['config_vars'][$config_var[1]]['data'] = $config_var[2];
                } else {
                    foreach ($config_var[2] as $key => $item) {
                        $context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
                    }
                }
            }
            // Finally allow overrides - and some final cleanups.
            foreach ($config_var as $k => $v) {
                if (!is_numeric($k)) {
                    if (substr($k, 0, 2) == 'on') {
                        $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
                    } else {
                        $context['config_vars'][$config_var[1]][$k] = $v;
                    }
                }
                // See if there are any other labels that might fit?
                if (isset($txt['setting_' . $config_var[1]])) {
                    $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
                } elseif (isset($txt['groups_' . $config_var[1]])) {
                    $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
                }
            }
            // Set the subtext in case it's part of the label.
            // !!! Temporary. Preventing divs inside label tags.
            $divPos = strpos($context['config_vars'][$config_var[1]]['label'], '<div');
            if ($divPos !== false) {
                $context['config_vars'][$config_var[1]]['subtext'] = preg_replace('~</?div[^>]*>~', '', substr($context['config_vars'][$config_var[1]]['label'], $divPos));
                $context['config_vars'][$config_var[1]]['label'] = substr($context['config_vars'][$config_var[1]]['label'], 0, $divPos);
            }
        }
    }
    // If we have inline permissions we need to prep them.
    if (!empty($inlinePermissions) && allowedTo('manage_permissions')) {
        require_once $sourcedir . '/ManagePermissions.php';
        init_inline_permissions($inlinePermissions, isset($context['permissions_excluded']) ? $context['permissions_excluded'] : array());
    }
    // What about any BBC selection boxes?
    if (!empty($bbcChoice)) {
        // What are the options, eh?
        $temp = parse_bbc(false);
        $bbcTags = array();
        foreach ($temp as $tag) {
            $bbcTags[] = $tag['tag'];
        }
        $bbcTags = array_unique($bbcTags);
        $totalTags = count($bbcTags);
        // The number of columns we want to show the BBC tags in.
        $numColumns = isset($context['num_bbc_columns']) ? $context['num_bbc_columns'] : 3;
        // Start working out the context stuff.
        $context['bbc_columns'] = array();
        $tagsPerColumn = ceil($totalTags / $numColumns);
        $col = 0;
        $i = 0;
        foreach ($bbcTags as $tag) {
            if ($i % $tagsPerColumn == 0 && $i != 0) {
                $col++;
            }
            $context['bbc_columns'][$col][] = array('tag' => $tag, 'show_help' => isset($helptxt[$tag]));
            $i++;
        }
        // Now put whatever BBC options we may have into context too!
        $context['bbc_sections'] = array();
        foreach ($bbcChoice as $bbc) {
            $context['bbc_sections'][$bbc] = array('title' => isset($txt['bbc_title_' . $bbc]) ? $txt['bbc_title_' . $bbc] : $txt['bbcTagsToUse_select'], 'disabled' => empty($modSettings['bbc_disabled_' . $bbc]) ? array() : $modSettings['bbc_disabled_' . $bbc], 'all_selected' => empty($modSettings['bbc_disabled_' . $bbc]));
        }
    }
}
function sportal_admin_block_edit()
{
    global $txt, $context, $modSettings, $smcFunc, $sourcedir, $boarddir, $boards;
    // Just in case, the admin could be doing something silly like editing a SP block while SP it disabled. ;)
    require_once $sourcedir . '/PortalBlocks.php';
    $context['SPortal']['is_new'] = empty($_REQUEST['block_id']);
    // BBC Fix move the parameter to the correct position.
    if (!empty($_POST['bbc_name'])) {
        $_POST['parameters'][$_POST['bbc_name']] = !empty($_POST[$_POST['bbc_parameter']]) ? $_POST[$_POST['bbc_parameter']] : '';
        // If we came from WYSIWYG then turn it back into BBC regardless.
        if (!empty($_REQUEST['bbc_' . $_POST['bbc_name'] . '_mode']) && isset($_POST['parameters'][$_POST['bbc_name']])) {
            require_once $sourcedir . '/Subs-Editor.php';
            $_POST['parameters'][$_POST['bbc_name']] = html_to_bbc($_POST['parameters'][$_POST['bbc_name']]);
            // We need to unhtml it now as it gets done shortly.
            $_POST['parameters'][$_POST['bbc_name']] = un_htmlspecialchars($_POST['parameters'][$_POST['bbc_name']]);
            // We need this for everything else.
            $_POST['parameters'][$_POST['bbc_name']] = $_POST['parameters'][$_POST['bbc_name']];
        }
    }
    // Passing the selected type via $_GET instead of $_POST?
    $start_parameters = array();
    if (!empty($_GET['selected_type']) && empty($_POST['selected_type'])) {
        $_POST['selected_type'] = array($_GET['selected_type']);
        if (!empty($_GET['parameters'])) {
            foreach ($_GET['parameters'] as $param) {
                if (isset($_GET[$param])) {
                    $start_parameters[$param] = $_GET[$param];
                }
            }
        }
    }
    if ($context['SPortal']['is_new'] && empty($_POST['selected_type']) && empty($_POST['add_block'])) {
        $context['SPortal']['block_types'] = getFunctionInfo();
        if (!empty($_REQUEST['col'])) {
            $context['SPortal']['block']['column'] = $_REQUEST['col'];
        }
        $context['sub_template'] = 'block_select_type';
        $context['page_title'] = $txt['sp-blocksAdd'];
    } elseif ($context['SPortal']['is_new'] && !empty($_POST['selected_type'])) {
        $context['SPortal']['block'] = array('id' => 0, 'label' => $txt['sp-blocksDefaultLabel'], 'type' => $_POST['selected_type'][0], 'type_text' => !empty($txt['sp_function_' . $_POST['selected_type'][0] . '_label']) ? $txt['sp_function_' . $_POST['selected_type'][0] . '_label'] : $txt['sp_function_unknown_label'], 'column' => !empty($_POST['block_column']) ? $_POST['block_column'] : 0, 'row' => 0, 'permission_set' => 3, 'groups_allowed' => array(), 'groups_denied' => array(), 'state' => 1, 'force_view' => 0, 'display' => '', 'display_custom' => '', 'style' => '', 'parameters' => !empty($start_parameters) ? $start_parameters : array(), 'options' => $_POST['selected_type'][0](array(), false, true), 'list_blocks' => !empty($_POST['block_column']) ? getBlockInfo($_POST['block_column']) : array());
    } elseif (!$context['SPortal']['is_new'] && empty($_POST['add_block'])) {
        $_REQUEST['block_id'] = (int) $_REQUEST['block_id'];
        $context['SPortal']['block'] = current(getBlockInfo(null, $_REQUEST['block_id']));
        $context['SPortal']['block'] += array('options' => $context['SPortal']['block']['type'](array(), false, true), 'list_blocks' => getBlockInfo($context['SPortal']['block']['column']));
    }
    if (!empty($_POST['preview_block'])) {
        // Just in case, the admin could be doing something silly like editing a SP block while SP it disabled. ;)
        require_once $boarddir . '/SSI.php';
        sportal_init_headers();
        loadTemplate('Portal');
        $type_parameters = $_POST['block_type'](array(), 0, true);
        if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) {
            foreach ($type_parameters as $name => $type) {
                if (isset($_POST['parameters'][$name])) {
                    if ($type == 'bbc') {
                        $parameter['value'] = $_POST['parameters'][$name];
                        require_once $sourcedir . '/Subs-Post.php';
                        $parameter['value'] = $smcFunc['htmlspecialchars']($parameter['value'], ENT_QUOTES);
                        preparsecode($parameter['value']);
                        $_POST['parameters'][$name] = $parameter['value'];
                    } elseif ($type == 'boards' || $type == 'board_select') {
                        $_POST['parameters'][$name] = is_array($_POST['parameters'][$name]) ? implode('|', $_POST['parameters'][$name]) : $_POST['parameters'][$name];
                    } elseif ($type == 'int' || $type == 'select') {
                        $_POST['parameters'][$name] = (int) $_POST['parameters'][$name];
                    } elseif ($type == 'text' || $type == 'textarea' || is_array($type)) {
                        $_POST['parameters'][$name] = $smcFunc['htmlspecialchars']($_POST['parameters'][$name], ENT_QUOTES);
                    } elseif ($type == 'check') {
                        $_POST['parameters'][$name] = !empty($_POST['parameters'][$name]) ? 1 : 0;
                    }
                }
            }
        } else {
            $_POST['parameters'] = array();
        }
        if (empty($_POST['display_advanced'])) {
            if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) {
                $display = $_POST['display_simple'];
            } else {
                $display = '';
            }
            $custom = '';
        } else {
            $display = array();
            $custom = array();
            if (!empty($_POST['display_actions'])) {
                foreach ($_POST['display_actions'] as $action) {
                    $display[] = $smcFunc['htmlspecialchars']($action, ENT_QUOTES);
                }
            }
            if (!empty($_POST['display_boards'])) {
                foreach ($_POST['display_boards'] as $board) {
                    $display[] = 'b' . (int) substr($board, 1);
                }
            }
            if (!empty($_POST['display_pages'])) {
                foreach ($_POST['display_pages'] as $page) {
                    $display[] = 'p' . (int) substr($page, 1);
                }
            }
            if (!empty($_POST['display_custom'])) {
                $temp = explode(',', $_POST['display_custom']);
                foreach ($temp as $action) {
                    $custom[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($action), ENT_QUOTES);
                }
            }
            $display = empty($display) ? '' : implode(',', $display);
            $custom = empty($custom) ? '' : implode(',', $custom);
        }
        $permission_set = 0;
        $groups_allowed = $groups_denied = array();
        if (!empty($_POST['permission_set'])) {
            $permission_set = (int) $_POST['permission_set'];
        } elseif (!empty($_POST['membergroups']) && is_array($_POST['membergroups'])) {
            foreach ($_POST['membergroups'] as $id => $value) {
                if ($value == 1) {
                    $groups_allowed[] = (int) $id;
                } elseif ($value == -1) {
                    $groups_denied[] = (int) $id;
                }
            }
        }
        $context['SPortal']['block'] = array('id' => $_POST['block_id'], 'label' => $smcFunc['htmlspecialchars']($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'type_text' => !empty($txt['sp_function_' . $_POST['block_type'] . '_label']) ? $txt['sp_function_' . $_POST['block_type'] . '_label'] : $txt['sp_function_unknown_label'], 'column' => $_POST['block_column'], 'row' => !empty($_POST['block_row']) ? $_POST['block_row'] : 0, 'permission_set' => $permission_set, 'groups_allowed' => $groups_allowed, 'groups_denied' => $groups_denied, 'state' => !empty($_POST['block_active']), 'force_view' => !empty($_POST['block_force']), 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode'), 'parameters' => !empty($_POST['parameters']) ? $_POST['parameters'] : array(), 'options' => $_POST['block_type'](array(), false, true), 'list_blocks' => getBlockInfo($_POST['block_column']), 'collapsed' => false);
        if (strpos($modSettings['leftwidth'], '%') !== false || strpos($modSettings['leftwidth'], 'px') !== false) {
            $context['widths'][1] = $modSettings['leftwidth'];
        } else {
            $context['widths'][1] = $modSettings['leftwidth'] . 'px';
        }
        if (strpos($modSettings['rightwidth'], '%') !== false || strpos($modSettings['rightwidth'], 'px') !== false) {
            $context['widths'][4] = $modSettings['rightwidth'];
        } else {
            $context['widths'][4] = $modSettings['rightwidth'] . 'px';
        }
        if (strpos($context['widths'][1], '%') !== false) {
            $context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%';
        } elseif (strpos($context['widths'][1], 'px') !== false) {
            $context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px';
        }
        if (strpos($context['widths'][1], '%') !== false) {
            $context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%';
            $context['widths'][5] = $context['widths'][6] = '100%';
        } elseif (strpos($context['widths'][1], 'px') !== false) {
            $context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px';
            $context['widths'][5] = $context['widths'][6] = '960px';
        }
        $context['SPortal']['preview'] = true;
    }
    if (!empty($_POST['selected_type']) || !empty($_POST['preview_block']) || !$context['SPortal']['is_new'] && empty($_POST['add_block'])) {
        if ($context['SPortal']['block']['type'] == 'sp_php' && !allowedTo('admin_forum')) {
            fatal_lang_error('cannot_admin_forum', false);
        }
        $context['html_headers'] .= '
	<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
		function sp_collapseObject(id)
		{
			mode = document.getElementById("sp_object_" + id).style.display == "" ? 0 : 1;
			document.getElementById("sp_collapse_" + id).src = smf_images_url + (mode ? "/collapse.gif" : "/expand.gif");
			document.getElementById("sp_object_" + id).style.display = mode ? "" : "none";
		}
	// ]]></script>';
        loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp'));
        $context['SPortal']['block']['groups'] = sp_load_membergroups();
        $context['simple_actions'] = array('sportal' => $txt['sp-portal'], 'sforum' => $txt['sp-forum'], 'allaction' => $txt['sp-blocksOptionAllActions'], 'allboard' => $txt['sp-blocksOptionAllBoards'], 'allpages' => $txt['sp-blocksOptionAllPages'], 'all' => $txt['sp-blocksOptionEverywhere']);
        $context['display_actions'] = array('portal' => $txt['sp-portal'], 'forum' => $txt['sp-forum'], 'recent' => $txt['recent_posts'], 'unread' => $txt['unread_topics_visit'], 'unreadreplies' => $txt['unread_replies'], 'profile' => $txt['profile'], 'pm' => $txt['pm_short'], 'calendar' => $txt['calendar'], 'admin' => $txt['admin'], 'login' => $txt['login'], 'register' => $txt['register'], 'post' => $txt['post'], 'stats' => $txt['forum_stats'], 'search' => $txt['search'], 'mlist' => $txt['members_list'], 'moderate' => $txt['moderate'], 'help' => $txt['help'], 'who' => $txt['who_title']);
        $request = $smcFunc['db_query']('', '
			SELECT id_board, name
			FROM {db_prefix}boards
			ORDER BY name DESC');
        $context['display_boards'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $context['display_boards']['b' . $row['id_board']] = $row['name'];
        }
        $smcFunc['db_free_result']($request);
        $request = $smcFunc['db_query']('', '
			SELECT id_page, title
			FROM {db_prefix}sp_pages
			ORDER BY title DESC');
        $context['display_pages'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $context['display_pages']['p' . $row['id_page']] = $row['title'];
        }
        $smcFunc['db_free_result']($request);
        if (empty($context['SPortal']['block']['display'])) {
            $context['SPortal']['block']['display'] = array('0');
        } else {
            $context['SPortal']['block']['display'] = explode(',', $context['SPortal']['block']['display']);
        }
        if (in_array($context['SPortal']['block']['display'][0], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages')) || $context['SPortal']['is_new'] || empty($context['SPortal']['block']['display'][0]) && empty($context['SPortal']['block']['display_custom'])) {
            $context['SPortal']['block']['display_type'] = 0;
        } else {
            $context['SPortal']['block']['display_type'] = 1;
        }
        $context['SPortal']['block']['style'] = sportal_parse_style('explode', $context['SPortal']['block']['style'], !empty($context['SPortal']['preview']));
        // Prepare the Textcontent for BBC, only the first bbc will be correct detected! (SMF Support only 1 per page with the standard function)
        $firstBBCFound = false;
        foreach ($context['SPortal']['block']['options'] as $name => $type) {
            // Selectable Boards :D
            if ($type == 'board_select' || $type == 'boards') {
                if (empty($boards)) {
                    require_once $sourcedir . '/Subs-Boards.php';
                    getBoardTree();
                }
                // Merge the array ;). (Only in 2.0 needed)
                if (!isset($context['SPortal']['block']['parameters'][$name])) {
                    $context['SPortal']['block']['parameters'][$name] = array();
                } elseif (!empty($context['SPortal']['block']['parameters'][$name]) && is_array($context['SPortal']['block']['parameters'][$name])) {
                    $context['SPortal']['block']['parameters'][$name] = implode('|', $context['SPortal']['block']['parameters'][$name]);
                }
                $context['SPortal']['block']['board_options'][$name] = array();
                $config_variable = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : array();
                $config_variable = !is_array($config_variable) ? explode('|', $config_variable) : $config_variable;
                $context['SPortal']['block']['board_options'][$name] = array();
                // Create the list for this Item
                foreach ($boards as $board) {
                    if (!empty($board['redirect'])) {
                        // Ignore the redirected boards :)
                        continue;
                    }
                    $context['SPortal']['block']['board_options'][$name][$board['id']] = array('value' => $board['id'], 'text' => $board['name'], 'selected' => in_array($board['id'], $config_variable));
                }
            } elseif ($type == 'bbc') {
                // SMF support only one bbc correct, multiple bbc do not work at the moment
                if (!$firstBBCFound) {
                    $firstBBCFound = true;
                    // Start SMF BBC Sytem :)
                    require_once $sourcedir . '/Subs-Editor.php';
                    // Prepare the output :D
                    $form_message = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : '';
                    // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited!
                    if (strpos($form_message, '[html]') !== false) {
                        $parts = preg_split('~(\\[/code\\]|\\[code(?:=[^\\]]+)?\\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE);
                        for ($i = 0, $n = count($parts); $i < $n; $i++) {
                            // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
                            if ($i % 4 == 0) {
                                $parts[$i] = preg_replace('~\\[html\\](.+?)\\[/html\\]~ise', '\'[html]\' . preg_replace(\'~<br\\s?/?>~i\', \'&lt;br /&gt;<br />\', \'$1\') . \'[/html]\'', $parts[$i]);
                            }
                        }
                        $form_message = implode('', $parts);
                    }
                    $form_message = preg_replace('~<br(?: /)?' . '>~i', "\n", $form_message);
                    // Prepare the data before i want them inside the textarea
                    $form_message = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
                    $context['SPortal']['bbc'] = 'bbc_' . $name;
                    $message_data = array('id' => $context['SPortal']['bbc'], 'width' => '95%', 'height' => '200px', 'value' => $form_message, 'form' => 'sp_block');
                    // Run the SMF bbc editor rutine
                    create_control_richedit($message_data);
                    // Store the updated data on the parameters
                    $context['SPortal']['block']['parameters'][$name] = $form_message;
                } else {
                    $context['SPortal']['block']['options'][$name] = 'textarea';
                }
            }
        }
        $context['sub_template'] = 'block_edit';
        $context['page_title'] = $context['SPortal']['is_new'] ? $txt['sp-blocksAdd'] : $txt['sp-blocksEdit'];
    }
    if (!empty($_POST['add_block'])) {
        if ($_POST['block_type'] == 'sp_php' && !allowedTo('admin_forum')) {
            fatal_lang_error('cannot_admin_forum', false);
        }
        if (!isset($_POST['block_name']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['block_name']), ENT_QUOTES) === '') {
            fatal_lang_error('error_sp_name_empty', false);
        }
        if ($_POST['block_type'] == 'sp_php' && !empty($_POST['parameters']['content']) && empty($modSettings['sp_disable_php_validation'])) {
            $error = sp_validate_php($_POST['parameters']['content']);
            if ($error) {
                fatal_lang_error('error_sp_php_' . $error, false);
            }
        }
        if (!empty($_REQUEST['block_id'])) {
            $current_data = current(getBlockInfo(null, $_REQUEST['block_id']));
        }
        if (!empty($_POST['placement']) && ($_POST['placement'] == 'before' || $_POST['placement'] == 'after')) {
            if (!empty($current_data)) {
                $current_row = $current_data['row'];
            } else {
                $current_row = null;
            }
            if ($_POST['placement'] == 'before') {
                $row = (int) $_POST['block_row'];
            } else {
                $row = (int) $_POST['block_row'] + 1;
            }
            if (!empty($current_row) && $row > $current_row) {
                $row = $row - 1;
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}sp_blocks
					SET row = row - 1
					WHERE col = {int:col}
						AND row > {int:start}
						AND row <= {int:end}', array('col' => (int) $_POST['block_column'], 'start' => $current_row, 'end' => $row));
            } else {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}sp_blocks
					SET row = row + 1
					WHERE col = {int:col}
						AND row >= {int:start}' . (!empty($current_row) ? '
						AND row < {int:end}' : ''), array('col' => (int) $_POST['block_column'], 'start' => $row, 'end' => !empty($current_row) ? $current_row : 0));
            }
        } elseif (!empty($_POST['placement']) && $_POST['placement'] == 'nochange') {
            $row = 0;
        } else {
            $request = $smcFunc['db_query']('', '
				SELECT row
				FROM {db_prefix}sp_blocks
				WHERE col = {int:col}' . (!empty($_REQUEST['block_id']) ? '
					AND id_block != {int:current_id}' : '') . '
				ORDER BY row DESC
				LIMIT 1', array('col' => $_POST['block_column'], 'current_id' => $_REQUEST['block_id']));
            list($row) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
            $row = $row + 1;
        }
        $type_parameters = $_POST['block_type'](array(), 0, true);
        if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) {
            foreach ($type_parameters as $name => $type) {
                if (isset($_POST['parameters'][$name])) {
                    // Prepare BBC Content for SMF 2 special case =D
                    if ($type == 'bbc') {
                        $parameter['value'] = $_POST['parameters'][$name];
                        require_once $sourcedir . '/Subs-Post.php';
                        // Prepare the message a bit for some additional testing.
                        $parameter['value'] = $smcFunc['htmlspecialchars']($parameter['value'], ENT_QUOTES);
                        preparsecode($parameter['value']);
                        //Store now the correct and fixed value ;)
                        $_POST['parameters'][$name] = $parameter['value'];
                    } elseif ($type == 'boards' || $type == 'board_select') {
                        $_POST['parameters'][$name] = is_array($_POST['parameters'][$name]) ? implode('|', $_POST['parameters'][$name]) : $_POST['parameters'][$name];
                    } elseif ($type == 'int' || $type == 'select') {
                        $_POST['parameters'][$name] = (int) $_POST['parameters'][$name];
                    } elseif ($type == 'text' || $type == 'textarea' || is_array($type)) {
                        $_POST['parameters'][$name] = $smcFunc['htmlspecialchars']($_POST['parameters'][$name], ENT_QUOTES);
                    } elseif ($type == 'check') {
                        $_POST['parameters'][$name] = !empty($_POST['parameters'][$name]) ? 1 : 0;
                    }
                }
            }
        } else {
            $_POST['parameters'] = array();
        }
        $permission_set = 0;
        $groups_allowed = $groups_denied = '';
        if (!empty($_POST['permission_set'])) {
            $permission_set = (int) $_POST['permission_set'];
        } elseif (!empty($_POST['membergroups']) && is_array($_POST['membergroups'])) {
            $groups_allowed = $groups_denied = array();
            foreach ($_POST['membergroups'] as $id => $value) {
                if ($value == 1) {
                    $groups_allowed[] = (int) $id;
                } elseif ($value == -1) {
                    $groups_denied[] = (int) $id;
                }
            }
            $groups_allowed = implode(',', $groups_allowed);
            $groups_denied = implode(',', $groups_denied);
        }
        if (empty($_POST['display_advanced'])) {
            if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) {
                $display = $_POST['display_simple'];
            } else {
                $display = '';
            }
            $custom = '';
        } else {
            $display = array();
            if (!empty($_POST['display_actions'])) {
                foreach ($_POST['display_actions'] as $action) {
                    $display[] = $smcFunc['htmlspecialchars']($action, ENT_QUOTES);
                }
            }
            if (!empty($_POST['display_boards'])) {
                foreach ($_POST['display_boards'] as $board) {
                    $display[] = 'b' . (int) substr($board, 1);
                }
            }
            if (!empty($_POST['display_pages'])) {
                foreach ($_POST['display_pages'] as $page) {
                    $display[] = 'p' . (int) substr($page, 1);
                }
            }
            if (!empty($_POST['display_custom'])) {
                $temp = explode(',', $_POST['display_custom']);
                foreach ($temp as $action) {
                    $custom[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($action), ENT_QUOTES);
                }
            }
            $display = empty($display) ? '' : implode(',', $display);
            if (!allowedTo('admin_forum') && isset($current_data['display_custom']) && substr($current_data['display_custom'], 0, 4) === '$php') {
                $custom = $current_data['display_custom'];
            } elseif (!empty($_POST['display_custom'])) {
                if (allowedTo('admin_forum') && substr($_POST['display_custom'], 0, 4) === '$php') {
                    $custom = $smcFunc['htmlspecialchars']($_POST['display_custom'], ENT_QUOTES);
                } else {
                    $custom = array();
                    $temp = explode(',', $_POST['display_custom']);
                    foreach ($temp as $action) {
                        $custom[] = $smcFunc['htmlspecialchars']($action, ENT_QUOTES);
                    }
                    $custom = empty($custom) ? '' : implode(',', $custom);
                }
            } else {
                $custom = '';
            }
        }
        $blockInfo = array('id' => (int) $_POST['block_id'], 'label' => $smcFunc['htmlspecialchars']($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'col' => $_POST['block_column'], 'row' => $row, 'permission_set' => $permission_set, 'groups_allowed' => $groups_allowed, 'groups_denied' => $groups_denied, 'state' => !empty($_POST['block_active']) ? 1 : 0, 'force_view' => !empty($_POST['block_force']) ? 1 : 0, 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode'));
        if ($context['SPortal']['is_new']) {
            unset($blockInfo['id']);
            $smcFunc['db_insert']('', '{db_prefix}sp_blocks', array('label' => 'string', 'type' => 'string', 'col' => 'int', 'row' => 'int', 'permission_set' => 'int', 'groups_allowed' => 'string', 'groups_denied' => 'string', 'state' => 'int', 'force_view' => 'int', 'display' => 'string', 'display_custom' => 'string', 'style' => 'string'), $blockInfo, array('id_block'));
            $blockInfo['id'] = $smcFunc['db_insert_id']('{db_prefix}sp_blocks', 'id_block');
        } else {
            $block_fields = array("label = {string:label}", "permission_set = {int:permission_set}", "groups_allowed = {string:groups_allowed}", "groups_denied = {string:groups_denied}", "state = {int:state}", "force_view = {int:force_view}", "display = {string:display}", "display_custom = {string:display_custom}", "style = {string:style}");
            if (!empty($blockInfo['row'])) {
                $block_fields[] = "row = {int:row}";
            } else {
                unset($blockInfo['row']);
            }
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}sp_blocks
				SET ' . implode(', ', $block_fields) . '
				WHERE id_block = {int:id}', $blockInfo);
            $smcFunc['db_query']('', '
				DELETE FROM {db_prefix}sp_parameters
				WHERE id_block = {int:id}', array('id' => $blockInfo['id']));
        }
        if (!empty($_POST['parameters'])) {
            $parameters = array();
            foreach ($_POST['parameters'] as $variable => $value) {
                $parameters[] = array('id_block' => $blockInfo['id'], 'variable' => $variable, 'value' => $value);
            }
            $smcFunc['db_insert']('', '{db_prefix}sp_parameters', array('id_block' => 'int', 'variable' => 'string', 'value' => 'string'), $parameters, array());
        }
        redirectexit('action=admin;area=portalblocks');
    }
}
/**
 * Menu Button hook, integrate_menu_buttons, called from subs.php
 * used to add top menu buttons
 *
 * @param mixed[] $buttons
 */
function sp_integrate_menu_buttons(&$buttons)
{
    global $txt, $scripturl, $modSettings, $context;
    require_once SUBSDIR . '/Portal.subs.php';
    loadLanguage('SPortal', sp_languageSelect('SPortal'));
    // Set the right portalurl based on what integration mode the portal is using
    if ($modSettings['sp_portal_mode'] == 1 && empty($context['disable_sp'])) {
        $sportalurl = $scripturl . '?action=forum';
    } elseif ($modSettings['sp_portal_mode'] == 3 && empty($context['disable_sp'])) {
        $sportalurl = $modSettings['sp_standalone_url'];
    } else {
        $sportalurl = '';
    }
    // Define the new menu item(s), show it for modes 1 and 3 only
    $buttons = elk_array_insert($buttons, 'home', array('forum' => array('title' => empty($txt['sp-forum']) ? 'Forum' : $txt['sp-forum'], 'data-icon' => '&#xf0c0;', 'href' => $sportalurl, 'show' => in_array($modSettings['sp_portal_mode'], array(1, 3)) && empty($context['disable_sp']), 'sub_buttons' => array())), 'after');
}
 /**
  * Displays the credit page outside of the admin area,
  *
  * - Forwards to admin controller to display credits outside the admin area
  */
 public function action_sportal_credits()
 {
     loadLanguage('SPortalAdmin', sp_languageSelect('SPortalAdmin'));
     require_once ADMINDIR . '/PortalAdminMain.controller.php';
     $adminmain = new ManagePortalConfig_Controller();
     $adminmain->action_sportal_information(false);
 }
 /**
  * Adding or editing a block.
  */
 public function action_sportal_admin_block_edit()
 {
     global $txt, $context, $modSettings, $boards;
     // Just in case, the admin could be doing something silly like editing a SP block while SP is disabled. ;)
     require_once SUBSDIR . '/PortalBlocks.subs.php';
     $context['SPortal']['is_new'] = empty($_REQUEST['block_id']);
     // BBC Fix move the parameter to the correct position.
     if (!empty($_POST['bbc_name'])) {
         $_POST['parameters'][$_POST['bbc_name']] = !empty($_POST[$_POST['bbc_parameter']]) ? $_POST[$_POST['bbc_parameter']] : '';
         // If we came from WYSIWYG then turn it back into BBC regardless.
         if (!empty($_REQUEST['bbc_' . $_POST['bbc_name'] . '_mode']) && isset($_POST['parameters'][$_POST['bbc_name']])) {
             require_once SUBSDIR . 'Html2BBC.class.php';
             $bbc_converter = new Convert_BBC($_POST['parameters'][$_POST['bbc_name']]);
             $_POST['parameters'][$_POST['bbc_name']] = $bbc_converter->get_bbc();
             // We need to unhtml it now as it gets done shortly.
             $_POST['parameters'][$_POST['bbc_name']] = un_htmlspecialchars($_POST['parameters'][$_POST['bbc_name']]);
         }
     }
     // Passing the selected type via $_GET instead of $_POST?
     $start_parameters = array();
     if (!empty($_GET['selected_type']) && empty($_POST['selected_type'])) {
         $_POST['selected_type'] = array($_GET['selected_type']);
         if (!empty($_GET['parameters'])) {
             foreach ($_GET['parameters'] as $param) {
                 if (isset($_GET[$param])) {
                     $start_parameters[$param] = $_GET[$param];
                 }
             }
         }
     }
     // Want use a block on the portal?
     if ($context['SPortal']['is_new'] && empty($_POST['selected_type']) && empty($_POST['add_block'])) {
         // Gather the blocks we have available
         $context['SPortal']['block_types'] = getFunctionInfo();
         // Create a list of the blocks in use
         $in_use = getBlockInfo();
         foreach ($in_use as $block) {
             $context['SPortal']['block_inuse'][$block['type']] = array('state' => $block['state'], 'column' => $block['column']);
         }
         $context['location'] = array(1 => $txt['sp-positionLeft'], $txt['sp-positionTop'], $txt['sp-positionBottom'], $txt['sp-positionRight'], $txt['sp-positionHeader'], $txt['sp-positionFooter']);
         if (!empty($_REQUEST['col'])) {
             $context['SPortal']['block']['column'] = $_REQUEST['col'];
         }
         $context['sub_template'] = 'block_select_type';
         $context['page_title'] = $txt['sp-blocksAdd'];
     } elseif ($context['SPortal']['is_new'] && !empty($_POST['selected_type'])) {
         $context['SPortal']['block'] = array('id' => 0, 'label' => $txt['sp-blocksDefaultLabel'], 'type' => $_POST['selected_type'][0], 'type_text' => !empty($txt['sp_function_' . $_POST['selected_type'][0] . '_label']) ? $txt['sp_function_' . $_POST['selected_type'][0] . '_label'] : $txt['sp_function_unknown_label'], 'column' => !empty($_POST['block_column']) ? $_POST['block_column'] : 0, 'row' => 0, 'permissions' => 3, 'state' => 1, 'force_view' => 0, 'mobile_view' => 0, 'display' => '', 'display_custom' => '', 'style' => '', 'parameters' => !empty($start_parameters) ? $start_parameters : array(), 'options' => $_POST['selected_type'][0](array(), false, true), 'list_blocks' => !empty($_POST['block_column']) ? getBlockInfo($_POST['block_column']) : array());
     } elseif (!$context['SPortal']['is_new'] && empty($_POST['add_block'])) {
         $_REQUEST['block_id'] = (int) $_REQUEST['block_id'];
         $context['SPortal']['block'] = current(getBlockInfo(null, $_REQUEST['block_id']));
         $context['SPortal']['block'] += array('options' => $context['SPortal']['block']['type'](array(), false, true), 'list_blocks' => getBlockInfo($context['SPortal']['block']['column']));
     }
     // Want to take a look at how this block will appear, well we try our best
     if (!empty($_POST['preview_block']) || isset($_SESSION['sp_error'])) {
         // An error was generated on save, lets set things up like a preview and return to the preview
         if (isset($_SESSION['sp_error'])) {
             $context['SPortal']['error'] = $_SESSION['sp_error'];
             $_POST = $_SESSION['sp_error_post'];
             $_POST['preview_block'] = true;
             // Clean up
             unset($_SESSION['sp_error'], $_SESSION['sp_error_post'], $_POST['add_block']);
         }
         // Just in case, the admin could be doing something silly like editing a SP block while SP is disabled. ;)
         require_once BOARDDIR . '/SSI.php';
         sportal_init_headers();
         loadTemplate('Portal');
         $type_parameters = $_POST['block_type'](array(), 0, true);
         if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) {
             foreach ($type_parameters as $name => $type) {
                 if (isset($_POST['parameters'][$name])) {
                     $this->_prepare_parameters($type, $name);
                 }
             }
         } else {
             $_POST['parameters'] = array();
         }
         // Simple is clean
         if (empty($_POST['display_advanced'])) {
             if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) {
                 $display = $_POST['display_simple'];
             } else {
                 $display = '';
             }
             $custom = '';
         } else {
             $display = array();
             $custom = array();
             if (!empty($_POST['display_actions'])) {
                 foreach ($_POST['display_actions'] as $action) {
                     $display[] = Util::htmlspecialchars($action, ENT_QUOTES);
                 }
             }
             if (!empty($_POST['display_boards'])) {
                 foreach ($_POST['display_boards'] as $board) {
                     $display[] = 'b' . (int) substr($board, 1);
                 }
             }
             if (!empty($_POST['display_pages'])) {
                 foreach ($_POST['display_pages'] as $page) {
                     $display[] = 'p' . (int) substr($page, 1);
                 }
             }
             if (!empty($_POST['display_custom'])) {
                 $temp = explode(',', $_POST['display_custom']);
                 foreach ($temp as $action) {
                     $custom[] = Util::htmlspecialchars(Util::htmltrim($action), ENT_QUOTES);
                 }
             }
             $display = empty($display) ? '' : implode(',', $display);
             $custom = empty($custom) ? '' : implode(',', $custom);
         }
         // Create all the information we know about this block
         $context['SPortal']['block'] = array('id' => $_POST['block_id'], 'label' => Util::htmlspecialchars($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'type_text' => !empty($txt['sp_function_' . $_POST['block_type'] . '_label']) ? $txt['sp_function_' . $_POST['block_type'] . '_label'] : $txt['sp_function_unknown_label'], 'column' => $_POST['block_column'], 'row' => !empty($_POST['block_row']) ? $_POST['block_row'] : 0, 'placement' => !empty($_POST['placement']) && in_array($_POST['placement'], array('before', 'after')) ? $_POST['placement'] : '', 'permissions' => $_POST['permissions'], 'state' => !empty($_POST['block_active']), 'force_view' => !empty($_POST['block_force']), 'mobile_view' => !empty($_POST['block_mobile']), 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode'), 'parameters' => !empty($_POST['parameters']) ? $_POST['parameters'] : array(), 'options' => $_POST['block_type'](array(), false, true), 'list_blocks' => getBlockInfo($_POST['block_column']), 'collapsed' => false);
         if (strpos($modSettings['leftwidth'], '%') !== false || strpos($modSettings['leftwidth'], 'px') !== false) {
             $context['widths'][1] = $modSettings['leftwidth'];
         } else {
             $context['widths'][1] = $modSettings['leftwidth'] . 'px';
         }
         if (strpos($modSettings['rightwidth'], '%') !== false || strpos($modSettings['rightwidth'], 'px') !== false) {
             $context['widths'][4] = $modSettings['rightwidth'];
         } else {
             $context['widths'][4] = $modSettings['rightwidth'] . 'px';
         }
         if (strpos($context['widths'][1], '%') !== false) {
             $context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%';
             $context['widths'][5] = $context['widths'][6] = '100%';
         } elseif (strpos($context['widths'][1], 'px') !== false) {
             $context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px';
             $context['widths'][5] = $context['widths'][6] = '960px';
         }
         $context['SPortal']['preview'] = true;
     }
     if (!empty($_POST['selected_type']) || !empty($_POST['preview_block']) || !$context['SPortal']['is_new'] && empty($_POST['add_block'])) {
         // Only the admin can use PHP blocks
         if ($context['SPortal']['block']['type'] == 'sp_php' && !allowedTo('admin_forum')) {
             fatal_lang_error('cannot_admin_forum', false);
         }
         loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp'));
         // Load up the permissions
         $context['SPortal']['block']['permission_profiles'] = sportal_get_profiles(null, 1, 'name');
         if (empty($context['SPortal']['block']['permission_profiles'])) {
             fatal_lang_error('error_sp_no_permission_profiles', false);
         }
         $context['simple_actions'] = array('sportal' => $txt['sp-portal'], 'sforum' => $txt['sp-forum'], 'allaction' => $txt['sp-blocksOptionAllActions'], 'allboard' => $txt['sp-blocksOptionAllBoards'], 'allpages' => $txt['sp-blocksOptionAllPages'], 'all' => $txt['sp-blocksOptionEverywhere']);
         $context['display_actions'] = array('portal' => $txt['sp-portal'], 'forum' => $txt['sp-forum'], 'recent' => $txt['recent_posts'], 'unread' => $txt['unread_topics_visit'], 'unreadreplies' => $txt['unread_replies'], 'profile' => $txt['profile'], 'pm' => $txt['pm_short'], 'calendar' => $txt['calendar'], 'admin' => $txt['admin'], 'login' => $txt['login'], 'register' => $txt['register'], 'post' => $txt['post'], 'stats' => $txt['forum_stats'], 'search' => $txt['search'], 'mlist' => $txt['members_list'], 'moderate' => $txt['moderate'], 'help' => $txt['help'], 'who' => $txt['who_title']);
         // Load up boards and pages for selection in the template
         sp_block_template_helpers();
         if (empty($context['SPortal']['block']['display'])) {
             $context['SPortal']['block']['display'] = array('0');
         } else {
             $context['SPortal']['block']['display'] = explode(',', $context['SPortal']['block']['display']);
         }
         if (in_array($context['SPortal']['block']['display'][0], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages')) || $context['SPortal']['is_new'] || empty($context['SPortal']['block']['display'][0]) && empty($context['SPortal']['block']['display_custom'])) {
             $context['SPortal']['block']['display_type'] = 0;
         } else {
             $context['SPortal']['block']['display_type'] = 1;
         }
         $context['SPortal']['block']['style'] = sportal_parse_style('explode', $context['SPortal']['block']['style'], !empty($context['SPortal']['preview']));
         // Prepare the Textcontent for BBC, only the first bbc will be detected correctly!
         $firstBBCFound = false;
         foreach ($context['SPortal']['block']['options'] as $name => $type) {
             // Selectable Boards :D
             if ($type == 'board_select' || $type == 'boards') {
                 if (empty($boards)) {
                     require_once SUBSDIR . '/Boards.subs.php';
                     getBoardTree();
                 }
                 // Merge the array ;)
                 if (!isset($context['SPortal']['block']['parameters'][$name])) {
                     $context['SPortal']['block']['parameters'][$name] = array();
                 } elseif (!empty($context['SPortal']['block']['parameters'][$name]) && is_array($context['SPortal']['block']['parameters'][$name])) {
                     $context['SPortal']['block']['parameters'][$name] = implode('|', $context['SPortal']['block']['parameters'][$name]);
                 }
                 $context['SPortal']['block']['board_options'][$name] = array();
                 $config_variable = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : array();
                 $config_variable = !is_array($config_variable) ? explode('|', $config_variable) : $config_variable;
                 $context['SPortal']['block']['board_options'][$name] = array();
                 // Create the list for this Item
                 foreach ($boards as $board) {
                     // Ignore the redirected boards :)
                     if (!empty($board['redirect'])) {
                         continue;
                     }
                     $context['SPortal']['block']['board_options'][$name][$board['id']] = array('value' => $board['id'], 'text' => $board['name'], 'selected' => in_array($board['id'], $config_variable));
                 }
             } elseif ($type === 'bbc') {
                 // ELK support only one bbc correct, multiple bbc do not work at the moment
                 if (!$firstBBCFound) {
                     $firstBBCFound = true;
                     // Start Elk BBC System :)
                     require_once SUBSDIR . '/Editor.subs.php';
                     // Prepare the output :D
                     $form_message = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : '';
                     // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited!
                     if (strpos($form_message, '[html]') !== false) {
                         $parts = preg_split('~(\\[/code\\]|\\[code(?:=[^\\]]+)?\\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE);
                         for ($i = 0, $n = count($parts); $i < $n; $i++) {
                             // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
                             if ($i % 4 == 0) {
                                 $parts[$i] = preg_replace_callback('~\\[html\\](.+?)\\[/html\\]~is', create_function('$m', 'return "[html]" . preg_replace(\'~<br\\s?/?>~i\', \'&lt;br /&gt;<br />\', "$m[1]") . "[/html]";'), $parts[$i]);
                             }
                         }
                         $form_message = implode('', $parts);
                     }
                     $form_message = preg_replace('~<br(?: /)?' . '>~i', "\n", $form_message);
                     // Prepare the data before i want them inside the textarea
                     $form_message = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
                     $context['SPortal']['bbc'] = 'bbc_' . $name;
                     $message_data = array('id' => $context['SPortal']['bbc'], 'width' => '95%', 'height' => '200px', 'value' => $form_message, 'form' => 'sp_block');
                     // Run the ELK bbc editor routine
                     create_control_richedit($message_data);
                     // Store the updated data on the parameters
                     $context['SPortal']['block']['parameters'][$name] = $form_message;
                 } else {
                     $context['SPortal']['block']['options'][$name] = 'textarea';
                 }
             }
         }
         loadJavascriptFile('portal.js?sp24');
         $context['sub_template'] = 'block_edit';
         $context['page_title'] = $context['SPortal']['is_new'] ? $txt['sp-blocksAdd'] : $txt['sp-blocksEdit'];
     }
     // Want to add / edit a block oo the portal
     if (!empty($_POST['add_block'])) {
         checkSession();
         // Only the admin can do php here
         if ($_POST['block_type'] == 'sp_php' && !allowedTo('admin_forum')) {
             fatal_lang_error('cannot_admin_forum', false);
         }
         // Make sure the block name is something safe
         if (!isset($_POST['block_name']) || Util::htmltrim(Util::htmlspecialchars($_POST['block_name']), ENT_QUOTES) === '') {
             fatal_lang_error('error_sp_name_empty', false);
         }
         if ($_POST['block_type'] == 'sp_php' && !empty($_POST['parameters']['content']) && empty($modSettings['sp_disable_php_validation'])) {
             require_once SUBSDIR . '/DataValidator.class.php';
             $validator = new Data_Validator();
             $validator->validation_rules(array('content' => 'php_syntax'));
             $validator->validate(array('content' => $_POST['parameters']['content']));
             $error = $validator->validation_errors();
             if ($error) {
                 $_SESSION['sp_error'] = $error[0];
                 $_SESSION['sp_error_post'] = $_POST;
                 redirectexit('action=admin;area=portalblocks;sa=' . $_REQUEST['sa'] . (!empty($_REQUEST['block_id']) ? ';block_id=' . $_REQUEST['block_id'] : ''));
             }
         }
         // If we have a block ID passed, we must be editing, so the the blocks current data
         if (!empty($_REQUEST['block_id'])) {
             $current_data = current(getBlockInfo(null, $_REQUEST['block_id']));
         }
         // Where are we going to place this new block, before, after, no change
         if (!empty($_POST['placement']) && ($_POST['placement'] === 'before' || $_POST['placement'] === 'after')) {
             if (!empty($current_data)) {
                 $current_row = $current_data['row'];
             } else {
                 $current_row = null;
             }
             // Before or after the chosen block
             if ($_POST['placement'] === 'before') {
                 $row = (int) $_POST['block_row'];
             } else {
                 $row = (int) $_POST['block_row'] + 1;
             }
             if (!empty($current_row) && $row > $current_row) {
                 sp_update_block_row($current_row, $row - 1, $_POST['block_column'], true);
             } else {
                 sp_update_block_row($current_row, $row, $_POST['block_column'], false);
             }
         } elseif (!empty($_POST['placement']) && $_POST['placement'] == 'nochange') {
             $row = 0;
         } else {
             $block_id = !empty($_REQUEST['block_id']) ? (int) $_REQUEST['block_id'] : 0;
             $row = sp_block_nextrow($_POST['block_column'], $block_id);
         }
         $type_parameters = $_POST['block_type'](array(), 0, true);
         if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) {
             foreach ($type_parameters as $name => $type) {
                 // Prepare BBC Content for ELK
                 if (isset($_POST['parameters'][$name])) {
                     $this->_prepare_parameters($type, $name);
                 }
             }
         } else {
             $_POST['parameters'] = array();
         }
         // Standard options
         if (empty($_POST['display_advanced'])) {
             if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) {
                 $display = $_POST['display_simple'];
             } else {
                 $display = '';
             }
             $custom = '';
         } else {
             $display = array();
             if (!empty($_POST['display_actions'])) {
                 foreach ($_POST['display_actions'] as $action) {
                     $display[] = Util::htmlspecialchars($action, ENT_QUOTES);
                 }
             }
             if (!empty($_POST['display_boards'])) {
                 foreach ($_POST['display_boards'] as $board) {
                     $display[] = 'b' . (int) substr($board, 1);
                 }
             }
             if (!empty($_POST['display_pages'])) {
                 foreach ($_POST['display_pages'] as $page) {
                     $display[] = 'p' . (int) substr($page, 1);
                 }
             }
             if (!empty($_POST['display_custom'])) {
                 $custom = array();
                 $temp = explode(',', $_POST['display_custom']);
                 foreach ($temp as $action) {
                     $custom[] = Util::htmlspecialchars(Util::htmltrim($action), ENT_QUOTES);
                 }
             }
             $display = empty($display) ? '' : implode(',', $display);
             if (!allowedTo('admin_forum') && isset($current_data['display_custom']) && substr($current_data['display_custom'], 0, 4) === '$php') {
                 $custom = $current_data['display_custom'];
             } elseif (!empty($_POST['display_custom'])) {
                 if (allowedTo('admin_forum') && substr($_POST['display_custom'], 0, 4) === '$php') {
                     $custom = Util::htmlspecialchars($_POST['display_custom'], ENT_QUOTES);
                 } else {
                     $custom = array();
                     $temp = explode(',', $_POST['display_custom']);
                     foreach ($temp as $action) {
                         $custom[] = Util::htmlspecialchars($action, ENT_QUOTES);
                     }
                     $custom = empty($custom) ? '' : implode(',', $custom);
                 }
             } else {
                 $custom = '';
             }
         }
         $blockInfo = array('id' => (int) $_POST['block_id'], 'label' => Util::htmlspecialchars($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'col' => $_POST['block_column'], 'row' => $row, 'permissions' => (int) $_POST['permissions'], 'state' => !empty($_POST['block_active']) ? 1 : 0, 'force_view' => !empty($_POST['block_force']) ? 1 : 0, 'mobile_view' => !empty($_POST['block_mobile']) ? 1 : 0, 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode'));
         // Insert a new block in to the portal
         if ($context['SPortal']['is_new']) {
             unset($blockInfo['id']);
             $blockInfo['id'] = sp_block_insert($blockInfo);
         } else {
             sp_block_update($blockInfo);
         }
         // Save any parameters for the block
         if (!empty($_POST['parameters'])) {
             sp_block_insert_parameters($_POST['parameters'], $blockInfo['id']);
         }
         redirectexit('action=admin;area=portalblocks');
     }
 }
function sportal_add_article()
{
    global $smcFunc, $context, $scripturl, $sourcedir, $txt;
    if (!allowedTo(array('sp_add_article', 'sp_manage_articles', 'sp_admin'))) {
        fatal_lang_error('error_sp_cannot_add_article');
    }
    require_once $sourcedir . '/Subs-PortalAdmin.php';
    loadLanguage('SPortalAdmin', sp_languageSelect('SPortalAdmin'));
    loadTemplate('PortalArticles');
    if (!empty($_POST['add_article'])) {
        $article_options = array('id_category' => !empty($_POST['category']) ? (int) $_POST['category'] : 0, 'id_message' => !empty($_POST['message']) ? (int) $_POST['message'] : 0, 'approved' => allowedTo(array('sp_admin', 'sp_manage_articles', 'sp_auto_article_approval')) ? 1 : 0);
        createArticle($article_options);
        redirectexit('topic=' . $_POST['return']);
    }
    $context['message'] = !empty($_REQUEST['message']) ? (int) $_REQUEST['message'] : 0;
    $context['return'] = !empty($_REQUEST['return']) ? $_REQUEST['return'] : '';
    if (empty($context['message'])) {
        fatal_lang_error('error_sp_no_message_id');
    }
    $request = $smcFunc['db_query']('', '
		SELECT id_message
		FROM {db_prefix}sp_articles
		WHERE id_message = {int:message}', array('message' => $context['message']));
    list($exists) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    if ($exists) {
        fatal_lang_error('error_sp_article_exists');
    }
    $context['list_categories'] = getCategoryInfo(null, true);
    if (empty($context['list_categories'])) {
        fatal_error(allowedTo(array('sp_admin', 'sp_manage_articles')) ? $txt['error_sp_no_category'] . '<br />' . sprintf($txt['error_sp_no_category_sp_moderator'], $scripturl . '?action=admin;area=portalarticles;sa=addcategory') : $txt['error_sp_no_category_normaluser'], false);
    }
    $context['sub_template'] = 'add_article';
}