/** * Load all articles for selection */ public function action_sportal_articles() { global $context, $scripturl, $txt, $modSettings; // Set up for pagination $total_articles = sportal_get_articles_count(); $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($scripturl . '?action=portal;sa=articles;start=%1$d', $start, $total_articles, $per_page, true); } // Fetch the article page $context['articles'] = sportal_get_articles(0, true, true, 'spa.id_article DESC', 0, $per_page, $start); foreach ($context['articles'] as $article) { // Want to cut this one a bit short? 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 . '?action=portal;sa=articles', 'name' => $txt['sp-articles']); $context['page_title'] = $txt['sp-articles']; $context['sub_template'] = 'view_articles'; }
/** * 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']); } } } }