/**
 * Loads all the defined portal blocks in to context
 */
function sportal_load_blocks()
{
    global $context, $modSettings, $options;
    $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));
    // Get the blocks in the system
    $blocks = getBlockInfo(null, null, true, true, true);
    // If the member has arranged the blocks, display them like that
    if (!empty($options['sp_block_layout'])) {
        $layout = @unserialize($options['sp_block_layout']);
        // If some bad arrangement data found its way in
        if ($layout === false) {
            resetMemberLayout();
        } else {
            foreach ($layout as $id => $column) {
                if (empty($column) || empty($id) || !$context['SPortal']['sides'][$id]['active']) {
                    continue;
                }
                foreach ($column as $item) {
                    if (empty($blocks[$item])) {
                        continue;
                    }
                    $blocks[$item]['style'] = sportal_parse_style('explode', $blocks[$item]['style'], true);
                    $context['SPortal']['blocks'][$id][] = $blocks[$item];
                    unset($blocks[$item]);
                }
                $context['SPortal']['blocks']['custom_arrange'] = true;
            }
        }
    }
    if (!isset($context['SPortal']['blocks'])) {
        $context['SPortal']['blocks'] = array();
    }
    foreach ($blocks as $block) {
        if (!$context['SPortal']['sides'][$block['column']]['active']) {
            continue;
        }
        if ($context['browser_body_id'] === 'mobile' && empty($block['mobile_view'])) {
            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']]);
    }
}
 /**
  * Reset a users custom portal block arrangement
  */
 public function action_sportal_resetLayout()
 {
     checkSession('request');
     // Remove the block layout settings
     require_once SUBSDIR . '/Portal.subs.php';
     resetMemberLayout();
     // Redirect to the main page
     redirectexit();
 }