| 1 |
<?php |
<?php |
| 2 |
// $Id: nmoderation.module,v 1.29 2006/06/09 00:17:18 eaton Exp $ |
// $Id: nmoderation.module,v 1.30 2006/06/20 20:40:30 eaton Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 21 |
} |
} |
| 22 |
|
|
| 23 |
function nmoderation_menu($may_cache) { |
function nmoderation_menu($may_cache) { |
| 24 |
|
|
| 25 |
|
$items[] = array( |
| 26 |
|
'path' => 'admin/settings/nmoderation', |
| 27 |
|
'title' => t('Nmoderation'), |
| 28 |
|
'description' => t('Moderate nodes.'), |
| 29 |
|
'callback' => 'drupal_get_form', |
| 30 |
|
'callback arguments' => array('nmoderation_admin_settings'), |
| 31 |
|
'access' => user_access('administer site configuration'), |
| 32 |
|
'type' => MENU_NORMAL_ITEM, // optional |
| 33 |
|
); |
| 34 |
|
|
| 35 |
if ($may_cache) { |
if ($may_cache) { |
| 36 |
$access = user_access('administer node moderation votes'); |
$access = user_access('administer node moderation votes'); |
| 37 |
$items[] = array('path' => 'admin/nmoderation', 'title' => t('node moderation'), |
$items[] = array('path' => 'admin/nmoderation', 'title' => t('node moderation'), |
| 62 |
'callback' => 'nmoderation_list_all', 'weight' => 5, 'access' => user_access('administer node moderation votes')); |
'callback' => 'nmoderation_list_all', 'weight' => 5, 'access' => user_access('administer node moderation votes')); |
| 63 |
} |
} |
| 64 |
else { |
else { |
| 65 |
if (arg(0) == 'node' && is_numeric(arg(1))) { |
if (arg(0) == 'node' && is_numeric(arg(1))) { |
| 66 |
$access = user_access('administer node moderation votes') || user_access('view node moderation votes'); |
$access = user_access('administer node moderation votes') || user_access('view node moderation votes'); |
| 67 |
$items[] = array('path' => 'node/'. arg(1). '/nmoderation', 'title' => t('votes'), |
$items[] = array('path' => 'node/'. arg(1). '/nmoderation', 'title' => t('votes'), |
| 68 |
'type' => MENU_LOCAL_TASK, 'callback' => 'nmoderation_list_node', 'weight' => 5, 'access' => $access, 'callback arguments' => array(arg(1))); |
'type' => MENU_LOCAL_TASK, 'callback' => 'nmoderation_list_node', 'weight' => 5, 'access' => $access, 'callback arguments' => array(arg(1))); |
| 69 |
} |
} |
| 124 |
|
|
| 125 |
function nmoderation_matrix_settings() { |
function nmoderation_matrix_settings() { |
| 126 |
$output .= '<h3>Node Moderation vote/value matrix</h3>'; |
$output .= '<h3>Node Moderation vote/value matrix</h3>'; |
| 127 |
|
$output .= drupal_get_form('nmoderation_matrix_settings_form', $form_id); |
| 128 |
|
return $output; |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
function nmoderation_matrix_settings_form() { |
| 132 |
$result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate nodes%'"); |
$result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate nodes%'"); |
| 133 |
$role_names = array(); |
$role_names = array(); |
| 134 |
while ($role = db_fetch_object($result)) { |
while ($role = db_fetch_object($result)) { |
| 168 |
'#value' => $role_names, |
'#value' => $role_names, |
| 169 |
); |
); |
| 170 |
|
|
| 171 |
$output .= drupal_get_form('nmoderation_matrix_form', $form); |
return $form; |
|
return $output; |
|
| 172 |
} |
} |
| 173 |
|
|
| 174 |
function nmoderation_matrix_form_submit($form_id, $form_values) { |
function nmoderation_matrix_settings_form_submit($form_id, $form_values) { |
| 175 |
// db_query('DELETE FROM {nmoderation_roles} '); |
// db_query('DELETE FROM {nmoderation_roles} '); |
| 176 |
foreach (element_children($form_values['votes']) as $mid) { |
foreach (element_children($form_values['votes']) as $mid) { |
| 177 |
foreach (element_children($form_values['votes'][$mid]) as $rid) { |
foreach (element_children($form_values['votes'][$mid]) as $rid) { |
| 184 |
drupal_set_message(t('the vote values have been saved.')); |
drupal_set_message(t('the vote values have been saved.')); |
| 185 |
} |
} |
| 186 |
|
|
| 187 |
function theme_nmoderation_matrix_form(&$form) { |
function theme_nmoderation_matrix__settings_form(&$form) { |
| 188 |
$role_names = $form['role_names']['#value']; |
$role_names = $form['role_names']['#value']; |
| 189 |
$header = array_merge(array(t('votes')), array_values($role_names)); |
$header = array_merge(array(t('votes')), array_values($role_names)); |
| 190 |
|
|
| 191 |
foreach (element_children($form['votes']) as $mid) { |
foreach (element_children($form['votes']) as $mid) { |
| 192 |
$row = array(); |
$row = array(); |
| 193 |
foreach (element_children($form['votes'][$mid]) as $rid) { |
foreach (element_children($form['votes'][$mid]) as $rid) { |
| 194 |
$row[] = form_render($form['votes'][$mid][$rid]); |
$row[] = drupal_render($form['votes'][$mid][$rid]); |
| 195 |
} |
} |
| 196 |
$rows[] = $row; |
$rows[] = $row; |
| 197 |
} |
} |
| 202 |
} |
} |
| 203 |
|
|
| 204 |
$output = theme('table', $header, $rows); |
$output = theme('table', $header, $rows); |
| 205 |
$output .= form_render($form); |
$output .= drupal_render($form); |
| 206 |
return $output; |
return $output; |
| 207 |
} |
} |
| 208 |
|
|
| 211 |
*/ |
*/ |
| 212 |
function nmoderation_role_settings() { |
function nmoderation_role_settings() { |
| 213 |
$output .= '<h3>Initial node scores</h3>'; |
$output .= '<h3>Initial node scores</h3>'; |
| 214 |
|
$output .= drupal_get_form('nmoderation_role_settings_form', $form_id); |
| 215 |
|
return $output; |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
function nmoderation_role_settings_form() { |
| 219 |
$start_values = variable_get('nmoderation_roles', array()); |
$start_values = variable_get('nmoderation_roles', array()); |
| 220 |
|
|
| 221 |
$result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate nodes%' ORDER BY r.rid"); |
$result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate nodes%' ORDER BY r.rid"); |
| 235 |
'#value' => t('Save scores') |
'#value' => t('Save scores') |
| 236 |
); |
); |
| 237 |
|
|
| 238 |
$output .= drupal_get_form('nmoderation_role_form', $form); |
return $form; |
|
return $output; |
|
| 239 |
} |
} |
| 240 |
|
|
| 241 |
function nmoderation_role_form_validate($form_id, $form_values) { |
function nmoderation_role_settings_form_validate($form_id, $form_values) { |
| 242 |
// make sure everything is numeric/int |
// make sure everything is numeric/int |
| 243 |
} |
} |
| 244 |
|
|
| 245 |
function nmoderation_role_form_submit($form_id, $form_values) { |
function nmoderation_role_settings_form_submit($form_id, $form_values) { |
| 246 |
$new_values = array(); |
$new_values = array(); |
| 247 |
foreach (element_children($form_values['role']) as $rid) { |
foreach (element_children($form_values['role']) as $rid) { |
| 248 |
$new_values[$rid] = $form_values['role'][$rid]['#value']; |
$new_values[$rid] = $form_values['role'][$rid]['#value']; |
| 251 |
drupal_set_message(t('the node moderation scores have been saved.')); |
drupal_set_message(t('the node moderation scores have been saved.')); |
| 252 |
} |
} |
| 253 |
|
|
| 254 |
function theme_nmoderation_role_form(&$form) { |
function theme_nmoderation_role_settings_form(&$form) { |
| 255 |
$header = array(t('user role'), t('initial score')); |
$header = array(t('user role'), t('initial score')); |
| 256 |
|
|
| 257 |
$rows = array(); |
$rows = array(); |
| 259 |
$row = array(); |
$row = array(); |
| 260 |
$row[] = $form['role'][$rid]['#title']; |
$row[] = $form['role'][$rid]['#title']; |
| 261 |
unset($form['role'][$rid]['#title']); |
unset($form['role'][$rid]['#title']); |
| 262 |
$row[] = form_render($form['role'][$rid]); |
$row[] = drupal_render($form['role'][$rid]); |
| 263 |
$rows[] = $row; |
$rows[] = $row; |
| 264 |
} |
} |
| 265 |
|
|
| 266 |
$output = theme('table', $header, $rows); |
$output = theme('table', $header, $rows); |
| 267 |
$output .= form_render($form); |
$output .= drupal_render($form); |
| 268 |
return $output; |
return $output; |
| 269 |
} |
} |
| 270 |
|
|
| 271 |
/** |
/** |
| 272 |
* Menu callback; displays page for assigning names to vote values. |
* Menu callback; displays page for assigning names to vote values. |
| 273 |
*/ |
*/ |
| 274 |
function nmoderation_vote_settings() { |
|
| 275 |
|
function nmoderation_vote_settings() { |
| 276 |
$output .= '<h3>'. t('Node moderation votes overview') .'</h3>'; |
$output .= '<h3>'. t('Node moderation votes overview') .'</h3>'; |
| 277 |
|
$output = drupal_get_form('nmoderation_vote_settings_form', $form_id); |
| 278 |
|
return $output; |
| 279 |
|
} |
| 280 |
|
|
| 281 |
|
function nmoderation_vote_settings_form() { |
| 282 |
|
|
| 283 |
// load up and show any vote types previously defined. |
// load up and show any vote types previously defined. |
| 284 |
$result = db_query('SELECT mid, vote, weight FROM {nmoderation_votes} ORDER BY weight'); |
$result = db_query('SELECT mid, vote, weight FROM {nmoderation_votes} ORDER BY weight'); |
| 325 |
'#value' => t('Save changes'), |
'#value' => t('Save changes'), |
| 326 |
); |
); |
| 327 |
|
|
| 328 |
$output = drupal_get_form('nmoderation_vote_form', $form); |
return $form; |
|
return $output; |
|
| 329 |
} |
} |
| 330 |
|
|
| 331 |
function nmoderation_vote_form_validate($form_id, $form_values) { |
function nmoderation_vote_settings_form_validate($form_id, $form_values) { |
| 332 |
// make sure $weight is an int and $vote is markup clean, no injections. |
// make sure $weight is an int and $vote is markup clean, no injections. |
| 333 |
} |
} |
| 334 |
|
|
| 335 |
function nmoderation_vote_form_submit($form_id, $form_values) { |
function nmoderation_vote_settings_form_submit($form_id, $form_values) { |
| 336 |
// loop through the fields for old votes, update or delete as necessary. |
// loop through the fields for old votes, update or delete as necessary. |
| 337 |
foreach (element_children($form_values['old']) as $mid) { |
foreach (element_children($form_values['old']) as $mid) { |
| 338 |
if ($form_values['old'][$mid]['delete'] == 1) { |
if ($form_values['old'][$mid]['delete'] == 1) { |
| 353 |
drupal_goto('admin/nmoderation/votes'); // do this because we want the form completely rebuilt. |
drupal_goto('admin/nmoderation/votes'); // do this because we want the form completely rebuilt. |
| 354 |
} |
} |
| 355 |
|
|
| 356 |
function theme_nmoderation_vote_form(&$form) { |
function theme_nmoderation_vote_settings_form(&$form) { |
| 357 |
$header = array(t('votes'), t('weight'), t('delete')); |
$header = array(t('votes'), t('weight'), t('delete')); |
| 358 |
|
|
| 359 |
// render the existing-vote fields. |
// render the existing-vote fields. |
| 360 |
foreach (element_children($form['old']) as $mid) { |
foreach (element_children($form['old']) as $mid) { |
| 361 |
$row = array(); |
$row = array(); |
| 362 |
$row[] = form_render($form['old'][$mid]['vote']); |
$row[] = drupal_render($form['old'][$mid]['vote']); |
| 363 |
$row[] = form_render($form['old'][$mid]['weight']); |
$row[] = drupal_render($form['old'][$mid]['weight']); |
| 364 |
$row[] = form_render($form['old'][$mid]['delete']); |
$row[] = drupal_render($form['old'][$mid]['delete']); |
| 365 |
$rows[] = $row; |
$rows[] = $row; |
| 366 |
} |
} |
| 367 |
|
|
| 368 |
// render the add-a-vote fields. |
// render the add-a-vote fields. |
| 369 |
$row = array(); |
$row = array(); |
| 370 |
$row[] = form_render($form['new']['vote']); |
$row[] = drupal_render($form['new']['vote']); |
| 371 |
$row[] = form_render($form['new']['weight']); |
$row[] = drupal_render($form['new']['weight']); |
| 372 |
$row[] = ''; |
$row[] = ''; |
| 373 |
$rows[] = $row; |
$rows[] = $row; |
| 374 |
|
|
| 375 |
$output .= theme('table', $header, $rows); |
$output .= theme('table', $header, $rows); |
| 376 |
$output .= form_render($form); |
$output .= drupal_render($form); |
| 377 |
|
return $output; |
| 378 |
|
} |
| 379 |
|
|
| 380 |
|
function nmoderation_moderation($content_type, $content_id, $vote, $title= NULL) { |
| 381 |
|
$output = drupal_get_form('nmoderation_moderation_form', $form_id, $content_type, $content_id, $vote, $title= NULL); |
| 382 |
return $output; |
return $output; |
| 383 |
} |
} |
| 384 |
|
|
| 385 |
function nmoderation_get_moderation_form($content_type, $content_id, $vote, $title= NULL) { |
function nmoderation_moderation_form($content_type, $content_id, $vote, $title= NULL) { |
| 386 |
global $user; |
global $user; |
| 387 |
static $votes; |
static $votes; |
| 388 |
|
|
| 469 |
function theme_nmoderation_moderation_form($form) { |
function theme_nmoderation_moderation_form($form) { |
| 470 |
// We aren't actually going to do anything fancy, but it's here |
// We aren't actually going to do anything fancy, but it's here |
| 471 |
// in case folks want to override it for a given theme. |
// in case folks want to override it for a given theme. |
| 472 |
$output = form_render($form); |
$output = drupal_render($form); |
| 473 |
return $output; |
return $output; |
| 474 |
} |
} |
| 475 |
|
|
| 492 |
// may only edit own vote if you are not an admin |
// may only edit own vote if you are not an admin |
| 493 |
if ($user->uid == $vote->uid || user_access('administer node moderation votes')) { |
if ($user->uid == $vote->uid || user_access('administer node moderation votes')) { |
| 494 |
$node = node_load($vote->content_id); |
$node = node_load($vote->content_id); |
| 495 |
$form = nmoderation_get_moderation_form('node', $node->nid, $vote, t('Edit vote')); |
$form = nmoderation_moderation_form('node', $node->nid, $vote, t('Edit vote')); |
| 496 |
|
|
| 497 |
if ($vote->uid != $user->uid) { |
if ($vote->uid != $user->uid) { |
| 498 |
$form['username'] = array( |
$form['username'] = array( |
| 510 |
'#weight' => -1, |
'#weight' => -1, |
| 511 |
); |
); |
| 512 |
|
|
| 513 |
$output .= drupal_get_form('nmoderation_moderation_form', $form); |
//$output .= drupal_get_form('nmoderation_moderation_form'); |
| 514 |
|
$output .= drupal_get_form('nmoderation_moderation_form', 'node', $node->nid, $vote, t('Edit vote')); |
| 515 |
return $output; |
return $output; |
| 516 |
} |
} |
| 517 |
else { |
else { |
| 522 |
function nmoderation_uservote_delete($vote_id) { |
function nmoderation_uservote_delete($vote_id) { |
| 523 |
$form['vote_id'] = array('#type' => 'value', '#value' => $vote_id); |
$form['vote_id'] = array('#type' => 'value', '#value' => $vote_id); |
| 524 |
$output = confirm_form( |
$output = confirm_form( |
| 525 |
'nmoderation_delete_confirm', |
//'nmoderation_delete_confirm', |
| 526 |
$form, |
$form, |
| 527 |
t('Are you sure you want to delete this vote?'), |
t('Are you sure you want to delete this vote?'), |
| 528 |
$_GET['destination'] ? $_GET['destination'] : 'nmoderation/voted', |
$_GET['destination'] ? $_GET['destination'] : 'nmoderation/voted', |
| 530 |
t('Delete Vote'), |
t('Delete Vote'), |
| 531 |
t('Cancel') |
t('Cancel') |
| 532 |
); |
); |
| 533 |
|
var_export($output); |
| 534 |
return $output; |
return $output; |
| 535 |
} |
} |
| 536 |
|
|
| 581 |
); |
); |
| 582 |
$cols = 2; |
$cols = 2; |
| 583 |
$title = t('my unmoderated nodes'); |
$title = t('my unmoderated nodes'); |
| 584 |
$types = implode("','", variable_get('nmoderation_node_types', array_flip(node_get_types()))); |
$types = implode("','", variable_get('nmoderation_node_types', node_get_types())); |
| 585 |
$sql = "SELECT n.nid, n.created, u.name, n.title, n.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {votingapi_vote} v ON n.nid = v.content_id AND v.content_type = '$content_type' AND v.uid = $user->uid WHERE n.type IN ('$types') AND n.status = 1 AND ISNULL(v.vote_id)"; |
$sql = "SELECT n.nid, n.created, u.name, n.title, n.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {votingapi_vote} v ON n.nid = v.content_id AND v.content_type = '$content_type' AND v.uid = $user->uid WHERE n.type IN ('$types') AND n.status = 1 AND ISNULL(v.vote_id)"; |
| 586 |
$min = time()-24*3600*variable_get('nmoderation_vote_interval', 7); |
$min = time()-24*3600*variable_get('nmoderation_vote_interval', 7); |
| 587 |
$sql .= " AND n.created > $min"; |
$sql .= " AND n.created > $min"; |
| 707 |
return $output; |
return $output; |
| 708 |
} |
} |
| 709 |
|
|
| 710 |
function nmoderation_settings() { |
function nmoderation_admin_settings() { |
| 711 |
$promote = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100)); |
$promote = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100)); |
| 712 |
$unpublish = drupal_map_assoc(array(-1, -2, -3, -4, -5, -6, -7, -8, -8, -10, -11, -12, -13, -14, -15, -20, -25, -30)); |
$unpublish = drupal_map_assoc(array(-1, -2, -3, -4, -5, -6, -7, -8, -8, -10, -11, -12, -13, -14, -15, -20, -25, -30, -100)); |
| 713 |
$interval = drupal_map_assoc(range(1,60)); |
$interval = drupal_map_assoc(range(1,60)); |
| 714 |
|
|
| 715 |
$form['nmoderation_node_types'] = array( |
$form['nmoderation_node_types'] = array( |
| 716 |
'#type' => 'select', |
'#type' => 'select', |
| 717 |
'#title' => t('Node Types'), |
'#title' => t('Node Types'), |
| 718 |
'#default_value' => variable_get('nmoderation_node_types', node_get_types()), |
'#default_value' => variable_get('nmoderation_node_types', node_get_types()), |
| 719 |
'#options' => node_get_types(), |
'#options' => node_get_types('names'), |
| 720 |
'#description' => t('Select the node types upon which accept node moderation votes.'), |
'#description' => t('Select the node types upon which accept node moderation votes.'), |
| 721 |
'#extra' => 0, |
'#extra' => 0, |
| 722 |
'#multiple' => 1, |
'#multiple' => 1, |
| 743 |
'#description' => t('The number of days since the creation of a node when we allow voting.'), |
'#description' => t('The number of days since the creation of a node when we allow voting.'), |
| 744 |
); |
); |
| 745 |
|
|
| 746 |
return $form; |
return system_settings_form($form); |
| 747 |
} |
} |
| 748 |
|
|
| 749 |
|
|
| 772 |
else { |
else { |
| 773 |
$title = t('Add vote'); |
$title = t('Add vote'); |
| 774 |
} |
} |
| 775 |
if ($frm = nmoderation_get_moderation_form('node', $node->nid, $vote, $title)) { |
$node->content['body']['#value'] .= drupal_get_form('nmoderation_moderation_form', 'node', $node->nid, $vote, $title); |
|
$node->body .= drupal_get_form('nmoderation_moderation_form', $frm); |
|
|
} |
|
| 776 |
} |
} |
| 777 |
break; |
break; |
| 778 |
} |
} |