| 1 |
<?php |
<?php |
| 2 |
// $Id: hidden.action-pages.inc,v 1.1 2008/12/10 23:03:47 ekes Exp $ |
// $Id: hidden.action-pages.inc,v 1.2 2008/12/12 19:23:35 ekes Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 9 |
/** |
/** |
| 10 |
* Menu callback; form to hide a node or comment. |
* Menu callback; form to hide a node or comment. |
| 11 |
* |
* |
| 12 |
* @param @todo $form_state == form? |
* @param $form_state |
| 13 |
* |
* @param $type |
| 14 |
|
* string 'node' or 'comment' |
| 15 |
|
* @param $id |
| 16 |
|
* int nid or cid |
| 17 |
* @return |
* @return |
| 18 |
* form. |
* form. |
| 19 |
* @ingroup forms |
* @ingroup forms |
| 34 |
drupal_goto(); |
drupal_goto(); |
| 35 |
} |
} |
| 36 |
|
|
| 37 |
drupal_set_title(t('Hide ') . check_plain($item->title)); |
drupal_set_title(t('Hide @title', array('@title' => $item->title))); |
| 38 |
|
|
| 39 |
if (user_access('administer hidden')) { |
if (user_access('administer hidden')) { |
| 40 |
$form['user'] = array( |
$form['user'] = array( |
| 47 |
} |
} |
| 48 |
else { |
else { |
| 49 |
$form['user'] = array( |
$form['user'] = array( |
| 50 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 51 |
'#title' => t('Hidden by'), |
'#title' => t('Hidden by'), |
| 52 |
'#value' => check_plain($user->name), |
'#value' => check_plain($user->name), |
| 53 |
'#disabled' => TRUE, |
'#disabled' => TRUE, |
| 54 |
); |
); |
| 85 |
$form['#content_id'] = $item->id; |
$form['#content_id'] = $item->id; |
| 86 |
|
|
| 87 |
$form['submit'] = array( |
$form['submit'] = array( |
| 88 |
'#type' => 'submit', |
'#type' => 'submit', |
| 89 |
'#value' => t('Hide'), |
'#value' => t('Hide'), |
| 90 |
); |
); |
| 91 |
|
|
| 95 |
/** |
/** |
| 96 |
* Menu callback; form to report a node or comment. |
* Menu callback; form to report a node or comment. |
| 97 |
* |
* |
| 98 |
* @param @todo $form_state == form? |
* @param $form_state |
| 99 |
|
* @param $type |
| 100 |
|
* string 'node' or 'comment' |
| 101 |
|
* @param $id |
| 102 |
|
* int nid or cid |
| 103 |
* |
* |
| 104 |
* @return |
* @return |
| 105 |
* form. |
* form. |
| 107 |
* @see hidden_report_submit() |
* @see hidden_report_submit() |
| 108 |
*/ |
*/ |
| 109 |
function hidden_report(&$form_state, $type, $id) { |
function hidden_report(&$form_state, $type, $id) { |
| 110 |
|
if (! user_access('report for hiding')) { |
| 111 |
|
drupal_access_denied(); |
| 112 |
|
} |
| 113 |
global $user; |
global $user; |
|
|
|
| 114 |
$type = (string) $type; |
$type = (string) $type; |
| 115 |
$id = (int) $id; |
$id = (int) $id; |
| 116 |
|
|
| 117 |
|
_hidden_hide_form_hidden_get($type, $id); |
| 118 |
if (! $item = _hidden_hide_form_item_get($type, $id)) { |
if (! $item = _hidden_hide_form_item_get($type, $id)) { |
| 119 |
drupal_goto(); |
drupal_goto(); |
| 120 |
} |
} |
| 121 |
|
|
| 122 |
drupal_set_title(t('Report ') . check_plain($item->title)); |
drupal_set_title(t('Report @title', array('@title' => $item->title))); |
| 123 |
|
|
| 124 |
$form['user'] = array( |
$form['user'] = array( |
| 125 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 126 |
'#title' => t('Reported by'), |
'#title' => t('Reported by'), |
| 127 |
'#value' => check_plain($user->name), |
'#value' => check_plain($user->name), |
| 128 |
'#disabled' => TRUE, |
'#disabled' => TRUE, |
| 129 |
); |
); |
| 149 |
$form['#content_id'] = $item->id; |
$form['#content_id'] = $item->id; |
| 150 |
|
|
| 151 |
$form['submit'] = array( |
$form['submit'] = array( |
| 152 |
'#type' => 'submit', |
'#type' => 'submit', |
| 153 |
'#value' => t('Report'), |
'#value' => t('Report'), |
| 154 |
); |
); |
| 155 |
|
|
| 172 |
if ($hidden = _hidden_hidden_get($type, $id)) { |
if ($hidden = _hidden_hidden_get($type, $id)) { |
| 173 |
if ($hidden->delay == 0) { |
if ($hidden->delay == 0) { |
| 174 |
// already fully hidden |
// already fully hidden |
| 175 |
drupal_set_message('Item is already hidden!', 'error'); |
drupal_set_message(t('Item is already hidden.'), 'error'); |
| 176 |
_hidden_goto_hidden($type, $id); |
drupal_goto(hidden_path($type, $id, 'view')); |
| 177 |
} |
} |
| 178 |
|
// else it is hidden but it's on delay, so not yet actually hidden |
| 179 |
} |
} |
| 180 |
|
|
| 181 |
return $hidden; |
return $hidden; |
| 183 |
|
|
| 184 |
/** |
/** |
| 185 |
* Retrieves node or comment. |
* Retrieves node or comment. |
| 186 |
* |
* |
| 187 |
* @todo this is generic MOVE |
* @todo this is generic MOVE |
| 188 |
* |
* |
| 189 |
* Moves comment->subject to title to make consistent handling of both nodes and comments. |
* Moves comment->subject to title to make consistent handling of both nodes and comments. |
| 190 |
* Calling functions are only using the title, but for abstraction using _load commands - |
* Calling functions are only using the title, but for abstraction using _load commands - |
| 191 |
* eg. should also work with node comments then. |
* eg. should also work with node comments then. |
| 192 |
* |
* |
| 193 |
* @param string $type 'node' or 'comment'. |
* @param string $type 'node' or 'comment'. |
| 226 |
form_set_error('user', t('The username %name does not exist.', array('%name' => $form_state['values']['user']))); |
form_set_error('user', t('The username %name does not exist.', array('%name' => $form_state['values']['user']))); |
| 227 |
} |
} |
| 228 |
} |
} |
| 229 |
// @todo check nid/cid/type? |
// @todo check nid/cid/type? |
| 230 |
// probably not _needed_ |
// probably not _needed_ |
| 231 |
// and note hidden_admin_filter_form_validate() uses this too |
// and note hidden_admin_filter_form_validate() uses this too |
| 232 |
} |
} |
| 233 |
|
|
| 263 |
$t_args = array('%type' => $type); |
$t_args = array('%type' => $type); |
| 264 |
if (hidden_hidden_hide($type, $id, $uid, $rid, $public, $private)) { |
if (hidden_hidden_hide($type, $id, $uid, $rid, $public, $private)) { |
| 265 |
$msg = t('Hidden %type.', $t_args); |
$msg = t('Hidden %type.', $t_args); |
| 266 |
_hidden_log(HIDDEN_LOG_HIDE, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_HIDE, $msg, $type, $id, $rid, $public); |
| 267 |
drupal_set_message($msg); |
drupal_set_message($msg); |
| 268 |
} |
} |
| 269 |
else { |
else { |
| 270 |
$msg = t('Error hiding %type.', $t_args); |
$msg = t('Error hiding %type.', $t_args); |
| 271 |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public); |
| 272 |
drupal_set_message($msg, 'error'); |
drupal_set_message($msg, 'error'); |
| 273 |
} |
} |
| 274 |
|
/** |
| 275 |
|
* The redirect challenge. |
| 276 |
|
* |
| 277 |
|
* What do users want/expect to see next? |
| 278 |
|
* What are they allowed to see? |
| 279 |
|
*/ |
| 280 |
|
if (! user_access('administer content')) { |
| 281 |
|
if (isset($_REQUEST['destination'])) { |
| 282 |
|
unset($_REQUEST['destination']); |
| 283 |
|
} |
| 284 |
|
} |
| 285 |
$form_state['redirect'] = 'hidden/'. $type .'/'. $id; |
$form_state['redirect'] = 'hidden/'. $type .'/'. $id; |
| 286 |
} |
} |
| 287 |
|
|
| 308 |
$public = (string) $form_state['values']['publictext']; |
$public = (string) $form_state['values']['publictext']; |
| 309 |
|
|
| 310 |
$t_args = array('%type' => $type); |
$t_args = array('%type' => $type); |
| 311 |
if (_hidden_reported_hide($type, $id, $uid, $rid, $public, $private)) { |
if (_hidden_reported_hide($type, $id, $uid, $rid, $public)) { |
| 312 |
$msg = t('Reported %type.', $t_args); |
$msg = t('Reported %type.', $t_args); |
| 313 |
_hidden_log(HIDDEN_LOG_REPORTED, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_REPORTED, $msg, $type, $id, $rid, $public); |
| 314 |
drupal_set_message($msg); |
drupal_set_message($msg); |
| 315 |
} |
} |
| 316 |
else { |
else { |
| 317 |
$msg = t('Error reporting %type.', $t_args); |
$msg = t('Error reporting %type.', $t_args); |
| 318 |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public); |
| 319 |
drupal_set_message($msg, 'error'); |
drupal_set_message($msg, 'error'); |
| 320 |
} |
} |
| 321 |
} |
} |
| 324 |
* Menu callback; unhide a node or comment. |
* Menu callback; unhide a node or comment. |
| 325 |
* |
* |
| 326 |
* @param $hidden |
* @param $hidden |
| 327 |
* hidden details object see _hidden_hidden_check() |
* hidden details object see hidden_hidden_check() |
| 328 |
*/ |
*/ |
| 329 |
function hidden_unhide($type, $id) { |
function hidden_unhide($type, $id) { |
| 330 |
$t_array = array('%type' => $type); |
$t_array = array('%type' => $type); |
| 333 |
_hidden_log(HIDDEN_LOG_UNHIDE, $msg, $type, $id); |
_hidden_log(HIDDEN_LOG_UNHIDE, $msg, $type, $id); |
| 334 |
drupal_set_message($msg); |
drupal_set_message($msg); |
| 335 |
if ($type == 'node') { |
if ($type == 'node') { |
|
unset($_REQUEST['destination']); |
|
| 336 |
drupal_goto('node/'. $id); |
drupal_goto('node/'. $id); |
| 337 |
} |
} |
| 338 |
else { |
else { |
| 339 |
// @TODO |
$nid = _hidden_comment_nid($id); |
| 340 |
drupal_goto(''); |
drupal_goto('node/'. $nid, NULL, 'comment-'. $id); |
| 341 |
} |
} |
| 342 |
} |
} |
| 343 |
else { |
else { |