Commit 62e5c587 authored by Dries's avatar Dries

- Patch #38491 by Neil: refactor comment viewing controls to _execute model.

parent 9f8fcab8
...@@ -122,8 +122,6 @@ function comment_menu($may_cache) { ...@@ -122,8 +122,6 @@ function comment_menu($may_cache) {
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$access = user_access('post comments'); $access = user_access('post comments');
$items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
'callback' => 'comment_save_settings', 'access' => 1, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/edit', 'title' => t('edit comment'), $items[] = array('path' => 'comment/edit', 'title' => t('edit comment'),
'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK); 'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/delete', 'title' => t('delete comment'), $items[] = array('path' => 'comment/delete', 'title' => t('delete comment'),
...@@ -808,8 +806,7 @@ function comment_render($node, $cid = 0) { ...@@ -808,8 +806,7 @@ function comment_render($node, $cid = 0) {
} }
else { else {
// Multiple comment view // Multiple comment view
$query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = %d";
$query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name , c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = %d";
$query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread'; $query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread';
...@@ -903,7 +900,7 @@ function comment_render($node, $cid = 0) { ...@@ -903,7 +900,7 @@ function comment_render($node, $cid = 0) {
// Start a form, for use with comment control. // Start a form, for use with comment control.
$result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d", $nid, COMMENT_PUBLISHED); $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d", $nid, COMMENT_PUBLISHED);
if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
$output .= comment_controls($mode, $order, $comments_per_page, $nid, 'top'); $output .= comment_controls($mode, $order, $comments_per_page);
} }
while ($comment = db_fetch_object($result)) { while ($comment = db_fetch_object($result)) {
...@@ -930,7 +927,7 @@ function comment_render($node, $cid = 0) { ...@@ -930,7 +927,7 @@ function comment_render($node, $cid = 0) {
$output .= theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page)); $output .= theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page));
if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
$output .= comment_controls($mode, $order, $comments_per_page, $nid, 'bottom'); $output .= comment_controls($mode, $order, $comments_per_page);
} }
} }
...@@ -1026,27 +1023,6 @@ function comment_admin_overview($type = 'new') { ...@@ -1026,27 +1023,6 @@ function comment_admin_overview($type = 'new') {
*** misc functions: helpers, privates, history *** misc functions: helpers, privates, history
**/ **/
function comment_save_settings() {
global $user;
$edit = $_POST['edit'];
$mode = $edit['mode'];
$order = $edit['order'];
$comments_per_page = $edit['comments_per_page'];
if ($user->uid) {
$user = user_save($user, array('mode' => $mode, 'sort' => $order, 'comments_per_page' => $comments_per_page));
}
else {
$_SESSION['comment_mode'] = $mode;
$_SESSION['comment_sort'] = $order;
$_SESSION['comment_comments_per_page'] = $comments_per_page;
}
drupal_goto('node/'. $edit['nid'], NULL, 'comment');
}
function comment_num_all($nid) { function comment_num_all($nid) {
static $cache; static $cache;
...@@ -1312,35 +1288,60 @@ function theme_comment_view($comment, $links = array(), $visible = 1) { ...@@ -1312,35 +1288,60 @@ function theme_comment_view($comment, $links = array(), $visible = 1) {
return $output; return $output;
} }
function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50, $nid = 0, $top_or_bottom = '') { function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50) {
$form['mode'] = array('#type' => 'select',
$form['mode'] = array('#type' => 'select', '#default_value' => $mode, '#options' => _comment_get_modes(), '#weight' => 1); '#default_value' => $mode,
'#options' => _comment_get_modes(),
$form['order'] = array('#type' => 'select', '#default_value' => $order, '#options' => _comment_get_orders(), '#weight' => 2); '#weight' => 1,
);
$form['order'] = array(
'#type' => 'select',
'#default_value' => $order,
'#options' => _comment_get_orders(),
'#weight' => 2,
);
foreach (_comment_per_page() as $i) { foreach (_comment_per_page() as $i) {
$options[] = t('%a comments per page', array('%a' => $i)); $options[$i] = t('%a comments per page', array('%a' => $i));
} }
$form['comments_per_page'] = array('#type' => 'select', '#default_value' => $comments_per_page, '#options' => $options, '#weight' => 3); $form['comments_per_page'] = array('#type' => 'select',
'#default_value' => $comments_per_page,
$form['submit'] = array('#type' => 'submit', '#value' => t('Save settings'), '#weight' => 20); '#options' => $options,
'#weight' => 3,
$form['nid'] = array('#type' => 'hidden', '#value' => $nid); );
$form['#action'] = url('comment/reply'); $form['submit'] = array('#type' => 'submit',
'#value' => t('Save settings'),
'#weight' => 20,
);
return drupal_get_form('comment_controls'. $top_or_bottom, $form, 'comment_controls'); return drupal_get_form('comment_controls', $form);
} }
function theme_comment_controls($form) { function theme_comment_controls($form) {
$output .= '<div class="container-inline">'; $output .= '<div class="container-inline">';
$output .= form_render($form); $output .= form_render($form);
$output .= '</div>'; $output .= '</div>';
$output .= '<div class="description">' . t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') . '</div>'; $output .= '<div class="description">'. t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') .'</div>';
return theme('box', t('Comment viewing options'), $output); return theme('box', t('Comment viewing options'), $output);
} }
function comment_controls_execute($form_id, $form_values) {
global $user;
$mode = $form_values['mode'];
$order = $form_values['order'];
$comments_per_page = $form_values['comments_per_page'];
if ($user->uid) {
$user = user_save($user, array('mode' => $mode, 'sort' => $order, 'comments_per_page' => $comments_per_page));
}
else {
$_SESSION['comment_mode'] = $mode;
$_SESSION['comment_sort'] = $order;
$_SESSION['comment_comments_per_page'] = $comments_per_page;
}
}
function theme_comment($comment, $links = array()) { function theme_comment($comment, $links = array()) {
$output = '<div class="comment">'; $output = '<div class="comment">';
$output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n"; $output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
......
...@@ -122,8 +122,6 @@ function comment_menu($may_cache) { ...@@ -122,8 +122,6 @@ function comment_menu($may_cache) {
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$access = user_access('post comments'); $access = user_access('post comments');
$items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
'callback' => 'comment_save_settings', 'access' => 1, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/edit', 'title' => t('edit comment'), $items[] = array('path' => 'comment/edit', 'title' => t('edit comment'),
'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK); 'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/delete', 'title' => t('delete comment'), $items[] = array('path' => 'comment/delete', 'title' => t('delete comment'),
...@@ -808,8 +806,7 @@ function comment_render($node, $cid = 0) { ...@@ -808,8 +806,7 @@ function comment_render($node, $cid = 0) {
} }
else { else {
// Multiple comment view // Multiple comment view
$query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = %d";
$query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name , c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = %d";
$query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread'; $query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread';
...@@ -903,7 +900,7 @@ function comment_render($node, $cid = 0) { ...@@ -903,7 +900,7 @@ function comment_render($node, $cid = 0) {
// Start a form, for use with comment control. // Start a form, for use with comment control.
$result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d", $nid, COMMENT_PUBLISHED); $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d", $nid, COMMENT_PUBLISHED);
if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
$output .= comment_controls($mode, $order, $comments_per_page, $nid, 'top'); $output .= comment_controls($mode, $order, $comments_per_page);
} }
while ($comment = db_fetch_object($result)) { while ($comment = db_fetch_object($result)) {
...@@ -930,7 +927,7 @@ function comment_render($node, $cid = 0) { ...@@ -930,7 +927,7 @@ function comment_render($node, $cid = 0) {
$output .= theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page)); $output .= theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page));
if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
$output .= comment_controls($mode, $order, $comments_per_page, $nid, 'bottom'); $output .= comment_controls($mode, $order, $comments_per_page);
} }
} }
...@@ -1026,27 +1023,6 @@ function comment_admin_overview($type = 'new') { ...@@ -1026,27 +1023,6 @@ function comment_admin_overview($type = 'new') {
*** misc functions: helpers, privates, history *** misc functions: helpers, privates, history
**/ **/
function comment_save_settings() {
global $user;
$edit = $_POST['edit'];
$mode = $edit['mode'];
$order = $edit['order'];
$comments_per_page = $edit['comments_per_page'];
if ($user->uid) {
$user = user_save($user, array('mode' => $mode, 'sort' => $order, 'comments_per_page' => $comments_per_page));
}
else {
$_SESSION['comment_mode'] = $mode;
$_SESSION['comment_sort'] = $order;
$_SESSION['comment_comments_per_page'] = $comments_per_page;
}
drupal_goto('node/'. $edit['nid'], NULL, 'comment');
}
function comment_num_all($nid) { function comment_num_all($nid) {
static $cache; static $cache;
...@@ -1312,35 +1288,60 @@ function theme_comment_view($comment, $links = array(), $visible = 1) { ...@@ -1312,35 +1288,60 @@ function theme_comment_view($comment, $links = array(), $visible = 1) {
return $output; return $output;
} }
function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50, $nid = 0, $top_or_bottom = '') { function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50) {
$form['mode'] = array('#type' => 'select',
$form['mode'] = array('#type' => 'select', '#default_value' => $mode, '#options' => _comment_get_modes(), '#weight' => 1); '#default_value' => $mode,
'#options' => _comment_get_modes(),
$form['order'] = array('#type' => 'select', '#default_value' => $order, '#options' => _comment_get_orders(), '#weight' => 2); '#weight' => 1,
);
$form['order'] = array(
'#type' => 'select',
'#default_value' => $order,
'#options' => _comment_get_orders(),
'#weight' => 2,
);
foreach (_comment_per_page() as $i) { foreach (_comment_per_page() as $i) {
$options[] = t('%a comments per page', array('%a' => $i)); $options[$i] = t('%a comments per page', array('%a' => $i));
} }
$form['comments_per_page'] = array('#type' => 'select', '#default_value' => $comments_per_page, '#options' => $options, '#weight' => 3); $form['comments_per_page'] = array('#type' => 'select',
'#default_value' => $comments_per_page,
$form['submit'] = array('#type' => 'submit', '#value' => t('Save settings'), '#weight' => 20); '#options' => $options,
'#weight' => 3,
$form['nid'] = array('#type' => 'hidden', '#value' => $nid); );
$form['#action'] = url('comment/reply'); $form['submit'] = array('#type' => 'submit',
'#value' => t('Save settings'),
'#weight' => 20,
);
return drupal_get_form('comment_controls'. $top_or_bottom, $form, 'comment_controls'); return drupal_get_form('comment_controls', $form);
} }
function theme_comment_controls($form) { function theme_comment_controls($form) {
$output .= '<div class="container-inline">'; $output .= '<div class="container-inline">';
$output .= form_render($form); $output .= form_render($form);
$output .= '</div>'; $output .= '</div>';
$output .= '<div class="description">' . t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') . '</div>'; $output .= '<div class="description">'. t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') .'</div>';
return theme('box', t('Comment viewing options'), $output); return theme('box', t('Comment viewing options'), $output);
} }
function comment_controls_execute($form_id, $form_values) {
global $user;
$mode = $form_values['mode'];
$order = $form_values['order'];
$comments_per_page = $form_values['comments_per_page'];
if ($user->uid) {
$user = user_save($user, array('mode' => $mode, 'sort' => $order, 'comments_per_page' => $comments_per_page));
}
else {
$_SESSION['comment_mode'] = $mode;
$_SESSION['comment_sort'] = $order;
$_SESSION['comment_comments_per_page'] = $comments_per_page;
}
}
function theme_comment($comment, $links = array()) { function theme_comment($comment, $links = array()) {
$output = '<div class="comment">'; $output = '<div class="comment">';
$output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n"; $output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment