-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathog.api.php
executable file
·273 lines (250 loc) · 7.14 KB
/
og.api.php
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
// $Id$
/**
* @file
* Hooks provided by the Organic groups module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Add group permissions.
*/
function hook_og_permission() {
return array(
'subscribe' => array(
'title' => t('Subscribe user to group'),
'description' => t("Allow user to be a member of a group (approval required)."),
'roles' => array(OG_ANONYMOUS_ROLE),
),
);
}
/**
* Set the default permissions to be assigned to members, by thier role.
*/
function hook_og_permission_default() {
return array(
OG_ANONYMOUS_ROLE => array('an anonymous permission'),
OG_AUTHENTICATED_ROLE => array('an authenticated permission'),
OG_ADMINISTRATOR_ROLE => array(),
);
}
/**
* Determine if a user has access to a certain operation within a group context.
*
* For content access @see hook_og_node_access().
*
* @param $op
* The operation name.
* @param $node
* The group or group post node object.
* @param $acting_user
* The user object of the acting user.
* @param $account
* Optional; The account related to the operation.
* @return
* OG_ACCESS_ALLOW - if operation is allowed;
* OG_ACCESS_DENY - if it should be denied;
* OG_ACCESS_IGNORE - if you don't care about this operation.
*/
function hook_og_access($op, $node, $acting_user, $account = NULL) {
if ($op == 'view') {
// Show group posts only if they are in a certain day, defined in the
// group's data. This data is fictional, and it's up to an implementing
// module to implement it.
if (og_is_group_post_type($node->type)) {
// Get the first node group this group post belongs to.
$gids = og_get_object_groups('node', $node);
$group = node_load($gids[0]);
if (!empty($group->data['show day'])) {
$today = date('N');
if ($group->data['show day'] == $today) {
return OG_ACCESS_ALLOW;
}
else {
return OG_ACCESS_DENY;
}
}
else {
// The group doesn't have a day definition, so we don't care about this
// operation.
return OG_ACCESS_IGNORE;
}
}
}
}
/**
* Own implementation of hook_node_access().
*
* Having this implementation makes sure that if no organic group module
* allowed access to the content, then it will be denied.
*/
function hook_og_node_access($node, $op, $account) {
// Allow user to edit posts if the title is 'My post'.
// For the example we assume the $node is the full node object. If the title
// of the node doesn't match, and the user didn't get permission from
// somewhere else (e.g. user already has a permission to 'Edit group posts')
// Then access will be denied.
if ($node->title == 'MY post') {
return OG_ACCESS_ALLOW;
}
}
/**
* Alter a group that is being fetched.
*
* @param $group
* An object with the following keys:
* - nid:
* The node ID of the group.
* - data:
* Optional; An array of data related to the association. The data is per
* per group, and it's up to an implementing module to act on the data.
*/
function hook_og_get_group_alter($group) {
// Set the theme according to the user name.
global $user;
if ($user->name == 'foo') {
// An implementing module should act on this data and change the theme
// accordingly.
$group->data['theme'] = 'MY_THEME';
}
}
/**
* Alter a group that is being saved.
*
* @param $group
* An object with the following keys:
* - nid:
* The node ID of the group.
* - data:
* Optional; An array of data related to the association. The data is per
* per group, and it's up to an implementing module to act on the data.
*/
function hook_og_set_group_alter($group) {
}
/**
* Return the types of group or group posts available.
*
* @return
* An array keyed with the type name and it's value is an array with the
* following keys:
* - type: The type can be "group", "group_post" or "omitted".
* - description: Explanation about the type.
*/
function hook_og_types_info() {
// Add a wiki style group post.
return array(
'wiki' => array(
'type' => 'group post',
'description' => t('Wiki group post (any group member may edit).'),
)
);
}
/**
* Alter the users which will be notified about a subscription of another user.
*
* @param $uids
* An array with the users ID, passed by reference.
* @param $node
* The group node, the user has subscribed to.
* @param $group
* The group object.
* @param $account
* The subscribing user object.
* @param $request
* Optional; The request text the subscribing user has entered.
*/
function hook_og_user_request(&$uids, $node, $group, $account, $request) {
// Add user ID 1 to the list of notified users.
$uids[] = 1;
}
/**
* Insert state and data, that will be saved with the group post.
*
* @param $alter
* Array keyed by "state" and "data" passed by reference.
* The data passed by reference.
* @param $obj_type
* @param $object
* @param $field
* @param $instance
* @param $langcode
* @param $items
*/
function hook_og_field_insert(&$alter, $obj_type, $object, $field, $instance, $langcode, $items) {
// Add timestamp for the subscription.
// It's up to the implementing module to act on the data.
$alter['data']['timestamp'] = time();
}
/**
* Update state and data, that will be saved with the group post.
*
* @param $alter
* Array keyed by "state" and "data" passed by reference.
* The data passed by reference.
* @param $obj_type
* @param $object
* @param $field
* @param $instance
* @param $langcode
* @param $items
*/
function hook_og_field_update (&$alter, $obj_type, $object, $field, $instance, $langcode, $items) {
// Reject a group post when it's updated.
// It's up to the implementing module to act on the data.
$alter['state'] = 'updated, approve urgently';
}
/**
* Alter the groups an object is associated with.
*
* User subscription for example is passed through here, allows modules to
* change them. Also user unsubscription is using this function. To identify
* the type of action, we get the $op argument.
*
* @param $edit
* An array with the groups the object will be associated with, passed by
* reference.
* @param $account
* The user being subscribed.
@param $op
* Optional; The operation that is being done (e.g. "subscribe user" or
* "unsubscribe content").
*/
function hook_og_set_association_alter(&$gids, $account, $op = '') {
if ($op == 'subscribe user') {
// Subscribe the user to another group.
$gids[] = 1;
}
}
function hook_og_users_roles_grant($nid, $uid, $rid) {
}
function hook_og_users_roles_revoke($nid, $uid, $rid) {
}
/**
* Define the table, ID and label columns of a fieldable entity.
*
* This is used so groups can appear in the OG audience field with their
* sanitized name.
*/
function hook_og_entity_get_label_info() {
return array(
'my_entity' => array(
'table' => 'foo',
'id' => 'bar',
'label' => 'baz',
),
);
}
/**
* Alter get entity label definitions.
*
*/
function hook_og_entity_get_label_info_alter(&$data) {
if (!empty($data['my_entity'])) {
$data['my_entity']['table'] = 'new_foo';
}
}
/**
* @} End of "addtogroup hooks".
*/