1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
76e2e7c3
|
Assos Assos
|
* Contains the flag_comment class.
|
6 |
85ad3d82
|
Assos Assos
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements a comment flag.
|
10 |
|
|
*/
|
11 |
|
|
class flag_comment extends flag_entity {
|
12 |
|
|
function options() {
|
13 |
|
|
$options = parent::options();
|
14 |
|
|
$options += array(
|
15 |
|
|
'access_author' => '',
|
16 |
|
|
);
|
17 |
|
|
return $options;
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Options form extras for comment flags.
|
22 |
|
|
*/
|
23 |
|
|
function options_form(&$form) {
|
24 |
|
|
parent::options_form($form);
|
25 |
|
|
|
26 |
|
|
$form['access']['access_author'] = array(
|
27 |
|
|
'#type' => 'radios',
|
28 |
|
|
'#title' => t('Flag access by content authorship'),
|
29 |
|
|
'#options' => array(
|
30 |
|
|
'' => t('No additional restrictions'),
|
31 |
|
|
'comment_own' => t('Users may only flag own comments'),
|
32 |
|
|
'comment_others' => t('Users may only flag comments by others'),
|
33 |
|
|
'node_own' => t('Users may only flag comments of nodes they own'),
|
34 |
|
|
'node_others' => t('Users may only flag comments of nodes by others'),
|
35 |
|
|
),
|
36 |
|
|
'#default_value' => $this->access_author,
|
37 |
|
|
'#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."),
|
38 |
|
|
);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
function type_access_multiple($entity_ids, $account) {
|
42 |
|
|
$access = array();
|
43 |
|
|
|
44 |
|
|
// If all subtypes are allowed, we have nothing to say here.
|
45 |
|
|
if (empty($this->types)) {
|
46 |
|
|
return $access;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
// Ensure node types are granted access. This avoids a
|
50 |
|
|
// node_load() on every type, usually done by applies_to_entity_id().
|
51 |
|
|
$query = db_select('comment', 'c');
|
52 |
|
|
$query->innerJoin('node', 'n', 'c.nid = n.nid');
|
53 |
|
|
$result = $query
|
54 |
|
|
->fields('c', array('cid'))
|
55 |
|
|
->condition('c.cid', $entity_ids, 'IN')
|
56 |
|
|
->condition('n.type', $this->types, 'NOT IN')
|
57 |
|
|
->execute();
|
58 |
|
|
foreach ($result as $row) {
|
59 |
|
|
$access[$row->nid] = FALSE;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
return $access;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
function get_entity_id($comment) {
|
66 |
|
|
// Store the comment object in the static cache, to avoid getting it
|
67 |
|
|
// again unneedlessly.
|
68 |
|
|
$this->remember_entity($comment->cid, $comment);
|
69 |
|
|
return $comment->cid;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
function get_labels_token_types() {
|
73 |
|
|
return array_merge(array('comment', 'node'), parent::get_labels_token_types());
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
function replace_tokens($label, $contexts, $options, $entity_id) {
|
77 |
|
|
if ($entity_id) {
|
78 |
|
|
if (($comment = $this->fetch_entity($entity_id)) && ($node = node_load($comment->nid))) {
|
79 |
|
|
$contexts['node'] = $node;
|
80 |
|
|
$contexts['comment'] = $comment;
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
return parent::replace_tokens($label, $contexts, $options, $entity_id);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
function get_flag_action($entity_id) {
|
87 |
|
|
$flag_action = parent::get_flag_action($entity_id);
|
88 |
|
|
$comment = $this->fetch_entity($entity_id);
|
89 |
|
|
$flag_action->content_title = $comment->subject;
|
90 |
|
|
$flag_action->content_url = $this->_flag_url("comment/$comment->cid", "comment-$comment->cid");
|
91 |
|
|
return $flag_action;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
function get_relevant_action_objects($entity_id) {
|
95 |
|
|
$comment = $this->fetch_entity($entity_id);
|
96 |
|
|
return array(
|
97 |
|
|
'comment' => $comment,
|
98 |
|
|
'node' => node_load($comment->nid),
|
99 |
|
|
);
|
100 |
|
|
}
|
101 |
|
|
} |