summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/comment
diff options
context:
space:
mode:
Diffstat (limited to 'kolab.org/www/drupal-7.26/modules/comment')
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment-node-form.js32
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment-rtl.css5
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment-wrapper.tpl.php52
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.admin.inc284
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.api.php145
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.css13
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.info16
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.install578
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.module2739
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.pages.inc123
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.test2225
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.tokens.inc243
-rw-r--r--kolab.org/www/drupal-7.26/modules/comment/comment.tpl.php92
13 files changed, 6547 insertions, 0 deletions
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment-node-form.js b/kolab.org/www/drupal-7.26/modules/comment/comment-node-form.js
new file mode 100644
index 0000000..76db240
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment-node-form.js
@@ -0,0 +1,32 @@
+
+(function ($) {
+
+Drupal.behaviors.commentFieldsetSummaries = {
+ attach: function (context) {
+ $('fieldset.comment-node-settings-form', context).drupalSetSummary(function (context) {
+ return Drupal.checkPlain($('.form-item-comment input:checked', context).next('label').text());
+ });
+
+ // Provide the summary for the node type form.
+ $('fieldset.comment-node-type-settings-form', context).drupalSetSummary(function(context) {
+ var vals = [];
+
+ // Default comment setting.
+ vals.push($(".form-item-comment select option:selected", context).text());
+
+ // Threading.
+ var threading = $(".form-item-comment-default-mode input:checked", context).next('label').text();
+ if (threading) {
+ vals.push(threading);
+ }
+
+ // Comments per page.
+ var number = $(".form-item-comment-default-per-page select option:selected", context).val();
+ vals.push(Drupal.t('@number comments per page', {'@number': number}));
+
+ return Drupal.checkPlain(vals.join(', '));
+ });
+ }
+};
+
+})(jQuery);
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment-rtl.css b/kolab.org/www/drupal-7.26/modules/comment/comment-rtl.css
new file mode 100644
index 0000000..39c3929
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment-rtl.css
@@ -0,0 +1,5 @@
+
+.indented {
+ margin-left: 0;
+ margin-right: 25px;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment-wrapper.tpl.php b/kolab.org/www/drupal-7.26/modules/comment/comment-wrapper.tpl.php
new file mode 100644
index 0000000..c691459
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment-wrapper.tpl.php
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * @file
+ * Default theme implementation to provide an HTML container for comments.
+ *
+ * Available variables:
+ * - $content: The array of content-related elements for the node. Use
+ * render($content) to print them all, or
+ * print a subset such as render($content['comment_form']).
+ * - $classes: String of classes that can be used to style contextually through
+ * CSS. It can be manipulated through the variable $classes_array from
+ * preprocess functions. The default value has the following:
+ * - comment-wrapper: The current template type, i.e., "theming hook".
+ * - $title_prefix (array): An array containing additional output populated by
+ * modules, intended to be displayed in front of the main title tag that
+ * appears in the template.
+ * - $title_suffix (array): An array containing additional output populated by
+ * modules, intended to be displayed after the main title tag that appears in
+ * the template.
+ *
+ * The following variables are provided for contextual information.
+ * - $node: Node object the comments are attached to.
+ * The constants below the variables show the possible values and should be
+ * used for comparison.
+ * - $display_mode
+ * - COMMENT_MODE_FLAT
+ * - COMMENT_MODE_THREADED
+ *
+ * Other variables:
+ * - $classes_array: Array of html class attribute values. It is flattened
+ * into a string within the variable $classes.
+ *
+ * @see template_preprocess_comment_wrapper()
+ *
+ * @ingroup themeable
+ */
+?>
+<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>>
+ <?php if ($content['comments'] && $node->type != 'forum'): ?>
+ <?php print render($title_prefix); ?>
+ <h2 class="title"><?php print t('Comments'); ?></h2>
+ <?php print render($title_suffix); ?>
+ <?php endif; ?>
+
+ <?php print render($content['comments']); ?>
+
+ <?php if ($content['comment_form']): ?>
+ <h2 class="title comment-form"><?php print t('Add new comment'); ?></h2>
+ <?php print render($content['comment_form']); ?>
+ <?php endif; ?>
+</div>
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.admin.inc b/kolab.org/www/drupal-7.26/modules/comment/comment.admin.inc
new file mode 100644
index 0000000..43b53e2
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.admin.inc
@@ -0,0 +1,284 @@
+<?php
+
+/**
+ * @file
+ * Admin page callbacks for the comment module.
+ */
+
+/**
+ * Menu callback; present an administrative comment listing.
+ */
+function comment_admin($type = 'new') {
+ $edit = $_POST;
+
+ if (isset($edit['operation']) && ($edit['operation'] == 'delete') && isset($edit['comments']) && $edit['comments']) {
+ return drupal_get_form('comment_multiple_delete_confirm');
+ }
+ else {
+ return drupal_get_form('comment_admin_overview', $type);
+ }
+}
+
+/**
+ * Form builder for the comment overview administration form.
+ *
+ * @param $arg
+ * Current path's fourth component: the type of overview form ('approval' or
+ * 'new').
+ *
+ * @ingroup forms
+ * @see comment_admin_overview_validate()
+ * @see comment_admin_overview_submit()
+ * @see theme_comment_admin_overview()
+ */
+function comment_admin_overview($form, &$form_state, $arg) {
+ // Build an 'Update options' form.
+ $form['options'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Update options'),
+ '#attributes' => array('class' => array('container-inline')),
+ );
+
+ if ($arg == 'approval') {
+ $options['publish'] = t('Publish the selected comments');
+ }
+ else {
+ $options['unpublish'] = t('Unpublish the selected comments');
+ }
+ $options['delete'] = t('Delete the selected comments');
+
+ $form['options']['operation'] = array(
+ '#type' => 'select',
+ '#title' => t('Operation'),
+ '#title_display' => 'invisible',
+ '#options' => $options,
+ '#default_value' => 'publish',
+ );
+ $form['options']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Update'),
+ );
+
+ // Load the comments that need to be displayed.
+ $status = ($arg == 'approval') ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED;
+ $header = array(
+ 'subject' => array('data' => t('Subject'), 'field' => 'subject'),
+ 'author' => array('data' => t('Author'), 'field' => 'name'),
+ 'posted_in' => array('data' => t('Posted in'), 'field' => 'node_title'),
+ 'changed' => array('data' => t('Updated'), 'field' => 'c.changed', 'sort' => 'desc'),
+ 'operations' => array('data' => t('Operations')),
+ );
+
+ $query = db_select('comment', 'c')->extend('PagerDefault')->extend('TableSort');
+ $query->join('node', 'n', 'n.nid = c.nid');
+ $query->addField('n', 'title', 'node_title');
+ $query->addTag('node_access');
+ $result = $query
+ ->fields('c', array('cid', 'subject', 'name', 'changed'))
+ ->condition('c.status', $status)
+ ->limit(50)
+ ->orderByHeader($header)
+ ->execute();
+
+ $cids = array();
+
+ // We collect a sorted list of node_titles during the query to attach to the
+ // comments later.
+ foreach ($result as $row) {
+ $cids[] = $row->cid;
+ $node_titles[] = $row->node_title;
+ }
+ $comments = comment_load_multiple($cids);
+
+ // Build a table listing the appropriate comments.
+ $options = array();
+ $destination = drupal_get_destination();
+
+ foreach ($comments as $comment) {
+ // Remove the first node title from the node_titles array and attach to
+ // the comment.
+ $comment->node_title = array_shift($node_titles);
+ $comment_body = field_get_items('comment', $comment, 'comment_body');
+ $options[$comment->cid] = array(
+ 'subject' => array(
+ 'data' => array(
+ '#type' => 'link',
+ '#title' => $comment->subject,
+ '#href' => 'comment/' . $comment->cid,
+ '#options' => array('attributes' => array('title' => truncate_utf8($comment_body[0]['value'], 128)), 'fragment' => 'comment-' . $comment->cid),
+ ),
+ ),
+ 'author' => theme('username', array('account' => $comment)),
+ 'posted_in' => array(
+ 'data' => array(
+ '#type' => 'link',
+ '#title' => $comment->node_title,
+ '#href' => 'node/' . $comment->nid,
+ ),
+ ),
+ 'changed' => format_date($comment->changed, 'short'),
+ 'operations' => array(
+ 'data' => array(
+ '#type' => 'link',
+ '#title' => t('edit'),
+ '#href' => 'comment/' . $comment->cid . '/edit',
+ '#options' => array('query' => $destination),
+ ),
+ ),
+ );
+ }
+
+ $form['comments'] = array(
+ '#type' => 'tableselect',
+ '#header' => $header,
+ '#options' => $options,
+ '#empty' => t('No comments available.'),
+ );
+
+ $form['pager'] = array('#theme' => 'pager');
+
+ return $form;
+}
+
+/**
+ * Validate comment_admin_overview form submissions.
+ */
+function comment_admin_overview_validate($form, &$form_state) {
+ $form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0));
+ // We can't execute any 'Update options' if no comments were selected.
+ if (count($form_state['values']['comments']) == 0) {
+ form_set_error('', t('Select one or more comments to perform the update on.'));
+ }
+}
+
+/**
+ * Process comment_admin_overview form submissions.
+ *
+ * Execute the chosen 'Update option' on the selected comments, such as
+ * publishing, unpublishing or deleting.
+ */
+function comment_admin_overview_submit($form, &$form_state) {
+ $operation = $form_state['values']['operation'];
+ $cids = $form_state['values']['comments'];
+
+ if ($operation == 'delete') {
+ comment_delete_multiple($cids);
+ }
+ else {
+ foreach ($cids as $cid => $value) {
+ $comment = comment_load($value);
+
+ if ($operation == 'unpublish') {
+ $comment->status = COMMENT_NOT_PUBLISHED;
+ }
+ elseif ($operation == 'publish') {
+ $comment->status = COMMENT_PUBLISHED;
+ }
+ comment_save($comment);
+ }
+ }
+ drupal_set_message(t('The update has been performed.'));
+ $form_state['redirect'] = 'admin/content/comment';
+ cache_clear_all();
+}
+
+/**
+ * List the selected comments and verify that the admin wants to delete them.
+ *
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @return
+ * TRUE if the comments should be deleted, FALSE otherwise.
+ * @ingroup forms
+ * @see comment_multiple_delete_confirm_submit()
+ */
+function comment_multiple_delete_confirm($form, &$form_state) {
+ $edit = $form_state['input'];
+
+ $form['comments'] = array(
+ '#prefix' => '<ul>',
+ '#suffix' => '</ul>',
+ '#tree' => TRUE,
+ );
+ // array_filter() returns only elements with actual values.
+ $comment_counter = 0;
+ foreach (array_filter($edit['comments']) as $cid => $value) {
+ $comment = comment_load($cid);
+ if (is_object($comment) && is_numeric($comment->cid)) {
+ $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
+ $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '<li>', '#suffix' => check_plain($subject) . '</li>');
+ $comment_counter++;
+ }
+ }
+ $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
+
+ if (!$comment_counter) {
+ drupal_set_message(t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.'));
+ drupal_goto('admin/content/comment');
+ }
+ else {
+ return confirm_form($form,
+ t('Are you sure you want to delete these comments and all their children?'),
+ 'admin/content/comment', t('This action cannot be undone.'),
+ t('Delete comments'), t('Cancel'));
+ }
+}
+
+/**
+ * Process comment_multiple_delete_confirm form submissions.
+ */
+function comment_multiple_delete_confirm_submit($form, &$form_state) {
+ if ($form_state['values']['confirm']) {
+ comment_delete_multiple(array_keys($form_state['values']['comments']));
+ cache_clear_all();
+ $count = count($form_state['values']['comments']);
+ watchdog('content', 'Deleted @count comments.', array('@count' => $count));
+ drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
+ }
+ $form_state['redirect'] = 'admin/content/comment';
+}
+
+/**
+ * Page callback for comment deletions.
+ */
+function comment_confirm_delete_page($cid) {
+ if ($comment = comment_load($cid)) {
+ return drupal_get_form('comment_confirm_delete', $comment);
+ }
+ return MENU_NOT_FOUND;
+}
+
+/**
+ * Form builder; Builds the confirmation form for deleting a single comment.
+ *
+ * @ingroup forms
+ * @see comment_confirm_delete_submit()
+ */
+function comment_confirm_delete($form, &$form_state, $comment) {
+ $form['#comment'] = $comment;
+ // Always provide entity id in the same form key as in the entity edit form.
+ $form['cid'] = array('#type' => 'value', '#value' => $comment->cid);
+ return confirm_form(
+ $form,
+ t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)),
+ 'node/' . $comment->nid,
+ t('Any replies to this comment will be lost. This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel'),
+ 'comment_confirm_delete');
+}
+
+/**
+ * Process comment_confirm_delete form submissions.
+ */
+function comment_confirm_delete_submit($form, &$form_state) {
+ $comment = $form['#comment'];
+ // Delete the comment and its replies.
+ comment_delete($comment->cid);
+ drupal_set_message(t('The comment and all its replies have been deleted.'));
+ watchdog('content', 'Deleted comment @cid and its replies.', array('@cid' => $comment->cid));
+ // Clear the cache so an anonymous user sees that his comment was deleted.
+ cache_clear_all();
+
+ $form_state['redirect'] = "node/$comment->nid";
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.api.php b/kolab.org/www/drupal-7.26/modules/comment/comment.api.php
new file mode 100644
index 0000000..0591265
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.api.php
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * @file
+ * Hooks provided by the Comment module.
+ */
+
+/**
+ * @addtogroup hooks
+ * @{
+ */
+
+/**
+ * The comment passed validation and is about to be saved.
+ *
+ * Modules may make changes to the comment before it is saved to the database.
+ *
+ * @param $comment
+ * The comment object.
+ */
+function hook_comment_presave($comment) {
+ // Remove leading & trailing spaces from the comment subject.
+ $comment->subject = trim($comment->subject);
+}
+
+/**
+ * The comment is being inserted.
+ *
+ * @param $comment
+ * The comment object.
+ */
+function hook_comment_insert($comment) {
+ // Reindex the node when comments are added.
+ search_touch_node($comment->nid);
+}
+
+/**
+ * The comment is being updated.
+ *
+ * @param $comment
+ * The comment object.
+ */
+function hook_comment_update($comment) {
+ // Reindex the node when comments are updated.
+ search_touch_node($comment->nid);
+}
+
+/**
+ * Comments are being loaded from the database.
+ *
+ * @param $comments
+ * An array of comment objects indexed by cid.
+ */
+function hook_comment_load($comments) {
+ $result = db_query('SELECT cid, foo FROM {mytable} WHERE cid IN (:cids)', array(':cids' => array_keys($comments)));
+ foreach ($result as $record) {
+ $comments[$record->cid]->foo = $record->foo;
+ }
+}
+
+/**
+ * The comment is being viewed. This hook can be used to add additional data to the comment before theming.
+ *
+ * @param $comment
+ * Passes in the comment the action is being performed on.
+ * @param $view_mode
+ * View mode, e.g. 'full', 'teaser'...
+ * @param $langcode
+ * The language code used for rendering.
+ *
+ * @see hook_entity_view()
+ */
+function hook_comment_view($comment, $view_mode, $langcode) {
+ // how old is the comment
+ $comment->time_ago = time() - $comment->changed;
+}
+
+/**
+ * The comment was built; the module may modify the structured content.
+ *
+ * This hook is called after the content has been assembled in a structured array
+ * and may be used for doing processing which requires that the complete comment
+ * content structure has been built.
+ *
+ * If the module wishes to act on the rendered HTML of the comment rather than the
+ * structured content array, it may use this hook to add a #post_render callback.
+ * Alternatively, it could also implement hook_preprocess_comment(). See
+ * drupal_render() and theme() documentation respectively for details.
+ *
+ * @param $build
+ * A renderable array representing the comment.
+ *
+ * @see comment_view()
+ * @see hook_entity_view_alter()
+ */
+function hook_comment_view_alter(&$build) {
+ // Check for the existence of a field added by another module.
+ if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
+ // Change its weight.
+ $build['an_additional_field']['#weight'] = -10;
+ }
+
+ // Add a #post_render callback to act on the rendered HTML of the comment.
+ $build['#post_render'][] = 'my_module_comment_post_render';
+}
+
+/**
+ * The comment is being published by the moderator.
+ *
+ * @param $comment
+ * Passes in the comment the action is being performed on.
+ * @return
+ * Nothing.
+ */
+function hook_comment_publish($comment) {
+ drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->subject)));
+}
+
+/**
+ * The comment is being unpublished by the moderator.
+ *
+ * @param $comment
+ * Passes in the comment the action is being performed on.
+ * @return
+ * Nothing.
+ */
+function hook_comment_unpublish($comment) {
+ drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject)));
+}
+
+/**
+ * The comment is being deleted by the moderator.
+ *
+ * @param $comment
+ * Passes in the comment the action is being performed on.
+ * @return
+ * Nothing.
+ */
+function hook_comment_delete($comment) {
+ drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject)));
+}
+
+/**
+ * @} End of "addtogroup hooks".
+ */
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.css b/kolab.org/www/drupal-7.26/modules/comment/comment.css
new file mode 100644
index 0000000..a55f527
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.css
@@ -0,0 +1,13 @@
+
+#comments {
+ margin-top: 15px;
+}
+.indented {
+ margin-left: 25px; /* LTR */
+}
+.comment-unpublished {
+ background-color: #fff4f4;
+}
+.comment-preview {
+ background-color: #ffffea;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.info b/kolab.org/www/drupal-7.26/modules/comment/comment.info
new file mode 100644
index 0000000..ed7fdc7
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.info
@@ -0,0 +1,16 @@
+name = Comment
+description = Allows users to comment on and discuss published content.
+package = Core
+version = VERSION
+core = 7.x
+dependencies[] = text
+files[] = comment.module
+files[] = comment.test
+configure = admin/content/comment
+stylesheets[all][] = comment.css
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.install b/kolab.org/www/drupal-7.26/modules/comment/comment.install
new file mode 100644
index 0000000..e4da58f
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.install
@@ -0,0 +1,578 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the comment module.
+ */
+
+/**
+ * Implements hook_uninstall().
+ */
+function comment_uninstall() {
+ // Delete comment_body field.
+ field_delete_field('comment_body');
+
+ // Remove variables.
+ variable_del('comment_block_count');
+ $node_types = array_keys(node_type_get_types());
+ foreach ($node_types as $node_type) {
+ field_attach_delete_bundle('comment', 'comment_node_' . $node_type);
+ variable_del('comment_' . $node_type);
+ variable_del('comment_anonymous_' . $node_type);
+ variable_del('comment_controls_' . $node_type);
+ variable_del('comment_default_mode_' . $node_type);
+ variable_del('comment_default_order_' . $node_type);
+ variable_del('comment_default_per_page_' . $node_type);
+ variable_del('comment_form_location_' . $node_type);
+ variable_del('comment_preview_' . $node_type);
+ variable_del('comment_subject_field_' . $node_type);
+ }
+}
+
+/**
+ * Implements hook_enable().
+ */
+function comment_enable() {
+ // Insert records into the node_comment_statistics for nodes that are missing.
+ $query = db_select('node', 'n');
+ $query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid');
+ $query->addField('n', 'created', 'last_comment_timestamp');
+ $query->addField('n', 'uid', 'last_comment_uid');
+ $query->addField('n', 'nid');
+ $query->addExpression('0', 'comment_count');
+ $query->addExpression('NULL', 'last_comment_name');
+ $query->isNull('ncs.comment_count');
+
+ db_insert('node_comment_statistics')
+ ->from($query)
+ ->execute();
+}
+
+/**
+ * Implements hook_modules_enabled().
+ *
+ * Creates comment body fields for node types existing before the comment module
+ * is enabled. We use hook_modules_enabled() rather than hook_enable() so we can
+ * react to node types of existing modules, and those of modules being enabled
+ * both before and after comment module in the loop of module_enable().
+ *
+ * There is a separate comment bundle for each node type to allow for
+ * per-node-type customization of comment fields. Each one of these bundles
+ * needs a comment body field instance. A comment bundle is needed even for
+ * node types whose comments are disabled by default, because individual nodes
+ * may override that default.
+ *
+ * @see comment_node_type_insert()
+ */
+function comment_modules_enabled($modules) {
+ // Only react if comment module is one of the modules being enabled.
+ // hook_node_type_insert() is used to create body fields while the comment
+ // module is enabled.
+ if (in_array('comment', $modules)) {
+ // Ensure that the list of node types reflects newly enabled modules.
+ node_types_rebuild();
+
+ // Create comment body fields for each node type, if needed.
+ foreach (node_type_get_types() as $type => $info) {
+ _comment_body_field_create($info);
+ }
+ }
+}
+
+/**
+ * Implements hook_update_dependencies().
+ */
+function comment_update_dependencies() {
+ // comment_update_7005() creates the comment body field and therefore must
+ // run after all Field modules have been enabled, which happens in
+ // system_update_7027().
+ $dependencies['comment'][7005] = array(
+ 'system' => 7027,
+ );
+
+ // comment_update_7006() needs to query the {filter_format} table to get a
+ // list of existing text formats, so it must run after filter_update_7000(),
+ // which creates that table.
+ $dependencies['comment'][7006] = array(
+ 'filter' => 7000,
+ );
+
+ return $dependencies;
+}
+
+/**
+ * @addtogroup updates-6.x-to-7.x
+ * @{
+ */
+
+/**
+ * Rename comment display setting variables.
+ */
+function comment_update_7000() {
+ $types = _update_7000_node_get_types();
+ foreach ($types as $type => $type_object) {
+ variable_del('comment_default_order' . $type);
+
+ // Drupal 6 had four display modes:
+ // - COMMENT_MODE_FLAT_COLLAPSED = 1
+ // - COMMENT_MODE_FLAT_EXPANDED = 2
+ // - COMMENT_MODE_THREADED_COLLAPSED = 3
+ // - COMMENT_MODE_THREADED_EXPANDED = 4
+ //
+ // Drupal 7 doesn't support collapsed/expanded modes anymore, so we
+ // migrate all the flat modes to COMMENT_MODE_FLAT (0) and all the threaded
+ // modes to COMMENT_MODE_THREADED (1).
+ $setting = variable_get('comment_default_mode_' . $type, 4);
+ if ($setting == 3 || $setting == 4) {
+ variable_set('comment_default_mode_' . $type, 1);
+ }
+ else {
+ variable_set('comment_default_mode_' . $type, 0);
+ }
+
+ // There were only two comment modes in the past:
+ // - 1 was 'required' previously, convert into DRUPAL_REQUIRED (2).
+ // - 0 was 'optional' previously, convert into DRUPAL_OPTIONAL (1).
+ $preview = variable_get('comment_preview_' . $type, 1) ? 2 : 1;
+ variable_set('comment_preview_' . $type, $preview);
+ }
+}
+
+/**
+ * Change comment status from published being 0 to being 1
+ */
+function comment_update_7001() {
+ // Choose a temporary status value different from the existing status values.
+ $tmp_status = db_query('SELECT MAX(status) FROM {comments}')->fetchField() + 1;
+
+ $changes = array(
+ 0 => $tmp_status,
+ 1 => 0,
+ $tmp_status => 1,
+ );
+
+ foreach ($changes as $old => $new) {
+ db_update('comments')
+ ->fields(array('status' => $new))
+ ->condition('status', $old)
+ ->execute();
+ }
+}
+
+/**
+ * Rename {comments} table to {comment} and upgrade it.
+ */
+function comment_update_7002() {
+ db_rename_table('comments', 'comment');
+
+ // Add user-related indexes. These may already exist from Drupal 6.
+ if (!db_index_exists('comment', 'comment_uid')) {
+ db_add_index('comment', 'comment_uid', array('uid'));
+ db_add_index('node_comment_statistics', 'last_comment_uid', array('last_comment_uid'));
+ }
+
+ // Create a language column.
+ db_add_field('comment', 'language', array(
+ 'type' => 'varchar',
+ 'length' => 12,
+ 'not null' => TRUE,
+ 'default' => '',
+ ));
+ db_add_index('comment', 'comment_nid_language', array('nid', 'language'));
+}
+
+/**
+ * Split {comment}.timestamp into 'created' and 'changed', improve indexing on {comment}.
+ */
+function comment_update_7003() {
+ // Drop the old indexes.
+ db_drop_index('comment', 'status');
+ db_drop_index('comment', 'pid');
+
+ // Create a created column.
+ db_add_field('comment', 'created', array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ ));
+
+ // Rename the timestamp column to changed.
+ db_change_field('comment', 'timestamp', 'changed', array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ ));
+
+ // Migrate the data.
+ // @todo db_update() should support this.
+ db_query('UPDATE {comment} SET created = changed');
+
+ // Recreate the indexes.
+ // The 'comment_num_new' index is optimized for comment_num_new()
+ // and comment_new_page_count().
+ db_add_index('comment', 'comment_num_new', array('nid', 'status', 'created', 'cid', 'thread'));
+ db_add_index('comment', 'comment_pid_status', array('pid', 'status'));
+}
+
+/**
+ * Upgrade the {node_comment_statistics} table.
+ */
+function comment_update_7004() {
+ db_add_field('node_comment_statistics', 'cid', array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {comment}.cid of the last comment.',
+ ));
+ db_add_index('node_comment_statistics', 'cid', array('cid'));
+
+ // The comment_count index may have been added in Drupal 6.
+ if (!db_index_exists('node_comment_statistics', 'comment_count')) {
+ // Add an index on the comment_count.
+ db_add_index('node_comment_statistics', 'comment_count', array('comment_count'));
+ }
+}
+
+/**
+ * Create the comment_body field.
+ */
+function comment_update_7005() {
+ // Create comment body field.
+ $field = array(
+ 'field_name' => 'comment_body',
+ 'type' => 'text_long',
+ 'module' => 'text',
+ 'entity_types' => array(
+ 'comment',
+ ),
+ 'settings' => array(),
+ 'cardinality' => 1,
+ );
+ _update_7000_field_create_field($field);
+
+ // Add the field to comments for all existing bundles.
+ $generic_instance = array(
+ 'entity_type' => 'comment',
+ 'label' => t('Comment'),
+ 'settings' => array(
+ 'text_processing' => 1,
+ ),
+ 'required' => TRUE,
+ 'display' => array(
+ 'default' => array(
+ 'label' => 'hidden',
+ 'type' => 'text_default',
+ 'weight' => 0,
+ 'settings' => array(),
+ 'module' => 'text',
+ ),
+ ),
+ 'widget' => array(
+ 'type' => 'text_textarea',
+ 'settings' => array(
+ 'rows' => 5,
+ ),
+ 'weight' => 0,
+ 'module' => 'text',
+ ),
+ 'description' => '',
+ );
+
+ $types = _update_7000_node_get_types();
+ foreach ($types as $type => $type_object) {
+ $instance = $generic_instance;
+ $instance['bundle'] = 'comment_node_' . $type;
+ _update_7000_field_create_instance($field, $instance);
+ }
+}
+
+/**
+ * Migrate data from the comment field to field storage.
+ */
+function comment_update_7006(&$sandbox) {
+ // This is a multipass update. First set up some comment variables.
+ if (empty($sandbox['total'])) {
+ $comments = (bool) db_query_range('SELECT 1 FROM {comment}', 0, 1)->fetchField();
+ $sandbox['types'] = array();
+ if ($comments) {
+ $sandbox['types'] = array_keys(_update_7000_node_get_types());
+ }
+ $sandbox['total'] = count($sandbox['types']);
+ }
+
+ if (!empty($sandbox['types'])) {
+ $type = array_shift($sandbox['types']);
+
+ $query = db_select('comment', 'c');
+ $query->innerJoin('node', 'n', 'c.nid = n.nid AND n.type = :type', array(':type' => $type));
+ $query->addField('c', 'cid', 'entity_id');
+ $query->addExpression("'comment_node_$type'", 'bundle');
+ $query->addExpression("'comment'", 'entity_type');
+ $query->addExpression('0', 'deleted');
+ $query->addExpression("'" . LANGUAGE_NONE . "'", 'language');
+ $query->addExpression('0', 'delta');
+ $query->addField('c', 'comment', 'comment_body_value');
+ $query->addField('c', 'format', 'comment_body_format');
+
+ db_insert('field_data_comment_body')
+ ->from($query)
+ ->execute();
+
+ $sandbox['#finished'] = 1 - count($sandbox['types']) / $sandbox['total'];
+ }
+
+ // On the last pass of the update, $sandbox['types'] will be empty.
+ if (empty($sandbox['types'])) {
+ // Update the comment body text formats. For an explanation of these
+ // updates, see the code comments in user_update_7010().
+ db_update('field_data_comment_body')
+ ->fields(array('comment_body_format' => NULL))
+ ->condition('comment_body_value', '')
+ ->condition('comment_body_format', 0)
+ ->execute();
+ $existing_formats = db_query("SELECT format FROM {filter_format}")->fetchCol();
+ $default_format = variable_get('filter_default_format', 1);
+ db_update('field_data_comment_body')
+ ->fields(array('comment_body_format' => $default_format))
+ ->isNotNull('comment_body_format')
+ ->condition('comment_body_format', $existing_formats, 'NOT IN')
+ ->execute();
+
+ // Finally, remove the old comment data.
+ db_drop_field('comment', 'comment');
+ db_drop_field('comment', 'format');
+ }
+}
+
+/**
+ * @} End of "addtogroup updates-6.x-to-7.x".
+ */
+
+/**
+ * @addtogroup updates-7.x-extra
+ * @{
+ */
+
+/**
+ * Add an index to the created column.
+ */
+function comment_update_7007() {
+ db_add_index('comment', 'comment_created', array('created'));
+}
+
+/**
+ * Update database to match Drupal 7 schema.
+ */
+function comment_update_7008() {
+ // Update default status to 1.
+ db_change_field('comment', 'status', 'status', array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 1,
+ 'size' => 'tiny',
+ ));
+
+ // Realign indexes.
+ db_drop_index('comment', 'comment_status_pid');
+ db_add_index('comment', 'comment_status_pid', array('pid', 'status'));
+ db_drop_index('comment', 'comment_pid_status');
+ db_drop_index('comment', 'nid');
+}
+
+/**
+ * Change the last_comment_timestamp column description.
+ */
+function comment_update_7009() {
+ db_change_field('node_comment_statistics', 'last_comment_timestamp', 'last_comment_timestamp', array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.',
+ ));
+}
+
+/**
+ * @} End of "addtogroup updates-7.x-extra".
+ */
+
+/**
+ * Implements hook_schema().
+ */
+function comment_schema() {
+ $schema['comment'] = array(
+ 'description' => 'Stores comments and associated data.',
+ 'fields' => array(
+ 'cid' => array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'Primary Key: Unique comment ID.',
+ ),
+ 'pid' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {comment}.cid to which this comment is a reply. If set to 0, this comment is not a reply to an existing comment.',
+ ),
+ 'nid' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {node}.nid to which this comment is a reply.',
+ ),
+ 'uid' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
+ ),
+ 'subject' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'The comment title.',
+ ),
+ 'hostname' => array(
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => "The author's host name.",
+ ),
+ 'created' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The time that the comment was created, as a Unix timestamp.',
+ ),
+ 'changed' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The time that the comment was last edited, as a Unix timestamp.',
+ ),
+ 'status' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 1,
+ 'size' => 'tiny',
+ 'description' => 'The published status of a comment. (0 = Not Published, 1 = Published)',
+ ),
+ 'thread' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'description' => "The vancode representation of the comment's place in a thread.",
+ ),
+ 'name' => array(
+ 'type' => 'varchar',
+ 'length' => 60,
+ 'not null' => FALSE,
+ 'description' => "The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form.",
+ ),
+ 'mail' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => FALSE,
+ 'description' => "The comment author's e-mail address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
+ ),
+ 'homepage' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => FALSE,
+ 'description' => "The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
+ ),
+ 'language' => array(
+ 'description' => 'The {languages}.language of this comment.',
+ 'type' => 'varchar',
+ 'length' => 12,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ ),
+ 'indexes' => array(
+ 'comment_status_pid' => array('pid', 'status'),
+ 'comment_num_new' => array('nid', 'status', 'created', 'cid', 'thread'),
+ 'comment_uid' => array('uid'),
+ 'comment_nid_language' => array('nid', 'language'),
+ 'comment_created' => array('created'),
+ ),
+ 'primary key' => array('cid'),
+ 'foreign keys' => array(
+ 'comment_node' => array(
+ 'table' => 'node',
+ 'columns' => array('nid' => 'nid'),
+ ),
+ 'comment_author' => array(
+ 'table' => 'users',
+ 'columns' => array('uid' => 'uid'),
+ ),
+ ),
+ );
+
+ $schema['node_comment_statistics'] = array(
+ 'description' => 'Maintains statistics of node and comments posts to show "new" and "updated" flags.',
+ 'fields' => array(
+ 'nid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {node}.nid for which the statistics are compiled.',
+ ),
+ 'cid' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {comment}.cid of the last comment.',
+ ),
+ 'last_comment_timestamp' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.',
+ ),
+ 'last_comment_name' => array(
+ 'type' => 'varchar',
+ 'length' => 60,
+ 'not null' => FALSE,
+ 'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.',
+ ),
+ 'last_comment_uid' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
+ ),
+ 'comment_count' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The total number of comments on this node.',
+ ),
+ ),
+ 'primary key' => array('nid'),
+ 'indexes' => array(
+ 'node_comment_timestamp' => array('last_comment_timestamp'),
+ 'comment_count' => array('comment_count'),
+ 'last_comment_uid' => array('last_comment_uid'),
+ ),
+ 'foreign keys' => array(
+ 'statistics_node' => array(
+ 'table' => 'node',
+ 'columns' => array('nid' => 'nid'),
+ ),
+ 'last_comment_author' => array(
+ 'table' => 'users',
+ 'columns' => array(
+ 'last_comment_uid' => 'uid',
+ ),
+ ),
+ ),
+ );
+
+ return $schema;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.module b/kolab.org/www/drupal-7.26/modules/comment/comment.module
new file mode 100644
index 0000000..6f6c04b
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.module
@@ -0,0 +1,2739 @@
+<?php
+
+/**
+ * @file
+ * Enables users to comment on published content.
+ *
+ * When enabled, the Drupal comment module creates a discussion
+ * board for each Drupal node. Users can post comments to discuss
+ * a forum topic, weblog post, story, collaborative book page, etc.
+ */
+
+/**
+ * Comment is awaiting approval.
+ */
+define('COMMENT_NOT_PUBLISHED', 0);
+
+/**
+ * Comment is published.
+ */
+define('COMMENT_PUBLISHED', 1);
+
+/**
+ * Comments are displayed in a flat list - expanded.
+ */
+define('COMMENT_MODE_FLAT', 0);
+
+/**
+ * Comments are displayed as a threaded list - expanded.
+ */
+define('COMMENT_MODE_THREADED', 1);
+
+/**
+ * Anonymous posters cannot enter their contact information.
+ */
+define('COMMENT_ANONYMOUS_MAYNOT_CONTACT', 0);
+
+/**
+ * Anonymous posters may leave their contact information.
+ */
+define('COMMENT_ANONYMOUS_MAY_CONTACT', 1);
+
+/**
+ * Anonymous posters are required to leave their contact information.
+ */
+define('COMMENT_ANONYMOUS_MUST_CONTACT', 2);
+
+/**
+ * Comment form should be displayed on a separate page.
+ */
+define('COMMENT_FORM_SEPARATE_PAGE', 0);
+
+/**
+ * Comment form should be shown below post or list of comments.
+ */
+define('COMMENT_FORM_BELOW', 1);
+
+/**
+ * Comments for this node are hidden.
+ */
+define('COMMENT_NODE_HIDDEN', 0);
+
+/**
+ * Comments for this node are closed.
+ */
+define('COMMENT_NODE_CLOSED', 1);
+
+/**
+ * Comments for this node are open.
+ */
+define('COMMENT_NODE_OPEN', 2);
+
+/**
+ * Implements hook_help().
+ */
+function comment_help($path, $arg) {
+ switch ($path) {
+ case 'admin/help#comment':
+ $output = '<h3>' . t('About') . '</h3>';
+ $output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the online handbook entry for <a href="@comment">Comment module</a>.', array('@comment' => 'http://drupal.org/documentation/modules/comment/')) . '</p>';
+ $output .= '<h3>' . t('Uses') . '</h3>';
+ $output .= '<dl>';
+ $output .= '<dt>' . t('Default and custom settings') . '</dt>';
+ $output .= '<dd>' . t("Each <a href='@content-type'>content type</a> can have its own default comment settings configured as: <em>Open</em> to allow new comments, <em>Hidden</em> to hide existing comments and prevent new comments, or <em>Closed</em> to view existing comments, but prevent new comments. These defaults will apply to all new content created (changes to the settings on existing content must be done manually). Other comment settings can also be customized per content type, and can be overridden for any given item of content. When a comment has no replies, it remains editable by its author, as long as the author has a user account and is logged in.", array('@content-type' => url('admin/structure/types'))) . '</dd>';
+ $output .= '<dt>' . t('Comment approval') . '</dt>';
+ $output .= '<dd>' . t("Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href='@comment-approval'>Unapproved comments</a> queue, until a user who has permission to <em>Administer comments</em> publishes or deletes them. Published comments can be bulk managed on the <a href='@admin-comment'>Published comments</a> administration page.", array('@comment-approval' => url('admin/content/comment/approval'), '@admin-comment' => url('admin/content/comment'))) . '</dd>';
+ $output .= '</dl>';
+ return $output;
+ }
+}
+
+/**
+ * Implements hook_entity_info().
+ */
+function comment_entity_info() {
+ $return = array(
+ 'comment' => array(
+ 'label' => t('Comment'),
+ 'base table' => 'comment',
+ 'uri callback' => 'comment_uri',
+ 'fieldable' => TRUE,
+ 'controller class' => 'CommentController',
+ 'entity keys' => array(
+ 'id' => 'cid',
+ 'bundle' => 'node_type',
+ 'label' => 'subject',
+ 'language' => 'language',
+ ),
+ 'bundles' => array(),
+ 'view modes' => array(
+ 'full' => array(
+ 'label' => t('Full comment'),
+ 'custom settings' => FALSE,
+ ),
+ ),
+ 'static cache' => FALSE,
+ ),
+ );
+
+ foreach (node_type_get_names() as $type => $name) {
+ $return['comment']['bundles']['comment_node_' . $type] = array(
+ 'label' => t('@node_type comment', array('@node_type' => $name)),
+ // Provide the node type/bundle name for other modules, so it does not
+ // have to be extracted manually from the bundle name.
+ 'node bundle' => $type,
+ 'admin' => array(
+ // Place the Field UI paths for comments one level below the
+ // corresponding paths for nodes, so that they appear in the same set
+ // of local tasks. Note that the paths use a different placeholder name
+ // and thus a different menu loader callback, so that Field UI page
+ // callbacks get a comment bundle name from the node type in the URL.
+ // See comment_node_type_load() and comment_menu_alter().
+ 'path' => 'admin/structure/types/manage/%comment_node_type/comment',
+ 'bundle argument' => 4,
+ 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type) . '/comment',
+ 'access arguments' => array('administer content types'),
+ ),
+ );
+ }
+
+ return $return;
+}
+
+/**
+ * Menu loader callback for Field UI paths.
+ *
+ * Return a comment bundle name from a node type in the URL.
+ */
+function comment_node_type_load($name) {
+ if ($type = node_type_get_type(strtr($name, array('-' => '_')))) {
+ return 'comment_node_' . $type->type;
+ }
+}
+
+/**
+ * Implements callback_entity_info_uri().
+ */
+function comment_uri($comment) {
+ return array(
+ 'path' => 'comment/' . $comment->cid,
+ 'options' => array('fragment' => 'comment-' . $comment->cid),
+ );
+}
+
+/**
+ * Implements hook_field_extra_fields().
+ */
+function comment_field_extra_fields() {
+ $return = array();
+
+ foreach (node_type_get_types() as $type) {
+ if (variable_get('comment_subject_field_' . $type->type, 1) == 1) {
+ $return['comment']['comment_node_' . $type->type] = array(
+ 'form' => array(
+ 'author' => array(
+ 'label' => t('Author'),
+ 'description' => t('Author textfield'),
+ 'weight' => -2,
+ ),
+ 'subject' => array(
+ 'label' => t('Subject'),
+ 'description' => t('Subject textfield'),
+ 'weight' => -1,
+ ),
+ ),
+ );
+ }
+ }
+
+ return $return;
+}
+
+/**
+ * Implements hook_theme().
+ */
+function comment_theme() {
+ return array(
+ 'comment_block' => array(
+ 'variables' => array(),
+ ),
+ 'comment_preview' => array(
+ 'variables' => array('comment' => NULL),
+ ),
+ 'comment' => array(
+ 'template' => 'comment',
+ 'render element' => 'elements',
+ ),
+ 'comment_post_forbidden' => array(
+ 'variables' => array('node' => NULL),
+ ),
+ 'comment_wrapper' => array(
+ 'template' => 'comment-wrapper',
+ 'render element' => 'content',
+ ),
+ );
+}
+
+/**
+ * Implements hook_menu().
+ */
+function comment_menu() {
+ $items['admin/content/comment'] = array(
+ 'title' => 'Comments',
+ 'description' => 'List and edit site comments and the comment approval queue.',
+ 'page callback' => 'comment_admin',
+ 'access arguments' => array('administer comments'),
+ 'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
+ 'file' => 'comment.admin.inc',
+ );
+ // Tabs begin here.
+ $items['admin/content/comment/new'] = array(
+ 'title' => 'Published comments',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
+ $items['admin/content/comment/approval'] = array(
+ 'title' => 'Unapproved comments',
+ 'title callback' => 'comment_count_unpublished',
+ 'page arguments' => array('approval'),
+ 'access arguments' => array('administer comments'),
+ 'type' => MENU_LOCAL_TASK,
+ );
+ $items['comment/%'] = array(
+ 'title' => 'Comment permalink',
+ 'page callback' => 'comment_permalink',
+ 'page arguments' => array(1),
+ 'access arguments' => array('access comments'),
+ );
+ $items['comment/%/view'] = array(
+ 'title' => 'View comment',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
+ // Every other comment path uses %, but this one loads the comment directly,
+ // so we don't end up loading it twice (in the page and access callback).
+ $items['comment/%comment/edit'] = array(
+ 'title' => 'Edit',
+ 'page callback' => 'comment_edit_page',
+ 'page arguments' => array(1),
+ 'access callback' => 'comment_access',
+ 'access arguments' => array('edit', 1),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 0,
+ );
+ $items['comment/%/approve'] = array(
+ 'title' => 'Approve',
+ 'page callback' => 'comment_approve',
+ 'page arguments' => array(1),
+ 'access arguments' => array('administer comments'),
+ 'file' => 'comment.pages.inc',
+ 'weight' => 1,
+ );
+ $items['comment/%/delete'] = array(
+ 'title' => 'Delete',
+ 'page callback' => 'comment_confirm_delete_page',
+ 'page arguments' => array(1),
+ 'access arguments' => array('administer comments'),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'comment.admin.inc',
+ 'weight' => 2,
+ );
+ $items['comment/reply/%node'] = array(
+ 'title' => 'Add new comment',
+ 'page callback' => 'comment_reply',
+ 'page arguments' => array(2),
+ 'access callback' => 'node_access',
+ 'access arguments' => array('view', 2),
+ 'file' => 'comment.pages.inc',
+ );
+
+ return $items;
+}
+
+/**
+ * Implements hook_menu_alter().
+ */
+function comment_menu_alter(&$items) {
+ // Add comments to the description for admin/content.
+ $items['admin/content']['description'] = 'Administer content and comments.';
+
+ // Adjust the Field UI tabs on admin/structure/types/manage/[node-type].
+ // See comment_entity_info().
+ $items['admin/structure/types/manage/%comment_node_type/comment/fields']['title'] = 'Comment fields';
+ $items['admin/structure/types/manage/%comment_node_type/comment/fields']['weight'] = 3;
+ $items['admin/structure/types/manage/%comment_node_type/comment/display']['title'] = 'Comment display';
+ $items['admin/structure/types/manage/%comment_node_type/comment/display']['weight'] = 4;
+}
+
+/**
+ * Returns a menu title which includes the number of unapproved comments.
+ */
+function comment_count_unpublished() {
+ $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array(
+ ':status' => COMMENT_NOT_PUBLISHED,
+ ))->fetchField();
+ return t('Unapproved comments (@count)', array('@count' => $count));
+}
+
+/**
+ * Implements hook_node_type_insert().
+ *
+ * Creates a comment body field for a node type created while the comment module
+ * is enabled. For node types created before the comment module is enabled,
+ * hook_modules_enabled() serves to create the body fields.
+ *
+ * @see comment_modules_enabled()
+ */
+function comment_node_type_insert($info) {
+ _comment_body_field_create($info);
+}
+
+/**
+ * Implements hook_node_type_update().
+ */
+function comment_node_type_update($info) {
+ if (!empty($info->old_type) && $info->type != $info->old_type) {
+ field_attach_rename_bundle('comment', 'comment_node_' . $info->old_type, 'comment_node_' . $info->type);
+ }
+}
+
+/**
+ * Implements hook_node_type_delete().
+ */
+function comment_node_type_delete($info) {
+ field_attach_delete_bundle('comment', 'comment_node_' . $info->type);
+ $settings = array(
+ 'comment',
+ 'comment_default_mode',
+ 'comment_default_per_page',
+ 'comment_anonymous',
+ 'comment_subject_field',
+ 'comment_preview',
+ 'comment_form_location',
+ );
+ foreach ($settings as $setting) {
+ variable_del($setting . '_' . $info->type);
+ }
+}
+
+ /**
+ * Creates a comment_body field instance for a given node type.
+ */
+function _comment_body_field_create($info) {
+ // Create the field if needed.
+ if (!field_read_field('comment_body', array('include_inactive' => TRUE))) {
+ $field = array(
+ 'field_name' => 'comment_body',
+ 'type' => 'text_long',
+ 'entity_types' => array('comment'),
+ );
+ field_create_field($field);
+ }
+ // Create the instance if needed.
+ if (!field_read_instance('comment', 'comment_body', 'comment_node_' . $info->type, array('include_inactive' => TRUE))) {
+ field_attach_create_bundle('comment', 'comment_node_' . $info->type);
+ // Attaches the body field by default.
+ $instance = array(
+ 'field_name' => 'comment_body',
+ 'label' => 'Comment',
+ 'entity_type' => 'comment',
+ 'bundle' => 'comment_node_' . $info->type,
+ 'settings' => array('text_processing' => 1),
+ 'required' => TRUE,
+ 'display' => array(
+ 'default' => array(
+ 'label' => 'hidden',
+ 'type' => 'text_default',
+ 'weight' => 0,
+ ),
+ ),
+ );
+ field_create_instance($instance);
+ }
+}
+
+/**
+ * Implements hook_permission().
+ */
+function comment_permission() {
+ return array(
+ 'administer comments' => array(
+ 'title' => t('Administer comments and comment settings'),
+ ),
+ 'access comments' => array(
+ 'title' => t('View comments'),
+ ),
+ 'post comments' => array(
+ 'title' => t('Post comments'),
+ ),
+ 'skip comment approval' => array(
+ 'title' => t('Skip comment approval'),
+ ),
+ 'edit own comments' => array(
+ 'title' => t('Edit own comments'),
+ ),
+ );
+}
+
+/**
+ * Implements hook_block_info().
+ */
+function comment_block_info() {
+ $blocks['recent']['info'] = t('Recent comments');
+ $blocks['recent']['properties']['administrative'] = TRUE;
+
+ return $blocks;
+}
+
+/**
+ * Implements hook_block_configure().
+ */
+function comment_block_configure($delta = '') {
+ $form['comment_block_count'] = array(
+ '#type' => 'select',
+ '#title' => t('Number of recent comments'),
+ '#default_value' => variable_get('comment_block_count', 10),
+ '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)),
+ );
+
+ return $form;
+}
+
+/**
+ * Implements hook_block_save().
+ */
+function comment_block_save($delta = '', $edit = array()) {
+ variable_set('comment_block_count', (int) $edit['comment_block_count']);
+}
+
+/**
+ * Implements hook_block_view().
+ *
+ * Generates a block with the most recent comments.
+ */
+function comment_block_view($delta = '') {
+ if (user_access('access comments')) {
+ $block['subject'] = t('Recent comments');
+ $block['content'] = theme('comment_block');
+
+ return $block;
+ }
+}
+
+/**
+ * Redirects comment links to the correct page depending on comment settings.
+ *
+ * Since comments are paged there is no way to guarantee which page a comment
+ * appears on. Comment paging and threading settings may be changed at any time.
+ * With threaded comments, an individual comment may move between pages as
+ * comments can be added either before or after it in the overall discussion.
+ * Therefore we use a central routing function for comment links, which
+ * calculates the page number based on current comment settings and returns
+ * the full comment view with the pager set dynamically.
+ *
+ * @param $cid
+ * A comment identifier.
+ * @return
+ * The comment listing set to the page on which the comment appears.
+ */
+function comment_permalink($cid) {
+ if (($comment = comment_load($cid)) && ($node = node_load($comment->nid))) {
+
+ // Find the current display page for this comment.
+ $page = comment_get_display_page($comment->cid, $node->type);
+
+ // Set $_GET['q'] and $_GET['page'] ourselves so that the node callback
+ // behaves as it would when visiting the page directly.
+ $_GET['q'] = 'node/' . $node->nid;
+ $_GET['page'] = $page;
+
+ // Return the node view, this will show the correct comment in context.
+ return menu_execute_active_handler('node/' . $node->nid, FALSE);
+ }
+ return MENU_NOT_FOUND;
+}
+
+/**
+ * Find the most recent comments that are available to the current user.
+ *
+ * @param integer $number
+ * (optional) The maximum number of comments to find. Defaults to 10.
+ *
+ * @return
+ * An array of comment objects or an empty array if there are no recent
+ * comments visible to the current user.
+ */
+function comment_get_recent($number = 10) {
+ $query = db_select('comment', 'c');
+ $query->innerJoin('node', 'n', 'n.nid = c.nid');
+ $query->addTag('node_access');
+ $comments = $query
+ ->fields('c')
+ ->condition('c.status', COMMENT_PUBLISHED)
+ ->condition('n.status', NODE_PUBLISHED)
+ ->orderBy('c.created', 'DESC')
+ // Additionally order by cid to ensure that comments with the same timestamp
+ // are returned in the exact order posted.
+ ->orderBy('c.cid', 'DESC')
+ ->range(0, $number)
+ ->execute()
+ ->fetchAll();
+
+ return $comments ? $comments : array();
+}
+
+/**
+ * Calculate page number for first new comment.
+ *
+ * @param $num_comments
+ * Number of comments.
+ * @param $new_replies
+ * Number of new replies.
+ * @param $node
+ * The first new comment node.
+ * @return
+ * "page=X" if the page number is greater than zero; empty string otherwise.
+ */
+function comment_new_page_count($num_comments, $new_replies, $node) {
+ $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
+ $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
+ $pagenum = NULL;
+ $flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE;
+ if ($num_comments <= $comments_per_page) {
+ // Only one page of comments.
+ $pageno = 0;
+ }
+ elseif ($flat) {
+ // Flat comments.
+ $count = $num_comments - $new_replies;
+ $pageno = $count / $comments_per_page;
+ }
+ else {
+ // Threaded comments: we build a query with a subquery to find the first
+ // thread with a new comment.
+
+ // 1. Find all the threads with a new comment.
+ $unread_threads_query = db_select('comment')
+ ->fields('comment', array('thread'))
+ ->condition('nid', $node->nid)
+ ->condition('status', COMMENT_PUBLISHED)
+ ->orderBy('created', 'DESC')
+ ->orderBy('cid', 'DESC')
+ ->range(0, $new_replies);
+
+ // 2. Find the first thread.
+ $first_thread = db_select($unread_threads_query, 'thread')
+ ->fields('thread', array('thread'))
+ ->orderBy('SUBSTRING(thread, 1, (LENGTH(thread) - 1))')
+ ->range(0, 1)
+ ->execute()
+ ->fetchField();
+
+ // Remove the final '/'.
+ $first_thread = substr($first_thread, 0, -1);
+
+ // Find the number of the first comment of the first unread thread.
+ $count = db_query('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array(
+ ':status' => COMMENT_PUBLISHED,
+ ':nid' => $node->nid,
+ ':thread' => $first_thread,
+ ))->fetchField();
+
+ $pageno = $count / $comments_per_page;
+ }
+
+ if ($pageno >= 1) {
+ $pagenum = array('page' => intval($pageno));
+ }
+
+ return $pagenum;
+}
+
+/**
+ * Returns HTML for a list of recent comments to be displayed in the comment block.
+ *
+ * @ingroup themeable
+ */
+function theme_comment_block() {
+ $items = array();
+ $number = variable_get('comment_block_count', 10);
+ foreach (comment_get_recent($number) as $comment) {
+ $items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . '&nbsp;<span>' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->changed))) . '</span>';
+ }
+
+ if ($items) {
+ return theme('item_list', array('items' => $items));
+ }
+ else {
+ return t('No comments available.');
+ }
+}
+
+/**
+ * Implements hook_node_view().
+ */
+function comment_node_view($node, $view_mode) {
+ $links = array();
+
+ if ($node->comment != COMMENT_NODE_HIDDEN) {
+ if ($view_mode == 'rss') {
+ // Add a comments RSS element which is a URL to the comments of this node.
+ $node->rss_elements[] = array(
+ 'key' => 'comments',
+ 'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))
+ );
+ }
+ elseif ($view_mode == 'teaser') {
+ // Teaser view: display the number of comments that have been posted,
+ // or a link to add new comments if the user has permission, the node
+ // is open to new comments, and there currently are none.
+ if (user_access('access comments')) {
+ if (!empty($node->comment_count)) {
+ $links['comment-comments'] = array(
+ 'title' => format_plural($node->comment_count, '1 comment', '@count comments'),
+ 'href' => "node/$node->nid",
+ 'attributes' => array('title' => t('Jump to the first comment of this posting.')),
+ 'fragment' => 'comments',
+ 'html' => TRUE,
+ );
+ // Show a link to the first new comment.
+ if ($new = comment_num_new($node->nid)) {
+ $links['comment-new-comments'] = array(
+ 'title' => format_plural($new, '1 new comment', '@count new comments'),
+ 'href' => "node/$node->nid",
+ 'query' => comment_new_page_count($node->comment_count, $new, $node),
+ 'attributes' => array('title' => t('Jump to the first new comment of this posting.')),
+ 'fragment' => 'new',
+ 'html' => TRUE,
+ );
+ }
+ }
+ }
+ if ($node->comment == COMMENT_NODE_OPEN) {
+ if (user_access('post comments')) {
+ $links['comment-add'] = array(
+ 'title' => t('Add new comment'),
+ 'href' => "comment/reply/$node->nid",
+ 'attributes' => array('title' => t('Add a new comment to this page.')),
+ 'fragment' => 'comment-form',
+ );
+ }
+ else {
+ $links['comment_forbidden'] = array(
+ 'title' => theme('comment_post_forbidden', array('node' => $node)),
+ 'html' => TRUE,
+ );
+ }
+ }
+ }
+ elseif ($view_mode != 'search_index' && $view_mode != 'search_result') {
+ // Node in other view modes: add a "post comment" link if the user is
+ // allowed to post comments and if this node is allowing new comments.
+ // But we don't want this link if we're building the node for search
+ // indexing or constructing a search result excerpt.
+ if ($node->comment == COMMENT_NODE_OPEN) {
+ $comment_form_location = variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW);
+ if (user_access('post comments')) {
+ // Show the "post comment" link if the form is on another page, or
+ // if there are existing comments that the link will skip past.
+ if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE || (!empty($node->comment_count) && user_access('access comments'))) {
+ $links['comment-add'] = array(
+ 'title' => t('Add new comment'),
+ 'attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')),
+ 'href' => "node/$node->nid",
+ 'fragment' => 'comment-form',
+ );
+ if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE) {
+ $links['comment-add']['href'] = "comment/reply/$node->nid";
+ }
+ }
+ }
+ else {
+ $links['comment_forbidden'] = array(
+ 'title' => theme('comment_post_forbidden', array('node' => $node)),
+ 'html' => TRUE,
+ );
+ }
+ }
+ }
+
+ $node->content['links']['comment'] = array(
+ '#theme' => 'links__node__comment',
+ '#links' => $links,
+ '#attributes' => array('class' => array('links', 'inline')),
+ );
+
+ // Only append comments when we are building a node on its own node detail
+ // page. We compare $node and $page_node to ensure that comments are not
+ // appended to other nodes shown on the page, for example a node_reference
+ // displayed in 'full' view mode within another node.
+ if ($node->comment && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
+ $node->content['comments'] = comment_node_page_additions($node);
+ }
+ }
+}
+
+/**
+ * Build the comment-related elements for node detail pages.
+ *
+ * @param $node
+ * A node object.
+ */
+function comment_node_page_additions($node) {
+ $additions = array();
+
+ // Only attempt to render comments if the node has visible comments.
+ // Unpublished comments are not included in $node->comment_count, so show
+ // comments unconditionally if the user is an administrator.
+ if (($node->comment_count && user_access('access comments')) || user_access('administer comments')) {
+ $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
+ $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
+ if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
+ $comments = comment_load_multiple($cids);
+ comment_prepare_thread($comments);
+ $build = comment_view_multiple($comments, $node);
+ $build['pager']['#theme'] = 'pager';
+ $additions['comments'] = $build;
+ }
+ }
+
+ // Append comment form if needed.
+ if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) {
+ $build = drupal_get_form("comment_node_{$node->type}_form", (object) array('nid' => $node->nid));
+ $additions['comment_form'] = $build;
+ }
+
+ if ($additions) {
+ $additions += array(
+ '#theme' => 'comment_wrapper__node_' . $node->type,
+ '#node' => $node,
+ 'comments' => array(),
+ 'comment_form' => array(),
+ );
+ }
+
+ return $additions;
+}
+
+/**
+ * Retrieve comments for a thread.
+ *
+ * @param $node
+ * The node whose comment(s) needs rendering.
+ * @param $mode
+ * The comment display mode; COMMENT_MODE_FLAT or COMMENT_MODE_THREADED.
+ * @param $comments_per_page
+ * The amount of comments to display per page.
+ *
+ * To display threaded comments in the correct order we keep a 'thread' field
+ * and order by that value. This field keeps this data in
+ * a way which is easy to update and convenient to use.
+ *
+ * A "thread" value starts at "1". If we add a child (A) to this comment,
+ * we assign it a "thread" = "1.1". A child of (A) will have "1.1.1". Next
+ * brother of (A) will get "1.2". Next brother of the parent of (A) will get
+ * "2" and so on.
+ *
+ * First of all note that the thread field stores the depth of the comment:
+ * depth 0 will be "X", depth 1 "X.X", depth 2 "X.X.X", etc.
+ *
+ * Now to get the ordering right, consider this example:
+ *
+ * 1
+ * 1.1
+ * 1.1.1
+ * 1.2
+ * 2
+ *
+ * If we "ORDER BY thread ASC" we get the above result, and this is the
+ * natural order sorted by time. However, if we "ORDER BY thread DESC"
+ * we get:
+ *
+ * 2
+ * 1.2
+ * 1.1.1
+ * 1.1
+ * 1
+ *
+ * Clearly, this is not a natural way to see a thread, and users will get
+ * confused. The natural order to show a thread by time desc would be:
+ *
+ * 2
+ * 1
+ * 1.2
+ * 1.1
+ * 1.1.1
+ *
+ * which is what we already did before the standard pager patch. To achieve
+ * this we simply add a "/" at the end of each "thread" value. This way, the
+ * thread fields will look like this:
+ *
+ * 1/
+ * 1.1/
+ * 1.1.1/
+ * 1.2/
+ * 2/
+ *
+ * we add "/" since this char is, in ASCII, higher than every number, so if
+ * now we "ORDER BY thread DESC" we get the correct order. However this would
+ * spoil the reverse ordering, "ORDER BY thread ASC" -- here, we do not need
+ * to consider the trailing "/" so we use a substring only.
+ */
+function comment_get_thread($node, $mode, $comments_per_page) {
+ $query = db_select('comment', 'c')->extend('PagerDefault');
+ $query->addField('c', 'cid');
+ $query
+ ->condition('c.nid', $node->nid)
+ ->addTag('node_access')
+ ->addTag('comment_filter')
+ ->addMetaData('node', $node)
+ ->limit($comments_per_page);
+
+ $count_query = db_select('comment', 'c');
+ $count_query->addExpression('COUNT(*)');
+ $count_query
+ ->condition('c.nid', $node->nid)
+ ->addTag('node_access')
+ ->addTag('comment_filter')
+ ->addMetaData('node', $node);
+
+ if (!user_access('administer comments')) {
+ $query->condition('c.status', COMMENT_PUBLISHED);
+ $count_query->condition('c.status', COMMENT_PUBLISHED);
+ }
+ if ($mode === COMMENT_MODE_FLAT) {
+ $query->orderBy('c.cid', 'ASC');
+ }
+ else {
+ // See comment above. Analysis reveals that this doesn't cost too
+ // much. It scales much much better than having the whole comment
+ // structure.
+ $query->addExpression('SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))', 'torder');
+ $query->orderBy('torder', 'ASC');
+ }
+
+ $query->setCountQuery($count_query);
+ $cids = $query->execute()->fetchCol();
+
+ return $cids;
+}
+
+/**
+ * Loop over comment thread, noting indentation level.
+ *
+ * @param array $comments
+ * An array of comment objects, keyed by cid.
+ * @return
+ * The $comments argument is altered by reference with indentation information.
+ */
+function comment_prepare_thread(&$comments) {
+ // A flag stating if we are still searching for first new comment on the thread.
+ $first_new = TRUE;
+
+ // A counter that helps track how indented we are.
+ $divs = 0;
+
+ foreach ($comments as $key => $comment) {
+ if ($first_new && $comment->new != MARK_READ) {
+ // Assign the anchor only for the first new comment. This avoids duplicate
+ // id attributes on a page.
+ $first_new = FALSE;
+ $comment->first_new = TRUE;
+ }
+
+ // The $divs element instructs #prefix whether to add an indent div or
+ // close existing divs (a negative value).
+ $comment->depth = count(explode('.', $comment->thread)) - 1;
+ if ($comment->depth > $divs) {
+ $comment->divs = 1;
+ $divs++;
+ }
+ else {
+ $comment->divs = $comment->depth - $divs;
+ while ($comment->depth < $divs) {
+ $divs--;
+ }
+ }
+ $comments[$key] = $comment;
+ }
+
+ // The final comment must close up some hanging divs
+ $comments[$key]->divs_final = $divs;
+}
+
+/**
+ * Generate an array for rendering the given comment.
+ *
+ * @param $comment
+ * A comment object.
+ * @param $node
+ * The node the comment is attached to.
+ * @param $view_mode
+ * View mode, e.g. 'full', 'teaser'...
+ * @param $langcode
+ * (optional) A language code to use for rendering. Defaults to the global
+ * content language of the current request.
+ *
+ * @return
+ * An array as expected by drupal_render().
+ */
+function comment_view($comment, $node, $view_mode = 'full', $langcode = NULL) {
+ if (!isset($langcode)) {
+ $langcode = $GLOBALS['language_content']->language;
+ }
+
+ // Populate $comment->content with a render() array.
+ comment_build_content($comment, $node, $view_mode, $langcode);
+
+ $build = $comment->content;
+ // We don't need duplicate rendering info in comment->content.
+ unset($comment->content);
+
+ $build += array(
+ '#theme' => 'comment__node_' . $node->type,
+ '#comment' => $comment,
+ '#node' => $node,
+ '#view_mode' => $view_mode,
+ '#language' => $langcode,
+ );
+
+ if (empty($comment->in_preview)) {
+ $prefix = '';
+ $is_threaded = isset($comment->divs) && variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED) == COMMENT_MODE_THREADED;
+
+ // Add 'new' anchor if needed.
+ if (!empty($comment->first_new)) {
+ $prefix .= "<a id=\"new\"></a>\n";
+ }
+
+ // Add indentation div or close open divs as needed.
+ if ($is_threaded) {
+ $prefix .= $comment->divs <= 0 ? str_repeat('</div>', abs($comment->divs)) : "\n" . '<div class="indented">';
+ }
+
+ // Add anchor for each comment.
+ $prefix .= "<a id=\"comment-$comment->cid\"></a>\n";
+ $build['#prefix'] = $prefix;
+
+ // Close all open divs.
+ if ($is_threaded && !empty($comment->divs_final)) {
+ $build['#suffix'] = str_repeat('</div>', $comment->divs_final);
+ }
+ }
+
+ // Allow modules to modify the structured comment.
+ $type = 'comment';
+ drupal_alter(array('comment_view', 'entity_view'), $build, $type);
+
+ return $build;
+}
+
+/**
+ * Builds a structured array representing the comment's content.
+ *
+ * The content built for the comment (field values, comments, file attachments or
+ * other comment components) will vary depending on the $view_mode parameter.
+ *
+ * @param $comment
+ * A comment object.
+ * @param $node
+ * The node the comment is attached to.
+ * @param $view_mode
+ * View mode, e.g. 'full', 'teaser'...
+ * @param $langcode
+ * (optional) A language code to use for rendering. Defaults to the global
+ * content language of the current request.
+ */
+function comment_build_content($comment, $node, $view_mode = 'full', $langcode = NULL) {
+ if (!isset($langcode)) {
+ $langcode = $GLOBALS['language_content']->language;
+ }
+
+ // Remove previously built content, if exists.
+ $comment->content = array();
+
+ // Allow modules to change the view mode.
+ $context = array(
+ 'entity_type' => 'comment',
+ 'entity' => $comment,
+ 'langcode' => $langcode,
+ );
+ drupal_alter('entity_view_mode', $view_mode, $context);
+
+ // Build fields content.
+ field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode);
+ entity_prepare_view('comment', array($comment->cid => $comment), $langcode);
+ $comment->content += field_attach_view('comment', $comment, $view_mode, $langcode);
+
+ $comment->content['links'] = array(
+ '#theme' => 'links__comment',
+ '#pre_render' => array('drupal_pre_render_links'),
+ '#attributes' => array('class' => array('links', 'inline')),
+ );
+ if (empty($comment->in_preview)) {
+ $comment->content['links']['comment'] = array(
+ '#theme' => 'links__comment__comment',
+ '#links' => comment_links($comment, $node),
+ '#attributes' => array('class' => array('links', 'inline')),
+ );
+ }
+
+ // Allow modules to make their own additions to the comment.
+ module_invoke_all('comment_view', $comment, $view_mode, $langcode);
+ module_invoke_all('entity_view', $comment, 'comment', $view_mode, $langcode);
+
+ // Make sure the current view mode is stored if no module has already
+ // populated the related key.
+ $comment->content += array('#view_mode' => $view_mode);
+}
+
+/**
+ * Helper function, build links for an individual comment.
+ *
+ * Adds reply, edit, delete etc. depending on the current user permissions.
+ *
+ * @param $comment
+ * The comment object.
+ * @param $node
+ * The node the comment is attached to.
+ * @return
+ * A structured array of links.
+ */
+function comment_links($comment, $node) {
+ $links = array();
+ if ($node->comment == COMMENT_NODE_OPEN) {
+ if (user_access('administer comments') && user_access('post comments')) {
+ $links['comment-delete'] = array(
+ 'title' => t('delete'),
+ 'href' => "comment/$comment->cid/delete",
+ 'html' => TRUE,
+ );
+ $links['comment-edit'] = array(
+ 'title' => t('edit'),
+ 'href' => "comment/$comment->cid/edit",
+ 'html' => TRUE,
+ );
+ $links['comment-reply'] = array(
+ 'title' => t('reply'),
+ 'href' => "comment/reply/$comment->nid/$comment->cid",
+ 'html' => TRUE,
+ );
+ if ($comment->status == COMMENT_NOT_PUBLISHED) {
+ $links['comment-approve'] = array(
+ 'title' => t('approve'),
+ 'href' => "comment/$comment->cid/approve",
+ 'html' => TRUE,
+ 'query' => array('token' => drupal_get_token("comment/$comment->cid/approve")),
+ );
+ }
+ }
+ elseif (user_access('post comments')) {
+ if (comment_access('edit', $comment)) {
+ $links['comment-edit'] = array(
+ 'title' => t('edit'),
+ 'href' => "comment/$comment->cid/edit",
+ 'html' => TRUE,
+ );
+ }
+ $links['comment-reply'] = array(
+ 'title' => t('reply'),
+ 'href' => "comment/reply/$comment->nid/$comment->cid",
+ 'html' => TRUE,
+ );
+ }
+ else {
+ $links['comment_forbidden']['title'] = theme('comment_post_forbidden', array('node' => $node));
+ $links['comment_forbidden']['html'] = TRUE;
+ }
+ }
+ return $links;
+}
+
+/**
+ * Construct a drupal_render() style array from an array of loaded comments.
+ *
+ * @param $comments
+ * An array of comments as returned by comment_load_multiple().
+ * @param $node
+ * The node the comments are attached to.
+ * @param $view_mode
+ * View mode, e.g. 'full', 'teaser'...
+ * @param $weight
+ * An integer representing the weight of the first comment in the list.
+ * @param $langcode
+ * A string indicating the language field values are to be shown in. If no
+ * language is provided the current content language is used.
+ *
+ * @return
+ * An array in the format expected by drupal_render().
+ */
+function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL) {
+ field_attach_prepare_view('comment', $comments, $view_mode, $langcode);
+ entity_prepare_view('comment', $comments, $langcode);
+
+ $build = array(
+ '#sorted' => TRUE,
+ );
+ foreach ($comments as $comment) {
+ $build[$comment->cid] = comment_view($comment, $node, $view_mode, $langcode);
+ $build[$comment->cid]['#weight'] = $weight;
+ $weight++;
+ }
+ return $build;
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function comment_form_node_type_form_alter(&$form, $form_state) {
+ if (isset($form['type'])) {
+ $form['comment'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Comment settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'additional_settings',
+ '#attributes' => array(
+ 'class' => array('comment-node-type-settings-form'),
+ ),
+ '#attached' => array(
+ 'js' => array(drupal_get_path('module', 'comment') . '/comment-node-form.js'),
+ ),
+ );
+ // Unlike coment_form_node_form_alter(), all of these settings are applied
+ // as defaults to all new nodes. Therefore, it would be wrong to use #states
+ // to hide the other settings based on the primary comment setting.
+ $form['comment']['comment'] = array(
+ '#type' => 'select',
+ '#title' => t('Default comment setting for new content'),
+ '#default_value' => variable_get('comment_' . $form['#node_type']->type, COMMENT_NODE_OPEN),
+ '#options' => array(
+ COMMENT_NODE_OPEN => t('Open'),
+ COMMENT_NODE_CLOSED => t('Closed'),
+ COMMENT_NODE_HIDDEN => t('Hidden'),
+ ),
+ );
+ $form['comment']['comment_default_mode'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Threading'),
+ '#default_value' => variable_get('comment_default_mode_' . $form['#node_type']->type, COMMENT_MODE_THREADED),
+ '#description' => t('Show comment replies in a threaded list.'),
+ );
+ $form['comment']['comment_default_per_page'] = array(
+ '#type' => 'select',
+ '#title' => t('Comments per page'),
+ '#default_value' => variable_get('comment_default_per_page_' . $form['#node_type']->type, 50),
+ '#options' => _comment_per_page(),
+ );
+ $form['comment']['comment_anonymous'] = array(
+ '#type' => 'select',
+ '#title' => t('Anonymous commenting'),
+ '#default_value' => variable_get('comment_anonymous_' . $form['#node_type']->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT),
+ '#options' => array(
+ COMMENT_ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'),
+ COMMENT_ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'),
+ COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'),
+ ),
+ '#access' => user_access('post comments', drupal_anonymous_user()),
+ );
+ $form['comment']['comment_subject_field'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Allow comment title'),
+ '#default_value' => variable_get('comment_subject_field_' . $form['#node_type']->type, 1),
+ );
+ $form['comment']['comment_form_location'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Show reply form on the same page as comments'),
+ '#default_value' => variable_get('comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_BELOW),
+ );
+ $form['comment']['comment_preview'] = array(
+ '#type' => 'radios',
+ '#title' => t('Preview comment'),
+ '#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, DRUPAL_OPTIONAL),
+ '#options' => array(
+ DRUPAL_DISABLED => t('Disabled'),
+ DRUPAL_OPTIONAL => t('Optional'),
+ DRUPAL_REQUIRED => t('Required'),
+ ),
+ );
+ }
+}
+
+/**
+ * Implements hook_form_BASE_FORM_ID_alter().
+ */
+function comment_form_node_form_alter(&$form, $form_state) {
+ $node = $form['#node'];
+ $form['comment_settings'] = array(
+ '#type' => 'fieldset',
+ '#access' => user_access('administer comments'),
+ '#title' => t('Comment settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'additional_settings',
+ '#attributes' => array(
+ 'class' => array('comment-node-settings-form'),
+ ),
+ '#attached' => array(
+ 'js' => array(drupal_get_path('module', 'comment') . '/comment-node-form.js'),
+ ),
+ '#weight' => 30,
+ );
+ $comment_count = isset($node->nid) ? db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() : 0;
+ $comment_settings = ($node->comment == COMMENT_NODE_HIDDEN && empty($comment_count)) ? COMMENT_NODE_CLOSED : $node->comment;
+ $form['comment_settings']['comment'] = array(
+ '#type' => 'radios',
+ '#title' => t('Comments'),
+ '#title_display' => 'invisible',
+ '#parents' => array('comment'),
+ '#default_value' => $comment_settings,
+ '#options' => array(
+ COMMENT_NODE_OPEN => t('Open'),
+ COMMENT_NODE_CLOSED => t('Closed'),
+ COMMENT_NODE_HIDDEN => t('Hidden'),
+ ),
+ COMMENT_NODE_OPEN => array(
+ '#description' => t('Users with the "Post comments" permission can post comments.'),
+ ),
+ COMMENT_NODE_CLOSED => array(
+ '#description' => t('Users cannot post comments, but existing comments will be displayed.'),
+ ),
+ COMMENT_NODE_HIDDEN => array(
+ '#description' => t('Comments are hidden from view.'),
+ ),
+ );
+ // If the node doesn't have any comments, the "hidden" option makes no
+ // sense, so don't even bother presenting it to the user.
+ if (empty($comment_count)) {
+ $form['comment_settings']['comment'][COMMENT_NODE_HIDDEN]['#access'] = FALSE;
+ // Also adjust the description of the "closed" option.
+ $form['comment_settings']['comment'][COMMENT_NODE_CLOSED]['#description'] = t('Users cannot post comments.');
+ }
+}
+
+/**
+ * Implements hook_node_load().
+ */
+function comment_node_load($nodes, $types) {
+ $comments_enabled = array();
+
+ // Check if comments are enabled for each node. If comments are disabled,
+ // assign values without hitting the database.
+ foreach ($nodes as $node) {
+ // Store whether comments are enabled for this node.
+ if ($node->comment != COMMENT_NODE_HIDDEN) {
+ $comments_enabled[] = $node->nid;
+ }
+ else {
+ $node->cid = 0;
+ $node->last_comment_timestamp = $node->created;
+ $node->last_comment_name = '';
+ $node->last_comment_uid = $node->uid;
+ $node->comment_count = 0;
+ }
+ }
+
+ // For nodes with comments enabled, fetch information from the database.
+ if (!empty($comments_enabled)) {
+ $result = db_query('SELECT nid, cid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count FROM {node_comment_statistics} WHERE nid IN (:comments_enabled)', array(':comments_enabled' => $comments_enabled));
+ foreach ($result as $record) {
+ $nodes[$record->nid]->cid = $record->cid;
+ $nodes[$record->nid]->last_comment_timestamp = $record->last_comment_timestamp;
+ $nodes[$record->nid]->last_comment_name = $record->last_comment_name;
+ $nodes[$record->nid]->last_comment_uid = $record->last_comment_uid;
+ $nodes[$record->nid]->comment_count = $record->comment_count;
+ }
+ }
+}
+
+/**
+ * Implements hook_node_prepare().
+ */
+function comment_node_prepare($node) {
+ if (!isset($node->comment)) {
+ $node->comment = variable_get("comment_$node->type", COMMENT_NODE_OPEN);
+ }
+}
+
+/**
+ * Implements hook_node_insert().
+ */
+function comment_node_insert($node) {
+ // Allow bulk updates and inserts to temporarily disable the
+ // maintenance of the {node_comment_statistics} table.
+ if (variable_get('comment_maintain_node_statistics', TRUE)) {
+ db_insert('node_comment_statistics')
+ ->fields(array(
+ 'nid' => $node->nid,
+ 'cid' => 0,
+ 'last_comment_timestamp' => $node->changed,
+ 'last_comment_name' => NULL,
+ 'last_comment_uid' => $node->uid,
+ 'comment_count' => 0,
+ ))
+ ->execute();
+ }
+}
+
+/**
+ * Implements hook_node_delete().
+ */
+function comment_node_delete($node) {
+ $cids = db_query('SELECT cid FROM {comment} WHERE nid = :nid', array(':nid' => $node->nid))->fetchCol();
+ comment_delete_multiple($cids);
+ db_delete('node_comment_statistics')
+ ->condition('nid', $node->nid)
+ ->execute();
+}
+
+/**
+ * Implements hook_node_update_index().
+ */
+function comment_node_update_index($node) {
+ $index_comments = &drupal_static(__FUNCTION__);
+
+ if ($index_comments === NULL) {
+ // Find and save roles that can 'access comments' or 'search content'.
+ $perms = array('access comments' => array(), 'search content' => array());
+ $result = db_query("SELECT rid, permission FROM {role_permission} WHERE permission IN ('access comments', 'search content')");
+ foreach ($result as $record) {
+ $perms[$record->permission][$record->rid] = $record->rid;
+ }
+
+ // Prevent indexing of comments if there are any roles that can search but
+ // not view comments.
+ $index_comments = TRUE;
+ foreach ($perms['search content'] as $rid) {
+ if (!isset($perms['access comments'][$rid]) && ($rid <= DRUPAL_AUTHENTICATED_RID || !isset($perms['access comments'][DRUPAL_AUTHENTICATED_RID]))) {
+ $index_comments = FALSE;
+ break;
+ }
+ }
+ }
+
+ if ($index_comments) {
+ $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
+ $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
+ if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) {
+ $comments = comment_load_multiple($cids);
+ comment_prepare_thread($comments);
+ $build = comment_view_multiple($comments, $node);
+ return drupal_render($build);
+ }
+ }
+ return '';
+}
+
+/**
+ * Implements hook_update_index().
+ */
+function comment_update_index() {
+ // Store the maximum possible comments per thread (used for ranking by reply count)
+ variable_set('node_cron_comments_scale', 1.0 / max(1, db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')->fetchField()));
+}
+
+/**
+ * Implements hook_node_search_result().
+ *
+ * Formats a comment count string and returns it, for display with search
+ * results.
+ */
+function comment_node_search_result($node) {
+ // Do not make a string if comments are hidden.
+ if (user_access('access comments') && $node->comment != COMMENT_NODE_HIDDEN) {
+ $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
+ // Do not make a string if comments are closed and there are currently
+ // zero comments.
+ if ($node->comment != COMMENT_NODE_CLOSED || $comments > 0) {
+ return array('comment' => format_plural($comments, '1 comment', '@count comments'));
+ }
+ }
+}
+
+/**
+ * Implements hook_user_cancel().
+ */
+function comment_user_cancel($edit, $account, $method) {
+ switch ($method) {
+ case 'user_cancel_block_unpublish':
+ $comments = comment_load_multiple(array(), array('uid' => $account->uid));
+ foreach ($comments as $comment) {
+ $comment->status = 0;
+ comment_save($comment);
+ }
+ break;
+
+ case 'user_cancel_reassign':
+ $comments = comment_load_multiple(array(), array('uid' => $account->uid));
+ foreach ($comments as $comment) {
+ $comment->uid = 0;
+ comment_save($comment);
+ }
+ break;
+ }
+}
+
+/**
+ * Implements hook_user_delete().
+ */
+function comment_user_delete($account) {
+ $cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol();
+ comment_delete_multiple($cids);
+}
+
+/**
+ * Determines whether the current user has access to a particular comment.
+ *
+ * Authenticated users can edit their comments as long they have not been
+ * replied to. This prevents people from changing or revising their statements
+ * based on the replies to their posts.
+ *
+ * @param $op
+ * The operation that is to be performed on the comment. Only 'edit' is
+ * recognized now.
+ * @param $comment
+ * The comment object.
+ * @return
+ * TRUE if the current user has acces to the comment, FALSE otherwise.
+ */
+function comment_access($op, $comment) {
+ global $user;
+
+ if ($op == 'edit') {
+ return ($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments');
+ }
+}
+
+/**
+ * Accepts a submission of new or changed comment content.
+ *
+ * @param $comment
+ * A comment object.
+ */
+function comment_save($comment) {
+ global $user;
+
+ $transaction = db_transaction();
+ try {
+ $defaults = array(
+ 'mail' => '',
+ 'homepage' => '',
+ 'name' => '',
+ 'status' => user_access('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED,
+ );
+ foreach ($defaults as $key => $default) {
+ if (!isset($comment->$key)) {
+ $comment->$key = $default;
+ }
+ }
+ // Make sure we have a bundle name.
+ if (!isset($comment->node_type)) {
+ $node = node_load($comment->nid);
+ $comment->node_type = 'comment_node_' . $node->type;
+ }
+
+ // Load the stored entity, if any.
+ if (!empty($comment->cid) && !isset($comment->original)) {
+ $comment->original = entity_load_unchanged('comment', $comment->cid);
+ }
+
+ field_attach_presave('comment', $comment);
+
+ // Allow modules to alter the comment before saving.
+ module_invoke_all('comment_presave', $comment);
+ module_invoke_all('entity_presave', $comment, 'comment');
+
+ if ($comment->cid) {
+
+ drupal_write_record('comment', $comment, 'cid');
+
+ // Ignore slave server temporarily to give time for the
+ // saved comment to be propagated to the slave.
+ db_ignore_slave();
+
+ // Update the {node_comment_statistics} table prior to executing hooks.
+ _comment_update_node_statistics($comment->nid);
+
+ field_attach_update('comment', $comment);
+ // Allow modules to respond to the updating of a comment.
+ module_invoke_all('comment_update', $comment);
+ module_invoke_all('entity_update', $comment, 'comment');
+ }
+ else {
+ // Add the comment to database. This next section builds the thread field.
+ // Also see the documentation for comment_view().
+ if (!empty($comment->thread)) {
+ // Allow calling code to set thread itself.
+ $thread = $comment->thread;
+ }
+ elseif ($comment->pid == 0) {
+ // This is a comment with no parent comment (depth 0): we start
+ // by retrieving the maximum thread level.
+ $max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid))->fetchField();
+ // Strip the "/" from the end of the thread.
+ $max = rtrim($max, '/');
+ // We need to get the value at the correct depth.
+ $parts = explode('.', $max);
+ $firstsegment = $parts[0];
+ // Finally, build the thread field for this new comment.
+ $thread = int2vancode(vancode2int($firstsegment) + 1) . '/';
+ }
+ else {
+ // This is a comment with a parent comment, so increase the part of the
+ // thread value at the proper depth.
+
+ // Get the parent comment:
+ $parent = comment_load($comment->pid);
+ // Strip the "/" from the end of the parent thread.
+ $parent->thread = (string) rtrim((string) $parent->thread, '/');
+ // Get the max value in *this* thread.
+ $max = db_query("SELECT MAX(thread) FROM {comment} WHERE thread LIKE :thread AND nid = :nid", array(
+ ':thread' => $parent->thread . '.%',
+ ':nid' => $comment->nid,
+ ))->fetchField();
+
+ if ($max == '') {
+ // First child of this parent.
+ $thread = $parent->thread . '.' . int2vancode(0) . '/';
+ }
+ else {
+ // Strip the "/" at the end of the thread.
+ $max = rtrim($max, '/');
+ // Get the value at the correct depth.
+ $parts = explode('.', $max);
+ $parent_depth = count(explode('.', $parent->thread));
+ $last = $parts[$parent_depth];
+ // Finally, build the thread field for this new comment.
+ $thread = $parent->thread . '.' . int2vancode(vancode2int($last) + 1) . '/';
+ }
+ }
+
+ if (empty($comment->created)) {
+ $comment->created = REQUEST_TIME;
+ }
+
+ if (empty($comment->changed)) {
+ $comment->changed = $comment->created;
+ }
+
+ if ($comment->uid === $user->uid && isset($user->name)) { // '===' Need to modify anonymous users as well.
+ $comment->name = $user->name;
+ }
+
+ // Ensure the parent id (pid) has a value set.
+ if (empty($comment->pid)) {
+ $comment->pid = 0;
+ }
+
+ // Add the values which aren't passed into the function.
+ $comment->thread = $thread;
+ $comment->hostname = ip_address();
+
+ drupal_write_record('comment', $comment);
+
+ // Ignore slave server temporarily to give time for the
+ // created comment to be propagated to the slave.
+ db_ignore_slave();
+
+ // Update the {node_comment_statistics} table prior to executing hooks.
+ _comment_update_node_statistics($comment->nid);
+
+ field_attach_insert('comment', $comment);
+
+ // Tell the other modules a new comment has been submitted.
+ module_invoke_all('comment_insert', $comment);
+ module_invoke_all('entity_insert', $comment, 'comment');
+ }
+ if ($comment->status == COMMENT_PUBLISHED) {
+ module_invoke_all('comment_publish', $comment);
+ }
+ unset($comment->original);
+ }
+ catch (Exception $e) {
+ $transaction->rollback('comment');
+ watchdog_exception('comment', $e);
+ throw $e;
+ }
+
+}
+
+/**
+ * Delete a comment and all its replies.
+ *
+ * @param $cid
+ * The comment to delete.
+ */
+function comment_delete($cid) {
+ comment_delete_multiple(array($cid));
+}
+
+/**
+ * Delete comments and all their replies.
+ *
+ * @param $cids
+ * The comment to delete.
+ */
+function comment_delete_multiple($cids) {
+ $comments = comment_load_multiple($cids);
+ if ($comments) {
+ $transaction = db_transaction();
+ try {
+ // Delete the comments.
+ db_delete('comment')
+ ->condition('cid', array_keys($comments), 'IN')
+ ->execute();
+ foreach ($comments as $comment) {
+ field_attach_delete('comment', $comment);
+ module_invoke_all('comment_delete', $comment);
+ module_invoke_all('entity_delete', $comment, 'comment');
+
+ // Delete the comment's replies.
+ $child_cids = db_query('SELECT cid FROM {comment} WHERE pid = :cid', array(':cid' => $comment->cid))->fetchCol();
+ comment_delete_multiple($child_cids);
+ _comment_update_node_statistics($comment->nid);
+ }
+ }
+ catch (Exception $e) {
+ $transaction->rollback();
+ watchdog_exception('comment', $e);
+ throw $e;
+ }
+ }
+}
+
+/**
+ * Load comments from the database.
+ *
+ * @param $cids
+ * An array of comment IDs.
+ * @param $conditions
+ * (deprecated) An associative array of conditions on the {comments}
+ * table, where the keys are the database fields and the values are the
+ * values those fields must have. Instead, it is preferable to use
+ * EntityFieldQuery to retrieve a list of entity IDs loadable by
+ * this function.
+ * @param $reset
+ * Whether to reset the internal static entity cache. Note that the static
+ * cache is disabled in comment_entity_info() by default.
+ *
+ * @return
+ * An array of comment objects, indexed by comment ID.
+ *
+ * @see entity_load()
+ * @see EntityFieldQuery
+ *
+ * @todo Remove $conditions in Drupal 8.
+ */
+function comment_load_multiple($cids = array(), $conditions = array(), $reset = FALSE) {
+ return entity_load('comment', $cids, $conditions, $reset);
+}
+
+/**
+ * Load the entire comment by cid.
+ *
+ * @param $cid
+ * The identifying comment id.
+ * @param $reset
+ * Whether to reset the internal static entity cache. Note that the static
+ * cache is disabled in comment_entity_info() by default.
+ *
+ * @return
+ * The comment object.
+ */
+function comment_load($cid, $reset = FALSE) {
+ $comment = comment_load_multiple(array($cid), array(), $reset);
+ return $comment ? $comment[$cid] : FALSE;
+}
+
+/**
+ * Controller class for comments.
+ *
+ * This extends the DrupalDefaultEntityController class, adding required
+ * special handling for comment objects.
+ */
+class CommentController extends DrupalDefaultEntityController {
+
+ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
+ $query = parent::buildQuery($ids, $conditions, $revision_id);
+ // Specify additional fields from the user and node tables.
+ $query->innerJoin('node', 'n', 'base.nid = n.nid');
+ $query->addField('n', 'type', 'node_type');
+ $query->innerJoin('users', 'u', 'base.uid = u.uid');
+ $query->addField('u', 'name', 'registered_name');
+ $query->fields('u', array('uid', 'signature', 'signature_format', 'picture'));
+ return $query;
+ }
+
+ protected function attachLoad(&$comments, $revision_id = FALSE) {
+ // Setup standard comment properties.
+ foreach ($comments as $key => $comment) {
+ $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
+ $comment->new = node_mark($comment->nid, $comment->changed);
+ $comment->node_type = 'comment_node_' . $comment->node_type;
+ $comments[$key] = $comment;
+ }
+ parent::attachLoad($comments, $revision_id);
+ }
+}
+
+/**
+ * Get number of new comments for current user and specified node.
+ *
+ * @param $nid
+ * Node-id to count comments for.
+ * @param $timestamp
+ * Time to count from (defaults to time of last user access
+ * to node).
+ * @return The result or FALSE on error.
+ */
+function comment_num_new($nid, $timestamp = 0) {
+ global $user;
+
+ if ($user->uid) {
+ // Retrieve the timestamp at which the current user last viewed this node.
+ if (!$timestamp) {
+ $timestamp = node_last_viewed($nid);
+ }
+ $timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT);
+
+ // Use the timestamp to retrieve the number of new comments.
+ return db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND created > :timestamp AND status = :status', array(
+ ':nid' => $nid,
+ ':timestamp' => $timestamp,
+ ':status' => COMMENT_PUBLISHED,
+ ))->fetchField();
+ }
+ else {
+ return FALSE;
+ }
+
+}
+
+/**
+ * Get the display ordinal for a comment, starting from 0.
+ *
+ * Count the number of comments which appear before the comment we want to
+ * display, taking into account display settings and threading.
+ *
+ * @param $cid
+ * The comment ID.
+ * @param $node_type
+ * The node type of the comment's parent.
+ * @return
+ * The display ordinal for the comment.
+ * @see comment_get_display_page()
+ */
+function comment_get_display_ordinal($cid, $node_type) {
+ // Count how many comments (c1) are before $cid (c2) in display order. This is
+ // the 0-based display ordinal.
+ $query = db_select('comment', 'c1');
+ $query->innerJoin('comment', 'c2', 'c2.nid = c1.nid');
+ $query->addExpression('COUNT(*)', 'count');
+ $query->condition('c2.cid', $cid);
+ if (!user_access('administer comments')) {
+ $query->condition('c1.status', COMMENT_PUBLISHED);
+ }
+ $mode = variable_get('comment_default_mode_' . $node_type, COMMENT_MODE_THREADED);
+
+ if ($mode == COMMENT_MODE_FLAT) {
+ // For flat comments, cid is used for ordering comments due to
+ // unpredicatable behavior with timestamp, so we make the same assumption
+ // here.
+ $query->condition('c1.cid', $cid, '<');
+ }
+ else {
+ // For threaded comments, the c.thread column is used for ordering. We can
+ // use the vancode for comparison, but must remove the trailing slash.
+ // See comment_view_multiple().
+ $query->where('SUBSTRING(c1.thread, 1, (LENGTH(c1.thread) -1)) < SUBSTRING(c2.thread, 1, (LENGTH(c2.thread) -1))');
+ }
+
+ return $query->execute()->fetchField();
+}
+
+/**
+ * Return the page number for a comment.
+ *
+ * Finds the correct page number for a comment taking into account display
+ * and paging settings.
+ *
+ * @param $cid
+ * The comment ID.
+ * @param $node_type
+ * The node type the comment is attached to.
+ * @return
+ * The page number.
+ */
+function comment_get_display_page($cid, $node_type) {
+ $ordinal = comment_get_display_ordinal($cid, $node_type);
+ $comments_per_page = variable_get('comment_default_per_page_' . $node_type, 50);
+ return floor($ordinal / $comments_per_page);
+}
+
+/**
+ * Page callback for comment editing.
+ */
+function comment_edit_page($comment) {
+ drupal_set_title(t('Edit comment %comment', array('%comment' => $comment->subject)), PASS_THROUGH);
+ $node = node_load($comment->nid);
+ return drupal_get_form("comment_node_{$node->type}_form", $comment);
+}
+
+/**
+ * Implements hook_forms().
+ */
+function comment_forms() {
+ $forms = array();
+ foreach (node_type_get_types() as $type) {
+ $forms["comment_node_{$type->type}_form"]['callback'] = 'comment_form';
+ }
+ return $forms;
+}
+
+/**
+ * Generate the basic commenting form, for appending to a node or display on a separate page.
+ *
+ * @see comment_form_validate()
+ * @see comment_form_submit()
+ *
+ * @ingroup forms
+ */
+function comment_form($form, &$form_state, $comment) {
+ global $user;
+
+ // During initial form build, add the comment entity to the form state for
+ // use during form building and processing. During a rebuild, use what is in
+ // the form state.
+ if (!isset($form_state['comment'])) {
+ $defaults = array(
+ 'name' => '',
+ 'mail' => '',
+ 'homepage' => '',
+ 'subject' => '',
+ 'comment' => '',
+ 'cid' => NULL,
+ 'pid' => NULL,
+ 'language' => LANGUAGE_NONE,
+ 'uid' => 0,
+ );
+ foreach ($defaults as $key => $value) {
+ if (!isset($comment->$key)) {
+ $comment->$key = $value;
+ }
+ }
+ $form_state['comment'] = $comment;
+ }
+ else {
+ $comment = $form_state['comment'];
+ }
+
+ $node = node_load($comment->nid);
+ $form['#node'] = $node;
+
+ // Use #comment-form as unique jump target, regardless of node type.
+ $form['#id'] = drupal_html_id('comment_form');
+ $form['#attributes']['class'][] = 'comment-form';
+ $form['#theme'] = array('comment_form__node_' . $node->type, 'comment_form');
+
+ $anonymous_contact = variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT);
+ $is_admin = (!empty($comment->cid) && user_access('administer comments'));
+
+ if (!$user->uid && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
+ $form['#attached']['library'][] = array('system', 'jquery.cookie');
+ $form['#attributes']['class'][] = 'user-info-from-cookie';
+ }
+
+ // If not replying to a comment, use our dedicated page callback for new
+ // comments on nodes.
+ if (empty($comment->cid) && empty($comment->pid)) {
+ $form['#action'] = url('comment/reply/' . $comment->nid);
+ }
+
+ if (isset($form_state['comment_preview'])) {
+ $form += $form_state['comment_preview'];
+ }
+
+ // Display author information in a fieldset for comment moderators.
+ if ($is_admin) {
+ $form['author'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Administration'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#weight' => -2,
+ );
+ }
+ else {
+ // Sets the author form elements above the subject.
+ $form['author'] = array(
+ '#weight' => -2,
+ );
+ }
+
+ // Prepare default values for form elements.
+ if ($is_admin) {
+ $author = (!$comment->uid && $comment->name ? $comment->name : $comment->registered_name);
+ $status = (isset($comment->status) ? $comment->status : COMMENT_NOT_PUBLISHED);
+ $date = (!empty($comment->date) ? $comment->date : format_date($comment->created, 'custom', 'Y-m-d H:i O'));
+ }
+ else {
+ if ($user->uid) {
+ $author = $user->name;
+ }
+ else {
+ $author = ($comment->name ? $comment->name : '');
+ }
+ $status = (user_access('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED);
+ $date = '';
+ }
+
+ // Add the author name field depending on the current user.
+ if ($is_admin) {
+ $form['author']['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Authored by'),
+ '#default_value' => $author,
+ '#maxlength' => 60,
+ '#size' => 30,
+ '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))),
+ '#autocomplete_path' => 'user/autocomplete',
+ );
+ }
+ elseif ($user->uid) {
+ $form['author']['_author'] = array(
+ '#type' => 'item',
+ '#title' => t('Your name'),
+ '#markup' => theme('username', array('account' => $user)),
+ );
+ $form['author']['name'] = array(
+ '#type' => 'value',
+ '#value' => $author,
+ );
+ }
+ else {
+ $form['author']['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Your name'),
+ '#default_value' => $author,
+ '#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
+ '#maxlength' => 60,
+ '#size' => 30,
+ );
+ }
+
+ // Add author e-mail and homepage fields depending on the current user.
+ $form['author']['mail'] = array(
+ '#type' => 'textfield',
+ '#title' => t('E-mail'),
+ '#default_value' => $comment->mail,
+ '#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
+ '#maxlength' => 64,
+ '#size' => 30,
+ '#description' => t('The content of this field is kept private and will not be shown publicly.'),
+ '#access' => $is_admin || (!$user->uid && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
+ );
+ $form['author']['homepage'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Homepage'),
+ '#default_value' => $comment->homepage,
+ '#maxlength' => 255,
+ '#size' => 30,
+ '#access' => $is_admin || (!$user->uid && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
+ );
+
+ // Add administrative comment publishing options.
+ $form['author']['date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Authored on'),
+ '#default_value' => $date,
+ '#maxlength' => 25,
+ '#size' => 20,
+ '#access' => $is_admin,
+ );
+ $form['author']['status'] = array(
+ '#type' => 'radios',
+ '#title' => t('Status'),
+ '#default_value' => $status,
+ '#options' => array(
+ COMMENT_PUBLISHED => t('Published'),
+ COMMENT_NOT_PUBLISHED => t('Not published'),
+ ),
+ '#access' => $is_admin,
+ );
+
+ $form['subject'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Subject'),
+ '#maxlength' => 64,
+ '#default_value' => $comment->subject,
+ '#access' => variable_get('comment_subject_field_' . $node->type, 1) == 1,
+ '#weight' => -1,
+ );
+
+ // Used for conditional validation of author fields.
+ $form['is_anonymous'] = array(
+ '#type' => 'value',
+ '#value' => ($comment->cid ? !$comment->uid : !$user->uid),
+ );
+
+ // Add internal comment properties.
+ foreach (array('cid', 'pid', 'nid', 'language', 'uid') as $key) {
+ $form[$key] = array('#type' => 'value', '#value' => $comment->$key);
+ }
+ $form['node_type'] = array('#type' => 'value', '#value' => 'comment_node_' . $node->type);
+
+ // Only show the save button if comment previews are optional or if we are
+ // already previewing the submission.
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ '#access' => ($comment->cid && user_access('administer comments')) || variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || isset($form_state['comment_preview']),
+ '#weight' => 19,
+ );
+ $form['actions']['preview'] = array(
+ '#type' => 'submit',
+ '#value' => t('Preview'),
+ '#access' => (variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED),
+ '#weight' => 20,
+ '#submit' => array('comment_form_build_preview'),
+ );
+
+ // Attach fields.
+ $comment->node_type = 'comment_node_' . $node->type;
+ $langcode = entity_language('comment', $comment);
+ field_attach_form('comment', $comment, $form, $form_state, $langcode);
+
+ return $form;
+}
+
+/**
+ * Build a preview from submitted form values.
+ */
+function comment_form_build_preview($form, &$form_state) {
+ $comment = comment_form_submit_build_comment($form, $form_state);
+ $form_state['comment_preview'] = comment_preview($comment);
+ $form_state['rebuild'] = TRUE;
+}
+
+/**
+ * Generate a comment preview.
+ */
+function comment_preview($comment) {
+ global $user;
+
+ drupal_set_title(t('Preview comment'), PASS_THROUGH);
+
+ $node = node_load($comment->nid);
+
+ if (!form_get_errors()) {
+ $comment_body = field_get_items('comment', $comment, 'comment_body');
+ $comment->format = $comment_body[0]['format'];
+ // Attach the user and time information.
+ if (!empty($comment->name)) {
+ $account = user_load_by_name($comment->name);
+ }
+ elseif ($user->uid && empty($comment->is_anonymous)) {
+ $account = $user;
+ }
+
+ if (!empty($account->uid)) {
+ $comment->uid = $account->uid;
+ $comment->name = check_plain($account->name);
+ $comment->signature = $account->signature;
+ $comment->signature_format = $account->signature_format;
+ $comment->picture = $account->picture;
+ }
+ elseif (empty($comment->name)) {
+ $comment->name = variable_get('anonymous', t('Anonymous'));
+ }
+
+ $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME;
+ $comment->changed = REQUEST_TIME;
+ $comment->in_preview = TRUE;
+ $comment_build = comment_view($comment, $node);
+ $comment_build['#weight'] = -100;
+
+ $form['comment_preview'] = $comment_build;
+ }
+
+ if ($comment->pid) {
+ $build = array();
+ if ($comments = comment_load_multiple(array($comment->pid), array('status' => COMMENT_PUBLISHED))) {
+ $parent_comment = $comments[$comment->pid];
+ $build = comment_view($parent_comment, $node);
+ }
+ }
+ else {
+ $build = node_view($node);
+ }
+
+ $form['comment_output_below'] = $build;
+ $form['comment_output_below']['#weight'] = 100;
+
+ return $form;
+}
+
+/**
+ * Validate comment form submissions.
+ */
+function comment_form_validate($form, &$form_state) {
+ global $user;
+
+ entity_form_field_validate('comment', $form, $form_state);
+
+ if (!empty($form_state['values']['cid'])) {
+ // Verify the name in case it is being changed from being anonymous.
+ $account = user_load_by_name($form_state['values']['name']);
+ $form_state['values']['uid'] = $account ? $account->uid : 0;
+
+ if ($form_state['values']['date'] && strtotime($form_state['values']['date']) === FALSE) {
+ form_set_error('date', t('You have to specify a valid date.'));
+ }
+ if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) {
+ form_set_error('name', t('You have to specify a valid author.'));
+ }
+ }
+ elseif ($form_state['values']['is_anonymous']) {
+ // Validate anonymous comment author fields (if given). If the (original)
+ // author of this comment was an anonymous user, verify that no registered
+ // user with this name exists.
+ if ($form_state['values']['name']) {
+ $query = db_select('users', 'u');
+ $query->addField('u', 'uid', 'uid');
+ $taken = $query
+ ->condition('name', db_like($form_state['values']['name']), 'LIKE')
+ ->countQuery()
+ ->execute()
+ ->fetchField();
+ if ($taken) {
+ form_set_error('name', t('The name you used belongs to a registered user.'));
+ }
+ }
+ }
+ if ($form_state['values']['mail'] && !valid_email_address($form_state['values']['mail'])) {
+ form_set_error('mail', t('The e-mail address you specified is not valid.'));
+ }
+ if ($form_state['values']['homepage'] && !valid_url($form_state['values']['homepage'], TRUE)) {
+ form_set_error('homepage', t('The URL of your homepage is not valid. Remember that it must be fully qualified, i.e. of the form <code>http://example.com/directory</code>.'));
+ }
+}
+
+/**
+ * Prepare a comment for submission.
+ */
+function comment_submit($comment) {
+ // @todo Legacy support. Remove in Drupal 8.
+ if (is_array($comment)) {
+ $comment += array('subject' => '');
+ $comment = (object) $comment;
+ }
+
+ if (empty($comment->date)) {
+ $comment->date = 'now';
+ }
+ $comment->created = strtotime($comment->date);
+ $comment->changed = REQUEST_TIME;
+
+ // If the comment was posted by a registered user, assign the author's ID.
+ // @todo Too fragile. Should be prepared and stored in comment_form() already.
+ if (!$comment->is_anonymous && !empty($comment->name) && ($account = user_load_by_name($comment->name))) {
+ $comment->uid = $account->uid;
+ }
+ // If the comment was posted by an anonymous user and no author name was
+ // required, use "Anonymous" by default.
+ if ($comment->is_anonymous && (!isset($comment->name) || $comment->name === '')) {
+ $comment->name = variable_get('anonymous', t('Anonymous'));
+ }
+
+ // Validate the comment's subject. If not specified, extract from comment body.
+ if (trim($comment->subject) == '') {
+ // The body may be in any format, so:
+ // 1) Filter it into HTML
+ // 2) Strip out all HTML tags
+ // 3) Convert entities back to plain-text.
+ $field = field_info_field('comment_body');
+ $langcode = field_is_translatable('comment', $field) ? entity_language('comment', $comment) : LANGUAGE_NONE;
+ $comment_body = $comment->comment_body[$langcode][0];
+ if (isset($comment_body['format'])) {
+ $comment_text = check_markup($comment_body['value'], $comment_body['format']);
+ }
+ else {
+ $comment_text = check_plain($comment_body['value']);
+ }
+ $comment->subject = truncate_utf8(trim(decode_entities(strip_tags($comment_text))), 29, TRUE);
+ // Edge cases where the comment body is populated only by HTML tags will
+ // require a default subject.
+ if ($comment->subject == '') {
+ $comment->subject = t('(No subject)');
+ }
+ }
+ return $comment;
+}
+
+/**
+ * Updates the form state's comment entity by processing this submission's values.
+ *
+ * This is the default builder function for the comment form. It is called
+ * during the "Save" and "Preview" submit handlers to retrieve the entity to
+ * save or preview. This function can also be called by a "Next" button of a
+ * wizard to update the form state's entity with the current step's values
+ * before proceeding to the next step.
+ *
+ * @see comment_form()
+ */
+function comment_form_submit_build_comment($form, &$form_state) {
+ $comment = $form_state['comment'];
+ entity_form_submit_build_entity('comment', $comment, $form, $form_state);
+ comment_submit($comment);
+ return $comment;
+}
+
+/**
+ * Process comment form submissions; prepare the comment, store it, and set a redirection target.
+ */
+function comment_form_submit($form, &$form_state) {
+ $node = node_load($form_state['values']['nid']);
+ $comment = comment_form_submit_build_comment($form, $form_state);
+ if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) {
+ // Save the anonymous user information to a cookie for reuse.
+ if (user_is_anonymous()) {
+ user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage'))));
+ }
+
+ comment_save($comment);
+ $form_state['values']['cid'] = $comment->cid;
+
+ // Add an entry to the watchdog log.
+ watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)));
+
+ // Explain the approval queue if necessary.
+ if ($comment->status == COMMENT_NOT_PUBLISHED) {
+ if (!user_access('administer comments')) {
+ drupal_set_message(t('Your comment has been queued for review by site administrators and will be published after approval.'));
+ }
+ }
+ else {
+ drupal_set_message(t('Your comment has been posted.'));
+ }
+ $query = array();
+ // Find the current display page for this comment.
+ $page = comment_get_display_page($comment->cid, $node->type);
+ if ($page > 0) {
+ $query['page'] = $page;
+ }
+ // Redirect to the newly posted comment.
+ $redirect = array('node/' . $node->nid, array('query' => $query, 'fragment' => 'comment-' . $comment->cid));
+ }
+ else {
+ watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject), WATCHDOG_WARNING);
+ drupal_set_message(t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject)), 'error');
+ // Redirect the user to the node they are commenting on.
+ $redirect = 'node/' . $node->nid;
+ }
+ $form_state['redirect'] = $redirect;
+ // Clear the block and page caches so that anonymous users see the comment
+ // they have posted.
+ cache_clear_all();
+}
+
+/**
+ * Process variables for comment.tpl.php.
+ *
+ * @see comment.tpl.php
+ */
+function template_preprocess_comment(&$variables) {
+ $comment = $variables['elements']['#comment'];
+ $node = $variables['elements']['#node'];
+ $variables['comment'] = $comment;
+ $variables['node'] = $node;
+ $variables['author'] = theme('username', array('account' => $comment));
+
+ $variables['created'] = format_date($comment->created);
+
+ // Avoid calling format_date() twice on the same timestamp.
+ if ($comment->changed == $comment->created) {
+ $variables['changed'] = $variables['created'];
+ }
+ else {
+ $variables['changed'] = format_date($comment->changed);
+ }
+
+ $variables['new'] = !empty($comment->new) ? t('new') : '';
+ $variables['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : '';
+ $variables['signature'] = $comment->signature;
+
+ $uri = entity_uri('comment', $comment);
+ $uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
+
+ $variables['title'] = l($comment->subject, $uri['path'], $uri['options']);
+ $variables['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
+ $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created']));
+
+ // Preprocess fields.
+ field_attach_preprocess('comment', $comment, $variables['elements'], $variables);
+
+ // Helpful $content variable for templates.
+ foreach (element_children($variables['elements']) as $key) {
+ $variables['content'][$key] = $variables['elements'][$key];
+ }
+
+ // Set status to a string representation of comment->status.
+ if (isset($comment->in_preview)) {
+ $variables['status'] = 'comment-preview';
+ }
+ else {
+ $variables['status'] = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published';
+ }
+
+ // Gather comment classes.
+ // 'comment-published' class is not needed, it is either 'comment-preview' or
+ // 'comment-unpublished'.
+ if ($variables['status'] != 'comment-published') {
+ $variables['classes_array'][] = $variables['status'];
+ }
+ if ($variables['new']) {
+ $variables['classes_array'][] = 'comment-new';
+ }
+ if (!$comment->uid) {
+ $variables['classes_array'][] = 'comment-by-anonymous';
+ }
+ else {
+ if ($comment->uid == $variables['node']->uid) {
+ $variables['classes_array'][] = 'comment-by-node-author';
+ }
+ if ($comment->uid == $variables['user']->uid) {
+ $variables['classes_array'][] = 'comment-by-viewer';
+ }
+ }
+}
+
+/**
+ * Returns HTML for a "you can't post comments" notice.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - node: The comment node.
+ *
+ * @ingroup themeable
+ */
+function theme_comment_post_forbidden($variables) {
+ $node = $variables['node'];
+ global $user;
+
+ // Since this is expensive to compute, we cache it so that a page with many
+ // comments only has to query the database once for all the links.
+ $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);
+
+ if (!$user->uid) {
+ if (!isset($authenticated_post_comments)) {
+ // We only output a link if we are certain that users will get permission
+ // to post comments by logging in.
+ $comment_roles = user_roles(TRUE, 'post comments');
+ $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
+ }
+
+ if ($authenticated_post_comments) {
+ // We cannot use drupal_get_destination() because these links
+ // sometimes appear on /node and taxonomy listing pages.
+ if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
+ $destination = array('destination' => "comment/reply/$node->nid#comment-form");
+ }
+ else {
+ $destination = array('destination' => "node/$node->nid#comment-form");
+ }
+
+ if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
+ // Users can register themselves.
+ return t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
+ }
+ else {
+ // Only admins can add new users, no public registration.
+ return t('<a href="@login">Log in</a> to post comments', array('@login' => url('user/login', array('query' => $destination))));
+ }
+ }
+ }
+}
+
+/**
+ * Process variables for comment-wrapper.tpl.php.
+ *
+ * @see comment-wrapper.tpl.php
+ */
+function template_preprocess_comment_wrapper(&$variables) {
+ // Provide contextual information.
+ $variables['node'] = $variables['content']['#node'];
+ $variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->type, COMMENT_MODE_THREADED);
+ // The comment form is optional and may not exist.
+ $variables['content'] += array('comment_form' => array());
+}
+
+/**
+ * Return an array of viewing modes for comment listings.
+ *
+ * We can't use a global variable array because the locale system
+ * is not initialized yet when the comment module is loaded.
+ */
+function _comment_get_modes() {
+ return array(
+ COMMENT_MODE_FLAT => t('Flat list'),
+ COMMENT_MODE_THREADED => t('Threaded list')
+ );
+}
+
+/**
+ * Return an array of "comments per page" settings from which the user
+ * can choose.
+ */
+function _comment_per_page() {
+ return drupal_map_assoc(array(10, 30, 50, 70, 90, 150, 200, 250, 300));
+}
+
+/**
+ * Updates the comment statistics for a given node. This should be called any
+ * time a comment is added, deleted, or updated.
+ *
+ * The following fields are contained in the node_comment_statistics table.
+ * - last_comment_timestamp: the timestamp of the last comment for this node or the node create stamp if no comments exist for the node.
+ * - last_comment_name: the name of the anonymous poster for the last comment
+ * - last_comment_uid: the uid of the poster for the last comment for this node or the node authors uid if no comments exists for the node.
+ * - comment_count: the total number of approved/published comments on this node.
+ */
+function _comment_update_node_statistics($nid) {
+ // Allow bulk updates and inserts to temporarily disable the
+ // maintenance of the {node_comment_statistics} table.
+ if (!variable_get('comment_maintain_node_statistics', TRUE)) {
+ return;
+ }
+
+ $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND status = :status', array(
+ ':nid' => $nid,
+ ':status' => COMMENT_PUBLISHED,
+ ))->fetchField();
+
+ if ($count > 0) {
+ // Comments exist.
+ $last_reply = db_query_range('SELECT cid, name, changed, uid FROM {comment} WHERE nid = :nid AND status = :status ORDER BY cid DESC', 0, 1, array(
+ ':nid' => $nid,
+ ':status' => COMMENT_PUBLISHED,
+ ))->fetchObject();
+ db_update('node_comment_statistics')
+ ->fields(array(
+ 'cid' => $last_reply->cid,
+ 'comment_count' => $count,
+ 'last_comment_timestamp' => $last_reply->changed,
+ 'last_comment_name' => $last_reply->uid ? '' : $last_reply->name,
+ 'last_comment_uid' => $last_reply->uid,
+ ))
+ ->condition('nid', $nid)
+ ->execute();
+ }
+ else {
+ // Comments do not exist.
+ $node = db_query('SELECT uid, created FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
+ db_update('node_comment_statistics')
+ ->fields(array(
+ 'cid' => 0,
+ 'comment_count' => 0,
+ 'last_comment_timestamp' => $node->created,
+ 'last_comment_name' => '',
+ 'last_comment_uid' => $node->uid,
+ ))
+ ->condition('nid', $nid)
+ ->execute();
+ }
+}
+
+/**
+ * Generate vancode.
+ *
+ * Consists of a leading character indicating length, followed by N digits
+ * with a numerical value in base 36. Vancodes can be sorted as strings
+ * without messing up numerical order.
+ *
+ * It goes:
+ * 00, 01, 02, ..., 0y, 0z,
+ * 110, 111, ... , 1zy, 1zz,
+ * 2100, 2101, ..., 2zzy, 2zzz,
+ * 31000, 31001, ...
+ */
+function int2vancode($i = 0) {
+ $num = base_convert((int) $i, 10, 36);
+ $length = strlen($num);
+
+ return chr($length + ord('0') - 1) . $num;
+}
+
+/**
+ * Decode vancode back to an integer.
+ */
+function vancode2int($c = '00') {
+ return base_convert(substr($c, 1), 36, 10);
+}
+
+/**
+ * Implements hook_action_info().
+ */
+function comment_action_info() {
+ return array(
+ 'comment_publish_action' => array(
+ 'label' => t('Publish comment'),
+ 'type' => 'comment',
+ 'configurable' => FALSE,
+ 'behavior' => array('changes_property'),
+ 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
+ ),
+ 'comment_unpublish_action' => array(
+ 'label' => t('Unpublish comment'),
+ 'type' => 'comment',
+ 'configurable' => FALSE,
+ 'behavior' => array('changes_property'),
+ 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
+ ),
+ 'comment_unpublish_by_keyword_action' => array(
+ 'label' => t('Unpublish comment containing keyword(s)'),
+ 'type' => 'comment',
+ 'configurable' => TRUE,
+ 'behavior' => array('changes_property'),
+ 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
+ ),
+ 'comment_save_action' => array(
+ 'label' => t('Save comment'),
+ 'type' => 'comment',
+ 'configurable' => FALSE,
+ 'triggers' => array('comment_insert', 'comment_update'),
+ ),
+ );
+}
+
+/**
+ * Publishes a comment.
+ *
+ * @param $comment
+ * An optional comment object.
+ * @param array $context
+ * Array with components:
+ * - 'cid': Comment ID. Required if $comment is not given.
+ *
+ * @ingroup actions
+ */
+function comment_publish_action($comment, $context = array()) {
+ if (isset($comment->subject)) {
+ $subject = $comment->subject;
+ $comment->status = COMMENT_PUBLISHED;
+ }
+ else {
+ $cid = $context['cid'];
+ $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
+ db_update('comment')
+ ->fields(array('status' => COMMENT_PUBLISHED))
+ ->condition('cid', $cid)
+ ->execute();
+ }
+ watchdog('action', 'Published comment %subject.', array('%subject' => $subject));
+}
+
+/**
+ * Unpublishes a comment.
+ *
+ * @param $comment
+ * An optional comment object.
+ * @param array $context
+ * Array with components:
+ * - 'cid': Comment ID. Required if $comment is not given.
+ *
+ * @ingroup actions
+ */
+function comment_unpublish_action($comment, $context = array()) {
+ if (isset($comment->subject)) {
+ $subject = $comment->subject;
+ $comment->status = COMMENT_NOT_PUBLISHED;
+ }
+ else {
+ $cid = $context['cid'];
+ $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
+ db_update('comment')
+ ->fields(array('status' => COMMENT_NOT_PUBLISHED))
+ ->condition('cid', $cid)
+ ->execute();
+ }
+ watchdog('action', 'Unpublished comment %subject.', array('%subject' => $subject));
+}
+
+/**
+ * Unpublishes a comment if it contains certain keywords.
+ *
+ * @param $comment
+ * Comment object to modify.
+ * @param array $context
+ * Array with components:
+ * - 'keywords': Keywords to look for. If the comment contains at least one
+ * of the keywords, it is unpublished.
+ *
+ * @ingroup actions
+ * @see comment_unpublish_by_keyword_action_form()
+ * @see comment_unpublish_by_keyword_action_submit()
+ */
+function comment_unpublish_by_keyword_action($comment, $context) {
+ foreach ($context['keywords'] as $keyword) {
+ $text = drupal_render($comment);
+ if (strpos($text, $keyword) !== FALSE) {
+ $comment->status = COMMENT_NOT_PUBLISHED;
+ watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject));
+ break;
+ }
+ }
+}
+
+/**
+ * Form builder; Prepare a form for blacklisted keywords.
+ *
+ * @ingroup forms
+ * @see comment_unpublish_by_keyword_action()
+ * @see comment_unpublish_by_keyword_action_submit()
+ */
+function comment_unpublish_by_keyword_action_form($context) {
+ $form['keywords'] = array(
+ '#title' => t('Keywords'),
+ '#type' => 'textarea',
+ '#description' => t('The comment will be unpublished if it contains any of the phrases above. Use a case-sensitive, comma-separated list of phrases. Example: funny, bungee jumping, "Company, Inc."'),
+ '#default_value' => isset($context['keywords']) ? drupal_implode_tags($context['keywords']) : '',
+ );
+
+ return $form;
+}
+
+/**
+ * Process comment_unpublish_by_keyword_action_form form submissions.
+ *
+ * @see comment_unpublish_by_keyword_action()
+ */
+function comment_unpublish_by_keyword_action_submit($form, $form_state) {
+ return array('keywords' => drupal_explode_tags($form_state['values']['keywords']));
+}
+
+/**
+ * Saves a comment.
+ *
+ * @ingroup actions
+ */
+function comment_save_action($comment) {
+ comment_save($comment);
+ cache_clear_all();
+ watchdog('action', 'Saved comment %title', array('%title' => $comment->subject));
+}
+
+/**
+ * Implements hook_ranking().
+ */
+function comment_ranking() {
+ return array(
+ 'comments' => array(
+ 'title' => t('Number of comments'),
+ 'join' => array(
+ 'type' => 'LEFT',
+ 'table' => 'node_comment_statistics',
+ 'alias' => 'node_comment_statistics',
+ 'on' => 'node_comment_statistics.nid = i.sid',
+ ),
+ // Inverse law that maps the highest reply count on the site to 1 and 0 to 0.
+ 'score' => '2.0 - 2.0 / (1.0 + node_comment_statistics.comment_count * CAST(:scale AS DECIMAL))',
+ 'arguments' => array(':scale' => variable_get('node_cron_comments_scale', 0)),
+ ),
+ );
+}
+
+/**
+ * Implements hook_rdf_mapping().
+ */
+function comment_rdf_mapping() {
+ return array(
+ array(
+ 'type' => 'comment',
+ 'bundle' => RDF_DEFAULT_BUNDLE,
+ 'mapping' => array(
+ 'rdftype' => array('sioc:Post', 'sioct:Comment'),
+ 'title' => array(
+ 'predicates' => array('dc:title'),
+ ),
+ 'created' => array(
+ 'predicates' => array('dc:date', 'dc:created'),
+ 'datatype' => 'xsd:dateTime',
+ 'callback' => 'date_iso8601',
+ ),
+ 'changed' => array(
+ 'predicates' => array('dc:modified'),
+ 'datatype' => 'xsd:dateTime',
+ 'callback' => 'date_iso8601',
+ ),
+ 'comment_body' => array(
+ 'predicates' => array('content:encoded'),
+ ),
+ 'pid' => array(
+ 'predicates' => array('sioc:reply_of'),
+ 'type' => 'rel',
+ ),
+ 'uid' => array(
+ 'predicates' => array('sioc:has_creator'),
+ 'type' => 'rel',
+ ),
+ 'name' => array(
+ 'predicates' => array('foaf:name'),
+ ),
+ ),
+ ),
+ );
+}
+
+/**
+ * Implements hook_file_download_access().
+ */
+function comment_file_download_access($field, $entity_type, $entity) {
+ if ($entity_type == 'comment') {
+ if (user_access('access comments') && $entity->status == COMMENT_PUBLISHED || user_access('administer comments')) {
+ $node = node_load($entity->nid);
+ return node_access('view', $node);
+ }
+ return FALSE;
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.pages.inc b/kolab.org/www/drupal-7.26/modules/comment/comment.pages.inc
new file mode 100644
index 0000000..482e3f2
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.pages.inc
@@ -0,0 +1,123 @@
+<?php
+
+/**
+ * @file
+ * User page callbacks for the comment module.
+ */
+
+/**
+ * This function is responsible for generating a comment reply form.
+ * There are several cases that have to be handled, including:
+ * - replies to comments
+ * - replies to nodes
+ * - attempts to reply to nodes that can no longer accept comments
+ * - respecting access permissions ('access comments', 'post comments', etc.)
+ *
+ * The node or comment that is being replied to must appear above the comment
+ * form to provide the user context while authoring the comment.
+ *
+ * @param $node
+ * Every comment belongs to a node. This is that node.
+ *
+ * @param $pid
+ * Some comments are replies to other comments. In those cases, $pid is the parent
+ * comment's cid.
+ *
+ * @return array
+ * An associative array containing:
+ * - An array for rendering the node or parent comment.
+ * - comment_node: If the comment is a reply to the node.
+ * - comment_parent: If the comment is a reply to another comment.
+ * - comment_form: The comment form as a renderable array.
+ */
+function comment_reply($node, $pid = NULL) {
+ // Set the breadcrumb trail.
+ drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/' . $node->nid)));
+ $op = isset($_POST['op']) ? $_POST['op'] : '';
+ $build = array();
+
+ // The user is previewing a comment prior to submitting it.
+ if ($op == t('Preview')) {
+ if (user_access('post comments')) {
+ $build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", (object) array('pid' => $pid, 'nid' => $node->nid));
+ }
+ else {
+ drupal_set_message(t('You are not authorized to post comments.'), 'error');
+ drupal_goto("node/$node->nid");
+ }
+ }
+ else {
+ // $pid indicates that this is a reply to a comment.
+ if ($pid) {
+ if (user_access('access comments')) {
+ // Load the comment whose cid = $pid
+ $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
+ ':cid' => $pid,
+ ':status' => COMMENT_PUBLISHED,
+ ))->fetchObject();
+ if ($comment) {
+ // If that comment exists, make sure that the current comment and the
+ // parent comment both belong to the same parent node.
+ if ($comment->nid != $node->nid) {
+ // Attempting to reply to a comment not belonging to the current nid.
+ drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
+ drupal_goto("node/$node->nid");
+ }
+ // Display the parent comment
+ $comment->node_type = 'comment_node_' . $node->type;
+ field_attach_load('comment', array($comment->cid => $comment));
+ $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
+ $build['comment_parent'] = comment_view($comment, $node);
+ }
+ else {
+ drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
+ drupal_goto("node/$node->nid");
+ }
+ }
+ else {
+ drupal_set_message(t('You are not authorized to view comments.'), 'error');
+ drupal_goto("node/$node->nid");
+ }
+ }
+ // This is the case where the comment is in response to a node. Display the node.
+ elseif (user_access('access content')) {
+ $build['comment_node'] = node_view($node);
+ }
+
+ // Should we show the reply box?
+ if ($node->comment != COMMENT_NODE_OPEN) {
+ drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
+ drupal_goto("node/$node->nid");
+ }
+ elseif (user_access('post comments')) {
+ $edit = array('nid' => $node->nid, 'pid' => $pid);
+ $build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", (object) $edit);
+ }
+ else {
+ drupal_set_message(t('You are not authorized to post comments.'), 'error');
+ drupal_goto("node/$node->nid");
+ }
+ }
+
+ return $build;
+}
+
+/**
+ * Menu callback; publish specified comment.
+ *
+ * @param $cid
+ * A comment identifier.
+ */
+function comment_approve($cid) {
+ if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], "comment/$cid/approve")) {
+ return MENU_ACCESS_DENIED;
+ }
+ if ($comment = comment_load($cid)) {
+ $comment->status = COMMENT_PUBLISHED;
+ comment_save($comment);
+
+ drupal_set_message(t('Comment approved.'));
+ drupal_goto('node/' . $comment->nid);
+ }
+ return MENU_NOT_FOUND;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.test b/kolab.org/www/drupal-7.26/modules/comment/comment.test
new file mode 100644
index 0000000..9e69ba6
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.test
@@ -0,0 +1,2225 @@
+<?php
+
+/**
+ * @file
+ * Tests for comment.module.
+ */
+
+class CommentHelperCase extends DrupalWebTestCase {
+ protected $admin_user;
+ protected $web_user;
+ protected $node;
+
+ function setUp() {
+ parent::setUp('comment', 'search');
+ // Create users and test node.
+ $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks'));
+ $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments'));
+ $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
+ }
+
+ /**
+ * Post comment.
+ *
+ * @param $node
+ * Node to post comment on.
+ * @param $comment
+ * Comment body.
+ * @param $subject
+ * Comment subject.
+ * @param $contact
+ * Set to NULL for no contact info, TRUE to ignore success checking, and
+ * array of values to set contact info.
+ */
+ function postComment($node, $comment, $subject = '', $contact = NULL) {
+ $langcode = LANGUAGE_NONE;
+ $edit = array();
+ $edit['comment_body[' . $langcode . '][0][value]'] = $comment;
+
+ $preview_mode = variable_get('comment_preview_article', DRUPAL_OPTIONAL);
+ $subject_mode = variable_get('comment_subject_field_article', 1);
+
+ // Must get the page before we test for fields.
+ if ($node !== NULL) {
+ $this->drupalGet('comment/reply/' . $node->nid);
+ }
+
+ if ($subject_mode == TRUE) {
+ $edit['subject'] = $subject;
+ }
+ else {
+ $this->assertNoFieldByName('subject', '', 'Subject field not found.');
+ }
+
+ if ($contact !== NULL && is_array($contact)) {
+ $edit += $contact;
+ }
+ switch ($preview_mode) {
+ case DRUPAL_REQUIRED:
+ // Preview required so no save button should be found.
+ $this->assertNoFieldByName('op', t('Save'), 'Save button not found.');
+ $this->drupalPost(NULL, $edit, t('Preview'));
+ // Don't break here so that we can test post-preview field presence and
+ // function below.
+ case DRUPAL_OPTIONAL:
+ $this->assertFieldByName('op', t('Preview'), 'Preview button found.');
+ $this->assertFieldByName('op', t('Save'), 'Save button found.');
+ $this->drupalPost(NULL, $edit, t('Save'));
+ break;
+
+ case DRUPAL_DISABLED:
+ $this->assertNoFieldByName('op', t('Preview'), 'Preview button not found.');
+ $this->assertFieldByName('op', t('Save'), 'Save button found.');
+ $this->drupalPost(NULL, $edit, t('Save'));
+ break;
+ }
+ $match = array();
+ // Get comment ID
+ preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
+
+ // Get comment.
+ if ($contact !== TRUE) { // If true then attempting to find error message.
+ if ($subject) {
+ $this->assertText($subject, 'Comment subject posted.');
+ }
+ $this->assertText($comment, 'Comment body posted.');
+ $this->assertTrue((!empty($match) && !empty($match[1])), 'Comment id found.');
+ }
+
+ if (isset($match[1])) {
+ return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment);
+ }
+ }
+
+ /**
+ * Checks current page for specified comment.
+ *
+ * @param object $comment Comment object.
+ * @param boolean $reply The comment is a reply to another comment.
+ * @return boolean Comment found.
+ */
+ function commentExists($comment, $reply = FALSE) {
+ if ($comment && is_object($comment)) {
+ $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
+ $regex .= '<a id="comment-' . $comment->id . '"(.*?)'; // Comment anchor.
+ $regex .= '<div(.*?)'; // Begin in comment div.
+ $regex .= $comment->subject . '(.*?)'; // Match subject.
+ $regex .= $comment->comment . '(.*?)'; // Match comment.
+ $regex .= '/s';
+
+ return (boolean)preg_match($regex, $this->drupalGetContent());
+ }
+ else {
+ return FALSE;
+ }
+ }
+
+ /**
+ * Delete comment.
+ *
+ * @param object $comment
+ * Comment to delete.
+ */
+ function deleteComment($comment) {
+ $this->drupalPost('comment/' . $comment->id . '/delete', array(), t('Delete'));
+ $this->assertText(t('The comment and all its replies have been deleted.'), 'Comment deleted.');
+ }
+
+ /**
+ * Set comment subject setting.
+ *
+ * @param boolean $enabled
+ * Subject value.
+ */
+ function setCommentSubject($enabled) {
+ $this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.');
+ }
+
+ /**
+ * Set comment preview setting.
+ *
+ * @param int $mode
+ * Preview value.
+ */
+ function setCommentPreview($mode) {
+ switch ($mode) {
+ case DRUPAL_DISABLED:
+ $mode_text = 'disabled';
+ break;
+
+ case DRUPAL_OPTIONAL:
+ $mode_text = 'optional';
+ break;
+
+ case DRUPAL_REQUIRED:
+ $mode_text = 'required';
+ break;
+ }
+ $this->setCommentSettings('comment_preview', $mode, format_string('Comment preview @mode_text.', array('@mode_text' => $mode_text)));
+ }
+
+ /**
+ * Set comment form location setting.
+ *
+ * @param boolean $enabled
+ * Form value.
+ */
+ function setCommentForm($enabled) {
+ $this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
+ }
+
+ /**
+ * Set comment anonymous level setting.
+ *
+ * @param integer $level
+ * Anonymous level.
+ */
+ function setCommentAnonymous($level) {
+ $this->setCommentSettings('comment_anonymous', $level, format_string('Anonymous commenting set to level @level.', array('@level' => $level)));
+ }
+
+ /**
+ * Set the default number of comments per page.
+ *
+ * @param integer $comments
+ * Comments per page value.
+ */
+ function setCommentsPerPage($number) {
+ $this->setCommentSettings('comment_default_per_page', $number, format_string('Number of comments per page set to @number.', array('@number' => $number)));
+ }
+
+ /**
+ * Set comment setting for article content type.
+ *
+ * @param string $name
+ * Name of variable.
+ * @param string $value
+ * Value of variable.
+ * @param string $message
+ * Status message to display.
+ */
+ function setCommentSettings($name, $value, $message) {
+ variable_set($name . '_article', $value);
+ // Display status message.
+ $this->pass($message);
+ }
+
+ /**
+ * Check for contact info.
+ *
+ * @return boolean Contact info is available.
+ */
+ function commentContactInfoAvailable() {
+ return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent());
+ }
+
+ /**
+ * Perform the specified operation on the specified comment.
+ *
+ * @param object $comment
+ * Comment to perform operation on.
+ * @param string $operation
+ * Operation to perform.
+ * @param boolean $aproval
+ * Operation is found on approval page.
+ */
+ function performCommentOperation($comment, $operation, $approval = FALSE) {
+ $edit = array();
+ $edit['operation'] = $operation;
+ $edit['comments[' . $comment->id . ']'] = TRUE;
+ $this->drupalPost('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update'));
+
+ if ($operation == 'delete') {
+ $this->drupalPost(NULL, array(), t('Delete comments'));
+ $this->assertRaw(format_plural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation @operation was performed on comment.', array('@operation' => $operation)));
+ }
+ else {
+ $this->assertText(t('The update has been performed.'), format_string('Operation @operation was performed on comment.', array('@operation' => $operation)));
+ }
+ }
+
+ /**
+ * Get the comment ID for an unapproved comment.
+ *
+ * @param string $subject
+ * Comment subject to find.
+ * @return integer
+ * Comment id.
+ */
+ function getUnapprovedComment($subject) {
+ $this->drupalGet('admin/content/comment/approval');
+ preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->drupalGetContent(), $match);
+
+ return $match[2];
+ }
+}
+
+class CommentInterfaceTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment interface',
+ 'description' => 'Test comment user interfaces.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test comment interface.
+ */
+ function testCommentInterface() {
+ $langcode = LANGUAGE_NONE;
+ // Set comments to have subject and preview disabled.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(DRUPAL_DISABLED);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(FALSE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
+ $this->drupalLogout();
+
+ // Post comment #1 without subject or preview.
+ $this->drupalLogin($this->web_user);
+ $comment_text = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text);
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment found.');
+
+ // Set comments to have subject and preview to required.
+ $this->drupalLogout();
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentPreview(DRUPAL_REQUIRED);
+ $this->drupalLogout();
+
+ // Create comment #2 that allows subject and requires preview.
+ $this->drupalLogin($this->web_user);
+ $subject_text = $this->randomName();
+ $comment_text = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment found.');
+
+ // Check comment display.
+ $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id);
+ $this->assertText($subject_text, 'Individual comment subject found.');
+ $this->assertText($comment_text, 'Individual comment body found.');
+
+ // Set comments to have subject and preview to optional.
+ $this->drupalLogout();
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentPreview(DRUPAL_OPTIONAL);
+
+ // Test changing the comment author to "Anonymous".
+ $this->drupalGet('comment/' . $comment->id . '/edit');
+ $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => ''));
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue(empty($comment_loaded->name) && $comment_loaded->uid == 0, 'Comment author successfully changed to anonymous.');
+
+ // Test changing the comment author to an unverified user.
+ $random_name = $this->randomName();
+ $this->drupalGet('comment/' . $comment->id . '/edit');
+ $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $random_name));
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertText($random_name . ' (' . t('not verified') . ')', 'Comment author successfully changed to an unverified user.');
+
+ // Test changing the comment author to a verified user.
+ $this->drupalGet('comment/' . $comment->id . '/edit');
+ $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $this->web_user->name));
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, 'Comment author successfully changed to a registered user.');
+
+ $this->drupalLogout();
+
+ // Reply to comment #2 creating comment #3 with optional preview and no
+ // subject though field enabled.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
+ $this->assertText($subject_text, 'Individual comment-reply subject found.');
+ $this->assertText($comment_text, 'Individual comment-reply body found.');
+ $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
+ $this->assertEqual($comment->id, $reply_loaded->pid, 'Pid of a reply to a comment is set correctly.');
+ $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.00/', $reply_loaded->thread, 'Thread of reply grows correctly.');
+
+ // Second reply to comment #3 creating comment #4.
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
+ $this->assertText($subject_text, 'Individual comment-reply subject found.');
+ $this->assertText($comment_text, 'Individual comment-reply body found.');
+ $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.');
+ $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.01/', $reply_loaded->thread, 'Thread of second reply grows correctly.');
+
+ // Edit reply.
+ $this->drupalGet('comment/' . $reply->id . '/edit');
+ $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Modified reply found.');
+
+ // Correct link count
+ $this->drupalGet('node');
+ $this->assertRaw('4 comments', 'Link to the 4 comments exist.');
+
+ // Confirm a new comment is posted to the correct page.
+ $this->setCommentsPerPage(2);
+ $comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
+ $this->assertTrue($this->commentExists($comment_new_page), 'Page one exists. %s');
+ $this->drupalGet('node/' . $this->node->nid, array('query' => array('page' => 1)));
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Page two exists. %s');
+ $this->setCommentsPerPage(50);
+
+ // Attempt to post to node with comments disabled.
+ $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_HIDDEN));
+ $this->assertTrue($this->node, 'Article node created.');
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $this->assertText('This discussion is closed', 'Posting to node with comments disabled');
+ $this->assertNoField('edit-comment', 'Comment body field found.');
+
+ // Attempt to post to node with read-only comments.
+ $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_CLOSED));
+ $this->assertTrue($this->node, 'Article node created.');
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $this->assertText('This discussion is closed', 'Posting to node with comments read-only');
+ $this->assertNoField('edit-comment', 'Comment body field found.');
+
+ // Attempt to post to node with comments enabled (check field names etc).
+ $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
+ $this->assertTrue($this->node, 'Article node created.');
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $this->assertNoText('This discussion is closed', 'Posting to node with comments enabled');
+ $this->assertField('edit-comment-body-' . $langcode . '-0-value', 'Comment body field found.');
+
+ // Delete comment and make sure that reply is also removed.
+ $this->drupalLogout();
+ $this->drupalLogin($this->admin_user);
+ $this->deleteComment($comment);
+ $this->deleteComment($comment_new_page);
+
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertFalse($this->commentExists($comment), 'Comment not found.');
+ $this->assertFalse($this->commentExists($reply, TRUE), 'Reply not found.');
+
+ // Enabled comment form on node page.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentForm(TRUE);
+ $this->drupalLogout();
+
+ // Submit comment through node form.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('node/' . $this->node->nid);
+ $form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+ $this->assertTrue($this->commentExists($form_comment), 'Form comment found.');
+
+ // Disable comment form on node page.
+ $this->drupalLogout();
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentForm(FALSE);
+ }
+
+ /**
+ * Tests new comment marker.
+ */
+ public function testCommentNewCommentsIndicator() {
+ // Test if the right links are displayed when no comment is present for the
+ // node.
+ $this->drupalLogin($this->admin_user);
+ $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
+ $this->drupalGet('node');
+ $this->assertNoLink(t('@count comments', array('@count' => 0)));
+ $this->assertNoLink(t('@count new comments', array('@count' => 0)));
+ $this->assertLink(t('Read more'));
+ $count = $this->xpath('//div[@id=:id]/div[@class=:class]/ul/li', array(':id' => 'node-' . $this->node->nid, ':class' => 'link-wrapper'));
+ $this->assertTrue(count($count) == 1, 'One child found');
+
+ // Create a new comment. This helper function may be run with different
+ // comment settings so use comment_save() to avoid complex setup.
+ $comment = (object) array(
+ 'cid' => NULL,
+ 'nid' => $this->node->nid,
+ 'node_type' => $this->node->type,
+ 'pid' => 0,
+ 'uid' => $this->loggedInUser->uid,
+ 'status' => COMMENT_PUBLISHED,
+ 'subject' => $this->randomName(),
+ 'hostname' => ip_address(),
+ 'language' => LANGUAGE_NONE,
+ 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
+ );
+ comment_save($comment);
+ $this->drupalLogout();
+
+ // Log in with 'web user' and check comment links.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('node');
+ $this->assertLink(t('1 new comment'));
+ $this->clickLink(t('1 new comment'));
+ $this->assertRaw('<a id="new"></a>', 'Found "new" marker.');
+ $this->assertTrue($this->xpath('//a[@id=:new]/following-sibling::a[1][@id=:comment_id]', array(':new' => 'new', ':comment_id' => 'comment-1')), 'The "new" anchor is positioned at the right comment.');
+
+ // Test if "new comment" link is correctly removed.
+ $this->drupalGet('node');
+ $this->assertLink(t('1 comment'));
+ $this->assertLink(t('Read more'));
+ $this->assertNoLink(t('1 new comment'));
+ $this->assertNoLink(t('@count new comments', array('@count' => 0)));
+ $count = $this->xpath('//div[@id=:id]/div[@class=:class]/ul/li', array(':id' => 'node-' . $this->node->nid, ':class' => 'link-wrapper'));
+ $this->assertTrue(count($count) == 2, print_r($count, TRUE));
+ }
+
+ /**
+ * Tests CSS classes on comments.
+ */
+ function testCommentClasses() {
+ // Create all permutations for comments, users, and nodes.
+ $parameters = array(
+ 'node_uid' => array(0, $this->web_user->uid),
+ 'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid),
+ 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
+ 'user' => array('anonymous', 'authenticated', 'admin'),
+ );
+ $permutations = $this->generatePermutations($parameters);
+
+ foreach ($permutations as $case) {
+ // Create a new node.
+ $node = $this->drupalCreateNode(array('type' => 'article', 'uid' => $case['node_uid']));
+
+ // Add a comment.
+ $comment = (object) array(
+ 'cid' => NULL,
+ 'nid' => $node->nid,
+ 'pid' => 0,
+ 'uid' => $case['comment_uid'],
+ 'status' => $case['comment_status'],
+ 'subject' => $this->randomName(),
+ 'language' => LANGUAGE_NONE,
+ 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
+ );
+ comment_save($comment);
+
+ // Adjust the current/viewing user.
+ switch ($case['user']) {
+ case 'anonymous':
+ $this->drupalLogout();
+ $case['user_uid'] = 0;
+ break;
+
+ case 'authenticated':
+ $this->drupalLogin($this->web_user);
+ $case['user_uid'] = $this->web_user->uid;
+ break;
+
+ case 'admin':
+ $this->drupalLogin($this->admin_user);
+ $case['user_uid'] = $this->admin_user->uid;
+ break;
+ }
+ // Request the node with the comment.
+ $this->drupalGet('node/' . $node->nid);
+
+ // Verify classes if the comment is visible for the current user.
+ if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+ // Verify the comment-by-anonymous class.
+ $comments = $this->xpath('//*[contains(@class, "comment-by-anonymous")]');
+ if ($case['comment_uid'] == 0) {
+ $this->assertTrue(count($comments) == 1, 'comment-by-anonymous class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-by-anonymous class not found.');
+ }
+
+ // Verify the comment-by-node-author class.
+ $comments = $this->xpath('//*[contains(@class, "comment-by-node-author")]');
+ if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['node_uid']) {
+ $this->assertTrue(count($comments) == 1, 'comment-by-node-author class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-by-node-author class not found.');
+ }
+
+ // Verify the comment-by-viewer class.
+ $comments = $this->xpath('//*[contains(@class, "comment-by-viewer")]');
+ if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['user_uid']) {
+ $this->assertTrue(count($comments) == 1, 'comment-by-viewer class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-by-viewer class not found.');
+ }
+ }
+
+ // Verify the comment-unpublished class.
+ $comments = $this->xpath('//*[contains(@class, "comment-unpublished")]');
+ if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') {
+ $this->assertTrue(count($comments) == 1, 'comment-unpublished class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-unpublished class not found.');
+ }
+
+ // Verify the comment-new class.
+ if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+ $comments = $this->xpath('//*[contains(@class, "comment-new")]');
+ if ($case['user'] != 'anonymous') {
+ $this->assertTrue(count($comments) == 1, 'comment-new class found.');
+
+ // Request the node again. The comment-new class should disappear.
+ $this->drupalGet('node/' . $node->nid);
+ $comments = $this->xpath('//*[contains(@class, "comment-new")]');
+ $this->assertFalse(count($comments), 'comment-new class not found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-new class not found.');
+ }
+ }
+ }
+ }
+
+ /**
+ * Tests the node comment statistics.
+ */
+ function testCommentNodeCommentStatistics() {
+ $langcode = LANGUAGE_NONE;
+ // Set comments to have subject and preview disabled.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(DRUPAL_DISABLED);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(FALSE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
+ $this->drupalLogout();
+
+ // Creates a second user to post comments.
+ $this->web_user2 = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments'));
+
+ // Checks the initial values of node comment statistics with no comment.
+ $node = node_load($this->node->nid);
+ $this->assertEqual($node->last_comment_timestamp, $this->node->created, 'The initial value of node last_comment_timestamp is the node created date.');
+ $this->assertEqual($node->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.');
+ $this->assertEqual($node->last_comment_uid, $this->web_user->uid, 'The initial value of node last_comment_uid is the node uid.');
+ $this->assertEqual($node->comment_count, 0, 'The initial value of node comment_count is zero.');
+
+ // Post comment #1 as web_user2.
+ $this->drupalLogin($this->web_user2);
+ $comment_text = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text);
+ $comment_loaded = comment_load($comment->id);
+
+ // Checks the new values of node comment statistics with comment #1.
+ // The node needs to be reloaded with a node_load_multiple cache reset.
+ $node = node_load($this->node->nid, NULL, TRUE);
+ $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is NULL.');
+ $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is the comment #1 uid.');
+ $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is 1.');
+
+ // Prepare for anonymous comment submission (comment approval enabled).
+ variable_set('user_register', USER_REGISTER_VISITORS);
+ $this->drupalLogin($this->admin_user);
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => TRUE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => FALSE,
+ ));
+ // Ensure that the poster can leave some contact info.
+ $this->setCommentAnonymous('1');
+ $this->drupalLogout();
+
+ // Post comment #2 as anonymous (comment approval enabled).
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', TRUE);
+ $comment_unpublished_loaded = comment_load($anonymous_comment->id);
+
+ // Checks the new values of node comment statistics with comment #2 and
+ // ensure they haven't changed since the comment has not been moderated.
+ // The node needs to be reloaded with a node_load_multiple cache reset.
+ $node = node_load($this->node->nid, NULL, TRUE);
+ $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.');
+ $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is still the comment #1 uid.');
+ $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is still 1.');
+
+ // Prepare for anonymous comment submission (no approval required).
+ $this->drupalLogin($this->admin_user);
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => TRUE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => TRUE,
+ ));
+ $this->drupalLogout();
+
+ // Post comment #3 as anonymous.
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', array('name' => $this->randomName()));
+ $comment_loaded = comment_load($anonymous_comment->id);
+
+ // Checks the new values of node comment statistics with comment #3.
+ // The node needs to be reloaded with a node_load_multiple cache reset.
+ $node = node_load($this->node->nid, NULL, TRUE);
+ $this->assertEqual($node->last_comment_name, $comment_loaded->name, 'The value of node last_comment_name is the name of the anonymous user.');
+ $this->assertEqual($node->last_comment_uid, 0, 'The value of node last_comment_uid is zero.');
+ $this->assertEqual($node->comment_count, 2, 'The value of node comment_count is 2.');
+ }
+
+ /**
+ * Tests comment links.
+ *
+ * The output of comment links depends on various environment conditions:
+ * - Various Comment module configuration settings, user registration
+ * settings, and user access permissions.
+ * - Whether the user is authenticated or not, and whether any comments exist.
+ *
+ * To account for all possible cases, this test creates permutations of all
+ * possible conditions and tests the expected appearance of comment links in
+ * each environment.
+ */
+ function testCommentLinks() {
+ // Bartik theme alters comment links, so use a different theme.
+ theme_enable(array('garland'));
+ variable_set('theme_default', 'garland');
+
+ // Remove additional user permissions from $this->web_user added by setUp(),
+ // since this test is limited to anonymous and authenticated roles only.
+ user_role_delete(key($this->web_user->roles));
+
+ // Matrix of possible environmental conditions and configuration settings.
+ // See setEnvironment() for details.
+ $conditions = array(
+ 'authenticated' => array(FALSE, TRUE),
+ 'comment count' => array(FALSE, TRUE),
+ 'access comments' => array(0, 1),
+ 'post comments' => array(0, 1),
+ 'form' => array(COMMENT_FORM_BELOW, COMMENT_FORM_SEPARATE_PAGE),
+ // USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL is irrelevant for this
+ // test; there is only a difference between open and closed registration.
+ 'user_register' => array(USER_REGISTER_VISITORS, USER_REGISTER_ADMINISTRATORS_ONLY),
+ // @todo Complete test coverage for:
+ //'comments' => array(COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, COMMENT_NODE_HIDDEN),
+ //// COMMENT_ANONYMOUS_MUST_CONTACT is irrelevant for this test.
+ //'contact ' => array(COMMENT_ANONYMOUS_MAY_CONTACT, COMMENT_ANONYMOUS_MAYNOT_CONTACT),
+ );
+
+ $environments = $this->generatePermutations($conditions);
+ foreach ($environments as $info) {
+ $this->assertCommentLinks($info);
+ }
+ }
+
+ /**
+ * Re-configures the environment, module settings, and user permissions.
+ *
+ * @param $info
+ * An associative array describing the environment to setup:
+ * - Environment conditions:
+ * - authenticated: Boolean whether to test with $this->web_user or
+ * anonymous.
+ * - comment count: Boolean whether to test with a new/unread comment on
+ * $this->node or no comments.
+ * - Configuration settings:
+ * - form: COMMENT_FORM_BELOW or COMMENT_FORM_SEPARATE_PAGE.
+ * - user_register: USER_REGISTER_ADMINISTRATORS_ONLY or
+ * USER_REGISTER_VISITORS.
+ * - contact: COMMENT_ANONYMOUS_MAY_CONTACT or
+ * COMMENT_ANONYMOUS_MAYNOT_CONTACT.
+ * - comments: COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, or
+ * COMMENT_NODE_HIDDEN.
+ * - User permissions:
+ * These are granted or revoked for the user, according to the
+ * 'authenticated' flag above. Pass 0 or 1 as parameter values. See
+ * user_role_change_permissions().
+ * - access comments
+ * - post comments
+ * - skip comment approval
+ * - edit own comments
+ */
+ function setEnvironment(array $info) {
+ static $current;
+
+ // Apply defaults to initial environment.
+ if (!isset($current)) {
+ $current = array(
+ 'authenticated' => FALSE,
+ 'comment count' => FALSE,
+ 'form' => COMMENT_FORM_BELOW,
+ 'user_register' => USER_REGISTER_VISITORS,
+ 'contact' => COMMENT_ANONYMOUS_MAY_CONTACT,
+ 'comments' => COMMENT_NODE_OPEN,
+ 'access comments' => 0,
+ 'post comments' => 0,
+ // Enabled by default, because it's irrelevant for this test.
+ 'skip comment approval' => 1,
+ 'edit own comments' => 0,
+ );
+ }
+ // Complete new environment with current environment.
+ $info = array_merge($current, $info);
+
+ // Change environment conditions.
+ if ($current['authenticated'] != $info['authenticated']) {
+ if ($this->loggedInUser) {
+ $this->drupalLogout();
+ }
+ else {
+ $this->drupalLogin($this->web_user);
+ }
+ }
+ if ($current['comment count'] != $info['comment count']) {
+ if ($info['comment count']) {
+ // Create a comment via CRUD API functionality, since
+ // $this->postComment() relies on actual user permissions.
+ $comment = (object) array(
+ 'cid' => NULL,
+ 'nid' => $this->node->nid,
+ 'node_type' => $this->node->type,
+ 'pid' => 0,
+ 'uid' => 0,
+ 'status' => COMMENT_PUBLISHED,
+ 'subject' => $this->randomName(),
+ 'hostname' => ip_address(),
+ 'language' => LANGUAGE_NONE,
+ 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
+ );
+ comment_save($comment);
+ $this->comment = $comment;
+
+ // comment_num_new() relies on node_last_viewed(), so ensure that no one
+ // has seen the node of this comment.
+ db_delete('history')->condition('nid', $this->node->nid)->execute();
+ }
+ else {
+ $cids = db_query("SELECT cid FROM {comment}")->fetchCol();
+ comment_delete_multiple($cids);
+ unset($this->comment);
+ }
+ }
+
+ // Change comment settings.
+ variable_set('comment_form_location_' . $this->node->type, $info['form']);
+ variable_set('comment_anonymous_' . $this->node->type, $info['contact']);
+ if ($this->node->comment != $info['comments']) {
+ $this->node->comment = $info['comments'];
+ node_save($this->node);
+ }
+
+ // Change user settings.
+ variable_set('user_register', $info['user_register']);
+
+ // Change user permissions.
+ $rid = ($this->loggedInUser ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID);
+ $perms = array_intersect_key($info, array('access comments' => 1, 'post comments' => 1, 'skip comment approval' => 1, 'edit own comments' => 1));
+ user_role_change_permissions($rid, $perms);
+
+ // Output verbose debugging information.
+ // @see DrupalTestCase::error()
+ $t_form = array(
+ COMMENT_FORM_BELOW => 'below',
+ COMMENT_FORM_SEPARATE_PAGE => 'separate page',
+ );
+ $t_contact = array(
+ COMMENT_ANONYMOUS_MAY_CONTACT => 'optional',
+ COMMENT_ANONYMOUS_MAYNOT_CONTACT => 'disabled',
+ COMMENT_ANONYMOUS_MUST_CONTACT => 'required',
+ );
+ $t_comments = array(
+ COMMENT_NODE_OPEN => 'open',
+ COMMENT_NODE_CLOSED => 'closed',
+ COMMENT_NODE_HIDDEN => 'hidden',
+ );
+ $verbose = $info;
+ $verbose['form'] = $t_form[$info['form']];
+ $verbose['contact'] = $t_contact[$info['contact']];
+ $verbose['comments'] = $t_comments[$info['comments']];
+ $message = t('Changed environment:<pre>@verbose</pre>', array(
+ '@verbose' => var_export($verbose, TRUE),
+ ));
+ $this->assert('debug', $message, 'Debug');
+
+ // Update current environment.
+ $current = $info;
+
+ return $info;
+ }
+
+ /**
+ * Asserts that comment links appear according to the passed environment setup.
+ *
+ * @param $info
+ * An associative array describing the environment to pass to
+ * setEnvironment().
+ */
+ function assertCommentLinks(array $info) {
+ $info = $this->setEnvironment($info);
+
+ $nid = $this->node->nid;
+
+ foreach (array('', "node/$nid") as $path) {
+ $this->drupalGet($path);
+
+ // User is allowed to view comments.
+ if ($info['access comments']) {
+ if ($path == '') {
+ // In teaser view, a link containing the comment count is always
+ // expected.
+ if ($info['comment count']) {
+ $this->assertLink(t('1 comment'));
+
+ // For logged in users, a link containing the amount of new/unread
+ // comments is expected.
+ // See important note about comment_num_new() below.
+ if ($this->loggedInUser && isset($this->comment) && !isset($this->comment->seen)) {
+ $this->assertLink(t('1 new comment'));
+ $this->comment->seen = TRUE;
+ }
+ }
+ }
+ }
+ else {
+ $this->assertNoLink(t('1 comment'));
+ $this->assertNoLink(t('1 new comment'));
+ }
+ // comment_num_new() is based on node views, so comments are marked as
+ // read when a node is viewed, regardless of whether we have access to
+ // comments.
+ if ($path == "node/$nid" && $this->loggedInUser && isset($this->comment)) {
+ $this->comment->seen = TRUE;
+ }
+
+ // User is not allowed to post comments.
+ if (!$info['post comments']) {
+ $this->assertNoLink('Add new comment');
+
+ // Anonymous users should see a note to log in or register in case
+ // authenticated users are allowed to post comments.
+ // @see theme_comment_post_forbidden()
+ if (!$this->loggedInUser) {
+ if (user_access('post comments', $this->web_user)) {
+ // The note depends on whether users are actually able to register.
+ if ($info['user_register']) {
+ $this->assertText('Log in or register to post comments');
+ }
+ else {
+ $this->assertText('Log in to post comments');
+ }
+ }
+ else {
+ $this->assertNoText('Log in or register to post comments');
+ $this->assertNoText('Log in to post comments');
+ }
+ }
+ }
+ // User is allowed to post comments.
+ else {
+ $this->assertNoText('Log in or register to post comments');
+
+ // "Add new comment" is always expected, except when there are no
+ // comments or if the user cannot see them.
+ if ($path == "node/$nid" && $info['form'] == COMMENT_FORM_BELOW && (!$info['comment count'] || !$info['access comments'])) {
+ $this->assertNoLink('Add new comment');
+ }
+ else {
+ $this->assertLink('Add new comment');
+ }
+
+ // Also verify that the comment form appears according to the configured
+ // location.
+ if ($path == "node/$nid") {
+ $elements = $this->xpath('//form[@id=:id]', array(':id' => 'comment-form'));
+ if ($info['form'] == COMMENT_FORM_BELOW) {
+ $this->assertTrue(count($elements), 'Comment form found below.');
+ }
+ else {
+ $this->assertFalse(count($elements), 'Comment form not found below.');
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Test previewing comments.
+ */
+class CommentPreviewTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment preview',
+ 'description' => 'Test comment preview.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test comment preview.
+ */
+ function testCommentPreview() {
+ $langcode = LANGUAGE_NONE;
+
+ // As admin user, configure comment settings.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(DRUPAL_OPTIONAL);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
+ $this->drupalLogout();
+
+ // Login as web user and add a signature and a user picture.
+ $this->drupalLogin($this->web_user);
+ variable_set('user_signatures', 1);
+ variable_set('user_pictures', 1);
+ $test_signature = $this->randomName();
+ $edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature. '</a>';
+ $edit['signature[format]'] = 'filtered_html';
+ $image = current($this->drupalGetTestFiles('image'));
+ $edit['files[picture_upload]'] = drupal_realpath($image->uri);
+ $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
+
+ // As the web user, fill in the comment form and preview the comment.
+ $edit = array();
+ $edit['subject'] = $this->randomName(8);
+ $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
+ $this->drupalPost('node/' . $this->node->nid, $edit, t('Preview'));
+
+ // Check that the preview is displaying the title and body.
+ $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
+ $this->assertText($edit['subject'], 'Subject displayed.');
+ $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], 'Comment displayed.');
+
+ // Check that the title and body fields are displayed with the correct values.
+ $this->assertFieldByName('subject', $edit['subject'], 'Subject field displayed.');
+ $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
+
+ // Check that the signature is displaying with the correct text format.
+ $this->assertLink($test_signature);
+
+ // Check that the user picture is displayed.
+ $this->assertFieldByXPath("//div[contains(@class, 'comment-preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
+ }
+
+ /**
+ * Test comment edit, preview, and save.
+ */
+ function testCommentEditPreviewSave() {
+ $langcode = LANGUAGE_NONE;
+ $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval'));
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(DRUPAL_OPTIONAL);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
+
+ $edit = array();
+ $edit['subject'] = $this->randomName(8);
+ $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
+ $edit['name'] = $web_user->name;
+ $edit['date'] = '2008-03-02 17:23 +0300';
+ $raw_date = strtotime($edit['date']);
+ $expected_text_date = format_date($raw_date);
+ $expected_form_date = format_date($raw_date, 'custom', 'Y-m-d H:i O');
+ $comment = $this->postComment($this->node, $edit['subject'], $edit['comment_body[' . $langcode . '][0][value]'], TRUE);
+ $this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Preview'));
+
+ // Check that the preview is displaying the subject, comment, author and date correctly.
+ $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
+ $this->assertText($edit['subject'], 'Subject displayed.');
+ $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], 'Comment displayed.');
+ $this->assertText($edit['name'], 'Author displayed.');
+ $this->assertText($expected_text_date, 'Date displayed.');
+
+ // Check that the subject, comment, author and date fields are displayed with the correct values.
+ $this->assertFieldByName('subject', $edit['subject'], 'Subject field displayed.');
+ $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
+ $this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
+ $this->assertFieldByName('date', $edit['date'], 'Date field displayed.');
+
+ // Check that saving a comment produces a success message.
+ $this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Save'));
+ $this->assertText(t('Your comment has been posted.'), 'Comment posted.');
+
+ // Check that the comment fields are correct after loading the saved comment.
+ $this->drupalGet('comment/' . $comment->id . '/edit');
+ $this->assertFieldByName('subject', $edit['subject'], 'Subject field displayed.');
+ $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
+ $this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
+ $this->assertFieldByName('date', $expected_form_date, 'Date field displayed.');
+
+ // Submit the form using the displayed values.
+ $displayed = array();
+ $displayed['subject'] = (string) current($this->xpath("//input[@id='edit-subject']/@value"));
+ $displayed['comment_body[' . $langcode . '][0][value]'] = (string) current($this->xpath("//textarea[@id='edit-comment-body-" . $langcode . "-0-value']"));
+ $displayed['name'] = (string) current($this->xpath("//input[@id='edit-name']/@value"));
+ $displayed['date'] = (string) current($this->xpath("//input[@id='edit-date']/@value"));
+ $this->drupalPost('comment/' . $comment->id . '/edit', $displayed, t('Save'));
+
+ // Check that the saved comment is still correct.
+ $comment_loaded = comment_load($comment->id);
+ $this->assertEqual($comment_loaded->subject, $edit['subject'], 'Subject loaded.');
+ $this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], 'Comment body loaded.');
+ $this->assertEqual($comment_loaded->name, $edit['name'], 'Name loaded.');
+ $this->assertEqual($comment_loaded->created, $raw_date, 'Date loaded.');
+
+ }
+
+}
+
+class CommentAnonymous extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Anonymous comments',
+ 'description' => 'Test anonymous comments.',
+ 'group' => 'Comment',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+ variable_set('user_register', USER_REGISTER_VISITORS);
+ }
+
+ /**
+ * Test anonymous comment functionality.
+ */
+ function testAnonymous() {
+ $this->drupalLogin($this->admin_user);
+ // Enabled anonymous user comments.
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => TRUE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => TRUE,
+ ));
+ $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
+ $this->drupalLogout();
+
+ // Post anonymous comment without contact info.
+ $anonymous_comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
+ $this->assertTrue($this->commentExists($anonymous_comment1), 'Anonymous comment without contact info found.');
+
+ // Allow contact info.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentAnonymous('1');
+
+ // Attempt to edit anonymous comment.
+ $this->drupalGet('comment/' . $anonymous_comment1->id . '/edit');
+ $edited_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
+ $this->assertTrue($this->commentExists($edited_comment, FALSE), 'Modified reply found.');
+ $this->drupalLogout();
+
+ // Post anonymous comment with contact info (optional).
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.');
+
+ $anonymous_comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
+ $this->assertTrue($this->commentExists($anonymous_comment2), 'Anonymous comment with contact info (optional) found.');
+
+ // Ensure anonymous users cannot post in the name of registered users.
+ $langcode = LANGUAGE_NONE;
+ $edit = array(
+ 'name' => $this->admin_user->name,
+ 'mail' => $this->randomName() . '@example.com',
+ 'subject' => $this->randomName(),
+ "comment_body[$langcode][0][value]" => $this->randomName(),
+ );
+ $this->drupalPost('comment/reply/' . $this->node->nid, $edit, t('Save'));
+ $this->assertText(t('The name you used belongs to a registered user.'));
+
+ // Require contact info.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentAnonymous('2');
+ $this->drupalLogout();
+
+ // Try to post comment with contact info (required).
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.');
+
+ $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
+ // Name should have 'Anonymous' for value by default.
+ $this->assertText(t('E-mail field is required.'), 'E-mail required.');
+ $this->assertFalse($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) not found.');
+
+ // Post comment with contact info (required).
+ $author_name = $this->randomName();
+ $author_mail = $this->randomName() . '@example.com';
+ $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), array('name' => $author_name, 'mail' => $author_mail));
+ $this->assertTrue($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) found.');
+
+ // Make sure the user data appears correctly when editing the comment.
+ $this->drupalLogin($this->admin_user);
+ $this->drupalGet('comment/' . $anonymous_comment3->id . '/edit');
+ $this->assertRaw($author_name, "The anonymous user's name is correct when editing the comment.");
+ $this->assertRaw($author_mail, "The anonymous user's e-mail address is correct when editing the comment.");
+
+ // Unpublish comment.
+ $this->performCommentOperation($anonymous_comment3, 'unpublish');
+
+ $this->drupalGet('admin/content/comment/approval');
+ $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was unpublished.');
+
+ // Publish comment.
+ $this->performCommentOperation($anonymous_comment3, 'publish', TRUE);
+
+ $this->drupalGet('admin/content/comment');
+ $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was published.');
+
+ // Delete comment.
+ $this->performCommentOperation($anonymous_comment3, 'delete');
+
+ $this->drupalGet('admin/content/comment');
+ $this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was deleted.');
+ $this->drupalLogout();
+
+ // Reset.
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => FALSE,
+ 'post comments' => FALSE,
+ 'skip comment approval' => FALSE,
+ ));
+
+ // Attempt to view comments while disallowed.
+ // NOTE: if authenticated user has permission to post comments, then a
+ // "Login or register to post comments" type link may be shown.
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
+ $this->assertNoLink('Add new comment', 'Link to add comment was found.');
+
+ // Attempt to view node-comment form while disallowed.
+ $this->drupalGet('comment/reply/' . $this->node->nid);
+ $this->assertText('You are not authorized to post comments', 'Error attempting to post comment.');
+ $this->assertNoFieldByName('subject', '', 'Subject field not found.');
+ $this->assertNoFieldByName("comment_body[$langcode][0][value]", '', 'Comment field not found.');
+
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => TRUE,
+ 'post comments' => FALSE,
+ 'skip comment approval' => FALSE,
+ ));
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
+ $this->assertLink('Log in', 1, 'Link to log in was found.');
+ $this->assertLink('register', 1, 'Link to register was found.');
+
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => FALSE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => TRUE,
+ ));
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
+ $this->assertFieldByName('subject', '', 'Subject field found.');
+ $this->assertFieldByName("comment_body[$langcode][0][value]", '', 'Comment field found.');
+
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $anonymous_comment3->id);
+ $this->assertText('You are not authorized to view comments', 'Error attempting to post reply.');
+ $this->assertNoText($author_name, 'Comment not displayed.');
+ }
+}
+
+/**
+ * Verify pagination of comments.
+ */
+class CommentPagerTest extends CommentHelperCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment paging settings',
+ 'description' => 'Test paging of comments and their settings.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Confirm comment paging works correctly with flat and threaded comments.
+ */
+ function testCommentPaging() {
+ $this->drupalLogin($this->admin_user);
+
+ // Set comment variables.
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentPreview(DRUPAL_DISABLED);
+
+ // Create a node and three comments.
+ $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $comments = array();
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.');
+
+ // Set comments to one per page so that we are able to test paging without
+ // needing to insert large numbers of comments.
+ $this->setCommentsPerPage(1);
+
+ // Check the first page of the node, and confirm the correct comments are
+ // shown.
+ $this->drupalGet('node/' . $node->nid);
+ $this->assertRaw(t('next'), 'Paging links found.');
+ $this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page 1.');
+ $this->assertFalse($this->commentExists($comments[1]), 'Comment 2 does not appear on page 1.');
+ $this->assertFalse($this->commentExists($comments[2]), 'Comment 3 does not appear on page 1.');
+
+ // Check the second page.
+ $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 1)));
+ $this->assertTrue($this->commentExists($comments[1]), 'Comment 2 appears on page 2.');
+ $this->assertFalse($this->commentExists($comments[0]), 'Comment 1 does not appear on page 2.');
+ $this->assertFalse($this->commentExists($comments[2]), 'Comment 3 does not appear on page 2.');
+
+ // Check the third page.
+ $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 2)));
+ $this->assertTrue($this->commentExists($comments[2]), 'Comment 3 appears on page 3.');
+ $this->assertFalse($this->commentExists($comments[0]), 'Comment 1 does not appear on page 3.');
+ $this->assertFalse($this->commentExists($comments[1]), 'Comment 2 does not appear on page 3.');
+
+ // Post a reply to the oldest comment and test again.
+ $replies = array();
+ $oldest_comment = reset($comments);
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $oldest_comment->id);
+ $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ $this->setCommentsPerPage(2);
+ // We are still in flat view - the replies should not be on the first page,
+ // even though they are replies to the oldest comment.
+ $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
+ $this->assertFalse($this->commentExists($reply, TRUE), 'In flat mode, reply does not appear on page 1.');
+
+ // If we switch to threaded mode, the replies on the oldest comment
+ // should be bumped to the first page and comment 6 should be bumped
+ // to the second page.
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.');
+ $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
+ $this->assertTrue($this->commentExists($reply, TRUE), 'In threaded mode, reply appears on page 1.');
+ $this->assertFalse($this->commentExists($comments[1]), 'In threaded mode, comment 2 has been bumped off of page 1.');
+
+ // If (# replies > # comments per page) in threaded expanded view,
+ // the overage should be bumped.
+ $reply2 = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+ $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
+ $this->assertFalse($this->commentExists($reply2, TRUE), 'In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.');
+
+ $this->drupalLogout();
+ }
+
+ /**
+ * Test comment ordering and threading.
+ */
+ function testCommentOrderingThreading() {
+ $this->drupalLogin($this->admin_user);
+
+ // Set comment variables.
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentPreview(DRUPAL_DISABLED);
+
+ // Display all the comments on the same page.
+ $this->setCommentsPerPage(1000);
+
+ // Create a node and three comments.
+ $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $comments = array();
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the second comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the first comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the last comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the second comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[3]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // At this point, the comment tree is:
+ // - 0
+ // - 4
+ // - 1
+ // - 3
+ // - 6
+ // - 2
+ // - 5
+
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.');
+
+ $expected_order = array(
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ );
+ $this->drupalGet('node/' . $node->nid);
+ $this->assertCommentOrder($comments, $expected_order);
+
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.');
+
+ $expected_order = array(
+ 0,
+ 4,
+ 1,
+ 3,
+ 6,
+ 2,
+ 5,
+ );
+ $this->drupalGet('node/' . $node->nid);
+ $this->assertCommentOrder($comments, $expected_order);
+ }
+
+ /**
+ * Helper function: assert that the comments are displayed in the correct order.
+ *
+ * @param $comments
+ * And array of comments.
+ * @param $expected_order
+ * An array of keys from $comments describing the expected order.
+ */
+ function assertCommentOrder(array $comments, array $expected_order) {
+ $expected_cids = array();
+
+ // First, rekey the expected order by cid.
+ foreach ($expected_order as $key) {
+ $expected_cids[] = $comments[$key]->id;
+ }
+
+ $comment_anchors = $this->xpath('//a[starts-with(@id,"comment-")]');
+ $result_order = array();
+ foreach ($comment_anchors as $anchor) {
+ $result_order[] = substr($anchor['id'], 8);
+ }
+
+ return $this->assertIdentical($expected_cids, $result_order, format_string('Comment order: expected @expected, returned @returned.', array('@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order))));
+ }
+
+ /**
+ * Test comment_new_page_count().
+ */
+ function testCommentNewPageIndicator() {
+ $this->drupalLogin($this->admin_user);
+
+ // Set comment variables.
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentPreview(DRUPAL_DISABLED);
+
+ // Set comments to one per page so that we are able to test paging without
+ // needing to insert large numbers of comments.
+ $this->setCommentsPerPage(1);
+
+ // Create a node and three comments.
+ $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $comments = array();
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the second comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the first comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the last comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // At this point, the comment tree is:
+ // - 0
+ // - 4
+ // - 1
+ // - 3
+ // - 2
+ // - 5
+
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.');
+
+ $expected_pages = array(
+ 1 => 5, // Page of comment 5
+ 2 => 4, // Page of comment 4
+ 3 => 3, // Page of comment 3
+ 4 => 2, // Page of comment 2
+ 5 => 1, // Page of comment 1
+ 6 => 0, // Page of comment 0
+ );
+
+ $node = node_load($node->nid);
+ foreach ($expected_pages as $new_replies => $expected_page) {
+ $returned = comment_new_page_count($node->comment_count, $new_replies, $node);
+ $returned_page = is_array($returned) ? $returned['page'] : 0;
+ $this->assertIdentical($expected_page, $returned_page, format_string('Flat mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
+ }
+
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.');
+
+ $expected_pages = array(
+ 1 => 5, // Page of comment 5
+ 2 => 1, // Page of comment 4
+ 3 => 1, // Page of comment 4
+ 4 => 1, // Page of comment 4
+ 5 => 1, // Page of comment 4
+ 6 => 0, // Page of comment 0
+ );
+
+ $node = node_load($node->nid);
+ foreach ($expected_pages as $new_replies => $expected_page) {
+ $returned = comment_new_page_count($node->comment_count, $new_replies, $node);
+ $returned_page = is_array($returned) ? $returned['page'] : 0;
+ $this->assertEqual($expected_page, $returned_page, format_string('Threaded mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
+ }
+ }
+}
+
+/**
+ * Tests comments with node access.
+ *
+ * See http://drupal.org/node/886752 -- verify there is no PostgreSQL error when
+ * viewing a node with threaded comments (a comment and a reply), if a node
+ * access module is in use.
+ */
+class CommentNodeAccessTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment node access',
+ 'description' => 'Test comment viewing with node access.',
+ 'group' => 'Comment',
+ );
+ }
+
+ function setUp() {
+ DrupalWebTestCase::setUp('comment', 'search', 'node_access_test');
+ node_access_rebuild();
+
+ // Create users and test node.
+ $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks'));
+ $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments', 'node test view'));
+ $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
+ }
+
+ /**
+ * Test that threaded comments can be viewed.
+ */
+ function testThreadedCommentView() {
+ $langcode = LANGUAGE_NONE;
+ // Set comments to have subject required and preview disabled.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(DRUPAL_DISABLED);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
+ $this->drupalLogout();
+
+ // Post comment.
+ $this->drupalLogin($this->web_user);
+ $comment_text = $this->randomName();
+ $comment_subject = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text, $comment_subject);
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment found.');
+
+ // Check comment display.
+ $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id);
+ $this->assertText($comment_subject, 'Individual comment subject found.');
+ $this->assertText($comment_text, 'Individual comment body found.');
+
+ // Reply to comment, creating second comment.
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
+ $reply_text = $this->randomName();
+ $reply_subject = $this->randomName();
+ $reply = $this->postComment(NULL, $reply_text, $reply_subject, TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
+
+ // Go to the node page and verify comment and reply are visible.
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertText($comment_text);
+ $this->assertText($comment_subject);
+ $this->assertText($reply_text);
+ $this->assertText($reply_subject);
+ }
+}
+
+class CommentApprovalTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment approval',
+ 'description' => 'Test comment approval functionality.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test comment approval functionality through admin/content/comment.
+ */
+ function testApprovalAdminInterface() {
+ // Set anonymous comments to require approval.
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => TRUE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => FALSE,
+ ));
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
+
+ // Test that the comments page loads correctly when there are no comments
+ $this->drupalGet('admin/content/comment');
+ $this->assertText(t('No comments available.'));
+
+ $this->drupalLogout();
+
+ // Post anonymous comment without contact info.
+ $subject = $this->randomName();
+ $body = $this->randomName();
+ $this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
+ $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
+
+ // Get unapproved comment id.
+ $this->drupalLogin($this->admin_user);
+ $anonymous_comment4 = $this->getUnapprovedComment($subject);
+ $anonymous_comment4 = (object) array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body);
+ $this->drupalLogout();
+
+ $this->assertFalse($this->commentExists($anonymous_comment4), 'Anonymous comment was not published.');
+
+ // Approve comment.
+ $this->drupalLogin($this->admin_user);
+ $this->performCommentOperation($anonymous_comment4, 'publish', TRUE);
+ $this->drupalLogout();
+
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.');
+
+ // Post 2 anonymous comments without contact info.
+ $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
+ $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
+
+ // Publish multiple comments in one operation.
+ $this->drupalLogin($this->admin_user);
+ $this->drupalGet('admin/content/comment/approval');
+ $this->assertText(t('Unapproved comments (@count)', array('@count' => 2)), 'Two unapproved comments waiting for approval.');
+ $edit = array(
+ "comments[{$comments[0]->id}]" => 1,
+ "comments[{$comments[1]->id}]" => 1,
+ );
+ $this->drupalPost(NULL, $edit, t('Update'));
+ $this->assertText(t('Unapproved comments (@count)', array('@count' => 0)), 'All comments were approved.');
+
+ // Delete multiple comments in one operation.
+ $edit = array(
+ 'operation' => 'delete',
+ "comments[{$comments[0]->id}]" => 1,
+ "comments[{$comments[1]->id}]" => 1,
+ "comments[{$anonymous_comment4->id}]" => 1,
+ );
+ $this->drupalPost(NULL, $edit, t('Update'));
+ $this->assertText(t('Are you sure you want to delete these comments and all their children?'), 'Confirmation required.');
+ $this->drupalPost(NULL, $edit, t('Delete comments'));
+ $this->assertText(t('No comments available.'), 'All comments were deleted.');
+ }
+
+ /**
+ * Test comment approval functionality through node interface.
+ */
+ function testApprovalNodeInterface() {
+ // Set anonymous comments to require approval.
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => TRUE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => FALSE,
+ ));
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
+ $this->drupalLogout();
+
+ // Post anonymous comment without contact info.
+ $subject = $this->randomName();
+ $body = $this->randomName();
+ $this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
+ $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
+
+ // Get unapproved comment id.
+ $this->drupalLogin($this->admin_user);
+ $anonymous_comment4 = $this->getUnapprovedComment($subject);
+ $anonymous_comment4 = (object) array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body);
+ $this->drupalLogout();
+
+ $this->assertFalse($this->commentExists($anonymous_comment4), 'Anonymous comment was not published.');
+
+ // Approve comment.
+ $this->drupalLogin($this->admin_user);
+ $this->drupalGet('comment/1/approve');
+ $this->assertResponse(403, 'Forged comment approval was denied.');
+ $this->drupalGet('comment/1/approve', array('query' => array('token' => 'forged')));
+ $this->assertResponse(403, 'Forged comment approval was denied.');
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->clickLink(t('approve'));
+ $this->drupalLogout();
+
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.');
+ }
+}
+
+/**
+ * Functional tests for the comment module blocks.
+ */
+class CommentBlockFunctionalTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment blocks',
+ 'description' => 'Test comment block functionality.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test the recent comments block.
+ */
+ function testRecentCommentBlock() {
+ $this->drupalLogin($this->admin_user);
+
+ // Set the block to a region to confirm block is available.
+ $edit = array(
+ 'blocks[comment_recent][region]' => 'sidebar_first',
+ );
+ $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
+ $this->assertText(t('The block settings have been updated.'), 'Block saved to first sidebar region.');
+
+ // Set block title and variables.
+ $block = array(
+ 'title' => $this->randomName(),
+ 'comment_block_count' => 2,
+ );
+ $this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), 'Block saved.');
+
+ // Add some test comments, one without a subject.
+ $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
+ $comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
+ $comment3 = $this->postComment($this->node, $this->randomName());
+
+ // Test that a user without the 'access comments' permission cannot see the
+ // block.
+ $this->drupalLogout();
+ user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
+ $this->drupalGet('');
+ $this->assertNoText($block['title'], 'Block was not found.');
+ user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
+
+ // Test that a user with the 'access comments' permission can see the
+ // block.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('');
+ $this->assertText($block['title'], 'Block was found.');
+
+ // Test the only the 2 latest comments are shown and in the proper order.
+ $this->assertNoText($comment1->subject, 'Comment not found in block.');
+ $this->assertText($comment2->subject, 'Comment found in block.');
+ $this->assertText($comment3->comment, 'Comment found in block.');
+ $this->assertTrue(strpos($this->drupalGetContent(), $comment3->comment) < strpos($this->drupalGetContent(), $comment2->subject), 'Comments were ordered correctly in block.');
+
+ // Set the number of recent comments to show to 10.
+ $this->drupalLogout();
+ $this->drupalLogin($this->admin_user);
+ $block = array(
+ 'comment_block_count' => 10,
+ );
+ $this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), 'Block saved.');
+
+ // Post an additional comment.
+ $comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName());
+
+ // Test that all four comments are shown.
+ $this->assertText($comment1->subject, 'Comment found in block.');
+ $this->assertText($comment2->subject, 'Comment found in block.');
+ $this->assertText($comment3->comment, 'Comment found in block.');
+ $this->assertText($comment4->subject, 'Comment found in block.');
+
+ // Test that links to comments work when comments are across pages.
+ $this->setCommentsPerPage(1);
+ $this->drupalGet('');
+ $this->clickLink($comment1->subject);
+ $this->assertText($comment1->subject, 'Comment link goes to correct page.');
+ $this->drupalGet('');
+ $this->clickLink($comment2->subject);
+ $this->assertText($comment2->subject, 'Comment link goes to correct page.');
+ $this->clickLink($comment4->subject);
+ $this->assertText($comment4->subject, 'Comment link goes to correct page.');
+ // Check that when viewing a comment page from a link to the comment, that
+ // rel="canonical" is added to the head of the document.
+ $this->assertRaw('<link rel="canonical"', 'Canonical URL was found in the HTML head');
+ }
+}
+
+/**
+ * Unit tests for comment module integration with RSS feeds.
+ */
+class CommentRSSUnitTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment RSS',
+ 'description' => 'Test comments as part of an RSS feed.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test comments as part of an RSS feed.
+ */
+ function testCommentRSS() {
+ // Find comment in RSS feed.
+ $this->drupalLogin($this->web_user);
+ $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
+ $this->drupalGet('rss.xml');
+ $raw = '<comments>' . url('node/' . $this->node->nid, array('fragment' => 'comments', 'absolute' => TRUE)) . '</comments>';
+ $this->assertRaw($raw, 'Comments as part of RSS feed.');
+
+ // Hide comments from RSS feed and check presence.
+ $this->node->comment = COMMENT_NODE_HIDDEN;
+ node_save($this->node);
+ $this->drupalGet('rss.xml');
+ $this->assertNoRaw($raw, 'Hidden comments is not a part of RSS feed.');
+ }
+}
+
+
+/**
+ * Test to make sure comment content is rebuilt.
+ */
+class CommentContentRebuild extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment Rebuild',
+ 'description' => 'Test to make sure the comment content is rebuilt.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test to ensure that the comment's content array is rebuilt for every
+ * call to comment_view().
+ */
+ function testCommentRebuild() {
+ // Update the comment settings so preview isn't required.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentPreview(DRUPAL_OPTIONAL);
+ $this->drupalLogout();
+
+ // Log in as the web user and add the comment.
+ $this->drupalLogin($this->web_user);
+ $subject_text = $this->randomName();
+ $comment_text = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment found.');
+
+ // Add the property to the content array and then see if it still exists on build.
+ $comment_loaded->content['test_property'] = array('#value' => $this->randomString());
+ $built_content = comment_view($comment_loaded, $this->node);
+
+ // This means that the content was rebuilt as the added test property no longer exists.
+ $this->assertFalse(isset($built_content['test_property']), 'Comment content was emptied before being built.');
+ }
+}
+
+/**
+ * Test comment token replacement in strings.
+ */
+class CommentTokenReplaceTestCase extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment token replacement',
+ 'description' => 'Generates text using placeholders for dummy content to check comment token replacement.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Creates a comment, then tests the tokens generated from it.
+ */
+ function testCommentTokenReplacement() {
+ global $language;
+ $url_options = array(
+ 'absolute' => TRUE,
+ 'language' => $language,
+ );
+
+ $this->drupalLogin($this->admin_user);
+
+ // Set comment variables.
+ $this->setCommentSubject(TRUE);
+
+ // Create a node and a comment.
+ $node = $this->drupalCreateNode(array('type' => 'article'));
+ $parent_comment = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
+
+ // Post a reply to the comment.
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $parent_comment->id);
+ $child_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
+ $comment = comment_load($child_comment->id);
+ $comment->homepage = 'http://example.org/';
+
+ // Add HTML to ensure that sanitation of some fields tested directly.
+ $comment->subject = '<blink>Blinking Comment</blink>';
+ $instance = field_info_instance('comment', 'body', 'comment_body');
+
+ // Generate and test sanitized tokens.
+ $tests = array();
+ $tests['[comment:cid]'] = $comment->cid;
+ $tests['[comment:hostname]'] = check_plain($comment->hostname);
+ $tests['[comment:name]'] = filter_xss($comment->name);
+ $tests['[comment:mail]'] = check_plain($this->admin_user->mail);
+ $tests['[comment:homepage]'] = check_url($comment->homepage);
+ $tests['[comment:title]'] = filter_xss($comment->subject);
+ $tests['[comment:body]'] = _text_sanitize($instance, LANGUAGE_NONE, $comment->comment_body[LANGUAGE_NONE][0], 'value');
+ $tests['[comment:url]'] = url('comment/' . $comment->cid, $url_options + array('fragment' => 'comment-' . $comment->cid));
+ $tests['[comment:edit-url]'] = url('comment/' . $comment->cid . '/edit', $url_options);
+ $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created, 2, $language->language);
+ $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed, 2, $language->language);
+ $tests['[comment:parent:cid]'] = $comment->pid;
+ $tests['[comment:parent:title]'] = check_plain($parent_comment->subject);
+ $tests['[comment:node:nid]'] = $comment->nid;
+ $tests['[comment:node:title]'] = check_plain($node->title);
+ $tests['[comment:author:uid]'] = $comment->uid;
+ $tests['[comment:author:name]'] = check_plain($this->admin_user->name);
+
+ // Test to make sure that we generated something for each token.
+ $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('comment' => $comment), array('language' => $language));
+ $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input)));
+ }
+
+ // Generate and test unsanitized tokens.
+ $tests['[comment:hostname]'] = $comment->hostname;
+ $tests['[comment:name]'] = $comment->name;
+ $tests['[comment:mail]'] = $this->admin_user->mail;
+ $tests['[comment:homepage]'] = $comment->homepage;
+ $tests['[comment:title]'] = $comment->subject;
+ $tests['[comment:body]'] = $comment->comment_body[LANGUAGE_NONE][0]['value'];
+ $tests['[comment:parent:title]'] = $parent_comment->subject;
+ $tests['[comment:node:title]'] = $node->title;
+ $tests['[comment:author:name]'] = $this->admin_user->name;
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('comment' => $comment), array('language' => $language, 'sanitize' => FALSE));
+ $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input)));
+ }
+
+ // Load node so comment_count gets computed.
+ $node = node_load($node->nid);
+
+ // Generate comment tokens for the node (it has 2 comments, both new).
+ $tests = array();
+ $tests['[node:comment-count]'] = 2;
+ $tests['[node:comment-count-new]'] = 2;
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('node' => $node), array('language' => $language));
+ $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
+ }
+ }
+}
+
+/**
+ * Test actions provided by the comment module.
+ */
+class CommentActionsTestCase extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment actions',
+ 'description' => 'Test actions provided by the comment module.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test comment publish and unpublish actions.
+ */
+ function testCommentPublishUnpublishActions() {
+ $this->drupalLogin($this->web_user);
+ $comment_text = $this->randomName();
+ $subject = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text, $subject);
+ $comment = comment_load($comment->id);
+
+ // Unpublish a comment (direct form: doesn't actually save the comment).
+ comment_unpublish_action($comment);
+ $this->assertEqual($comment->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished');
+ $this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), 'Found watchdog message');
+ $this->clearWatchdog();
+
+ // Unpublish a comment (indirect form: modify the comment in the database).
+ comment_unpublish_action(NULL, array('cid' => $comment->cid));
+ $this->assertEqual(comment_load($comment->cid)->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished');
+ $this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), 'Found watchdog message');
+
+ // Publish a comment (direct form: doesn't actually save the comment).
+ comment_publish_action($comment);
+ $this->assertEqual($comment->status, COMMENT_PUBLISHED, 'Comment was published');
+ $this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), 'Found watchdog message');
+ $this->clearWatchdog();
+
+ // Publish a comment (indirect form: modify the comment in the database).
+ comment_publish_action(NULL, array('cid' => $comment->cid));
+ $this->assertEqual(comment_load($comment->cid)->status, COMMENT_PUBLISHED, 'Comment was published');
+ $this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), 'Found watchdog message');
+ $this->clearWatchdog();
+ }
+
+ /**
+ * Verify that a watchdog message has been entered.
+ *
+ * @param $watchdog_message
+ * The watchdog message.
+ * @param $variables
+ * The array of variables passed to watchdog().
+ * @param $message
+ * The assertion message.
+ */
+ function assertWatchdogMessage($watchdog_message, $variables, $message) {
+ $status = (bool) db_query_range("SELECT 1 FROM {watchdog} WHERE message = :message AND variables = :variables", 0, 1, array(':message' => $watchdog_message, ':variables' => serialize($variables)))->fetchField();
+ return $this->assert($status, format_string('@message', array('@message' => $message)));
+ }
+
+ /**
+ * Helper function: clear the watchdog.
+ */
+ function clearWatchdog() {
+ db_truncate('watchdog')->execute();
+ }
+}
+
+/**
+ * Test fields on comments.
+ */
+class CommentFieldsTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment fields',
+ 'description' => 'Tests fields on comments.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Tests that the default 'comment_body' field is correctly added.
+ */
+ function testCommentDefaultFields() {
+ // Do not make assumptions on default node types created by the test
+ // installation profile, and create our own.
+ $this->drupalCreateContentType(array('type' => 'test_node_type'));
+
+ // Check that the 'comment_body' field is present on all comment bundles.
+ $instances = field_info_instances('comment');
+ foreach (node_type_get_types() as $type_name => $info) {
+ $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
+
+ // Delete the instance along the way.
+ field_delete_instance($instances['comment_node_' . $type_name]['comment_body']);
+ }
+
+ // Check that the 'comment_body' field is deleted.
+ $field = field_info_field('comment_body');
+ $this->assertTrue(empty($field), 'The comment_body field was deleted');
+
+ // Create a new content type.
+ $type_name = 'test_node_type_2';
+ $this->drupalCreateContentType(array('type' => $type_name));
+
+ // Check that the 'comment_body' field exists and has an instance on the
+ // new comment bundle.
+ $field = field_info_field('comment_body');
+ $this->assertTrue($field, 'The comment_body field exists');
+ $instances = field_info_instances('comment');
+ $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
+ }
+
+ /**
+ * Test that comment module works when enabled after a content module.
+ */
+ function testCommentEnable() {
+ // Create a user to do module administration.
+ $this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
+ $this->drupalLogin($this->admin_user);
+
+ // Disable the comment module.
+ $edit = array();
+ $edit['modules[Core][comment][enable]'] = FALSE;
+ $this->drupalPost('admin/modules', $edit, t('Save configuration'));
+ $this->resetAll();
+ $this->assertFalse(module_exists('comment'), 'Comment module disabled.');
+
+ // Enable core content type modules (blog, book, and poll).
+ $edit = array();
+ $edit['modules[Core][blog][enable]'] = 'blog';
+ $edit['modules[Core][book][enable]'] = 'book';
+ $edit['modules[Core][poll][enable]'] = 'poll';
+ $this->drupalPost('admin/modules', $edit, t('Save configuration'));
+ $this->resetAll();
+
+ // Now enable the comment module.
+ $edit = array();
+ $edit['modules[Core][comment][enable]'] = 'comment';
+ $this->drupalPost('admin/modules', $edit, t('Save configuration'));
+ $this->resetAll();
+ $this->assertTrue(module_exists('comment'), 'Comment module enabled.');
+
+ // Create nodes of each type.
+ $blog_node = $this->drupalCreateNode(array('type' => 'blog'));
+ $book_node = $this->drupalCreateNode(array('type' => 'book'));
+ $poll_node = $this->drupalCreateNode(array('type' => 'poll', 'active' => 1, 'runtime' => 0, 'choice' => array(array('chtext' => ''))));
+
+ $this->drupalLogout();
+
+ // Try to post a comment on each node. A failure will be triggered if the
+ // comment body is missing on one of these forms, due to postComment()
+ // asserting that the body is actually posted correctly.
+ $this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'post comments', 'skip comment approval'));
+ $this->drupalLogin($this->web_user);
+ $this->postComment($blog_node, $this->randomName(), $this->randomName());
+ $this->postComment($book_node, $this->randomName(), $this->randomName());
+ $this->postComment($poll_node, $this->randomName(), $this->randomName());
+ }
+
+ /**
+ * Test that comment module works correctly with plain text format.
+ */
+ function testCommentFormat() {
+ // Disable text processing for comments.
+ $this->drupalLogin($this->admin_user);
+ $edit = array('instance[settings][text_processing]' => 0);
+ $this->drupalPost('admin/structure/types/manage/article/comment/fields/comment_body', $edit, t('Save settings'));
+
+ // Post a comment without an explicit subject.
+ $this->drupalLogin($this->web_user);
+ $edit = array('comment_body[und][0][value]' => $this->randomName(8));
+ $this->drupalPost('node/' . $this->node->nid, $edit, t('Save'));
+ }
+}
+
+/**
+ * Tests comment threading.
+ */
+class CommentThreadingTestCase extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment Threading',
+ 'description' => 'Test to make sure the comment number increments properly.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Tests the comment threading.
+ */
+ function testCommentThreading() {
+ $langcode = LANGUAGE_NONE;
+ // Set comments to have a subject with preview disabled.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(DRUPAL_DISABLED);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
+ $this->drupalLogout();
+
+ // Create a node.
+ $this->drupalLogin($this->web_user);
+ $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
+
+ // Post comment #1.
+ $this->drupalLogin($this->web_user);
+ $subject_text = $this->randomName();
+ $comment_text = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment #1. Comment found.');
+ $this->assertEqual($comment_loaded->thread, '01/');
+
+ // Reply to comment #1 creating comment #2.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
+ $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #2. Reply found.');
+ $this->assertEqual($reply_loaded->thread, '01.00/');
+
+ // Reply to comment #2 creating comment #3.
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
+ $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #3. Second reply found.');
+ $this->assertEqual($reply_loaded->thread, '01.00.00/');
+
+ // Reply to comment #1 creating comment #4.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
+ $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment #4. Third reply found.');
+ $this->assertEqual($reply_loaded->thread, '01.01/');
+
+ // Post comment #2 overall comment #5.
+ $this->drupalLogin($this->web_user);
+ $subject_text = $this->randomName();
+ $comment_text = $this->randomName();
+ $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
+ $comment_loaded = comment_load($comment->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment #5. Second comment found.');
+ $this->assertEqual($comment_loaded->thread, '02/');
+
+ // Reply to comment #5 creating comment #6.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
+ $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #6. Reply found.');
+ $this->assertEqual($reply_loaded->thread, '02.00/');
+
+ // Reply to comment #6 creating comment #7.
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
+ $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #7. Second reply found.');
+ $this->assertEqual($reply_loaded->thread, '02.00.00/');
+
+ // Reply to comment #5 creating comment #8.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
+ $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
+ $reply_loaded = comment_load($reply->id);
+ $this->assertTrue($this->commentExists($comment), 'Comment #8. Third reply found.');
+ $this->assertEqual($reply_loaded->thread, '02.01/');
+ }
+}
+
+/**
+ * Tests that comments behave correctly when the node is changed.
+ */
+class CommentNodeChangesTestCase extends CommentHelperCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment deletion on node changes',
+ 'description' => 'Tests that comments behave correctly when the node is changed.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Tests that comments are deleted with the node.
+ */
+ function testNodeDeletion() {
+ $this->drupalLogin($this->web_user);
+ $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
+ $this->assertTrue(comment_load($comment->id), 'The comment could be loaded.');
+ node_delete($this->node->nid);
+ $this->assertFalse(comment_load($comment->id), 'The comment could not be loaded after the node was deleted.');
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.tokens.inc b/kolab.org/www/drupal-7.26/modules/comment/comment.tokens.inc
new file mode 100644
index 0000000..c495ec3
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.tokens.inc
@@ -0,0 +1,243 @@
+<?php
+
+/**
+ * @file
+ * Builds placeholder replacement tokens for comment-related data.
+ */
+
+/**
+ * Implements hook_token_info().
+ */
+function comment_token_info() {
+ $type = array(
+ 'name' => t('Comments'),
+ 'description' => t('Tokens for comments posted on the site.'),
+ 'needs-data' => 'comment',
+ );
+
+ // Comment-related tokens for nodes
+ $node['comment-count'] = array(
+ 'name' => t("Comment count"),
+ 'description' => t("The number of comments posted on a node."),
+ );
+ $node['comment-count-new'] = array(
+ 'name' => t("New comment count"),
+ 'description' => t("The number of comments posted on a node since the reader last viewed it."),
+ );
+
+ // Core comment tokens
+ $comment['cid'] = array(
+ 'name' => t("Comment ID"),
+ 'description' => t("The unique ID of the comment."),
+ );
+ $comment['hostname'] = array(
+ 'name' => t("IP Address"),
+ 'description' => t("The IP address of the computer the comment was posted from."),
+ );
+ $comment['name'] = array(
+ 'name' => t("Name"),
+ 'description' => t("The name left by the comment author."),
+ );
+ $comment['mail'] = array(
+ 'name' => t("Email address"),
+ 'description' => t("The email address left by the comment author."),
+ );
+ $comment['homepage'] = array(
+ 'name' => t("Home page"),
+ 'description' => t("The home page URL left by the comment author."),
+ );
+ $comment['title'] = array(
+ 'name' => t("Title"),
+ 'description' => t("The title of the comment."),
+ );
+ $comment['body'] = array(
+ 'name' => t("Content"),
+ 'description' => t("The formatted content of the comment itself."),
+ );
+ $comment['url'] = array(
+ 'name' => t("URL"),
+ 'description' => t("The URL of the comment."),
+ );
+ $comment['edit-url'] = array(
+ 'name' => t("Edit URL"),
+ 'description' => t("The URL of the comment's edit page."),
+ );
+
+ // Chained tokens for comments
+ $comment['created'] = array(
+ 'name' => t("Date created"),
+ 'description' => t("The date the comment was posted."),
+ 'type' => 'date',
+ );
+ $comment['changed'] = array(
+ 'name' => t("Date changed"),
+ 'description' => t("The date the comment was most recently updated."),
+ 'type' => 'date',
+ );
+ $comment['parent'] = array(
+ 'name' => t("Parent"),
+ 'description' => t("The comment's parent, if comment threading is active."),
+ 'type' => 'comment',
+ );
+ $comment['node'] = array(
+ 'name' => t("Node"),
+ 'description' => t("The node the comment was posted to."),
+ 'type' => 'node',
+ );
+ $comment['author'] = array(
+ 'name' => t("Author"),
+ 'description' => t("The author of the comment, if they were logged in."),
+ 'type' => 'user',
+ );
+
+ return array(
+ 'types' => array('comment' => $type),
+ 'tokens' => array(
+ 'node' => $node,
+ 'comment' => $comment,
+ ),
+ );
+}
+
+/**
+ * Implements hook_tokens().
+ */
+function comment_tokens($type, $tokens, array $data = array(), array $options = array()) {
+ $url_options = array('absolute' => TRUE);
+ if (isset($options['language'])) {
+ $url_options['language'] = $options['language'];
+ $language_code = $options['language']->language;
+ }
+ else {
+ $language_code = NULL;
+ }
+ $sanitize = !empty($options['sanitize']);
+
+ $replacements = array();
+
+ if ($type == 'comment' && !empty($data['comment'])) {
+ $comment = $data['comment'];
+
+ foreach ($tokens as $name => $original) {
+ switch ($name) {
+ // Simple key values on the comment.
+ case 'cid':
+ $replacements[$original] = $comment->cid;
+ break;
+
+ // Poster identity information for comments
+ case 'hostname':
+ $replacements[$original] = $sanitize ? check_plain($comment->hostname) : $comment->hostname;
+ break;
+
+ case 'name':
+ $name = ($comment->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $comment->name;
+ $replacements[$original] = $sanitize ? filter_xss($name) : $name;
+ break;
+
+ case 'mail':
+ if ($comment->uid != 0) {
+ $account = user_load($comment->uid);
+ $mail = $account->mail;
+ }
+ else {
+ $mail = $comment->mail;
+ }
+ $replacements[$original] = $sanitize ? check_plain($mail) : $mail;
+ break;
+
+ case 'homepage':
+ $replacements[$original] = $sanitize ? check_url($comment->homepage) : $comment->homepage;
+ break;
+
+ case 'title':
+ $replacements[$original] = $sanitize ? filter_xss($comment->subject) : $comment->subject;
+ break;
+
+ case 'body':
+ if ($items = field_get_items('comment', $comment, 'comment_body', $language_code)) {
+ $instance = field_info_instance('comment', 'body', 'comment_body');
+ $field_langcode = field_language('comment', $comment, 'comment_body', $language_code);
+ $replacements[$original] = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], 'value') : $items[0]['value'];
+ }
+ break;
+
+ // Comment related URLs.
+ case 'url':
+ $url_options['fragment'] = 'comment-' . $comment->cid;
+ $replacements[$original] = url('comment/' . $comment->cid, $url_options);
+ break;
+
+ case 'edit-url':
+ $url_options['fragment'] = NULL;
+ $replacements[$original] = url('comment/' . $comment->cid . '/edit', $url_options);
+ break;
+
+ // Default values for the chained tokens handled below.
+ case 'author':
+ $replacements[$original] = $sanitize ? filter_xss($comment->name) : $comment->name;
+ break;
+
+ case 'parent':
+ if (!empty($comment->pid)) {
+ $parent = comment_load($comment->pid);
+ $replacements[$original] = $sanitize ? filter_xss($parent->subject) : $parent->subject;
+ }
+ break;
+
+ case 'created':
+ $replacements[$original] = format_date($comment->created, 'medium', '', NULL, $language_code);
+ break;
+
+ case 'changed':
+ $replacements[$original] = format_date($comment->changed, 'medium', '', NULL, $language_code);
+ break;
+
+ case 'node':
+ $node = node_load($comment->nid);
+ $title = $node->title;
+ $replacements[$original] = $sanitize ? filter_xss($title) : $title;
+ break;
+ }
+ }
+
+ // Chained token relationships.
+ if ($node_tokens = token_find_with_prefix($tokens, 'node')) {
+ $node = node_load($comment->nid);
+ $replacements += token_generate('node', $node_tokens, array('node' => $node), $options);
+ }
+
+ if ($date_tokens = token_find_with_prefix($tokens, 'created')) {
+ $replacements += token_generate('date', $date_tokens, array('date' => $comment->created), $options);
+ }
+
+ if ($date_tokens = token_find_with_prefix($tokens, 'changed')) {
+ $replacements += token_generate('date', $date_tokens, array('date' => $comment->changed), $options);
+ }
+
+ if (($parent_tokens = token_find_with_prefix($tokens, 'parent')) && $parent = comment_load($comment->pid)) {
+ $replacements += token_generate('comment', $parent_tokens, array('comment' => $parent), $options);
+ }
+
+ if (($author_tokens = token_find_with_prefix($tokens, 'author')) && $account = user_load($comment->uid)) {
+ $replacements += token_generate('user', $author_tokens, array('user' => $account), $options);
+ }
+ }
+ elseif ($type == 'node' & !empty($data['node'])) {
+ $node = $data['node'];
+
+ foreach ($tokens as $name => $original) {
+ switch($name) {
+ case 'comment-count':
+ $replacements[$original] = $node->comment_count;
+ break;
+
+ case 'comment-count-new':
+ $replacements[$original] = comment_num_new($node->nid);
+ break;
+ }
+ }
+ }
+
+ return $replacements;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/comment/comment.tpl.php b/kolab.org/www/drupal-7.26/modules/comment/comment.tpl.php
new file mode 100644
index 0000000..8298473
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/comment/comment.tpl.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * @file
+ * Default theme implementation for comments.
+ *
+ * Available variables:
+ * - $author: Comment author. Can be link or plain text.
+ * - $content: An array of comment items. Use render($content) to print them all, or
+ * print a subset such as render($content['field_example']). Use
+ * hide($content['field_example']) to temporarily suppress the printing of a
+ * given element.
+ * - $created: Formatted date and time for when the comment was created.
+ * Preprocess functions can reformat it by calling format_date() with the
+ * desired parameters on the $comment->created variable.
+ * - $changed: Formatted date and time for when the comment was last changed.
+ * Preprocess functions can reformat it by calling format_date() with the
+ * desired parameters on the $comment->changed variable.
+ * - $new: New comment marker.
+ * - $permalink: Comment permalink.
+ * - $submitted: Submission information created from $author and $created during
+ * template_preprocess_comment().
+ * - $picture: Authors picture.
+ * - $signature: Authors signature.
+ * - $status: Comment status. Possible values are:
+ * comment-unpublished, comment-published or comment-preview.
+ * - $title: Linked title.
+ * - $classes: String of classes that can be used to style contextually through
+ * CSS. It can be manipulated through the variable $classes_array from
+ * preprocess functions. The default values can be one or more of the following:
+ * - comment: The current template type, i.e., "theming hook".
+ * - comment-by-anonymous: Comment by an unregistered user.
+ * - comment-by-node-author: Comment by the author of the parent node.
+ * - comment-preview: When previewing a new or edited comment.
+ * The following applies only to viewers who are registered users:
+ * - comment-unpublished: An unpublished comment visible only to administrators.
+ * - comment-by-viewer: Comment by the user currently viewing the page.
+ * - comment-new: New comment since last the visit.
+ * - $title_prefix (array): An array containing additional output populated by
+ * modules, intended to be displayed in front of the main title tag that
+ * appears in the template.
+ * - $title_suffix (array): An array containing additional output populated by
+ * modules, intended to be displayed after the main title tag that appears in
+ * the template.
+ *
+ * These two variables are provided for context:
+ * - $comment: Full comment object.
+ * - $node: Node object the comments are attached to.
+ *
+ * Other variables:
+ * - $classes_array: Array of html class attribute values. It is flattened
+ * into a string within the variable $classes.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_comment()
+ * @see template_process()
+ * @see theme_comment()
+ *
+ * @ingroup themeable
+ */
+?>
+<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
+ <?php print $picture ?>
+
+ <?php if ($new): ?>
+ <span class="new"><?php print $new ?></span>
+ <?php endif; ?>
+
+ <?php print render($title_prefix); ?>
+ <h3<?php print $title_attributes; ?>><?php print $title ?></h3>
+ <?php print render($title_suffix); ?>
+
+ <div class="submitted">
+ <?php print $permalink; ?>
+ <?php print $submitted; ?>
+ </div>
+
+ <div class="content"<?php print $content_attributes; ?>>
+ <?php
+ // We hide the comments and links now so that we can render them later.
+ hide($content['links']);
+ print render($content);
+ ?>
+ <?php if ($signature): ?>
+ <div class="user-signature clearfix">
+ <?php print $signature ?>
+ </div>
+ <?php endif; ?>
+ </div>
+
+ <?php print render($content['links']) ?>
+</div>