You are here

class flag_comment in Flag 6.2

Same name and namespace in other branches
  1. 5 flag.inc \flag_comment
  2. 6 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 1467
Implements various flags. Uses object oriented style inspired by that of Views 2.

View source
class flag_comment extends flag_flag {
  function options() {
    $options = parent::options();
    $options += array(
      'access_author' => '',
      'show_on_comment' => TRUE,
    );
    return $options;
  }
  function options_form(&$form) {
    parent::options_form($form);
    $form['access']['access_author'] = array(
      '#type' => 'radios',
      '#title' => t('Flag access by content authorship'),
      '#options' => array(
        '' => t('No additional restrictions'),
        'comment_own' => t('Users may only flag own comments'),
        'comment_others' => t('Users may only flag comments by others'),
        'node_own' => t('Users may only flag comments of nodes they own'),
        'node_others' => t('Users may only flag comments of nodes by others'),
      ),
      '#default_value' => $this->access_author,
      '#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
    );
    $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 type_access_multiple($content_ids, $account) {
    $access = array();

    // Ensure node types are granted access. This avoids a
    // node_load() on every type, usually done by applies_to_content_id().
    $cids = implode(',', array_map('intval', array_keys($content_ids)));
    $placeholders = implode(',', array_fill(0, sizeof($this->types), "'%s'"));
    $result = db_query("SELECT cid as content_id FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE cid IN ({$cids}) and n.type NOT IN ({$placeholders})", $this->types);
    while ($row = db_fetch_object($result)) {
      $access[$row->content_id] = FALSE;
    }
    return $access;
  }
  function get_content_id($comment) {

    // Store the comment object in the static cache, to avoid getting it
    // again unneedlessly.
    $this
      ->remember_content($comment->cid, $comment);
    return $comment->cid;
  }
  function uses_hook_link($teaser) {
    return $this->show_on_comment;
  }
  function get_labels_token_types() {
    return array_merge(array(
      'comment',
      'node',
    ), parent::get_labels_token_types());
  }
  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.'),
    );
  }

}

Members