-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflag_hidden.module
161 lines (140 loc) · 3.78 KB
/
flag_hidden.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/*
* Implement hook_views_api()
*/
function flag_hidden_views_api() {
return array('api' => 2.0);
}
/*
* Implement hook_flag_default_flags()
*/
function flag_hidden_flag_default_flags() {
$flags = array();
// Exported flag: "Hidden Node".
$flags['hidden_node'] = array(
'content_type' => 'node',
'title' => 'Hidden Node',
'global' => '1',
'types' => array(),
'flag_short' => 'Hide [node:type-name]',
'flag_long' => '',
'flag_message' => '',
'unflag_short' => 'Unhide [node:type-name]',
'unflag_long' => '',
'unflag_message' => '',
'unflag_denied_text' => '',
'link_type' => 'normal',
'roles' => array(
'flag' => array(),
'unflag' => array(),
),
'show_on_page' => 0,
'show_on_teaser' => 0,
'show_on_form' => 0,
'access_author' => '',
'i18n' => 0,
'api_version' => 2,
);
// Exported flag: "Hidden Comment".
$flags['hidden_comment'] = array(
'content_type' => 'comment',
'title' => 'Hidden Comment',
'global' => '1',
'types' => array(),
'flag_short' => 'Hide Comment',
'flag_long' => '',
'flag_message' => '',
'unflag_short' => 'Unhide Comment',
'unflag_long' => '',
'unflag_message' => '',
'unflag_denied_text' => '',
'link_type' => 'normal',
'roles' => array(
'flag' => array(),
'unflag' => array(),
),
'access_author' => '',
'show_on_comment' => 1,
'api_version' => 2,
);
return $flags;
}
/*
* Hide hidden comments
*/
function flag_hidden_comment_view($comment, $view_mode, $langcode) {
$flag = flag_get_flag('hidden_comment');
if ($flag && $flag->is_flagged($comment->cid)) {
flag_hidden_hide_comment_content($comment);
}
}
function flag_hidden_hide_comment_content($comment) {
$fieldset = array(
'#type' => 'fieldset',
'#title' => t("@title (hidden by the editors)", array('@title' => $comment->subject)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// Need to manually attach/set some stuff to make this work outside of a
// form
'#attached' => array(
'js' => array(
'misc/form.js',
'misc/collapse.js',
),
),
'#attributes' => array(
'class' => array('collapsible', 'collapsed'),
),
);
$fieldset['hidden_content'] = $comment->content;
$comment->content = $fieldset;
// For some reason moving the arrays around messes up the ordering of
// comment elemnts. Manually set the weight for links to fix this.
$fieldset['hidden_content']['links']['#weight'] = 1;
}
/*
* Add robots META tags for hidden nodes and our hidden view.
*/
/*
* Implement hook_page_alter
*/
function flag_hidden_page_alter() {
if(flag_hidden_page_is_hidden_node() ||
flag_hidden_page_is_hidden_view()) {
flag_hidden_add_robots_meta_tag();
}
}
function flag_hidden_add_robots_meta_tag() {
$element = array(
'#tag' => 'meta',
'#attributes' => array(
'name' => 'robots',
'content' => 'noindex, nofollow',
),
);
drupal_add_html_head($element, 'robots-noindex');
}
function flag_hidden_node_is_hidden(&$node) {
$flag = flag_get_flag('hidden_node');
return ($flag && $flag->is_flagged($node->nid));
}
function flag_hidden_page_is_hidden_node() {
static $cache = null;
if(isset($cache)) return $cache;
$current_node = menu_get_object('node');
$cache = ($current_node && flag_hidden_node_is_hidden($current_node));
return $cache;
}
function flag_hidden_page_is_hidden_view() {
static $cache = null;
if(isset($cache)) return $cache;
$page_view = views_get_page_view();
$cache = ($page_view && $page_view->name == 'hidden_nodes');
return $cache;
}
/*
* Add a hidden_node variable for themes
*/
function flag_hidden_preprocess_page(&$variables) {
$variables['hidden_node'] = flag_hidden_page_is_hidden_node();
}