function __wps__groups() { global $wpdb, $current_user; // View (and set tabs) if (!isset($_GET['view']) || $_GET['term'] != '') { $browse_active = 'active'; $create_active = 'inactive'; $view = "browse"; } if ( isset($_GET['view']) && $_GET['view'] == "create") { $browse_active = 'inactive'; $create_active = 'active'; $view = "create"; } $thispage = get_permalink(); if ($thispage[strlen($thispage)-1] != '/') { $thispage .= '/'; } $group_url = get_option(WPS_OPTIONS_PREFIX.'_group_url'); $group_all_create = get_option(WPS_OPTIONS_PREFIX.'_group_all_create'); if (isset($_GET['page_id']) && $_GET['page_id'] != '') { // No Permalink $thispage = $group_url; $q = "&"; } else { $q = "?"; } if (isset($_GET['term'])) { $term = $_GET['term']; } else { $term = ''; } $html = '<div class="__wps__wrapper">'; if ( (is_user_logged_in()) && ($group_all_create == "on" || __wps__get_current_userlevel() == 5) ) { $html .= "<input type='submit' id='show_create_group_button' class='__wps__button' value='".__("Create Group", WPS_TEXT_DOMAIN)."'>"; $html .= "<div id='create_group_form' style='display:none'>"; $html .= "<div>"; $html .= "<strong>".__("Name of Group", WPS_TEXT_DOMAIN)."</strong><br />"; $html .= "<input type='text' id='name_of_group' class='new-topic-subject-input' style='width: 98% !important;'>"; $html .= "</div>"; $html .= "<div>"; $html .= "<strong>".__("Description", WPS_TEXT_DOMAIN)."</strong><br />"; $html .= "<input type='text' id='description_of_group' style='width: 98% !important;'>"; $html .= "</div>"; $html .= "<div style='margin-top:10px'>"; $html .= "<input type='submit' id='create_group_button' class='__wps__button' value='".__("Create", WPS_TEXT_DOMAIN)."'>"; $html .= "<input type='submit' id='cancel_create_group_button' class='__wps__button' value='".__("Cancel", WPS_TEXT_DOMAIN)."'>"; $html .= "</div>"; $html .= "</div>"; } $html .= "<div id='groups_results'>"; if ( $term != '' ) { $me = $current_user->ID; $page = 1; $page_length = 25; $term = ""; if (isset($_POST['group'])) { $term .= $_POST['group']; } if (isset($_GET['term'])) { $term .= $_GET['term']; } $html .= "<div style='padding:0px;'>"; $html .= '<input type="text" id="group" name="group" autocomplete="off" class="groups_search_box" value="'.$term.'" style="margin-right:10px" />'; $html .= '<input type="hidden" id="group_id" name="group_id" />'; $html .= '<input id="groups_go_button" type="submit" class="__wps__button" value="'.__("Search", WPS_TEXT_DOMAIN).'" />'; $html .= "</div>"; $sql = "SELECT g.*, (SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_group_members WHERE group_id = g.gid) AS member_count FROM ".$wpdb->prefix."symposium_groups g WHERE ( g.name LIKE '%".$term."%') OR ( g.description LIKE '%".$term."%' ) ORDER BY group_order, last_activity DESC LIMIT 0,25"; $groups = $wpdb->get_results($sql); if ($groups) { foreach ($groups as $group) { if (__wps__member_of($group->gid) == 'yes') { $html .= "<div class='groups_row row_odd corners'>"; } else { $html .= "<div class='groups_row row corners'>"; } $html .= "<div class='groups_avatar'>"; $html .= __wps__get_group_avatar($group->gid, 64); $html .= "</div>"; $html .= "<div class='group_name'>"; $name = stripslashes($group->name) != '' ? stripslashes($group->name) : __('[No name]', WPS_TEXT_DOMAIN); $html .= "<a class='row_link' href='".__wps__get_url('group')."?gid=".$group->gid."'>".$name."</a>"; $html .= "</div>"; $html .= "<div class='group_member_count'>"; $html .= __("Member Count:", WPS_TEXT_DOMAIN)." ".$group->member_count; if ($group->last_activity) { $html .= '<br /><em>'.__('last active', WPS_TEXT_DOMAIN).' '.__wps__time_ago($group->last_activity)."</em>"; } $html .= "</div>"; $html .= "<div class='group_description'>"; $html .= $group->description; $html .= "</div>"; $html .= "</div>"; } } } else { $html .= "<div style='padding:0px;'>"; $html .= '<input type="text" id="__wps__group" name="group" autocomplete="off" class="groups_search_box" value="'.$term.'" style="margin-right:10px" />'; $html .= '<input type="hidden" id="group_id" name="group_id" />'; $html .= '<input id="groups_go_button" type="submit" class="__wps__button" value="'.__("Search", WPS_TEXT_DOMAIN).'" />'; $html .= "</div>"; $html .= "<div id='__wps__groups'><img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/busy.gif' /></div>"; } $html .= "</div>"; // End of Groups Results if (isset($groups) && !$groups) $html .= "<div style='clear:both'>".__("No group found....", WPS_TEXT_DOMAIN)."</div>"; $html .= '</div>'; // End of Wrapper // Send HTML return $html; }
function __wps__do_Forumnoanswer_Widget($preview,$cat_id,$cat_id_exclude,$timescale,$postcount,$groups) { global $wpdb, $current_user; $html = ''; // Previous login if (is_user_logged_in()) { $previous_login = __wps__get_meta($current_user->ID, 'previous_login'); } // Content of widget $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_group, t.topic_started, (SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_topics v WHERE v.topic_parent = t.tid) AS replies FROM ".$wpdb->prefix."symposium_topics t INNER JOIN ".$wpdb->base_prefix.'users'." u ON t.topic_owner = u.ID WHERE t.topic_parent = 0 AND t.for_info != 'on' AND t.topic_approved = 'on' AND t.topic_started >= ( CURDATE() - INTERVAL ".$timescale." DAY ) AND NOT EXISTS (SELECT tid from ".$wpdb->prefix."symposium_topics s WHERE s.topic_parent = t.tid AND s.topic_answer = 'on') "; if ($cat_id != '' && $cat_id > 0) { $sql .= "AND topic_category IN (".$cat_id.") "; } if ($cat_id_exclude != '' && $cat_id_exclude > 0) { $sql .= "AND topic_category NOT IN (".$cat_id_exclude.") "; } if ($groups != 'on') { $sql .= "AND topic_group = 0 "; } $sql .= "ORDER BY t.topic_started DESC LIMIT 0,".$postcount; $posts = $wpdb->get_results($sql); // Get forum URL worked out $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 .= get_avatar($post->topic_owner, 32); $html .= "</div>"; $html .= "<div class='__wps__latest_forum_row_post'>"; $html .= __wps__profile_link($post->topic_owner); if ($preview > 0) { $text = stripslashes($post->topic_subject); 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)." <a href='".$url.$q."cid=".$post->topic_category."&show=".$post->tid."'>".$text."</a>"; } else { $html .= "<br />"; } $html .= " ".__wps__time_ago($post->topic_started).". "; if ($post->replies > 0) { $html .= $post->replies.' '; if ($post->replies != 1) { $html .= __('replies', WPS_TEXT_DOMAIN); } else { $html .= __('reply', WPS_TEXT_DOMAIN); } $html .= "."; } if (is_user_logged_in() && get_option(WPS_OPTIONS_PREFIX.'_forum_stars')) { if ($post->topic_started > $previous_login && $post->topic_owner != $current_user->ID) { $html .= " <img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/new.gif' alt='New!' />"; } } $html .= "<br />"; $html .= "</div>"; $html .= "</div>"; } } } $html .= "</div>"; } echo $html; }
function add_reply($tid, $reply_text, $uid=0, $replybyemail=false) { if ($tid != '') { global $wpdb, $current_user; // Defaults for current state of class $topic_approved = 'on'; $group_id = 0; $answered = ''; // User ID? if ($uid == 0) { $uid = $current_user->ID; } // Get category for this topic ID $cat_id = $wpdb->get_var($wpdb->prepare("SELECT topic_category from ".$wpdb->prefix."symposium_topics where tid = %d", $tid)); // Don't allow HTML in subject if not using WYSIWYG editor if (get_option(WPS_OPTIONS_PREFIX.'_use_wysiwyg') != 'on') { $reply_text = str_replace("<", "<", $reply_text); $reply_text = str_replace(">", ">", $reply_text); } // Check for banned words $chatroom_banned = get_option(WPS_OPTIONS_PREFIX.'_chatroom_banned'); if ($chatroom_banned != '') { $badwords = $pieces = explode(",", $chatroom_banned); for($i=0;$i < sizeof($badwords);$i++){ if (strpos(' '.$reply_text.' ', $badwords[$i])) { $reply_text=eregi_replace($badwords[$i], "***", $reply_text); } } } // First check for potential duplicate $sql = "SELECT tid FROM ".$wpdb->prefix."symposium_topics WHERE topic_parent = %d AND topic_post = %s"; $duplicate = $wpdb->get_var($wpdb->prepare($sql, $tid, $reply_text)); if (!$duplicate) { if ( // Store new reply in post $wpdb->query( $wpdb->prepare( " INSERT INTO ".$wpdb->prefix."symposium_topics ( topic_subject, topic_category, topic_post, topic_date, topic_started, topic_owner, topic_parent, topic_views, topic_approved, topic_group, topic_answer ) VALUES ( %s, %d, %s, %s, %s, %d, %d, %d, %s, %d, %s )", array( '', $cat_id, $reply_text, date("Y-m-d H:i:s"), date("Y-m-d H:i:s"), $uid, $tid, 0, $topic_approved, $group_id, $answered ) ) ) ) { // get new topic id (or response) for return $new_id = $wpdb->insert_id; // Now send out emails as appropriate // Get forum URL worked out $forum_url = __wps__get_url('forum'); if (strpos($forum_url, '?') !== FALSE) { $q = "&"; } else { $q = "?"; } // Get group URL worked out if ($group_id > 0) { $forum_url = __wps__get_url('group'); if (strpos($forum_url, '?') !== FALSE) { $q = "&gid=".$group_id."&"; } else { $q = "?gid=".$group_id."&"; } } // Email people who want to know and prepare body $owner_name = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM ".$wpdb->base_prefix."users WHERE ID = %d", $uid)); $parent = $wpdb->get_var($wpdb->prepare("SELECT topic_subject FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d", $tid)); $body = "<span style='font-size:24px'>".$parent."</span><br /><br />"; $body .= "<p>".$owner_name." ".__('replied', WPS_TEXT_DOMAIN)."...</p>"; $body .= "<p>".$reply_text."</p>"; $url = $forum_url.$q."cid=".$cat_id."&show=".$tid; $body .= "<p><a href='".$url."'>".$url."</a></p>"; $body = str_replace(chr(13), "<br />", $body); $body = str_replace("\\r\\n", "<br />", $body); $body = str_replace("\\", "", $body); $email_list = '0,'; if ($topic_approved == "on") { $query = $wpdb->get_results($wpdb->prepare(" SELECT user_email, ID FROM ".$wpdb->base_prefix."users u RIGHT JOIN ".$wpdb->prefix."symposium_subs ON ".$wpdb->prefix."symposium_subs.uid = u.ID WHERE u.ID != %d AND tid = %d", $uid, $tid)); if ($query) { foreach ($query as $user) { // Filter to allow further actions to take place apply_filters ('__wps__forum_newreply_filter', $user->ID, $uid, $owner_name, $url); // Keep track of who sent to so far $email_list .= $user->ID.','; // Check for Reply-By-Email if ($replybyemail || function_exists('__wps__mailinglist')) { $subject_add = ' #TID='.$tid.' ['.__('do not edit', WPS_TEXT_DOMAIN).']'; $body = get_option(WPS_OPTIONS_PREFIX.'_mailinglist_prompt').'<br />'.get_option(WPS_OPTIONS_PREFIX.'_mailinglist_divider').'<br /><br />'.get_option(WPS_OPTIONS_PREFIX.'_mailinglist_divider_bottom').'<br /><br />'.'<br /><br />'.$body; } else { $subject_add = ''; } // Send mail if (strpos(get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'), '[topic]') !== FALSE) { $subject = str_replace("[topic]", $parent, get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply')); } else { $subject = get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'); } __wps__sendmail($user->user_email, $subject.$subject_add, $body); } } // Now send to everyone who wants to know about all new topics and replies $email_list .= '0'; $sql = "SELECT ID,user_email FROM ".$wpdb->base_prefix."users u WHERE ID != %d AND ID NOT IN (".$email_list.")"; $list = $wpdb->get_results($wpdb->prepare($sql, $current_user->ID)); if ($list) { $list_array = array(); foreach ($list as $item) { if (__wps__get_meta($item->ID, 'forum_all') == 'on') { $add = array ( 'ID' => $item->ID, 'user_email' => $item->user_email ); array_push($list_array, $add); } } $query = __wps__sub_val_sort($list_array, 'last_activity'); } else { $query = false; } // Get list of permitted roles for this topic category $sql = "SELECT level FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d"; $level = $wpdb->get_var($wpdb->prepare($sql, $cat_id)); $cat_roles = unserialize($level); if ($query) { foreach ($query as $user) { // If a group and a member of the group, or not a group forum... if ($group_id == 0 || __wps__member_of($group_id) == "yes") { // Get role of recipient user $the_user = get_userdata( $user->ID ); $capabilities = $the_user->{$wpdb->prefix . 'capabilities'}; if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $user_role = 'NONE'; if ($capabilities) { foreach ( $wp_roles->role_names as $role => $name ) { if ( array_key_exists( $role, $capabilities ) ) $user_role = $role; } } // Check in this topics category level if (strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos(strtolower($cat_roles), $user_role.',') !== FALSE) { // Filter to allow further actions to take place apply_filters ('__wps__forum_newreply_filter', $user->ID, $uid, $owner_name, $url); // Send mail if (strpos(get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'), '[topic]') !== FALSE) { $subject = str_replace("[topic]", $parent, get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply')); } else { $subject = get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'); } __wps__sendmail($user->user_email, $subject, $body); } } } } } else { // Email admin if post needs approval $body = "<span style='font-size:24px; font-style:italic;'>".__("Moderation required for a reply", WPS_TEXT_DOMAIN)."</span><br /><br />".$body; __wps__sendmail(get_bloginfo('admin_email'), __('Moderation required for a reply', WPS_TEXT_DOMAIN), $body); } return $new_id; } else { //__wps__sendmail(get_bloginfo('admin_email'), __('POP3 insert failed', WPS_TEXT_DOMAIN), 'Query:'.$wpdb->last_query); return false; } } else { //__wps__sendmail(get_bloginfo('admin_email'), __('POP3 insert failed', WPS_TEXT_DOMAIN), 'Duplicate skipped: '.$wpdb->last_query); return false; } // End duplicate check } else { //__wps__sendmail(get_bloginfo('admin_email'), __('POP3 insert failed', WPS_TEXT_DOMAIN), 'No tid passed'); return false; } }
$sql = "SELECT g.*, (SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_group_members WHERE group_id = g.gid) AS member_count FROM ".$wpdb->prefix."symposium_groups g WHERE ( g.name LIKE '%%%s%%') OR ( g.description LIKE '%%%s%%' ) ORDER BY group_order, last_activity DESC LIMIT 0,25"; $groups = $wpdb->get_results($wpdb->prepare($sql, $term, $term)); $url = get_option(WPS_OPTIONS_PREFIX.'_group_url'); if ($groups) { foreach ($groups as $group) { if (__wps__member_of($group->gid) == 'yes') { $html .= "<div class='groups_row row_odd corners'>"; } else { $html .= "<div class='groups_row row corners'>"; } $html .= "<div class='groups_info'>"; $html .= "<div class='groups_avatar'>"; $html .= __wps__get_group_avatar($group->gid, 64); $html .= "</div>"; $html .= "<div class='group_name'>"; $name = stripslashes($group->name) != '' ? stripslashes($group->name) : __('[No name]', WPS_TEXT_DOMAIN); $html .= "<a class='row_link' href='".__wps__get_url('group').__wps__string_query($url)."gid=".$group->gid."'>".$name."</a>"; $html .= "</div>";
ORDER BY t.tid DESC LIMIT 0,40"; $topics = $wpdb->get_results($wpdb->prepare($sql, $term, $term, $term)); if ($topics) { foreach ($topics as $topic) { // Check permitted to see forum category $sql = "SELECT level FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d"; $levels = $wpdb->get_var($wpdb->prepare($sql, $topic->topic_category)); $cat_roles = unserialize($levels); if ($topic->topic_group > 0 || strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos(strtolower($cat_roles), $user_role.',') !== FALSE) { $gid = $topic->topic_group; if ($gid == 0 || __wps__member_of($gid) == "yes") { if ($found_count > $max_return) { $html .= '<p>'.sprintf(__('A maxium of %d search results will be displayed, please narrow your search.', WPS_TEXT_DOMAIN), $max_return).'</p>'; break; } $found_count++; // 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 {
$html .= __wps__make_url(stripslashes($c)); $html .= "</div>"; $html .= "</div>"; $html .= "<div class='wall_reply_avatar'>"; $html .= get_avatar($reply->author_uid, 40); $html .= "</div>"; $html .= "</div>"; } } else { $html .= "<div class='no_wall_replies'></div>"; } $html .= "<div style='clear:both;' id='__wps__comment_".$comment->cid."'></div>"; // Reply field if (is_user_logged_in() && __wps__member_of($uid1) == "yes") { $html .= '<div>'; $html .= '<textarea id="__wps__reply_'.$comment->cid.'" title="'.$comment->cid.'" class="__wps__group_reply'; if (get_option(WPS_OPTIONS_PREFIX.'_elastic')) $html .= ' elastic'; $html .= '" id="__wps__reply_'.$comment->cid.'" onblur="this.value=(this.value==\'\') ? \''.__('Write a comment...', WPS_TEXT_DOMAIN).'\' : this.value;" onfocus="this.value=(this.value==\''.__('Write a comment...', WPS_TEXT_DOMAIN).'\') ? \'\' : this.value;">'.__('Write a comment...', WPS_TEXT_DOMAIN).'</textarea>'; if (get_option(WPS_OPTIONS_PREFIX.'_show_buttons')) { $html .= '<br /><input title="'.$comment->cid.'" id="__wps__reply_'.$comment->cid.'" type="submit" style="width:75px" class="__wps__button reply_field-button" value="'.__('Add', WPS_TEXT_DOMAIN).'" />'; } $html .= '<input id="symposium_author_'.$comment->cid.'" type="hidden" value="'.$comment->author_uid.'" />'; $html .= '</div>'; }