| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
|
* $Id$ |
| 5 |
|
* |
| 6 |
* @file |
* @file |
| 7 |
* A medium-level demonstration of VotingAPI. |
* A medium-level demonstration of VotingAPI. |
| 8 |
* Original simplevote module with: |
* Original simplevote module with: |
| 9 |
* 1) AJAX handling (if javascript is not enabled, uses normal links) |
* 1) AJAX handling (if javascript is not enabled, uses regular links) |
| 10 |
* 2) Multi-criteria voting |
* 2) Multi-criteria voting |
| 11 |
* 3) Option to choose voting mode |
* 3) Option to choose voting mode (either all modes, mode-specific) |
| 12 |
* settings->mediumvote->Voting Settings |
* settings->mediumvote |
| 13 |
|
* 4) Node-specific voting options |
| 14 |
|
* |
| 15 |
|
* Development funded by addictedtotravel.com |
| 16 |
*/ |
*/ |
| 17 |
|
|
| 18 |
|
// ability to show voting on nodes & comments |
| 19 |
|
define ('MEDIUMVOTE_DENY', 0); |
| 20 |
|
define ('MEDIUMVOTE_ALLOW', 1); |
| 21 |
|
define ('MEDIUMVOTE_NODE', 2); |
| 22 |
|
|
| 23 |
// ability to vote on nodes and comments |
// ability to vote on nodes and comments |
| 24 |
define ('VOTINGAPI_VALUE_NODE_CONTENT_TYPE', 'node'); |
define ('VOTINGAPI_VALUE_NODE_CONTENT_TYPE', 'node'); |
| 25 |
define ('VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE', 'comment'); |
define ('VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE', 'comment'); |
| 28 |
define ('VOTINGAPI_COMMENT_TAG_TAG1', '1'); |
define ('VOTINGAPI_COMMENT_TAG_TAG1', '1'); |
| 29 |
define ('VOTINGAPI_COMMENT_TAG_TAG2', '2'); |
define ('VOTINGAPI_COMMENT_TAG_TAG2', '2'); |
| 30 |
|
|
| 31 |
|
// number of allowed voting criteria |
| 32 |
|
define ('NUM_VOTING_CRITERIA', 5); |
| 33 |
|
|
| 34 |
function mediumvote_menu($may_cache) { |
function mediumvote_menu($may_cache) { |
| 35 |
drupal_set_html_head(theme('stylesheet_import', theme('mediumvote_css_path'))); |
drupal_set_html_head(theme('stylesheet_import', theme('mediumvote_css_path'))); |
| 36 |
|
|
| 41 |
'path' => 'vote', |
'path' => 'vote', |
| 42 |
'title' => t('vote on content'), |
'title' => t('vote on content'), |
| 43 |
'callback' => 'mediumvote_vote', |
'callback' => 'mediumvote_vote', |
| 44 |
'access' => true, |
'access' => TRUE, |
| 45 |
'type' => MENU_CALLBACK |
'type' => MENU_CALLBACK |
| 46 |
); |
); |
| 47 |
$items[] = array( |
$items[] = array( |
| 48 |
'path' => 'ajax_mediumvote', |
'path' => 'ajax_mediumvote', |
| 49 |
'title' => t('vote on content (ajax)'), |
'title' => t('vote on content (ajax)'), |
| 50 |
'callback' => 'ajax_mediumvote_handler', |
'callback' => 'ajax_mediumvote_handler', |
| 51 |
'access' => true, |
'access' => TRUE, |
| 52 |
'type' => MENU_CALLBACK |
'type' => MENU_CALLBACK |
| 53 |
); |
); |
| 54 |
|
$items[] = array( |
| 55 |
|
'path' => 'admin/settings/mediumvote', |
| 56 |
|
'title' => t('mediumvote'), |
| 57 |
|
'callback' => 'mediumvote_configure' |
| 58 |
|
); |
| 59 |
|
|
| 60 |
} |
} |
| 61 |
|
|
| 67 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 68 |
return t('Adds a vote widget to every node and comment.'); |
return t('Adds a vote widget to every node and comment.'); |
| 69 |
break; |
break; |
| 70 |
|
case 'admin/settings/mediumvote': |
| 71 |
|
return t('<p>Configure mediumvote:</p>'); |
| 72 |
|
break; |
| 73 |
} |
} |
| 74 |
} |
} |
| 75 |
|
|
| 80 |
* VOTINGAPI_VALUE_TYPE_TOKEN -- 'Value' is a positive or negative int. The API will cache the sum of all votes. |
* VOTINGAPI_VALUE_TYPE_TOKEN -- 'Value' is a positive or negative int. The API will cache the sum of all votes. |
| 81 |
* VOTINGAPI_VALUE_TYPE_KEY -- 'Value' is a foreign key. The API will cache a vote-count for each discrete value. |
* VOTINGAPI_VALUE_TYPE_KEY -- 'Value' is a foreign key. The API will cache a vote-count for each discrete value. |
| 82 |
*/ |
*/ |
| 83 |
function _mediumvote_get_modes() { |
function _mediumvote_get_modes_array() { |
| 84 |
return array( |
return array( |
| 85 |
VOTINGAPI_VALUE_TYPE_PERCENT => t('Percentage (0-100)'), |
VOTINGAPI_VALUE_TYPE_PERCENT => t('Percentage (0-100)'), |
| 86 |
VOTINGAPI_VALUE_TYPE_TOKEN => t('Score (positive or negative)') |
VOTINGAPI_VALUE_TYPE_TOKEN => t('Score (positive or negative)') |
| 90 |
); |
); |
| 91 |
} |
} |
| 92 |
|
|
| 93 |
|
/** |
| 94 |
|
* Return voting mode for a node or comment |
| 95 |
|
* |
| 96 |
|
* @param $id |
| 97 |
|
* Element (node, comment) id. |
| 98 |
|
* @param $type |
| 99 |
|
* node or comment |
| 100 |
|
* @return |
| 101 |
|
* Voting mode for element |
| 102 |
|
*/ |
| 103 |
|
function _mediumvote_get_mode($id, $type) { |
| 104 |
|
$allow_override = variable_get('allow_override_'.$type, FALSE); |
| 105 |
|
if ($allow_override) { |
| 106 |
|
if ($type == VOTINGAPI_VALUE_NODE_CONTENT_TYPE) { |
| 107 |
|
$node = node_load(array('nid' => $id)); |
| 108 |
|
$mode = variable_get($type.'_mode_'.$node->type, VOTINGAPI_VALUE_TYPE_PERCENT); |
| 109 |
|
} |
| 110 |
|
elseif ($type == VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE) { |
| 111 |
|
$comment_result = _comment_load($id); |
| 112 |
|
$comment_nid = $comment_result->nid; |
| 113 |
|
$node = node_load(array('nid' => $comment_nid)); |
| 114 |
|
$mode = variable_get($type.'_mode_'.$node->type, VOTINGAPI_VALUE_TYPE_PERCENT); |
| 115 |
|
} |
| 116 |
|
else { |
| 117 |
|
$mode = variable_get($type.'_mode_all', VOTINGAPI_VALUE_TYPE_PERCENT); |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
else { |
| 121 |
|
$mode = variable_get($type.'_mode_all', VOTINGAPI_VALUE_TYPE_PERCENT); |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
return $mode; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
/** |
| 128 |
|
* Return voting tag for a node or comment |
| 129 |
|
* |
| 130 |
|
* @param $index |
| 131 |
|
* Tag number |
| 132 |
|
* @param $id |
| 133 |
|
* Element (node, comment) id. |
| 134 |
|
* @param $type |
| 135 |
|
* node or comment |
| 136 |
|
* @param $node |
| 137 |
|
* Either node, or node comment belongs to |
| 138 |
|
* @return |
| 139 |
|
* Voting tag for element at index |
| 140 |
|
*/ |
| 141 |
|
function _mediumvote_get_tag($index, $type, &$node) { |
| 142 |
|
$allow_override = variable_get('allow_override_'.$type, FALSE); |
| 143 |
|
if ($allow_override) { |
| 144 |
|
if ($type == VOTINGAPI_VALUE_NODE_CONTENT_TYPE) { |
| 145 |
|
$tag = variable_get($type.'_tag_'.$node->type.'_'.$index, ''); |
| 146 |
|
} |
| 147 |
|
elseif ($type == VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE) { |
| 148 |
|
$tag = variable_get($type.'_tag_'.$node->type.'_'.$index, ''); |
| 149 |
|
} |
| 150 |
|
else { |
| 151 |
|
$tag = variable_get($type.'_tag_'.$index, ''); |
| 152 |
|
} |
| 153 |
|
} |
| 154 |
|
else { |
| 155 |
|
$tag = variable_get($type.'_tag_'.$index, ''); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
return $tag; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
/** |
| 162 |
|
* Return an array of allow modes. |
| 163 |
|
*/ |
| 164 |
|
function _mediumvote_get_allow($type, $node_type) { |
| 165 |
|
$allow = array( |
| 166 |
|
MEDIUMVOTE_ALLOW => t('Allow').' '.($type?$type.' ':'').t('voting for'.' '.$node_type), |
| 167 |
|
MEDIUMVOTE_DENY => t('Deny').' '.($type?$type.' ':'').t('voting for'.' '.$node_type), |
| 168 |
|
); |
| 169 |
|
|
| 170 |
|
return $allow; |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
function mediumvote_configure_settings() { |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
|
| 177 |
/** |
/** |
| 178 |
* mediumvote settings page. |
* mediumvote settings page. |
| 179 |
*/ |
*/ |
| 180 |
function mediumvote_settings() { |
function mediumvote_configure() { |
| 181 |
|
|
| 182 |
$form['vote_settings'] = array( |
// default settings |
| 183 |
|
$form['default_settings'] = array( |
| 184 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 185 |
'#title' => t('Voting Settings'), |
'#title' => t('Default settings'), |
|
'#collapsible' => TRUE, |
|
|
'#collapsed' => TRUE, |
|
| 186 |
); |
); |
| 187 |
|
|
| 188 |
$form['vote_settings']['mediumvote_default_mode'] = array( |
// nodes defaults |
| 189 |
|
$form['default_settings']['node'] = array( |
| 190 |
|
'#type' => 'fieldset', |
| 191 |
|
'#title' => t('Nodes'), |
| 192 |
|
); |
| 193 |
|
|
| 194 |
|
$form['default_settings']['node']['allow_node_all'] = array( |
| 195 |
|
'#type' => 'radios', |
| 196 |
|
'#title' => t('Allow/Deny'), |
| 197 |
|
'#default_value' => variable_get('allow_node_all', MEDIUMVOTE_ALLOW), |
| 198 |
|
'#options' => _mediumvote_get_allow('', t('all nodes')) |
| 199 |
|
); |
| 200 |
|
|
| 201 |
|
$form['default_settings']['node']['node_mode_all'] = array( |
| 202 |
|
'#type' => 'radios', |
| 203 |
|
'#title' => t('Default Voting Mode'), |
| 204 |
|
'#default_value' => variable_get('node_mode_all', VOTINGAPI_VALUE_TYPE_PERCENT), |
| 205 |
|
'#options' => _mediumvote_get_modes_array(), |
| 206 |
|
'#description' => t('The default voting mode: Percentages or Raw Scores.'), |
| 207 |
|
); |
| 208 |
|
|
| 209 |
|
$form['default_settings']['node']['criteria'] = array( |
| 210 |
|
'#type' => 'fieldset', |
| 211 |
|
'#title' => t('Voting Criteria'), |
| 212 |
|
); |
| 213 |
|
|
| 214 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 215 |
|
$form['default_settings']['node']['criteria']['node_tag_'.$tag_count] = array( |
| 216 |
|
'#type' => 'textfield', |
| 217 |
|
'#title' => t('Tag').' '.$tag_count, |
| 218 |
|
'#default_value' => variable_get('node_tag_'.$tag_count, ''), |
| 219 |
|
'#size' => 25, |
| 220 |
|
'#maxlength' => 25 |
| 221 |
|
); |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
$form['default_settings']['node']['allow_override_node'] = array( |
| 225 |
|
'#type' => 'checkbox', |
| 226 |
|
'#title' => t('Allow node-specific override'), |
| 227 |
|
'#return_value' => 1, |
| 228 |
|
'#default_value' => variable_get('allow_override_node', FALSE), |
| 229 |
|
'#description' => t('If checked, node-specific settings below will override default values.') |
| 230 |
|
); |
| 231 |
|
|
| 232 |
|
// comments defaults |
| 233 |
|
$form['default_settings']['comment'] = array( |
| 234 |
|
'#type' => 'fieldset', |
| 235 |
|
'#title' => t('Comments'), |
| 236 |
|
); |
| 237 |
|
|
| 238 |
|
$form['default_settings']['comment']['allow_comment_all'] = array( |
| 239 |
'#type' => 'radios', |
'#type' => 'radios', |
| 240 |
'#title' => t('Default voting mode'), |
'#title' => t('Allow/Deny'), |
| 241 |
'#default_value' => variable_get('mediumvote_default_mode', VOTINGAPI_VALUE_TYPE_PERCENT), |
'#default_value' => variable_get('allow_comment_all', MEDIUMVOTE_ALLOW), |
| 242 |
'#options' => _mediumvote_get_modes(), |
'#options' => _mediumvote_get_allow('', t('all comments')) |
| 243 |
|
); |
| 244 |
|
|
| 245 |
|
$form['default_settings']['comment']['comment_mode_all'] = array( |
| 246 |
|
'#type' => 'radios', |
| 247 |
|
'#title' => t('Default Voting Mode'), |
| 248 |
|
'#default_value' => variable_get('comment_mode_all', VOTINGAPI_VALUE_TYPE_PERCENT), |
| 249 |
|
'#options' => _mediumvote_get_modes_array(), |
| 250 |
'#description' => t('The default voting mode: Percentages or Raw Scores.'), |
'#description' => t('The default voting mode: Percentages or Raw Scores.'), |
| 251 |
); |
); |
| 252 |
|
|
| 253 |
return $form; |
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 254 |
|
$form['default_settings']['comment']['criteria']['comment_tag_'.$tag_count] = array( |
| 255 |
|
'#type' => 'textfield', |
| 256 |
|
'#title' => t('Tag').' '.$tag_count, |
| 257 |
|
'#default_value' => variable_get('comment_tag_'.$tag_count, ''), |
| 258 |
|
'#size' => 25, |
| 259 |
|
'#maxlength' => 25 |
| 260 |
|
); |
| 261 |
|
} |
| 262 |
|
|
| 263 |
|
$form['default_settings']['comment']['allow_override_comment'] = array( |
| 264 |
|
'#type' => 'checkbox', |
| 265 |
|
'#title' => t('Allow node-specific override for comments'), |
| 266 |
|
'#return_value' => 1, |
| 267 |
|
'#default_value' => variable_get('allow_override_comment', FALSE), |
| 268 |
|
'#description' => t('If checked, node-specific settings below will override default values.') |
| 269 |
|
); |
| 270 |
|
|
| 271 |
|
// if override of node or comments is allowed |
| 272 |
|
// show node-specific settings |
| 273 |
|
if (variable_get('allow_override_node', FALSE) OR variable_get('allow_override_comment', FALSE)) { |
| 274 |
|
|
| 275 |
|
// node-specific settings |
| 276 |
|
$form['allow_votes'] = array( |
| 277 |
|
'#type' => 'fieldset', |
| 278 |
|
'#title' => t('Node-specific settings'), |
| 279 |
|
); |
| 280 |
|
|
| 281 |
|
foreach(node_get_types() as $type => $name) { |
| 282 |
|
|
| 283 |
|
$form['allow_votes'][$type] = array( |
| 284 |
|
'#type' => 'fieldset', |
| 285 |
|
'#title' => $name, |
| 286 |
|
'#collapsible' => TRUE, |
| 287 |
|
'#collapsed' => TRUE, |
| 288 |
|
); |
| 289 |
|
|
| 290 |
|
if (variable_get('allow_override_node', FALSE)) { |
| 291 |
|
// node |
| 292 |
|
$form['allow_votes'][$type]['node'] = array( |
| 293 |
|
'#type' => 'fieldset', |
| 294 |
|
'#title' => t('Node'), |
| 295 |
|
); |
| 296 |
|
|
| 297 |
|
$form['allow_votes'][$type]['node']['allow_node_'.$type] = array( |
| 298 |
|
'#type' => 'radios', |
| 299 |
|
'#title' => t('Allow/Deny'), |
| 300 |
|
'#default_value' => variable_get('allow_node_'.$type, MEDIUMVOTE_ALLOW), |
| 301 |
|
'#options' => _mediumvote_get_allow(t('node'), $name) |
| 302 |
|
); |
| 303 |
|
|
| 304 |
|
$form['allow_votes'][$type]['node']['node_mode_'.$type] = array( |
| 305 |
|
'#type' => 'radios', |
| 306 |
|
'#title' => t('Voting Mode'), |
| 307 |
|
'#default_value' => variable_get('node_mode_'.$type, VOTINGAPI_VALUE_TYPE_PERCENT), |
| 308 |
|
'#options' => _mediumvote_get_modes_array(), |
| 309 |
|
'#description' => t('The default voting mode: Percentages or Raw Scores.'), |
| 310 |
|
); |
| 311 |
|
|
| 312 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 313 |
|
$form['allow_votes'][$type]['node']['criteria']['node_tag_'.$type.'_'.$tag_count] = array( |
| 314 |
|
'#type' => 'textfield', |
| 315 |
|
'#title' => t('Tag').' '.$tag_count, |
| 316 |
|
'#default_value' => variable_get('node_tag_'.$type.'_'.$tag_count, ''), |
| 317 |
|
'#size' => 25, |
| 318 |
|
'#maxlength' => 25 |
| 319 |
|
); |
| 320 |
|
} |
| 321 |
|
} |
| 322 |
|
else { |
| 323 |
|
// clear variables |
| 324 |
|
variable_set('allow_node_'.$type, MEDIUMVOTE_DENY); |
| 325 |
|
variable_set('node_mode_'.$type, VOTINGAPI_VALUE_TYPE_PERCENT); |
| 326 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 327 |
|
variable_set('node_tag_'.$type.'_'.$tag_count, ''); |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
} // end if node override |
| 331 |
|
|
| 332 |
|
if (variable_get('allow_override_comment', FALSE)) { |
| 333 |
|
// comments |
| 334 |
|
$form['allow_votes'][$type]['comment'] = array( |
| 335 |
|
'#type' => 'fieldset', |
| 336 |
|
'#title' => t('Comments'), |
| 337 |
|
); |
| 338 |
|
|
| 339 |
|
$form['allow_votes'][$type]['comment']['allow_comment_'.$type] = array( |
| 340 |
|
'#type' => 'radios', |
| 341 |
|
'#title' => t('Allow/Deny'), |
| 342 |
|
'#default_value' => variable_get('allow_comment_'.$type, MEDIUMVOTE_ALLOW), |
| 343 |
|
'#options' => _mediumvote_get_allow(t('comment'), $name) |
| 344 |
|
); |
| 345 |
|
|
| 346 |
|
$form['allow_votes'][$type]['comment']['comment_mode_'.$type] = array( |
| 347 |
|
'#type' => 'radios', |
| 348 |
|
'#title' => t('Voting Mode'), |
| 349 |
|
'#default_value' => variable_get('comment_mode_'.$type, VOTINGAPI_VALUE_TYPE_PERCENT), |
| 350 |
|
'#options' => _mediumvote_get_modes_array(), |
| 351 |
|
'#description' => t('The default voting mode: Percentages or Raw Scores.'), |
| 352 |
|
); |
| 353 |
|
|
| 354 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 355 |
|
$form['allow_votes'][$type]['comment']['criteria']['comment_tag_'.$type.'_'.$tag_count] = array( |
| 356 |
|
'#type' => 'textfield', |
| 357 |
|
'#title' => t('Tag').' '.$tag_count, |
| 358 |
|
'#default_value' => variable_get('comment_tag_'.$type.'_'.$tag_count, ''), |
| 359 |
|
'#size' => 25, |
| 360 |
|
'#maxlength' => 25 |
| 361 |
|
); |
| 362 |
|
} |
| 363 |
|
} |
| 364 |
|
else { |
| 365 |
|
// clear variables |
| 366 |
|
variable_set('allow_comment_'.$type, MEDIUMVOTE_DENY); |
| 367 |
|
variable_set('comment_mode_'.$type, VOTINGAPI_VALUE_TYPE_PERCENT); |
| 368 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 369 |
|
variable_set('comment_tag_'.$type.'_'.$tag_count, ''); |
| 370 |
|
} |
| 371 |
|
} // end if comment override |
| 372 |
|
|
| 373 |
|
} // end foreach node type |
| 374 |
|
|
| 375 |
|
} |
| 376 |
|
else { |
| 377 |
|
// clear variables |
| 378 |
|
foreach(node_get_types() as $type => $name) { |
| 379 |
|
variable_set('allow_node_'.$type, MEDIUMVOTE_DENY); |
| 380 |
|
variable_set('node_mode_'.$type, VOTINGAPI_VALUE_TYPE_PERCENT); |
| 381 |
|
variable_set('allow_comment_'.$type, MEDIUMVOTE_DENY); |
| 382 |
|
variable_set('comment_mode_'.$type, VOTINGAPI_VALUE_TYPE_PERCENT); |
| 383 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 384 |
|
variable_set('node_tag_'.$type.'_'.$tag_count, ''); |
| 385 |
|
variable_set('comment_tag_'.$type.'_'.$tag_count, ''); |
| 386 |
|
} |
| 387 |
|
} |
| 388 |
|
} // end if override |
| 389 |
|
|
| 390 |
|
return system_settings_form('mediumvote_configure_settings', $form); |
| 391 |
|
|
| 392 |
} |
} |
| 393 |
|
|
| 394 |
function mediumvote_vote($type, $tag = VOTINGAPI_VALUE_DEFAULT_TAG, $cid, $value) { |
function mediumvote_vote($type, $tag = VOTINGAPI_VALUE_DEFAULT_TAG, $cid, $value) { |
| 395 |
|
|
| 396 |
$mode = variable_get('mediumvote_default_mode', VOTINGAPI_VALUE_TYPE_PERCENT); |
$mode = _mediumvote_get_mode($cid, $type); |
| 397 |
|
|
| 398 |
if ($mode == VOTINGAPI_VALUE_TYPE_PERCENT) { |
if ($mode == VOTINGAPI_VALUE_TYPE_PERCENT) { |
| 399 |
// sanity-check the incoming values. |
// sanity-check the incoming values. |
| 436 |
$id = arg(3); |
$id = arg(3); |
| 437 |
$score = arg(4); |
$score = arg(4); |
| 438 |
|
|
| 439 |
$mode = variable_get('mediumvote_default_mode', VOTINGAPI_VALUE_TYPE_PERCENT); |
$mode = _mediumvote_get_mode($id, $content_type); |
| 440 |
|
|
|
$print_extra = ''; |
|
| 441 |
if ($mode == VOTINGAPI_VALUE_TYPE_PERCENT) { |
if ($mode == VOTINGAPI_VALUE_TYPE_PERCENT) { |
| 442 |
$function = 'average'; |
$function = 'average'; |
|
if ($tag == VOTINGAPI_VALUE_DEFAULT_TAG) { |
|
|
$print_extra = t('Rating') . ' '; |
|
|
} |
|
| 443 |
} |
} |
| 444 |
else { |
else { |
| 445 |
$function = 'sum'; |
$function = 'sum'; |
|
if ($tag == VOTINGAPI_VALUE_DEFAULT_TAG) { |
|
|
$print_extra = t('Score') . ' '; |
|
|
} |
|
| 446 |
} |
} |
| 447 |
|
|
| 448 |
// add the vote |
// add the vote |
| 456 |
$vote = votingapi_get_voting_result($content_type, $id, $mode, $tag, $function); |
$vote = votingapi_get_voting_result($content_type, $id, $mode, $tag, $function); |
| 457 |
|
|
| 458 |
// send the results back |
// send the results back |
| 459 |
print $print_extra.'(' . $vote->value . ')'; |
print $tag.' (' . $vote->value . ')'; |
| 460 |
|
|
| 461 |
exit(); |
exit(); |
| 462 |
} |
} |
| 466 |
|
|
| 467 |
global $user; |
global $user; |
| 468 |
|
|
| 469 |
$mode = variable_get('mediumvote_default_mode', VOTINGAPI_VALUE_TYPE_PERCENT); |
$mode = _mediumvote_get_mode($cid, $type); |
| 470 |
|
|
| 471 |
// if user is logged in, get votes already cast |
// if user is logged in, get votes already cast |
| 472 |
$user_vote = ''; |
$user_vote = ''; |
| 489 |
switch ($type) |
switch ($type) |
| 490 |
{ |
{ |
| 491 |
case VOTINGAPI_VALUE_NODE_CONTENT_TYPE: |
case VOTINGAPI_VALUE_NODE_CONTENT_TYPE: |
| 492 |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">' . t("Rating") . ' (' . $stars . ')'; |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">' . $tag . ' (' . $stars . ')'; |
| 493 |
break; |
break; |
| 494 |
case VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE: |
case VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE: |
| 495 |
default: |
default: |
| 496 |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">(' . $stars . ')'; |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">' . $tag . ' (' . $stars . ')'; |
| 497 |
break; |
break; |
| 498 |
} |
} |
| 499 |
|
|
| 520 |
switch ($type) |
switch ($type) |
| 521 |
{ |
{ |
| 522 |
case VOTINGAPI_VALUE_NODE_CONTENT_TYPE: |
case VOTINGAPI_VALUE_NODE_CONTENT_TYPE: |
| 523 |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">' . t("Score") . ' (' . $score . ')'; |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">' . $tag . ' (' . $score . ')'; |
| 524 |
break; |
break; |
| 525 |
case VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE: |
case VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE: |
| 526 |
default: |
default: |
| 527 |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">(' . $score . ')'; |
$output .= '<span class="score" id="score_' . $tag . '_' . $cid .'">' . $tag . ' (' . $score . ')'; |
| 528 |
break; |
break; |
| 529 |
} |
} |
| 530 |
|
|
| 531 |
// add positive vote |
// add positive vote |
| 532 |
$output .= theme('mediumvote_icon', $type, $cid, 1, false, $tag, $mode, $user_vote); |
$output .= theme('mediumvote_icon', $type, $cid, 1, FALSE, $tag, $mode, $user_vote); |
| 533 |
// add negative vote |
// add negative vote |
| 534 |
$output .= theme('mediumvote_icon', $type, $cid, -1, false, $tag, $mode, $user_vote); |
$output .= theme('mediumvote_icon', $type, $cid, -1, FALSE, $tag, $mode, $user_vote); |
| 535 |
|
|
| 536 |
$output .= '</span>'; |
$output .= '</span>'; |
| 537 |
|
|
| 606 |
} |
} |
| 607 |
|
|
| 608 |
function theme_mediumvote_css_path() { |
function theme_mediumvote_css_path() { |
| 609 |
|
// depending on installation this path may require a preceding / |
| 610 |
|
// return '/' . drupal_get_path('module', 'mediumvote') . '/theme/mediumvote.css'; |
| 611 |
|
|
| 612 |
return drupal_get_path('module', 'mediumvote') . '/theme/mediumvote.css'; |
return drupal_get_path('module', 'mediumvote') . '/theme/mediumvote.css'; |
| 613 |
} |
} |
| 614 |
|
|
| 615 |
function mediumvote_nodeapi(&$node, $op, $teaser, $page) { |
function mediumvote_nodeapi(&$node, $op, $teaser, $page) { |
| 616 |
switch ($op) { |
|
| 617 |
case 'view': |
$path = drupal_get_path('module', 'mediumvote'); |
| 618 |
if ($teaser == false) { |
drupal_add_js($path . '/theme/ajax_mediumvote.js'); |
| 619 |
$node->body = theme('mediumvote_widget', $node->nid, VOTINGAPI_VALUE_NODE_CONTENT_TYPE) . $node->body; |
|
| 620 |
} |
$allow_all = variable_get('allow_node_all', FALSE); |
| 621 |
break; |
$allow_override = variable_get('allow_override_node', FALSE); |
| 622 |
|
$allow_node_type = variable_get('allow_node_'.$node->type, FALSE); |
| 623 |
|
|
| 624 |
|
if ($allow_all OR ($allow_override AND $allow_node_type)) { |
| 625 |
|
switch ($op) { |
| 626 |
|
case 'view': |
| 627 |
|
if ($teaser == FALSE) { |
| 628 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 629 |
|
$tag = _mediumvote_get_tag($tag_count, VOTINGAPI_VALUE_NODE_CONTENT_TYPE, $node); |
| 630 |
|
if ($tag) { |
| 631 |
|
$node->body = theme('mediumvote_widget', $node->nid, VOTINGAPI_VALUE_NODE_CONTENT_TYPE, $tag) . $node->body; |
| 632 |
|
} |
| 633 |
|
} |
| 634 |
|
} |
| 635 |
|
break; |
| 636 |
|
} |
| 637 |
} |
} |
| 638 |
} |
} |
| 639 |
|
|
| 640 |
function mediumvote_comment(&$comment, $op) { |
function mediumvote_comment(&$comment, $op) { |
|
switch ($op) { |
|
|
case 'view': |
|
| 641 |
|
|
| 642 |
$path = drupal_get_path('module', 'mediumvote'); |
$path = drupal_get_path('module', 'mediumvote'); |
| 643 |
drupal_add_js($path . '/theme/ajax_mediumvote.js'); |
drupal_add_js($path . '/theme/ajax_mediumvote.js'); |
| 644 |
|
|
| 645 |
// add 2 criteria on comments |
// get comment's node to see if comment voting |
| 646 |
$comment->comment = theme('mediumvote_widget', $comment->cid, VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE, VOTINGAPI_COMMENT_TAG_TAG1) . |
// is allowed for node type |
| 647 |
theme('mediumvote_widget', $comment->cid, VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE, VOTINGAPI_COMMENT_TAG_TAG2) . |
$node = node_load(array('nid' => $comment->nid)); |
| 648 |
$comment->comment; |
|
| 649 |
|
$allow_all = variable_get('allow_comment_all', FALSE); |
| 650 |
|
$allow_override = variable_get('allow_override_comment', FALSE); |
| 651 |
|
$allow_node_type = variable_get('allow_comment_'.$node->type, FALSE); |
| 652 |
|
|
| 653 |
|
if ($allow_all OR ($allow_override AND $allow_node_type)) { |
| 654 |
|
switch ($op) { |
| 655 |
|
case 'view': |
| 656 |
|
|
| 657 |
|
for ($tag_count = 1; $tag_count <= NUM_VOTING_CRITERIA; $tag_count++) { |
| 658 |
|
$tag = _mediumvote_get_tag($tag_count, VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE, $node); |
| 659 |
|
if ($tag) { |
| 660 |
|
$comment->comment = theme('mediumvote_widget', $node->nid, VOTINGAPI_VALUE_COMMENT_CONTENT_TYPE, $tag) . $comment->comment; |
| 661 |
|
} |
| 662 |
|
} |
| 663 |
|
|
| 664 |
break; |
break; |
| 665 |
} |
} |
| 666 |
|
} // end if voting allowed |
| 667 |
} |
} |