Esempio n. 1
0
/**
 * Get array of latest comments
 *
 * @param array of params
 *			- Blog (object)
 *			- User (object)
 *			- limit (int) the number of comments to return
 *			- comment_ID (int) return specified comment or NULL to return all available
 *			- item_ID (int) return comments for specified item only
 * @return xmlrpcmsg
 */
function xmlrpc_get_comments($params, &$Blog)
{
    global $DB, $current_User;
    $params = array_merge(array('limit' => 0, 'comment_ID' => 0, 'item_ID' => 0, 'statuses' => '', 'types' => array('comment', 'trackback', 'pingback')), $params);
    $params['comment_ID'] = abs(intval($params['comment_ID']));
    $params['item_ID'] = abs(intval($params['item_ID']));
    if (empty($params['statuses'])) {
        // Return all except 'trash'
        $params['statuses'] = array('published', 'deprecated', 'draft');
    }
    if (!empty($params['comment_ID'])) {
        logIO('Getting comment #' . $params['comment_ID']);
        $filters = array('comment_ID' => $params['comment_ID'], 'types' => $params['types'], 'statuses' => $params['statuses']);
    } elseif (!empty($params['item_ID'])) {
        logIO('Getting comments to item #' . $params['item_ID']);
        $ItemCache =& get_ItemCache();
        $Item =& $ItemCache->get_by_ID($params['item_ID'], false, false);
        if (empty($Item)) {
            // Item not found
            return xmlrpcs_resperror(5, 'Requested post/Item (' . $params['item_ID'] . ') does not exist.');
        }
        if (!$Item->can_see_comments()) {
            // Cannot see comments
            return xmlrpcs_resperror(5, 'You are not allowed to view comments for this post/Item (' . $params['item_ID'] . ').');
        }
        $filters = array('post_ID' => $Item->ID, 'types' => $params['types'], 'statuses' => $params['statuses'], 'comments' => $params['limit'], 'order' => 'DESC');
    } else {
        logIO(sprintf('Trying to get latest comments (%s)', $params['limit'] ? $params['limit'] : 'all'));
        $filters = array('types' => $params['types'], 'statuses' => $params['statuses'], 'comments' => $params['limit'], 'order' => 'DESC');
    }
    //logIO( "Filters:\n".var_export($filters, true) );
    $CommentList = new CommentList2($Blog);
    // Filter list:
    $CommentList->set_filters($filters, false);
    // Get ready for display (runs the query):
    $CommentList->display_init();
    logIO('Comments found: ' . $CommentList->result_num_rows);
    $data = array();
    if ($CommentList->result_num_rows) {
        while ($Comment =& $CommentList->get_next()) {
            // Loop through comments:
            $Comment->get_Item();
            $data[] = array('dateCreated' => new xmlrpcval(datetime_to_iso8601($Comment->date, true), 'dateTime.iso8601'), 'date_created_gmt' => new xmlrpcval(datetime_to_iso8601($Comment->date, true), 'dateTime.iso8601'), 'user_id' => new xmlrpcval(intval($Comment->author_user_ID)), 'comment_id' => new xmlrpcval($Comment->ID), 'parent' => new xmlrpcval(intval($Comment->in_reply_to_cmt_ID)), 'status' => new xmlrpcval(wp_or_b2evo_comment_status($Comment->status, 'wp')), 'content' => new xmlrpcval($Comment->content), 'link' => new xmlrpcval($Comment->get_permanent_url()), 'post_id' => new xmlrpcval($Comment->Item->ID), 'post_title' => new xmlrpcval($Comment->Item->title), 'author' => new xmlrpcval($Comment->get_author_name()), 'author_url' => new xmlrpcval($Comment->get_author_url()), 'author_email' => new xmlrpcval($Comment->get_author_email()), 'author_ip' => new xmlrpcval($Comment->author_IP), 'type' => new xmlrpcval($Comment->type == 'comment' ? '' : $Comment->type));
        }
    }
    return $data;
}
Esempio n. 2
0
 }
 $user_perm_moderate_cmt = count($user_modeartion_statuses);
 if ($user_perm_moderate_cmt) {
     /*
      * COMMENTS:
      */
     $CommentList = new CommentList2($Blog);
     // Filter list:
     $CommentList->set_filters(array('types' => array('comment', 'trackback', 'pingback'), 'statuses' => $user_modeartion_statuses, 'user_perm' => 'moderate', 'post_statuses' => array('published', 'community', 'protected'), 'order' => 'DESC', 'comments' => 30));
     // Set param prefix for URLs
     $param_prefix = 'cmnt_fullview_';
     if (!empty($CommentList->param_prefix)) {
         $param_prefix = $CommentList->param_prefix;
     }
     // Get ready for display (runs the query):
     $CommentList->display_init();
 }
 if ($user_perm_moderate_cmt && $CommentList->result_num_rows) {
     // We have comments awaiting moderation
     load_funcs('comments/model/_comment_js.funcs.php');
     $nb_blocks_displayed++;
     $opentrash_link = get_opentrash_link(true, false, array('class' => 'btn btn-default'));
     $refresh_link = '<span class="floatright">' . action_icon(T_('Refresh comment list'), 'refresh', $admin_url . '?blog=' . $blog, ' ' . T_('Refresh'), 3, 4, array('onclick' => 'startRefreshComments( \'' . request_from() . '\' ); return false;', 'class' => 'btn btn-default')) . '</span> ';
     $show_statuses_param = $param_prefix . 'show_statuses[]=' . implode('&amp;' . $param_prefix . 'show_statuses[]=', $user_modeartion_statuses);
     $block_item_Widget->title = $refresh_link . $opentrash_link . T_('Comments awaiting moderation') . ' <a href="' . $admin_url . '?ctrl=comments&amp;blog=' . $Blog->ID . '&amp;' . $show_statuses_param . '" style="text-decoration:none">' . '<span id="badge" class="badge badge-important">' . $CommentList->get_total_rows() . '</span></a>' . get_manual_link('collection-dashboard');
     echo '<div class="evo_content_block">';
     echo '<div id="comments_block" class="dashboard_comments_block">';
     $block_item_Widget->disp_template_replaced('block_start');
     echo '<div id="comments_container">';
     // GET COMMENTS AWAITING MODERATION (the code generation is shared with the AJAX callback):
     show_comments_awaiting_moderation($Blog->ID, $CommentList);
Esempio n. 3
0
/**
 * Display CommentList with the given filters
 *
 * @param integer Blog ID
 * @param integer Item ID
 * @param array Status filters
 * @param integer Limit
 * @param array Comments IDs string to exclude from the list
 * @param string Filterset name
 * @param string Expiry status: 'all', 'active', 'expired'
 */
function echo_item_comments($blog_ID, $item_ID, $statuses = NULL, $currentpage = 1, $limit = 20, $comment_IDs = array(), $filterset_name = '', $expiry_status = 'active')
{
    global $inc_path, $status_list, $Blog, $admin_url;
    $BlogCache =& get_BlogCache();
    $Blog =& $BlogCache->get_by_ID($blog_ID, false, false);
    global $CommentList;
    $CommentList = new CommentList2($Blog, $limit, 'CommentCache', '', $filterset_name);
    $exlude_ID_list = NULL;
    if (!empty($comment_IDs)) {
        $exlude_ID_list = '-' . implode(",", $comment_IDs);
    }
    if (empty($statuses)) {
        $statuses = get_visibility_statuses('keys', array('redirected', 'trash'));
    }
    if ($expiry_status == 'all') {
        // Display all comments
        $expiry_statuses = array('active', 'expired');
    } else {
        // Display active or expired comments
        $expiry_statuses = array($expiry_status);
    }
    // if item_ID == -1 then don't use item filter! display all comments from current blog
    if ($item_ID == -1) {
        $item_ID = NULL;
    }
    // set redirect_to
    if ($item_ID != null) {
        // redirect to the items full view
        param('redirect_to', 'url', url_add_param($admin_url, 'ctrl=items&blog=' . $blog_ID . '&p=' . $item_ID, '&'));
        param('item_id', 'integer', $item_ID);
        param('currentpage', 'integer', $currentpage);
        if (count($statuses) == 1) {
            $show_comments = $statuses[0];
        } else {
            $show_comments = 'all';
        }
        param('comments_number', 'integer', generic_ctp_number($item_ID, 'comments', $show_comments));
        // Filter list:
        $CommentList->set_filters(array('types' => array('comment', 'trackback', 'pingback'), 'statuses' => $statuses, 'expiry_statuses' => $expiry_statuses, 'comment_ID_list' => $exlude_ID_list, 'post_ID' => $item_ID, 'order' => 'ASC', 'comments' => $limit, 'page' => $currentpage));
    } else {
        // redirect to the comments full view
        param('redirect_to', 'url', url_add_param($admin_url, 'ctrl=comments&blog=' . $blog_ID . '&filter=restore', '&'));
        // this is an ajax call we always have to restore the filterst (we can set filters only without ajax call)
        $CommentList->set_filters(array('types' => array('comment', 'trackback', 'pingback')));
        $CommentList->restore_filterset();
    }
    // Get ready for display (runs the query):
    $CommentList->display_init();
    $CommentList->display_if_empty(array('before' => '<div class="bComment"><p>', 'after' => '</p></div>', 'msg_empty' => T_('No feedback for this post yet...')));
    // display comments
    require $inc_path . 'comments/views/_comment_list.inc.php';
}
Esempio n. 4
0
 function disp_feedback_list($type = 'comment', $params = array())
 {
     global $Blog, $Item, $app_version;
     $type_list = array($type);
     if (version_compare($app_version, '4.0') < 0) {
         // b2evo 3
         //array_walk($type_list, function(&$v){ $v = "'$v'"; });
         foreach ($type_list as $v) {
             $type_list_fixed[] = "'{$v}'";
         }
         $CommentList = new CommentList(NULL, implode(',', $type_list_fixed), array('published'), $Item->ID, '', 'ASC');
     } else {
         // b2evo 4
         $type = substr($type, 0, 1);
         $CommentList = new CommentList2($Blog, $Blog->get_setting('comments_per_page'), 'CommentCache', $type . '_');
         // Filter list:
         $CommentList->set_default_filters(array('types' => $type_list, 'statuses' => array('published'), 'post_ID' => $Item->ID, 'order' => $Blog->get_setting('comments_orderdir')));
         $CommentList->load_from_Request();
         // Get ready for display (runs the query):
         $CommentList->display_init();
     }
     if ($CommentList->result_num_rows < 1) {
         return;
     }
     forget_param('c');
     forget_param('tb');
     forget_param('pb');
     forget_param('disp');
     forget_param('more');
     forget_param('title');
     if (method_exists($CommentList, 'page_links') && $Blog->get_setting('paged_comments')) {
         // Navigation
         $CommentList->page_links(array('page_url' => url_add_tail($Item->get_permanent_url(), '#post-tabs'), 'block_start' => '<div class="comment-navigation clearfix">', 'block_end' => '</div>', 'prev_text' => '&laquo;', 'next_text' => '&raquo;'));
         $nav_displayed = 1;
     }
     echo $params['comment_list_start'];
     while ($Comment =& $CommentList->get_next()) {
         // Loop through comments:
         // ------------------ COMMENT INCLUDED HERE ------------------
         skin_include($params['comment_template'], array('Comment' => &$Comment, 'comment_start' => $params['comment_start'], 'comment_end' => $params['comment_end'], 'link_to' => $params['link_to']));
         // ---------------------- END OF COMMENT ---------------------
     }
     // End of comment list loop.
     echo $params['comment_list_end'];
     if (!empty($nav_displayed)) {
         // Navigation
         $CommentList->page_links(array('page_url' => url_add_tail($Item->get_permanent_url(), '#post-tabs'), 'block_start' => '<div class="comment-navigation clearfix">', 'block_end' => '</div>', 'prev_text' => '&laquo;', 'next_text' => '&raquo;'));
     }
 }
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     global $Blog;
     $this->init_display($params);
     $blog_ID = intval($this->disp_params['blog_ID']);
     $blogCache =& get_BlogCache();
     $listBlog = $blog_ID ? $blogCache->get_by_ID($blog_ID) : $Blog;
     // Create ItemList
     // Note: we pass a widget specific prefix in order to make sure to never interfere with the mainlist
     $limit = intval($this->disp_params['limit']);
     $order = $this->disp_params['disp_order'];
     $CommentList = new CommentList2($listBlog, $limit, 'CommentCache', $this->code . '_');
     $filters = array('types' => array('comment', 'trackback', 'pingback'), 'statuses' => array('published'), 'order' => $order, 'comments' => $limit);
     if (isset($this->disp_params['page'])) {
         $filters['page'] = $this->disp_params['page'];
     }
     // Filter list:
     $CommentList->set_filters($filters);
     // Get ready for display (runs the query):
     $CommentList->display_init();
     echo $this->disp_params['block_start'];
     // Display title if requested
     $this->disp_title();
     echo $this->disp_params['block_body_start'];
     echo $this->disp_params['list_start'];
     if (empty($this->disp_params['author_link_text'])) {
         $this->disp_params['author_link_text'] = 'login';
     }
     /**
      * @var Comment
      */
     while ($Comment =& $CommentList->get_next()) {
         // Loop through comments:
         // Load comment's Item object:
         $Comment->get_Item();
         echo $this->disp_params['item_start'];
         $Comment->author('', ' ', '', ' ', 'htmlbody', $this->disp_params['author_links'], $this->disp_params['author_link_text']);
         echo T_('on ');
         $Comment->permanent_link(array('text' => $Comment->Item->title, 'title' => $this->disp_params['hover_text']));
         echo $this->disp_params['item_end'];
     }
     // End of comment loop.}
     if (isset($this->disp_params['page'])) {
         if (empty($this->disp_params['pagination'])) {
             $this->disp_params['pagination'] = array();
         }
         $CommentList->page_links($this->disp_params['pagination']);
     }
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_body_end'];
     echo $this->disp_params['block_end'];
     return true;
 }
Esempio n. 6
0
/**
 * Show comments awaiting moderation
 *
 * @todo fp> move this to a more appropriate place
 *
 * @param integer blog ID
 * @param object CommentList
 * @param integer limit
 * @param array comment IDs to exclude
 * @param boolean TRUE - for script
 */
function show_comments_awaiting_moderation($blog_ID, $CommentList = NULL, $limit = 5, $comment_IDs = array(), $script = true)
{
    global $current_User, $dispatcher;
    if (is_null($CommentList)) {
        // Inititalize CommentList
        $BlogCache =& get_BlogCache();
        $Blog =& $BlogCache->get_by_ID($blog_ID, false, false);
        $CommentList = new CommentList2($Blog, NULL, 'CommentCache', 'cmnt_fullview_', 'fullview');
        $exlude_ID_list = NULL;
        if (!empty($comment_IDs)) {
            $exlude_ID_list = '-' . implode(",", $comment_IDs);
        }
        $moderation_statuses = explode(',', $Blog->get_setting('moderation_statuses'));
        // Filter list:
        $CommentList->set_filters(array('types' => array('comment', 'trackback', 'pingback'), 'statuses' => $moderation_statuses, 'comment_ID_list' => $exlude_ID_list, 'post_statuses' => array('published', 'community', 'protected'), 'order' => 'DESC', 'comments' => $limit));
        // Get ready for display (runs the query):
        $CommentList->display_init();
    }
    $new_comment_IDs = array();
    while ($Comment =& $CommentList->get_next()) {
        // Loop through comments:
        $new_comment_IDs[] = $Comment->ID;
        echo '<div id="comment_' . $Comment->ID . '" class="dashboard_post dashboard_post_' . ($CommentList->current_idx % 2 ? 'even' : 'odd') . '">';
        echo '<div class="floatright"><span class="note status_' . $Comment->status . '"><span>';
        $Comment->status();
        echo '</span></span></div>';
        if ($Comment->status !== 'draft' || $Comment->author_user_ID == $current_User->ID) {
            // Display Comment permalink icon
            echo '<span style="float: left; padding-right: 5px; margin-top: 4px">' . $Comment->get_permanent_link('#icon#') . '</span>';
        }
        echo '<h3 class="dashboard_post_title">';
        echo $Comment->get_title(array('author_format' => '<strong>%s</strong>', 'link_text' => 'avatar', 'thumb_size' => 'crop-top-15x15'));
        $comment_Item =& $Comment->get_Item();
        echo ' ' . T_('in response to') . ' <a href="?ctrl=items&amp;blog=' . $comment_Item->get_blog_ID() . '&amp;p=' . $comment_Item->ID . '"><strong>' . $comment_Item->dget('title') . '</strong></a>';
        echo '</h3>';
        echo '<div class="notes">';
        $Comment->rating(array('before' => '<div class="dashboard_rating">', 'after' => '</div> &bull; '));
        $Comment->date();
        $Comment->author_url_with_actions('', true);
        $Comment->author_email('', ' &bull; Email: <span class="bEmail">', '</span> &bull; ');
        $Comment->author_ip('IP: <span class="bIP">', '</span> ', true);
        $Comment->ip_country();
        $Comment->spam_karma(' &bull; ' . T_('Spam Karma') . ': %s%', ' &bull; ' . T_('No Spam Karma'));
        echo '</div>';
        echo '<div class="small">';
        $Comment->content('htmlbody', true);
        echo '</div>';
        echo '<div class="dashboard_action_area">';
        // Display edit button if current user has the rights:
        $redirect_to = NULL;
        if (!$script) {
            // Set page, where to redirect, because the function is called from async.php (regenerate_url gives => async.php)
            global $admin_url;
            $redirect_to = $admin_url . '?ctrl=dashboard&blog=' . $blog_ID;
        }
        echo '<div class="floatleft">';
        $Comment->edit_link(' ', ' ', get_icon('edit'), '#', 'roundbutton', '&amp;', true, $redirect_to);
        echo '<span class="roundbutton_group">';
        // Display publish NOW button if current user has the rights:
        $Comment->publish_link('', '', '#', '#', 'roundbutton_text', '&amp;', true, true);
        // Display deprecate button if current user has the rights:
        $Comment->deprecate_link('', '', '#', '#', 'roundbutton_text', '&amp;', true, true);
        // Display delete button if current user has the rights:
        $Comment->delete_link('', '', '#', '#', 'roundbutton_text', false, '&amp;', true, true);
        echo '</span>';
        echo '</div>';
        // Display Spam Voting system
        $Comment->vote_spam('', '', '&amp;', true, true);
        echo '<div class="clear"></div>';
        echo '</div>';
        echo '</div>';
    }
    if (!$script) {
        echo '<input type="hidden" id="new_badge" value="' . $CommentList->total_rows . '"/>';
    }
}