Index: dashboard_blocks.module =================================================================== RCS file: dashboard_blocks.module diff -N dashboard_blocks.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dashboard_blocks.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,130 @@ + 'recent_content_refresh', + 'access arguments' => array('access dashboard'), + 'type' => MENU_CALLBACK, + ); + return $items; +} + +function dashboard_blocks_theme(){ + return array( + 'comment_approval_block' => array( + 'arguments' => array('cids'=> null), + ), + ); +} +/** + * Implementation of hook_block_info() + */ +function dashboard_blocks_block_info(){ + $blocks = array(); + $blocks['recent_content']= array( + 'info' => t('recently published content'), + ); + $blocks['comment_approval']=array( + 'info' => t('comments to be approved'), + ); + return $blocks; +} + +/** + * Implementation of hook_block_view(). + */ +function dashboard_blocks_block_view($delta=''){ + switch($delta){ + case 'recent_content': + drupal_add_js(drupal_get_path('module', 'recent_content') . '/recent_content.js'); + $settings = array( + 'recent_content' => array( + 'refresh' => url('recent_content/refresh'), + ), + ); + drupal_add_js($settings, array('type' => 'setting')); + $block = array( + 'subject' => 'Recent content', + 'content' => recent_content_display_block() + ); + return $block; + case 'comment_approval': + $block = array( + 'subject' => 'Recent comments', + 'content' => comment_approval_display_block() + ); + return $block; + } +} + +function recent_content_display_block(){ + $result = db_query_range('SELECT n.nid,n.changed FROM {node} n WHERE status = 1 ORDER BY n.changed DESC',0,10,array()); + $items = array(); + $nids = array(); + foreach($result as $record){ + $nids[] = $record->nid; + + } + + $nodes=node_load_multiple($nids); + foreach($nodes as $nid => $node){ + if(node_access('view',$node)){ + $item = l($node->title,'node/'. $nid); + if(node_access('update',$node)){ + $item .= l(' [edit]','node/'. $nid .'/edit'); + } + $items[] = $item; + } + } + return theme('item_list',$items); +} + +function comment_approval_display_block(){ + $result = db_query('SELECT c.cid,c.timestamp FROM {comment} c WHERE c.status = :status ORDER BY c.timestamp DESC',array(':status'=>COMMENT_NOT_PUBLISHED)); + $cids = array(); + foreach($result as $record){ + $cids[] = $record->cid; + } + return theme('comment_approval_block',$cids); +} + +function theme_comment_approval_block($cids){ + $output =''; + $uids = array(); + $comments = comment_load_multiple($cids); + foreach($comments as $comment){ + $uids[] = $comment->uid; + } + $users=user_load_multiple($uids); + foreach($comments as $comment){ + $output .= "
"; + $user = $users[$comment->uid]; + // theme user picture if available + if(!empty($user->picture)){ + $output .= theme('user_picture',$user); + } + $output .='
'; + $result = db_query('SELECT n.title,n.type FROM {node} n WHERE n.nid = :nid',array(':nid'=>$comment->nid)); + foreach($result as $record){ + $node_title=$record->title; + $node_type=$record->type; + // I bet there's a better way to fetch only 1 row + } + $output .= '
'. t('Submitted by ') . theme('username',$user) . ' on ' . format_date($comment->timestamp,'medium') . '
'; + $output .= node_type_get_name($node_type) . ': ' .l($node_title,'node/'. $comment->nid) .'
' . $comment->comment; + $output .="
"; + } + return $output; +} +/** + * ajax callback for refreshing recent_content block + * @return unknown_type + */ +function recent_content_refresh(){ + print recent_content_display_block(); +} \ No newline at end of file Index: recent_content.js =================================================================== RCS file: recent_content.js diff -N recent_content.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ recent_content.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ +// $Id +(function ($) { + +/** + * Implementation of Drupal.behaviors for dashboard. + */ +Drupal.behaviors.recent_content = { + attach: function(){ + $('#block-recent_content-recent_content').append('
'); + $('#block-recent_content-recent_content .refresh .action-links a').click(Drupal.behaviors.recent_content.refresh).addClass('use-ajax'); + }, + + /** + * refresh the content of the block + */ + refresh: function(){ + $.get(Drupal.settings.recent_content.refresh,{}, + function (data) { + $("#block-recent_content-recent_content > div.content").replaceWith(data); + }, + 'html' + ); + + } +}; + +})(jQuery); \ No newline at end of file Index: dashboard_blocks.info =================================================================== RCS file: dashboard_blocks.info diff -N dashboard_blocks.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dashboard_blocks.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +; $Id$ +name = dasboard blocks +description = blocks for use on the dasboard +package = core +core = 7.x +files[] = dashboard_blocks.module