コード例 #1
0
function bb_upgrade_190()
{
    if (($dbv = bb_get_option_from_db('bb_db_version')) && $dbv >= 630) {
        return;
    }
    global $bbdb;
    $exists = false;
    foreach ((array) $bbdb->get_col("DESC {$bbdb->topics}") as $col) {
        if ('topic_resolved' == $col) {
            $exists = true;
        }
    }
    if (!$exists) {
        return;
    }
    $topics = (array) $bbdb->get_results("SELECT topic_id, topic_resolved FROM {$bbdb->topics}");
    foreach ($topics as $topic) {
        bb_update_topicmeta($topic->topic_id, 'topic_resolved', $topic->topic_resolved);
    }
    unset($topics, $topic);
    $bbdb->query("ALTER TABLE {$bbdb->topics} DROP topic_resolved");
    bb_update_option('bb_db_version', 630);
    return 'Done converting topic_resolved: ' . __FUNCTION__;
}
コード例 #2
0
function bb_update_topic_voices($topic_id)
{
    if (!$topic_id) {
        return;
    }
    $topic_id = abs((int) $topic_id);
    global $bbdb;
    if ($voices = $bbdb->get_col($bbdb->prepare("SELECT DISTINCT poster_id FROM {$bbdb->posts} WHERE topic_id = %s AND post_status = '0';", $topic_id))) {
        $voices = count($voices);
        bb_update_topicmeta($topic_id, 'voices_count', $voices);
    }
}
コード例 #3
0
function bb_get_topic_voices($id = 0)
{
    $topic = get_topic(get_topic_id($id));
    if (empty($topic->voices_count)) {
        global $bbdb;
        if ($voices = $bbdb->get_col($bbdb->prepare("SELECT DISTINCT poster_id FROM {$bbdb->posts} WHERE topic_id = %s AND post_status = '0';", $topic->topic_id))) {
            $voices = count($voices);
            bb_update_topicmeta($topic->topic_id, 'voices_count', $voices);
        }
    } else {
        $voices = $topic->voices_count;
    }
    return apply_filters('bb_get_topic_voices', $voices, $topic->topic_id);
}
コード例 #4
0
ファイル: functions.php プロジェクト: achorg/DH-Answers
function socialit_hide_show_do()
{
    if (bb_is_topic() && $_GET['socialit_hide_show'] == "1" && isset($_GET['shs_opt']) && isset($_GET['tid']) && bb_current_user_can('moderate')) {
        $topic = get_topic($_GET['tid']);
        if (bb_verify_nonce($_GET['_wpnonce'], 'socialit_hide_show_' . $topic->topic_id)) {
            if ($_GET['shs_opt'] == "2") {
                bb_update_topicmeta($topic->topic_id, 'hide_socialit', 'true');
            } else {
                bb_delete_topicmeta($topic->topic_id, 'hide_socialit');
            }
        } else {
            _e('Sorry, but that could not be done.', 'socialit');
            exit;
        }
        wp_redirect(get_topic_link($topic->topic_id));
    }
}
コード例 #5
0
ファイル: bb-attachments.php プロジェクト: achorg/DH-Answers
function bb_attachments_recount($post_id = 0)
{
    // update topic icon flag and sync attachment count for topic  given a post_id
    global $bb_attachments, $bbdb;
    $count = 0;
    if (empty($topic_id)) {
        $topic_id = intval($bbdb->get_var("SELECT topic_id FROM {$bbdb->posts} WHERE post_id={$post_id} LIMIT 1"));
    }
    if ($topic_id) {
        $query = "SELECT count(status) as count FROM " . $bb_attachments['db'] . " AS t1 LEFT JOIN {$bbdb->posts} AS t2 ON t1.post_id=t2.post_id \n \t\t\tWHERE t1.status=0 AND t1.user_id>0 AND t1.size>0 AND t2.post_status=0 AND t2.topic_id={$topic_id}";
        $count = intval($bbdb->get_var($query));
        bb_update_topicmeta($topic_id, 'bb_attachments', $count);
    }
    return $count;
}
コード例 #6
0
ファイル: bozo.php プロジェクト: laiello/cartonbank
function bb_fermion($user_id, $topic_id = 0)
{
    global $bbdb;
    $user_id = (int) $user_id;
    $topic_id = (int) $topic_id;
    if (!$topic_id) {
        bb_delete_usermeta($user_id, 'is_bozo');
    } else {
        $topic = get_topic($topic_id);
        $user = bb_get_user($user_id);
        if (--$topic->bozos[$user_id] < 1) {
            unset($topic->bozos[$user_id]);
        }
        bb_update_topicmeta($topic_id, 'bozos', $topic->bozos);
        if (--$user->bozo_topics[$topic_id] < 1) {
            unset($user->bozo_topics[$topic_id]);
        }
        bb_update_usermeta($user_id, $bbdb->prefix . 'bozo_topics', $user->bozo_topics);
    }
}
コード例 #7
0
 /**
  * Sends a single pingback if a link is found
  *
  * @return integer The number of pingbacks sent
  */
 function send_pingback($topic_id, $post_text)
 {
     if (!$topic_id || !$post_text) {
         return 0;
     }
     // Get all links in the text and add them to an array
     if (!preg_match_all('@<a ([^>]+)>@im', make_clickable($post_text), $post_links)) {
         return 0;
     }
     $_links = array();
     foreach ($post_links[1] as $post_link_attributes) {
         $post_link_attributes = preg_split('@\\s+@im', $post_link_attributes, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($post_link_attributes as $post_link_attribute) {
             if (strpos($post_link_attribute, '=', 1) !== false) {
                 list($_key, $_value) = explode('=', $post_link_attribute, 2);
                 if (strtolower($_key) === 'href') {
                     $_links[] = trim($_value, "'\"");
                 }
             }
         }
     }
     // Get pingbacks which have already been performed from this topic
     $past_pingbacks = bb_get_topicmeta($topic_id, 'pingback_performed');
     $new_pingbacks = array();
     foreach ($_links as $_link) {
         // If it's already been pingbacked, then skip it
         if ($past_pingbacks && in_array($_link, $past_pingbacks)) {
             continue;
         }
         // If it's trying to ping itself, then skip it
         if ($topic = bb_get_topic_from_uri($_link)) {
             if ($topic->topic_id === $topic_id) {
                 continue;
             }
         }
         // Make sure it's a page on a site and not the root
         if (!($_url = parse_url($_link))) {
             continue;
         }
         if (!isset($_url['query'])) {
             if ($_url['path'] == '' || $_url['path'] == '/') {
                 continue;
             }
         }
         // Add the URL to the array of those to be pingbacked
         $new_pingbacks[] = $_link;
     }
     include_once BACKPRESS_PATH . '/class.ixr.php';
     $count = 0;
     foreach ($new_pingbacks as $pingback_to_url) {
         if (!($pingback_endpoint_uri = BB_Pingbacks::get_endpoint_uri($pingback_to_url))) {
             continue;
         }
         // Stop this nonsense after 60 seconds
         @set_time_limit(60);
         // Get the URL to pingback from
         $pingback_from_url = get_topic_link($topic_id);
         // Using a timeout of 3 seconds should be enough to cover slow servers
         $client = new IXR_Client($pingback_endpoint_uri);
         $client->timeout = 3;
         $client->useragent .= ' -- bbPress/' . bb_get_option('version');
         // When set to true, this outputs debug messages by itself
         $client->debug = false;
         // If successful or the ping already exists then add to the pingbacked list
         if ($client->query('pingback.ping', $pingback_from_url, $pingback_to_url) || isset($client->error->code) && 48 == $client->error->code) {
             $count++;
             $past_pingbacks[] = $pingback_to_url;
         }
     }
     bb_update_topicmeta($topic_id, 'pingback_performed', $past_pingbacks);
     return $count;
 }
コード例 #8
0
function bb_delete_post($post_id, $new_status = 0)
{
    global $bbdb, $topic, $bb_post;
    $post_id = (int) $post_id;
    $bb_post = bb_get_post($post_id);
    $new_status = (int) $new_status;
    $old_status = (int) $bb_post->post_status;
    add_filter('get_topic_where', 'bb_no_where');
    $topic = get_topic($bb_post->topic_id);
    $topic_id = (int) $topic->topic_id;
    if ($bb_post) {
        $uid = (int) $bb_post->poster_id;
        if ($new_status == $old_status) {
            return;
        }
        _bb_delete_post($post_id, $new_status);
        if (0 == $old_status) {
            bb_update_topicmeta($topic_id, 'deleted_posts', $topic->deleted_posts + 1);
            $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts - 1 WHERE forum_id = %d", $topic->forum_id));
        } else {
            if (0 == $new_status) {
                bb_update_topicmeta($topic_id, 'deleted_posts', $topic->deleted_posts - 1);
                $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts + 1 WHERE forum_id = %d", $topic->forum_id));
            }
        }
        $posts = (int) $bbdb->get_var($bbdb->prepare("SELECT COUNT(*) FROM {$bbdb->posts} WHERE topic_id = %d AND post_status = 0", $topic_id));
        $bbdb->update($bbdb->topics, array('topic_posts' => $posts), compact('topic_id'));
        if (0 == $posts) {
            if (0 == $topic->topic_status || 1 == $new_status) {
                bb_delete_topic($topic_id, $new_status);
            }
        } else {
            if (0 != $topic->topic_status) {
                $bbdb->update($bbdb->topics, array('topic_status' => 0), compact('topic_id'));
                $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics + 1 WHERE forum_id = %d", $topic->forum_id));
            }
            bb_topic_set_last_post($topic_id);
            bb_update_post_positions($topic_id);
            bb_update_topic_voices($topic_id);
        }
        $user = bb_get_user($uid);
        $user_posts = new BB_Query('post', array('post_author_id' => $user->ID, 'topic_id' => $topic_id));
        if ($new_status && !$user_posts->results) {
            $topics_replied_key = $bbdb->prefix . 'topics_replied';
            bb_update_usermeta($user->ID, $topics_replied_key, $user->{$topics_replied_key} - 1);
        }
        nxt_cache_delete($topic_id, 'bb_topic');
        nxt_cache_delete($topic_id, 'bb_thread');
        nxt_cache_flush('bb_forums');
        nxt_cache_flush('bb_query');
        nxt_cache_flush('bb_cache_posts_post_ids');
        do_action('bb_delete_post', $post_id, $new_status, $old_status);
        return $post_id;
    } else {
        return false;
    }
}
コード例 #9
0
ファイル: best-answer.php プロジェクト: achorg/DH-Answers
function best_answer_init()
{
    global $best_answer, $topic, $bb_current_user, $posts, $page;
    if (!empty($best_answer['forums']) && !isset($best_answer['forums'][$topic->forum_id])) {
        return;
    }
    add_action('best_answer', 'best_answer');
    add_action('best-answer', 'best_answer');
    add_filter('best_answer_class', 'best_answer_class');
    if ($best_answer['automatic']) {
        add_filter('post_author_title', 'best_answer_filter', 300);
        add_filter('post_author_title_link', 'best_answer_filter', 300);
    }
    if (!empty($bb_current_user->ID) && $bb_current_user->ID == $topic->topic_poster || bb_current_user_can('moderate')) {
        $best_answer['can_edit'] = true;
    } else {
        $best_answer['can_edit'] = false;
    }
    if (empty($topic->best_answer)) {
        $topic->best_answer = array();
    } elseif (!is_array($topic->best_answer)) {
        (array) ($topic->best_answer = explode(',', $topic->best_answer));
    }
    $topic->best_answer = array_flip($topic->best_answer);
    // speedup by using post id as key
    if (!empty($topic->topic_id) && !empty($_GET['best_answer']) && $best_answer['can_edit']) {
        $value = intval($_GET['best_answer']);
        if (isset($topic->best_answer[$value])) {
            unset($topic->best_answer[$value]);
        } else {
            if ($best_answer['max'] == 1) {
                $topic->best_answer = array();
            }
            $topic->best_answer[$value] = $value;
        }
        if (empty($topic->best_answer)) {
            bb_delete_topicmeta($topic->topic_id, 'best_answer');
        } else {
            bb_update_topicmeta($topic->topic_id, 'best_answer', implode(',', array_flip($topic->best_answer)));
        }
        wp_redirect(get_post_link($value));
        exit;
    }
    $best_answer[$topic->topic_id] = $topic->best_answer;
    $best_answer['count'] = count($topic->best_answer);
    if ($best_answer['display_first'] && !empty($best_answer[$topic->topic_id])) {
        // move best answer(s) to top of topic
        if ($page == 1) {
            $question = $posts[0];
            unset($posts[0]);
        }
        foreach ($posts as $key => $bb_post) {
            if ($bb_post->post_status == 0 && isset($best_answer[$topic->topic_id][$bb_post->post_id])) {
                unset($posts[$key]);
            }
        }
        if ($page == 1) {
            foreach ($best_answer[$topic->topic_id] as $post_id => $ignore) {
                $best = bb_get_post($post_id);
                if ($best->post_status == 0) {
                    array_unshift($posts, $best);
                } else {
                    unset($best_answer[$topic->topic_id][$post_id]);
                }
            }
            array_unshift($posts, $question);
        }
    }
}
コード例 #10
0
ファイル: bird-watcher.php プロジェクト: achorg/DH-Answers
function bw_insert_tweet($t_user, $t_id, $t_title, $t_tweet, $t_tags)
{
    //add a new topic by "Twitter User"
    $new_topic = bb_insert_topic(array('topic_title' => str_ireplace('#dhanswers', '', $t_title), 'topic_poster' => bw_get_id_from_user($t_user), 'forum_id' => 'general', 'tags' => $t_tags));
    //add the tweet guid to the meta table for duplication
    bb_update_topicmeta($new_topic, 'tweetid', $t_id);
    //add a new post to this topic with the full tweet
    bb_insert_post(array('topic_id' => $new_topic, 'post_text' => $t_tweet, 'poster_id' => bw_get_id_from_user($t_user), 'poster_ip' => '127.0.0.1'));
}
コード例 #11
0
             $topic_id = (int) $topic->topic_id;
             if ($voices = $bbdb->get_col($bbdb->prepare("SELECT DISTINCT poster_id FROM {$bbdb->posts} WHERE topic_id = %s AND post_status = '0';", $topic_id))) {
                 $voices = count($voices);
                 bb_update_topicmeta($topic_id, 'voices_count', $voices);
             }
         }
         unset($topics, $topic, $topic_id);
     }
 }
 if (isset($_POST['topic-deleted-posts']) && 1 == $_POST['topic-deleted-posts']) {
     $old = (array) $bbdb->get_col("SELECT object_id FROM {$bbdb->meta} WHERE object_type = 'bb_topics' AND meta_key = 'deleted_posts'");
     $old = array_flip($old);
     if ($topics = (array) $bbdb->get_results("SELECT topic_id, COUNT(post_id) AS count FROM {$bbdb->posts} WHERE post_status != '0' GROUP BY topic_id")) {
         $messages[] = __('Counting deleted posts&#8230;');
         foreach ($topics as $topic) {
             bb_update_topicmeta($topic->topic_id, 'deleted_posts', $topic->count);
             unset($old[$topic->topic_id]);
         }
         unset($topics, $topic);
     }
     if ($old) {
         $old = join(',', array_flip($old));
         $bbdb->query("DELETE FROM {$bbdb->meta} WHERE object_type = 'bb_topic' AND object_id IN ({$old}) AND meta_key = 'deleted_posts'");
         $messages[] = __('&#8230;counted deleted posts');
     } else {
         $messages[] = __('&#8230;no deleted posts to count');
     }
 }
 if (isset($_POST['forums']) && 1 == $_POST['forums']) {
     if ($all_forums = (array) $bbdb->get_col("SELECT forum_id FROM {$bbdb->forums}")) {
         $messages[] = __('Counted forum topics and posts');