You are here

class flag_comment in Flag 6

Same name and namespace in other branches
  1. 5 flag.inc \flag_comment
  2. 6.2 flag.inc \flag_comment
  3. 7.3 includes/flag/flag_comment.inc \flag_comment
  4. 7.2 flag.inc \flag_comment

Implements a comment flag.

Hierarchy

Expanded class hierarchy of flag_comment

1 string reference to 'flag_comment'
flag_flag_definitions in ./flag.inc
Implementation of hook_flag_definitions().

File

./flag.inc, line 987
Implements various flags. Uses object oriented style inspired by that of Views 2.

View source
class flag_comment extends flag_flag {
  function default_options() {
    $options = parent::default_options();
    $options += array(
      'show_on_comment' => TRUE,
    );
    return $options;
  }
  function options_form(&$form) {
    parent::options_form($form);
    $form['display']['show_on_comment'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display link under comment'),
      '#default_value' => $this->show_on_comment,
      '#access' => empty($this->locked['show_on_comment']),
    );
  }
  function _load_content($content_id) {
    return _comment_load($content_id);
  }
  function applies_to_content_object($comment) {
    if ($comment && ($node = node_load($comment->nid)) && in_array($node->type, $this->types)) {
      return TRUE;
    }
    return FALSE;
  }
  function get_content_id($comment) {
    return $comment->cid;
  }
  function uses_hook_link($teaser) {
    return $this->show_on_comment;
  }
  function get_labels_token_types() {
    return array(
      'comment',
      'node',
    );
  }
  function replace_tokens($label, $contexts, $content_id) {
    if ($content_id) {
      if (($comment = $this
        ->fetch_content($content_id)) && ($node = node_load($comment->nid))) {
        $contexts['node'] = $node;
        $contexts['comment'] = $comment;
      }
    }
    return parent::replace_tokens($label, $contexts, $content_id);
  }
  function get_flag_action($content_id) {
    $flag_action = parent::get_flag_action($content_id);
    $comment = $this
      ->fetch_content($content_id);
    $flag_action->content_title = $comment->subject;
    $flag_action->content_url = _flag_url("node/{$comment->nid}/{$comment->cid}", "comment-{$comment->cid}");
    return $flag_action;
  }
  function get_relevant_action_objects($content_id) {
    $comment = $this
      ->fetch_content($content_id);
    return array(
      'comment' => $comment,
      'node' => node_load($comment->nid),
    );
  }
  function rules_get_event_arguments_definition() {
    return array(
      'comment' => array(
        'type' => 'comment',
        'label' => t('flagged comment'),
        'handler' => 'flag_rules_get_event_argument',
      ),
      'comment_author' => array(
        'type' => 'user',
        'label' => t('flagged comment author'),
        'handler' => 'flag_rules_get_comment_author',
      ),
      'node' => array(
        'type' => 'node',
        'label' => t("the flagged comment's content"),
        'handler' => 'flag_rules_get_comment_content',
      ),
      'node_author' => array(
        'type' => 'user',
        'label' => t('commented content author'),
        'handler' => 'flag_rules_get_comment_node_author',
      ),
    );
  }
  function rules_get_element_argument_definition() {
    return array(
      'type' => 'comment',
      'label' => t('Flagged comment'),
    );
  }
  function get_views_info() {
    return array(
      'views table' => 'comments',
      'join field' => 'cid',
      'title field' => 'subject',
      'title' => t('Comment flag'),
      'help' => t('Limit results to only those comments flagged by a certain flag; Or display information about the flag set on a comment.'),
      'counter title' => t('Comment flag counter'),
      'counter help' => t('Include this to gain access to the flag counter field.'),
    );
  }
  function applies_to_content_id_array($content_ids) {
    $passed = array();
    $content_ids = implode(',', array_map('intval', $content_ids));
    $placeholders = implode(',', array_fill(0, sizeof($this->types), "'%s'"));
    $result = db_query("SELECT cid FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE cid IN ({$content_ids}) and n.type IN ({$placeholders})", $this->types);
    while ($row = db_fetch_object($result)) {
      $passed[$row->cid] = TRUE;
    }
    return $passed;
  }

}

Members