'Recent Comments', 'page callback' => 'drupal_get_form', 'page arguments' => array('recent_comments_settings'), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('administer recent_comments'), ); return $items; } /** * Implementation of hook_perm(). */ function recent_comments_perm() { return array('administer recent_comments'); } /** * Implementation of hook_block(). */ function recent_comments_block($op = 'list', $delta = 0, $edit = array()) { if ($op == 'list') { $block[0]['info'] = t('Recent comments (Recent Comments module)'); return $block; } else if ($op == 'view' && user_access('access comments')) { $block['subject'] = t('Recent comments'); $block['content'] = _recent_comments_getcontent(variable_get('recent_comments_num', 10)); return $block; } } /** * Implementation of hook_settings(). */ function recent_comments_settings() { $form = array(); $form['recent_comments_num'] = array( '#type' => 'textfield', '#title' => t('Number of comments to display'), '#default_value' => variable_get('recent_comments_num', 10), '#maxlength' => '3', '#size' => '3', ); $form['recent_comments_nodetypes'] = array( '#type' => 'checkboxes', '#title' => t('Display comments for only these content types'), '#options' => node_get_types('names'), '#default_value' => variable_get('recent_comments_nodetypes', array('story')), ); return system_settings_form($form); } /** * Implementation of hook_form_alter(). */ function recent_comments_form_alter(&$form, $form_state, $form_id) { // Rename some blocks in the block admin form to avoid confusion if ($form_id == 'block_admin_display_form') { if (module_exists('comment') || module_exists('views')) { foreach ($form as $key => $block) { if (is_array($block)) { $block_module = $block['module']['#value']; $block_delta = $block['delta']['#value']; if (($block_module == 'comment') && ($block_delta == 0)) { $form[$key]['info']['#value'] .= ' (Comment module)'; } else if (($block_module == 'views') && ($block_delta == 'comments_recent')) { $form[$key]['info']['#value'] .= ' (Views module)'; } } } } } } /** * Get the themed comment list. * * @param $num int * The number of comments to retrieve. * * @return string * The rendered HTML links. */ function _recent_comments_getcontent($num) { $node_types = variable_get('recent_comments_nodetypes', array('story')); $types = "'" . implode("', '", $node_types) . "'"; $query = 'SELECT subject, name, c.timestamp, cid, c.nid FROM {comments} c INNER JOIN {node} n ON (n.nid = c.nid) WHERE c.status = 0 AND n.type IN (' . $types . ') ORDER BY timestamp DESC'; $query = db_rewrite_sql($query, '{comments}', 'cid'); $result = db_query_range($query, 0, $num); while ($comment = db_fetch_object($result)) { $item = theme('recent_comments_link', $comment); $items[] = $item; } return theme('item_list', $items); } /** * Return a link to the comment. * * @param $comment * The comment object from _recent_comments_getcontent(). */ function theme_recent_comments_link($comment) { $link_text = ''; if (!empty($comment->name)) { $link_text .= $comment->name .': '; } // Theming example: Use the node's title in the comment link /* $node = node_load($comment->nid); $link_text .= $node->title . ': '; */ $link_text .= $comment->subject; return l($link_text, 'node/' . $comment->nid, array(), NULL, 'comment-' . $comment->cid); } function recent_comments_theme() { return array( 'recent_comments_link' => array( 'arguments' => array($comment => NULL), ), ); }