예제 #1
0
function dsq_sync_forum($last_comment_id = false, $force = false)
{
    global $dsq_api, $wpdb;
    set_time_limit(DISQUS_SYNC_TIMEOUT);
    if ($force) {
        $sync_time = null;
    } else {
        $sync_time = (int) get_option('_disqus_sync_lock');
    }
    // lock expires after 1 hour
    if ($sync_time && $sync_time > time() - 60 * 60) {
        $dsq_api->api->last_error = 'Sync already in progress (lock found)';
        return false;
    } else {
        update_option('_disqus_sync_lock', time());
    }
    // sync all pending posts
    $post_ids = dsq_get_pending_post_ids();
    dsq_clear_pending_post_ids($post_ids);
    foreach ($post_ids as $post_id) {
        dsq_sync_post($post_id);
    }
    if ($last_comment_id === false) {
        $last_comment_id = get_option('disqus_last_comment_id');
        if (!$last_comment_id) {
            $last_comment_id = 0;
        }
    }
    if ($last_comment_id) {
        $last_comment_id++;
    }
    //$last_comment_id = 0;
    // Pull comments from API
    $dsq_response = $dsq_api->get_forum_posts($last_comment_id);
    if ($dsq_response < 0 || $dsq_response === false) {
        return false;
    }
    // Sync comments with database.
    dsq_sync_comments($dsq_response);
    $total = 0;
    if ($dsq_response) {
        foreach ($dsq_response as $comment) {
            $total += 1;
            if ($comment->id > $last_comment_id) {
                $last_comment_id = $comment->id;
            }
        }
        if ($last_comment_id > get_option('disqus_last_comment_id')) {
            update_option('disqus_last_comment_id', $last_comment_id);
        }
    }
    unset($comment);
    delete_option('_disqus_sync_lock');
    return array($total, $last_comment_id);
}
예제 #2
0
function dsq_comments_template($value)
{
    global $dsq_response;
    global $dsq_sort;
    global $dsq_api;
    global $post;
    if (!(is_singular() && (have_comments() || 'open' == $post->comment_status))) {
        return;
    }
    if (!dsq_can_replace()) {
        return $value;
    }
    if (dsq_legacy_mode()) {
        return dirname(__FILE__) . '/comments-legacy.php';
    }
    $permalink = get_permalink();
    $title = get_the_title();
    $excerpt = get_the_excerpt();
    $dsq_sort = get_option('disqus_sort');
    if (is_numeric($_COOKIE['disqus_sort'])) {
        $dsq_sort = $_COOKIE['disqus_sort'];
    }
    if (is_numeric($_GET['dsq_sort'])) {
        setcookie('disqus_sort', $_GET['dsq_sort']);
        $dsq_sort = $_GET['dsq_sort'];
    }
    // Call "get_thread" API method.
    $dsq_response = $dsq_api->get_thread($post, $permalink, $title, $excerpt);
    if ($dsq_response < 0) {
        return false;
    }
    // Sync comments with database.
    dsq_sync_comments($post, $dsq_response['posts']);
    // TODO: If a disqus-comments.php is found in the current template's
    // path, use that instead of the default bundled comments.php
    //return TEMPLATEPATH . '/disqus-comments.php';
    return dirname(__FILE__) . '/comments.php';
}
예제 #3
0
function dsq_sync_forum($last_comment_id = false)
{
    global $dsq_api, $wpdb;
    if ($last_comment_id === false) {
        $last_comment_id = get_option('disqus_last_comment_id');
        if (!$last_comment_id) {
            $last_comment_id = 0;
        }
    }
    if ($last_comment_id) {
        $last_comment_id++;
    }
    //$last_comment_id = 0;
    // Pull comments from API
    $dsq_response = $dsq_api->get_forum_posts($last_comment_id);
    if ($dsq_response < 0 || $dsq_response === false) {
        return false;
    }
    // Sync comments with database.
    dsq_sync_comments($dsq_response);
    $total = 0;
    if ($dsq_response) {
        foreach ($dsq_response as $comment) {
            $total += 1;
            if ($comment->id > $last_comment_id) {
                $last_comment_id = $comment->id;
            }
        }
        if ($last_comment_id > get_option('disqus_last_comment_id')) {
            update_option('disqus_last_comment_id', $last_comment_id);
        }
    }
    unset($comment);
    return array($total, $last_comment_id);
}
예제 #4
0
function dsq_sync_post($post_id)
{
    global $dsq_api;
    $post = get_post($post_id);
    // Call update_thread to ensure our permalink is up to date
    dsq_update_permalink($post);
    // Pull comments from API
    $dsq_response = $dsq_api->get_thread($post);
    if ($dsq_response < 0) {
        // header("HTTP/1.0 500 Internal Server Error");
        echo 'There was an error when attempting to sync comments';
        return;
    }
    // Sync comments with database.
    dsq_sync_comments($post, $dsq_response);
}
예제 #5
0
파일: disqus.php 프로젝트: easunlee/MT-copy
function dsq_comments_template($value)
{
    global $dsq_response;
    global $dsq_sort;
    global $dsq_api;
    global $post;
    //	if ( ! (is_single() || is_page() || $withcomments) ) {
    //		return;
    //	}
    //	if ( !dsq_can_replace() ) {
    //		return $value;
    //	}
    //	if ( dsq_legacy_mode() ) {
    //		return dirname(__FILE__) . '/comments-legacy.php';
    //	}
    $permalink = get_permalink();
    $title = get_the_title();
    $excerpt = get_the_excerpt();
    $dsq_sort = get_option('disqus_sort');
    if (is_numeric($_COOKIE['disqus_sort'])) {
        $dsq_sort = $_COOKIE['disqus_sort'];
    }
    if (is_numeric($_GET['dsq_sort'])) {
        setcookie('disqus_sort', $_GET['dsq_sort']);
        $dsq_sort = $_GET['dsq_sort'];
    }
    // echo var_dump($dsq_api);
    // Call "get_thread" API method.
    $dsq_response = $dsq_api->get_thread($post, $permalink, $title, $excerpt);
    // echo var_dump($dsq_response);
    if ($dsq_response < 0) {
        return false;
    }
    // Sync comments with database.
    if (!get_option('disqus_disable_sync')) {
        dsq_sync_comments($post, $dsq_response['posts']);
    }
    // TODO: If a disqus-comments.php is found in the current template's
    // path, use that instead of the default bundled comments.php
    //return TEMPLATEPATH . '/disqus-comments.php';
    $comments = array('none');
    return dirname(__FILE__) . '/comments.php';
}