/** * Loads article previews for display with the portal index template */ public function action_sportal_index() { global $context, $modSettings; // Showing articles on the index page? if (!empty($modSettings['sp_articles_index'])) { require_once SUBSDIR . '/PortalArticle.subs.php'; $context['sub_template'] = 'portal_index'; // Set up the pages $total_articles = sportal_get_articles_count(); $total = min($total_articles, !empty($modSettings['sp_articles_index_total']) ? $modSettings['sp_articles_index_total'] : 20); $per_page = min($total, !empty($modSettings['sp_articles_index_per_page']) ? $modSettings['sp_articles_index_per_page'] : 5); $start = !empty($_REQUEST['articles']) ? (int) $_REQUEST['articles'] : 0; if ($total > $per_page) { $context['article_page_index'] = constructPageIndex($context['portal_url'] . '?articles=%1$d', $start, $total, $per_page, true); } // If we have some articles require_once SUBSDIR . '/PortalArticle.subs.php'; $context['articles'] = sportal_get_articles(0, true, true, 'spa.id_article DESC', 0, $per_page, $start); foreach ($context['articles'] as $article) { if (empty($modSettings['sp_articles_length']) && ($cutoff = Util::strpos($article['body'], '[cutoff]')) !== false) { $article['body'] = Util::substr($article['body'], 0, $cutoff); if ($article['type'] === 'bbc') { require_once SUBSDIR . '/Post.subs.php'; preparsecode($article['body']); } } $context['articles'][$article['id']]['preview'] = sportal_parse_content($article['body'], $article['type'], 'return'); $context['articles'][$article['id']]['date'] = htmlTime($article['date']); // Just want a shorter look on the index page if (!empty($modSettings['sp_articles_length'])) { $context['articles'][$article['id']]['preview'] = Util::shorten_html($context['articles'][$article['id']]['preview'], $modSettings['sp_articles_length']); } } } }
/** * View a specific category, showing all articles it contains */ public function action_sportal_category() { global $context, $scripturl, $modSettings; // Basic article support require_once SUBSDIR . '/PortalArticle.subs.php'; $category_id = !empty($_REQUEST['category']) ? $_REQUEST['category'] : 0; if (is_int($category_id)) { $category_id = (int) $category_id; } else { $category_id = Util::htmlspecialchars($category_id, ENT_QUOTES); } $context['category'] = sportal_get_categories($category_id, true, true); if (empty($context['category']['id'])) { fatal_lang_error('error_sp_category_not_found', false); } // Set up the pages $total_articles = sportal_get_articles_in_cat_count($context['category']['id']); $per_page = min($total_articles, !empty($modSettings['sp_articles_per_page']) ? $modSettings['sp_articles_per_page'] : 10); $start = !empty($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0; if ($total_articles > $per_page) { $context['page_index'] = constructPageIndex($context['category']['href'] . ';start=%1$d', $start, $total_articles, $per_page, true); } // Load the articles in this category $context['articles'] = sportal_get_articles(0, true, true, 'spa.id_article DESC', $context['category']['id'], $per_page, $start); foreach ($context['articles'] as $article) { // Cut me mick if (($cutoff = Util::strpos($article['body'], '[cutoff]')) !== false) { $article['body'] = Util::substr($article['body'], 0, $cutoff); if ($article['type'] === 'bbc') { require_once SUBSDIR . '/Post.subs.php'; preparsecode($article['body']); } } $context['articles'][$article['id']]['preview'] = sportal_parse_content($article['body'], $article['type'], 'return'); $context['articles'][$article['id']]['date'] = htmlTime($article['date']); } $context['linktree'][] = array('url' => $scripturl . '?category=' . $context['category']['category_id'], 'name' => $context['category']['name']); $context['page_title'] = $context['category']['name']; $context['sub_template'] = 'view_category'; }
/** * 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'; }
/** * Article Block, show the list of articles in the system * * @param mixed[] $parameters * 'category' => list of categories to choose article from * 'limit' => number of articles to show * 'type' => 0 latest 1 random * 'length' => length for the body text preview * 'avatar' => whether to show the author avatar or not * * @param int $id - not used in this block * @param boolean $return_parameters if true returns the configuration options for the block */ function sp_articles($parameters, $id, $return_parameters = false) { global $scripturl, $txt, $color_profile; $block_parameters = array('category' => array(0 => $txt['sp_all']), 'limit' => 'int', 'type' => 'select', 'length' => 'int', 'avatar' => 'check'); if ($return_parameters) { require_once SUBSDIR . '/PortalAdmin.subs.php'; $categories = sp_load_categories(); foreach ($categories as $category) { $block_parameters['category'][$category['id']] = $category['name']; } return $block_parameters; } // Needed utilities require_once SUBSDIR . '/Post.subs.php'; require_once SUBSDIR . '/PortalArticle.subs.php'; // Set up for the query $category = empty($parameters['category']) ? 0 : (int) $parameters['category']; $limit = empty($parameters['limit']) ? 5 : (int) $parameters['limit']; $type = empty($parameters['type']) ? 0 : 1; $length = isset($parameters['length']) ? (int) $parameters['length'] : 250; $avatar = empty($parameters['avatar']) ? 0 : (int) $parameters['avatar']; $articles = sportal_get_articles(null, true, true, $type ? 'RAND()' : 'spa.date DESC', $category, $limit); $colorids = array(); foreach ($articles as $article) { if (!empty($article['author']['id'])) { $colorids[$article['author']['id']] = $article['author']['id']; } } // No articles in the system or none they can see if (empty($articles)) { echo ' ', $txt['error_sp_no_articles_found']; return; } // Doing the color thing if (!empty($colorids) && sp_loadColors($colorids) !== false) { foreach ($articles as $k => $p) { if (!empty($color_profile[$p['author']['id']]['link'])) { $articles[$k]['author']['link'] = $color_profile[$p['author']['id']]['link']; } } } // Not showing avatars, just use a compact link view if (empty($avatar)) { echo ' <ul class="sp_list">'; foreach ($articles as $article) { echo ' <li>', sp_embed_image('topic'), ' ', $article['link'], '</li>'; } echo ' </ul>'; } else { echo ' <table class="sp_fullwidth">'; foreach ($articles as $article) { // Using the cutoff tag? $limited = false; if (($cutoff = Util::strpos($article['body'], '[cutoff]')) !== false) { $article['body'] = Util::substr($article['body'], 0, $cutoff); preparsecode($article['body']); $limited = true; } // Good time to do this is ... now censorText($article['subject']); censorText($article['body']); $article['body'] = sportal_parse_content($article['body'], $article['type'], 'return'); // Shorten the text, link the ellipsis, etc as needed if ($limited || !empty($length)) { $ellip = '<a href="' . $scripturl . '?article=' . $article['article_id'] . '">…</a>'; $article['body'] = $limited ? $article['body'] . $ellip : Util::shorten_html($article['body'], $length, $ellip, false); } echo ' <tr class="sp_articles_row"> <td class="sp_articles centertext">'; // If we have an avatar to show, show it if ($avatar && !empty($article['author']['avatar']['href'])) { echo ' <a href="', $scripturl, '?action=profile;u=', $article['author']['id'], '"> <img src="', $article['author']['avatar']['href'], '" alt="', $article['author']['name'], '" style="max-width:40px" /> </a>'; } echo ' </td> <td> <span class="sp_articles_title">', $article['author']['link'], '</span><br /> ', $article['link'], ' </td> <td>', $article['body'], '</td> </tr> <tr> <td colspan="3" class="sp_articles_row"></td> </tr>'; } echo ' </table>'; } }
/** * Remove an article from the system */ public function action_sportal_admin_article_delete() { $article_ids = array(); // Get the article id's to remove if (!empty($_POST['remove_articles']) && !empty($_POST['remove']) && is_array($_POST['remove'])) { checkSession(); foreach ($_POST['remove'] as $index => $article_id) { $article_ids[(int) $index] = (int) $article_id; } } elseif (!empty($_REQUEST['article_id'])) { checkSession('get'); $article_ids[] = (int) $_REQUEST['article_id']; } // If we have some to remove .... if (!empty($article_ids)) { // Update the counts as we are about to remove some articles foreach ($article_ids as $index => $article_id) { $article_info = sportal_get_articles($article_id); sp_category_update_total($article_info['category']['id']); } sp_delete_articles($article_ids); } redirectexit('action=admin;area=portalarticles'); }