| 1 |
<?php |
<?php |
| 2 |
// $Id: hidden.module,v 1.5 2008/12/10 23:03:47 ekes Exp $ |
// $Id: hidden.module,v 1.6 2008/12/12 19:23:35 ekes Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 100 |
*/ |
*/ |
| 101 |
function hidden_perm() { |
function hidden_perm() { |
| 102 |
return array('access hidden', 'report for hiding', 'mark as hidden', 'administer hidden', 'bypass hidden filter'); |
return array('access hidden', 'report for hiding', 'mark as hidden', 'administer hidden', 'bypass hidden filter'); |
| 103 |
} |
} |
| 104 |
|
|
| 105 |
/** |
/** |
| 106 |
* Implementation of hook_theme(). |
* Implementation of hook_theme(). |
| 435 |
function hidden_comment(&$comment, $action) { |
function hidden_comment(&$comment, $action) { |
| 436 |
switch ($action) { |
switch ($action) { |
| 437 |
case 'view': |
case 'view': |
| 438 |
if ($comment->status == COMMENT_NOT_PUBLISHED) { |
if (isset($comment->status) && $comment->status == COMMENT_NOT_PUBLISHED) { |
| 439 |
// all hidden comments are unpublished so no point making unnecessary queries |
// all hidden comments are unpublished so no point making unnecessary queries |
| 440 |
if ($hidden=_hidden_hidden_get('comment', $comment->cid)) { |
if ($hidden=_hidden_hidden_get('comment', $comment->cid)) { |
| 441 |
$title = check_plain($hidden->title); |
$title = check_plain($hidden->title); |
| 443 |
$description = check_markup($hidden->description, FILTER_HTML_STRIP, FALSE); |
$description = check_markup($hidden->description, FILTER_HTML_STRIP, FALSE); |
| 444 |
$private = check_markup($hidden->privatenote, FILTER_HTML_STRIP, FALSE); |
$private = check_markup($hidden->privatenote, FILTER_HTML_STRIP, FALSE); |
| 445 |
$comment->comment = theme('hidden_view_reason', $title, $public, $description, $private, $comment->comment); |
$comment->comment = theme('hidden_view_reason', $title, $public, $description, $private, $comment->comment); |
| 446 |
$comment->subject = t('HIDDEN: ') . $comment->subject; |
$comment->subject = t('HIDDEN: @title', array('@title' => $comment->subject)); |
| 447 |
} |
} |
| 448 |
} |
} |
| 449 |
break; |
break; |
| 457 |
hidden_filter_content($comment['subject'] .' '. $comment['comment'], 'comment', $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)) { |
// @todo array, always? |
| 461 |
|
// what should happen here? filter? |
| 462 |
|
if (! hidden_hidden_check('comment', $comment['cid'])) { |
| 463 |
break; |
break; |
| 464 |
} |
} |
| 465 |
|
break; |
| 466 |
case 'delete': |
case 'delete': |
| 467 |
if (_hidden_hidden_delete('comment', $comment->cid)) { |
if (_hidden_hidden_delete('comment', $comment->cid)) { |
| 468 |
if (db_affected_rows()>0) { |
if (db_affected_rows()>0) { |
| 480 |
} |
} |
| 481 |
break; |
break; |
| 482 |
case 'form': |
case 'form': |
| 483 |
if ( _hidden_hidden_check('comment', $comment->cid) && user_access('administer hidden')) { |
if ( hidden_hidden_check('comment', $comment->cid) && user_access('administer hidden')) { |
| 484 |
//TODO edit form |
//TODO edit form |
| 485 |
return; |
return; |
| 486 |
} |
} |
| 506 |
$private = check_markup($hidden->privatenote, FILTER_HTML_STRIP, FALSE); |
$private = check_markup($hidden->privatenote, FILTER_HTML_STRIP, FALSE); |
| 507 |
// arg TRUE on teaser view |
// arg TRUE on teaser view |
| 508 |
$node->body = theme('hidden_view_reason', $title, $public, $description, $private, $node->body, !($arg)); |
$node->body = theme('hidden_view_reason', $title, $public, $description, $private, $node->body, !($arg)); |
| 509 |
$node->title = t('HIDDEN: ') . $node->title; // sadly usually set by this point for nodes |
$node->title = t('HIDDEN: @title', array('@title' => $node->title)); |
| 510 |
|
// sadly usually set by this point for nodes |
| 511 |
} |
} |
| 512 |
} |
} |
| 513 |
break; |
break; |
| 514 |
case 'update': |
case 'update': |
| 515 |
if ($action=='update' && $node->status) { |
if ($action=='update' && $node->status) { |
| 516 |
// node being updated and status is published check it wasn't hidden |
// node being updated and status is published check it wasn't hidden |
| 517 |
if (_hidden_hidden_check('node', $node->nid)) { |
if (hidden_hidden_check('node', $node->nid)) { |
| 518 |
if (_hidden_hidden_delete('node', $node->nid)) { |
if (_hidden_hidden_delete('node', $node->nid)) { |
| 519 |
_hidden_log(HIDDEN_LOG_UNHIDE, t('Hidden node published.'), 'node', $node->nid); |
_hidden_log(HIDDEN_LOG_UNHIDE, t('Hidden node published.'), 'node', $node->nid); |
| 520 |
drupal_set_message(t('Hidden node published.')); |
drupal_set_message(t('Hidden node published.')); |
| 632 |
$links['hidden-unhide'] = array( |
$links['hidden-unhide'] = array( |
| 633 |
'title' => t('unhide'), |
'title' => t('unhide'), |
| 634 |
'href' => "hidden/$type/$target/unhide", |
'href' => "hidden/$type/$target/unhide", |
| 635 |
'query' => drupal_get_destination(), |
// 'query' => drupal_get_destination(), |
| 636 |
); |
); |
| 637 |
} |
} |
| 638 |
} |
} |
| 805 |
$hide = array(); |
$hide = array(); |
| 806 |
$error = array(); |
$error = array(); |
| 807 |
foreach ($nids as $nid) { |
foreach ($nids as $nid) { |
| 808 |
if (! _hidden_hidden_check('node', $nid)) { |
if (! hidden_hidden_check('node', $nid)) { |
| 809 |
$nid = (int)$nid; |
$nid = (int)$nid; |
| 810 |
if (hidden_hidden_hide('node', $nid, $user->uid, 1)) { |
if (hidden_hidden_hide('node', $nid, $user->uid, 1)) { |
| 811 |
$hide[] = $nid; |
$hide[] = $nid; |
| 837 |
$error = array(); |
$error = array(); |
| 838 |
foreach ($nids as $nid) { |
foreach ($nids as $nid) { |
| 839 |
$nid = (int)$nid; |
$nid = (int)$nid; |
| 840 |
if (_hidden_hidden_check('node', $nid)) { |
if (hidden_hidden_check('node', $nid)) { |
| 841 |
if (_hidden_hidden_unhide('node', $nid)) { |
if (_hidden_hidden_unhide('node', $nid)) { |
| 842 |
$unhide[] = $nid; |
$unhide[] = $nid; |
| 843 |
} |
} |
| 870 |
* @return |
* @return |
| 871 |
* bool TRUE hidden FALSE not/fail. |
* bool TRUE hidden FALSE not/fail. |
| 872 |
*/ |
*/ |
| 873 |
function _hidden_hidden_check($type, $id) { |
function hidden_hidden_check($type, $id) { |
| 874 |
static $hidden, $ltype, $lid, $count; |
static $hidden, $ltype, $lid, $count; |
| 875 |
if ($type == $ltype && $id == $lid) { |
if ($type == $ltype && $id == $lid) { |
| 876 |
return $hidden; |
return $hidden; |
| 882 |
} |
} |
| 883 |
|
|
| 884 |
if ($type != 'node' && $type != 'comment') { |
if ($type != 'node' && $type != 'comment') { |
| 885 |
_hidden_log(HIDDEN_LOG_DEBUG, '_hidden_hidden_check() called with invalid $type'); |
_hidden_log(HIDDEN_LOG_DEBUG, 'hidden_hidden_check() called with invalid $type'); |
| 886 |
return FALSE; |
return FALSE; |
| 887 |
} |
} |
| 888 |
$table = ($type == 'node') ? 'node' : 'comment'; |
$table = ($type == 'node') ? 'node' : 'comment'; |
| 1006 |
|
|
| 1007 |
if ($hidden = _hidden_hidden_get($type, $id)) { |
if ($hidden = _hidden_hidden_get($type, $id)) { |
| 1008 |
if ($hidden->delay==0) { |
if ($hidden->delay==0) { |
| 1009 |
drupal_set_message('Item is already hidden!', 'error'); |
drupal_set_message(t('The %type is already hidden!', array('%type' => $type)), 'error'); |
| 1010 |
return FALSE; |
return FALSE; |
| 1011 |
} |
} |
| 1012 |
else { |
else { |
| 1176 |
if ($type != 'comment' && $type != 'node') { |
if ($type != 'comment' && $type != 'node') { |
| 1177 |
return FALSE; |
return FALSE; |
| 1178 |
} |
} |
| 1179 |
if (! is_integer($id) || $id < 1) { |
// @todo $nid is a string from node_save(); should be is_int |
| 1180 |
|
if (! is_numeric($id) || $id < 1) { |
| 1181 |
return FALSE; |
return FALSE; |
| 1182 |
} |
} |
| 1183 |
return TRUE; |
return TRUE; |
| 1214 |
* |
* |
| 1215 |
* @param $type |
* @param $type |
| 1216 |
* string content 'comment' or 'node'. |
* string content 'comment' or 'node'. |
| 1217 |
* @param $nid |
* @param $id |
| 1218 |
* int nid |
* int nid or cid |
|
* @param $cid |
|
|
* int cid or 0 if node |
|
| 1219 |
* @param $uid |
* @param $uid |
| 1220 |
* int uid |
* int uid |
| 1221 |
* @param $rid |
* @param $rid |
| 1227 |
* @return |
* @return |
| 1228 |
* FALSE on error |
* FALSE on error |
| 1229 |
*/ |
*/ |
| 1230 |
function _hidden_reported_hide($type, $type, $id, $uid, $rid=0, $public='', $private='') { |
function _hidden_reported_hide($type, $id, $uid, $rid=0, $public='', $private='') { |
| 1231 |
if ($type == 'node') { |
if ($type == 'node') { |
| 1232 |
$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')"; |
| 1233 |
return db_query($query, $id, $uid, time(), $rid, $public, $private); |
return db_query($query, $id, $uid, time(), $rid, $public, $private); |
| 1738 |
} |
} |
| 1739 |
|
|
| 1740 |
/** |
/** |
|
* drupal_goto() wrapper for redirecting to a possibly hidden item |
|
|
* |
|
|
* @param $id |
|
|
* nid |
|
|
* @param $cid |
|
|
* cid (if comment) |
|
|
*/ |
|
|
function hidden_goto($type, $id) { |
|
|
$path = hidden_path($type, $id); |
|
|
drupal_goto($path); |
|
|
} |
|
|
|
|
|
/** |
|
| 1741 |
* Get a functioning path to be able to see content. |
* Get a functioning path to be able to see content. |
| 1742 |
* |
* |
| 1743 |
* Basic version to start, should be possible to let people override. |
* Basic version to start, should be possible to let people override. |
| 1748 |
* string 'node' or 'comment' |
* string 'node' or 'comment' |
| 1749 |
* @param $cid |
* @param $cid |
| 1750 |
* int nid or cid |
* int nid or cid |
| 1751 |
|
* @param $view |
| 1752 |
|
* string action 'view', 'hide', 'report' |
| 1753 |
* @return array |
* @return array |
| 1754 |
* 'path' => relative path, 'fragment' => if comment in a node view |
* 'path' => relative path, 'fragment' => if comment in a node view |
| 1755 |
*/ |
*/ |
| 1756 |
function hidden_path($type, $id) { |
function hidden_path($type, $id, $action = 'view') { |
| 1757 |
if ($hidden = _hidden_hidden_check($type, $id)) { |
if (! _hidden_check_param($type, $id)) { |
| 1758 |
return array('path' => 'hidden/'. $type .'/'. $id); |
return 'hidden'; |
| 1759 |
} |
} |
| 1760 |
else { |
|
| 1761 |
// @todo if 'comment' get 'nid' _hidden_comment_get_node(); |
switch ($action) { |
| 1762 |
$path = 'node/'. $nid; |
case 'view': |
| 1763 |
if ($cid != 0) { |
return 'hidden/'. $type .'/'. $id; |
| 1764 |
$fragment = 'comment-'. $cid; |
case 'hide': |
| 1765 |
} |
return 'hidden/'. $type .'/'. $id .'/hide'; |
| 1766 |
return array('path' => $path, 'fragment' => $fragment); |
case 'report': |
| 1767 |
|
return 'hidden/'. $type .'/'. $id .'/report'; |
| 1768 |
} |
} |
| 1769 |
} |
} |
| 1770 |
|
|
| 1805 |
return variable_get('hidden_email', $default); |
return variable_get('hidden_email', $default); |
| 1806 |
} |
} |
| 1807 |
|
|
| 1808 |
|
/** |
| 1809 |
|
* Find which node a comment is attached to. |
| 1810 |
|
* |
| 1811 |
|
* @param $cid |
| 1812 |
|
* int cid |
| 1813 |
|
* @return |
| 1814 |
|
* int nid |
| 1815 |
|
*/ |
| 1816 |
|
function _hidden_comment_nid($cid) { |
| 1817 |
|
$comment = _comment_load($cid); |
| 1818 |
|
return $comment->nid; |
| 1819 |
|
} |