Пример #1
0
function __wps__getForum($cat_id, $limit_from=0, $group_id=0) {

	global $wpdb, $current_user;
		
	$limit_count = get_option(WPS_OPTIONS_PREFIX.'_topic_count') ? get_option(WPS_OPTIONS_PREFIX.'_topic_count') : 10; // Use even number to ensure row backgrounds continue to alternate

	$previous_login = __wps__get_meta($current_user->ID, 'previous_login');
	$forum_all = __wps__get_meta($current_user->ID, 'forum_all');

	$plugin = WP_CONTENT_URL.'/plugins/wp-symposium/';
	
	// Get forum URL worked out
	$forum_url = __wps__get_url('forum');
	if (strpos($forum_url, '?') !== FALSE) {
		$q = "&";
	} else {
		$q = "?";
	}

	$html = '';	
	$text_color = '';

	// Get group URL worked out
	$continue = true;
	if ($group_id > 0) {
		$forum_url = __wps__get_url('group');
		if (strpos($forum_url, '?') !== FALSE) {
			$q = "&gid=".$group_id."&";
		} else {
			$q = "?gid=".$group_id."&";
		}
		$group_info = $wpdb->get_row($wpdb->prepare("SELECT content_private, allow_new_topics FROM ".$wpdb->prefix . 'symposium_groups WHERE gid=%d', $group_id));
		$content_private = $group_info->content_private;
		$allow_new_topics = $group_info->allow_new_topics;
		$continue = false;
		if (__wps__member_of($group_id) == 'yes') {
			$continue = true;
		} else {
			if ($content_private != 'on') {
				$continue = true;
			}			
		}
	}

	// Get list of roles for this user
    $user_roles = $current_user->roles;
    $user_role = strtolower(array_shift($user_roles));
    $user_role = str_replace('_', '', str_replace(' ', '', $user_role));
	if ($user_role == '') $user_role = 'NONE';

	// If in a group forum check that they are a member!
	if ( $continue ) {
		
		// Post preview
		$snippet_length = get_option(WPS_OPTIONS_PREFIX.'_preview1');
		if ($snippet_length == '') { $snippet_length = '0'; }
		$snippet_length_long = get_option(WPS_OPTIONS_PREFIX.'_preview2');
		if ($snippet_length_long == '') { $snippet_length_long = '100'; }
		
		if ($limit_from == 0) {
		
			$template = get_option(WPS_OPTIONS_PREFIX.'_template_forum_header');
			$template = str_replace("[]", "", stripslashes($template));
	
			// Breadcrumbs	
			$allow_new = 'on';
			if ($wpdb->get_var($wpdb->prepare("SELECT hide_breadcrumbs FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d", $cat_id)) == 'on') {
				$allow_new = $wpdb->get_var($wpdb->prepare("SELECT allow_new FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d", $cat_id));
			} else {
				$breadcrumbs = '<div id="forum_breadcrumbs" class="breadcrumbs label">';

				if ($cat_id > 0) {
			
					if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
			
						$this_level = $wpdb->get_row($wpdb->prepare("SELECT cid, title, allow_new, cat_parent, stub FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d", $cat_id));
						$allow_new = $this_level->allow_new;
						if ($this_level->cat_parent == 0) {
							if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
								$breadcrumbs .= '<a href="#cid=0" class="category_title" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a> &rarr; ";
								$breadcrumbs .= '<a href="#cid='.$this_level->cid.'" class="category_title" title="'.$this_level->cid.'">'.stripslashes(trim($this_level->title)).'</a>';
							} else {
								if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
									$breadcrumbs .= '<a href="'.$forum_url.'" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a> &rarr; ";
									$breadcrumbs .= '<a href="'.$forum_url.'/'.$this_level->stub.'" title="'.$this_level->cid.'">'.stripslashes(trim($this_level->title)).'</a>';
								} else {
									$breadcrumbs .= '<a href="'.$forum_url.$q.'cid=0" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a> &rarr; ";
									$breadcrumbs .= '<a href="'.$forum_url.$q."cid=".$this_level->cid.'" title="'.$this_level->cid.'">'.stripslashes(trim($this_level->title)).'</a>';
								}
							}
						} else {
			
							$parent_level = $wpdb->get_row($wpdb->prepare("SELECT cid, title, cat_parent, stub FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d", $this_level->cat_parent));
			
							if ($parent_level->cat_parent == 0) {
								if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
									$breadcrumbs .= '<a href="#cid=0" class="category_title" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a> &rarr; ";
								} else {
									if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
										$breadcrumbs .= '<a href="'.$forum_url.'" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a> &rarr; ";
									} else {
										$breadcrumbs .= '<a href="'.$forum_url.$q.'cid=0" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a> &rarr; ";
									}
								}
							} else {
								$parent_level_2 = $wpdb->get_row($wpdb->prepare("SELECT cid, title, cat_parent, stub FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d", $parent_level->cat_parent));
								if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
									$breadcrumbs .= '<a href="#cid=0" class="category_title" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a> &rarr; " ;
									$breadcrumbs .= '<a href="#cid='.$parent_level_2->cid.'" class="category_title" title="'.$parent_level_2->cid.'">'.stripslashes($parent_level_2->title)."</a> &rarr; ";
								} else {
									if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
										$breadcrumbs .= '<a href="'.$forum_url.'" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</span></a> &rarr; " ;
										$breadcrumbs .= '<a href="'.$forum_url.'/'.$parent_level_2->stub.'"  title="'.$parent_level_2->cid.'">'.stripslashes($parent_level_2->title)."</a> &rarr; ";
									} else {
										$breadcrumbs .= '<a href="'.$forum_url.$q.'cid=0" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</span></a> &rarr; " ;
										$breadcrumbs .= '<a href="'.$forum_url.$q."cid=".$parent_level_2->cid.'"  title="'.$parent_level_2->cid.'">'.stripslashes($parent_level_2->title)."</a> &rarr; ";
									}
								}
							}
							if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
								$breadcrumbs .= '<a href="#cid='.$parent_level->cid.'" class="category_title" title="'.$parent_level->cid.'">'.$parent_level->title."</a> &rarr; " ;
								$breadcrumbs .= '<a href="#cid='.$this_level->cid.'" class="category_title" title="'.$this_level->cid.'">'.stripslashes($this_level->title)."</a>" ;
							} else {
								if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
									$breadcrumbs .= '<a href="'.$forum_url.'/'.$parent_level->stub.'" title="'.$parent_level->cid.'">'.$parent_level->title."</a> &rarr; " ;
									$breadcrumbs .= '<a href="'.$forum_url.'/'.$this_level->stub.'" title="'.$this_level->cid.'">'.stripslashes($this_level->title)."</a>" ;
								} else {
									$breadcrumbs .= '<a href="'.$forum_url.$q."cid=".$parent_level->cid.'" title="'.$parent_level->cid.'">'.$parent_level->title."</a> &rarr; " ;
									$breadcrumbs .= '<a href="'.$forum_url.$q."cid=".$this_level->cid.'" title="'.$this_level->cid.'">'.stripslashes($this_level->title)."</a>" ;
								}
							}
						}

					} else {
						// Lite mode
						$this_level = $wpdb->get_row($wpdb->prepare("SELECT allow_new, cat_parent FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d", $cat_id));
						$allow_new = $this_level->allow_new;
						$breadcrumbs .= '<a href="#cid=0" class="category_title" title="0">'.__('Forum Home', WPS_TEXT_DOMAIN)."</a>";
						if ($this_level->cat_parent > 0) {
							$breadcrumbs .= ' &rarr; <a href="'.$forum_url.$q."cid=".$this_level->cat_parent.'" title="'.$this_level->cat_parent.'">'.__('Up a level', WPS_TEXT_DOMAIN)."</a>" ;
						}
					}
				
				}
					
				$breadcrumbs .= '</div>';
			}
						
			// If a group forum, check that is a member - and that new topics can be created
			if ($group_id > 0) {
				// Is user a member of the group?
				$sql = "SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_group_members WHERE group_id=%d AND valid='on' AND member_id=%d";
				$member_count = $wpdb->get_var($wpdb->prepare($sql, $group_id, $current_user->ID));
				if ($member_count == 0) { 
					// Non members can never create topics
					$allow_new = ''; 
				} else {
					$sql = "SELECT member_id FROM ".$wpdb->prefix."symposium_group_members WHERE group_id=%d AND member_id=%d and admin='on'";
					$admin_check = $wpdb->get_var($wpdb->prepare($sql, $group_id, $current_user->ID));
					if ($admin_check || __wps__get_current_userlevel() == 5) {
						// Group and site admin can always create new topics
						$allow_new = 'on';
					} else {
						// Get setting from Group settings
						$allow_new = $allow_new_topics;
					}
				}	
			}
	
			// Check to see if this member is in the included list of roles
			$user = get_userdata( $current_user->ID );
			$can_edit = false;
			$viewer = str_replace('_', '', str_replace(' ', '', strtolower(get_option(WPS_OPTIONS_PREFIX.'_forum_editor'))));
			if ($user) {
				$capabilities = $user->{$wpdb->prefix.'capabilities'};
	
				if ($capabilities) {
					
					foreach ( $capabilities as $role => $name ) {
						if ($role) {
							$role = strtolower($role);
							$role = str_replace(' ', '', $role);
							$role = str_replace('_', '', $role);
							if (WPS_DEBUG) $html .= 'Checking global forum (symposium_functions) role '.$role.' against '.$viewer.'<br />';
							if (strpos($viewer, $role) !== FALSE) $can_edit = true;
						}
					}		 														
				
				}	
			}
			if (strpos($viewer, __('everyone', WPS_TEXT_DOMAIN)) !== FALSE) $can_edit = true;
			if ($group_id > 0) {
				$sql = "SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_group_members WHERE group_id=%d AND valid='on' AND member_id=%d";
				$member_count = $wpdb->get_var($wpdb->prepare($sql, $group_id, $current_user->ID));
				if ($member_count == 0) { $can_edit = false; } else { $can_edit = true; }
			}	
			
			// Advertising code
			if (get_option(WPS_OPTIONS_PREFIX.'_ad_forum_categories')) {
				$top_advert = '<div id="ad_forum_categories">'.stripslashes(get_option(WPS_OPTIONS_PREFIX.'_ad_forum_categories')).'</div>';
			}

			// Dropdown list for quick link			
			if (get_option(WPS_OPTIONS_PREFIX.'_show_dropdown') && !$group_id)
				$breadcrumbs .= __wps__forum_dropdown($cat_id, 0, $group_id);

			// New Topic Button & Form	
			$new_topic_form = "";
			if (is_user_logged_in()) {

				if ( ($can_edit) && (can_manage_forum() || $allow_new == 'on') ) {
	
					$new_topic_button = '<input type="submit" class="__wps__button floatright" id="new-topic-button" value="'.__("New Topic", WPS_TEXT_DOMAIN).'" />';
	
					$new_topic_form .= '<div name="new-topic" id="new-topic" style="display:none;">';
						$new_topic_form .= '<input type="hidden" id="cid" value="'.$cat_id.'">';

						$defaultcat = $wpdb->get_var($wpdb->prepare("SELECT cid FROM ".$wpdb->prefix."symposium_cats WHERE defaultcat = %s", 'on'));

						if ($group_id == 0) {
	
							$new_topic_form .= '<div class="new-topic-category label">'.__("Select a Category", WPS_TEXT_DOMAIN).'<br />';
							if (can_manage_forum()) {
								$categories = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix.'symposium_cats ORDER BY title');			
							} else {
								$categories = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix.'symposium_cats WHERE allow_new = "on" ORDER BY title');			
							}
							if ($categories) {
								$new_topic_form .= '<select name="new_topic_category" id="new_topic_category">';
					
								foreach ($categories as $category) {

									// Check if high enough rank (and applicable)
									if ( substr(get_option(WPS_OPTIONS_PREFIX.'_forum_ranks'), 0, 2) == 'on' ) {
										$min_rank = $category->min_rank;
										$my_count = __wps__forum_rank_points($current_user->ID);
										if (WPS_DEBUG) $html .= "Minimum rank = ".$min_rank." (my score = ".$my_count.")";
										if ($my_count >= $min_rank) {
											$rank_ok = true;
										} else {
											$rank_ok = false;
										}
									} else {
										$rank_ok = true;
									}
																
									// Check that permitted to category
									$cat_roles = unserialize($category->level);
									$cat_roles = str_replace('_', '', str_replace(' ', '', $cat_roles));

									if ($rank_ok && (strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos(strtolower($cat_roles), $user_role.',') !== FALSE)) {		

										$new_topic_form .= '<option value='.$category->cid;
										if ($cat_id > 0) {
											if (isset($defaultcat) && $category->cid == $cat_id) { $new_topic_form .= " SELECTED"; }
										} else {
											if (isset($defaultcat) && $category->cid == $defaultcat) { $new_topic_form .= " SELECTED"; }
										}
										$title = stripslashes($category->title);
										if ($category->allow_new != 'on') $title .= ' '.__('(admin only)', WPS_TEXT_DOMAIN);
										if ($cat_id == $category->cid)
											$new_topic_form .= ' SELECTED';
										$new_topic_form .= '>'.$title.'</option>';
																				
									}
								}
					
								$new_topic_form .= '</select>';
							}
							

						} else {
							// No categories for groups
							$new_topic_form .= '<input name="new_topic_category" type="hidden" value="0">';
						}
						
						$new_topic_form .= '<div style="clear:both"></div>';
						$new_topic_form .= '<div id="new-topic-subject-label" class="new-topic-subject label">'.__("Topic Subject", WPS_TEXT_DOMAIN).'</div>';
						$new_topic_form .= '<div style="clear:both"></div>';
						$new_topic_form .= '<input class="new-topic-subject-input" type="text" id="new_topic_subject" value="">';
						$new_topic_form .= '<div style="clear:both"></div>';
						$new_topic_form .= '<div class="new-topic-subject label">'.__("First Post in Topic", WPS_TEXT_DOMAIN).'</div>';
						if (get_option(WPS_OPTIONS_PREFIX.'_elastic') == 'on' && get_option(WPS_OPTIONS_PREFIX.'_use_wysiwyg') != 'on') { $elastic = ' elastic'; } else { $elastic = ''; }

						$new_topic_form .= '<div id="__wps__new-topic-subject-text_parent" style="width:'.get_option(WPS_OPTIONS_PREFIX.'_use_wysiwyg_width').'; height:'.get_option(WPS_OPTIONS_PREFIX.'_use_wysiwyg_height').';">';
						$new_topic_form .= __wps__bbcode_toolbar('new_topic_text');
						$new_topic_form .= '<textarea class="new-topic-subject-text'.$elastic.'" id="new_topic_text" style="width:100%;"></textarea>';
						$new_topic_form .= '</div>';
						if (get_option(WPS_OPTIONS_PREFIX.'_use_wysiwyg') == 'on') { $new_topic_form .= '<br />'; }
							
						// Upload
						if (get_option(WPS_OPTIONS_PREFIX.'_forum_uploads')) {
							include_once('server/file_upload_include.php');
							$new_topic_form .= show_upload_form(
								WP_CONTENT_DIR.'/wps-content/members/'.$current_user->ID.'/forum_upload/', 
								WP_CONTENT_URL.'/wps-content/members/'.$current_user->ID.'/forum_upload/',
								'forum',
								__('Attach file', WPS_TEXT_DOMAIN)
							);							
							$new_topic_form .= '<div id="forum_file_list" style="clear:both;"></div>';
						}
						
						$new_topic_form .= '<div>';
						if (get_option(WPS_OPTIONS_PREFIX.'_suppress_forum_notify') != "on") {
							if ($forum_all != 'on') {
								$new_topic_form .= '<input style="margin: 0;" type="checkbox" id="new_topic_subscribe"> '.__("Tell me when I get any replies", WPS_TEXT_DOMAIN).'<br />';
							}
						}
						if (get_option(WPS_OPTIONS_PREFIX.'_use_answers') == 'on') {
							$new_topic_form .= '<input style="margin: 0 0 10px 0;" type="checkbox" id="info_only"> '.__('This topic is for information only, no answer will be selected.', WPS_TEXT_DOMAIN);
						}
						$new_topic_form .= '</div>';
	
						$new_topic_form .= '<input id="symposium_new_post" type="submit" class="__wps__button" style="float: left" value="'.__("Post", WPS_TEXT_DOMAIN).'" />';
						$new_topic_form .= '<input id="cancel_post" type="submit" class="__wps__button clear" onClick="javascript:void(0)" value="'.__("Cancel", WPS_TEXT_DOMAIN).'" />';
	
	
						$new_topic_form .= '</div>';
	
					$new_topic_form .= '</div>';
	
				} else {
	
					if ($group_id == 0 && $allow_new == 'on') {
						$new_topic_form = "<p>".__("You are not permitted to start a new topic.", WPS_TEXT_DOMAIN);	
						if (__wps__get_current_userlevel() == 5) $new_topic_form .= sprintf(__('<br />Permissions are set via the WordPress admin dashboard->%s->Options->Forum.', WPS_TEXT_DOMAIN), WPS_WL);	
						$new_topic_forum .= "</p>";
					}
					if ($group_id > 0 && $allow_new != 'on' && $member_count > 0) {
						$new_topic_form = "<p>".__("New topics are disabled on this forum.", WPS_TEXT_DOMAIN)."</p>";							
					}
					$new_topic_button = '';
					
				}
				
	
			} else {
	
				$new_topic_button = '';
	
				if (get_option(WPS_OPTIONS_PREFIX.'_forum_login') == "on") {
					$new_topic_form .= "<p style='text-align: right;'>".__("Until you login, you can only view the forum.", WPS_TEXT_DOMAIN);
					$new_topic_form .= " <a href=".wp_login_url( get_permalink() )." class='simplemodal-login' title='".__("Login", WPS_TEXT_DOMAIN)."'>".__("Login", WPS_TEXT_DOMAIN).".</a></p>";
				}
	
			}
	
			// Options
			$digest = "";
			$subscribe = "";

			if (is_user_logged_in()) {
		
				$send_summary = get_option(WPS_OPTIONS_PREFIX.'_send_summary');
				if ($send_summary == "on" && $cat_id == 0) {
					$forum_digest = __wps__get_meta($current_user->ID, 'forum_digest');
					$digest = "<div class='__wps__subscribe_option label'>";
					$digest .= "<input type='checkbox' id='symposium_digest' name='symposium_digest'";
					if ($forum_digest == 'on') { $digest .= ' checked'; } 
					$digest .= "> ".__("Receive digests via email", WPS_TEXT_DOMAIN);
					$digest .= "</div>";
				}
				if (get_option(WPS_OPTIONS_PREFIX.'_suppress_forum_notify') != "on") {
					if ($forum_all != 'on') {
						if ($group_id == 0) {
							if ($cat_id > 0) {
								$subscribed_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_subs WHERE tid = 0 AND cid = %d AND uid = %d", $cat_id, $current_user->ID));
								$subscribe = "<div class='__wps__subscribe_option label'>";
								$subscribe .= "<input type='checkbox' title='".$cat_id."' id='symposium_subscribe' name='symposium_subscribe'";
								if ($subscribed_count > 0) { $subscribe .= ' checked'; } 
								$subscribe .= "> ".__("Tell me when there are new topics posted", WPS_TEXT_DOMAIN);
								$subscribe .= "</div>";
							}
						} else {
							$subscribed_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_subs WHERE tid = 0 AND cid = %d AND uid = %d", (10000+$group_id), $current_user->ID));
							$subscribe = "<div class='__wps__subscribe_option label'>";
							$subscribe .= "<input type='checkbox' title='".(10000+$group_id)."' id='symposium_subscribe' name='symposium_subscribe'";
							if ($subscribed_count > 0) { $subscribe .= ' checked'; } 
							$subscribe .= "> ".__("Tell me when there are new topics posted", WPS_TEXT_DOMAIN);
							$subscribe .= "</div>";
						}
					}
				}
	
			}	
	
			// Options above forum table
			$forum_options = "<div id='forum_options'>";
	
				$forum_options .= "<a id='show_search' class='label' href='javascript:void(0)'>".__("Search", WPS_TEXT_DOMAIN)."</a>";
				$forum_options .= "&nbsp;&nbsp;&nbsp;&nbsp;<a id='show_all_activity' href='javascript:void(0)'>".__("Activity", WPS_TEXT_DOMAIN)."</a>";
				$forum_options .= "&nbsp;&nbsp;&nbsp;&nbsp;<a id='show_threads_activity' class='label' href='javascript:void(0)'>".__("Latest Topics", WPS_TEXT_DOMAIN)."</a>";
	
				if (is_user_logged_in()) {
					$forum_options .= "&nbsp;&nbsp;&nbsp;&nbsp;<a id='show_activity' class='label' href='javascript:void(0)'>".__("My Activity", WPS_TEXT_DOMAIN)."</a>";
					$forum_options .= "&nbsp;&nbsp;&nbsp;&nbsp;<a id='show_favs' class='label' href='javascript:void(0)'>".__("Favorites", WPS_TEXT_DOMAIN)."</a>";
				}
	
			$forum_options .= "</div>";

			// Sharing icons
			if (get_option(WPS_OPTIONS_PREFIX.'_sharing') != '' && $cat_id > 0) {
				$sharing = __wps__show_sharing_icons($cat_id, 0, get_option(WPS_OPTIONS_PREFIX.'_sharing'), $group_id);
			} else {
				$sharing = "";
			}
	
			// Replace template tokens and add to output
			$template = str_replace('[new_topic_form]', $new_topic_form, $template);
			if (!isset($top_advert)) $top_advert = '';
			$template = str_replace('[top_advert]', $top_advert, $template);
			$template = str_replace('[new_topic_button]', $new_topic_button, $template);
			$template = str_replace('[breadcrumbs]', $breadcrumbs, $template);
			$template = str_replace('[digest]', $digest, $template);
			$template = str_replace('[subscribe]', $subscribe, $template);
			$template = str_replace('[forum_options]', $forum_options, $template);
			$template = str_replace('[sharing]', $sharing, $template);
	
			$html .= '<div id="__wps__forum_cagtegory_header">'.$template.'</div>';
			
			if ($group_id == 0) {
	
				// Show child categories in this category (and not in a group) ++++++++++++++++++++++++++++++++++++++++++++++++++
				$sql = $wpdb->prepare("SELECT * FROM ".$wpdb->prefix."symposium_cats WHERE cat_parent = %d AND hide_main != 'on' ORDER BY listorder", $cat_id);
				$categories = $wpdb->get_results($sql);

				// Row template		
				if ( $group_id > 0 ) {
					$template = get_option(WPS_OPTIONS_PREFIX.'_template_group_forum_category');
				} else {
					$template = get_option(WPS_OPTIONS_PREFIX.'_template_forum_category');
				}
				$template = str_replace("[]", "", stripslashes($template));

				if ($categories) {
					
					// Start of table
					$html .= '<div id="__wps__table" class="__wps__forum_table">';
	
						$num_cats = $wpdb->num_rows;
						$cnt = 0;
						foreach($categories as $category) {

							$forum_row = '';

							if ($cnt == 3 && get_option(WPS_OPTIONS_PREFIX.'_ad_forum_in_categories')) {
								// Advertising code +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
								$cnt++;
								if ($cnt&1) {
									$forum_row .= '<div class="row ';
									if ($cnt == $num_cats) { $forum_row .= ' round_bottom_left round_bottom_right'; }
									$forum_row .= '">';
								} else {
									$forum_row .= '<div class="row_odd ';
									if ($cnt == $num_cats) { $forum_row .= ' round_bottom_left round_bottom_right'; }
									$forum_row .= '">';
								}
								$forum_row .= "<div id='ad_forum_in_categories'>";
									$forum_row .= stripslashes(get_option(WPS_OPTIONS_PREFIX.'_ad_forum_in_categories'));	
								$forum_row .= "</div>";
								$forum_row .= '</div>';
							}

 							// Get list of permitted roles from forum_cat and check allowed
							$cat_roles = unserialize($category->level);
							$cat_roles = strtolower(str_replace('_', '', str_replace(' ', '', $cat_roles)));
							if (WPS_DEBUG) $forum_row .= 'Checking forum category role '.$user_role.' against '.$cat_roles.'<br />'.strpos($cat_roles, $user_role.',').'<br />';

							// Check if high enough rank (and applicable)
							if ( substr(get_option(WPS_OPTIONS_PREFIX.'_forum_ranks'), 0, 2) == 'on' ) {
								$min_rank = $category->min_rank;
								$my_count = __wps__forum_rank_points($current_user->ID);
								if (WPS_DEBUG) $forum_row .= "Minimum rank = ".$min_rank." (my score = ".$my_count.")";
								if ($my_count >= $min_rank) {
									$rank_ok = true;
								} else {
									$rank_ok = false;
								}
							} else {
								$rank_ok = true;
							}

							if ( ($rank_ok) && (strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos($cat_roles, $user_role.',') !== FALSE) ) {

								$cnt++;
								if ($cnt&1) {
									$forum_row .= '<div class="row ';
									if ($cnt == $num_cats) { $forum_row .= ' round_bottom_left round_bottom_right'; }
									$forum_row .= '">';
								} else {
									$forum_row .= '<div class="row_odd ';
									if ($cnt == $num_cats) { $forum_row .= ' round_bottom_left round_bottom_right'; }
									$forum_row .= '">';
								}
							
									// Start row template
									$row_template = $template;
						
									// Last Topic/Reply
									$last_topic = $wpdb->get_row($wpdb->prepare("
										SELECT tid, stub, topic_subject, topic_approved, topic_post, topic_date, topic_owner, topic_sticky, topic_parent, display_name, topic_category 
										FROM ".$wpdb->prefix."symposium_topics t 
										INNER JOIN ".$wpdb->base_prefix."users u ON u.ID = t.topic_owner
										WHERE (topic_approved = 'on' OR topic_owner = %d) AND topic_parent = 0 AND topic_category = %d ORDER BY topic_date DESC LIMIT 0,1", $current_user->ID, $category->cid)); 
		
									if ($last_topic) {
										
											if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
												$reply = $wpdb->get_row($wpdb->prepare("
													SELECT t.*, u.display_name
													FROM ".$wpdb->prefix."symposium_topics t 
													LEFT JOIN ".$wpdb->base_prefix."users u ON t.topic_owner = u.ID
													WHERE (topic_approved = 'on' OR topic_owner = %d) 
													  AND topic_parent = %d 
													ORDER BY topic_date DESC LIMIT 0,1", $current_user->ID, $last_topic->tid)); 
											} else {
												$reply = false;
											}
		
											// Avatar
											if ($reply) {
												$topic_owner = $reply->topic_owner;
											} else {
												$topic_owner = $last_topic->topic_owner;									
											}
											if (strpos($row_template, '[avatar') !== FALSE) {
	
												if (strpos($row_template, '[avatar]')) {
													$row_template = str_replace("[avatar]", get_avatar($topic_owner, 32), $row_template);
												} else {
													$x = strpos($row_template, '[avatar');
													$avatar = substr($row_template, 0, $x);
													$avatar2 = substr($row_template, $x+8, 2);
													$avatar3 = substr($row_template, $x+11, strlen($row_template)-$x-11);
													
													$row_template = $avatar . get_avatar($topic_owner, $avatar2) . $avatar3;
												}
											}
											
											if ($reply) {
												$row_template = str_replace("[replied]", __wps__profile_link($reply->topic_owner)." ".__("replied to", WPS_TEXT_DOMAIN)." ", $row_template);	
												$subject = __wps__bbcode_remove($last_topic->topic_subject);
												if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
													$subject = '<a title="'.$last_topic->tid.'" class="topic_subject backto row_link_topic" href="#cid='.$category->cid.',tid='.$last_topic->tid.'">'.stripslashes($subject).'</a> ';
												} else {
													if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
														$perma_cat = __wps__get_forum_category_part_url($reply->topic_category);
														$subject = '<a class="backto row_link_topic" href="'.$forum_url.'/'.$perma_cat.$last_topic->stub.'">'.stripslashes($subject).'</a> ';
													} else {
														$subject = '<a class="backto row_link_topic" href="'.$forum_url.$q."cid=".$last_topic->topic_category."&show=".$last_topic->tid.'">'.stripslashes($subject).'</a> ';
													}
												}
												if ($reply->topic_approved != 'on') { $subject .= "<em>[".__("pending approval", WPS_TEXT_DOMAIN)."]</em> "; }
												$subject_text = strip_tags(stripslashes($reply->topic_post));
												$subject_text = __wps__bbcode_remove($subject_text);
												if ( strlen($subject_text) > $snippet_length_long ) { $subject_text = substr($subject_text, 0, $snippet_length_long)."..."; }
												$row_template = str_replace("[subject_text]", $subject_text, $row_template);	
												$row_template = str_replace("[subject]", $subject, $row_template);	
												$row_template = str_replace("[ago]", __wps__time_ago($reply->topic_date), $row_template);	
											} else {
												$row_template = str_replace("[replied]", __wps__profile_link($last_topic->topic_owner)." ".__("started", WPS_TEXT_DOMAIN)." ", $row_template);	
												$subject = __wps__bbcode_remove($last_topic->topic_subject);
												if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
													$subject = '<a title="'.$last_topic->tid.'" class="topic_subject backto row_link_topic" href="#cid='.$category->cid.',tid='.$last_topic->tid.'">'.stripslashes($subject).'</a> ';
												} else {
													if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
														$perma_cat = __wps__get_forum_category_part_url($last_topic->topic_category);
														$subject = '<a class="backto row_link_topic" href="'.$forum_url.'/'.$perma_cat.$last_topic->stub.'">'.stripslashes($subject).'</a> ';
													} else {
														$subject = '<a class="backto row_link_topic" href="'.$forum_url.$q."cid=".$last_topic->topic_category."&show=".$last_topic->tid.'">'.stripslashes($subject).'</a> ';
													}
												}
												$subject_text = strip_tags(stripslashes($last_topic->topic_post));
												$subject_text = __wps__bbcode_remove($subject_text);												
												if ( strlen($subject_text) > $snippet_length_long ) { $subject_text = substr($subject_text, 0, $snippet_length_long)."..."; }
												$row_template = str_replace("[subject_text]", $subject_text, $row_template);	
												$row_template = str_replace("[subject]", $subject, $row_template);	
												$row_template = str_replace("[ago]", __wps__time_ago($last_topic->topic_date), $row_template);	
											}
		
									} else {
		
										if (strpos($row_template, '[avatar') !== FALSE) {
											if (strpos($row_template, '[avatar]')) {
												$row_template = str_replace("[avatar]", get_avatar($reply->topic_owner, 32), $row_template);						
											} else {
												$x = strpos($row_template, '[avatar');
												$avatar = substr($row_template, 0, $x);
												$avatar2 = substr($row_template, $x+8, 2);
												$avatar3 = substr($row_template, $x+11, strlen($row_template)-$x-11);
												$row_template = $avatar . $avatar3;									
											}
										}
										$row_template = str_replace("[subject_text]", "", $row_template);	
										$row_template = str_replace("[replied]", "", $row_template);	
										$row_template = str_replace("[subject]", "", $row_template);	
										$row_template = str_replace("[ago]", "", $row_template);
									}

									// Topic Count
									if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
										$topic_count = __wps__get_topic_count($category->cid);
			
										if ($topic_count > 0) {
											$topic_count_html = "<div class='post_count' style='color:".$text_color.";'>".$topic_count."</div>";
											$topic_count_html .= "<div style='color:".$text_color.";' class='post_count_label'>";
											if ($topic_count != 1) {
												$topic_count_html .= __("TOPICS", WPS_TEXT_DOMAIN);
											} else {
												$topic_count_html .= __("TOPIC", WPS_TEXT_DOMAIN);
											}
											$topic_count_html .= "</div>";
											$row_template = str_replace("[topic_count]", $topic_count_html, $row_template);	
										} else {
											$topic_count_html = "<div class='post_count' style='color:".$text_color.";'>0</div>";
											$topic_count_html .= "<div style='color:".$text_color.";' class='post_count_label'>";
											$topic_count_html .= __("TOPICS", WPS_TEXT_DOMAIN);
											$topic_count_html .= "</div>";	
										}
										$row_template = str_replace("[topic_count]", $topic_count_html, $row_template);	
									} else {
										$row_template = str_replace("[topic_count]", "", $row_template);	
									}

						
									// Replies
									if (get_option(WPS_OPTIONS_PREFIX.'_use_styles')) {
										$text_color = get_option(WPS_OPTIONS_PREFIX.'_text_color');
									} else {
										$text_color = '';
									}
									if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
										$post_count = 0;
		
										$sql = "SELECT COUNT(t.tid)
												FROM ".$wpdb->prefix."symposium_topics t 
												WHERE (t.topic_approved = 'on' OR t.topic_owner = %d) 
												  AND t.topic_category = %d
												  AND t.topic_parent > 0";
		
										$post_count = $wpdb->get_var($wpdb->prepare($sql, $current_user->ID, $category->cid));
										
										if ($post_count > 0) { 
											$post_count_html = "<div class='post_count' style='color:".$text_color.";'>".$post_count."</div>";
												$post_count_html .= "<div style='color:".$text_color.";' class='post_count_label'>";
												if ($post_count > 1) {
													$post_count_html .= __("REPLIES", WPS_TEXT_DOMAIN);
												} else {
													$post_count_html .= __("REPLY", WPS_TEXT_DOMAIN);
												}
												$post_count_html .= "</div>";
												$row_template = str_replace("[post_count]", $post_count_html, $row_template);	
										} else {
											$post_count_html = "<div class='post_count' style='color:".$text_color.";'>0</div>";
											$post_count_html .= "<div style='color:".$text_color.";' class='post_count_label'>";
											$post_count_html .= __("REPLIES", WPS_TEXT_DOMAIN);
											$post_count_html .= "</div>";
											$row_template = str_replace("[post_count]", $post_count_html, $row_template);	
										}
									} else {
										$row_template = str_replace("[post_count]", "", $row_template);	
									}

									// Check for new topics or replies in this category
									$category_title_html = "";
									$recursive_new = false;

									if (is_user_logged_in()) {
										$sql = "SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_topics WHERE topic_category = %d AND topic_started >= %s AND topic_owner != %d";
										$new_topics = $wpdb->get_var($wpdb->prepare($sql, $category->cid, $previous_login, $current_user->ID));
									
										if ($new_topics && $new_topics > 0) {
											$recursive_new = true;
										}
									
										$sql = "SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_topics t 
											LEFT JOIN ".$wpdb->prefix."symposium_topics p ON t.topic_parent = p.tid 
											WHERE t.topic_started >= %s
											  AND t.topic_owner != %d 
											  AND p.topic_category = %d";
										$new_replies = $wpdb->get_var($wpdb->prepare($sql, $previous_login, $current_user->ID, $category->cid));

										if ($new_replies && $new_replies > 0) {
											$recursive_new = true;
										} 
		
									}
									
									// Category title
									if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
										$category_title_html .= '<a class="category_title backto row_link" href="#cid='.$category->cid.'" title='.$category->cid.'>'.stripslashes($category->title).'</a>';
									} else {
										if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
											$category_title_html .= '<a class="backto row_link" href="'.$forum_url.'/'.$category->stub.'">'.stripslashes($category->title).'</a> ';
										} else {
											$category_title_html .= '<a class="backto row_link" href="'.$forum_url.$q."cid=".$category->cid.'">'.stripslashes($category->title).'</a> ';
										}
									}
									if ($recursive_new && get_option(WPS_OPTIONS_PREFIX.'_forum_stars'))
											$category_title_html .= "<img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/new.gif' alt='New!' /> ";

									$subscribed = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_subs WHERE cid = %d AND uid = %d", $category->cid, $current_user->ID));
									if ($subscribed > 0 && $forum_all != 'on') { $category_title_html .= ' <img src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/orange-tick.gif" alt="'.__('Subscribed', WPS_TEXT_DOMAIN).'" />'; } 
									$row_template = str_replace("[category_title]", $category_title_html, $row_template);	
									
									// Category description
									$category_desc_html = stripslashes($category->cat_desc);
									$row_template = str_replace("[category_desc]", $category_desc_html, $row_template);	
		
									// Add row template to HTML
									$forum_row .= $row_template;

									// Show child categories according to forum settings
									if (get_option(WPS_OPTIONS_PREFIX.'_alt_subs') == 'on') {
										$forum_row .= "<div>";
											// Get child categories
											$sql = $wpdb->prepare("SELECT * FROM ".$wpdb->prefix."symposium_cats WHERE cat_parent = %d AND hide_main != 'on' ORDER BY listorder", $category->cid);
											$categories = $wpdb->get_results($sql);
											if ($categories):
												$forum_row .= '<ul class="subcat_forums" style="clear: both">';
												foreach ($categories as $subcat):
													$forum_row .= '<li>';
													if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
														$forum_row .= '<a class="" href="#cid='.$subcat->cid.'" title='.$subcat->cid.'>'.stripslashes($subcat->title).'</a>';
													} else {
														if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
															$forum_row .= '<a class="" href="'.$forum_url.'/'.$subcat->stub.'">'.stripslashes($subcat->title).'</a> ';
														} else {
															$forum_row .= '<a class="" href="'.$forum_url.$q."cid=".$subcat->cid.'">'.stripslashes($subcat->title).'</a> ';
														}
													}
													$forum_row .= '</li>';
												endforeach;
												$forum_row .= '</ul>';
											endif;
										$forum_row .= "</div>";
									}
								
									// Separator
									$forum_row .= "<div class='sep'></div>";											
		
		
								$forum_row .= "</div>"; // Row in the table

								$forum_row .= '<div class="__wps__table_row_sep"></div>';
								
							}

							$forum_row = apply_filters ( '__wps__forum_category_filter', $forum_row, $category->cid );

							$html .= $forum_row;

						}
	
					$html .= '</div>';
					
					$html .= '<div id="__wps__table_sep"></div>';
			
				}
			}
		}
	
		// Show topics in this category ++++++++++++++++++++++++++++++++++++++++++++++++++
		if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
			$sql = "SELECT tid, stub, topic_subject, topic_approved, topic_post, topic_owner, topic_category, topic_date, display_name, topic_sticky, allow_replies, topic_started, 
				(SELECT COUNT(tid) FROM ".$wpdb->prefix."symposium_topics s WHERE s.topic_parent = t.tid AND s.topic_answer = 'on') AS answers, for_info
				FROM ".$wpdb->prefix."symposium_topics t INNER JOIN ".$wpdb->base_prefix."users u ON t.topic_owner = u.ID 
				WHERE (topic_approved = 'on' OR topic_owner = %d) AND topic_category = %d AND topic_parent = 0 AND topic_group = %d ORDER BY topic_sticky DESC, topic_date DESC 
				LIMIT %d, %d";
			$query = $wpdb->get_results($wpdb->prepare($sql, $current_user->ID, $cat_id, $group_id, $limit_from, $limit_count)); 
		} else {
			$sql = "SELECT tid, stub, topic_subject, topic_approved, topic_post, topic_owner, topic_category, topic_date, display_name, topic_sticky, allow_replies, topic_started,
				0 AS answers, for_info
				FROM ".$wpdb->prefix."symposium_topics t INNER JOIN ".$wpdb->base_prefix."users u ON t.topic_owner = u.ID 
				WHERE (topic_approved = 'on' OR topic_owner = %d) AND topic_category = %d AND topic_parent = 0 AND topic_group = %d ORDER BY topic_sticky DESC, topic_date DESC 
				LIMIT %d, %d";
			$query = $wpdb->get_results($wpdb->prepare($sql, $current_user->ID, $cat_id, $group_id, $limit_from, $limit_count)); 
		}
	
		$num_topics = $wpdb->num_rows;
	
		// Row template		
		if ( $group_id > 0 ) {
			$template = get_option(WPS_OPTIONS_PREFIX.'_template_group_forum_topic');
		} else {
			$template = get_option(WPS_OPTIONS_PREFIX.'_template_forum_topic');
		}
		$template = str_replace("[]", "", stripslashes($template));
			
		// Favourites
		$favs = __wps__get_meta($current_user->ID, 'forum_favs');
	
		$cnt = 0;									
					
		if ($query) {

			// Shouldn't get here, but this is a double check in case of deep links/hackers
			// Get list of permitted roles from forum_cat and check allowed
			$sql = "SELECT level FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d";
			$levels = $wpdb->get_var($wpdb->prepare($sql, $query[0]->topic_category));
			$cat_roles = unserialize($levels);
			$cat_roles = str_replace('_', '', str_replace(' ', '', $cat_roles));
			if ($group_id > 0 || strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos(strtolower($cat_roles), $user_role.',') !== FALSE) {		

				if ($limit_from == 0) {
					$html .= '<div id="__wps__table" class="__wps__forum_table">';		
				}
		
					// For every topic in this category 
					foreach ($query as $topic) {
	
						if ($cnt == 3 && get_option(WPS_OPTIONS_PREFIX.'_ad_forum_in_categories')) {
							// Advertising code +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
							$cnt++;
							if ($cnt&1) {
								$html .= '<div style="border-radius:0px;-moz-border-radius:0px" class="row ';
								if ($cnt == $num_topics) { $html .= ' round_bottom_left round_bottom_right'; }
								$html .= '">';
							} else {
								$html .= '<div style="border-radius:0px;-moz-border-radius:0px" class="row_odd ';
								if ($cnt == $num_topics) { $html .= ' round_bottom_left round_bottom_right'; }
								$html .= '">';
							}
							$html .= "<div id='ad_forum_in_categories'>";
								$html .= stripslashes(get_option(WPS_OPTIONS_PREFIX.'_ad_forum_in_categories'));	
							$html .= "</div>";
							$html .= '</div>';
						}

						$cnt++;
	
						if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
							$replies = $wpdb->get_var($wpdb->prepare("SELECT COUNT(tid) FROM ".$wpdb->prefix."symposium_topics WHERE (topic_approved = 'on' OR topic_owner = %d) AND topic_parent = %d", $current_user->ID, $topic->tid));
							$reply_views = $wpdb->get_var($wpdb->prepare("SELECT sum(topic_views) FROM ".$wpdb->prefix."symposium_topics WHERE (topic_approved = 'on' OR topic_owner = %d) AND tid = %d", $current_user->ID, $topic->tid));
						} else {
							$replies = false;
						}

						if ($cnt&1) {
							$html .= '<div id="row'.$topic->tid.'" style="border-radius:0px;-moz-border-radius:0px" class="row ';
							if ($cnt == $num_topics) { $html .= ' round_bottom_left round_bottom_right'; }
						} else {
							$html .= '<div id="row'.$topic->tid.'" style="border-radius:0px;-moz-border-radius:0px" class="row_odd ';
							if ($cnt == $num_topics) { $html .= ' round_bottom_left round_bottom_right'; }
						}
						$closed_word = strtolower(get_option(WPS_OPTIONS_PREFIX.'_closed_word'));
						if ( strpos(strtolower($topic->topic_subject), "{".$closed_word."}") > 0) {
							$color_check = ' transparent';
						} else {
							$color_check = '';
						}
						$html .= $color_check.'">';
	
							// Reset template
							$topic_template = $template;
						
							// Started by/Last Reply
							if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
								$sql = "SELECT tid, topic_subject, topic_approved, topic_post, topic_owner, topic_date, display_name, topic_sticky, topic_parent 
									FROM ".$wpdb->prefix."symposium_topics t INNER JOIN ".$wpdb->base_prefix."users u ON t.topic_owner = u.ID 
									WHERE (topic_approved = 'on' OR topic_owner = %d) AND topic_parent = %d ORDER BY tid DESC LIMIT 0,1";
								$last_post = $wpdb->get_results($wpdb->prepare($sql, $current_user->ID, $topic->tid)); 
							} else {
								$last_post = false;
							}
								
							$child_is_new = false;
							if ( $last_post ) {
	
								$done_last_reply = false;
								foreach ($last_post as $each_last_post) {
									
									if ($each_last_post->topic_date > $previous_login && $each_last_post->topic_owner != $current_user->ID && is_user_logged_in()) {
										$child_is_new = true;
									}
								
									if (!$done_last_reply) {
									
										$done_last_reply = true;
										
										// Who started it?
										if (strpos($topic_template, '[avatarfirst') !== FALSE) {
											if (strpos($topic_template, '[avatarfirst]')) {
												$topic_template = str_replace("[avatarfirst]", get_avatar($topic->topic_owner, 32), $topic_template);						
											} else {
												$x = strpos($topic_template, '[avatarfirst');
												$avatar = substr($topic_template, 0, $x);
												$avatar2 = substr($topic_template, $x+13, 2);
												$avatar3 = substr($topic_template, $x+16, strlen($topic_template)-$x-11);
															
												$topic_template = $avatar . get_avatar($topic->topic_owner, $avatar2) . $avatar3;
											
											}
										}
										$topic_template = str_replace("[startedby]", __("Started by", WPS_TEXT_DOMAIN)." ".__wps__profile_link($topic->topic_owner), $topic_template);	
										$topic_template = str_replace("[started]", " ".__wps__time_ago($topic->topic_started).".", $topic_template);	
										
										// Last reply
										if (strpos($topic_template, '[avatar') !== FALSE) {
											if (strpos($topic_template, '[avatar]')) {
												$topic_template = str_replace("[avatar]", get_avatar($each_last_post->topic_owner, 32), $topic_template);						
											} else {
												$x = strpos($topic_template, '[avatar');
												$avatar = substr($topic_template, 0, $x);
												$avatar2 = substr($topic_template, $x+8, 2);
												$avatar3 = substr($topic_template, $x+11, strlen($topic_template)-$x-11);
															
												$topic_template = $avatar . get_avatar($each_last_post->topic_owner, $avatar2) . $avatar3;
											
											}
										}
										$topic_template = str_replace("[replied]", __("Last reply by", WPS_TEXT_DOMAIN)." ".__wps__profile_link($each_last_post->topic_owner), $topic_template);	
										$topic_template = str_replace("[ago]", " ".__wps__time_ago($each_last_post->topic_date), $topic_template);	
										$post = stripslashes($each_last_post->topic_post);
										$post = strip_tags($post);
										$post = __wps__bbcode_remove($post);
										if ( strlen($post) > $snippet_length_long ) { $post = substr($post, 0, $snippet_length_long)."..."; }
										if ($each_last_post->topic_approved != 'on') { $post .= " <em>[".__("pending approval", WPS_TEXT_DOMAIN)."]</em>"; }
										$topic_template = str_replace("[topic]", " <span class='row_topic_text'>".trim($post)."</span>", $topic_template);										

									}
									
								}
									
							} else {
								
								// Strip out reply (not applicable)
								$topic_template = str_replace("avatar_last_topic'>", "avatar_last_topic' style='display:none'>", $topic_template);
								$topic_template = str_replace("last_topic_text'>", "last_topic_text' style='display:none'>", $topic_template);

								$topic_template = str_replace("[replied]", __("Last reply by", WPS_TEXT_DOMAIN)." ".__wps__profile_link($topic->topic_owner), $topic_template);	
								$topic_template = str_replace("[ago]", " ".__wps__time_ago($topic->topic_date), $topic_template);	
								$post = stripslashes($topic->topic_post);
								if ( strlen($post) > $snippet_length_long ) { $post = substr($post, 0, $snippet_length_long)."..."; }
								$post = __wps__bbcode_remove($post);
								$post = strip_tags($post);
								if ($topic->topic_approved != 'on') { $post .= " <em>[".__("pending approval", WPS_TEXT_DOMAIN)."]</em>"; }
								$topic_template = str_replace("[topic]", " <span class='row_topic_text'>".$post."</span>", $topic_template);										
								
								// First post
								if (strpos($topic_template, '[avatarfirst') !== FALSE) {
									if (strpos($topic_template, '[avatarfirst]')) {
										$topic_template = str_replace("[avatarfirst]", get_avatar($topic->topic_owner, 32), $topic_template);						
									} else {
										$x = strpos($topic_template, '[avatarfirst');
										$avatar = substr($topic_template, 0, $x);
										$avatar2 = substr($topic_template, $x+13, 2);
										$avatar3 = substr($topic_template, $x+16, strlen($topic_template)-$x-11);
													
										$topic_template = $avatar . get_avatar($topic->topic_owner, $avatar2) . $avatar3;
									
									}
								}
								$topic_template = str_replace("[startedby]", __("Started by", WPS_TEXT_DOMAIN)." ".__wps__profile_link($topic->topic_owner), $topic_template);	
								$topic_template = str_replace("[started]", " ".__wps__time_ago($topic->topic_started).".", $topic_template);	
													
							}

							// Move views and replies up if now replies (ie. no text)
							$adjustment = (false && !$replies) ? 'margin-top: -80px; ' : '';

							// Views
							if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
								$views_html = "<div class='post_count' style='".$adjustment."color:".get_option(WPS_OPTIONS_PREFIX.'_text_color').";'>".$reply_views."</div>";
								if ($reply_views != 1) { 
									$views_html .= "<div style='color:".get_option(WPS_OPTIONS_PREFIX.'_text_color').";' class='post_count_label'>".__("VIEWS", WPS_TEXT_DOMAIN)."</div>";
								} else {
									$views_html .= "<div style='color:".get_option(WPS_OPTIONS_PREFIX.'_text_color').";' class='post_count_label'>".__("VIEW", WPS_TEXT_DOMAIN)."</div>";						
								}
								$topic_template = str_replace("[views]", $views_html, $topic_template);	
							} else {
								$topic_template = str_replace("[views]", "", $topic_template);	
							}

							// Replies
							if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite')) {
								$replies_html = "<div class='post_count' style='".$adjustment."color:".get_option(WPS_OPTIONS_PREFIX.'_text_color').";'>".$replies."</div>";
								$replies_html .= "<div style='color:".get_option(WPS_OPTIONS_PREFIX.'_text_color').";' class='post_count_label'>";
								if ($replies != 1) {
									$replies_html .= __("REPLIES", WPS_TEXT_DOMAIN);
								} else {
									$replies_html .= __("REPLY", WPS_TEXT_DOMAIN);
								}
								$replies_html .= "</div>";
								$topic_template = str_replace("[replies]", $replies_html, $topic_template);	
							} else {
								$topic_template = str_replace("[replies]", "", $topic_template);	
							}
		
							// Topic Title		
							$topic_title_html = "";
							// Delete link if applicable
							$reply_posted_time = strtotime($topic->topic_started);
							$reply_posted_expire = $reply_posted_time + (get_option(WPS_OPTIONS_PREFIX.'_forum_lock') * 60);
							$now = time();
							$seconds_left = $reply_posted_expire - $now;
							if ($seconds_left > 0) {
								$title = __('Lock in', WPS_TEXT_DOMAIN).' '.gmdate("H:i:s", $seconds_left);
								$ttitle = '<br /><em>'.$title.'</em>';
							} else {
								$title = __('Admin only', WPS_TEXT_DOMAIN);
								$ttitle = '';
							}
							if (get_option(WPS_OPTIONS_PREFIX.'_forum_lock') == 0) {
								$title = __('No lock time', WPS_TEXT_DOMAIN);
								$ttitle = '';
								$seconds_left = 1;
							}
							if (can_manage_forum() || ($current_user->ID == $topic->topic_owner && $seconds_left > 0)) {
								$topic_title_html .= "<div class='topic-delete-icon'>";
								$topic_title_html .= "<a class='floatright delete_topic link_cursor' id='".$topic->tid."'style='width:16px;'><img title='".$title."' src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/delete.png' style='width:16px; height:16px;' /></a>";
								$topic_title_html .= "</div>";
							}
				
							if (strpos($favs, "[".$topic->tid."]") === FALSE ) { } else {
								$topic_title_html .= "<img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/fav-on.png' class='floatleft' style='height:18px; width:18px; margin-right:4px; margin-top:4px' />";						
							}								

							$subject = stripslashes(__wps__bbcode_remove($topic->topic_subject));
							$topic_title_html .= '<div class="row_link_div">';
		
								if ($topic->for_info == "on") { $topic_title_html .= '<img src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/info.png" alt="'.__('Information only', WPS_TEXT_DOMAIN).'" /> '; }
								if ($topic->answers > 0) { $topic_title_html .= '<img src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/tick.png" alt="'.__('Answer accepted', WPS_TEXT_DOMAIN).'" /> '; }
								if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') == 'on') {
									$topic_title_html .= '<a title="'.$topic->tid.'" href="#cid='.$topic->topic_category.',tid='.$topic->tid.'" class="topic_subject backto row_link">'.stripslashes($subject).'</a>';
								} else {
									if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure') && $group_id == 0) {
										$perma_cat = __wps__get_forum_category_part_url($topic->topic_category);
										$topic_title_html .= '<a class="backto row_link" href="'.$forum_url.'/'.$perma_cat.$topic->stub.'">'.stripslashes($subject).'</a> ';							
									} else {
										$topic_title_html .= '<a class="backto row_link" href="'.$forum_url.$q."cid=".$topic->topic_category."&show=".$topic->tid.'">'.stripslashes($subject).'</a> ';							
									}
								}
								if (is_user_logged_in() && get_option(WPS_OPTIONS_PREFIX.'_forum_stars')) {		
									if ( ($topic->topic_started > $previous_login && $topic->topic_owner != $current_user->ID) || ($child_is_new) ) {
										$topic_title_html .= "<img src='".get_option(WPS_OPTIONS_PREFIX.'_images')."/new.gif' alt='New!' /> ";
									}	
								}
											
								if ($topic->topic_approved != 'on') { $topic_title_html .= " <em>[".__("pending approval", WPS_TEXT_DOMAIN)."]</em>"; }
								if (is_user_logged_in()) {
									$is_subscribed = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_subs WHERE cid = 0 AND tid = %d AND uid = %d", $topic->tid, $current_user->ID));
									if ($is_subscribed > 0 && $forum_all != 'on') { $topic_title_html .= ' <img src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/orange-tick.gif" alt="Subscribed" />'; } 
								}
								if ($topic->allow_replies != 'on') { $topic_title_html .= ' <img src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/padlock.gif" alt="Replies locked" />'; } 
								if ($topic->topic_sticky) { $topic_title_html .= ' <img src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/pin.gif" alt="Sticky Topic" />'; } 
				
							$topic_title_html .= "</div>";

							if ( $snippet_length > 0) {
								$post = stripslashes($topic->topic_post);
								$post = str_replace("<br />", " ", $post);
								$post = strip_tags($post);
								$post = __wps__bbcode_remove($post);
								if ( strlen($post) > $snippet_length ) { $post = substr($post, 0, $snippet_length)."..."; }
								$topic_title_html .= "<span class='row_topic_text'>".$post."</span>";
								$topic_title_html .= $ttitle;
							}
		
							$topic_template = str_replace("[topic_title]", $topic_title_html, $topic_template);	
					
						// Add template to HTML				
						$html .= $topic_template;								
		
						$html .= "</div>";
								
						// Separator
						$html .= "<div class='sep __wps__table_row_sep'></div>";		
				
					}
		
					if ($num_topics >= $limit_count) {
						$html .= "<a href='javascript:void(0)' id='showmore_forum' title='".($limit_from+$limit_count).",".$cat_id."'>".__("more...", WPS_TEXT_DOMAIN)."</a>";
					}
		
				if ($limit_from == 0) {
					$html .= "</div>"; // End of table
				}
				
			}
		}

		if ( get_option(WPS_OPTIONS_PREFIX.'_forum_ajax') ) {
			$cat_title = $wpdb->get_var($wpdb->prepare("SELECT title FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d", $cat_id));
			if ($cat_title) {
				$html = $cat_title.' | '.html_entity_decode(get_bloginfo('name'), ENT_QUOTES).'[|]'.$html;
			} else {
				$html = __('Forum', WPS_TEXT_DOMAIN).' | '.html_entity_decode(get_bloginfo('name'), ENT_QUOTES).'[|]'.$html;
			}
		}
		
	} else {
		
		$html = "DONTSHOW";
		
	}

	// Filter for header
	$html = apply_filters ( '__wps__forum_categories_header_filter', $html, $cat_id );

	return $html;

}
Пример #2
0
	
}


// Delete Reply *************************************************************
if ($_POST['action'] == 'deleteReply') {

	if (is_user_logged_in()) {

		$tid = $_POST['topic_id'];

		// Get owner of this reply
		$sql = "SELECT topic_owner FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d";
		$owner = $wpdb->get_var($wpdb->prepare($sql, $tid));
		
		if (can_manage_forum() || $owner == $current_user->ID) {
			if (__wps__safe_param($tid)) {
				$wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d", $tid));
			}
		
			echo $tid;
			
			// Hook for more actions
			do_action('symposium_forum_delete_reply_hook', $owner, $tid);			
		
		} else {
			echo "NOT ADMIN OR OWNER";
		}
	
	}
}