/** * 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'; }
/** * Display a chosen article * * - Update the stats, like #views etc */ public function action_sportal_article() { global $context, $scripturl, $user_info; $article_id = !empty($_REQUEST['article']) ? $_REQUEST['article'] : 0; if (is_int($article_id)) { $article_id = (int) $article_id; } else { $article_id = Util::htmlspecialchars($article_id, ENT_QUOTES); } // Fetch and render the article $context['article'] = sportal_get_articles($article_id, true, true); if (empty($context['article']['id'])) { fatal_lang_error('error_sp_article_not_found', false); } $context['article']['body'] = sportal_parse_content($context['article']['body'], $context['article']['type'], 'return'); // Set up for the comment pagination $total_comments = sportal_get_article_comment_count($context['article']['id']); $per_page = min($total_comments, !empty($modSettings['sp_articles_comments_per_page']) ? $modSettings['sp_articles_comments_per_page'] : 20); $start = !empty($_REQUEST['comments']) ? (int) $_REQUEST['comments'] : 0; if ($total_comments > $per_page) { $context['page_index'] = constructPageIndex($scripturl . '?article=' . $context['article']['article_id'] . ';comments=%1$d', $start, $total_comments, $per_page, true); } // Load in all the comments for the article $context['article']['comments'] = sportal_get_comments($context['article']['id'], $per_page, $start); // Prepare the final template details $context['article']['date'] = htmlTime($context['article']['date']); $context['article']['can_comment'] = $context['user']['is_logged']; $context['article']['can_moderate'] = allowedTo('sp_admin') || allowedTo('sp_manage_articles'); // Commenting, new or an update perhaps if ($context['article']['can_comment'] && !empty($_POST['body'])) { checkSession(); sp_prevent_flood('spacp', false); require_once SUBSDIR . '/Post.subs.php'; // Prep the body / comment $body = Util::htmlspecialchars(trim($_POST['body'])); preparsecode($body); // Update or add a new comment if (!empty($body) && trim(strip_tags(parse_bbc($body, false), '<img>')) !== '') { if (!empty($_POST['comment'])) { list($comment_id, $author_id, ) = sportal_fetch_article_comment((int) $_POST['comment']); if (empty($comment_id) || !$context['article']['can_moderate'] && $user_info['id'] != $author_id) { fatal_lang_error('error_sp_cannot_comment_modify', false); } sportal_modify_article_comment($comment_id, $body); } else { sportal_create_article_comment($context['article']['id'], $body); } } // Set a anchor $anchor = '#comment' . (!empty($comment_id) ? $comment_id : ($total_comments > 0 ? $total_comments - 1 : 1)); redirectexit('article=' . $context['article']['article_id'] . $anchor); } // Prepare to edit an existing comment if ($context['article']['can_comment'] && !empty($_GET['modify'])) { checkSession('get'); list($comment_id, $author_id, $body) = sportal_fetch_article_comment((int) $_GET['modify']); if (empty($comment_id) || !$context['article']['can_moderate'] && $user_info['id'] != $author_id) { fatal_lang_error('error_sp_cannot_comment_modify', false); } require_once SUBSDIR . '/Post.subs.php'; $context['article']['comment'] = array('id' => $comment_id, 'body' => str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), un_preparsecode($body))); } // Want to delete a comment? if ($context['article']['can_comment'] && !empty($_GET['delete'])) { checkSession('get'); if (sportal_delete_article_comment((int) $_GET['delete']) === false) { fatal_lang_error('error_sp_cannot_comment_delete', false); } redirectexit('article=' . $context['article']['article_id']); } // Increase the article view counter if (empty($_SESSION['last_viewed_article']) || $_SESSION['last_viewed_article'] != $context['article']['id']) { sportal_increase_viewcount('article', $context['article']['id']); $_SESSION['last_viewed_article'] = $context['article']['id']; } // Build the breadcrumbs $context['linktree'] = array_merge($context['linktree'], array(array('url' => $scripturl . '?category=' . $context['article']['category']['category_id'], 'name' => $context['article']['category']['name']), array('url' => $scripturl . '?article=' . $context['article']['article_id'], 'name' => $context['article']['title']))); // Off to the template we go $context['page_title'] = $context['article']['title']; $context['sub_template'] = 'view_article'; }