private function __construct() { // Determine with the user ID if the user is logged in. self::$userID = get_current_user_id(); // Generate link for mark all forums read. self::$markAllReadLink = esc_url(add_query_arg(array('view' => 'markallread'), get_permalink())); // Initialize data. For guests we use a cookie as source, otherwise use database. if (self::$userID) { // Create database entry when it does not exist. if (!get_user_meta(self::$userID, 'asgarosforum_unread_cleared', true)) { add_user_meta(self::$userID, 'asgarosforum_unread_cleared', '0000-00-00 00:00:00'); } // Get IDs of excluded topics. self::$excludedItems = get_user_meta(self::$userID, 'asgarosforum_unread_exclude', true); } else { // Create a cookie when it does not exist. if (!isset($_COOKIE['asgarosforum_unread_cleared'])) { // There is no cookie set so basically the forum has never been visited. setcookie('asgarosforum_unread_cleared', '0000-00-00 00:00:00', 2147483647); } // Get IDs of excluded topics. if (isset($_COOKIE['asgarosforum_unread_exclude'])) { self::$excludedItems = maybe_unserialize($_COOKIE['asgarosforum_unread_exclude']); } } }
if (!defined('ABSPATH')) { exit; } ?> <div class="thread <?php echo $elementMarker; ?> "> <?php $lastpost_data = $this->get_lastpost_in_thread($thread->id); ?> <div class="thread-status"> <?php $unreadStatus = AsgarosForumUnread::getStatusThread($thread->id); echo '<span class="dashicons-before dashicons-' . $thread->status . $unreadStatus . '"></span>'; ?> </div> <div class="thread-name"> <strong><a href="<?php echo $this->getLink('topic', $thread->id); ?> " title="<?php echo esc_html(stripslashes($thread->name)); ?> "><?php echo esc_html(stripslashes($thread->name)); ?> </a></strong> <small><?php
} echo '<h1 class="main-title">' . __('Forum', 'asgaros-forum') . '</h1>'; if ($categories) { $forumsAvailable = false; foreach ($categories as $category) { echo '<div class="title-element" id="forum-category-' . $category->term_id . '">'; echo $category->name; echo '<span class="last-post-headline">' . __('Last post:', 'asgaros-forum') . '</span>'; echo '</div>'; echo '<div class="content-element">'; $forums = $this->get_forums($category->term_id); if (empty($forums)) { echo '<div class="notice">' . __('In this category are no forums yet!', 'asgaros-forum') . '</div>'; } else { $elementMarker = ''; $forumsCounter = 0; foreach ($forums as $forum) { $forumsAvailable = true; $forumsCounter++; $elementMarker = $forumsCounter & 1 ? 'odd' : 'even'; require 'forum-element.php'; } } echo '</div>'; } if ($forumsAvailable) { AsgarosForumUnread::showUnreadControls(); } } else { echo '<div class="notice">' . __('There are no categories yet!', 'asgaros-forum') . '</div>'; }
<?php if (!defined('ABSPATH')) { exit; } $lastpost_data = $this->get_lastpost_in_forum($forum->id); echo '<div class="forum ' . $elementMarker . '" id="forum-' . $forum->id . '">'; echo '<div class="forum-status">'; $unreadStatus = AsgarosForumUnread::getStatusForum($forum->id); echo '<span class="dashicons-before dashicons-overview' . $unreadStatus . '"></span>'; echo '</div>'; echo '<div class="forum-name">'; echo '<strong><a href="' . $this->getLink('forum', $forum->id) . '">' . esc_html(stripslashes($forum->name)) . '</a></strong>'; echo '<small>' . esc_html(stripslashes($forum->description)) . '</small>'; // Show subforums. if ($forum->count_subforums > 0) { echo '<small class="forum-subforums">'; echo '<b>' . __('Subforums', 'asgaros-forum') . ':</b> '; $subforums = $this->get_forums($category->term_id, $forum->id); $subforumsFirstDone = false; foreach ($subforums as $subforum) { echo $subforumsFirstDone ? ' · ' : ''; echo '<a href="' . $this->getLink('forum', $subforum->id) . '">' . esc_html(stripslashes($subforum->name)) . '</a>'; $subforumsFirstDone = true; } echo '</small>'; } echo '</div>'; echo '<div class="forum-stats">'; echo '<small>' . sprintf(_n('%s Topic', '%s Topics', $forum->count_threads, 'asgaros-forum'), $forum->count_threads) . '</small>'; echo '<small>' . sprintf(_n('%s Post', '%s Posts', $forum->count_posts, 'asgaros-forum'), $forum->count_posts) . '</small>';
function prepare() { global $post; if (is_a($post, 'WP_Post') && $this->checkForShortcode($post)) { $this->executePlugin = true; $this->options['location'] = $post->ID; } // Set all base links. if ($this->executePlugin || get_post($this->options['location'])) { $this->setLinks(); } if (!$this->executePlugin) { return; } if (isset($_GET['view'])) { $this->current_view = esc_html($_GET['view']); } if (isset($_GET['part']) && absint($_GET['part']) > 0) { $this->current_page = absint($_GET['part']) - 1; } $elementID = isset($_GET['id']) ? absint($_GET['id']) : false; switch ($this->current_view) { case 'forum': case 'addthread': if ($this->element_exists($elementID, $this->tables->forums)) { $this->current_forum = $elementID; $this->parent_forum = $this->get_parent_id($this->current_forum, $this->tables->forums, 'parent_forum'); $this->current_category = $this->get_parent_id($this->current_forum, $this->tables->forums); } else { $this->error = __('Sorry, this forum does not exist.', 'asgaros-forum'); } break; case 'movetopic': case 'thread': case 'addpost': if ($this->element_exists($elementID, $this->tables->topics)) { $this->current_topic = $elementID; $this->current_forum = $this->get_parent_id($this->current_topic, $this->tables->topics); $this->parent_forum = $this->get_parent_id($this->current_forum, $this->tables->forums, 'parent_forum'); $this->current_category = $this->get_parent_id($this->current_forum, $this->tables->forums); } else { $this->error = __('Sorry, this topic does not exist.', 'asgaros-forum'); } break; case 'editpost': if ($this->element_exists($elementID, $this->tables->posts)) { $this->current_post = $elementID; $this->current_topic = $this->get_parent_id($this->current_post, $this->tables->posts); $this->current_forum = $this->get_parent_id($this->current_topic, $this->tables->topics); $this->parent_forum = $this->get_parent_id($this->current_forum, $this->tables->forums, 'parent_forum'); $this->current_category = $this->get_parent_id($this->current_forum, $this->tables->forums); } else { $this->error = __('Sorry, this post does not exist.', 'asgaros-forum'); } break; case 'search': // Go back to overview when search is not enabled. if (!$this->options['enable_search']) { $this->current_view = 'overview'; } break; default: $this->current_view = 'overview'; break; } // Check $this->check_access(); // Override editor settings. $this->options_editor = apply_filters('asgarosforum_filter_editor_settings', $this->options_editor); // Prevent generation of some head-elements. remove_action('wp_head', 'rel_canonical'); remove_action('wp_head', 'wp_shortlink_wp_head'); remove_action('wp_head', 'wp_oembed_add_discovery_links'); if (isset($_POST['submit_action']) && (is_user_logged_in() || $this->options['allow_guest_postings'])) { if (AsgarosForumInsert::getAction()) { AsgarosForumInsert::setData(); if (AsgarosForumInsert::validateExecution()) { AsgarosForumInsert::insertData(); } } } else { if ($this->current_view === 'markallread') { AsgarosForumUnread::markAllRead(); } else { if (isset($_GET['move_thread'])) { $this->move_thread(); } else { if (isset($_GET['delete_thread'])) { $this->delete_thread($this->current_topic); } else { if (isset($_GET['remove_post'])) { $this->remove_post(); } else { if (isset($_GET['sticky_topic']) || isset($_GET['unsticky_topic'])) { $this->change_status('sticky'); } else { if (isset($_GET['open_topic']) || isset($_GET['close_topic'])) { $this->change_status('closed'); } else { if (isset($_GET['subscribe_topic'])) { AsgarosForumNotifications::subscribeTopic(); } else { if (isset($_GET['unsubscribe_topic'])) { AsgarosForumNotifications::unsubscribeTopic(); } else { if (isset($_GET['subscribe_forum'])) { AsgarosForumNotifications::subscribeForum(); } else { if (isset($_GET['unsubscribe_forum'])) { AsgarosForumNotifications::unsubscribeForum(); } } } } } } } } } } } // Mark visited topic as read. if ($this->current_view === 'thread' && $this->current_topic) { AsgarosForumUnread::markThreadRead(); } }