function sportal_pages() { global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info; loadTemplate('PortalPages'); $page_id = !empty($_REQUEST['page']) ? $_REQUEST['page'] : 0; if (is_numeric($page_id)) { $page_id = (int) $page_id; } else { $page_id = $smcFunc['htmlspecialchars']($page_id, ENT_QUOTES); } $context['SPortal']['page'] = sportal_get_pages($page_id, true, true); if (empty($context['SPortal']['page']['id'])) { fatal_lang_error('error_sp_page_not_found', false); } $context['SPortal']['page']['style'] = sportal_parse_style('explode', $context['SPortal']['page']['style'], true); if (empty($_SESSION['last_viewed_page']) || $_SESSION['last_viewed_page'] != $context['SPortal']['page']['id']) { $smcFunc['db_query']('', ' UPDATE {db_prefix}sp_pages SET views = views + 1 WHERE id_page = {int:current_page}', array('current_page' => $context['SPortal']['page']['id'])); $_SESSION['last_viewed_page'] = $context['SPortal']['page']['id']; } $context['linktree'][] = array('url' => $scripturl . '?page=' . $page_id, 'name' => $context['SPortal']['page']['title']); $context['page_title'] = $context['SPortal']['page']['title']; $context['sub_template'] = 'view_page'; }
/** * View a specific page in the system */ public function action_sportal_page() { global $context, $scripturl; // Use the requested page id $page_id = !empty($_REQUEST['page']) ? $_REQUEST['page'] : 0; // Fetch the page $context['SPortal']['page'] = sportal_get_pages($page_id, true, true); if (empty($context['SPortal']['page']['id'])) { fatal_lang_error('error_sp_page_not_found', false); } // Fetch any style associated with the page $context['SPortal']['page']['style'] = sportal_parse_style('explode', $context['SPortal']['page']['style'], true); // Prepare the body $context['SPortal']['page']['body'] = sportal_parse_content($context['SPortal']['page']['body'], $context['SPortal']['page']['type'], 'return'); // Increase the view counter if (empty($_SESSION['last_viewed_page']) || $_SESSION['last_viewed_page'] != $context['SPortal']['page']['id']) { sportal_increase_viewcount('page', $context['SPortal']['page']['id']); $_SESSION['last_viewed_page'] = $context['SPortal']['page']['id']; } // Prep the template for display $context['linktree'][] = array('url' => $scripturl . '?page=' . $page_id, 'name' => $context['SPortal']['page']['title']); $context['page_title'] = $context['SPortal']['page']['title']; $context['sub_template'] = 'view_page'; }
function sportal_admin_page_edit() { global $txt, $context, $modSettings, $smcFunc, $sourcedir, $options; require_once $sourcedir . '/Subs-Editor.php'; require_once $sourcedir . '/Subs-Post.php'; $context['SPortal']['is_new'] = empty($_REQUEST['page_id']); if (!empty($_REQUEST['content_mode']) && $_POST['type'] == 'bbc') { $_REQUEST['content'] = html_to_bbc($_REQUEST['content']); $_REQUEST['content'] = un_htmlspecialchars($_REQUEST['content']); $_POST['content'] = $_REQUEST['content']; } $context['sides'] = array(5 => $txt['sp-positionHeader'], 1 => $txt['sp-positionLeft'], 2 => $txt['sp-positionTop'], 3 => $txt['sp-positionBottom'], 4 => $txt['sp-positionRight'], 6 => $txt['sp-positionFooter']); $blocks = getBlockInfo(); $context['page_blocks'] = array(); foreach ($blocks as $block) { $shown = false; $tests = array('all', 'allpages', 'sforum'); if (!$context['SPortal']['is_new']) { $tests[] = 'p' . (int) $_REQUEST['page_id']; } foreach (array('display', 'display_custom') as $field) { if (substr($block[$field], 0, 4) === '$php') { continue 2; } $block[$field] = explode(',', $block[$field]); if (!$context['SPortal']['is_new'] && in_array('-p' . (int) $_REQUEST['page_id'], $block[$field])) { continue; } foreach ($tests as $test) { if (in_array($test, $block[$field])) { $shown = true; break; } } } $context['page_blocks'][$block['column']][] = array('id' => $block['id'], 'label' => $block['label'], 'shown' => $shown); } if (!empty($_POST['submit'])) { checkSession(); if (!isset($_POST['title']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['title'], ENT_QUOTES)) === '') { fatal_lang_error('sp_error_page_name_empty', false); } if (!isset($_POST['namespace']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['namespace'], ENT_QUOTES)) === '') { fatal_lang_error('sp_error_page_namespace_empty', false); } $result = $smcFunc['db_query']('', ' SELECT id_page FROM {db_prefix}sp_pages WHERE namespace = {string:namespace} AND id_page != {int:current} LIMIT 1', array('limit' => 1, 'namespace' => $smcFunc['htmlspecialchars']($_POST['namespace'], ENT_QUOTES), 'current' => (int) $_POST['page_id'])); list($has_duplicate) = $smcFunc['db_fetch_row']($result); $smcFunc['db_free_result']($result); if (!empty($has_duplicate)) { fatal_lang_error('sp_error_page_namespace_duplicate', false); } if (preg_match('~[^A-Za-z0-9_]+~', $_POST['namespace']) != 0) { fatal_lang_error('sp_error_page_namespace_invalid_chars', false); } if (preg_replace('~[0-9]+~', '', $_POST['namespace']) === '') { fatal_lang_error('sp_error_page_namespace_numeric', false); } if ($_POST['type'] == 'php' && !empty($_POST['content']) && empty($modSettings['sp_disable_php_validation'])) { $error = sp_validate_php($_POST['content']); if ($error) { fatal_lang_error('error_sp_php_' . $error, false); } } $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['blocks']) && is_array($_POST['blocks'])) { foreach ($_POST['blocks'] as $id => $block) { $_POST['blocks'][$id] = (int) $block; } } else { $_POST['blocks'] = array(); } $fields = array('namespace' => 'string', 'title' => 'string', 'body' => 'string', 'type' => 'string', 'permission_set' => 'int', 'groups_allowed' => 'string', 'groups_denied' => 'string', 'style' => 'string', 'status' => 'int'); $page_info = array('id' => (int) $_POST['page_id'], 'namespace' => $smcFunc['htmlspecialchars']($_POST['namespace'], ENT_QUOTES), 'title' => $smcFunc['htmlspecialchars']($_POST['title'], ENT_QUOTES), 'body' => $smcFunc['htmlspecialchars']($_POST['content'], ENT_QUOTES), 'type' => $_POST['type'], 'permission_set' => $permission_set, 'groups_allowed' => $groups_allowed, 'groups_denied' => $groups_denied, 'style' => sportal_parse_style('implode'), 'status' => !empty($_POST['status']) ? 1 : 0); if ($page_info['type'] == 'bbc') { preparsecode($page_info['body']); } if ($context['SPortal']['is_new']) { unset($page_info['id']); $smcFunc['db_insert']('', '{db_prefix}sp_pages', $fields, $page_info, array('id_page')); $page_info['id'] = $smcFunc['db_insert_id']('{db_prefix}sp_pages', 'id_page'); } else { $update_fields = array(); foreach ($fields as $name => $type) { $update_fields[] = $name . ' = {' . $type . ':' . $name . '}'; } $smcFunc['db_query']('', ' UPDATE {db_prefix}sp_pages SET ' . implode(', ', $update_fields) . ' WHERE id_page = {int:id}', $page_info); } $to_show = array(); $not_to_show = array(); $changes = array(); foreach ($context['page_blocks'] as $page_blocks) { foreach ($page_blocks as $block) { if ($block['shown'] && !in_array($block['id'], $_POST['blocks'])) { $not_to_show[] = $block['id']; } elseif (!$block['shown'] && in_array($block['id'], $_POST['blocks'])) { $to_show[] = $block['id']; } } } foreach ($to_show as $id) { if (empty($blocks[$id]['display']) && empty($blocks[$id]['display_custom']) || $blocks[$id]['display'] == 'sportal') { $changes[$id] = array('display' => 'portal,p' . $page_info['id'], 'display_custom' => ''); } elseif (in_array($blocks[$id]['display'], array('allaction', 'allboard'))) { $changes[$id] = array('display' => '', 'display_custom' => $blocks[$id]['display'] . ',p' . $page_info['id']); } elseif (in_array('-p' . $page_info['id'], explode(',', $blocks[$id]['display_custom']))) { $changes[$id] = array('display' => $blocks[$id]['display'], 'display_custom' => implode(',', array_diff(explode(',', $blocks[$id]['display_custom']), array('-p' . $page_info['id'])))); } elseif (empty($blocks[$id]['display_custom'])) { $changes[$id] = array('display' => implode(',', array_merge(explode(',', $blocks[$id]['display']), array('p' . $page_info['id']))), 'display_custom' => ''); } else { $changes[$id] = array('display' => $blocks[$id]['display'], 'display_custom' => implode(',', array_merge(explode(',', $blocks[$id]['display_custom']), array('p' . $page_info['id'])))); } } foreach ($not_to_show as $id) { if (count(array_intersect(array($blocks[$id]['display'], $blocks[$id]['display_custom']), array('sforum', 'allpages', 'all'))) > 0) { $changes[$id] = array('display' => '', 'display_custom' => $blocks[$id]['display'] . $blocks[$id]['display_custom'] . ',-p' . $page_info['id']); } elseif (empty($blocks[$id]['display_custom'])) { $changes[$id] = array('display' => implode(',', array_diff(explode(',', $blocks[$id]['display']), array('p' . $page_info['id']))), 'display_custom' => ''); } else { $changes[$id] = array('display' => implode(',', array_diff(explode(',', $blocks[$id]['display']), array('p' . $page_info['id']))), 'display_custom' => implode(',', array_diff(explode(',', $blocks[$id]['display_custom']), array('p' . $page_info['id'])))); } } foreach ($changes as $id => $data) { $smcFunc['db_query']('', ' UPDATE {db_prefix}sp_blocks SET display = {string:display}, display_custom = {string:display_custom} WHERE id_block = {int:id}', array('id' => $id, 'display' => $data['display'], 'display_custom' => $data['display_custom'])); } redirectexit('action=admin;area=portalpages'); } if (!empty($_POST['preview'])) { $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']['page'] = array('id' => $_POST['page_id'], 'page_id' => $_POST['namespace'], 'title' => $smcFunc['htmlspecialchars']($_POST['title'], ENT_QUOTES), 'body' => $smcFunc['htmlspecialchars']($_POST['content'], ENT_QUOTES), 'type' => $_POST['type'], 'permission_set' => $permission_set, 'groups_allowed' => $groups_allowed, 'groups_denied' => $groups_denied, 'style' => sportal_parse_style('implode'), 'status' => !empty($_POST['status'])); if ($context['SPortal']['page']['type'] == 'bbc') { preparsecode($context['SPortal']['page']['body']); } loadTemplate('PortalPages'); $context['SPortal']['preview'] = true; } elseif ($context['SPortal']['is_new']) { $context['SPortal']['page'] = array('id' => 0, 'page_id' => 'page' . mt_rand(1, 5000), 'title' => $txt['sp_pages_default_title'], 'body' => '', 'type' => 'bbc', 'permission_set' => 3, 'groups_allowed' => array(), 'groups_denied' => array(), 'style' => '', 'status' => 1); } else { $_REQUEST['page_id'] = (int) $_REQUEST['page_id']; $context['SPortal']['page'] = sportal_get_pages($_REQUEST['page_id']); } if ($context['SPortal']['page']['type'] == 'bbc') { $context['SPortal']['page']['body'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), un_preparsecode($context['SPortal']['page']['body'])); } if ($context['SPortal']['page']['type'] != 'bbc') { $temp_editor = !empty($options['wysiwyg_default']); $options['wysiwyg_default'] = false; } $editorOptions = array('id' => 'content', 'value' => $context['SPortal']['page']['body'], 'width' => '95%', 'height' => '200px', 'preview_type' => 0); create_control_richedit($editorOptions); $context['post_box_name'] = $editorOptions['id']; if (isset($temp_editor)) { $options['wysiwyg_default'] = $temp_editor; } $context['SPortal']['page']['groups'] = sp_load_membergroups(); $context['SPortal']['page']['style'] = sportal_parse_style('explode', $context['SPortal']['page']['style'], !empty($context['SPortal']['preview'])); $context['page_title'] = $context['SPortal']['is_new'] ? $txt['sp_admin_pages_add'] : $txt['sp_admin_pages_edit']; $context['sub_template'] = 'pages_edit'; }
/** * Function to get a block's display/show information. * * @param int|null $block_id * @param string|null $display * @param string|null $custom */ function getShowInfo($block_id = null, $display = null, $custom = null) { global $context, $modSettings; static $variables; $db = database(); // Do we have the display info? if ($display === null || $custom === null) { // Make sure that its an integer. $block_id = (int) $block_id; // We need an ID. if (empty($block_id)) { return false; } // Get the info. $result = $db->query('', ' SELECT display, display_custom FROM {db_prefix}sp_blocks WHERE id_block = {int:id_block} LIMIT 1', array('id_block' => $block_id)); list($display, $custom) = $db->fetch_row($result); $db->free_result($result); } if (!empty($_GET['page']) && (empty($context['current_action']) || $context['current_action'] == 'portal')) { if (empty($context['SPortal']['permissions'])) { sportal_load_permissions(); } $page_info = sportal_get_pages($_GET['page'], true, true); } // Some variables for ease. $action = !empty($context['current_action']) ? $context['current_action'] : ''; $sub_action = !empty($context['current_subaction']) ? $context['current_subaction'] : ''; $board = !empty($context['current_board']) ? 'b' . $context['current_board'] : ''; $topic = !empty($context['current_topic']) ? 't' . $context['current_topic'] : ''; $page = !empty($page_info['id']) ? 'p' . $page_info['id'] : ''; $portal = empty($action) && empty($sub_action) && empty($board) && empty($topic) && ELK !== 'SSI' && $modSettings['sp_portal_mode'] == 1 || $action == 'portal' || !empty($context['standalone']) ? true : false; // Will hopefully get larger in the future. $portal_actions = array('articles' => true, 'start' => true, 'theme' => true, 'PHPSESSID' => true, 'wwwRedirect' => true, 'www' => true, 'variant' => true, 'language' => true, 'action' => array('portal')); // Set some action exceptions. $exceptions = array('post' => array('announce', 'editpoll', 'emailuser', 'post2', 'sendtopic'), 'register' => array('activate', 'coppa'), 'forum' => array('collapse'), 'admin' => array('credits', 'theme', 'viewquery', 'viewsmfile'), 'moderate' => array('groups'), 'login' => array('reminder'), 'profile' => array('trackip', 'viewprofile')); // Still, we might not be in portal! if (!empty($_GET) && empty($context['standalone'])) { foreach ($_GET as $key => $value) { if (preg_match('~^news\\d+$~', $key)) { continue; } if (!isset($portal_actions[$key])) { $portal = false; } elseif (is_array($portal_actions[$key]) && !in_array($value, $portal_actions[$key])) { $portal = false; } } } // Set the action to more known one. foreach ($exceptions as $key => $exception) { if (in_array($action, $exception)) { $action = $key; } } // Take care of custom actions. $special = array(); $exclude = array(); if (!empty($custom)) { // Complex display options first... if (substr($custom, 0, 4) === '$php') { if (!isset($variables)) { $variables = array('{$action}' => "'{$action}'", '{$sa}' => "'{$sub_action}'", '{$board}' => "'{$board}'", '{$topic}' => "'{$topic}'", '{$page}' => "'{$page}'", '{$portal}' => $portal); } return @eval(str_replace(array_keys($variables), array_values($variables), un_htmlspecialchars(substr($custom, 4))) . ';'); } $custom = explode(',', $custom); // This is special... foreach ($custom as $key => $value) { // Is this a weird action? if ($value[0] == '~') { @(list($name, $item) = explode('|', substr($value, 1))); if (empty($item)) { $special[$name] = true; } else { $special[$name][] = $item; } } elseif ($value[0] == '-') { // We still may have weird things... if ($value[1] == '~') { @(list($name, $item) = explode('|', substr($value, 2))); if (empty($item)) { $exclude['special'][$name] = true; } else { $exclude['special'][$name][] = $item; } } else { $exclude['regular'][] = substr($value, 1); } } } // Add what we have to main variable. if (!empty($display)) { $display = $display . ',' . implode(',', $custom); } else { $display = $custom; } } // We don't want to show it on this action/page/board? if (!empty($exclude['regular']) && count(array_intersect(array($action, $page, $board), $exclude['regular'])) > 0) { return false; } // Maybe we don't want to show it in somewhere special. if (!empty($exclude['special'])) { foreach ($exclude['special'] as $key => $value) { if (isset($_GET[$key])) { if (is_array($value) && !in_array($_GET[$key], $value)) { continue; } else { return false; } } } } // If no display info and/or integration disabled and we are on portal; show it! if ((empty($display) || empty($modSettings['sp_enableIntegration'])) && $portal) { return true; } elseif (empty($display) || empty($modSettings['sp_enableIntegration'])) { return false; } elseif (!is_array($display)) { $display = explode(',', $display); } // Did we disable all blocks for this action? if (!empty($modSettings['sp_' . $action . 'IntegrationHide'])) { return false; } elseif (in_array('all', $display)) { return true; } elseif ($portal && (in_array('portal', $display) || in_array('sportal', $display)) || !$portal && in_array('sforum', $display)) { return true; } elseif (!empty($board) && (in_array('allboard', $display) || in_array($board, $display))) { return true; } elseif (!empty($action) && $action != 'portal' && (in_array('allaction', $display) || in_array($action, $display))) { return true; } elseif (!empty($page) && (in_array('allpages', $display) || in_array($page, $display))) { return true; } elseif (empty($action) && empty($board) && empty($_GET['page']) && !$portal && ($modSettings['sp_portal_mode'] == 2 || $modSettings['sp_portal_mode'] == 3) && in_array('forum', $display)) { return true; } // For mods using weird urls... foreach ($special as $key => $value) { if (isset($_GET[$key])) { if (is_array($value) && !in_array($_GET[$key], $value)) { continue; } else { return true; } } } // Ummm, no block! return false; }
/** * Interface for adding/editing a page */ public function action_sportal_admin_page_edit() { global $txt, $context, $options; $context['SPortal']['is_new'] = empty($_REQUEST['page_id']); $pages_errors = Error_Context::context('pages', 0); // Some help will be needed require_once SUBSDIR . '/Editor.subs.php'; require_once SUBSDIR . '/Post.subs.php'; // Convert this to BBC? if (!empty($_REQUEST['content_mode']) && $_POST['type'] === 'bbc') { require_once SUBSDIR . 'Html2BBC.class.php'; $bbc_converter = new Convert_BBC($_REQUEST['content']); $_REQUEST['content'] = $bbc_converter->get_bbc(); $_REQUEST['content'] = un_htmlspecialchars($_REQUEST['content']); $_POST['content'] = $_REQUEST['content']; } // Load in the blocks that can be used on a page $this->blocks = getBlockInfo(); $context['page_blocks'] = $this->_sportal_admin_page_load_blocks(); // Saving the work? if (!empty($_POST['submit']) && !$pages_errors->hasErrors()) { checkSession(); $this->_sportal_admin_page_edit_save(); } // Doing a quick look before you save or you messed up? if (!empty($_POST['preview']) || $pages_errors->hasErrors()) { $context['SPortal']['page'] = array('id' => $_POST['page_id'], 'page_id' => $_POST['namespace'], 'title' => Util::htmlspecialchars($_POST['title'], ENT_QUOTES), 'body' => Util::htmlspecialchars($_POST['content'], ENT_QUOTES), 'type' => $_POST['type'], 'permissions' => $_POST['permissions'], 'style' => sportal_parse_style('implode'), 'status' => !empty($_POST['status'])); // Fix up bbc errors before we go to the preview if ($context['SPortal']['page']['type'] == 'bbc') { preparsecode($context['SPortal']['page']['body']); } loadTemplate('PortalPages'); // Showing errors or a preview? if ($pages_errors->hasErrors()) { $context['pages_errors'] = array('errors' => $pages_errors->prepareErrors(), 'type' => $pages_errors->getErrorType() == 0 ? 'minor' : 'serious', 'title' => $txt['sp_form_errors_detected']); } else { $context['SPortal']['preview'] = true; } } elseif ($context['SPortal']['is_new']) { $context['SPortal']['page'] = array('id' => 0, 'page_id' => 'page' . mt_rand(1, 5000), 'title' => $txt['sp_pages_default_title'], 'body' => '', 'type' => 'bbc', 'permissions' => 3, 'style' => '', 'status' => 1); } else { $_REQUEST['page_id'] = (int) $_REQUEST['page_id']; $context['SPortal']['page'] = sportal_get_pages($_REQUEST['page_id']); } if ($context['SPortal']['page']['type'] === 'bbc') { $context['SPortal']['page']['body'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), un_preparsecode($context['SPortal']['page']['body'])); } // Set up the editor, values, initial state, etc if ($context['SPortal']['page']['type'] !== 'bbc') { // No wizzy mode if they don't need it $temp_editor = !empty($options['wysiwyg_default']); $options['wysiwyg_default'] = false; } $editorOptions = array('id' => 'content', 'value' => $context['SPortal']['page']['body'], 'width' => '100%', 'height' => '225px', 'preview_type' => 2); create_control_richedit($editorOptions); $context['post_box_name'] = $editorOptions['id']; if (isset($temp_editor)) { $options['wysiwyg_default'] = $temp_editor; } // Set the editor box as needed (editor or textbox, etc) addInlineJavascript(' $(window).load(function() { diewithfire = window.setTimeout(function() {sp_update_editor("' . $context['SPortal']['page']['type'] . '", "");}, 200); }); '); // Permissions $context['SPortal']['page']['permission_profiles'] = sportal_get_profiles(null, 1, 'name'); if (empty($context['SPortal']['page']['permission_profiles'])) { fatal_lang_error('error_sp_no_permission_profiles', false); } // And for the template $context['SPortal']['page']['style'] = sportal_parse_style('explode', $context['SPortal']['page']['style'], !empty($context['SPortal']['preview'])); $context['SPortal']['page']['body'] = sportal_parse_content($context['SPortal']['page']['body'], $context['SPortal']['page']['type'], 'return'); $context['page_title'] = $context['SPortal']['is_new'] ? $txt['sp_admin_pages_add'] : $txt['sp_admin_pages_edit']; $context['sub_template'] = 'pages_edit'; }