Public feed
#600683
function blog_block($op = 'list', $delta = 0) {
global $user;
if ($op == 'list') {
$block[0]['info'] = t('Recent blog posts');
$block[1]['info'] = t('MyExchange Blog');
return $block;
}
else if ($op == 'view') {
if (user_access('access content')) {
$blog_sql = "SELECT n.nid, n.title, n.created, n.uid " .
"FROM {node} n " .
"WHERE n.type = 'blog' " .
"AND n.status = 1 ";
// a bit of a hack right here.. no point in duplicating code though..
if($delta == '0') {
$header = t('Recent blog posts');
} else if ($delta == '1') {
$header = t('MyBlog');
// get the user selected from the URI.
if(is_numeric(arg(1))) {
$user_details = user_load(array('uid' => arg(1)));
// user exist?
if($user_details === FALSE) {
// make it return nothing if the user_id requested doesnt exist
return FALSE;
} else {
// otherwise we need to get the last 10 posts for the user
$blog_sql .= "AND n.uid=%s ";
}
}
}
$blog_sql .= "ORDER BY n.created DESC";
print"<pre>";
print $blog_sql;
print"</pre>";
// i'd kill for some real data objects so I didnt have to do this:
if(isset($user_details->uid)) {
$result = db_query_range(db_rewrite_sql($blog_sql), 0, 10, $user_details->uid);
} else {
$result = db_query_range(db_rewrite_sql($blog_sql), 0, 10);
}
// well, it'll work i guess.
if (db_num_rows($result)) {
$block['content'] = node_title_list($result);
} else {
$block['content'] = t("This user has not posted any blog entries.");
}
$block['content'] = 'nothing';
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
$block['subject'] = $header;
return $block;
}
}
}