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; }
function get_inbox($count=10, $start=0, $avatar_size=40, $term="", $order=true, $message_len=75, $unread_only=false, $sent_items=false) { global $wpdb; $mail_count = 1; $return_arr = array(); $results_order = $order ? "DESC" : ""; $unread = $unread_only ? " AND m.mail_read = ''" : ""; if (!$sent_items) { $sql = "SELECT m.mail_mid, m.mail_from, m.mail_to, m.mail_read, m.mail_sent, m.mail_subject, m.mail_message, u.display_name FROM ".$wpdb->base_prefix."symposium_mail m INNER JOIN ".$wpdb->base_prefix."users u ON m.mail_from = u.ID WHERE m.mail_in_deleted != 'on' AND m.mail_to = %d ORDER BY m.mail_mid ".$results_order." LIMIT ".$start.",1000"; // Maximum 1,000 to reduce load on database } else { $sql = "SELECT m.mail_mid, m.mail_from, m.mail_to, m.mail_read, m.mail_sent, m.mail_subject, m.mail_message, u.display_name FROM ".$wpdb->base_prefix."symposium_mail m INNER JOIN ".$wpdb->base_prefix."users u ON m.mail_to = u.ID WHERE m.mail_sent_deleted != 'on' AND m.mail_from = %d ORDER BY m.mail_mid ".$results_order." LIMIT ".$start.",1000"; // Maximum 1,000 to reduce load on database } $messages = $wpdb->get_results($wpdb->prepare($sql, $this->id)); foreach ($messages AS $item) { $continue = false; if ($term != '') { if (strpos(strtolower($item->mail_subject), strtolower($term)) !== FALSE) $continue = true; if (strpos(strtolower($item->mail_message), strtolower($term)) !== FALSE) $continue = true; if (strpos(strtolower($item->display_name), strtolower($term)) !== FALSE) $continue = true; } else { $continue = true; } if ($continue) { $row_array['mail_id'] = $item->mail_mid; $row_array['mail_from'] = $item->mail_from; $row_array['mail_to'] = $item->mail_to; $row_array['mail_read'] = $item->mail_read; $row_array['mail_sent'] = $item->mail_sent; $row_array['mail_subject'] = __wps__bbcode_remove(stripslashes($item->mail_subject)); $row_array['mail_subject'] = preg_replace( "/(>|^)([^<]+)(?=<|$)/iesx", "'\\1' . str_replace('" . $term . "', '<span class=\"__wps__search_highlight\">" . $term . "</span>', '\\2')", $row_array['mail_subject'] ); $row_array['mail_subject'] = stripslashes($row_array['mail_subject']); $message = strip_tags(stripslashes($item->mail_message)); if ( strlen($message) > $message_len ) { $message = substr($message, 0, $message_len)."..."; } $message = preg_replace( "/(>|^)([^<]+)(?=<|$)/iesx", "'\\1' . str_replace('" . $term . "', '<span class=\"__wps__search_highlight\">" . $term . "</span>', '\\2')", $message ); $row_array['mail_message'] = $message; $row_array['display_name'] = $item->display_name; if (!$sent_items) { $row_array['display_name_link'] = stripslashes(__wps__profile_link($item->mail_from)); $row_array['avatar'] = get_avatar($item->mail_from, $avatar_size); } else { $row_array['display_name_link'] = stripslashes(__wps__profile_link($item->mail_to)); $row_array['avatar'] = get_avatar($item->mail_to, $avatar_size); } array_push($return_arr,$row_array); if ($mail_count++ == $count) break; } } return $return_arr; }
$row_array['mail_subject'] = __wps__bbcode_remove(stripslashes($item->mail_subject)); @$row_array['mail_subject'] = preg_replace( "/(>|^)([^<]+)(?=<|$)/iesx", "'\\1' . str_replace('" . $term . "', '<span class=\"__wps__search_highlight\">" . $term . "</span>', '\\2')", $row_array['mail_subject'] ); $row_array['mail_subject'] = stripslashes($row_array['mail_subject']); $message = strip_tags(stripslashes($item->mail_message)); if ( strlen($message) > 75 ) { $message = substr($message, 0, 75)."..."; } @$message = preg_replace( "/(>|^)([^<]+)(?=<|$)/iesx", "'\\1' . str_replace('" . $term . "', '<span class=\"__wps__search_highlight\">" . $term . "</span>', '\\2')", $message ); $row_array['message'] = stripslashes(__wps__bbcode_remove($message)); array_push($return_arr,$row_array); } } else { array_push($return_arr,$row_array); } echo json_encode($return_arr); } } // Get single mail message
$topic_subject ); 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", $topic->tid)); $perma_cat = __wps__get_forum_category_part_url($topic->topic_category); $url = $thispage.$perma_cat.$stub; $html .= "<a class='__wps__search_subject' href='".$url."'>".stripslashes($topic_subject)."</a> "; } else { $html .= "<a class='__wps__search_subject' href='".$thispage.$q.'cid='.$topic->topic_category.'&show='.$topic->tid."'>".stripslashes($topic_subject)."</a> "; } $html .= __("by", WPS_TEXT_DOMAIN)." ".$topic->display_name.", ".__wps__time_ago($topic->topic_started)."."; } $html .= "</div>"; $text = __wps__bbcode_remove(strip_tags(stripslashes($topic->topic_post))); $result = ""; $buffer = 20; for ($i = 0; $i <= strlen($text)-strlen($term); $i++) { if ( substr(strtolower($text), $i, strlen($term)) == strtolower($term) ) { $start = ($i - $buffer >= 0) ? $i - $buffer : 0; $end = strlen($term) + ($buffer * 2); $end = ($end >= strlen($text)) ? strlen($text) : $end; $snippet = substr($text, $start, $end); if ($start > 0) { $snippet = "...".$snippet; } if ($end < strlen($text)) { $snippet .= "... "; } $snippet = preg_replace('/('.$term.')/i', "<span class=\"__wps__search_highlight\">$1</span>", $snippet); $result .= $snippet; }