--- comment.module 2004/03/18 01:59:33 1.17 +++ comment.module 2004/03/18 06:49:43 @@ -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 .= "
"; } @@ -725,15 +754,25 @@ $output .= $pager; } + if (comment_keep_expanded() && + $_SESSION['comment_expanded'] && + array_search($nid, $_SESSION['comment_expanded'])) { + $bottom_buttons .= form_submit(t("Collapse all")); + } + if (db_num_rows($result) && comment_user_can_moderate($node)) { - $output .= "