options = $this->get_forum_admin_ops();
$this->get_set_ads_options();
if($this->options['forum_use_seo_friendly_urls'])
{
add_filter("init", array(&$this, "flush_wp_rewrite_rules"));
add_filter("rewrite_rules_array", array(&$this, "set_seo_friendly_rules"));
}
add_action("admin_menu", array(&$this,"add_admin_pages"));
add_action("admin_head", array(&$this, "admin_header"));
add_action("wp_head", array(&$this, "setup_header"));
add_action("plugins_loaded", array(&$this, "wpf_load_widget"));
add_action("wp_footer", array(&$this, "wpf_footer"));
if($this->options['wp_posts_to_forum'])
{
add_action("add_meta_boxes", array(&$this, "send_wp_posts_to_forum"));
add_action("publish_post", array(&$this, "saving_posts"));
}
//Ads filter hooks
add_filter('mf_ad_above_forum', array(&$this, 'mf_ad_above_forum'));
add_filter('mf_ad_below_forum', array(&$this, 'mf_ad_below_forum'));
add_filter('mf_ad_above_branding', array(&$this, 'mf_ad_above_branding'));
add_filter('mf_ad_above_info_center', array(&$this, 'mf_ad_above_info_center'));
add_filter('mf_ad_above_quick_reply', array(&$this, 'mf_ad_above_quick_reply'));
add_filter('mf_ad_above_breadcrumbs', array(&$this, 'mf_ad_above_breadcrumbs'));
add_filter('mf_ad_below_first_post', array(&$this, 'mf_ad_below_first_post'));
$this->init();
}
// !Member variables
var $showing = false;
var $page_id = "";
var $reg_link = "";
var $profile_link = "";
var $logout_link = "";
var $home_url = "";
var $forum_link = "";
var $group_link = "";
var $thread_link = "";
var $add_topic_link = "";
// DB tables
var $t_forums = "";
var $t_threads = "";
var $t_posts = "";
var $t_usergroups = "";
var $t_usergroup2user = "";
var $o = "";
var $current_group = "";
var $current_forum = "";
var $current_thread = "";
var $notify_msg = "";
var $current_view = "";
var $opt = array();
var $base_url = "";
var $skin_url = "";
var $curr_page = "";
var $last_visit = "";
var $user_options = array();
var $options = array();
var $ads_options = array();
// Initialize varables
function init(){
global $table_prefix;
$this->page_id = $this->get_pageid();
$this->profile_link = site_url()."/wp-admin/profile.php";
$this->t_forums = $table_prefix."forum_forums";
$this->t_threads = $table_prefix."forum_threads";
$this->t_posts = $table_prefix."forum_posts";
$this->t_usergroups = $table_prefix."forum_usergroups";//! check this later
$this->t_usergroup2user = $table_prefix."forum_usergroup2user"; //x testing
$this->current_forum = false;
$this->current_group = false;
$this->current_thread = false;
$this->curr_page = 0;
$this->user_options = array('allow_profile' => true,
'signature' => ""
);
// Get the options
$this->opt = get_option('mingleforum_options');
$this->skin_url = SKINURL.$this->opt['forum_skin'];
}
function get_set_ads_options() {
$this->ads_options = array( 'mf_ad_above_forum_on' => false,
'mf_ad_above_forum' => '',
'mf_ad_below_forum_on' => false,
'mf_ad_below_forum' => '',
'mf_ad_above_branding_on' => false,
'mf_ad_above_branding' => '',
'mf_ad_above_info_center_on' => false,
'mf_ad_above_info_center' => '',
'mf_ad_above_quick_reply_on' => false,
'mf_ad_above_quick_reply' => '',
'mf_ad_above_breadcrumbs_on' => false,
'mf_ad_above_breadcrumbs' => '',
'mf_ad_below_first_post_on' => false,
'mf_ad_below_first_post' => '',
'mf_ad_custom_css' => ''
);
$initOps = get_option('mingleforum_ads_options');
if (!empty($initOps)){
foreach ($initOps as $key => $option)
$this->ads_options[$key] = $option;
}
update_option('mingleforum_ads_options', $this->ads_options);
}
function get_forum_admin_ops() {
$this->options = array( 'wp_posts_to_forum' => false,
'forum_posts_per_page' => 10,
'forum_threads_per_page' => 20,
'forum_require_registration' => true,
'forum_show_login_form' => true,
'forum_date_format' => get_option('date_format'),
'forum_use_gravatar' => true,
'forum_show_bio' => true,
'forum_skin' => "Default",
'forum_use_rss' => true,
'forum_use_seo_friendly_urls' => false,
'forum_allow_image_uploads' => false,
'notify_admin_on_new_posts' => false,
'set_sort' => "DESC",
'forum_use_spam' => false,
'forum_use_bbcode' => true,
'forum_captcha' => true,
'hot_topic' => 15,
'veryhot_topic' => 25,
'forum_display_name' => 'user_login',
'level_one' => 25,
'level_two' => 50,
'level_three' => 100,
'level_newb_name' => __("Newbie", "mingleforum"),
'level_one_name' => __("Beginner", "mingleforum"),
'level_two_name' => __("Advanced", "mingleforum"),
'level_three_name' => __("Pro", "mingleforum"),
'forum_db_version' => 0,
'forum_disabled_cats' => array(),
'allow_user_replies_locked_cats' => false,
'forum_posting_time_limit' => 300,
'forum_hide_branding' => false,
'forum_last_posts' => 0
);
$initOps = get_option('mingleforum_options');
//Don't overwrite current opitions but allow the flexibility to add more options
if (!empty($initOps)){
foreach ($initOps as $key => $option)
$this->options[$key] = $option;
}
update_option('mingleforum_options', $this->options);
return $this->options;
}
// Add admin pages
function add_admin_pages(){
include_once("fs-admin/fs-admin.php");
$wpfa = new mingleforumadmin();
add_menu_page(__("Mingle Forum - Options", "mingleforum"), "Mingle Forum", "administrator", "mingle-forum", array(&$wpfa, "options"), WPFURL."images/logo.png");
add_submenu_page("mingle-forum", __("Mingle Forum - Options", "mingleforum"), __("Options", "mingleforum"), "administrator", 'mingle-forum', array(&$wpfa, "options"));
add_submenu_page('mingle-forum', __('Ads', 'mingleforum'), __('Ads', 'mingleforum'), "administrator", 'mfads', array(&$wpfa, "ads"));
add_submenu_page("mingle-forum", __("Skins", "mingleforum"), __("Skins", "mingleforum"), "administrator", 'mfskins', array(&$wpfa, "skins"));
add_submenu_page("mingle-forum", __("Forum Structure - Categories & Forums", "mingleforum"), __("Forum Structure", "mingleforum"), "administrator", 'mfstructure', array(&$wpfa, "structure"));
add_submenu_page("mingle-forum", __("Moderators", "mingleforum"), __("Moderators", "mingleforum"), "administrator", 'mfmods', array(&$wpfa, "moderators"));
add_submenu_page("mingle-forum", __("User Groups", "mingleforum"), __("User Groups", "mingleforum"), "administrator", 'mfgroups', array(&$wpfa, "usergroups"));
add_submenu_page("mingle-forum", __("About", "mingleforum"), __("About", "mingleforum"), "administrator", 'mfabout', array(&$wpfa, "about"));
}
function admin_header(){
wp_enqueue_style('mingle-forum', plugins_url('wpf_admin.css', __FILE__));
wp_enqueue_script('mingle-forum', plugins_url('js/script.js', __FILE__), array('jquery'));
}
function wpf_load_widget() {
wp_register_sidebar_widget("MFWidget", __("Forums Latest Activity", "mingleforum"), array(&$this, "widget"));
wp_register_widget_control("MFWidget", __("Forums Latest Activity", "mingleforum"), array(&$this, "widget_wpf_control"));
}
function widget($args) {
global $wpdb;
$toShow = 0;
$unique = array();
$this->setup_links();
$this->get_forum_admin_ops();
$widget_option = get_option("wpf_widget");
$posts = $wpdb->get_results("SELECT * FROM $this->t_posts ORDER BY `date` DESC LIMIT 50");
echo $args['before_widget'];
echo $args['before_title'] . $widget_option["wpf_title"] . $args['after_title'];
echo "
";
foreach($posts as $post) {
if(!in_array($post->parent_id, $unique) && $toShow < $widget_option["wpf_num"])
{
//$user = get_userdata($post->author_id);
if($this->have_access($this->forum_get_group_from_post($post->parent_id)) && $this->have_access($this->forum_get_forum_from_post($post->parent_id)))
echo "id)."'>".$this->output_filter($post->subject)." ".__("by:", "mingleforum")." ".$this->profile_link($post->author_id)."".$this->format_date($post->date)." ";
$unique[] = $post->parent_id;
$toShow += 1;
}
}
echo " ";
echo $args['after_widget'];
}
function latest_activity($num = 5, $ul = true){
global $wpdb;
$toShow = 0;
$unique = array();
$posts = $wpdb->get_results("SELECT * FROM $this->t_posts ORDER BY `date` DESC LIMIT 50");
if($ul) echo "";
foreach($posts as $post){
if(!in_array($post->parent_id, $unique) && $toShow < $num)
{
//$user = get_userdata($post->author_id);
if($this->have_access($this->forum_get_group_from_post($post->parent_id)) && $this->have_access($this->forum_get_forum_from_post($post->parent_id)))
echo "id)."'>".$this->output_filter($post->subject)." ".__("by:", "mingleforum")." ".$this->profile_link($post->author_id)."".$this->format_date($post->date)." ";
$unique[] = $post->parent_id;
$toShow += 1;
}
}
if($ul)echo " ";
}
function widget_wpf_control(){
if (isset($_POST["wpf_submit"])) {
$name = strip_tags(stripslashes($_POST["wpf_title"]));
$num = strip_tags(stripslashes($_POST["wpf_num"]));
$widget_option["wpf_title"] = $name;
$widget_option["wpf_num"] = $num;
update_option("wpf_widget", $widget_option);
}
$widget_option = get_option("wpf_widget");
echo "".__("Title to display in the sidebar:", "mingleforum")."
";
echo "".__("How many items would you like to display?", "mingleforum");
echo "";
for($i = 1; $i < 21; ++$i){
if($widget_option["wpf_num"] == $i)
$selected = "selected = 'selected'";
else
$selected = "";
echo "$i ";
}
echo " ";
echo "
";
}
function wpf_footer(){
if(is_page($this->get_pageid()))
{
?>
using_permalinks())
$delim = "?";
else
$delim = "&";
$perm = get_permalink($this->page_id);
$this->forum_link = $perm.$delim."mingleforumaction=viewforum&f=";
$this->group_link = $perm.$delim."mingleforumaction=vforum&g=";
$this->thread_link = $perm.$delim."mingleforumaction=viewtopic&t=";
$this->add_topic_link = $perm.$delim."mingleforumaction=addtopic&forum=$this->current_forum";
$this->post_reply_link = $perm.$delim."mingleforumaction=postreply&thread=$this->current_thread";
$this->base_url = $perm.$delim."mingleforumaction=";
$this->reg_link = wp_login_url()."?action=register";
//END MINGLE REG LINK
$this->topic_feed_url = WPFURL."feed.php?topic=";
$this->global_feed_url = WPFURL."feed.php?topic=all";
$this->home_url = $perm;
$this->logout_link = wp_logout_url(get_permalink($this->get_pageid()));
}
function setup_linksdk($perm){
global $wp_rewrite;
if($wp_rewrite->using_permalinks())
$delim = "?";
else
$delim = "&";
$this->forum_link = $perm.$delim."mingleforumaction=viewforum&f=";
$this->group_link = $perm.$delim."mingleforumaction=vforum&g=";
$this->thread_link = $perm.$delim."mingleforumaction=viewtopic&t=";
$this->add_topic_link = $perm.$delim."mingleforumaction=addtopic&forum=$this->current_forum";
$this->post_reply_link = $perm.$delim."mingleforumaction=postreply&thread=$this->current_thread";
$this->base_url = $perm.$delim."mingleforumaction=";
$this->reg_link = wp_login_url()."?action=register";
//END MINGLE REG LINK
$this->topic_feed_url = WPFURL."feed.php?topic=";
$this->global_feed_url = WPFURL."feed.php?topic=all";
$this->home_url = $perm;
$this->logout_link = wp_logout_url(get_permalink($this->get_pageid()));
}
function get_addtopic_link(){
return $this->add_topic_link.".$this->curr_page";
}
function get_post_reply_link(){
return $this->post_reply_link.".$this->curr_page";
}
function get_forumlink($id, $page = ''){
if($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($this->forum_get_parent($id))."-group".$this->forum_get_parent($id));
$forum = $this->get_seo_friendly_title($this->get_forumname($id)."-forum".$id).$page;
return rtrim($this->home_url, '/').'/'.$group.'/'.$forum;
}
else
if($page == '')
return $this->forum_link.$id.".$this->curr_page";
else
return $this->forum_link.$id.$page;
}
function get_grouplink($id){
if($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($id)."-group".$id);
return rtrim($this->home_url, '/').'/'.$group;
}
else
return $this->group_link.$id.".$this->curr_page";
}
function get_threadlink($id, $page = ''){
if($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($this->forum_get_parent($this->forum_get_forum_from_post($id)))."-group".$this->forum_get_parent($this->forum_get_forum_from_post($id)));
$forum = $this->get_seo_friendly_title($this->get_forumname($this->forum_get_forum_from_post($id))."-forum".$this->forum_get_forum_from_post($id));
$thread = $this->get_seo_friendly_title($this->get_subject($id)."-thread".$id);
return rtrim($this->home_url, '/').'/'.$group.'/'.$forum.'/'.$thread.$page;
}
else
return $this->thread_link.$id.$page;
}
function get_paged_threadlink($id, $postid = ''){
global $wpdb;
$wpdb->query("SELECT * FROM {$this->t_posts} WHERE parent_id = {$id}");
$num = ceil($wpdb->num_rows / $this->options['forum_posts_per_page']) - 1;
if($num < 0)
$num = 0;
if($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($this->forum_get_parent($this->forum_get_forum_from_post($id)))."-group".$this->forum_get_parent($this->forum_get_forum_from_post($id)));
$forum = $this->get_seo_friendly_title($this->get_forumname($this->forum_get_forum_from_post($id))."-forum".$this->forum_get_forum_from_post($id));
$thread = $this->get_seo_friendly_title($this->get_subject($id)."-thread".$id);
return rtrim($this->home_url, '/').'/'.$group.'/'.$forum.'/'.$thread.".".$num.$postid;
}
else
return $this->thread_link.$id.".".$num.$postid;
}
function get_pageid(){
global $wpdb;
return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content LIKE '%[mingleforum]%' AND post_status = 'publish' AND post_type = 'page'");
}
function get_forums($id = 0){
global $wpdb;
$forums = $wpdb->get_results("SELECT * FROM $this->t_forums WHERE parent_id = $id ORDER BY SORT ".SORT_ORDER);
return $forums;
}
function get_threads($id = ''){
global $wpdb;
$start = $this->curr_page*$this->opt['forum_threads_per_page'];
$end = $this->opt['forum_threads_per_page'];
$limit = "$start, $end";
if($id){
$threads = $wpdb->get_results("SELECT * FROM $this->t_threads WHERE parent_id = $id AND status='open' ORDER BY last_post ".SORT_ORDER." LIMIT $limit");
return $threads;
}
else
return $wpdb->get_results("SELECT * FROM $this->t_threads ORDER BY `date` ".SORT_ORDER);
}
function get_sticky_threads($id){
global $wpdb;
if($id){
$threads = $wpdb->get_results("SELECT * FROM $this->t_threads WHERE parent_id = $id AND status='sticky' ORDER BY last_post ".SORT_ORDER);
return $threads;
}
}
function get_posts($thread_id){
global $wpdb;
$start = $this->curr_page*$this->opt['forum_posts_per_page'];
$end = $this->opt['forum_posts_per_page'];
$limit = "$start, $end";
if($thread_id){
$posts = $wpdb->get_results("SELECT * FROM $this->t_posts WHERE parent_id = $thread_id ORDER BY `date` ASC LIMIT $limit");
return $posts;
}else{
return false;
}
}
function get_groupname($id){
global $wpdb;
return $this->output_filter($wpdb->get_var("SELECT name FROM $this->t_forums WHERE id = $id"));
}
function get_forumname($id){
global $wpdb;
return $this->output_filter($wpdb->get_var("SELECT name FROM $this->t_forums WHERE id = $id"));
}
function get_threadname($id){
global $wpdb;
return $this->output_filter($wpdb->get_var("SELECT subject FROM $this->t_threads WHERE id = $id"));
}
function get_postname($id){
global $wpdb;
return $this->output_filter($wpdb->get_var("SELECT subject FROM $this->t_posts WHERE id = $id"));
}
function get_group_description($id){
global $wpdb;
return $wpdb->get_var("SELECT description FROM $this->t_forums WHERE id = $id");
}
function get_forum_description($id){
global $wpdb;
return $wpdb->get_var("SELECT description FROM $this->t_forums WHERE id = $id");
}
function current_group(){
return $this->current_group;
}
function current_forum(){
return $this->current_forum;
}
function current_thread(){
return $this->current_thread;
}
function check_parms($parm){
$regexp = "/^([+-]?((([0-9]+(\.)?)|([0-9]*\.[0-9]+))([eE][+-]?[0-9]+)?))$/";
if (!preg_match($regexp, $parm)){
wp_die("Bad request, please re-enter.");
}
$p = explode(".", $parm);
if(count($p) > 1)
$this->curr_page = $p[1];
else
$this->curr_page = 0;
return $p[0];
}
function before_go()
{
$this->setup_links();
if(isset($_GET['markallread']) && $_GET['markallread'] == "true")
$this->markallread();
if(isset($_GET['mingleforumaction']))
$action = $_GET['mingleforumaction'];
else
$action = false;
if (!isset($_GET['getNewForumID']) && !isset($_GET['delete_topic']) && !isset($_GET['remove_post']) && !isset($_GET['forumsubs']) && !isset($_GET['threadsubs']) && !isset($_GET['sticky']) && !isset($_GET['closed']))
{
if ($action != false)
{
if ($this->options['forum_use_seo_friendly_urls'])
{
switch($action)
{
case 'vforum':
$whereto = $this->get_grouplink($this->check_parms($_GET['g']));
break;
case 'viewforum':
$whereto = $this->get_forumlink($this->check_parms($_GET['f']));
break;
case 'viewtopic':
$whereto = $this->get_threadlink($this->check_parms($_GET['t']));
break;
}
if (!empty($whereto))
{
header("HTTP/1.1 301 Moved Permanently");
if($this->curr_page > 0)
header("Location: ".$whereto.".".$this->curr_page);
else
header("Location: ".$whereto);
}
}
}
}
}
function go() {
global $user_ID;
get_currentuserinfo();
$this->o = "";
if($user_ID){
if(get_user_meta($user_ID, 'wpf_useroptions', true) == ''){
update_user_meta($user_ID, 'wpf_useroptions', $this->user_options);
}
}
if(isset($_GET['mingleforumaction']))
$action = $_GET['mingleforumaction'];
else
$action = false;
if ($action == false)
{
if ($this->options['forum_use_seo_friendly_urls'])
{
$uri = $this->get_seo_friendly_query();
if (!empty($uri) && $uri['action'] && $uri['id'])
{
switch($uri['action'])
{
case 'group':
$action = 'vforum';
$_GET['g'] = $uri['id'];
break;
case 'forum':
$action = 'viewforum';
$_GET['f'] = $uri['id'];
break;
case 'thread':
$action = 'viewtopic';
$_GET['t'] = $uri['id'];
break;
}
}
}
}
if($action){
switch($action){
case 'viewforum':
$this->current_view = FORUM;
$this->showforum($this->check_parms($_GET['f']));
break;
case 'viewtopic':
$this->current_view = THREAD;
$this->showthread($this->check_parms($_GET['t']));
break;
case 'addtopic':
include(WPFPATH.'wpf-thread.php');
break;
case 'postreply':
if($this->is_closed($_GET['thread'])){
wp_die(__("An unknown error has occured. Please try again.", "mingleforum"));
}else{
$this->current_thread = $this->check_parms($_GET['thread']);
include(WPFPATH.'wpf-post.php');
}
break;
case 'shownew':
$this->show_new();
break;
case 'editpost':
include(WPFPATH.'wpf-post.php');
break;
case 'profile':
$this->view_profile();
break;
case 'search':
$this->search_results();
break;
case 'editprofile':
include(WPFPATH.'wpf-edit-profile.php');
break;
case 'vforum':
$this->vforum($this->check_parms($_GET['g']));
break;
}
}
else{
$this->current_view = MAIN;
$this->mydefault();
}
if(!$this->options['forum_hide_branding'])
{
$this->o .= apply_filters('mf_ad_above_branding', ''); //Adsense Area -- Above Branding
}
$above_forum_ad = apply_filters('mf_ad_above_forum', ''); //Adsense Area -- Above Forum
$below_forum_ad = apply_filters('mf_ad_below_forum', ''); //Adsense Area -- Below Forum
return $above_forum_ad."".$this->o."
".$below_forum_ad;
}
function get_version(){
$plugin_data = implode('', file(ABSPATH."wp-content/plugins/".WPFPLUGIN."/wpf-main.php"));
$version = '';
if (preg_match("|Version:(.*)|i", $plugin_data, $version))
$version = $version[1];
return $version;
}
function get_userdata($user_id, $data){
$user = get_userdata($user_id);
if(!$user)
return __("Guest", "mingleforum");
return $user->$data;
}
function get_lastpost($thread_id){
global $wpdb;
$post = $wpdb->get_row("select `date`, author_id, id from $this->t_posts where parent_id = $thread_id order by `date` DESC limit 1");
if (!empty($post)) {
$link = $this->get_paged_threadlink($thread_id);
return __("by", "mingleforum")." ".$this->profile_link($post->author_id)." ".__("on", "mingleforum")." ".date_i18n($this->opt['forum_date_format'], strtotime($post->date))." ";
}
else
return false;
}
function get_lastpost_all(){
global $wpdb;
$post = $wpdb->get_row("select `date`, author_id, id from $this->t_posts order by `date` DESC limit 1");
return __("Latest Post by", "mingleforum")." ".$this->profile_link($post->author_id)." ".__("on", "mingleforum")." ".date_i18n($this->opt['forum_date_format'], strtotime($post->date));
}
function showsubforum($forum_id) {
global $user_ID;
$out = $alt = '';
$frs = $this->get_forums($forum_id);
foreach($frs as $f){
if ($this->have_access($f->id)){
$alt = ($alt=="alt even")?"odd":"alt even";
$out .= "";
$image = "off.gif";
if($user_ID){
$lpif = $this->last_poster_in_forum($f->id, true);
$last_posterid = $this->last_posterid($f->id);
if($last_posterid != $user_ID){
$lp = strtotime($lpif); // date
$lv = strtotime($this->last_visit());
if($lv < $lp)
$image = "on.gif";
}
}
$out .= "
"
.$this->output_filter($f->name)." "
.$this->output_filter($f->description);
if($f->description != "") $out .= " ";
$out .= $this->get_sub_forums($f->id);
$out .= $this->get_forum_moderators($f->id)
." ";
$out .= "".__("Topics: ", "mingleforum").$this->num_threads($f->id)." ".__("Posts: ", "mingleforum").$this->num_posts_forum($f->id)." ";
$out .= "".$this->last_poster_in_forum($f->id)." ";
$out .= " ";
}
}
return $out;
}
function showforum($forum_id){
global $user_ID;
if(isset($_GET['delete_topic']))
$this->remove_topic();
if(isset($_GET['move_topic']))
$this->move_topic();
if(!empty($forum_id)){
$out = "";
$del = "";
$threads = $this->get_threads($forum_id);
$sticky_threads = $this->get_sticky_threads($forum_id);
$this->current_group = $this->forum_get_group_id($forum_id);
$this->current_forum = $forum_id;
$this->forum_subscribe();
if($this->is_forum_subscribed())
$this->notify_msg = __("Remove this Forum from your email notifications?", "mingleforum");
else
$this->notify_msg = __("This will notify you of all new Topics created in this Forum. Are you sure that is what you want to do?", "mingleforum");
$this->header();
if(isset($_GET['getNewForumID'])){
$out .= $this->getNewForumID();
}else{
if(!$this->have_access($this->current_group) || !$this->have_access($this->current_forum)){
wp_die(__("Sorry, but you don't have access to this forum", "mingleforum"));
}
$subforums = $this->showsubforum($this->current_forum);
if (!empty($subforums)) {
$out .= "
".__("Subforums", "mingleforum")." ";
$out .= $subforums;
$out .= "
";
}
$out .= "";
$out .= "
".__("Status", "mingleforum")."
".__("Topic Title", "mingleforum")."
".__("Started by", "mingleforum")."
".__("Replies", "mingleforum")."
".__("Views", "mingleforum")."
".__("Last post", "mingleforum")."
";
/***************************************************************************************/
if($sticky_threads){
$out .= "".__("Sticky Topics", "mingleforum")." ";
foreach($sticky_threads as $thread){
if($this->is_moderator($user_ID, $this->current_forum)){
if($this->options['forum_use_seo_friendly_urls'])
$strCommands = "".__("Move Topic", "mingleforum")." | ".__("Delete Topic", "mingleforum")." ";
else
$strCommands = "".__("Move Topic", "mingleforum")." | ".__("Delete Topic", "mingleforum")." ";
$del = " ($strCommands) ";
}
$image = "";
if($user_ID){
$poster_id = $this->last_posterid_thread($thread->id); // date and author_id
if($user_ID != $poster_id){
$lp = strtotime($this->last_poster_in_thread($thread->id)); // date
$lv = strtotime($this->last_visit());
if($lp > $lv)
$image = " ";
}
}
$sticky_img = " ";
$out .= "
$sticky_img
"
.$this->output_filter($thread->subject)." $image $del
".$this->profile_link($thread->starter)."
".( $this->num_posts($thread->id) - 1 )."
".$thread->views."
".$this->get_lastpost($thread->id)."
";
}
/********************************************************************************************************/
$out .= "".__("Forum Topics", "mingleforum")." ";
}
$alt = "alt even";
foreach($threads as $thread){
$alt = ($alt=="alt even")?"odd":"alt even";
if($user_ID){
$image = "";
$poster_id = $this->last_posterid_thread($thread->id); // date and author_id
if($user_ID != $poster_id){
$lp = strtotime($this->last_poster_in_thread($thread->id)); // date
$lv = strtotime($this->last_visit());
if($lp > $lv)
$image = " ";
}
}
if($this->is_moderator($user_ID, $this->current_forum)){
if($this->options['forum_use_seo_friendly_urls'])
$strCommands = "".__("Move Topic", "mingleforum")." | ".__("Delete Topic", "mingleforum")." ";
else
$strCommands = "".__("Move Topic", "mingleforum")." | ".__("Delete Topic", "mingleforum")." ";
$del = " ($strCommands) ";
}
$out .= "
".$this->get_topic_image($thread->id)."
"
.$this->output_filter($thread->subject)." $image $del
".$this->profile_link($thread->starter)."
".( $this->num_posts($thread->id) - 1 )."
".$thread->views."
".$this->get_lastpost($thread->id)."
";
}
$out .= "
";
$out .= "";
}
$out .= $this->trail("bottom");
$this->o .= $out;
$this->footer();
}
}
function get_subject($id){
global $wpdb;
return stripslashes($wpdb->get_var("SELECT subject FROM $this->t_threads WHERE id = $id"));
}
function showthread($thread_id){
global $wpdb, $user_ID;
$this->current_group = $this->forum_get_group_from_post($thread_id);
$this->current_forum = $this->forum_get_forum_from_post($thread_id);
$this->current_thread = $thread_id;
if(isset($_GET['remove_post']))
$this->remove_post();
if(isset($_GET['sticky']))
$this->sticky_post();
$this->thread_subscribe();
$posts = $this->get_posts($thread_id);
if($posts){
if($this->is_thread_subscribed())
$this->notify_msg = __("Remove this Topic from your email notifications?", "mingleforum");
else
$this->notify_msg = __("This will notify you of all responses to this Topic. Are you sure that is what you want to do?", "mingleforum");
if(!current_user_can('administrator') && !is_super_admin($user_ID) && !$this->is_moderator($user_ID, $this->current_forum))
$wpdb->query("UPDATE {$this->t_threads} SET views = views+1 WHERE id = {$thread_id}");
if($this->is_sticky($thread_id))
$image = "normal_post_sticky.gif";
else
$image = $this->get_topic_image_two($thread_id);
if(!$this->have_access($this->current_group) || !$this->have_access($this->current_forum)){
wp_die(__("Sorry, but you don't have access to this forum", "mingleforum"));
}
$this->header();
$out = "";
if ($this->is_closed())
$meClosed = " ".__("TOPIC CLOSED", "mingleforum")." ";
else
$meClosed = "";
$out .= "
".__("Author", "mingleforum")."
".$this->get_subject($thread_id).$meClosed."
";
$out .= "
";
$class = "";
$c = 0;
foreach($posts as $post){
$class = ($class == "wpf-alt")?"":"wpf-alt";
$user = get_user_meta($post->author_id, "wpf_useroptions", true);
$out .= "
".
$this->profile_link($post->author_id);
$out .= "";
$out .= $this->get_userrole($post->author_id)."
";
$out .= __("Posts:", "mingleforum")." ".$this->get_userposts_num($post->author_id)."
";
$out .= '
Permalink ';
if($this->opt["forum_use_gravatar"])
$out .= $this->get_avatar($post->author_id);
$out .= "
".apply_filters('mf_below_post_avatar', '', $post->author_id, $post->id)."
";
if(!$c)
$out .= apply_filters('mf_ad_below_first_post', ''); //Adsense Area -- Below First Post
$out .= "
";
$c += 1;
}
$quick_thread = $this->check_parms($_GET['t']);
//QUICK REPLY AREA
if(!in_array($this->current_group, $this->options['forum_disabled_cats']) || is_super_admin() || $this->is_moderator($user_ID, $this->current_forum) || $this->options['allow_user_replies_locked_cats'])
{
if(!$this->is_closed() && ($user_ID || !$this->options['forum_require_registration']) && $this->have_access($this->current_forum, 'post') && $this->have_access($this->current_group, 'post')) {
$parser = new cartpaujBBCodeParser();
$out .= "";
}
}
$out .= "";
$out .= $this->trail("bottom");
$this->o .= $out;
$this->footer();
}
}
function get_postmeta($post_id, $author_id){
global $user_ID;
$image = " ";
$o = "
$image ".$this->get_postname($post_id)." ".__("on:", "mingleforum")." ".$this->get_postdate($post_id)." ";
if(!in_array($this->current_group, $this->options['forum_disabled_cats']) || is_super_admin() || $this->is_moderator($user_ID, $this->current_forum) || $this->options['allow_user_replies_locked_cats'])
{
if($this->options['forum_use_seo_friendly_urls'])
{
if($user_ID && !$this->is_closed() && $this->have_access($this->current_forum, 'post') && $this->have_access($this->current_group, 'post'))
$o .= " ".__("Quote", "mingleforum")." ";
if($this->is_moderator($user_ID, $this->current_forum))
$o .= " ".__("Remove", "mingleforum")." ";
if(($this->is_moderator($user_ID, $this->current_forum)) || ($user_ID == $author_id && $user_ID))
$o .= "" .__("Edit", "mingleforum")." ";
}
else
{
if($user_ID && !$this->is_closed() && $this->have_access($this->current_forum, 'post') && $this->have_access($this->current_group, 'post'))
$o .= " ".__("Quote", "mingleforum")." ";
if($this->is_moderator($user_ID, $this->current_forum))
$o .= " ".__("Remove", "mingleforum")." ";
if(($this->is_moderator($user_ID, $this->current_forum)) || ($user_ID == $author_id && $user_ID))
$o .= "" .__("Edit", "mingleforum")." ";
}
}
$o .= "
";
return $o;
}
function get_postdate($post){
global $wpdb;
return $this->format_date($wpdb->get_var("select `date` from $this->t_posts where id = $post"));
}
function format_date($date){
if($date)
return date_i18n($this->opt['forum_date_format'], strtotime($date));
else
return false;
}
function wpf_current_time_fixed( $type, $gmt = 0 ) {
$t = ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
switch ( $type ) {
case 'mysql':
return $t;
break;
case 'timestamp':
return strtotime($t);
break;
}
}
function get_userposts_num($id){
global $wpdb;
return $wpdb->get_var("select count(*) from $this->t_posts where author_id = $id");
}
function get_post_owner($id) {
global $wpdb;
return $wpdb->get_var($wpdb->prepare("SELECT `author_id` FROM {$this->t_posts} WHERE `id` = %d", $id));
}
function show_last_posts() {
global $wpdb, $user_ID;
if ($this->opt['forum_last_posts']) {
$alt = ($alt == "alt even") ? "odd" : "alt even";
$posts = $wpdb->get_results("SELECT * FROM `$this->t_threads` ORDER BY `last_post` DESC LIMIT " . $this->opt['forum_last_posts']);
$nb_valid = 0;
foreach ($posts as $thread) {
if ($this->have_access($thread->parent_id)) {
$nb_valid++;
}
}
if ($nb_valid) {
$this->o .= "";
$this->o .= "" . __("Latest posts", "mingleforum") . "";
foreach ($posts as $thread) {
if ($this->have_access($thread->parent_id)) {
if ($user_ID) {
$image = "";
$poster_id = $this->last_posterid_thread($thread->id); // date and author_id
if ($user_ID != $poster_id) {
$lp = strtotime($this->last_poster_in_thread($thread->id)); // date
$lv = strtotime($this->last_visit());
if ($lp > $lv)
$image = " ";
}
}
$this->o .= "
" . $this->get_topic_image($thread->id) . "
"
. $this->output_filter($thread->subject) . " $image
" . __("Replies", "mingleforum") . ": " . ( $this->num_posts($thread->id) - 1 ) . " " . __("Views", "mingleforum") . ": " . $thread->views . "
" . $this->get_lastpost($thread->id) . "
";
}
}
$this->o .= "
";
}
}
}
function mydefault(){
global $wp_rewrite;
if($wp_rewrite->using_permalinks())
$delim = "?";
else
$delim = "&";
$grs = $this->get_forums();
$this->header();
$this->show_last_posts();
foreach($grs as $g){
if($this->have_access($g->id)){
$this->o .= " ";
}
}
$this->o .= apply_filters('wpwf_new_posts'," ");
$this->footer();
}
function vforum($groupid){
global $user_ID;
$alt = "";
$grs = $this->get_forums($groupid);
$this->current_group = $groupid;
$this->header();
foreach($grs as $g){
if($this->have_access($g->id)){
$this->o .= "";
$this->o .= "".$this->output_filter($g->name)." ";
$frs = $this->get_forums($g->id);
foreach($frs as $f){
if ($this->have_access($f->id)) {
$alt = ($alt=="alt even")?"odd":"alt even";
$this->o .= "";
$image = "off.gif";
if($user_ID){
$lpif = $this->last_poster_in_forum($f->id, true);
$last_posterid = $this->last_posterid($f->id);
if($last_posterid != $user_ID){
$lp = strtotime($lpif); // date
$lv = strtotime($this->last_visit());
if($lv < $lp)
$image = "on.gif";
else
$image = "off.gif";
}
}
$this->o .= "
"
.$this->output_filter($f->name)." "
.$this->output_filter($f->description);
if($f->description != "")$this->o .= " ";
$this->o .= $this->get_forum_moderators($f->id)
." ";
$this->o .= "".__("Topics: ", "mingleforum").$this->num_threads($f->id)." ".__("Posts: ", "mingleforum").$this->num_posts_forum($f->id)." ";
$this->o .= "".$this->last_poster_in_forum($f->id)." ";
$this->o .= " ";
}
}
$this->o .= "
";
}
}
$this->o .= apply_filters('wpwf_new_posts',"
".__("New posts", "mingleforum")." ".__("No new posts", "mingleforum")."
");
$this->footer();
}
function output_filter($string){
$parser = new cartpaujBBCodeParser();
return stripslashes($parser->bbc2html($string));
}
function input_filter($string){
$Find = array("<", "%", "$");
$Replace = array("<", "%", "$");
$newStr = str_replace($Find, $Replace, $string);
return $newStr;
}
function sig_input_filter($string){
$Find = array("<", "%", "$");
$Replace = array("<", "%", "$");
$newStr = str_replace($Find, $Replace, $string);
return $newStr;
}
function last_posterid($forum){
global $wpdb;
return $wpdb->get_var("SELECT $this->t_posts.author_id FROM $this->t_posts INNER JOIN $this->t_threads ON $this->t_posts.parent_id=$this->t_threads.id WHERE $this->t_threads.parent_id = $forum ORDER BY $this->t_posts.date DESC");
}
function last_posterid_thread($thread_id){
global $wpdb;
return $wpdb->get_var("SELECT $this->t_posts.author_id FROM $this->t_posts INNER JOIN $this->t_threads ON $this->t_posts.parent_id=$this->t_threads.id WHERE $this->t_posts.parent_id = $thread_id ORDER BY $this->t_posts.date DESC");
}
function num_threads($forum){
global $wpdb;
return $wpdb->get_var("select count(id) from $this->t_threads where parent_id = $forum ");
}
function num_posts_forum($forum){
global $wpdb;
return $wpdb->get_var("SELECT count($this->t_posts.id) FROM $this->t_posts INNER JOIN $this->t_threads ON $this->t_posts.parent_id=$this->t_threads.id WHERE $this->t_threads.parent_id = $forum ORDER BY $this->t_posts.date DESC");
}
function num_posts_total(){
global $wpdb;
return $wpdb->get_var("select count(id) from $this->t_posts");
}
function num_posts($thread_id){
global $wpdb;
return $wpdb->get_var("select count(id) from $this->t_posts where parent_id = $thread_id ");
}
function num_threads_total(){
global $wpdb;
return $wpdb->get_var("select count(id) from $this->t_threads");
}
function last_poster_in_forum($forum, $post_date = false){
global $wpdb;
$date = $wpdb->get_row("SELECT $this->t_posts.date, $this->t_posts.id, $this->t_posts.parent_id, $this->t_posts.author_id FROM $this->t_posts INNER JOIN $this->t_threads ON $this->t_posts.parent_id=$this->t_threads.id WHERE $this->t_threads.parent_id = $forum ORDER BY $this->t_posts.date DESC");
if($post_date && is_object($date))
return $date->date;
if(!$date)
return __("No topics yet", "mingleforum");
$d = date_i18n($this->opt['forum_date_format'], strtotime($date->date));
return "".__("Last post", "mingleforum")." ".__("by", "mingleforum")." ".$this->profile_link($date->author_id)
." ".__("in", "mingleforum")." ".$this->get_threadname($date->parent_id)." ".__("on", "mingleforum")." $d";
}
function last_poster_in_thread($thread_id) {
global $wpdb;
return $wpdb->get_var("select `date` from $this->t_posts where parent_id = $thread_id order by `date` DESC");
}
function have_access($groupid, $type='access') {
global $wpdb, $user_ID;
if(current_user_can("administrator") || is_super_admin($user_ID))
return true;
switch ($type) {
case 'access':
$type = 'usergroups';
break;
case 'post':
$type = 'usercanpost';
break;
}
$user_groups = maybe_unserialize($wpdb->get_var("select $type from {$this->t_forums} where id = {$groupid}"));
if(!$user_groups)
return true;
foreach($user_groups as $user_group) {
if($this->is_user_ingroup($user_ID, $user_group))
return true;
}
return false;
}
function get_usergroups(){
global $wpdb;
return $wpdb->get_results("SELECT * FROM $this->t_usergroups");
}
function get_members($usergroup){
global $wpdb;
return $wpdb->get_results("SELECT user_id FROM $this->t_usergroup2user WHERE `group` = $usergroup");
}
function is_user_ingroup($user_id = "0", $user_group_id=''){
global $wpdb;
if(!$user_id)
return false;
$id = $wpdb->get_var("select user_id from $this->t_usergroup2user where user_id = $user_id and `group` = $user_group_id");
if($id != "")
return true;
return false;
}
// TODO
function setup_header(){
$this->setup_links();
if($this->options['forum_use_rss']) { ?>
" href="global_feed_url;?>" /> get_pageid()))
{
if($this->ads_options['mf_ad_custom_css'] != "") {
?>
skin_url/style.css";?>" />
options['forum_use_seo_friendly_urls'])
{
$uri = $this->get_seo_friendly_query();
if (!empty($uri) && $uri['action'] && $uri['id'])
{
switch($uri['action'])
{
case 'group':
$action = 'vforum';
$_GET['g'] = $uri['id'];
break;
case 'forum':
$action = 'viewforum';
$_GET['f'] = $uri['id'];
break;
case 'thread':
$action = 'viewtopic';
$_GET['t'] = $uri['id'];
break;
}
}
}
switch($action){
case "vforum":
$title = $default_title.$this->get_groupname($this->check_parms($_GET['g']));
break;
case "viewforum":
$title = $default_title.$this->get_groupname($this->forum_get_parent($this->check_parms($_GET['f'])))." » ".$this->get_forumname($this->check_parms($_GET['f']));
break;
case "viewtopic":
$group = $this->get_groupname($this->forum_get_parent($this->forum_get_forum_from_post($this->check_parms($_GET['t']))));
$title = $default_title.$group." » ".$this->get_forumname($this->forum_get_forum_from_post($this->check_parms($_GET['t'])))." » ".$this->get_threadname($this->check_parms($_GET['t']));
break;
case "search":
$terms = htmlentities($wpdb->escape($_POST['search_words']), ENT_QUOTES);
$title = $default_title.__("Search Results", "mingleforum"). " » {$terms} | ";
break;
case "profile":
$title = $default_title.__("Profile", "mingleforum")."";
break;
case "editpost":
$title = $default_title.__("Edit Post", "mingleforum")."";
break;
case "postreply":
$title = $default_title.__("Post Reply", "mingleforum")."";
break;
case "addtopic":
$title = $default_title.__("New Topic", "mingleforum")."";
break;
}
return $bef_title.$title." ";
}
function set_pagetitle($title){
if(is_page($this->get_pageid())) {
return $this->get_pagetitle($title);
} else {
return $title;
}
}
function array_search( $needle, $haystack, $strict = FALSE ){
if( !is_array($haystack) )return false;
foreach($haystack as $val){
if( ( ( $strict ) && ( $needle === $val ) ) || ( ( !$strict ) && ( $needle == $val ) ) )return $val;
}
return false;
}
function get_usergroup_name($usergroup_id){
global $wpdb;
return $wpdb->get_var("SELECT name FROM $this->t_usergroups WHERE id = $usergroup_id");
}
function get_usergroup_description($usergroup_id){
global $wpdb;
return $wpdb->get_var("SELECT description FROM $this->t_usergroups WHERE id = $usergroup_id");
}
function is_moderator($user_id, $forum_id = ''){
$user = get_userdata($user_id);
if($user && $user->user_level >= 9)
return true;
$forums = get_user_meta($user_id, 'wpf_moderator', true);
if(!$forum_id)
return $forums;
if($forums == "mod_global")
return true;
return $this->array_search( $forum_id, $forums );
}
function get_users(){
global $wpdb;
return $wpdb->get_results("SELECT user_login, ID FROM {$wpdb->users} ORDER BY user_login ASC");
}
function get_moderators(){
global $wpdb;
return $wpdb->get_results("
select $wpdb->usermeta.user_id, $wpdb->users.user_login
from
$wpdb->usermeta
inner join
$wpdb->users on $wpdb->usermeta.user_id = $wpdb->users.ID
where
$wpdb->usermeta.meta_key = 'wpf_moderator' ORDER BY $wpdb->users.user_login ASC");
}
function get_forum_moderators($forum_id){
global $wpdb;
$out = "";
$mods = $wpdb->get_results("SELECT user_id, meta_value FROM $wpdb->usermeta WHERE meta_key = 'wpf_moderator'");
foreach($mods as $mod){
if($this->is_moderator($mod->user_id, $forum_id)){
$out .= $this->profile_link($mod->user_id).", ";
}
}
$out = substr($out, 0, strlen($out)-2);
return (empty($out)) ? '' : "".__("Moderators:", "mingleforum")." $out ";
}
function get_sub_forums($forum_id){
global $wpdb;
$out = "";
$fs = $wpdb->get_results("SELECT id, name FROM $this->t_forums WHERE parent_id = $forum_id");
foreach($fs as $f){
$out .= "".$this->output_filter($f->name)." ";
}
return (empty($out)) ? '' : "".__("Subforums", "mingleforum").": $out ";
}
function wp_forum_install()
{
global $table_prefix, $wpdb;
$table_threads = $table_prefix."forum_threads";
$table_posts = $table_prefix."forum_posts";
$table_forums = $table_prefix."forum_forums";
$table_usergroup2user = $table_prefix."forum_usergroup2user";
$table_usergroups = $table_prefix."forum_usergroups";
$oldops = get_option('mingleforum_options');
if($oldops['forum_db_version'] < $this->db_version) //Don't run all the friggin queries if db is already at latest version
{
$charset_collate = '';
if( $wpdb->has_cap('collation'))
{
if(!empty($wpdb->charset))
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if(!empty($wpdb->collate))
$charset_collate .= " COLLATE $wpdb->collate";
}
$sql1 = "
CREATE TABLE ". $table_forums." (
id int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
parent_id int(11) NOT NULL default '0',
`description` varchar(255) NOT NULL default '',
views int(11) NOT NULL default '0',
`sort` int( 11 ) NOT NULL default '0',
PRIMARY KEY (id)
){$charset_collate};";
$sql3 = "
CREATE TABLE ". $table_posts." (
id int(11) NOT NULL auto_increment,
`text` longtext,
parent_id int(11) NOT NULL default '0',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
author_id int(11) NOT NULL default '0',
`subject` varchar(255) NOT NULL default '',
views int(11) NOT NULL default '0',
PRIMARY KEY (id)
){$charset_collate};";
$sql4 = "
CREATE TABLE ". $table_threads." (
id int(11) NOT NULL auto_increment,
parent_id int(11) NOT NULL default '0',
views int(11) NOT NULL default '0',
`subject` varchar(255) NOT NULL default '',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`status` varchar(20) NOT NULL default 'open',
closed int(11) NOT NULL default '0',
mngl_id int(11) NOT NULL default '-1',
starter int(11) NOT NULL,
`last_post` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id)
){$charset_collate};";
$sql5 = "
CREATE TABLE ". $table_usergroup2user." (
`id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`group` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
){$charset_collate};";
$sql6 =
"CREATE TABLE ". $table_usergroups." (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`description` varchar(255) default NULL,
`leaders` varchar(255) default NULL,
PRIMARY KEY (`id`)
){$charset_collate};";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql1);
dbDelta($sql3);
dbDelta($sql4);
dbDelta($sql5);
dbDelta($sql6);
$xyquery2="ALTER TABLE ".$table_forums." ADD sort int( 11 ) NOT NULL;";
$xyquery3="ALTER TABLE ".$table_threads." ADD last_post datetime NOT NULL;";
$xyquery7="ALTER TABLE ".$table_posts." CHANGE thread_id parent_id int(11);";
$xyquery8="ALTER TABLE `".$table_posts."` ADD FULLTEXT ( `text` );";
$xyquery9="ALTER TABLE ".$table_threads." ADD closed int(11) NOT NULL default '0';";
$xyquery10="ALTER TABLE ".$table_threads." ADD mngl_id int(11) NOT NULL default '-1';";
$xyquery11="ALTER TABLE ".$table_forums." ADD usergroups VARCHAR( 255 ) NULL DEFAULT ''";
$xyquery12="ALTER TABLE ".$table_forums." ADD usercanpost VARCHAR( 255 ) NULL DEFAULT ''";
// 1.7.3
maybe_add_column($table_forums, 'sort', $xyquery2);
// 1.7.5
maybe_add_column($table_threads, 'last_post', $xyquery3);
// 2.0
maybe_add_column($table_posts, 'parent_id', $xyquery7);
$wpdb->query($xyquery8);
// 3.0
maybe_add_column($table_forums, 'usergroups', $xyquery11);
maybe_add_column($table_forums, 'usercanpost', $xyquery12);
// Mingle Forum 1.0
maybe_add_column($table_threads, 'closed', $xyquery9);
maybe_add_column($table_threads, 'mngl_id', $xyquery10);
$this->convert_moderators();
$this->upgrade_forums_groups();
//Setup the Skin Folder outside of the plugin
$target_path = ABSPATH.'wp-content/mingle-forum-skins';
if(!file_exists($target_path))
@mkdir($target_path."/");
$oldops['forum_db_version'] = 2;
update_option('mingleforum_options', $oldops);
}
}
function forum_menu($pos = "top"){
global $user_ID;
$menu = "";
if($user_ID || $this->allow_unreg()){
if($pos == "top")
$class = "mirrortab";
else
$class= "maintab";
$menu = "";
}
return $menu;
}
function topic_menu($pos = "top"){
global $user_ID;
$menu = "";
$stick = "";
$closed = "";
if($user_ID || $this->allow_unreg()){
if($pos == "top"){
$class = "mirrortab";
}else{
$class = "maintab";
}
if($this->is_moderator($user_ID, $this->current_forum)){
if($this->options['forum_use_seo_friendly_urls'])
{
if($this->is_sticky()){
$stick = "".__("Undo Sticky", "mingleforum")." ";
}else{
$stick = "".__("Sticky", "mingleforum")." ";
}
if($this->is_closed()){
$closed = "".__("Re-open", "mingleforum")." ";
}else{
$closed = "".__("Close", "mingleforum")." ";
}
}
else
{
if($this->is_sticky()){
$stick = "".__("Undo Sticky", "mingleforum")." ";
}else{
$stick = "".__("Sticky", "mingleforum")." ";
}
if($this->is_closed()){
$closed = "".__("Re-open", "mingleforum")." ";
}else{
$closed = "".__("Close", "mingleforum")." ";
}
}
}
$menu .= "";
}
return $menu;
}
function setup_menu(){
global $user_ID;
$this->setup_links();
if(isset($_GET['closed']))
$this->closed_post();
$link = "".__("My Profile", "mingleforum")." ";
if($this->options['forum_use_seo_friendly_urls'])
{
$menuitems = array(
"home" => "".__("Forum Home", "mingleforum")." ",
"profile" => $link,
"move" => "".__("Move Topic", "mingleforum")." "
);
}
else
{
$menuitems = array(
"home" => "".__("Forum Home", "mingleforum")." ",
"profile" => $link,
"move" => "".__("Move Topic", "mingleforum")." ");
}
$menu = "";
if($user_ID || $this->allow_unreg()){
$menu .= "";
$menu .= "";
if($user_ID)
$menu .= "";
switch($this->current_view){
case THREAD:
if($this->is_moderator($user_ID, $this->current_forum)){
$menu .= "";
}
}
$menu .= "
";
}
return $menu;
}
function convert_moderators(){
global $wpdb;
if(!get_option('wpf_mod_option_vers')){
$mods = $wpdb->get_results("SELECT user_id, user_login, meta_value FROM $wpdb->usermeta
INNER JOIN $wpdb->users ON $wpdb->usermeta.user_id=$wpdb->users.ID WHERE meta_key = 'moderator' AND meta_value <> ''");
foreach($mods as $mod){
$string = explode(",", substr_replace($mod->meta_value, "", 0, 1));
update_user_meta($mod->user_id, 'wpf_moderator', maybe_serialize($string));
}
update_option('wpf_mod_option_vers', '2');
}
}
function upgrade_forums_groups() {
global $wpdb, $table_prefix;
$wpdb->get_var("SHOW TABLES LIKE '%forum_groups%'");
if ($wpdb->num_rows) {
$groups = $wpdb->get_results("SELECT * FROM {$table_prefix}forum_groups");
foreach ($groups as $group) {
$wpdb->query($wpdb->prepare(
"INSERT INTO $this->t_forums (name, description, sort, usergroups) VALUES (%s, %s, %d, %s)",
$group->name,
$group->description,
$group->sort,
$group->usergroups
));
$wpdb->query($wpdb->prepare(
"UPDATE $this->t_forums SET parent_id = %d WHERE parent_id = %d",
$wpdb->insert_id,
$group->id
));
}
$wpdb->query("DROP TABLE {$table_prefix}forum_groups");
}
}
function login_form(){
global $user_ID;
if($user_ID)
$user = get_userdata($user_ID);
$login_msg = "";
if ($user_ID)
$login_msg = "".__("You are logged in as:", "mingleforum")." ".$user->user_login."
";
else
$login_msg = "";
if(!is_user_logged_in() && $this->options['forum_show_login_form']){
return "";
}
else
return $login_msg;
}
function print_curr(){
$this->o .= "Group: $this->current_group
Forum: $this->current_forum
Thread: $this->current_thread
";
}
// TODO
function get_userrole($user_id){
$user = get_userdata($user_id);
if($user && $user->user_level >= 9)
return __("Administrator", "mingleforum");
if(!$user_id)
return ""; //User is a guest
if($this->is_moderator($user_id, $this->current_forum))
return __("Moderator", "mingleforum");
else
{
$mePosts = $this->get_userposts_num($user_id);
if ($mePosts < $this->opt['level_one'])
return __($this->opt['level_newb_name'], "mingleforum");
if ($mePosts < $this->opt['level_two'])
return __($this->opt['level_one_name'], "mingleforum");
if ($mePosts < $this->opt['level_three'])
return __($this->opt['level_two_name'], "mingleforum");
else
return __($this->opt['level_three_name'], "mingleforum");
}
}
/**************************************************/
function forum_get_group_id($group){
$group = ($group) ? $group : 0;
while (true) {
$parent = $this->forum_get_parent($group);
if (!$parent) return $group;
$group = $parent;
}
}
function forum_get_parent($forum){
$forum = ($forum) ? $forum : 0;
global $wpdb;
return $wpdb->get_var("SELECT parent_id FROM $this->t_forums WHERE id = $forum");
}
function forum_get_forum_from_post($thread){
$thread = ($thread) ? $thread : 0;
global $wpdb;
return $wpdb->get_var("SELECT parent_id FROM $this->t_threads WHERE id = $thread");
}
function forum_get_group_from_post($thread_id){
return $this->forum_get_group_id($this->forum_get_parent($this->forum_get_forum_from_post($thread_id)));
}
/****************************************************/
function trail($pos = "top"){
global $wpdb;
$this->setup_links();
$class= "maintab";
if($pos == "top")
$class = "mirrortab";
$trail = "".__("Forum", "mingleforum")." ";
if($this->current_group)
if($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($this->current_group))."-group".$this->current_group;
$trail .= " » ".$this->get_groupname($this->current_group)." ";
}
else
$trail .= " » ".$this->get_groupname($this->current_group)." ";
$parents = array();
$current = $this->forum_get_parent($this->current_forum);
while ($current) {
$parents[] = $current;
$current = $this->forum_get_parent($current);
}
$parents = array_reverse($parents);
unset($parents[0]);
foreach ($parents as $parent) {
if ($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($this->forum_get_parent($parent))."-group".$this->forum_get_parent($parent));
$forum = $this->get_seo_friendly_title($this->get_forumname($parent)."-forum".$parent);
$trail .= " » ".$this->get_forumname($parent)." ";
}
else
$trail .= " » ".$this->get_forumname($parent)." ";
}
if($this->current_forum)
if ($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($this->forum_get_parent($this->current_forum))."-group".$this->forum_get_parent($this->current_forum));
$forum = $this->get_seo_friendly_title($this->get_forumname($this->current_forum)."-forum".$this->current_forum);
$trail .= " » ".$this->get_forumname($this->current_forum)." ";
}
else
$trail .= " » ".$this->get_forumname($this->current_forum)." ";
if($this->current_thread)
if ($this->options['forum_use_seo_friendly_urls'])
{
$group = $this->get_seo_friendly_title($this->get_groupname($this->forum_get_parent($this->forum_get_forum_from_post($this->current_thread)))."-group".$this->forum_get_parent($this->forum_get_forum_from_post($this->current_thread)));
$forum = $this->get_seo_friendly_title($this->get_forumname($this->forum_get_forum_from_post($this->current_thread))."-forum".$this->forum_get_forum_from_post($this->current_thread));
$thread = $this->get_seo_friendly_title($this->get_threadname($this->current_thread)."-thread".$this->current_thread);
$trail .= " » ".$this->get_threadname($this->current_thread)." ";
}
else
$trail .= " » ".$this->get_threadname($this->current_thread)." ";
if($this->current_view == NEWTOPICS)
$trail .= " » ".__("New Topics since last visit", "mingleforum");
if($this->current_view == SEARCH){
$terms = "";
if(isset($_POST['search_words']))
$terms = htmlentities($wpdb->escape($_POST['search_words']), ENT_QUOTES);
$trail .= " » ".__("Search Results", "mingleforum")." » $terms";
}
if($this->current_view == PROFILE)
$trail .= " » ".__("Profile Info", "mingleforum");
if($this->current_view == POSTREPLY)
$trail .= " » ".__("Post Reply", "mingleforum");
if($this->current_view == EDITPOST)
$trail .= " » ".__("Edit Post", "mingleforum");
if($this->current_view == NEWTOPIC)
$trail .= " » ".__("New Topic", "mingleforum");
return apply_filters('mf_ad_above_breadcrumbs', '')."$trail
"; //Adsense Area -- Above Breadcrumbs
}
function last_visit(){
global $user_ID;
if($user_ID)
return $_COOKIE['wpmfcookie'];
else
return "0000-00-00 00:00:00";
}
function set_cookie()
{
global $user_ID;
if($user_ID && !isset($_COOKIE['wpmfcookie']))
{
$last = get_user_meta($user_ID, 'lastvisit', true);
setcookie("wpmfcookie", $last, 0, "/");
update_user_meta($user_ID, 'lastvisit', $this->wpf_current_time_fixed('mysql', 0));
}
}
function markallread()
{
global $user_ID;
if($user_ID)
{
update_user_meta($user_ID, 'lastvisit', $this->wpf_current_time_fixed('mysql', 0));
$last = get_user_meta($user_ID, 'lastvisit', true);
setcookie("wpmfcookie", $last, 0, "/");
}
}
function get_avatar($user_id, $size = 60){
if($this->opt['forum_use_gravatar'] == 'true')
return get_avatar($user_id, $size);
else
return "";
}
function header(){
global $user_ID;
$avatar = "";
$this->setup_links();
$ProfLinky = "".__("Edit Profile", "mingleforum")." ";
if($user_ID){
$welcome = __("Welcome", "mingleforum")." ".$this->get_userdata($user_ID, $this->options['forum_display_name']);
$meta = "";
$avatar = "".$this->get_avatar($user_ID, 60)." ";
$colspan = "colspan = '2'";
}
else{
$meta = apply_filters('wpwf_guest_welcome_msg', "".__("Welcome Guest, please login or", "mingleforum")." "."".__("register.", "mingleforum")."
".$this->login_form()); //--weaver--
$welcome = __("Welcome", "mingleforum"). " ".$this->get_userdata($user_ID, $this->options['forum_display_name'])." ";
$colspan = "";
}
if(!$user_ID && !$this->allow_unreg()){
$meta = "".__("Welcome Guest, posting in this forum requires", "mingleforum")." ".__("registration.", "mingleforum")."
".$this->login_form();
$colspan = "";
}
$o = "
";
$o .= $this->setup_menu();
$o .= $this->trail();
$this->o .= $o;
}
function post_pageing($thread_id){
global $wpdb;
$out = __("Pages:", "mingleforum");
$count = $wpdb->get_var("SELECT count(*) FROM $this->t_posts WHERE parent_id = $thread_id");
$num_pages = ceil($count/$this->opt['forum_posts_per_page']);
if($num_pages <= 6) {
for($i = 0; $i < $num_pages; ++$i){
if($i == $this->curr_page)
$out .= " [".($i+1)." ]";
else
$out .= " ".($i+1)." ";
}
}
else {
if($this->curr_page >= 4)
$out .= " ".__("First", "mingleforum")." << ";
for($i = 3; $i > 0; $i--) {
if((($this->curr_page + 1) - $i) > 0)
$out .= " ".(($this->curr_page + 1) - $i)." ";
}
$out .= " [".($this->curr_page + 1)." ]";
for($i = 1; $i <= 3; $i++) {
if((($this->curr_page + 1) + $i) <= $num_pages)
$out .= " ".(($this->curr_page + 1) + $i)." ";
}
if($num_pages - $this->curr_page >= 5)
$out .= " >> ".__("Last", "mingleforum")." ";
}
return "".$out." ";
}
function thread_pageing($forum_id){
global $wpdb;
$out = __("Pages:", "mingleforum");
$count = $wpdb->get_var("SELECT count(*) FROM $this->t_threads WHERE parent_id = $forum_id AND `status` <> 'sticky'");
$num_pages = ceil($count/$this->opt['forum_threads_per_page']);
if($num_pages <= 6) {
for($i = 0; $i < $num_pages; ++$i){
if($i == $this->curr_page)
$out .= " [".($i+1)." ]";
else
$out .= " ".($i+1)." ";
}
}
else {
if($this->curr_page >= 4)
$out .= " ".__("First", "mingleforum")." << ";
for($i = 3; $i > 0; $i--) {
if((($this->curr_page + 1) - $i) > 0)
$out .= " ".(($this->curr_page + 1) - $i)." ";
}
$out .= " [".($this->curr_page + 1)." ]";
for($i = 1; $i <= 3; $i++) {
if((($this->curr_page + 1) + $i) <= $num_pages)
$out .= " ".(($this->curr_page + 1) + $i)." ";
}
if($num_pages - $this->curr_page >= 5)
$out .= " >> ".__("Last", "mingleforum")." ";
}
return "".$out." ";
}
function remove_topic(){
global $user_ID, $wpdb;
$topic = $_GET['topic'];
if($this->is_moderator($user_ID, $this->current_forum)){
$wpdb->query($wpdb->prepare("DELETE FROM {$this->t_posts} WHERE `parent_id` = %d", $topic));
$wpdb->query($wpdb->prepare("DELETE FROM {$this->t_threads} WHERE `id` = %d", $topic));
}else{
wp_die(__("An unknown error has occured. Please try again.", "mingleforum"));
}
}
function getNewForumID(){
global $user_ID;
$topic = !empty($_GET['topic']) ? (int)$_GET['topic'] : 0;
$topic = !empty($_GET['t']) ? (int)$_GET['t'] : $topic;
if($this->is_moderator($user_ID, $this->current_forum)){
$currentForumID = $this->check_parms($_GET['f']);
$strOUT = '
';
return $strOUT;
}else{
wp_die(__("An unknown error has occured. Please try again.", "mingleforum"));
}
}
function move_getSubForums($frs, $cfid, $i=0) {
$out = '';
foreach ($frs as $f) {
$lvl = '';
for ($l=0;$l<$i;$l++)
$lvl.='-';
$out .= 'id==$cfid ? ' selected="selected"' : '').($f->parent_id==0 ? ' disabled="disabled"' : '').'>'.$lvl.' '.$f->name.' ';
$subfrs = $this->get_forums($f->id);
if (!empty($subfrs)) {
$out .= $this->move_getSubForums($subfrs, $cfid, ++$i);
$i--;
}
}
return $out;
}
function move_topic(){
global $user_ID, $wpdb;
$topic = $_GET['topic'];
$newForumID = !empty($_GET['newForumID']) ? (int)$_GET['newForumID'] : 0;
$newForumID = !empty($_POST['newForumID']) ? (int)$_POST['newForumID'] : $newForumID;
if($this->is_moderator($user_ID, $this->current_forum)){
$strSQL = $wpdb->prepare("UPDATE {$this->t_threads} SET `parent_id` = {$newForumID} WHERE id = %d", $topic);
$wpdb->query($strSQL);
@header("location: ".$this->base_url."viewforum&f=".$newForumID);
@exit;
}else{
wp_die(__("An unknown error has occured. Please try again.", "mingleforum"));
}
}
function remove_post(){
global $user_ID, $wpdb;
$id = (isset($_GET['id']) && is_numeric($_GET['id']))?$_GET['id']:0;
$author = $wpdb->get_var($wpdb->prepare("SELECT author_id, parent_id from {$this->t_posts} where id = %d"), $id);
$del = "fail";
if(current_user_can("administrator") || is_super_admin($user_ID))
$del = "ok";
if($this->is_moderator($user_ID, $this->current_forum))
$del = "ok";
if($user_ID == $author->author_id)
$del = "ok";
if($del == "ok"){
$wpdb->query($wpdb->prepare("DELETE FROM {$this->t_posts} WHERE id = %d", $id));
$nbmsg = $wpdb->get_var("SELECT COUNT(*) FROM {$this->t_posts} WHERE parent_id = {$author->parent_id}");
if (!$nbmsg)
$wpdb->query("DELETE FROM {$this->t_threads} WHERE id = {$author->parent_id}");
$this->o .= "".__("Post deleted", "mingleforum")."
";
}else{
wp_die(__("An unknown error has occured. Please try again.", "mingleforum"));
}
}
function sticky_post(){
global $user_ID, $wpdb;
if(current_user_can("administrator") || is_super_admin($user_ID)){
if(!$this->is_moderator($user_ID, $this->current_forum)){
wp_die(__("An unknown error has occured. Please try again.", "mingleforum"));
}
}
$id = (isset($_GET['id']) && is_numeric($_GET['id']))?$_GET['id']:0;
$status = $wpdb->get_var($wpdb->prepare("SELECT status FROM {$this->t_threads} WHERE id = %d", $id));
switch($status){
case 'sticky':
$wpdb->query($wpdb->prepare("UPDATE {$this->t_threads} SET status = 'open' WHERE id = %d", $id));
break;
case 'open':
$wpdb->query($wpdb->prepare("UPDATE {$this->t_threads} SET status = 'sticky' WHERE id = %d", $id));
break;
}
}
function forum_subscribe()
{
global $user_ID;
if(isset($_GET['forumsubs']) && $user_ID)
{
$useremail = $this->get_userdata($user_ID, 'user_email');
if(!empty($useremail))
{
$list = get_option("mf_forum_subscribers_".$this->current_forum, array());
if($this->is_forum_subscribed()) //remove user if already exists (user clicked unsubscribe)
{
$key = array_search($useremail, $list);
unset($list[$key]);
}
else
$list[] = $useremail;
update_option("mf_forum_subscribers_".$this->current_forum, $list);
}
}
}
function is_forum_subscribed()
{
global $user_ID;
if($user_ID)
{
$useremail = $this->get_userdata($user_ID, 'user_email');
$list = get_option("mf_forum_subscribers_".$this->current_forum, array());
if(in_array($useremail, $list))
return true;
}
return false;
}
function get_subscribed_forums()
{
global $user_ID, $wpdb;
$results = array();
$email = $this->get_userdata($user_ID, 'user_email');
$forums = $wpdb->get_results("SELECT id FROM {$this->t_forums}");
if(!empty($forums))
foreach($forums as $f)
{
$list = get_option("mf_forum_subscribers_".$f->id, array());
if(in_array($email, $list))
$results[] = $f->id;
}
return $results;
}
function thread_subscribe()
{
global $user_ID;
if(isset($_GET['threadsubs']) && $user_ID)
{
$useremail = $this->get_userdata($user_ID, 'user_email');
if(!empty($useremail))
{
$list = get_option("mf_thread_subscribers_".$this->current_thread, array());
if($this->is_thread_subscribed()) //remove user if already exists (user clicked unsubscribe)
{
$key = array_search($useremail, $list);
unset($list[$key]);
}
else
$list[] = $useremail;
update_option("mf_thread_subscribers_".$this->current_thread, $list);
}
}
}
function is_thread_subscribed()
{
global $user_ID;
if($user_ID)
{
$useremail = $this->get_userdata($user_ID, 'user_email');
$list = get_option("mf_thread_subscribers_".$this->current_thread, array());
if(in_array($useremail, $list))
return true;
}
return false;
}
function get_subscribed_threads()
{
global $user_ID, $wpdb;
$results = array();
$email = $this->get_userdata($user_ID, 'user_email');
$threads = $wpdb->get_results("SELECT id FROM {$this->t_threads}");
if(!empty($threads))
foreach($threads as $t)
{
$list = get_option("mf_thread_subscribers_".$t->id, array());
if(in_array($email, $list))
$results[] = $t->id;
}
return $results;
}
function is_sticky($thread_id = ''){
global $wpdb;
if($thread_id){
$id = $thread_id;
}else{
$id = $this->current_thread;
}
$status = $wpdb->get_var("select status from $this->t_threads where id = $id");
if($status == "sticky")
return true;
else
return false;
}
function closed_post(){
global $user_ID, $wpdb;
if(current_user_can("administrator") || is_super_admin($user_ID)){
if(!$this->is_moderator($user_ID, $this->current_forum)){
wp_die(__("An unknown error has occured. Please try again.", "mingleforum"));
}
}
$strSQL = "UPDATE {$this->t_threads} SET closed = %d WHERE id = %d";
$wpdb->query($wpdb->prepare($strSQL, (int)$_GET['closed'], (int)$_GET['id']));
}
function is_closed($thread_id = ''){
global $wpdb;
if($thread_id){
$id = $thread_id;
}else{
$id = $this->current_thread;
}
$strSQL = $wpdb->prepare("SELECT closed FROM {$this->t_threads} WHERE id = %d", $id);
$closed = $wpdb->get_var($strSQL);
if($closed){
return true;
}else{
return false;
}
}
function allow_unreg(){
if($this->opt['forum_require_registration'] == false)
return true;
return false;
}
function profile_link($user_id, $toWrap = false){
if($toWrap)
$user = wordwrap($this->get_userdata($user_id, $this->options['forum_display_name']), 10, "- ", 1);
else
$user = $this->get_userdata($user_id, $this->options['forum_display_name']);
$link = "$user ";
if($user == __("Guest", "mingleforum"))
return $user;
$user_op = get_user_meta($user_id, "wpf_useroptions", true);
if($user_op)
if($user_op['allow_profile'] == false)
return $user;
return $link;
}
function footer(){
$o = "";
switch($this->current_view){
case MAIN:
$o = apply_filters('mf_ad_above_info_center', ''); //Adsense Area -- Above Info Center
$o .= "";
$o .= "
";
$o .= "
".__("Info Center", "mingleforum")."
".$this->num_posts_total()." ".__("Posts in", "mingleforum")." ".$this->num_threads_total()." ".__("Topics Made by", "mingleforum")." ".count($this->get_users())." ".__("Members", "mingleforum").". ".__("Latest Member:", "mingleforum")." ".$this->profile_link($this->latest_member())."
".$this->get_lastpost_all()."
";
$o .= "
";
break;
case FORUM: break;
case THREAD: break;
}
$this->o .= $o;
}
function latest_member(){
global $wpdb;
return $wpdb->get_var("select ID from $wpdb->users order by user_registered DESC limit 1");
}
function show_new(){
$this->current_view = NEWTOPICS;
global $wpdb;
$this->header();
$lastvisit = $this->last_visit();
$threads = $wpdb->get_results("select distinct($this->t_threads.id) from $this->t_posts inner join $this->t_threads on $this->t_posts.parent_id = $this->t_threads.id where $this->t_posts.date > '$lastvisit' order by $this->t_posts.date desc");
$o = "
".__("New topics since your last visit", "mingleforum")."
".__("Status", "mingleforum")."
".__("Topic Title", "mingleforum")."
".__("Started by", "mingleforum")."
".__("Replies", "mingleforum")."
".__("Last post", "mingleforum")."
";
foreach($threads as $thread){
if($this->have_access($this->forum_get_group_from_post($thread->id)))
{
$starter_id = $wpdb->get_var("SELECT starter FROM $this->t_threads WHERE id = $thread->id");
$o .= "
".$this->get_topic_image($thread->id)."
"
.$this->output_filter($this->get_threadname($thread->id))."
".$this->profile_link($starter_id)."
".( $this->num_posts($thread->id) - 1 )."
".$this->get_lastpost($thread->id)."
";
}
}
$o .= "
";
$this->o .= $o;
$this->footer();
}
function num_post_user($user){
global $wpdb;
return $wpdb->get_var("SELECT count(author_id) FROM $this->t_posts WHERE author_id = $user");
}
function view_profile(){
$this->current_view = PROFILE;
if(is_numeric($_GET['id'])) //Security fix to prevent SQL injections
$user_id = $_GET['id'];
else
$user_id = 0;
$user = get_userdata($user_id);
$this->header();
$o = "
".__("Summary", "mingleforum")." - ".$this->get_userdata($user_id, $this->options['forum_display_name'])."
".__("Name:", "mingleforum")."
$user->first_name $user->last_name
".$this->get_avatar($user_id, 60)."
".__("Registered:", "mingleforum")."
".$this->format_date($user->user_registered)."
".__("Posts:", "mingleforum")."
".$this->num_post_user($user_id)."
".__("Position:", "mingleforum")."
".$this->get_userrole($user_id)."
".__("Website:", "mingleforum")."
$user->user_url
".__("AIM:", "mingleforum")."
$user->aim
".__("Yahoo:", "mingleforum")."
$user->yim
".__("Jabber/google Talk:", "mingleforum")."
$user->jabber
".__("Biographical Info:", "mingleforum")."
".$this->output_filter(make_clickable(convert_smilies(wpautop($user->description))))."
";
$this->o .= $o;
$this->footer();
}
function search_results(){
global $wpdb;
$o = "";
$this->current_view = SEARCH;
$this->header();
$search_string = $wpdb->escape($_POST['search_words']);
$sql = "SELECT $this->t_posts.id, `text`, $this->t_posts.subject, $this->t_posts.parent_id, $this->t_posts.`date`, MATCH (`text`) AGAINST (' {$search_string}') AS score
FROM $this->t_posts JOIN $this->t_threads on $this->t_posts.parent_id = $this->t_threads.id
AND MATCH (`text`) AGAINST ('{$search_string}')
ORDER BY score DESC
LIMIT 30";
$results = $wpdb->get_results($sql);
$max = 0;
foreach($results as $result)
if($result->score > $max)
$max = $result->score;
if($results)
$const = 100/$max;
$o .= "
Status
".__("Subject", "mingleforum")."
".__("Relevance", "mingleforum")."
".__("Started by", "mingleforum")."
".__("Posted", "mingleforum")."
";
foreach($results as $result){
if($this->have_access($this->forum_get_group_from_post($result->parent_id))){
$starter = $wpdb->get_var("select starter from {$this->t_threads} where id = {$result->parent_id}");
$o .= "
".$this->get_topic_image($result->parent_id)."
".stripslashes($result->subject)."
".round($result->score*$const, 1)."%
".$this->profile_link($starter)."
".$this->format_date($result->date)."
";
}
}
$o .= "
";
$this->o .= $o;
$this->footer();
}
function ext_str_ireplace($findme, $replacewith, $subject){
return substr($subject, 0, stripos($subject, $findme)).
str_replace('$1', substr($subject, stripos($subject, $findme), strlen($findme)), $replacewith).
substr($subject, stripos($subject, $findme)+strlen($findme));
}
function cuttext($value, $length){
if(is_array($value)) list($string, $match_to) = $value;
else { $string = $value; $match_to = $value{0}; }
$match_start = stristr($string, $match_to);
$match_compute = strlen($string) - strlen($match_start);
if (strlen($string) > $length)
{
if ($match_compute < ($length - strlen($match_to)))
{
$pre_string = substr($string, 0, $length);
$pos_end = strrpos($pre_string, " ");
if($pos_end === false) $string = $pre_string."...";
else $string = substr($pre_string, 0, $pos_end)."...";
}
else if ($match_compute > (strlen($string) - ($length - strlen($match_to))))
{
$pre_string = substr($string, (strlen($string) - ($length - strlen($match_to))));
$pos_start = strpos($pre_string, " ");
$string = "...".substr($pre_string, $pos_start);
if($pos_start === false) $string = "...".$pre_string;
else $string = "...".substr($pre_string, $pos_start);
}
else
{
$pre_string = substr($string, ($match_compute - round(($length / 3))), $length);
$pos_start = strpos($pre_string, " "); $pos_end = strrpos($pre_string, " ");
$string = "...".substr($pre_string, $pos_start, $pos_end)."...";
if($pos_start === false && $pos_end === false) $string = "...".$pre_string."...";
else $string = "...".substr($pre_string, $pos_start, $pos_end)."...";
}
$match_start = stristr($string, $match_to);
$match_compute = strlen($string) - strlen($match_start);
}
return $string;
}
function get_topic_image($thread){
$post_count = $this->num_posts($thread);
if($this->is_closed($thread)){
return " ";
}
if($post_count < $this->opt['hot_topic']){
return " ";
}
if($post_count >= $this->opt['hot_topic'] && $post_count < $this->opt['veryhot_topic']){
return " ";
}
if($post_count >= $this->opt['veryhot_topic']){
return " ";
}
}
function get_topic_image_two($thread){
$post_count = $this->num_posts($thread);
if($this->is_closed($thread)){
return "closed.gif";
}
if($post_count < $this->opt['hot_topic']){
return "normal_post.gif";
}
if($post_count >= $this->opt['hot_topic'] && $post_count < $this->opt['veryhot_topic']){
return "hot_post.gif";
}
if($post_count >= $this->opt['veryhot_topic']){
return "my_hot_post.gif";
}
}
function get_captcha(){
global $user_ID;
$out = "";
if(!$user_ID && $this->opt['forum_captcha'])
{
include_once(WPFPATH."captcha/shared.php");
include_once(WPFPATH."captcha/captcha_code.php");
$wpf_captcha = new CaptchaCode();
$wpf_code = wpf_str_encrypt($wpf_captcha->generateCode(6));
$out .= "
".__("Security Code:", "mingleforum")."
";
}
return $out;
}
function get_quick_reply_captcha(){
global $user_ID;
$out = "";
$out .= apply_filters('wpwf_quick_form_guestinfo',"");//--weaver-- show the guest info form
if(!$user_ID && $this->opt['forum_captcha'])
{
include_once(WPFPATH."captcha/shared.php");
include_once(WPFPATH."captcha/captcha_code.php");
$wpf_captcha = new CaptchaCode();
$wpf_code = wpf_str_encrypt($wpf_captcha->generateCode(6));
$out .= "
".__("Enter Security Code: (required)", "mingleforum")
."
";
}
return $out;
}
function notify_thread_subscribers($thread_id, $subject, $content, $date)
{
global $user_ID;
$submitter_name = (!$user_ID)?"Guest":$this->get_userdata($user_ID, $this->options['forum_display_name']);
$submitter_email = (!$user_ID)?"guest@nosite.com":$this->get_userdata($user_ID, 'user_email');
$sender = get_bloginfo("name");
$to = get_option("mf_thread_subscribers_".$thread_id, array());
$subject = __("Forum post - ", "mingleforum").$subject;
$message = __("DETAILS:", "mingleforum")." ".
__("Name:", "mingleforum")." ".$submitter_name." ".
__("Email:", "mingleforum")." ".$submitter_email." ".
__("Date:", "mingleforum")." ".$this->format_date($date)." ".
__("Reply Content:", "mingleforum")." ".$content." ".
__("View Post Here:", "mingleforum")." ".$this->get_threadlink($thread_id);
$headers = "MIME-Version: 1.0\r\n".
"From: ".$sender." "."<".get_bloginfo("admin_email").">\r\n".
"Content-Type: text/HTML; charset=\"".get_option('blog_charset')."\"\r\n".
"BCC: ".implode(",", $to)."\r\n";
if(!empty($to))
wp_mail("", $subject, make_clickable(convert_smilies(wpautop($this->output_filter(stripslashes($message))))), $headers);
}
function notify_forum_subscribers($thread_id, $subject, $content, $date, $forum_id)
{
global $user_ID;
$submitter_name = (!$user_ID)?"Guest":$this->get_userdata($user_ID, $this->options['forum_display_name']);
$submitter_email = (!$user_ID)?"guest@nosite.com":$this->get_userdata($user_ID, 'user_email');
$sender = get_bloginfo("name");
$to = get_option("mf_forum_subscribers_".$forum_id, array());
$subject = __("Forum post - ", "mingleforum").$subject;
$message = __("DETAILS:", "mingleforum")." ".
__("Name:", "mingleforum")." ".$submitter_name." ".
__("Email:", "mingleforum")." ".$submitter_email." ".
__("Date:", "mingleforum")." ".$this->format_date($date)." ".
__("Reply Content:", "mingleforum")." ".$content." ".
__("View Post Here:", "mingleforum")." ".$this->get_threadlink($thread_id);
$headers = "MIME-Version: 1.0\r\n".
"From: ".$sender." "."<".get_bloginfo("admin_email").">\r\n".
"Content-Type: text/HTML; charset=\"".get_option('blog_charset')."\"\r\n".
"BCC: ".implode(",", $to)."\r\n";
if(!empty($to))
wp_mail("", $subject, make_clickable(convert_smilies(wpautop($this->output_filter(stripslashes($message))))), $headers);
}
function notify_admins($thread_id, $subject, $content, $date)
{
global $user_ID;
$submitter_name = (!$user_ID)?"Guest":$this->get_userdata($user_ID, $this->options['forum_display_name']);
$submitter_email = (!$user_ID)?"guest@nosite.com":$this->get_userdata($user_ID, 'user_email');
$sender = get_bloginfo("name");
$to = get_bloginfo("admin_email");
$subject = __("New Forum content - ", "mingleforum").$subject;
$message = __("DETAILS:", "mingleforum")." ".
__("Name:", "mingleforum")." ".$submitter_name." ".
__("Email:", "mingleforum")." ".$submitter_email." ".
__("Date:", "mingleforum")." ".$this->format_date($date)." ".
__("Reply Content:", "mingleforum")." ".$content." ".
__("View Post Here:", "mingleforum")." ".$this->get_threadlink($thread_id);
$headers = "MIME-Version: 1.0\r\n".
"From: ".$sender." "."<".$to.">\n".
"Content-Type: text/HTML; charset=\"".get_option('blog_charset')."\"\r\n";
if($this->options['notify_admin_on_new_posts'])
if(!empty($to))
wp_mail($to, $subject, make_clickable(convert_smilies(wpautop($this->output_filter(stripslashes($message))))), $headers);
}
function autoembed($string)
{
global $wp_embed;
if (is_object($wp_embed))
return $wp_embed->autoembed($string);
else
return $string;
}
function rewriting_on()
{
$permalink_structure = get_option('permalink_structure');
return ($permalink_structure and !empty($permalink_structure));
}
function get_mingle_version()
{
$plugin_data = implode('', file(ABSPATH."wp-content/plugins/mingle/mingle.php"));
$version = '';
if (preg_match("|Version:(.*)|i", $plugin_data, $version))
$version = $version[1];
return (string)$version;
}
function convert_version_to_int($version)
{
$result = str_replace(".", "", $version);
return (int)$result;
}
function admin_get_pages()
{
global $wpdb;
$query = "SELECT * FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type = 'page'";
$results = $wpdb->get_results( $query );
if($results)
return $results;
else
return array();
}
//SEO Friendly URL stuff -- Pain in the @$$! -- But I am the bomb.com
function get_seo_friendly_query()
{
$end = array();
$request_uri = $_SERVER['REQUEST_URI'];
$link = str_replace(site_url(), '', get_permalink($this->get_pageid()));
$uri = explode('/', trim(str_replace($link, '', $request_uri), '/'));
if (array_count_values($uri))
{
$m = end($uri);
$found = '';
preg_match("/.*-(group|forum|thread)(\d*(\.?\d+)?)$/", $m, $found);
}
if (!empty($found))
{
$end = array('action' => $found[1], 'id' => $found[2]);
}
return $end;
}
function get_seo_friendly_title($str, $replace=array())
{
if(!empty($replace)) //Currently not used
{
$str = str_replace((array)$replace, ' ', $str);
}
if(function_exists('ctl_sanitize_title')) //perfect for crillic languages
return ctl_sanitize_title($str);
return sanitize_title_with_dashes($str); //Seems to work for most other languages
}
function flush_wp_rewrite_rules()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function set_seo_friendly_rules($args)
{
$new = array();
$link = trim(str_replace(array(site_url(), 'index.php/'), '', get_permalink($this->get_pageid())), '/');
$new['('.$link.')(/[-/0-9a-zA-Z]+)?/(.*)$'] = 'index.php?pagename=$matches[1]&page=$matches[2]';
return $new + $args;
}
//Add a dynamic sitemap for the forum posts
function do_sitemap()
{
$priority = "0.8";
$freq = "daily";
$threads = $this->get_threads(false);
$ind = " ";
$nl = "\n";
if(!empty($threads))
{
$out = "".$nl."".$nl;
foreach($threads as $t)
{
$time = explode(' ', $t->last_post, 2);
$time = explode('-', $time[0], 3);
$out .= $ind."".$nl.$ind.$ind."".$this->clean_link($this->get_threadlink($t->id))." ".$nl.$ind.$ind."".date_i18n('Y-m-d', mktime(0, 0, 0, $time[1], $time[2], $time[0]))." ".$nl.$ind.$ind."".$freq." ".$nl.$ind.$ind."".$priority." ".$nl.$ind." ".$nl;
}
$out .= " ";
}
echo $out;
}
function clean_link($l)
{
$l = str_replace('&', '&', $l);
return $l;
}
//Filter function for ads
function mf_ad_above_forum()
{
if($this->ads_options['mf_ad_above_forum_on'])
$str = "".stripslashes($this->ads_options['mf_ad_above_forum'])."
";
else
$str = '';
return $str;
}
function mf_ad_below_forum()
{
if($this->ads_options['mf_ad_below_forum_on'])
$str = "".stripslashes($this->ads_options['mf_ad_below_forum'])."
";
else
$str = '';
return $str;
}
function mf_ad_above_branding()
{
if($this->ads_options['mf_ad_above_branding_on'])
$str = "".stripslashes($this->ads_options['mf_ad_above_branding'])."
";
else
$str = '';
return $str;
}
function mf_ad_above_info_center()
{
if($this->ads_options['mf_ad_above_info_center_on'])
$str = "".stripslashes($this->ads_options['mf_ad_above_info_center'])."
";
else
$str = '';
return $str;
}
function mf_ad_above_quick_reply()
{
if($this->ads_options['mf_ad_above_quick_reply_on'])
$str = "".stripslashes($this->ads_options['mf_ad_above_quick_reply'])."
";
else
$str = '';
return $str;
}
function mf_ad_above_breadcrumbs()
{
if($this->ads_options['mf_ad_above_breadcrumbs_on'])
$str = "".stripslashes($this->ads_options['mf_ad_above_breadcrumbs'])."
";
else
$str = '';
return $str;
}
function mf_ad_below_first_post()
{
if($this->ads_options['mf_ad_below_first_post_on'])
$str = "".stripslashes($this->ads_options['mf_ad_below_first_post'])."
";
else
$str = '';
return $str;
}
//Integrate WP Posts with the Forum
function send_wp_posts_to_forum()
{
add_meta_box('mf_posts_to_forum', __('Mingle Forum Post Options', 'mingleforum'), array(&$this, 'show_meta_box_options'), 'post');
}
function show_meta_box_options()
{
$forums = $this->get_forums();
echo ' '.__('Add this post to', 'mingleforum');
echo ' ';
foreach($forums as $f)
echo ''.$f->name.' ';
echo ' '.__('Do not check this if this post has already been linked to the forum!', 'mingleforum').' ';
}
function saving_posts($post_id)
{
global $wpdb, $user_ID;
$this->setup_links();
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if('post' == $_POST['post_type'])
{
if(!current_user_can('edit_post', $post_id))
return;
}
else
return;
$mydata = ($_POST['mf_post_to_forum'] == 'true')?true:false;
if($mydata)
{
$date = $this->wpf_current_time_fixed('mysql', 0);
$fid = (int)$_POST['mf_post_to_forum_forum'];
$_POST['mf_post_to_forum'] = 'false'; //Eternal loop if this isn't set to false
$post = get_post($post_id);
$sql_thread = "INSERT INTO {$this->t_threads} (last_post, subject, parent_id, `date`, status, starter) VALUES('{$date}', '".$this->strip_single_quote($post->post_title)."', '{$fid}', '{$date}', 'open', '{$user_ID}')";
$wpdb->query($sql_thread);
$tid = $wpdb->insert_id;
$sql_post = "INSERT INTO {$this->t_posts} (text, parent_id, `date`, author_id, subject) VALUES('".$this->input_filter($wpdb->escape($post->post_content))."', '{$tid}', '{$date}', '{$user_ID}', '".$this->strip_single_quote($post->post_title)."')";
$wpdb->query($sql_post);
$new = $post->post_content."\n".''.__("Join the Forum discussion on this post", "mingleforum").'
';
$post->post_content = $new;
wp_update_post($post);
}
}
function strip_single_quote($string)
{
$Find = array("'", "\\");
$Replace = array("", "");
$newStr = str_replace($Find, $Replace, $string);
return $newStr;
}
} // End class
} // End
?>