Skip to content

Instantly share code, notes, and snippets.

@psynaptic
Created July 26, 2012 14:19
Show Gist options
  • Select an option

  • Save psynaptic/3182303 to your computer and use it in GitHub Desktop.

Select an option

Save psynaptic/3182303 to your computer and use it in GitHub Desktop.
<?php
/**
* Menu callback; edit a comment from the administrative interface.
*/
function comment_admin_edit($cid) {
// Comment edits need to be saved.
if ($_POST['op'] == t('Submit')) {
$edit = $_POST['edit'];
comment_save($edit['cid'], $edit);
drupal_goto('admin/comment');
}
// If we're not saving our changes above, we're editing it.
$result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid);
$comment = db_fetch_object($result);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment = drupal_unpack($comment);
if ($comment) {
if (!$comment->uid) {
// If comment from non-registered user, allow admin to modify anonymous fields.
$form .= form_textfield(t('Name'), 'name', $comment->name ? $comment->name : variable_get('anonymous', 'Anonymous') , 20, 60);
$form .= form_textfield(t('E-mail'), 'mail', $comment->mail, 20, 64);
$form .= form_textfield(t('Homepage'), 'homepage', $comment->homepage, 20, 255);
}
else {
// Otherwise, just display the author's name.
$form .= form_item(t('Author'), format_name($comment));
}
$form .= form_textfield(t('Subject'), 'subject', $comment->subject, 70, 128);
$form .= form_textarea(t('Comment'), 'comment', $comment->comment, 70, 15, '');
$form .= filter_form('format', $comment->format);
$form .= form_radios(t('Status'), 'status', $comment->status, array(t('Published'), t('Not published')));
$form .= form_hidden('nid', $comment->nid);
$form .= form_hidden('cid', $comment->cid);
$form .= form_submit(t('Submit'));
print theme('page', form($form));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment