| 1 |
<?php |
<?php |
| 2 |
// $Id: hidden.module,v 1.4 2008/07/01 13:12:15 ekes Exp $ |
// $Id: hidden.module,v 1.5 2008/12/10 23:03:47 ekes Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 338 |
'title' => 'Report post', |
'title' => 'Report post', |
| 339 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 340 |
'page arguments' => array('hidden_hide', 1, 2), |
'page arguments' => array('hidden_hide', 1, 2), |
| 341 |
'access arguments' => $report, |
'access arguments' => $hide, |
| 342 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 343 |
'file' => 'hidden.action-pages.inc', |
'file' => 'hidden.action-pages.inc', |
| 344 |
); |
); |
| 415 |
$query = "SELECT * FROM {hidden_$type} WHERE delay != 0 AND delay < %d"; |
$query = "SELECT * FROM {hidden_$type} WHERE delay != 0 AND delay < %d"; |
| 416 |
$result = db_query($query, time()); |
$result = db_query($query, time()); |
| 417 |
while ($hidden = db_fetch_object($result)) { |
while ($hidden = db_fetch_object($result)) { |
| 418 |
_hidden_hidden_hide_unpublish($hidden->nid, ($type == 'node') ? 0 : $hidden->cid); |
_hidden_hidden_hide_unpublish($type, ($type == 'node') ? $hidden->nid : $hidden->cid); |
| 419 |
$query = "UPDATE {hidden_$hidden} SET delay=0 WHERE hid=%d"; |
$query = "UPDATE {hidden_$hidden} SET delay=0 WHERE hid=%d"; |
| 420 |
db_query($query, $hidden->hid); |
db_query($query, $hidden->hid); |
| 421 |
_hidden_log(HIDDEN_LOG_HIDE, t('Hidden %type', array('%type' => $type)), $type, |
_hidden_log(HIDDEN_LOG_HIDE, t('Hidden %type', array('%type' => $type)), $type, |
| 454 |
return; |
return; |
| 455 |
} |
} |
| 456 |
// $comment an array here! |
// $comment an array here! |
| 457 |
hidden_filter_content($comment['subject'] .' '. $comment['comment'], $comment['nid'], $comment['cid']); |
hidden_filter_content($comment['subject'] .' '. $comment['comment'], 'comment', $comment['cid']); |
| 458 |
break; |
break; |
| 459 |
case 'publish': |
case 'publish': |
| 460 |
if (! _hidden_hidden_check('comment', $comment->cid)) { |
if (! _hidden_hidden_check('comment', $comment->cid)) { |
| 525 |
if (user_access('bypass hidden filter')) { |
if (user_access('bypass hidden filter')) { |
| 526 |
return; |
return; |
| 527 |
} |
} |
| 528 |
hidden_filter_content($node->title .' '. $node->teaser .' '. $node->body, $node->nid, 0); |
hidden_filter_content($node->title .' '. $node->teaser .' '. $node->body, 'node', $node->nid); |
| 529 |
break; |
break; |
| 530 |
case 'delete': |
case 'delete': |
| 531 |
// comment_nodeapi doesn't call hook_comment delete but this query will delete comments too |
// comment_nodeapi doesn't call hook_comment delete but this query will delete comments too |
| 545 |
*/ |
*/ |
| 546 |
function hidden_node_operations() { |
function hidden_node_operations() { |
| 547 |
$operations = array( |
$operations = array( |
| 548 |
'hide' => array( |
'hide' => array( |
| 549 |
'label' => t('Hide'), |
'label' => t('Hide'), |
| 550 |
'page callback' => 'hidden_operations_hide', |
'page callback' => 'hidden_operations_hide', |
| 551 |
), |
), |
| 552 |
'unhide' => array( |
'unhide' => array( |
| 553 |
'label' => t('Unhide'), |
'label' => t('Unhide'), |
| 554 |
'page callback' => 'hidden_operations_unhide', |
'page callback' => 'hidden_operations_unhide', |
| 555 |
), |
), |
| 556 |
); |
); |
| 557 |
|
|
| 558 |
return $operations; |
return $operations; |
| 559 |
} |
} |
| 803 |
foreach ($nids as $nid) { |
foreach ($nids as $nid) { |
| 804 |
if (! _hidden_hidden_check('node', $nid)) { |
if (! _hidden_hidden_check('node', $nid)) { |
| 805 |
$nid = (int)$nid; |
$nid = (int)$nid; |
| 806 |
if (_hidden_hidden_hide($nid, 0, $user->uid, 1)) { |
if (hidden_hidden_hide('node', $nid, $user->uid, 1)) { |
| 807 |
$hide[] = $nid; |
$hide[] = $nid; |
| 808 |
} |
} |
| 809 |
else { |
else { |
| 857 |
/** |
/** |
| 858 |
* Checks if item is hidden. |
* Checks if item is hidden. |
| 859 |
* |
* |
| 860 |
|
* @todo this isn't an internal function. |
| 861 |
|
* |
| 862 |
* @param $type |
* @param $type |
| 863 |
* string content 'comment' or 'node'. |
* string content 'comment' or 'node'. |
| 864 |
* @param $id |
* @param $id |
| 917 |
" WHERE nid=%d"; |
" WHERE nid=%d"; |
| 918 |
} |
} |
| 919 |
elseif ($type == 'comment') { |
elseif ($type == 'comment') { |
| 920 |
$query = 'SELECT h.hid, h.nid, h.cid, h.rid, h.publicnote, h.privatenote, h.delay,'. |
$query = 'SELECT h.hid, h.cid, h.rid, h.publicnote, h.privatenote, h.delay,'. |
| 921 |
' r.title, r.description'. |
' r.title, r.description'. |
| 922 |
" FROM {hidden_comment} AS h". |
" FROM {hidden_comment} AS h". |
| 923 |
' LEFT JOIN {hidden_reasons} AS r ON h.rid=r.rid'. |
' LEFT JOIN {hidden_reasons} AS r ON h.rid=r.rid'. |
| 996 |
* @return |
* @return |
| 997 |
* FALSE on fail. hid on success. |
* FALSE on fail. hid on success. |
| 998 |
*/ |
*/ |
| 999 |
function _hidden_hidden_hide($nid, $cid, $uid, $rid=0, $public='', $private='', $filter=FALSE) { |
function hidden_hidden_hide($type, $id, $uid, $rid=0, $public='', $private='', $filter=FALSE) { |
| 1000 |
// 'hide now' delay !=0 // in the future also editing a hidden if desired? |
// 'hide now' delay !=0 // in the future also editing a hidden if desired? |
| 1001 |
// this check here to prevent just hidden, or calls from report as hidden etc. clashing |
// this check here to prevent just hidden, or calls from report as hidden etc. clashing |
|
if ($cid==0) { |
|
|
$type = 'node'; |
|
|
$col = 'nid'; |
|
|
$id = $nid; |
|
|
} |
|
|
else { |
|
|
$type = 'comment'; |
|
|
$col = 'cid'; |
|
|
$id = $cid; |
|
|
} |
|
| 1002 |
|
|
| 1003 |
if ($hidden = _hidden_hidden_get($type, $id)) { |
if ($hidden = _hidden_hidden_get($type, $id)) { |
| 1004 |
if ($hidden->delay==0) { |
if ($hidden->delay==0) { |
| 1010 |
$hid = $hidden->hid; |
$hid = $hidden->hid; |
| 1011 |
if ($type == 'node') { |
if ($type == 'node') { |
| 1012 |
$query = "UPDATE {hidden_node} SET nid=%d, uid=%d, created=%d, rid=%d, publicnote='%s', privatenote='%s', delay=%d WHERE hid=%d"; |
$query = "UPDATE {hidden_node} SET nid=%d, uid=%d, created=%d, rid=%d, publicnote='%s', privatenote='%s', delay=%d WHERE hid=%d"; |
| 1013 |
$result = db_query($query, $nid, $uid, $created, $rid, $public, $private, $filter, $hid); |
$result = db_query($query, $id, $uid, $created, $rid, $public, $private, $filter, $hid); |
| 1014 |
} |
} |
| 1015 |
else { |
else { |
| 1016 |
$query = "UPDATE {hidden_comment} SET nid=%d, cid=%d, uid=%d, created=%d, rid=%d, publicnote='%s', privatenote='%s', delay=%d WHERE hid=%d"; |
$query = "UPDATE {hidden_comment} SET cid=%d, uid=%d, created=%d, rid=%d, publicnote='%s', privatenote='%s', delay=%d WHERE hid=%d"; |
| 1017 |
$result = db_query($query, $nid, $cid, $uid, $created, $rid, $public, $private, $filter, $hid); |
$result = db_query($query, $id, $uid, $created, $rid, $public, $private, $filter, $hid); |
| 1018 |
} |
} |
| 1019 |
} |
} |
| 1020 |
} |
} |
| 1022 |
// Insert into hidden table |
// Insert into hidden table |
| 1023 |
if ($type == 'node') { |
if ($type == 'node') { |
| 1024 |
$query = "INSERT INTO {hidden_node} (nid, uid, created, rid, publicnote, privatenote, delay) VALUES (%d, %d, %d, %d, '%s', '%s', %d)"; |
$query = "INSERT INTO {hidden_node} (nid, uid, created, rid, publicnote, privatenote, delay) VALUES (%d, %d, %d, %d, '%s', '%s', %d)"; |
| 1025 |
$result = db_query($query, $nid, $uid, time(), $rid, $public, $private, $filter); |
$result = db_query($query, $id, $uid, time(), $rid, $public, $private, $filter); |
| 1026 |
} |
} |
| 1027 |
else { |
else { |
| 1028 |
$query = "INSERT INTO {hidden_comment} (nid, cid, uid, created, rid, publicnote, privatenote, delay) VALUES (%d, %d, %d, %d, %d, '%s', '%s', %d)"; |
$query = "INSERT INTO {hidden_comment} (cid, uid, created, rid, publicnote, privatenote, delay) VALUES (%d, %d, %d, %d, '%s', '%s', %d)"; |
| 1029 |
$result = db_query($query, $nid, $cid, $uid, time(), $rid, $public, $private, $filter); |
$result = db_query($query, $id, $uid, time(), $rid, $public, $private, $filter); |
| 1030 |
} |
} |
| 1031 |
$hid = db_last_insert_id("{hidden_$type}_hid", "hid"); |
$hid = db_last_insert_id("{hidden_$type}_hid", "hid"); |
| 1032 |
} |
} |
| 1034 |
if ($filter === FALSE) { |
if ($filter === FALSE) { |
| 1035 |
drupal_set_message(t('Database error while storing hidden.'), 'error'); |
drupal_set_message(t('Database error while storing hidden.'), 'error'); |
| 1036 |
} |
} |
| 1037 |
_hidden_log(HIDDEN_LOG_DEBUG, "_hidden_hidden_hide() failed to insert into {hidden_$type}", 'hidden', $hid); |
_hidden_log(HIDDEN_LOG_DEBUG, "hidden_hidden_hide() failed to insert into {hidden_$type}", 'hidden', $hid); |
| 1038 |
return FALSE; |
return FALSE; |
| 1039 |
} |
} |
| 1040 |
|
|
| 1041 |
if ($filter > 0) { |
if ($filter > 0) { |
| 1042 |
// unpublishing handled by cron |
// unpublishing handled by cron |
| 1043 |
return; |
return TRUE; |
| 1044 |
} |
} |
| 1045 |
|
|
| 1046 |
|
$col = $type == 'node' ? 'nid' : 'cid'; |
| 1047 |
// If it has been reported mark as seen |
// If it has been reported mark as seen |
| 1048 |
$reported = db_query("SELECT COUNT(*) FROM {hidden_reported_$type} WHERE $col=%d", $id); |
$reported = db_query("SELECT COUNT(*) FROM {hidden_reported_$type} WHERE $col=%d", $id); |
| 1049 |
if (db_result($reported)>0) { |
if (db_result($reported)>0) { |
| 1052 |
} |
} |
| 1053 |
} |
} |
| 1054 |
|
|
| 1055 |
if (! _hidden_hidden_hide_unpublish($nid, $cid)) { |
if (! _hidden_hidden_hide_unpublish($type, $id)) { |
| 1056 |
// It's a bit messy if something is in the hidden db but published |
// It's a bit messy if something is in the hidden db but published |
| 1057 |
// on display it checks published status before hidden bothing with hidden db |
// on display it checks published status before hidden bothing with hidden db |
| 1058 |
return FALSE; |
return FALSE; |
| 1059 |
} |
} |
| 1060 |
|
|
| 1061 |
return $hid; |
return TRUE; |
| 1062 |
} |
} |
| 1063 |
|
|
| 1064 |
/** |
/** |
| 1067 |
* Updates comments to status COMMENT_NOT_PUBLISHED |
* Updates comments to status COMMENT_NOT_PUBLISHED |
| 1068 |
* and nodes to status 0, and stops further comments |
* and nodes to status 0, and stops further comments |
| 1069 |
* |
* |
| 1070 |
* @param $nid |
* @todo consider loading objects, manipulating (with actions), and saving |
| 1071 |
* int nid |
* |
| 1072 |
* @param $cid |
* @param $type |
| 1073 |
* int cid |
* string 'node' or 'comment' |
| 1074 |
|
* @param $id |
| 1075 |
|
* int nid or cid |
| 1076 |
* @return |
* @return |
| 1077 |
* TRUE on success |
* TRUE on success |
| 1078 |
*/ |
*/ |
| 1079 |
function _hidden_hidden_hide_unpublish($nid, $cid) { |
function _hidden_hidden_hide_unpublish($type, $id) { |
| 1080 |
if ($cid != 0) { |
if ($type == 'comment') { |
| 1081 |
// Set comment to unpublished |
// Set comment to unpublished |
| 1082 |
if (! db_query('UPDATE {comments} SET status = '. COMMENT_NOT_PUBLISHED ." WHERE cid=%d", $cid)) { |
if (! db_query('UPDATE {comments} SET status = '. COMMENT_NOT_PUBLISHED ." WHERE cid=%d", $id)) { |
| 1083 |
drupal_set_message(t("Database error occurred when updating comment's status."), 'error'); |
drupal_set_message(t("Database error occurred when updating comment's status."), 'error'); |
| 1084 |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide_do() error unpublishing comment.', 'comment', $cid); |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide_do() error unpublishing comment.', 'comment', $id); |
| 1085 |
return FALSE; |
return FALSE; |
| 1086 |
} |
} |
| 1087 |
} |
} |
| 1088 |
else { |
elseif ($type == 'node') { |
| 1089 |
// set node to unpublished and comments to read-only |
// set node to unpublished and comments to read-only |
| 1090 |
if (! db_query("UPDATE {node} SET status = 0, comment = 1 WHERE nid = %d", $nid)) { |
if (! db_query("UPDATE {node} SET status = 0, comment = 1 WHERE nid = %d", $id)) { |
| 1091 |
drupal_set_message(t("Database error occurred when updating node's status."), 'error'); |
drupal_set_message(t("Database error occurred when updating node's status."), 'error'); |
| 1092 |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide_do() error unpublishing node.', 'node', $nid); |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hide_do() error unpublishing node.', 'node', $id); |
| 1093 |
return FALSE; |
return FALSE; |
| 1094 |
} |
} |
| 1095 |
} |
} |
| 1096 |
|
else { |
| 1097 |
|
// @todo error |
| 1098 |
|
return FALSE; |
| 1099 |
|
} |
| 1100 |
|
|
| 1101 |
return TRUE; |
return TRUE; |
| 1102 |
} |
} |
| 1103 |
|
|
| 1130 |
return FALSE; |
return FALSE; |
| 1131 |
} |
} |
| 1132 |
|
|
| 1133 |
if ($type == 'comment') { |
$result = _hidden_hidden_publish($type, $id); |
|
$result = db_query('UPDATE {comments} SET status = '. COMMENT_PUBLISHED .' WHERE cid = %d', $id); |
|
|
} |
|
|
else { |
|
|
// set comments to read/write |
|
|
$result = db_query('UPDATE {node} SET status = 1, comment = 2 WHERE nid = %d', $id); |
|
|
} |
|
| 1134 |
|
|
| 1135 |
if ($result) { |
if ($result) { |
| 1136 |
return TRUE; |
return TRUE; |
| 1142 |
} |
} |
| 1143 |
|
|
| 1144 |
/** |
/** |
| 1145 |
* check parameters set error and goto hidden if not as expected. |
* Opposite actions to _hidden_hidden_unpublish(). |
| 1146 |
|
* |
| 1147 |
|
* @todo set comment status to correct for type, or back to previous settings (need storing). |
| 1148 |
|
*/ |
| 1149 |
|
function _hidden_hidden_publish($type, $id) { |
| 1150 |
|
if ($type == 'comment') { |
| 1151 |
|
$result = db_query('UPDATE {comments} SET status = '. COMMENT_PUBLISHED .' WHERE cid = %d', $id); |
| 1152 |
|
} |
| 1153 |
|
else { |
| 1154 |
|
// set comments to read/write |
| 1155 |
|
$result = db_query('UPDATE {node} SET status = 1, comment = 2 WHERE nid = %d', $id); |
| 1156 |
|
} |
| 1157 |
|
|
| 1158 |
|
return $result; |
| 1159 |
|
} |
| 1160 |
|
|
| 1161 |
|
/** |
| 1162 |
|
* Check parameters. |
| 1163 |
* |
* |
| 1164 |
* @param $type |
* @param $type |
| 1165 |
* string for content type - only accepts: comment || node. |
* string 'node' or 'comment'. |
| 1166 |
* @param $id |
* @param $id |
| 1167 |
* int for content id nid or cid - only accepts > 0. |
* int nid or cid. |
|
* @param $id2 |
|
|
* int (optional) then test against content type. |
|
| 1168 |
* @return |
* @return |
| 1169 |
* bool TRUE if pass, FALSE on fail |
* bool TRUE if pass, FALSE on fail |
| 1170 |
*/ |
*/ |
| 1171 |
function _hidden_check_param($type, $id, $id2=NULL) { |
function _hidden_check_param($type, $id) { |
| 1172 |
if (($type != 'comment' && $type != 'node') && (! is_integer($id) || $id < 1)) { |
if ($type != 'comment' && $type != 'node') { |
| 1173 |
return FALSE; |
return FALSE; |
| 1174 |
} |
} |
| 1175 |
if ($id2 != NULL) { |
if (! is_integer($id) || $id < 1) { |
| 1176 |
if (($type == 'node' && $id2 != 0) || ($type == 'comment' && $id2 < 1)) { |
return FALSE; |
|
return FALSE; |
|
|
} |
|
| 1177 |
} |
} |
|
|
|
| 1178 |
return TRUE; |
return TRUE; |
| 1179 |
} |
} |
| 1180 |
|
|
| 1224 |
* @return |
* @return |
| 1225 |
* FALSE on error |
* FALSE on error |
| 1226 |
*/ |
*/ |
| 1227 |
function _hidden_reported_hide($type, $nid, $cid, $uid, $rid=0, $public='', $private='') { |
function _hidden_reported_hide($type, $type, $id, $uid, $rid=0, $public='', $private='') { |
| 1228 |
if ($type == 'node') { |
if ($type == 'node') { |
| 1229 |
$query = "INSERT INTO {hidden_reported_node} (nid, uid, created, rid, publicnote, privatenote) VALUES (%d, %d, %d, %d, '%s', '%s')"; |
$query = "INSERT INTO {hidden_reported_node} (nid, uid, created, rid, publicnote, privatenote) VALUES (%d, %d, %d, %d, '%s', '%s')"; |
| 1230 |
return db_query($query, $nid, $uid, time(), $rid, $public, $private); |
return db_query($query, $id, $uid, time(), $rid, $public, $private); |
| 1231 |
} |
} |
| 1232 |
elseif ($type == 'comment') { |
elseif ($type == 'comment') { |
| 1233 |
$query = "INSERT INTO {hidden_reported_comment} (nid, cid, uid, created, rid, publicnote, privatenote) VALUES (%d, %d, %d, %d, %d, '%s', '%s')"; |
$query = "INSERT INTO {hidden_reported_comment} (cid, uid, created, rid, publicnote, privatenote) VALUES (%d, %d, %d, %d, %d, '%s', '%s')"; |
| 1234 |
return db_query($query, $nid, $cid, $uid, time(), $rid, $public, $private); |
return db_query($query, $id, $uid, time(), $rid, $public, $private); |
| 1235 |
} |
} |
| 1236 |
|
|
| 1237 |
return FALSE; |
return FALSE; |
| 1406 |
* |
* |
| 1407 |
* @param $content |
* @param $content |
| 1408 |
* string content to run through filters |
* string content to run through filters |
| 1409 |
* @param $nid |
* @param $type |
| 1410 |
* int nid |
* string 'node' or 'comment' |
| 1411 |
* @param $cid |
* @param $id |
| 1412 |
* int cid or 0 if node |
* int nid or cid |
| 1413 |
* @return |
* @return |
| 1414 |
* bool TRUE on matching a filter |
* bool TRUE on matching a filter |
| 1415 |
*/ |
*/ |
| 1416 |
function hidden_filter_content($content, $nid, $cid) { |
function hidden_filter_content($content, $type, $id) { |
| 1417 |
// TODO hidden filter switch... |
// TODO hidden filter switch... |
| 1418 |
|
|
| 1419 |
if (($filter = _hidden_filter_content_test($content)) == FALSE) { |
if (($filter = _hidden_filter_content_test($content)) == FALSE) { |
| 1420 |
_hidden_log(HIDDEN_LOG_DEBUG_FILTER, "hidden_filter_content() FALSE on nid $nid cid $cid"); |
_hidden_log(HIDDEN_LOG_DEBUG_FILTER, "hidden_filter_content() FALSE on $type $id"); |
| 1421 |
return FALSE; |
return FALSE; |
| 1422 |
} |
} |
| 1423 |
|
|
| 1424 |
_hidden_log(HIDDEN_LOG_DEBUG_FILTER, "hidden_filter_content() true on nid $nid cid $cid"); |
_hidden_log(HIDDEN_LOG_DEBUG_FILTER, "hidden_filter_content() true on nid $type $id"); |
| 1425 |
$reason = _hidden_filter_reason_get($filter->hfid); |
$reason = _hidden_filter_reason_get($filter->hfid); |
| 1426 |
if ($reason->delay != 0) { |
if ($reason->delay != 0) { |
| 1427 |
$reason->delay += time(); |
$reason->delay += time(); |
| 1429 |
else { |
else { |
| 1430 |
drupal_set_message(t('Your post has been marked as possibly contraviening the editorial policy, and will be hidden until a moderator can review it.')); |
drupal_set_message(t('Your post has been marked as possibly contraviening the editorial policy, and will be hidden until a moderator can review it.')); |
| 1431 |
} |
} |
| 1432 |
_hidden_hidden_hide($nid, $cid, $reason->uid, $reason->rid, $reason->publicnote, $reason->privatenote, $reason->delay); |
hidden_hidden_hide($type, $id, $reason->uid, $reason->rid, $reason->publicnote, $reason->privatenote, $reason->delay); |
| 1433 |
return TRUE; |
return TRUE; |
| 1434 |
} |
} |
| 1435 |
|
|
| 1595 |
else { |
else { |
| 1596 |
$table = 'hidden_reported'; |
$table = 'hidden_reported'; |
| 1597 |
} |
} |
| 1598 |
|
// @todo this is borked there is no $cid; isset($items[0]->cid) maybe |
| 1599 |
if ($cid==0) { |
if ($cid==0) { |
| 1600 |
$query = 'SELECT publicnote, rid from {'. $table .'_node} WHERE nid=%d'; |
$query = 'SELECT publicnote, rid from {'. $table .'_node} WHERE nid=%d'; |
| 1601 |
$id = $items[0]->nid; |
$id = $items[0]->nid; |
| 1658 |
// add links |
// add links |
| 1659 |
$links = array(); |
$links = array(); |
| 1660 |
foreach ($items as $item) { |
foreach ($items as $item) { |
| 1661 |
|
// @todo what's an item here we need $type, $id |
| 1662 |
$mail .= _hidden_url($item->nid, $item->cid, TRUE, TRUE) ."\n"; |
$mail .= _hidden_url($item->nid, $item->cid, TRUE, TRUE) ."\n"; |
| 1663 |
} |
} |
| 1664 |
case HIDDEN_LOG_REASONS: |
case HIDDEN_LOG_REASONS: |
| 1682 |
* @return |
* @return |
| 1683 |
* string text of url. |
* string text of url. |
| 1684 |
*/ |
*/ |
| 1685 |
function _hidden_url($nid=0, $cid=0, $normal=FALSE, $absolute=FALSE) { |
// @todo only called above |
| 1686 |
|
function _hidden_url($nid, $cid, $normal=FALSE, $absolute=FALSE) { |
| 1687 |
if (! $normal) { |
if (! $normal) { |
| 1688 |
if ($cid>0) { |
if ($cid>0) { |
| 1689 |
$path = "hidden/comment/$cid"; |
$path = "hidden/comment/$cid"; |
| 1735 |
} |
} |
| 1736 |
|
|
| 1737 |
/** |
/** |
| 1738 |
* drupal_goto() wrapper for redirecting to a hidden item |
* drupal_goto() wrapper for redirecting to a possibly hidden item |
|
* |
|
|
* Intended mainly for internal use. Will goto a hidden where it can be seen. |
|
|
* If user can see unpublished content it will goto normal view |
|
|
* if not will goto the hidden page |
|
|
* |
|
|
* NOTE: nid is actually redundant for comments at the moment. The fn could be $type, $id. |
|
|
* nid is already available at all calling points and may be required for future views.module |
|
|
* based redirects. |
|
| 1739 |
* |
* |
| 1740 |
* @param $id |
* @param $id |
| 1741 |
* nid |
* nid |
| 1742 |
* @param $cid |
* @param $cid |
| 1743 |
* cid (if comment) |
* cid (if comment) |
| 1744 |
*/ |
*/ |
| 1745 |
function _hidden_goto_hidden($nid, $cid = 0) { |
function hidden_goto($type, $id) { |
| 1746 |
drupal_set_message("_hidden_goto_hidden $nid $cid"); |
$path = hidden_path($type, $id); |
| 1747 |
if ($cid == 0) { |
drupal_goto($path); |
|
$access = user_access('administer nodes'); // it's a node can the user see unpublished nodes? |
|
|
} |
|
|
else { |
|
|
$access = user_access('administer comments'); // it's a comment can the user see unpublished comments |
|
|
} |
|
|
|
|
|
if (isset($_REQUEST['destination'])) { // **assumption** this was set by this module |
|
|
if ($access == TRUE) { // if the user can see it return there |
|
|
drupal_goto(); |
|
|
} |
|
|
else { // user can see now hidden item there unset it and continue to hidden view |
|
|
unset($_REQUEST['destination']); |
|
|
} |
|
|
} |
|
|
|
|
|
if ($cid == 0) { // the type is node |
|
|
$type = 'node'; |
|
|
$id = $nid; // make the id the nid |
|
|
} |
|
|
else { // the type is comment |
|
|
$type = 'comment'; |
|
|
$id = $cid; // the id is the cid |
|
|
} |
|
|
|
|
|
$url = "hidden/$type/$id"; |
|
|
|
|
|
drupal_goto($url); |
|
| 1748 |
} |
} |
| 1749 |
|
|
| 1750 |
/** |
/** |
| 1751 |
* drupal_goto() wrapper for redirecting to just unhidden content |
* Get a functioning path to be able to see content. |
| 1752 |
* |
* |
| 1753 |
* @param $nid |
* Basic version to start, should be possible to let people override. |
| 1754 |
* int nid |
* Should return a path that the present user will be able to view the |
| 1755 |
|
* hidden content. |
| 1756 |
|
* |
| 1757 |
|
* @param $type |
| 1758 |
|
* string 'node' or 'comment' |
| 1759 |
* @param $cid |
* @param $cid |
| 1760 |
* int cid (if comment) |
* int nid or cid |
| 1761 |
|
* @return array |
| 1762 |
|
* 'path' => relative path, 'fragment' => if comment in a node view |
| 1763 |
*/ |
*/ |
| 1764 |
function _hidden_goto_unhidden($nid, $cid = 0) { |
function hidden_path($type, $id) { |
| 1765 |
drupal_set_message("_hidden_goto_unhidden $nid $cid"); |
if ($hidden = _hidden_hidden_check($type, $id)) { |
| 1766 |
if (isset($_REQUEST['destination'])) { |
return array('path' => 'hidden/'. $type .'/'. $id); |
|
// this is pre-empting the probability that views.module displays may return to same location |
|
|
// some other switch may be required as well |
|
|
if (drupal_substr($_REQUEST['destination'], 0, 6) == 'hidden') { |
|
|
unset($_REQUEST['destination']); |
|
|
} |
|
|
else { |
|
|
drupal_goto(); |
|
|
} |
|
| 1767 |
} |
} |
| 1768 |
$url = 'node/'. $nid; |
else { |
| 1769 |
if ($cid != 0) { |
// @todo if 'comment' get 'nid' _hidden_comment_get_node(); |
| 1770 |
$fragment = 'comment-'. $cid; |
$path = 'node/'. $nid; |
| 1771 |
|
if ($cid != 0) { |
| 1772 |
|
$fragment = 'comment-'. $cid; |
| 1773 |
|
} |
| 1774 |
|
return array('path' => $path, 'fragment' => $fragment); |
| 1775 |
} |
} |
|
drupal_goto($url, NULL, $fragment); |
|
| 1776 |
} |
} |
| 1777 |
|
|
| 1778 |
/** |
/** |