'.t('Are you sure?').''; $block['content'] .= adminblock_multiple_delete_confirm(); } else $block['content'] = adminblock_view(); return $block; } } function adminblock_view() { $nlimit = 10; if (user_access('administer comments')) { $result = db_query_range('SELECT c.timestamp, c.subject, c.comment, c.cid, c.nid, c.uid, c.name, n.title FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.status = 1 ORDER BY c.timestamp DESC ', 0, $nlimit); $comment_count = db_num_rows($result); $comment_count_display = $comment_count > $nlimit ? ' ('. $comment_count .')' : ''; $comments = array(); while ($comment = db_fetch_object($result)) { $comments[$comment->cid] = l(truncate_utf8(check_plain($comment->comment),256), 'node/'. $comment->nid, array('title' => $comment->title), NULL, 'comment-'. $comment->cid) .'
['.($comment->uid!=0?l(t('By %user', array('%user' => $comment->name)), 'user/'. $comment->uid):t('By %user', array('%user' => $comment->name))) .']|['. l(t('edit'), 'comment/edit/'. $comment->cid) .']'; } if($comments) $form['comments'] = array( '#type' => 'checkboxes', '#title' => l(t('Comments queue'),'admin/comment/list/approval'), '#options' => $comments, ); } if (user_access('administer nodes')) { $result2 = db_query_range('SELECT n.nid, n.title, n.changed, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 0 AND n.moderate = 1 ORDER BY n.changed DESC', 0, $nlimit); $node_count = db_num_rows($result2); $node_count_display = $node_count > $nlimit ? ' ('. $node_count .')' : ''; $nodes = array(); while ($node = db_fetch_object($result2)) { $nodes[$node->nid] = l(check_plain($node->title),'node/'.$node->nid) .'
['. l(t('By %user', array('%user' => $node->name)), 'user/'. $node->uid) .']|['. l(t('edit'), 'node/'. $node->nid .'/edit') .']'; } if($nodes) $form['nodes'] = array( '#type' => 'checkboxes', '#title' => l(t('Content queue'),'admin/node'), '#options' => $nodes, ); } if (module_exist('trackback') && user_access('administer trackbacks')) { $result3 = db_query_range('SELECT t.created, t.subject, t.nid, t.trid, t.excerpt FROM {trackback_received} t INNER JOIN {node} n ON t.nid = n.nid WHERE t.status = 0 ORDER BY t.created DESC ', 0, $nlimit); $trackback_count = db_num_rows($result3); $trackback_count_display = $trackback_count > $nlimit ? ' ('. $trackback_count .')' : ''; $trackbacks = array(); while ($trackback = db_fetch_object($result3)) { $trackbacks[$trackback->trid] = check_plain($trackback->subject) .' - '. format_date($trackback->created, 'medium') .'
['. l(t('edit'), 'admin/trackback/edit/'. $trackback->trid) .']'; } if($trackbacks) $form['trackbacks'] = array( '#type' => 'checkboxes', '#title' => t('Trackback queue'), '#options' => $trackbacks, ); } if($comments || $nodes || $trackbacks) { // build an 'Update options' form $options = array(); $options['publish'] = t('publish'); $options['delete'] = t('delete'); $form['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'publish', '#prefix' => '
'); $form['submit'] = array('#type' => 'submit', '#value' => t('Go'), '#suffix' => '
'); return drupal_get_form('adminblock_view', $form); } return null; } /** * Implementation of hook_block(). * * $nlimit sets the number of comments, nodes and trackbacks to display */ function adminblock_view_submit($form_id, $edit) { if ($edit['operation'] == 'publish') { if($edit['comments']) { $operations = comment_operations(); // extract the appropriate database query operation $query = $operations[$edit['operation']][1]; foreach ($edit['comments'] as $cid => $value) { if ($value) { // perform the update action, then refresh node statistics db_query($query, $cid); $comment = _comment_load($cid); _comment_update_node_statistics($comment->nid); // Allow modules to respond to the updating of a comment. comment_invoke_comment($comment, $edit['operation']); // Add an entry to the watchdog log. watchdog('content', t('Comment: updated %subject.', array('%subject' => theme('placeholder', $comment->subject))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid)); } } } if($edit['nodes']) { $operations = node_operations(); $operation = $operations['approve'][1]; foreach ($edit['nodes'] as $nid => $value) { if ($value) { db_query($operation, $nid); } } } if (module_exist('trackback') && $edit['trackbacks']) { foreach ($edit['trackbacks'] as $trid => $value) { if ($value) { spam_publish_trackback($trid); } } } cache_clear_all(); drupal_set_message(t('The update has been performed.')); } } function adminblock_multiple_delete_confirm() { $edit = $_POST['edit']; $counter = 0; if($edit['comments']) { $form['comments'] = array('#prefix' => '', '#tree' => TRUE); // array_filter() returns only elements with actual values foreach (array_filter($edit['comments']) as $cid => $value) { $comment = _comment_load($cid); if (is_object($comment) && is_numeric($comment->cid)) { $subject = db_result(db_query('SELECT subject FROM {comments} WHERE cid = %d', $cid)); $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '
  • ', '#suffix' => check_plain($subject) .'
  • '); $counter++; } } } if($edit['nodes']) { $form['nodes'] = array('#prefix' => '', '#tree' => TRUE); // array_filter returns only elements with true values foreach (array_filter($edit['nodes']) as $nid => $value) { $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid)); $form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#prefix' => '
  • ', '#suffix' => check_plain($title) ."
  • \n"); $counter++; } } // to-do: add trackback if (!$counter) { drupal_set_message(t('There do not appear to be any item to delete or your selected item was deleted by another administrator.')); } else { $form['operation'] = array('#type' => 'hidden', '#value' => 'delete'); return confirm_form('adminblock_multiple_delete_confirm', $form, '', '', t('This action cannot be undone.'), t('Delete all'), t('Cancel')); } } /** * Perform the actual deletion. */ function adminblock_multiple_delete_confirm_submit($form_id, $edit) { if ($edit['confirm']) { if($edit['comments']) { foreach ($edit['comments'] as $cid => $value) { $comment = _comment_load($cid); _comment_delete_thread($comment); _comment_update_node_statistics($comment->nid); } } if($edit['nodes']) { foreach ($edit['nodes'] as $nid => $value) { node_delete($nid); } } // to-do: add trackback cache_clear_all(); drupal_set_message(t('The comments have been deleted.')); } } ?>