summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-11-22 15:48:46 +0000
committerDries Buytaert <dries@buytaert.net>2005-11-22 15:48:46 +0000
commit62e5c58777e700c0cdc71fcc8908b38b4a03c4c8 (patch)
tree7bb30a5158a065a9f47f0ad00ee52fef4195573b /modules
parent9f8fcab8dbc6d7e61cc96f897d00e17c9026d8d9 (diff)
downloadbrdo-62e5c58777e700c0cdc71fcc8908b38b4a03c4c8.tar.gz
brdo-62e5c58777e700c0cdc71fcc8908b38b4a03c4c8.tar.bz2
- Patch #38491 by Neil: refactor comment viewing controls to _execute model.
Diffstat (limited to 'modules')
-rw-r--r--modules/comment.module87
-rw-r--r--modules/comment/comment.module87
2 files changed, 88 insertions, 86 deletions
diff --git a/modules/comment.module b/modules/comment.module
index a16d31c1a..69727bd10 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -122,8 +122,6 @@ function comment_menu($may_cache) {
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$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'),
'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/delete', 'title' => t('delete comment'),
@@ -808,8 +806,7 @@ function comment_render($node, $cid = 0) {
}
else {
// 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';
@@ -903,7 +900,7 @@ function comment_render($node, $cid = 0) {
// 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);
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)) {
@@ -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));
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') {
*** 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) {
static $cache;
@@ -1312,35 +1288,60 @@ function theme_comment_view($comment, $links = array(), $visible = 1) {
return $output;
}
-function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50, $nid = 0, $top_or_bottom = '') {
-
- $form['mode'] = array('#type' => 'select', '#default_value' => $mode, '#options' => _comment_get_modes(), '#weight' => 1);
-
- $form['order'] = array('#type' => 'select', '#default_value' => $order, '#options' => _comment_get_orders(), '#weight' => 2);
-
+function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50) {
+ $form['mode'] = array('#type' => 'select',
+ '#default_value' => $mode,
+ '#options' => _comment_get_modes(),
+ '#weight' => 1,
+ );
+ $form['order'] = array(
+ '#type' => 'select',
+ '#default_value' => $order,
+ '#options' => _comment_get_orders(),
+ '#weight' => 2,
+ );
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['submit'] = array('#type' => 'submit', '#value' => t('Save settings'), '#weight' => 20);
-
- $form['nid'] = array('#type' => 'hidden', '#value' => $nid);
+ $form['comments_per_page'] = array('#type' => 'select',
+ '#default_value' => $comments_per_page,
+ '#options' => $options,
+ '#weight' => 3,
+ );
- $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) {
$output .= '<div class="container-inline">';
$output .= form_render($form);
$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);
}
+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()) {
$output = '<div class="comment">';
$output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index a16d31c1a..69727bd10 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -122,8 +122,6 @@ function comment_menu($may_cache) {
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$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'),
'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/delete', 'title' => t('delete comment'),
@@ -808,8 +806,7 @@ function comment_render($node, $cid = 0) {
}
else {
// 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';
@@ -903,7 +900,7 @@ function comment_render($node, $cid = 0) {
// 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);
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)) {
@@ -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));
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') {
*** 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) {
static $cache;
@@ -1312,35 +1288,60 @@ function theme_comment_view($comment, $links = array(), $visible = 1) {
return $output;
}
-function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50, $nid = 0, $top_or_bottom = '') {
-
- $form['mode'] = array('#type' => 'select', '#default_value' => $mode, '#options' => _comment_get_modes(), '#weight' => 1);
-
- $form['order'] = array('#type' => 'select', '#default_value' => $order, '#options' => _comment_get_orders(), '#weight' => 2);
-
+function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMMENT_ORDER_NEWEST_FIRST, $comments_per_page = 50) {
+ $form['mode'] = array('#type' => 'select',
+ '#default_value' => $mode,
+ '#options' => _comment_get_modes(),
+ '#weight' => 1,
+ );
+ $form['order'] = array(
+ '#type' => 'select',
+ '#default_value' => $order,
+ '#options' => _comment_get_orders(),
+ '#weight' => 2,
+ );
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['submit'] = array('#type' => 'submit', '#value' => t('Save settings'), '#weight' => 20);
-
- $form['nid'] = array('#type' => 'hidden', '#value' => $nid);
+ $form['comments_per_page'] = array('#type' => 'select',
+ '#default_value' => $comments_per_page,
+ '#options' => $options,
+ '#weight' => 3,
+ );
- $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) {
$output .= '<div class="container-inline">';
$output .= form_render($form);
$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);
}
+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()) {
$output = '<div class="comment">';
$output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";