/** * 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'; }
/** * 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'; }
/** * 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>'; } }
/** * Edits an existing or adds a new article to the system * Handles the previewing of an article */ public function action_sportal_admin_article_edit() { global $context, $options, $txt; $this->_is_new = empty($_REQUEST['article_id']); $article_errors = Error_Context::context('article', 0); // Going to use editor and post functions require_once SUBSDIR . '/Post.subs.php'; require_once SUBSDIR . '/Editor.subs.php'; // Convert this to BBC? if (!empty($_REQUEST['content_mode']) && $_POST['type'] == 'bbc') { $convert = $_REQUEST['content']; require_once SUBSDIR . '/Html2BBC.class.php'; $bbc_converter = new Convert_BBC($convert); $convert = $bbc_converter->get_bbc(); $convert = un_htmlspecialchars($convert); $_POST['content'] = $convert; } // Saving the work? if (!empty($_POST['submit']) && !$article_errors->hasErrors()) { checkSession(); $this->_sportal_admin_article_edit_save(); } // Just taking a look before you save? if (!empty($_POST['preview']) || $article_errors->hasErrors()) { $context['article'] = $this->_sportal_admin_article_preview(); // Fix any bbc errors they have created if ($context['article']['type'] == 'bbc') { preparsecode($context['article']['body']); } loadTemplate('PortalArticles'); // Showing errors or a preview? if ($article_errors->hasErrors()) { $context['article_errors'] = array('errors' => $article_errors->prepareErrors(), 'type' => $article_errors->getErrorType() == 0 ? 'minor' : 'serious', 'title' => $txt['sp_form_errors_detected']); } else { $context['preview'] = true; } } elseif ($this->_is_new) { $context['article'] = array('id' => 0, 'article_id' => 'article' . mt_rand(1, 5000), 'category' => array('id' => 0), 'title' => $txt['sp_articles_default_title'], 'body' => '', 'type' => 'bbc', 'permissions' => 3, 'status' => 1); } else { $_REQUEST['article_id'] = (int) $_REQUEST['article_id']; $context['article'] = sportal_get_articles($_REQUEST['article_id']); } if ($context['article']['type'] === 'bbc') { $context['article']['body'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), un_preparsecode($context['article']['body'])); } // On to the editor if ($context['article']['type'] !== 'bbc') { // Override user prefs for wizzy mode if they don't need it $temp_editor = !empty($options['wysiwyg_default']); $options['wysiwyg_default'] = false; } // Fire up the editor with the values $editor_options = array('id' => 'content', 'value' => $context['article']['body'], 'width' => '100%', 'height' => '225px', 'preview_type' => 2); create_control_richedit($editor_options); $context['post_box_name'] = $editor_options['id']; // Restore their settings if (isset($temp_editor)) { $options['wysiwyg_default'] = $temp_editor; } // Set the editor box to the right mode based on type (bbc, html, php) addInlineJavascript(' $(window).load(function() { diewithfire = window.setTimeout(function() {sp_update_editor("' . $context['article']['type'] . '", "");}, 200); }); '); // Final bits for the template, category's and permission settings $context['article']['permission_profiles'] = sportal_get_profiles(null, 1, 'name'); if (empty($context['article']['permission_profiles'])) { fatal_lang_error('error_sp_no_permission_profiles', false); } $context['article']['categories'] = sportal_get_categories(); if (empty($context['article']['categories'])) { fatal_lang_error('error_sp_no_category', false); } // Page out values $context['is_new'] = $this->_is_new; $context['article']['body'] = sportal_parse_content($context['article']['body'], $context['article']['type'], 'return'); $context['page_title'] = $this->_is_new ? $txt['sp_admin_articles_add'] : $txt['sp_admin_articles_edit']; $context['sub_template'] = 'articles_edit'; }
/** * 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'; }