function __wps__do_Forumrecentposts_Widget($postcount,$preview,$cat_id,$show_replies,$incl_cat,$incl_parent,$just_own) { global $wpdb, $current_user; $user_info = get_user_by('login', 'nobody'); $nobody_id = $user_info ? $user_info->ID : 0; if (!$nobody_id) $nobody_id = 0; // Content of widget $sql = "SELECT t.tid, t.stub, p.stub as parent_stub, p.topic_parent as parent_parent, p.topic_subject as parent_subject, p.topic_category as parent_category, t.topic_subject, t.topic_owner, t.topic_post, t.topic_started, t.topic_category, t.topic_date, u.display_name, t.topic_parent, t.topic_group FROM ".$wpdb->prefix.'symposium_topics'." t INNER JOIN ".$wpdb->base_prefix.'users'." u ON t.topic_owner = u.ID LEFT JOIN ".$wpdb->prefix."symposium_topics p ON t.topic_parent = p.tid WHERE t.topic_approved = 'on' AND (t.topic_parent = 0 || p.topic_parent = 0) "; if ($cat_id != '' && $cat_id > 0) { $sql .= "AND t.topic_category = ".$cat_id." "; } if ($show_replies != 'on') { $sql .= "AND t.topic_parent = 0 "; } if ($just_own == 'on') { $sql .= "AND t.topic_owner = ".$current_user->ID." "; } $sql .= "AND t.topic_owner != %d "; $sql .= "ORDER BY t.tid DESC LIMIT %d,%d"; $posts = $wpdb->get_results($wpdb->prepare($sql, $nobody_id, 0, 100)); $count = 0; $html = ''; if (WPS_DEBUG) $html .= $wpdb->last_query.'<br />'; // Previous login if (is_user_logged_in()) { $previous_login = __wps__get_meta($current_user->ID, 'previous_login'); } // Get URLs worked out $profile_url = __wps__get_url('profile'); $forum_url = __wps__get_url('forum'); $forum_q = __wps__string_query($forum_url); // Get list of roles for this user $user_roles = $current_user->roles; $user_role = strtolower(array_shift($user_roles)); if ($user_role == '') $user_role = 'NONE'; if ($posts) { $html .= "<div id='__wps__latest_forum'>"; foreach ($posts as $post) { if ($post->topic_group == 0 || (__wps__member_of($post->topic_group) == "yes") || ($wpdb->get_var($wpdb->prepare("SELECT content_private FROM ".$wpdb->prefix."symposium_groups WHERE gid = %d", $post->topic_group)) != "on") ) { // Check permitted to see forum category $sql = "SELECT level FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d"; $levels = $wpdb->get_var($wpdb->prepare($sql, $post->topic_category)); $cat_roles = unserialize($levels); if (strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos(strtolower($cat_roles), $user_role.',') !== FALSE) { $html .= "<div class='__wps__latest_forum_row'>"; $html .= "<div class='__wps__latest_forum_row_avatar'>"; $html .= "<a href='".$profile_url.$forum_q."uid=".$post->topic_owner."'>"; $html .= get_avatar($post->topic_owner, 32); $html .= "</a>"; $html .= "</div>"; $html .= "<div class='__wps__latest_forum_row_post'>"; if ($post->topic_parent > 0) { $html .= __wps__profile_link($post->topic_owner); if ($preview > 0) { $text = strip_tags(stripslashes($post->topic_post)); $text = __wps__bbcode_remove($text); if ( strlen($text) > $preview ) { $text = substr($text, 0, $preview)."..."; } if ($post->parent_parent == 0) { $html .= " ".__('replied', WPS_TEXT_DOMAIN); } else { $html .= " ".__('commented', WPS_TEXT_DOMAIN); } if ($text == '') $text = __('(No text)', WPS_TEXT_DOMAIN); if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) { $perma_cat = __wps__get_forum_category_part_url($post->topic_category); $html .= " <a href='".$forum_url.'/'.$perma_cat.$post->parent_stub."'>".$text."</a>"; } else { $html .= " <a href='".$forum_url.$forum_q."cid=".$post->topic_category."&show=".$post->topic_parent."'>".$text."</a>"; } if ($incl_parent) { if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) { $perma_cat = __wps__get_forum_category_part_url($post->parent_category); $html .= ' '.__('to', WPS_TEXT_DOMAIN)." <a href='".$forum_url.'/'.$perma_cat.$post->parent_stub."'>".strip_tags(stripslashes($post->parent_subject))."</a> "; } else { if ($post->parent_parent == 0) { $html .= ' '.__('to', WPS_TEXT_DOMAIN)." <a href='".$forum_url.$forum_q."cid=".$post->parent_category."&show=".$post->topic_parent."'>".strip_tags(stripslashes($post->parent_subject))."</a> "; } } } if ($incl_cat) { if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) { $cat = stripslashes($wpdb->get_var($wpdb->prepare('SELECT title FROM '.$wpdb->prefix.'symposium_cats WHERE cid = %d', $post->parent_category))); $perma_cat = __wps__get_forum_category_part_url($post->parent_category); $html .= ' '.__('in', WPS_TEXT_DOMAIN)." <a href='".$forum_url.'/'.$perma_cat."'>".$cat."</a> "; } else { $html .= ' '.__('in', WPS_TEXT_DOMAIN)." <a href='".$forum_url.$forum_q."cid=".$post->parent_category."'>".$cat."</a> "; } } } else { $html .= "<br />"; } $html .= " ".__wps__time_ago($post->topic_date)."."; } else { $html .= __wps__profile_link($post->topic_owner); if ($preview > 0) { $text = stripslashes($post->topic_subject); $text = __wps__bbcode_remove($text); if ( strlen($text) > $preview ) { $text = substr($text, 0, $preview)."..."; } if ($post->topic_group == 0) { $url = $forum_url; $q = $forum_q; } else { // Get group URL worked out $url = __wps__get_url('group'); if (strpos($url, '?') !== FALSE) { $q = "&gid=".$post->topic_group."&"; } else { $q = "?gid=".$post->topic_group."&"; } } $html .= " ".__('started', WPS_TEXT_DOMAIN); if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) { $perma_cat = __wps__get_forum_category_part_url($post->topic_category); $html .= " <a href='".$url.'/'.$perma_cat.$post->stub."'>".$text."</a>"; } else { $html .= " <a href='".$url.$q."cid=".$post->topic_category."&show=".$post->tid."'>".$text."</a>"; } if ($incl_cat) { if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) { $cat = stripslashes($wpdb->get_var($wpdb->prepare('SELECT title FROM '.$wpdb->prefix.'symposium_cats WHERE cid = %d', $post->topic_category))); $perma_cat = __wps__get_forum_category_part_url($post->topic_category); $html .= ' '.__('in', WPS_TEXT_DOMAIN)." <a href='".$forum_url.'/'.$perma_cat."'>".$cat."</a> "; } else { $html .= ' '.__('in', WPS_TEXT_DOMAIN)." <a href='".$forum_url.$forum_q."cid=".$post->topic_category."'>".$cat."</a> "; } } } $html .= " ".__wps__time_ago($post->topic_started)."."; } if (is_user_logged_in() && get_option(WPS_OPTIONS_PREFIX.'_forum_stars')) { if ($post->topic_date > $previous_login && $post->topic_owner != $current_user->ID) { $html .= " <img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/new.gif' alt='New!' />"; } } $html .= "</div>"; $html .= "</div>"; $count++; if ($count >= $postcount) { break; } } } } $html .= "</div>"; } else { $html .= __('None', WPS_TEXT_DOMAIN); } echo $html; }
} else { if ($mention->parent_topic_group == 0) { $url = __wps__get_url('forum'); $url .= __wps__string_query($url); $url .= 'show='.$mention->parent_id; } else { $url = __wps__get_url('group'); $url .= __wps__string_query($url); $url .= 'gid='.$mention->parent_topic_group.'&cid=0&show='.$mention->parent_id; } } $pre_text = __('Replied to', WPS_TEXT_DOMAIN).' '; $text = $mention->parent_text; } else { if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $mention->topic_group == 0) { $perma_cat = __wps__get_forum_category_part_url($mention->topic_category); $url = __wps__get_url('forum').'/'.$perma_cat.$mention->stub; } else { if ($mention->topic_group == 0) { $url = __wps__get_url('forum'); $url .= __wps__string_query($url); $url .= 'show='.$mention->id; } else { $url = __wps__get_url('group'); $url .= __wps__string_query($url); $url .= 'gid='.$mention->topic_group.'&cid=0&show='.$mention->id; } } $pre_text = __('Started', WPS_TEXT_DOMAIN).' '; $text = $mention->text; }
function symposium_forum_latestposts_showThreadChildren($count, $cat_id, $parent, $level, $use_answers) { global $wpdb, $current_user; $thispage = __wps__get_url('forum'); if ($thispage[strlen($thispage)-1] != '/') { $thispage .= '/'; } $q = __wps__string_query($thispage); $symposium_last_login = __wps__get_meta($current_user->ID, 'symposium_last_login'); $html = ""; $preview = 30; if ($count != '') { $postcount = $count; } else { $postcount = get_option(WPS_OPTIONS_PREFIX.'_symposium_forumlatestposts_count'); } if ($level == 0) { $avatar_size = 30; $margin_top = 10; $desc = "DESC"; } else { $avatar_size = 20; $margin_top = 6; $desc = "DESC"; } // All topics started $cat_sql = ($cat_id) ? " AND t.topic_category = ".$cat_id : ''; $posts = $wpdb->get_results(" SELECT t.tid, t.topic_subject, t.stub, p.stub as parent_stub, t.topic_owner, t.topic_post, t.topic_category, t.topic_started, u.display_name, t.topic_parent, t.topic_answer, t.topic_date, t.topic_approved FROM ".$wpdb->prefix.'symposium_topics'." t INNER JOIN ".$wpdb->base_prefix.'users'." u ON t.topic_owner = u.ID LEFT JOIN ".$wpdb->prefix.'symposium_topics'." p ON t.topic_parent = p.tid WHERE t.topic_parent = ".$parent." AND t.topic_group = 0".$cat_sql." ORDER BY t.tid ".$desc." LIMIT 0,".$postcount); if ($posts) { foreach ($posts as $post) { if ( ($post->topic_approved == 'on') || ($post->topic_approved != 'on' && ($post->topic_owner == $current_user->ID || current_user_can('level_10'))) ) { $padding_left = ($level == 0) ? 40 : 30; $html .= "<div class='__wps__latest_forum_row' style='padding-left: ".$padding_left."px; margin-left: ".($level*40)."px; margin-top:".$margin_top."px;'>"; $html .= "<div class='__wps__latest_forum_row_avatar'>"; $html .= get_avatar($post->topic_owner, $avatar_size); $html .= "</div>"; $html .= "<div style='float:left'>"; if ($post->topic_parent > 0) { $text = strip_tags(stripslashes($post->topic_post)); if ( strlen($text) > $preview ) { $text = substr($text, 0, $preview)."..."; } $reply_text = $level == 1 ? 'replied' : 'commented'; $html .= __wps__profile_link($post->topic_owner)." ".__($reply_text, WPS_TEXT_DOMAIN)." "; if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) { $perma_cat = __wps__get_forum_category_part_url($post->topic_category); $html .= "<a title='".$text."' href='".$thispage.$perma_cat.$post->parent_stub."'>"; } else { $html .= "<a title='".$text."' href='".$thispage.$q."cid=".$post->topic_category."&show=".$post->topic_parent."'>"; } $html .= $text."</a> ".__wps__time_ago($post->topic_started); if ($use_answers == 'on' && $post->topic_answer == 'on') { $html .= ' <img style="width:12px;height:12px" src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/tick.png" alt="'.__('Answer Accepted', WPS_TEXT_DOMAIN).'" />'; } $html .= "<br>"; } else { $text = stripslashes($post->topic_subject); if ( strlen($text) > $preview ) { $text = substr($text, 0, $preview)."..."; } $html .= __wps__profile_link($post->topic_owner)." ".__('started', WPS_TEXT_DOMAIN); if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) { $perma_cat = __wps__get_forum_category_part_url($post->topic_category); $html .= " <a title='".$text."' href='".$thispage.$perma_cat.$post->stub."'>".$text."</a> "; } else { $html .= " <a title='".$text."' href='".$thispage.$q."cid=".$post->topic_category."&show=".$post->tid."'>".$text."</a> "; } $html .= __wps__time_ago($post->topic_started).".<br>"; } $html .= "</div>"; if ($post->topic_date > $symposium_last_login && $post->topic_owner != $current_user->ID) { $html .= "<div style='float:left;'>"; $html .= " <img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/new.gif' alt='New!' />"; $html .= "</div>"; } if ($post->topic_approved != 'on') { $html .= " <em>[".__("pending approval", WPS_TEXT_DOMAIN)."]</em>"; } $html .= "</div>"; } $html .= symposium_forum_latestposts_showThreadChildren($count, $cat_id, $post->tid, $level+1, $use_answers); } } return $html; }
function showThreadChildren($parent, $level, $gid, $symposium_last_login) { global $wpdb, $current_user; // Work out link to this page, dealing with permalinks or not if ($gid == 0) { $thispage = __wps__get_url('forum'); if ($thispage[strlen($thispage)-1] != '/') { $thispage .= '/'; } if (strpos($thispage, "?") === FALSE) { $q = "?"; } else { // No Permalink $q = "&"; } } else { $thispage = __wps__get_url('group'); if ($thispage[strlen($thispage)-1] != '/') { $thispage .= '/'; } if (strpos($thispage, "?") === FALSE) { $q = "?"; } else { // No Permalink $q = "&"; } $q .= "gid=".$gid."&"; } $html = ""; $preview = 50 - (10*$level); if ($preview < 10) { $preview = 10; } $postcount = 20; // Tries to retrieve last 7 days, but this will be a maximum number of posts or replies if ($level == 0) { $avatar_size = 30; $margin_top = 10; $desc = "DESC"; } else { $avatar_size = 20; $margin_top = 3; $desc = "DESC"; } $include = strtotime("now") - (86400 * 280); // 4 weeks $include = date("Y-m-d H:i:s", $include); // All topics started $sql = " SELECT t.tid, t.topic_subject, t.topic_owner, t.topic_post, t.topic_category, t.topic_date, u.display_name, t.topic_parent, t.topic_answer, t.topic_started, p.topic_category as parent_category FROM ".$wpdb->prefix.'symposium_topics'." t INNER JOIN ".$wpdb->base_prefix.'users'." u ON t.topic_owner = u.ID LEFT JOIN ".$wpdb->prefix."symposium_topics p ON t.topic_parent = p.tid WHERE t.topic_approved = 'on' AND t.topic_parent = %d AND t.topic_group = %d AND t.topic_date > %s AND (t.topic_parent = 0 || p.topic_parent = 0) ORDER BY t.tid ".$desc." LIMIT 0,%d"; $posts = $wpdb->get_results($wpdb->prepare($sql, $parent, $gid, $include, $postcount)); // Get list of roles for this user global $current_user; $user_roles = $current_user->roles; $user_role = strtolower(array_shift($user_roles)); if ($user_role == '') $user_role = 'NONE'; if ($posts) { foreach ($posts as $post) { $sql = "SELECT level FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d"; $cat_level = $wpdb->get_var($wpdb->prepare($sql, $post->topic_category)); $cat_roles = unserialize($cat_level); if ($gid > 0 || strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos(strtolower($cat_roles), $user_role.',') !== FALSE) { $html .= "<div class='__wps__forum_activity_row' style='padding-left: ".($level*40)."px; margin-top:".$margin_top."px;min-height:".$avatar_size."px;'>"; $html .= "<div class='__wps__forum_activity_row_avatar' style='padding-left: ".($level*40)."px;'>"; $html .= get_avatar($post->topic_owner, $avatar_size); $html .= "</div>"; $move_over = ($level == 0) ? 40 : 30; $html .= "<div class='__wps__forum_activity_row_text' style='margin-left: ".$move_over."px;'>"; if ($post->topic_parent > 0) { $text = strip_tags(stripslashes($post->topic_post)); if ( strlen($text) > $preview ) { $text = substr($text, 0, $preview)."..."; } $html .= __wps__profile_link($post->topic_owner)." ".__('replied', WPS_TEXT_DOMAIN)." "; if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) { $stub = $wpdb->get_var($wpdb->prepare("SELECT stub FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d", $post->topic_parent)); $perma_cat = __wps__get_forum_category_part_url($post->parent_category); $url = $thispage.$perma_cat.$stub; $html .= "<a href='".$url."'>".$text."</a> "; } else { $html .= "<a href='".$thispage.$q."cid=".$post->topic_category."&show=".$post->topic_parent."'>".$text."</a> "; } $html .= __wps__time_ago($post->topic_date); if (get_option(WPS_OPTIONS_PREFIX.'_use_answers') == 'on' && $post->topic_answer == 'on') { $html .= ' <img style="width:12px; height:12px" src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/tick.png" alt="'.__('Answer Accepted', WPS_TEXT_DOMAIN).'" />'; } $html .= "<br>"; } else { $text = stripslashes($post->topic_subject); if ( strlen($text) > $preview ) { $text = substr($text, 0, $preview)."..."; } $html .= __wps__profile_link($post->topic_owner)." ".__('started', WPS_TEXT_DOMAIN)." "; if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) { $stub = $wpdb->get_var($wpdb->prepare("SELECT stub FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d", $post->tid)); $perma_cat = __wps__get_forum_category_part_url($post->topic_category); $url = $thispage.$perma_cat.$stub; $html .= "<a href='".$url."'>".$text."</a> "; } else { $html .= "<a href='".$thispage.$q."cid=".$post->topic_category."&show=".$post->tid."'>".$text."</a> "; } $html .= __wps__time_ago($post->topic_started).".<br>"; } $html .= "</div>"; if ($post->topic_date > $symposium_last_login && $post->topic_owner != $current_user->ID && is_user_logged_in() && get_option(WPS_OPTIONS_PREFIX.'_forum_stars')) { $html .= "<img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/new.gif' alt='New!' /> "; } $html .= "</div>"; $html .= showThreadChildren($post->tid, $level+1, $gid, $symposium_last_login); } } } return $html; }