| 1 |
<?php
|
| 2 |
// $Id: vote_up_down_actions.inc,v 1.5 2007/07/13 12:23:08 frjo Exp $
|
| 3 |
|
| 4 |
/* TODO FormAPI image buttons are now supported.
|
| 5 |
FormAPI now offers the 'image_button' element type, allowing developers to
|
| 6 |
use icons or other custom images in place of traditional HTML submit buttons.
|
| 7 |
|
| 8 |
$form['my_image_button'] = array(
|
| 9 |
'#type' => 'image_button',
|
| 10 |
'#title' => t('My button'),
|
| 11 |
'#return_value' => 'my_data',
|
| 12 |
'#src' => 'my/image/path.jpg',
|
| 13 |
); */
|
| 14 |
|
| 15 |
/* TODO New user_mail_tokens() method may be useful.
|
| 16 |
user.module now provides a user_mail_tokens() function to return an array
|
| 17 |
of the tokens available for the email notification messages it sends when
|
| 18 |
accounts are created, activated, blocked, etc. Contributed modules that
|
| 19 |
wish to make use of the same tokens for their own needs are encouraged
|
| 20 |
to use this function. */
|
| 21 |
|
| 22 |
/* TODO
|
| 23 |
There is a new hook_watchdog in core. This means that contributed modules
|
| 24 |
can implement hook_watchdog to log Drupal events to custom destinations.
|
| 25 |
Two core modules are included, dblog.module (formerly known as watchdog.module),
|
| 26 |
and syslog.module. Other modules in contrib include an emaillog.module,
|
| 27 |
included in the logging_alerts module. See syslog or emaillog for an
|
| 28 |
example on how to implement hook_watchdog.
|
| 29 |
function example_watchdog($log = array()) {
|
| 30 |
if ($log['severity'] == WATCHDOG_ALERT) {
|
| 31 |
mysms_send($log['user']->uid,
|
| 32 |
$log['type'],
|
| 33 |
$log['message'],
|
| 34 |
$log['variables'],
|
| 35 |
$log['severity'],
|
| 36 |
$log['referer'],
|
| 37 |
$log['ip'],
|
| 38 |
format_date($log['timestamp']));
|
| 39 |
}
|
| 40 |
} */
|
| 41 |
|
| 42 |
/* TODO Implement the hook_theme registry. Combine all theme registry entries
|
| 43 |
into one hook_theme function in each corresponding module file.
|
| 44 |
function vote_up_down_actions_theme() {
|
| 45 |
return array(
|
| 46 |
);
|
| 47 |
} */
|
| 48 |
|
| 49 |
/**
|
| 50 |
* @file
|
| 51 |
* Contains Drupal actions and actions sets for use with vote_up_down.module and the Voting API..
|
| 52 |
*/
|
| 53 |
|
| 54 |
/**
|
| 55 |
* Implementation of hook_votingapi_action_sets().
|
| 56 |
*/
|
| 57 |
/* function vote_up_down_votingapi_action_sets() { */
|
| 58 |
/* $sets = array( */
|
| 59 |
/* 'vote_up_down_promotion' => array( */
|
| 60 |
/* 'description' => 'Promotes a node to the front page if enough users vote for it.', */
|
| 61 |
/* 'content_type' => 'node', */
|
| 62 |
/* 'condition_mask' => 'AND', */
|
| 63 |
/* 'enabled' => 1, */
|
| 64 |
/* 'source' => 'vote_up_down', */
|
| 65 |
/* */
|
| 66 |
/* 'conditions' => array( */
|
| 67 |
/* 'is_promoted' => array( */
|
| 68 |
/* 'description' => 'Node is not promoted', */
|
| 69 |
/* 'handler' => 'votingapi_node_properties_handler', */
|
| 70 |
/* 'data' => array( */
|
| 71 |
/* 'property' => 'promote', */
|
| 72 |
/* 'comparison' => '!=', */
|
| 73 |
/* 'value' => 1, */
|
| 74 |
/* ), */
|
| 75 |
/* ), */
|
| 76 |
/* 'min_vote' => array( */
|
| 77 |
/* 'description' => 'Sum higher than 5', */
|
| 78 |
/* 'handler' => 'votingapi_vote_result_handler', */
|
| 79 |
/* 'data' => array( */
|
| 80 |
/* 'tag' => 'vote', */
|
| 81 |
/* 'function' => 'sum', */
|
| 82 |
/* 'comparison' => '>', */
|
| 83 |
/* 'value' => 5, */
|
| 84 |
/* ), */
|
| 85 |
/* ), */
|
| 86 |
/* ), */
|
| 87 |
/* 'actions' => array( */
|
| 88 |
/* 'action_node_promote', */
|
| 89 |
/* 'action_vote_up_down_userpoints_add', */
|
| 90 |
/* ), */
|
| 91 |
/* ), */
|
| 92 |
/* */
|
| 93 |
/* 'vote_up_down_demotion' => array( */
|
| 94 |
/* 'description' => 'Demote a node from the front page if enough users vote against it.', */
|
| 95 |
/* 'content_type' => 'node', */
|
| 96 |
/* 'condition_mask' => 'AND', */
|
| 97 |
/* 'enabled' => 1, */
|
| 98 |
/* 'source' => 'vote_up_down', */
|
| 99 |
/* */
|
| 100 |
/* 'conditions' => array( */
|
| 101 |
/* 'is_promoted' => array( */
|
| 102 |
/* 'description' => 'Node is promoted', */
|
| 103 |
/* 'handler' => 'votingapi_node_properties_handler', */
|
| 104 |
/* 'data' => array( */
|
| 105 |
/* 'property' => 'promote', */
|
| 106 |
/* 'comparison' => '=', */
|
| 107 |
/* 'value' => 1, */
|
| 108 |
/* ), */
|
| 109 |
/* ), */
|
| 110 |
/* 'min_vote' => array( */
|
| 111 |
/* 'description' => 'Sum lower than 0', */
|
| 112 |
/* 'handler' => 'votingapi_vote_result_handler', */
|
| 113 |
/* 'data' => array( */
|
| 114 |
/* 'tag' => 'vote', */
|
| 115 |
/* 'function' => 'sum', */
|
| 116 |
/* 'comparison' => '<', */
|
| 117 |
/* 'value' => 0, */
|
| 118 |
/* ), */
|
| 119 |
/* ), */
|
| 120 |
/* ), */
|
| 121 |
/* 'actions' => array( */
|
| 122 |
/* 'action_node_unpromote', */
|
| 123 |
/* 'action_vote_up_down_userpoints_remove', */
|
| 124 |
/* ), */
|
| 125 |
/* ), */
|
| 126 |
/* */
|
| 127 |
/* ); */
|
| 128 |
/* */
|
| 129 |
/* */
|
| 130 |
/* return $sets; */
|
| 131 |
/* } */
|
| 132 |
|
| 133 |
/**
|
| 134 |
* Implementation of a Drupal action.
|
| 135 |
* Award userpoint to node author.
|
| 136 |
*/
|
| 137 |
function action_vote_up_down_userpoints_add($op, $edit = array(), &$node) {
|
| 138 |
switch ($op) {
|
| 139 |
case 'metadata':
|
| 140 |
return array(
|
| 141 |
'description' => t('Award userpoint to node author (Vote up/down)'),
|
| 142 |
'type' => t('Node'),
|
| 143 |
'batchable' => FALSE,
|
| 144 |
'configurable' => FALSE,
|
| 145 |
);
|
| 146 |
|
| 147 |
case 'do':
|
| 148 |
userpoints_userpointsapi('points', variable_get('userpoints_actions', 0), $node->uid);
|
| 149 |
watchdog('action', 'Awarded userpoint to author of node id %id', array('%id' => intval($node->nid)));
|
| 150 |
break;
|
| 151 |
|
| 152 |
// return an HTML config form for the action
|
| 153 |
case 'form':
|
| 154 |
return '';
|
| 155 |
|
| 156 |
// validate the HTML form
|
| 157 |
case 'validate':
|
| 158 |
return TRUE;
|
| 159 |
|
| 160 |
// process the HTML form to store configuration
|
| 161 |
case 'submit':
|
| 162 |
return '';
|
| 163 |
}
|
| 164 |
}
|
| 165 |
|
| 166 |
/**
|
| 167 |
* Implementation of a Drupal action.
|
| 168 |
* Deduct userpoint from node author.
|
| 169 |
*/
|
| 170 |
function action_vote_up_down_userpoints_remove($op, $edit = array(), &$node) {
|
| 171 |
switch ($op) {
|
| 172 |
case 'metadata':
|
| 173 |
return array(
|
| 174 |
'description' => t('Deduct userpoint from node author (Vote up/down)'),
|
| 175 |
'type' => t('Node'),
|
| 176 |
'batchable' => FALSE,
|
| 177 |
'configurable' => FALSE,
|
| 178 |
);
|
| 179 |
|
| 180 |
case 'do':
|
| 181 |
userpoints_userpointsapi('points', -variable_get('userpoints_actions', 0), $node->uid);
|
| 182 |
watchdog('action', 'Deducted userpoint from author of node id %id', array('%id' => intval($node->nid)));
|
| 183 |
break;
|
| 184 |
|
| 185 |
// return an HTML config form for the action
|
| 186 |
case 'form':
|
| 187 |
return '';
|
| 188 |
|
| 189 |
// validate the HTML form
|
| 190 |
case 'validate':
|
| 191 |
return TRUE;
|
| 192 |
|
| 193 |
// process the HTML form to store configuration
|
| 194 |
case 'submit':
|
| 195 |
return '';
|
| 196 |
}
|
| 197 |
}
|
| 198 |
|
| 199 |
/**
|
| 200 |
* Touches the creation date of a node. Useful for moderated nodes that should appear
|
| 201 |
* 'fresh' as soon as they're promoted.
|
| 202 |
*/
|
| 203 |
function action_vote_up_down_node_touch_created($op, $edit = array(), &$node) {
|
| 204 |
switch ($op) {
|
| 205 |
case 'metadata':
|
| 206 |
return array(
|
| 207 |
'description' => t('Touch node creation date (Vote up/down)'),
|
| 208 |
'type' => t('Node'),
|
| 209 |
'batchable' => TRUE,
|
| 210 |
'configurable' => FALSE,
|
| 211 |
);
|
| 212 |
|
| 213 |
case 'do':
|
| 214 |
$node->created = time();
|
| 215 |
if (!$edit['defer']) {
|
| 216 |
node_save($node);
|
| 217 |
}
|
| 218 |
watchdog('action', 'Touched creation date of node id %id', array('%id' => intval($node->nid)));
|
| 219 |
break;
|
| 220 |
|
| 221 |
// return an HTML config form for the action
|
| 222 |
case 'form':
|
| 223 |
return '';
|
| 224 |
|
| 225 |
// validate the HTML form
|
| 226 |
case 'validate':
|
| 227 |
return TRUE;
|
| 228 |
|
| 229 |
// process the HTML form to store configuration
|
| 230 |
case 'submit':
|
| 231 |
return '';
|
| 232 |
}
|
| 233 |
}
|
| 234 |
|
| 235 |
/**
|
| 236 |
* Touches the change date of a node. Useful for moderated nodes that should appear
|
| 237 |
* 'fresh' as soon as they're promoted.
|
| 238 |
*/
|
| 239 |
function action_vote_up_down_node_touch_changed($op, $edit = array(), &$node) {
|
| 240 |
switch ($op) {
|
| 241 |
case 'metadata':
|
| 242 |
return array(
|
| 243 |
'description' => t('Touch node change date (Vote up/down)'),
|
| 244 |
'type' => t('Node'),
|
| 245 |
'batchable' => TRUE,
|
| 246 |
'configurable' => FALSE,
|
| 247 |
);
|
| 248 |
|
| 249 |
case 'do':
|
| 250 |
$node->changed = time();
|
| 251 |
if (!$edit['defer']) {
|
| 252 |
node_save($node);
|
| 253 |
}
|
| 254 |
watchdog('action', 'Touched change date of node id %id', array('%id' => intval($node->nid)));
|
| 255 |
break;
|
| 256 |
|
| 257 |
// return an HTML config form for the action
|
| 258 |
case 'form':
|
| 259 |
return '';
|
| 260 |
|
| 261 |
// validate the HTML form
|
| 262 |
case 'validate':
|
| 263 |
return TRUE;
|
| 264 |
|
| 265 |
// process the HTML form to store configuration
|
| 266 |
case 'submit':
|
| 267 |
return '';
|
| 268 |
}
|
| 269 |
}
|