diff -u b/comment_timer.module b/comment_timer.module
--- b/comment_timer.module
+++ b/comment_timer.module
@@ -74,6 +74,11 @@
'description' => t('Time spent on this comment.'),
'weight' => 0,
);
+ $return['comment']['comment_node_' . $type->type]['display']['comment_time_inclusion'] = array(
+ 'label' => t('Comment time inclusion'),
+ 'description' => t('Link to include/exclude comment time in node time.'),
+ 'weight' => 0,
+ );
$return['node'][$type->type]['display']['comment_timer'] = array(
'label' => t('Comment timer'),
'description' => t('Total time spent on this node\'s comments.'),
@@ -296,10 +301,98 @@
'#prefix' => '
',
);
+ $field_view_mode_settings = field_view_mode_settings('comment', $comment->node_type);
+ $real_view_mode = $field_view_mode_settings[$view_mode]['custom_settings'] ? $view_mode : 'default';
+ $field_info_extra_fields = field_info_extra_fields('comment', 'comment_node_issue', 'display');
+ if ($field_info_extra_fields['comment_time_inclusion']['display'][$real_view_mode]['visible']) {
+ if (comment_access('edit', $comment)) {
+ drupal_add_js('misc/ajax.js');
+ $comment->content['links']['comment_timer'] = array(
+ '#theme' => 'links',
+ '#links' => array(
+ 'comment-timer-inclusion' => comment_timer_status_link_array($comment),
+ ),
+ );
+ }
+ else {
+ $markup = '';
+ $comment->content['links']['comment_timer'] = array(
+ '#theme' => 'links',
+ '#links' => array(
+ 'comment-timer-inclusion' => array(
+ 'title' => $markup,
+ 'html' => TRUE,
+ ),
+ ),
+ );
+ }
+ }
}
}
/**
+ * Create the ingredients of a comment timer status ajax link.
+ */
+function comment_timer_status_link_array($comment) {
+ return array(
+ 'title' => $comment->comment_timer_status ? t('Exclude from issue total time') : t('Include in issue total time'),
+ 'href' => 'comment-timer-inclusion-toggle/' . $comment->cid . '/nojs',
+ 'attributes' => array(
+ 'class' => array('use-ajax'),
+ ),
+ );
+}
+
+/**
+ * Implements hook_menu().
+ */
+function comment_timer_menu() {
+ $items = array();
+ $items['comment-timer-inclusion-toggle/%comment'] = array(
+ 'title' => 'Toggle comment timer inclusion',
+ 'page callback' => 'comment_timer_inclusion_toggler',
+ 'page arguments' => array(1),
+ 'access callback' => 'comment_access',
+ 'access arguments' => array('edit', 1),
+ 'type' => MENU_CALLBACK,
+ );
+ return $items;
+}
+
+/**
+ * Menu callback to toggle the comment time status property.
+ */
+function comment_timer_inclusion_toggler($comment, $type = 'ajax') {
+ if ($comment->comment_timer_status == 0) {
+ $comment->comment_timer_status = 1;
+ }
+ else {
+ $comment->comment_timer_status = 0;
+ }
+ comment_save($comment);
+ if ($type == 'ajax') {
+ $link = comment_timer_status_link_array($comment);
+ $node = node_load($comment->nid, NULL, TRUE);
+ $time = array(
+ '#theme' => 'comment_timer_hhmmss',
+ '#seconds' => isset($node->comment_timer) ? $node->comment_timer : 0,
+ '#label_display' => 'hidden',
+ );
+ $commands = array();
+ $commands[] = ajax_command_html('#comment-' . $comment->cid . '+div .comment-timer-inclusion', l($link['title'], $link['href'], array('attributes' => $link['attributes'])));
+ drupal_alter('comment_timer_commands', $commands, $time);
+ $page = array('#type' => 'ajax', '#commands' => $commands);
+ ajax_deliver($page);
+ }
+ else {
+ drupal_goto('node/' . $comment->nid);
+ }
+}
+
+
+/**
* Implements hook_comment_delete().
*/
function comment_timer_comment_delete($comment) {