--- comment.module 2004/03/18 01:59:33 1.17 +++ comment.module 2004/03/18 06:55:35 1.19 @@ -117,6 +117,7 @@ $group = form_radios(t("Default display mode"), "comment_default_mode", variable_get("comment_default_mode", 4), _comment_get_modes(), t("The default view for comments. Expanded views display the body of the comment. Threaded views keep replies together.")); $group .= form_radios(t("Default display order"), "comment_default_order", variable_get("comment_default_order", 1), _comment_get_orders(), t("The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference.")); $group .= form_select(t("Default comments per page"), "comment_default_per_page", variable_get("comment_default_per_page", "50"), _comment_per_page(), t("Default number of comments for each page: more comments are distributed in several pages.")); + $group .= form_checkbox(t("Default remember expanded"), "comment_default_keep_expanded", 1, variable_get("comment_default_keep_expanded", 1), t("Whether to remember by default which comments have been expanded.")); $group .= form_radios(t("Comment controls"), "comment_controls", variable_get("comment_controls", 0), array(t("Display above the comments"), t("Display below the comments"), t("Display above and below the comments"), t("Do not display")), t("Position of the comment controls box. The comment controls let the user change the default display mode and display order of comments.")); $output = form_group(t('Comment viewing options'), $group); @@ -476,8 +477,6 @@ } function comment_links($comment, $return = 1) { - global $user; - $links = array(); /* @@ -488,17 +487,28 @@ $links[] = l(t("parent"), comment_referer_load(), NULL, NULL, "comment-$comment->cid"); } + if (comment_keep_expanded()) { + $links[] = l(t("collapse comment"), "comment/collapse/$comment->cid"); + $terse = 1; + } + if (node_comment_mode($comment->nid) == 2) { if (user_access("administer comments") && user_access("access administration pages")) { - $links[] = l(t("delete comment"), "admin/comment/delete/$comment->cid"); - $links[] = l(t("edit comment"), "admin/comment/edit/$comment->cid"); - $links[] = l(t("reply to this comment"), "comment/reply/$comment->nid/$comment->cid", NULL, "bc=" . check_url(serialize(drupal_get_breadcrumb()))); + $links[] = l(comment_keep_expanded() ? t("delete") : t("delete comment"), + "admin/comment/delete/$comment->cid"); + $terse = 1; + $links[] = l(t("edit"), "admin/comment/edit/$comment->cid"); + $links[] = l(t("reply"), "comment/reply/$comment->nid/$comment->cid", NULL, "bc=" . check_url(serialize(drupal_get_breadcrumb()))); } else if (user_access("post comments")) { if (comment_access("edit", $comment)) { - $links[] = l(t("edit your comment"), "comment/edit/$comment->cid"); - } - $links[] = l(t("reply to this comment"), "comment/reply/$comment->nid/$comment->cid", NULL, "bc=" . check_url(serialize(drupal_get_breadcrumb()))); + $links[] = l($terse ? t('edit') : t("edit comment"), + "comment/edit/$comment->cid"); + $terse = 1; + } + $links[] = l($terse ? t('reply') : t("reply to this comment"), + "comment/reply/$comment->nid/$comment->cid", NULL, "bc=" . check_url(serialize(drupal_get_breadcrumb()))); + $terse = 1; } else { $links[] = theme("comment_post_forbidden"); @@ -519,6 +529,7 @@ $order = $_GET["order"]; $threshold = $_GET["threshold"]; $comments_per_page = $_GET["comments_per_page"]; + $keep_expanded = $_GET["keep_expanded"]; $comment_page = $_GET["comment_page"]; $output = ""; @@ -532,6 +543,13 @@ comment_referer_save(); /* + ** Clear record of expanded comments if we're not supposed to use it. + */ + if (! comment_keep_expanded()) { + unset($_SESSION["comment_expanded"]); + } + + /* ** Pre-process variables: */ @@ -557,10 +575,21 @@ $comments_per_page = $user->comments_per_page ? $user->comments_per_page : ($_SESSION["comment_comments_per_page"] ? $_SESSION["comment_comments_per_page"] : variable_get("comment_default_per_page", "50")); } - $output .= "\n"; + if (empty($keep_expanded)) { + $keep_expanded = isset($user->keep_expanded) ? $user->keep_expanded : ($_SESSION["comment_keep_expanded"] ? $_SESSION["comment_keep_expanded"] : variable_get("comment_keep_expanded", "1")); + } + $output .= "\n"; if ($cid) { + _comment_set_expanded($cid, $nid); + } + + // Don't use single-comment view. Use the full view with the one + // desired comment expanded (which it will be because of the call + // above). + + if (false) { /* ** Single comment view @@ -684,7 +713,7 @@ $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = '". check_query($nid) ."'"); if (db_num_rows($result) && (variable_get("comment_controls", 0) == 0 || variable_get("comment_controls", 0) == 2)) { $output .= "
\n"; - $output .= theme("comment_controls", $threshold, $mode, $order, $comments_per_page); + $output .= theme("comment_controls", $threshold, $mode, $order, $comments_per_page, $keep_expanded); $output .= form_hidden("nid", $nid); $output .= "
"; } @@ -725,15 +754,26 @@ $output .= $pager; } + if (comment_keep_expanded() && + $_SESSION['comment_expanded'] && + array_search($nid, $_SESSION['comment_expanded']) && + ($mode != 2) && ($mode != 4)) { + $bottom_buttons .= form_submit(t("Collapse all")); + } + if (db_num_rows($result) && comment_user_can_moderate($node)) { - $output .= "
". form_submit(t("Moderate comments")) ."

"; + $bottom_buttons .= form_submit(t("Moderate comments")); + } + + if ($bottom_buttons) { + $output .= "
". $bottom_buttons ."

"; } $output .= ""; if (db_num_rows($result) && (variable_get("comment_controls", 0) == 1 || variable_get("comment_controls", 0) == 2)) { $output .= "
\n"; - $output .= theme("comment_controls", $threshold, $mode, $order, $comments_per_page); + $output .= theme("comment_controls", $threshold, $mode, $order, $comments_per_page, $keep_expanded); $output .= form_hidden("nid", $nid); $output .= "
"; } @@ -852,9 +892,19 @@ } switch ($op) { + case "collapse": + $cid = arg(2); + _comment_clear_expanded($cid); + $nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid=%d', $cid)); + drupal_goto("node/view/$nid", NULL, "comment-$cid"); + break; case "edit": print theme("page", comment_edit(check_query(arg(2))), t("Edit comment"));; break; + case t('Collapse all'): + $_SESSION['comment_expanded'] = array(); + drupal_goto('node/view/' . $edit['nid']); + break; case t("Moderate comments"): case t("Moderate comment"): comment_moderate($edit); @@ -880,8 +930,9 @@ $order = $_POST["order"]; $threshold = $_POST["threshold"]; $comments_per_page = $_POST["comments_per_page"]; + $keep_expanded = $_POST["keep_expanded"]; - comment_save_settings(check_query($mode), check_query($order), check_query($threshold), check_query($comments_per_page)); + comment_save_settings(check_query($mode), check_query($order), check_query($threshold), check_query($comments_per_page), check_query($keep_expanded)); drupal_goto(comment_referer_load()); break; } @@ -1313,6 +1364,7 @@ $output .= theme("comment", $comment, $links); if ($mark_read) { comment_tag_new($comment->cid); + _comment_set_expanded($comment->cid, $comment->nid); } } else { @@ -1348,6 +1400,11 @@ return "\n"; } +function theme_comment_keep_expanded_form($keep_expanded) { + return ' ' . t('Remember expanded'); +} + function theme_comment_threshold($threshold) { $result = db_query("SELECT fid, filter FROM {moderation_filters} "); $options .= " "; @@ -1359,13 +1416,14 @@ } } -function theme_comment_controls($threshold = 1, $mode = 3, $order = 1, $comments_per_page = 50) { +function theme_comment_controls($threshold = 1, $mode = 3, $order = 1, $comments_per_page = 50, $keep_expanded = 1) { static $output; if (!$output) { $output .= theme("comment_mode_form", $mode); $output .= theme("comment_order_form", $order); $output .= theme("comment_per_page_form", $comments_per_page); + $output .= theme("comment_keep_expanded_form", $keep_expanded); $output .= theme("comment_threshold", $threshold); $output .= " ". form_submit(t("Save settings")); @@ -1441,14 +1499,14 @@ function theme_comment_flat_collapsed($comment, $threshold) { if (comment_visible($comment, $threshold)) { - return theme("comment_view", $comment, "", 0); + return theme("comment_view", $comment, "", _comment_is_expanded($comment->cid)); } return ""; } function theme_comment_flat_expanded($comment, $threshold, $check_new = 0) { $expand = comment_visible($comment, $threshold) && - ($check_new ? $comment->new : 1); + (($check_new ? $comment->new : 1) || _comment_is_expanded($comment->cid)); return theme("comment_view", $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), $expand); } @@ -1459,7 +1517,7 @@ function theme_comment_thread_min($comment, $threshold, $pid = 0) { if (comment_visible($comment, $threshold)) { $output = "
depth * 25) ."px;\">\n"; - $output .= theme("comment_view", $comment, "", 0); + $output .= theme("comment_view", $comment, "", _comment_is_expanded($comment->cid)); $output .= "
\n"; } return $output; @@ -1472,7 +1530,7 @@ } $expand = comment_visible($comment, $threshold) && - ($check_new ? $comment->new : 1); + (($check_new ? $comment->new : 1) || _comment_is_expanded($comment->cid)); $output .= theme("comment_view", $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), $expand); @@ -1555,17 +1613,18 @@ } } -function comment_save_settings($mode, $order, $threshold, $comments_per_page) { +function comment_save_settings($mode, $order, $threshold, $comments_per_page, $keep_expanded) { global $user; if ($user->uid) { - $user = user_save($user, array("mode" => $mode, "sort" => $order, "threshold" => $threshold, "comments_per_page" => $comments_per_page)); + $user = user_save($user, array("mode" => $mode, "sort" => $order, "threshold" => $threshold, "comments_per_page" => $comments_per_page, "keep_expanded" => $keep_expanded)); } else { $_SESSION["comment_mode"] = $mode; $_SESSION["comment_sort"] = $order; $_SESSION["comment_threshold"] = $threshold; $_SESSION["comment_comments_per_page"] = $comments_per_page; + $_SESSION["comment_keep_expanded"] = $keep_expanded; } } @@ -1808,4 +1867,23 @@ return drupal_map_assoc(array(10, 30, 50, 70, 90)); } +function comment_keep_expanded() { + global $user; + + return isset($user->keep_expanded) ? $user->keep_expanded : + variable_get("comment_keep_expanded", 1); +} + +function _comment_is_expanded($cid) { + return $_SESSION["comment_expanded"][$cid]; +} + +function _comment_set_expanded($cid, $nid) { + $_SESSION["comment_expanded"][$cid] = $nid; +} + +function _comment_clear_expanded($cid) { + unset($_SESSION["comment_expanded"][$cid]); +} + ?>