"
.'No Comments!';
} else {
// $ncomms = $ncomms < 10 ? $ncomms : 10;
$htmlout =
// using the old api to make calling from js easier
// the new graph api method is much cleaner, but it causes problems in opera
// since it returns a value, which opera then prompts the user to open or save
"
"
."
"
// should probably change this to class so that it validates
.'
';
$parity = '';
$users = $comments[1]['fql_result_set'];
$comments = $comments[0]['fql_result_set'];
for ($i=0,$par=0;$i<$dcomms;$i++,$par++) {
// for people who use the same app id for more than one site,
// only return results unique to this xid
if ( strncmp($comments[$i]['xid'],$fbc_options['xid'],15) ) { $par--; continue; }
// find matching user
for ($j=0;$j$comments[$i][username]';
} else {
$username = ''. $users[$index]['name'] .'';
}
// make pretty
$commenttext = $comments[$i]['text'];
$order = array("\r\n", "\n", "\r");
$replace = ' ';
// Processes \r\n's first so they aren't converted twice.
$commenttext = str_replace($order, $replace, $commenttext);
// url of post/page on which comment was made
$post_id = substr($comments[$i]['xid'],20);
$commenturl = get_permalink($post_id);
// make pretty alternations
$parity = ($par&1)
? "comment byuser comment-author-admin odd alt thread-odd thread-alt depth-1 comment-item approved":
"comment byuser comment-author-admin even thread-even depth-1 comment-item approved";
$imgurl = $users[$index]['pic_square'];
// what will be written to the dashboard widget
$htmlout .=
'
';
print_r($htmlout);
}
}
// Create the function used in the action hook
function fbcomments_add_dashboard_widgets() {
global $fbc_options;
if ($fbc_options['showDBWidget'] == true)
wp_add_dashboard_widget('dashboard_widget', 'Recent Facebook comments', 'fbcomments_dashboard_widget_function');
}
/**********************************
Page recent comments widget
**********************************/
/* add styles before wp_head is loaded
see: http://bit.ly/igYFYu
*/
function conditionally_add_scripts_and_styles($posts){
if (empty($posts)) return $posts;
// enqueue here
wp_enqueue_style('fbc_rc_widgets-style', FBCOMMENTS_CSS_WIDGETS);
return $posts;
}
/**
* Recent_Comments widget class
*
* @since 3.0.0
*/
class FBCRC_Widget extends WP_Widget {
/** constructor */
function FBCRC_Widget() {
$widget_ops = array( 'description' => __('The most recent Facebook comments.') );
parent::WP_Widget(false, $name = 'Recent Facebook Comments', $widget_ops);
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
global $fbc_options;
$atoken = $fbc_options['accessToken'];
$fb = fbComments_getFbApi();
/*
select post_id, fromid, time, text, post_fbid
from comment
where object_id
in (select comments_fbid from link_stat where url="http://developers.facebook.com/blog/post/472")'
*/
$commentsq = "SELECT fromid, text, id, time, username, xid, object_id ".
"FROM comment WHERE xid IN (SELECT xid FROM comments_info WHERE app_id={$fbc_options['appId']})".
"ORDER BY time desc";
// $commurl = urlencode('');
// $commentsq = "SELECT fromid, text, id, time, username, xid, post_id, post_fbid, object_id ".
// "FROM comment ".
// "WHERE (xid IN (SELECT xid FROM comments_info WHERE app_id={$fbc_options['appId']})) ".
// "OR object_id IN (SELECT comments_fbid FROM link_stat WHERE url='$commurl') ".
// "ORDER BY time desc";
// $commentsq = "SELECT post_id, fromid, time, text, post_fbid ".
// 'FROM comment'.
// "ORDER BY time desc";
$usersq = "SELECT id, name, url, pic_square FROM profile ".
"WHERE id IN (SELECT fromid FROM #comments)";
$query = '{
"comments": "' . $commentsq . '",
"users": "' . $usersq . '"
}';
$query = array("method"=>"fql.multiquery","queries"=>$query,'access_token'=>$atoken);
$comments = $fb->api($query);
if ( ! $number = (int) $instance['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
$ncomms = sizeof($comments[0]['fql_result_set']);
// if no comments, display no comments; otherwise display the greater of $ncomms and $number comments
$ncomms = $ncomms == 0 ? 0 : ($ncomms < $number ? $ncomms : $number);
$output = '
';
$parity = '';
$users = $comments[1]['fql_result_set'];
$comments = $comments[0]['fql_result_set'];
$show_avatar = isset($instance['show_avatar']) ? $instance['show_avatar'] : true;
for ($i=0,$par=0;$i<$ncomms;$i++,$par++) {
if ( strncmp($comments[$i]['xid'],$fbc_options['xid'],15) ) { $par--; continue; }
// find matching user
for ($j=0;$j'.$users[$index]['name'].'';
}
// print user defined number of words, if there are less than this, don't trim
$commenttext = trim($comments[$i]['text'], ' ');
$nwords = count(explode(" ",$commenttext));
$dwords = $nwords <= $instance['word_count'] ? $nwords : $instance['word_count'];
if ($nwords > $dwords) {
preg_match("/^(\S+\s+){0,$dwords}/", $commenttext, $matches); // match spaces (nth space will be at end of nth word)
$commenttext = trim($matches[0]) . '[...]';
}
// print line breaks as such
$order = array("\r\n", "\n", "\r"); // Processes \r\n's first so they aren't converted twice.
$replace = ' ';
$commenttext = str_replace($order, $replace, $commenttext);
// url of post/page on which comment was made
$post_id = substr($comments[$i]['xid'],20);
$commenturl = get_permalink($post_id);
// to allow alternating styles on comments
$parity = ($par&1) ? "odd": "even";
// display avatar only if option is checked
if ($show_avatar) {
$imgurl = $users[$index]['pic_square'];
$imgclass = '';
} else {
$imgurl = $users[$index]['pic_square'];
$imgclass = 'style="display:none"';
}
// what will be written to the widget
$output .=
'
'.$username.'
'.date('d M Y',$comments[$i]['time']).'
'; // Processes \r\n's first so they aren't converted twice. $commenttext = str_replace($order, $replace, $commenttext); // url of post/page on which comment was made $post_id = substr($comments[$i]['xid'],20); $commenturl = get_permalink($post_id); // make pretty alternations $parity = ($par&1) ? "comment byuser comment-author-admin odd alt thread-odd thread-alt depth-1 comment-item approved": "comment byuser comment-author-admin even thread-even depth-1 comment-item approved"; $imgurl = $users[$index]['pic_square']; // what will be written to the dashboard widget $htmlout .= '
From '. ''.$username.' on '. ''.get_post($post_id)->post_title.' '.date('d M Y',$comments[$i]['time']).' [Pending]'. '
delete '. "