Issue #1426576 by ay13, ezra-g: Fixed Activity log resizes images regardless of Image...
[project/activity_log.git] / API.php
1 <?php
2
3 /**
4 * @file
5 * Hook documentation for the Activity Log module.
6 */
7
8 /**
9 * Implementation of hook_activity_log_collapse_methods().
10 *
11 * Specifies available options for combining an array of strings into a single
12 * string. These options are exposed on the "Log activity" Rules action form
13 * and are used to collapse an array of evaluated items into the [collection]
14 * token in the group template.
15 *
16 * @return
17 * An associative array of options where the key is the name of the
18 * function for collapsing an array and the value is the human-friendly name
19 * of the option. The available functions should take a $collection array and
20 * an integral $count of the number of items in that collection as parameters
21 * and return a string summarizing the items in the $collection. The
22 * $collection will always have at least 2 items.
23 */
24 function hook_activity_log_collapse_methods() {
25 return array(
26 'activity_log_collapse_inline' => t('Inline (A, B, and 3 others)'),
27 'activity_log_collapse_list_horizontal' => t('Horizontal list (A B C D)'),
28 'activity_log_collapse_list_vertical' => t('Vertical list (each item on its own line)'),
29 );
30 }
31
32 /**
33 * Implementation of hook_activity_log_event().
34 *
35 * Invoked when an activity is logged; allows taking action when this happens.
36 *
37 * @param $event
38 * The activity event object (properties correspond with the columns in the
39 * {activity_log_events} table).
40 * @param $group
41 * The activity message object (properties correspond with the columns in the
42 * {activity_log_messages} table).
43 * @param $settings
44 * An array containing the evaluated settings for the executed Activity Log
45 * Rules action.
46 */
47 function hook_activity_log_event($event, $group, $settings) {
48 if (module_exists('radioactivity')) {
49 module_load_include('inc', 'radioactivity');
50 $aids = explode(',', $group->aids);
51 if (count($aids) > 1) {
52 radioactivity_add_energy($group->mid, 'act_log', 'group:'. $event->tid);
53 }
54 else {
55 radioactivity_add_energy($group->mid, 'act_log', 'event:'. $event->tid);
56 }
57 }
58 }
59
60 /**
61 * Implementation of hook_activity_log_entity_groups().
62 *
63 * Defines groups of potential stream owners and message viewers for an action.
64 *
65 * @param $stream_owner
66 * If TRUE, the groups returned are valid for stream owners -- that is, all
67 * entity types, but "everyone" is not valid. If FALSE, the groups returned
68 * are only for users, and so are valid for message viewers.
69 * @return
70 * An associative array of group definitions keyed by the machine name.
71 * Values are also associative arrays that can have the following elements:
72 * - items callback: A function that returns an associative array where the
73 * keys are valid stream owner types (node, user, taxonomy_term) and the
74 * values are arrays of stream owner IDs of that type.
75 * - title: A translated, human-friendly name of the group.
76 * - weight: (Optional) The group's weight in an ordering of all groups.
77 * Lighter weights float to the top. Defaults to 0.
78 * - expose fields: (Optional) An array of which additional fields should be
79 * exposed if this group is selected. Valid values for this array are "id,"
80 * "type," and (if you know what you're doing) "acting_uid." Defaults to
81 * array().
82 * - additional arguments: (Optional) Extra arguments to pass to the items
83 * callback.
84 * - data types: (Optional) An array containing names of Rules data types for
85 * which this group is valid. If not specified, this group is assumed to be
86 * valid for all Rules data types. Valid data types that can be specified
87 * here include anything returned by
88 * activity_log_get_rules_data_types(array('stream owner types' => 'all)).
89 * - file: (Optional) The file where the items callback exists.
90 */
91 function hook_activity_log_entity_groups($stream_owner = TRUE) {
92 module_load_include('inc', 'activity_log', 'activity_log.entity_groups');
93 return activity_log_entity_groups($stream_owner);
94 }
95
96 /**
97 * Implementation of hook_activity_log_regenerate_info().
98 *
99 * Returns an associative array describing Rules events for which we support
100 * regenerating activity messages. The keys are the Rules event machine name
101 * (valid values can be found using array_keys(rules_get_events())) and the
102 * values are associative arrays with the following elements:
103 *
104 * - callback: A function that triggers the relevant event once for each
105 * relevant entity.
106 * - arguments: An array of additional arguments to pass to the count and
107 * generate callbacks. Useful for events with conditional names.
108 * - file: (Optional) A file to include before the callbacks are executed.
109 * - target_type: (Optional) The Rules data type of the entity for which your
110 * event regenerates activity messages. Existing activity messages that use
111 * this data type will be deleted before activity is regenerated to avoid
112 * duplicates.
113 *
114 * The callback's parameters include:
115 *
116 * - $age: Content created after this timestamp should have activity messages
117 * generated.
118 * - $context: The return value of the previous time that callback was invoked.
119 * The first time the callback is invoked, the value of this argument is
120 * FALSE. You can use the last return value to keep track of an "offset,"
121 * e.g. so you can only process a limited number of entities in one batch
122 * request and you know where to pick up on the next request.
123 * - Any arguments passed via the "arguments" key.
124 *
125 * The callback will be invoked repeatedly until it returns something that
126 * evaluates to FALSE.
127 */
128 function hook_activity_log_regenerate_info() {
129 $path = drupal_get_path('module', 'activity_log') .'/activity_log.generate.inc';
130 $items = array(
131 'comment_insert' => array(
132 'callback' => 'activity_log_regenerate_comments',
133 'file' => $path,
134 'target_type' => 'comment',
135 ),
136 'node_insert' => array(
137 'callback' => 'activity_log_regenerate_nodes',
138 'file' => $path,
139 'target_type' => 'node',
140 ),
141 'taxonomy_term_insert' => array(
142 'callback' => 'activity_log_regenerate_taxonomy_terms',
143 'file' => $path,
144 'target_type' => 'taxonomy_term',
145 ),
146 'user_insert' => array(
147 'callback' => 'activity_log_regenerate_users',
148 'file' => $path,
149 'target_type' => 'user',
150 ),
151 );
152 return $items;
153 }
154
155 /**
156 * Implementation of hook_activity_log_token_resources().
157 *
158 * Maps tokens to CSS and JS resources they require. The specified resources
159 * will be loaded for cached messages that use the relevant tokens.
160 */
161 function hook_activity_log_token_resources() {
162 return array(
163 '[:global:token]' => array(
164 'css' => array(
165 drupal_get_path('module', 'hook') .'/hook.css',
166 ),
167 'js' => array(
168 drupal_get_path('module', 'hook') .'/hook.js',
169 ),
170 ),
171 );
172 }
173
174 /**
175 * Implementation of hook_activity_log_uncacheable_tokens().
176 *
177 * Returns an array of tokens that cannot be cached. Messages generated from
178 * templates that use these tokens will never be cached.
179 */
180 function hook_activity_log_uncacheable_tokens() {
181 return array(
182 '[:global:user-id]',
183 '[:global:user-mail]',
184 '[:global:user-name]',
185 ':userpoints]',
186 );
187 }
188
189 /**
190 * Implementation of hook_activity_log_display_types().
191 *
192 * Returns an associative array of locations where activity messages can be
193 * displayed. The keys are the machine names and the values are the translated
194 * human-friendly names of the destinations.
195 */
196 function hook_activity_log_display_types() {
197 return array(
198 'web' => t('Web stream'),
199 );
200 }