| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: hidden.action-pages.inc,v 1.1 2008/12/10 23:03:47 ekes Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 18 |
* @see hidden_hide_submit() |
* @see hidden_hide_submit() |
| 19 |
*/ |
*/ |
| 20 |
function hidden_hide(&$form_state, $type, $id) { |
function hidden_hide(&$form_state, $type, $id) { |
| 21 |
global $user; |
if (! user_access('mark as hidden')) { |
| 22 |
|
drupal_access_denied(); |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
global $user; |
| 26 |
$type = (string) $type; |
$type = (string) $type; |
| 27 |
$id = (int) $id; |
$id = (int) $id; |
| 28 |
|
|
| 29 |
$hidden = (object) _hidden_hide_form_hidden_get($type, $id); |
$hidden = (object) _hidden_hide_form_hidden_get($type, $id); |
| 30 |
$item = _hidden_hide_form_item_get($type, $id); |
if (! $item = _hidden_hide_form_item_get($type, $id)) { |
| 31 |
|
drupal_goto(); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
drupal_set_title(t('Hide ') . check_plain($item->title)); |
drupal_set_title(t('Hide ') . check_plain($item->title)); |
| 35 |
|
|
| 69 |
'#description' => t("Optional - type your reason why this item shall be hidden."), |
'#description' => t("Optional - type your reason why this item shall be hidden."), |
| 70 |
); |
); |
| 71 |
|
|
| 72 |
if (user_access('mark as hidden')) { |
$form['privatetext'] = array( |
| 73 |
$form['privatetext'] = array( |
'#type' => 'textarea', |
| 74 |
'#type' => 'textarea', |
'#title' => t('Your Private notes'), |
| 75 |
'#title' => t('Your Private notes'), |
'#default_value' => isset($hidden->privatenote) ? $hidden->privatenote : '', |
| 76 |
'#default_value' => isset($hidden->privatenote) ? $hidden->privatenote : '', |
'#rows' => 5, |
| 77 |
'#rows' => 5, |
'#maxlength' => 128, |
| 78 |
'#maxlength' => 128, |
'#description' => t("Optional - notes that can only be seen by other users who can (un)hide content."), |
| 79 |
'#description' => t("Optional - notes that can only be seen by other users who can (un)hide content."), |
); |
|
); |
|
|
} |
|
| 80 |
|
|
| 81 |
$form['#type'] = $type; |
$form['#content_type'] = $item->type; |
| 82 |
$form['#nid'] = $item->nid; |
$form['#content_id'] = $item->id; |
|
$form['#cid'] = $item->cid; |
|
| 83 |
|
|
| 84 |
$form['submit'] = array( |
$form['submit'] = array( |
| 85 |
'#type' => 'submit', |
'#type' => 'submit', |
| 105 |
$type = (string) $type; |
$type = (string) $type; |
| 106 |
$id = (int) $id; |
$id = (int) $id; |
| 107 |
|
|
| 108 |
$item = _hidden_hide_form_item_get($type, $id); |
if (! $item = _hidden_hide_form_item_get($type, $id)) { |
| 109 |
|
drupal_goto(); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
drupal_set_title(t('Report ') . check_plain($item->title)); |
drupal_set_title(t('Report ') . check_plain($item->title)); |
| 113 |
|
|
| 135 |
'#description' => t("Optional - type your reason why this item should be hidden."), |
'#description' => t("Optional - type your reason why this item should be hidden."), |
| 136 |
); |
); |
| 137 |
|
|
| 138 |
$form['#type'] = $type; |
$form['#content_type'] = $item->type; |
| 139 |
$form['#nid'] = $item->nid; |
$form['#content_id'] = $item->id; |
|
$form['#cid'] = $item->cid; |
|
| 140 |
|
|
| 141 |
$form['submit'] = array( |
$form['submit'] = array( |
| 142 |
'#type' => 'submit', |
'#type' => 'submit', |
| 155 |
*/ |
*/ |
| 156 |
function _hidden_hide_form_hidden_get($type, $id) { |
function _hidden_hide_form_hidden_get($type, $id) { |
| 157 |
if (! _hidden_check_param($type, $id)) { |
if (! _hidden_check_param($type, $id)) { |
| 158 |
|
// @todo this is now called from hidden_hide and hidden_report - seperate |
| 159 |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide() called with invalid arg.'); |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide() called with invalid arg.'); |
| 160 |
drupal_goto('hidden'); |
drupal_goto('hidden'); |
| 161 |
} |
} |
| 162 |
if ($hidden = _hidden_hidden_get($type, $id)) { |
if ($hidden = _hidden_hidden_get($type, $id)) { |
| 163 |
if ($hidden->delay==0) { |
if ($hidden->delay == 0) { |
| 164 |
// already fully hidden |
// already fully hidden |
| 165 |
drupal_set_message('Item is already hidden!', 'error'); |
drupal_set_message('Item is already hidden!', 'error'); |
| 166 |
_hidden_goto_hidden($hidden->nid, $hidden->cid); |
_hidden_goto_hidden($type, $id); |
| 167 |
} |
} |
| 168 |
} |
} |
| 169 |
|
|
| 171 |
} |
} |
| 172 |
|
|
| 173 |
/** |
/** |
| 174 |
* Retrieves node or commennt or handles error. |
* Retrieves node or comment. |
| 175 |
|
* |
| 176 |
|
* @todo this is generic MOVE |
| 177 |
* |
* |
| 178 |
* 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. |
| 179 |
* 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 - |
| 185 |
*/ |
*/ |
| 186 |
function _hidden_hide_form_item_get($type, $id) { |
function _hidden_hide_form_item_get($type, $id) { |
| 187 |
if ($type == 'comment') { |
if ($type == 'comment') { |
| 188 |
$item = _comment_load($id); |
if (! $item = _comment_load($id)) { |
| 189 |
|
// @todo error |
| 190 |
|
return FALSE; |
| 191 |
|
} |
| 192 |
$item->title = $item->subject; |
$item->title = $item->subject; |
| 193 |
} |
} |
| 194 |
else { |
else { |
| 195 |
$item = node_load($id); |
if (! $item = node_load($id)) { |
| 196 |
|
// @todo error |
| 197 |
|
return FALSE; |
| 198 |
|
} |
| 199 |
$item->cid = 0; |
$item->cid = 0; |
| 200 |
} |
} |
| 201 |
if (! $item->nid) { |
|
| 202 |
drupal_set_message(t('Database error occurred when retrieving item.'), 'error'); |
$item->type = $type; |
| 203 |
drupal_goto(); |
$item->id = $id; |
|
} |
|
| 204 |
|
|
| 205 |
return $item; |
return $item; |
| 206 |
} |
} |
| 228 |
drupal_access_denied(); |
drupal_access_denied(); |
| 229 |
} |
} |
| 230 |
|
|
| 231 |
$type = (string) $form['#type']; |
$type = (string) $form['#content_type']; |
| 232 |
$nid = (int) $form['#nid']; |
$id = (int) $form['#content_id']; |
| 233 |
$cid = (int) $form['#cid']; |
if (! _hidden_check_param($type, $id)) { |
|
if (! _hidden_check_param($type, $nid, $cid)) { |
|
| 234 |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide_submit() passed invalid parameters.'); |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide_submit() passed invalid parameters.'); |
| 235 |
drupal_goto('hidden'); |
drupal_goto('hidden'); |
| 236 |
} |
} |
|
$id = ($type == 'node') ? $nid : $cid; |
|
| 237 |
|
|
| 238 |
if (user_access('administer hidden')) { |
if (user_access('administer hidden')) { |
| 239 |
$user = user_load(array('name' => $form_state['values']['user'])); |
$user = user_load(array('name' => $form_state['values']['user'])); |
| 250 |
$private = (string) $form_state['values']['privatetext']; |
$private = (string) $form_state['values']['privatetext']; |
| 251 |
|
|
| 252 |
$t_args = array('%type' => $type); |
$t_args = array('%type' => $type); |
| 253 |
if (_hidden_hidden_hide($nid, $cid, $uid, $rid, $public, $private)) { |
if (hidden_hidden_hide($type, $id, $uid, $rid, $public, $private)) { |
| 254 |
$msg = t('Hidden %type.', $t_args); |
$msg = t('Hidden %type.', $t_args); |
| 255 |
_hidden_log(HIDDEN_LOG_HIDE, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_HIDE, $msg, $type, $id, $rid, $public, $private); |
| 256 |
drupal_set_message($msg); |
drupal_set_message($msg); |
| 260 |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private); |
| 261 |
drupal_set_message($msg, 'error'); |
drupal_set_message($msg, 'error'); |
| 262 |
} |
} |
| 263 |
_hidden_goto_hidden($nid, $cid); |
|
| 264 |
|
$form_state['redirect'] = 'hidden/'. $type .'/'. $id; |
| 265 |
} |
} |
| 266 |
|
|
| 267 |
/** |
/** |
| 272 |
drupal_access_denied(); |
drupal_access_denied(); |
| 273 |
} |
} |
| 274 |
|
|
| 275 |
$type = (string) $form['#type']; |
$type = (string) $form['#content_type']; |
| 276 |
$nid = (int) $form['#nid']; |
$id = (int) $form['#content_id']; |
| 277 |
$cid = (int) $form['#cid']; |
if (! _hidden_check_param($type, $id)) { |
|
if (! _hidden_check_param($type, $nid, $cid)) { |
|
| 278 |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_report_submit() passed invalid parameters.'); |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_report_submit() passed invalid parameters.'); |
| 279 |
drupal_goto('hidden'); |
drupal_goto('hidden'); |
| 280 |
} |
} |
|
$id = ($type == 'node') ? $nid : $cid; |
|
| 281 |
|
|
| 282 |
global $user; |
global $user; |
| 283 |
$uid = $user->uid; |
$uid = $user->uid; |
| 287 |
$public = (string) $form_state['values']['publictext']; |
$public = (string) $form_state['values']['publictext']; |
| 288 |
|
|
| 289 |
$t_args = array('%type' => $type); |
$t_args = array('%type' => $type); |
| 290 |
if (_hidden_reported_hide($type, $nid, $cid, $uid, $rid, $public, $private)) { |
if (_hidden_reported_hide($type, $id, $uid, $rid, $public, $private)) { |
| 291 |
$msg = t('Reported %type.', $t_args); |
$msg = t('Reported %type.', $t_args); |
| 292 |
_hidden_log(HIDDEN_LOG_REPORTED, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_REPORTED, $msg, $type, $id, $rid, $public, $private); |
| 293 |
drupal_set_message($msg); |
drupal_set_message($msg); |
| 297 |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private); |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private); |
| 298 |
drupal_set_message($msg, 'error'); |
drupal_set_message($msg, 'error'); |
| 299 |
} |
} |
|
drupal_goto(); |
|
| 300 |
} |
} |
| 301 |
|
|
| 302 |
/** |
/** |
| 311 |
$msg = t('Hidden %type unhidden', $t_array); |
$msg = t('Hidden %type unhidden', $t_array); |
| 312 |
_hidden_log(HIDDEN_LOG_UNHIDE, $msg, $type, $id); |
_hidden_log(HIDDEN_LOG_UNHIDE, $msg, $type, $id); |
| 313 |
drupal_set_message($msg); |
drupal_set_message($msg); |
| 314 |
|
if ($type == 'node') { |
| 315 |
|
unset($_REQUEST['destination']); |
| 316 |
|
drupal_goto('node/'. $id); |
| 317 |
|
} |
| 318 |
|
else { |
| 319 |
|
// @TODO |
| 320 |
|
drupal_goto(''); |
| 321 |
|
} |
| 322 |
} |
} |
| 323 |
else { |
else { |
| 324 |
$msg = t('Error unhiding %type.', $t_array); |
$msg = t('Error unhiding %type.', $t_array); |
| 325 |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id); |
_hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id); |
| 326 |
drupal_set_message($msg, 'error'); |
drupal_set_message($msg, 'error'); |
| 327 |
|
drupal_goto(); |
| 328 |
} |
} |
| 329 |
$hidden = _hidden_hidden_get($type, $id); |
|
|
_hidden_goto_unhidden($hidden->nid, $hidden->cid); |
|
| 330 |
} |
} |