';
do_action('asgarosforum_content_top');
do_action('asgarosforum_'.$this->current_view.'_custom_content_top');
// Show Header Area except for single posts.
if ($this->current_view !== 'post') {
$this->showHeader();
do_action('asgarosforum_content_header');
}
if (!empty($this->error)) {
echo '
'.$this->error.'
';
} else {
if ($this->current_view === 'post') {
$this->showSinglePost();
} else {
$this->render_notices();
$this->showMainTitleAndDescription();
switch ($this->current_view) {
case 'search':
$this->search->show_search_results();
break;
case 'subscriptions':
$this->notifications->show_subscription_overview();
break;
case 'movetopic':
$this->showMoveTopic();
break;
case 'forum':
$this->show_forum();
break;
case 'topic':
$this->showTopic();
break;
case 'addtopic':
case 'addpost':
case 'editpost':
$this->editor->showEditor($this->current_view);
break;
case 'profile':
$this->profile->showProfile();
break;
case 'history':
$this->profile->show_history();
break;
case 'members':
$this->memberslist->show_memberslist();
break;
case 'activity':
$this->activity->show_activity();
break;
case 'unread':
$this->unread->show_unread_topics();
break;
case 'unapproved':
$this->approval->show_unapproved_topics();
break;
case 'reports':
$this->reports->show_reports();
break;
default:
$this->overview();
break;
}
// Action hook for optional bottom navigation elements.
echo '
';
do_action('asgarosforum_after_topic');
}
// Renders all subforums inside of a category/forum combination.
function render_subforums($category_id, $forum_id) {
$subforums = $this->get_forums($category_id, $forum_id);
if (!empty($subforums)) {
echo '
';
foreach ($subforums as $forum) {
require('views/forum-element.php');
}
echo '
';
}
}
function showTopic() {
// Create a unique slug for this topic if necessary.
$topic = $this->content->get_topic($this->current_topic);
if (empty($topic->slug)) {
$slug = $this->rewrite->create_unique_slug($topic->name, $this->tables->topics, 'topic');
$this->db->update($this->tables->topics, array('slug' => $slug), array('id' => $topic->id), array('%s'), array('%d'));
}
// Get posts of topic.
$posts = $this->get_posts();
if ($posts) {
$this->incrementTopicViews();
require('views/topic.php');
} else {
$this->render_notice(__('Sorry, but there are no posts.', 'asgaros-forum'));
}
}
public function incrementTopicViews() {
if ($this->options['count_topic_views']) {
$this->db->query($this->db->prepare("UPDATE {$this->tables->topics} SET views = views + 1 WHERE id = %d", $this->current_topic));
}
}
function showMoveTopic() {
if ($this->permissions->isModerator('current')) {
$strOUT = '';
echo $strOUT;
} else {
$this->render_notice(__('You are not allowed to move topics.', 'asgaros-forum'));
}
}
function get_category_name($category_id) {
$category = get_term($category_id, 'asgarosforum-category');
if ($category) {
return $category->name;
} else {
return false;
}
}
var $topic_counters_cache = false;
function get_topic_counters() {
// If the cache is not set yet, create it.
if ($this->topic_counters_cache === false) {
// Get all topic-counters of each forum first.
$topic_counters = $this->db->get_results("SELECT parent_id AS forum_id, COUNT(*) AS topic_counter FROM {$this->tables->topics} WHERE approved = 1 GROUP BY parent_id;");
// Assign topic-counter for each forum.
if (!empty($topic_counters)) {
foreach ($topic_counters as $counter) {
$this->topic_counters_cache[$counter->forum_id] = $counter->topic_counter;
}
}
// Now get all subforums.
$subforums = $this->content->get_all_subforums();
// Re-assign topic-counter for each forum based on the topic-counters in its subforums.
if (!empty($subforums)) {
foreach ($subforums as $subforum) {
// Continue if the subforum has no topics.
if (!isset($this->topic_counters_cache[$subforum->id])) {
continue;
}
// Re-assign value when the parent-forum has no topics.
if (!isset($this->topic_counters_cache[$subforum->parent_forum])) {
$this->topic_counters_cache[$subforum->parent_forum] = $this->topic_counters_cache[$subforum->id];
continue;
}
// Otherwise add subforum-topics to the counter of the parent forum.
$this->topic_counters_cache[$subforum->parent_forum] = ($this->topic_counters_cache[$subforum->parent_forum] + $this->topic_counters_cache[$subforum->id]);
}
}
}
return $this->topic_counters_cache;
}
function get_forum_topic_counter($forum_id) {
$counters = $this->get_topic_counters();
if (isset($counters[$forum_id])) {
return intval($counters[$forum_id]);
} else {
return 0;
}
}
var $post_counters_cache = false;
function get_post_counters() {
// If the cache is not set yet, create it.
if ($this->post_counters_cache === false) {
// Get all post-counters of each forum first.
$post_counters = $this->db->get_results("SELECT t.parent_id AS forum_id, COUNT(*) AS post_counter FROM {$this->tables->posts} AS p, {$this->tables->topics} AS t WHERE p.parent_id = t.id AND t.approved = 1 GROUP BY t.parent_id;");
// Assign post-counter for each forum.
if (!empty($post_counters)) {
foreach ($post_counters as $counter) {
$this->post_counters_cache[$counter->forum_id] = $counter->post_counter;
}
}
// Now get all subforums.
$subforums = $this->content->get_all_subforums();
// Re-assign post-counter for each forum based on the post-counters in its subforums.
if (!empty($subforums)) {
foreach ($subforums as $subforum) {
// Continue if the subforum has no posts.
if (!isset($this->post_counters_cache[$subforum->id])) {
continue;
}
// Re-assign value when the parent-forum has no posts.
if (!isset($this->post_counters_cache[$subforum->parent_forum])) {
$this->post_counters_cache[$subforum->parent_forum] = $this->post_counters_cache[$subforum->id];
continue;
}
// Otherwise add subforum-posts to the counter of the parent forum.
$this->post_counters_cache[$subforum->parent_forum] = ($this->post_counters_cache[$subforum->parent_forum] + $this->post_counters_cache[$subforum->id]);
}
}
}
return $this->post_counters_cache;
}
function get_forum_post_counter($forum_id) {
$counters = $this->get_post_counters();
if (isset($counters[$forum_id])) {
return intval($counters[$forum_id]);
} else {
return 0;
}
}
function get_forums($id = false, $parent_forum = 0, $output_type = OBJECT) {
if ($id) {
$query_count_subforums = "SELECT COUNT(*) FROM {$this->tables->forums} WHERE parent_forum = f.id";
return $this->db->get_results($this->db->prepare("SELECT f.*, ({$query_count_subforums}) AS count_subforums FROM {$this->tables->forums} AS f WHERE f.parent_id = %d AND f.parent_forum = %d ORDER BY f.sort ASC;", $id, $parent_forum), $output_type);
}
}
function getSpecificForums($ids) {
$results = $this->db->get_results("SELECT id, parent_id AS category_id, name FROM {$this->tables->forums} WHERE id IN (".implode(',', $ids).") ORDER BY id ASC;");
return $results;
}
function getSpecificTopics($ids) {
$results = $this->db->get_results("SELECT t.id, f.parent_id AS category_id, t.name FROM {$this->tables->topics} AS t LEFT JOIN {$this->tables->forums} AS f ON (f.id = t.parent_id) WHERE t.id IN (".implode(',', $ids).") ORDER BY t.id ASC;");
return $results;
}
function get_posts() {
$start = $this->current_page * $this->options['posts_per_page'];
$end = $this->options['posts_per_page'];
$order = apply_filters('asgarosforum_filter_get_posts_order', 'p1.id ASC');
$results = $this->db->get_results($this->db->prepare("SELECT p1.id, p1.text, p1.date, p1.date_edit, p1.author_id, p1.author_edit, (SELECT COUNT(*) FROM {$this->tables->posts} AS p2 WHERE p2.author_id = p1.author_id) AS author_posts, p1.uploads FROM {$this->tables->posts} AS p1 WHERE p1.parent_id = %d ORDER BY {$order} LIMIT %d, %d;", $this->current_topic, $start, $end));
$results = apply_filters('asgarosforum_filter_get_posts', $results);
return $results;
}
private $is_first_post_cache = array();
function is_first_post($post_id, $topic_id = false) {
// When we dont know the topic-id, we need to figure it out.
if (!$topic_id) {
// Check if there exists an current-topic-id.
if ($this->current_topic) {
$topic_id = $this->current_topic;
}
}
if (empty($this->is_first_post_cache[$topic_id])) {
$this->is_first_post_cache[$topic_id] = $this->db->get_var("SELECT id FROM {$this->tables->posts} WHERE parent_id = {$topic_id} ORDER BY id ASC LIMIT 1;");
}
if ($post_id == $this->is_first_post_cache[$topic_id]) {
return true;
} else {
return false;
}
}
function cut_string($string, $length = 33) {
if (strlen($string) > $length) {
return mb_substr($string, 0, $length, 'UTF-8') . ' …';
}
return $string;
}
// TODO: Clean up the complete username logic ...
function get_plain_username($user_id) {
if ($user_id) {
$user = get_userdata($user_id);
if ($user) {
return $user->display_name;
} else {
return __('Deleted user', 'asgaros-forum');
}
} else {
return __('Guest', 'asgaros-forum');
}
}
/**
* Returns and caches a username.
*/
var $cacheGetUsername = array();
function getUsername($user_id) {
if ($user_id) {
if (empty($this->cacheGetUsername[$user_id])) {
$user = get_userdata($user_id);
if ($user) {
$this->cacheGetUsername[$user_id] = $this->renderUsername($user);
} else {
$this->cacheGetUsername[$user_id] = __('Deleted user', 'asgaros-forum');
}
}
return $this->cacheGetUsername[$user_id];
} else {
return __('Guest', 'asgaros-forum');
}
}
/**
* Renders a username.
*/
function renderUsername($userObject, $custom_name = false) {
$user_name = $userObject->display_name;
if ($custom_name) {
$user_name = $custom_name;
}
$renderedUserName = $user_name;
$profileLink = $this->profile->getProfileLink($userObject);
if ($profileLink) {
$renderedUserName = ''.$user_name.'';;
} else {
$renderedUserName = $user_name;
}
$renderedUserName = $this->highlight_username($userObject, $renderedUserName);
return $renderedUserName;
}
/**
* Highlights a username when he is an administrator/moderator.
*/
function highlight_username($user, $string) {
if ($this->options['highlight_admin']) {
if ($this->permissions->isAdministrator($user->ID)) {
return ''.$string.'';
} else if ($this->permissions->isModerator($user->ID)) {
return ''.$string.'';
}
}
return $string;
}
private $lastpost_forum_cache = false;
function lastpost_forum_cache() {
if ($this->lastpost_forum_cache === false) {
// Get all lastpost-elements of each forum first. Selection on topics is needed here because we only want posts of approved topics.
$lastpost_elements = $this->db->get_results("SELECT t.parent_id AS forum_id, MAX(p.id) AS id FROM {$this->tables->posts} AS p, {$this->tables->topics} AS t WHERE p.parent_id = t.id AND t.approved = 1 GROUP BY t.parent_id;");
// Assign lastpost-ids for each forum.
if (!empty($lastpost_elements)) {
foreach ($lastpost_elements as $element) {
$this->lastpost_forum_cache[$element->forum_id] = $element->id;
}
}
// Now get all subforums.
$subforums = $this->content->get_all_subforums();
// Re-assign lastpost-ids for each forum based on the lastposts in its subforums.
if (!empty($subforums)) {
foreach ($subforums as $subforum) {
// Continue if the subforum has no posts.
if (!isset($this->lastpost_forum_cache[$subforum->id])) {
continue;
}
// Re-assign value when the parent-forum has no posts.
if (!isset($this->lastpost_forum_cache[$subforum->parent_forum])) {
$this->lastpost_forum_cache[$subforum->parent_forum] = $this->lastpost_forum_cache[$subforum->id];
}
// Otherwise re-assign value when a subforum has a more recent post.
if ($this->lastpost_forum_cache[$subforum->id] > $this->lastpost_forum_cache[$subforum->parent_forum]) {
$this->lastpost_forum_cache[$subforum->parent_forum] = $this->lastpost_forum_cache[$subforum->id];
}
}
}
}
}
private $get_lastpost_in_forum_cache = array();
function get_lastpost_in_forum($forum_id) {
if (!isset($this->get_lastpost_in_forum_cache[$forum_id])) {
$this->lastpost_forum_cache();
if (isset($this->lastpost_forum_cache[$forum_id])) {
$this->get_lastpost_in_forum_cache[$forum_id] = $this->db->get_row("SELECT p.id, p.date, p.parent_id, p.author_id, t.name FROM {$this->tables->posts} AS p, {$this->tables->topics} AS t WHERE p.id = ".$this->lastpost_forum_cache[$forum_id]." AND t.id = p.parent_id;");
} else {
$this->get_lastpost_in_forum_cache[$forum_id] = false;
}
}
return $this->get_lastpost_in_forum_cache[$forum_id];
}
function render_lastpost_in_forum($forum_id, $compact = false) {
$lastpost = $this->get_lastpost_in_forum($forum_id);
if ($lastpost === false) {
return ''.__('No topics yet!', 'asgaros-forum').'';
} else {
$output = '';
$post_link = $this->rewrite->get_post_link($lastpost->id, $lastpost->parent_id);
if ($compact === true) {
$output .= __('Last post:', 'asgaros-forum');
$output .= ' ';
$output .= ''.esc_html($this->cut_string(stripslashes($lastpost->name), 34)).'';
$output .= ' · ';
$output .= ''.sprintf(__('%s ago', 'asgaros-forum'), human_time_diff(strtotime($lastpost->date), current_time('timestamp'))).'';
$output .= ' · ';
$output .= $this->getUsername($lastpost->author_id);
} else {
// Avatar
if ($this->options['enable_avatars']) {
$output .= '
';
}
return $output;
}
function get_topic_starter($topic_id) {
return $this->db->get_var($this->db->prepare("SELECT author_id FROM {$this->tables->posts} WHERE parent_id = %d ORDER BY id ASC LIMIT 1;", $topic_id));
}
function format_date($date, $full = true) {
if ($full) {
return date_i18n($this->date_format.', '.$this->time_format, strtotime($date));
} else {
return date_i18n($this->date_format, strtotime($date));
}
}
function current_time() {
return current_time('Y-m-d H:i:s');
}
function get_post_author($post_id) {
return $this->db->get_var($this->db->prepare("SELECT author_id FROM {$this->tables->posts} WHERE id = %d;", $post_id));
}
function get_post_date($post_id) {
return $this->db->get_var($this->db->prepare("SELECT `date` FROM {$this->tables->posts} WHERE id = %d;", $post_id));
}
// Returns the topics created by a user.
function countTopicsByUser($user_id) {
return $this->db->get_var("SELECT COUNT(*) FROM {$this->tables->posts} WHERE id IN (SELECT MIN(id) FROM {$this->tables->posts} GROUP BY parent_id) AND author_id = {$user_id};");
}
function countPostsByUser($userID) {
return $this->db->get_var("SELECT COUNT(*) FROM {$this->tables->posts} WHERE author_id = {$userID};");
}
/**
* Generating menus for forums, topics and posts.
*/
function showForumMenu() {
$menu = '';
if ($this->forumIsOpen()) {
if ((is_user_logged_in() && !$this->permissions->isBanned('current')) || (!is_user_logged_in() && $this->options['allow_guest_postings'])) {
// New topic button.
$menu .= '
';
}
}
$menu = apply_filters('asgarosforum_filter_forum_menu', $menu);
return $menu;
}
public function render_sticky_panel() {
// Cancel if the current user is not at least a moderator.
if (!$this->permissions->isModerator('current')) {
return;
}
echo '
';
$this->breadcrumbs->show_breadcrumbs();
}
function showLogoutLink() {
if (is_user_logged_in() && $this->options['show_logout_button']) {
echo ''.__('Logout', 'asgaros-forum').'';
}
}
function showLoginLink() {
if (!is_user_logged_in() && $this->options['show_login_button']) {
echo ''.__('Login', 'asgaros-forum').'';
}
}
function showRegisterLink() {
if (!is_user_logged_in() && $this->options['show_register_button']) {
echo ''.__('Register', 'asgaros-forum').'';
}
}
function delete_topic($topic_id, $admin_action = false, $permission_check = true) {
// Cancel when no topic is given.
if (!$topic_id) {
return false;
}
// Cancel when topic does not exist.
if (!$this->content->topic_exists($topic_id)) {
return false;
}
// Cancel if user cannot delete topic.
if ($permission_check) {
$user_id = get_current_user_id();
if (!$this->permissions->can_delete_topic($user_id, $topic_id)) {
return false;
}
}
// Continue ...
do_action('asgarosforum_before_delete_topic', $topic_id);
// Delete posts.
$posts = $this->db->get_col($this->db->prepare("SELECT id FROM {$this->tables->posts} WHERE parent_id = %d;", $topic_id));
foreach ($posts as $post) {
$this->remove_post($post, false);
}
// Delete topic.
$this->db->delete($this->tables->topics, array('id' => $topic_id), array('%d'));
$this->notifications->remove_all_topic_subscriptions($topic_id);
do_action('asgarosforum_after_delete_topic', $topic_id);
if (!$admin_action) {
wp_redirect(html_entity_decode($this->get_link('forum', $this->current_forum)));
exit;
}
}
function moveTopic() {
$newForumID = $_POST['newForumID'];
if ($this->permissions->isModerator('current') && $newForumID && $this->content->forum_exists($newForumID)) {
$this->db->update($this->tables->topics, array('parent_id' => $newForumID), array('id' => $this->current_topic), array('%d'), array('%d'));
$this->db->update($this->tables->posts, array('forum_id' => $newForumID), array('parent_id' => $this->current_topic), array('%d'), array('%d'));
wp_redirect(html_entity_decode($this->get_link('topic', $this->current_topic)));
exit;
}
}
function remove_post($post_id, $permission_check = true) {
// Cancel if no post is given.
if (!$post_id) {
return false;
}
// Cancel if post does not exist.
if (!$this->content->post_exists($post_id)) {
return false;
}
// Cancel if user cannot delete post.
if ($permission_check) {
$user_id = get_current_user_id();
if (!$this->permissions->can_delete_post($user_id, $post_id)) {
return false;
}
}
// Delete post.
do_action('asgarosforum_before_delete_post', $post_id);
$this->uploads->delete_post_files($post_id);
$this->reports->remove_report($post_id, false);
$this->reactions->remove_all_reactions($post_id);
$this->db->delete($this->tables->posts, array('id' => $post_id), array('%d'));
do_action('asgarosforum_after_delete_post', $post_id);
}
function change_status($property) {
if ($this->permissions->isModerator('current')) {
if ($property == 'closed') {
$this->db->update($this->tables->topics, array('closed' => 1), array('id' => $this->current_topic), array('%d'), array('%d'));
} else if ($property == 'open') {
$this->db->update($this->tables->topics, array('closed' => 0), array('id' => $this->current_topic), array('%d'), array('%d'));
}
}
}
function set_sticky($topic_id, $sticky_mode) {
if (!$this->permissions->isModerator('current')) {
return;
}
// Ensure that only correct values can get set.
switch ($sticky_mode) {
case 0:
case 1:
case 2:
$this->db->update($this->tables->topics, array('sticky' => $sticky_mode), array('id' => $topic_id), array('%d'), array('%d'));
break;
}
}
function is_topic_sticky($topic_id) {
$status = $this->db->get_var("SELECT sticky FROM {$this->tables->topics} WHERE id = {$topic_id};");
if (intval($status) > 0) {
return true;
} else {
return false;
}
}
private $is_topic_closed_cache = array();
function is_topic_closed($topic_id) {
if (!isset($this->is_topic_closed_cache[$topic_id])) {
$status = $this->db->get_var("SELECT closed FROM {$this->tables->topics} WHERE id = {$topic_id};");
if (intval($status) === 1) {
$this->is_topic_closed_cache[$topic_id] = true;
} else {
$this->is_topic_closed_cache[$topic_id] = false;
}
}
return $this->is_topic_closed_cache[$topic_id];
}
// Returns TRUE if the forum is opened or the user has at least moderator rights.
function forumIsOpen() {
if (!$this->permissions->isModerator('current')) {
$closed = intval($this->db->get_var($this->db->prepare("SELECT closed FROM {$this->tables->forums} WHERE id = %d;", $this->current_forum)));
if ($closed === 1) {
return false;
}
}
return true;
}
// Builds and returns a requested link.
public function get_link($type, $elementID = false, $additionalParameters = false, $appendix = '', $escapeURL = true) {
return $this->rewrite->get_link($type, $elementID, $additionalParameters, $appendix, $escapeURL);
}
// Checks if an element exists and sets all parent IDs based on the given id and its content type.
public function setParents($id, $contentType) {
// Set possible error messages.
$error = array();
$error['post'] = __('Sorry, this post does not exist.', 'asgaros-forum');
$error['topic'] = __('Sorry, this topic does not exist.', 'asgaros-forum');
$error['forum'] = __('Sorry, this forum does not exist.', 'asgaros-forum');
if ($id) {
$query = '';
$results = false;
// Build the query.
switch ($contentType) {
case 'post':
$query = "SELECT f.parent_id AS current_category, f.id AS current_forum, f.name AS current_forum_name, f.parent_forum AS parent_forum, pf.name AS parent_forum_name, t.id AS current_topic, t.name AS current_topic_name, p.id AS current_post, p.text AS current_description FROM {$this->tables->forums} AS f LEFT JOIN {$this->tables->forums} AS pf ON (pf.id = f.parent_forum) LEFT JOIN {$this->tables->topics} AS t ON (f.id = t.parent_id) LEFT JOIN {$this->tables->posts} AS p ON (t.id = p.parent_id) WHERE p.id = {$id};";
break;
case 'topic':
$query = "SELECT f.parent_id AS current_category, f.id AS current_forum, f.name AS current_forum_name, f.parent_forum AS parent_forum, pf.name AS parent_forum_name, t.id AS current_topic, t.name AS current_topic_name, (SELECT td.text FROM {$this->tables->posts} AS td WHERE td.parent_id = t.id ORDER BY td.id ASC LIMIT 1) AS current_description FROM {$this->tables->forums} AS f LEFT JOIN {$this->tables->forums} AS pf ON (pf.id = f.parent_forum) LEFT JOIN {$this->tables->topics} AS t ON (f.id = t.parent_id) WHERE t.id = {$id};";
break;
case 'forum':
$query = "SELECT f.parent_id AS current_category, f.id AS current_forum, f.name AS current_forum_name, f.parent_forum AS parent_forum, pf.name AS parent_forum_name, f.description AS current_description FROM {$this->tables->forums} AS f LEFT JOIN {$this->tables->forums} AS pf ON (pf.id = f.parent_forum) WHERE f.id = {$id};";
break;
}
$results = $this->db->get_row($query);
// When the element exists, set parents and exit function.
if ($results) {
$this->current_description = ($contentType === 'post' || $contentType === 'topic' || $contentType === 'forum') ? $this->cut_string(str_replace(array("\r", "\n"), '', esc_html(strip_tags($results->current_description))), 155) : false;
$this->current_category = ($contentType === 'post' || $contentType === 'topic' || $contentType === 'forum') ? $results->current_category : false;
$this->parent_forum = ($contentType === 'post' || $contentType === 'topic' || $contentType === 'forum') ? $results->parent_forum : false;
$this->parent_forum_name = ($contentType === 'post' || $contentType === 'topic' || $contentType === 'forum') ? $results->parent_forum_name : false;
$this->current_forum = ($contentType === 'post' || $contentType === 'topic' || $contentType === 'forum') ? $results->current_forum : false;
$this->current_forum_name = ($contentType === 'post' || $contentType === 'topic' || $contentType === 'forum') ? $results->current_forum_name : false;
$this->current_topic = ($contentType === 'post' || $contentType === 'topic') ? $results->current_topic : false;
$this->current_topic_name = ($contentType === 'post' || $contentType === 'topic') ? $results->current_topic_name : false;
$this->current_post = ($contentType === 'post') ? $results->current_post : false;
$this->parents_set = true;
return;
}
}
// Assign error message, because when this location is reached, no parents has been set.
$this->error = $error[$contentType];
}
public function createBlogTopic($new_status, $old_status, $post) {
if ($post->post_type == 'post' && $new_status == 'publish' && $old_status != 'publish') {
$forumID = $this->options['create_blog_topics_id'];
$post_title = apply_filters('asgarosforum_filter_automatic_topic_title', $post->post_title, $post);
$post_content = apply_filters('asgarosforum_filter_automatic_topic_content', $post->post_content, $post);
if ($this->content->forum_exists($forumID)) {
$this->content->insert_topic($forumID, $post_title, $post_content, $post->post_author);
}
}
}
// Returns the amount of users.
public function count_users() {
return $this->db->get_var("SELECT COUNT(u.ID) FROM {$this->db->users} u");
}
// Prevents oembed dataparsing for links which points to the own forum.
function prevent_oembed_dataparse($return, $data, $url) {
$url_check = strpos($url, $this->rewrite->get_link('home'));
if ($url_check !== false) {
return $url;
}
return $return;
}
public function create_file($path, $content) {
// Create binding for the file first.
$binding = @fopen($path, 'wb');
// Check if the binding could get created.
if ($binding) {
// Write the content to the file.
$writing = @fwrite($binding, $content);
// Close the file.
fclose($binding);
// Clear stat cache so we can set the correct permissions.
clearstatcache();
// Get information about the file.
$file_stats = @stat(dirname($path));
// Update the permissions of the file.
$file_permissions = $file_stats['mode'] & 0007777;
$file_permissions = $file_permissions & 0000666;
@chmod($path, $file_permissions);
// Clear stat cache again so PHP is aware of the new permissions.
clearstatcache();
return true;
}
return false;
}
public function read_file($path) {
// Create binding for the file first.
$binding = @fopen($path, 'r');
// Check if the binding could get created.
if ($binding) {
// Ensure that the file is not empty.
$file_size = @filesize($path);
if (isset($file_size) && $file_size > 0) {
// Read the complete file.
$file_data = fread($binding, $file_size);
// Close the file.
fclose($binding);
// Return the file data.
return $file_data;
}
}
return false;
}
public function delete_file($path) {
if (file_exists($path)) {
unlink($path);
}
}
public function delete_user_form_reassign($current_user, $userids) {
// Remove own ID from users which should get deleted.
$userids = array_diff($userids, array($current_user->ID));
// Cancel if there are no users to delete.
if (empty($userids)) {
return;
}
// Check if users have posts.
$users_have_content = false;
if ($this->db->get_var("SELECT ID FROM {$this->tables->posts} WHERE author_id IN(".implode(',', $userids).") LIMIT 1;")) {
$users_have_content = true;
}
// Cancel if users have no posts.
if ($users_have_content === false) {
return;
}
// Show reassign-options.
echo '
'.__('Forum', 'asgaros-forum').'
';
echo '';
}
public function deleted_user_reassign($id, $reassign) {
// Ensure that correct values are passed.
if (empty($_POST['forum_reassign'])) {
return;
}
if ($_POST['forum_reassign'] != 'yes') {
return;
}
if (empty($_POST['forum_reassign_user'])) {
return;
}
// Reassign forum posts.
$this->db->update($this->tables->posts, array('author_id' => $_POST['forum_reassign_user']), array('author_id' => $id), array('%d'), array('%d'));
}
// Extract the first URL of an image from a given string.
public function extract_image_url($content) {
$images = array();
// Check if content is given.
if ($content) {
// Try to find images.
preg_match_all('#https?://[^\s\'\"<>]+\.(?:jpg|jpeg|png|gif)#isu', $content, $found, PREG_SET_ORDER);
if (empty($found)) {
preg_match_all('#//[^\s\'\"<>]+\.(?:jpg|jpeg|png|gif)#isu', $content, $found, PREG_SET_ORDER);
}
if (empty($found)) {
preg_match_all('#https?://[^\s\'\"<>]+#isu', $content, $found, PREG_SET_ORDER);
}
if (empty($found)) {
preg_match_all('#//[^\s\'\"<>]+#isu', $content, $found, PREG_SET_ORDER);
}
// If images found, check extensions.
if (!empty($found)) {
foreach ($found as $match) {
$extension = pathinfo($match[0], PATHINFO_EXTENSION);
if ($extension) {
$check = false;
$extension = strtolower($extension);
if ($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png' || $extension == 'gif') {
$check = true;
}
if ($check) {
$images[] = $match[0];
break;
}
}
}
}
}
if (empty($images)) {
return false;
} else {
return $images[0];
}
}
// Tries to get the signature for a given user.
public function get_signature($user_id) {
// Ensure signatures are enabled.
if (!$this->options['allow_signatures']) {
return false;
}
// Ensure that the user has the permission to use a signature.
if (!$this->permissions->can_use_signature($user_id)) {
return false;
}
// Try to get signature.
$signature = get_user_meta($user_id, 'asgarosforum_signature', true);
// Prepare signature based on settings.
if ($this->options['signatures_html_allowed']) {
$signature = strip_tags($signature, $this->options['signatures_html_tags']);
} else {
$signature = esc_html(strip_tags($signature));
}
// Trim it.
$signature = trim($signature);
// Ensure signature is not empty.
if (empty($signature)) {
return false;
}
return $signature;
}
}