#537654 by catch: Tidy up comment links, and remove hook_link() in favour of hook_page_alter().

merge-requests/26/head
Angie Byron 2009-08-08 22:52:59 +00:00
parent 1da6ef52c4
commit 0355caac41
3 changed files with 60 additions and 160 deletions

View File

@ -838,6 +838,66 @@ function comment_build_content($comment, $build_mode = 'full') {
return $comment;
}
/**
* Helper function, build links for an individual comment.
*
* Adds reply, edit, delete etc. depending on the current user permissions.
*
* @param $comment
* The comment object.
* @return
* A structured array of links.
*/
function comment_links($comment) {
$links = array();
$node = node_load($comment->nid);
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('administer comments') && user_access('post comments')) {
$links['comment_delete'] = array(
'title' => t('delete'),
'href' => "comment/delete/$comment->cid",
'html' => TRUE,
);
$links['comment_edit'] = array(
'title' => t('edit'),
'href' => "comment/edit/$comment->cid",
'html' => TRUE,
);
$links['comment_reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/$comment->nid/$comment->cid",
'html' => TRUE,
);
if ($comment->status == COMMENT_NOT_PUBLISHED) {
$links['comment_approve'] = array(
'title' => t('approve'),
'href' => "comment/approve/$comment->cid",
'html' => TRUE,
);
}
}
elseif (user_access('post comments')) {
if (comment_access('edit', $comment)) {
$links['comment_edit'] = array(
'title' => t('edit'),
'href' => "comment/edit/$comment->cid",
'html' => TRUE,
);
}
$links['comment_reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/$comment->nid/$comment->cid",
'html' => TRUE,
);
}
else {
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', $node);
$links['comment_forbidden']['html'] = TRUE;
}
}
return $links;
}
/**
* Construct a drupal_render() style array from an array of loaded comments.
*
@ -1323,80 +1383,6 @@ function comment_delete_multiple($cids) {
}
}
/**
* Implement hook_link().
*/
function comment_link($type, $object, $build_mode) {
if ($type == 'comment') {
$links = comment_links($object, FALSE);
return $links;
}
}
/**
* Build command links for a comment (e.g.\ edit, reply, delete) with respect to the current user's access permissions.
*
* @param $comment
* The comment to which the links will be related.
* @return
* An associative array containing the links.
*/
function comment_links(&$comment) {
global $user;
$links = array();
$node = node_load($comment->nid);
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('administer comments') && user_access('post comments')) {
$links['comment_delete'] = array(
'title' => t('delete'),
'href' => "comment/delete/$comment->cid",
'html' => TRUE,
);
$links['comment_edit'] = array(
'title' => t('edit'),
'href' => "comment/edit/$comment->cid",
'html' => TRUE,
);
$links['comment_reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/$comment->nid/$comment->cid",
'html' => TRUE,
);
if ($comment->status == COMMENT_NOT_PUBLISHED) {
$links['comment_approve'] = array(
'title' => t('approve'),
'href' => "comment/approve/$comment->cid",
'html' => TRUE,
);
}
}
elseif (user_access('post comments')) {
if (comment_access('edit', $comment)) {
$links['comment_edit'] = array(
'title' => t('edit'),
'href' => "comment/edit/$comment->cid",
'html' => TRUE,
);
}
$links['comment_reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/$comment->nid/$comment->cid",
'html' => TRUE,
);
}
else {
$node = node_load($comment->nid);
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', $node);
$links['comment_forbidden']['html'] = TRUE;
}
}
return $links;
}
/**
* Comment operations. Offer different update operations depending on
* which comment administration page is being viewed.

View File

@ -1594,27 +1594,6 @@ function theme_node_search_admin($form) {
return $output;
}
/**
* Implement hook_link().
*/
function node_link($type, $node, $build_mode) {
$links = array();
if ($type == 'node') {
if ($build_mode == 'teaser') {
$links['node_read_more'] = array(
'title' => t('Read more'),
'href' => "node/$node->nid",
// The title attribute gets escaped when the links are processed, so
// there is no need to escape here.
'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title)))
);
}
}
return $links;
}
function _node_revision_access($node, $op = 'view') {
static $access = array();
if (!isset($access[$node->vid])) {

View File

@ -511,71 +511,6 @@ function hook_image_toolkits() {
);
}
/**
* Define internal Drupal links.
*
* This hook enables modules to add links to many parts of Drupal. Links
* may be added in the navigation block, for example.
*
* The returned array should be a keyed array of link entries. Each link can
* be in one of two formats.
*
* The first format will use the l() function to render the link:
* - attributes: Optional. See l() for usage.
* - fragment: Optional. See l() for usage.
* - href: Required. The URL of the link.
* - html: Optional. See l() for usage.
* - query: Optional. See l() for usage.
* - title: Required. The name of the link.
*
* The second format can be used for non-links. Leaving out the href index will
* select this format:
* - title: Required. The text or HTML code to display.
* - attributes: Optional. An associative array of HTML attributes to apply to the span tag.
* - html: Optional. If not set to true, check_plain() will be run on the title before it is displayed.
*
* @param $type
* An identifier declaring what kind of link is being requested.
* Possible values:
* - comment: Links to be placed below a comment being viewed.
* @param $object
* A comment object.
* @param $build_mode
* Build mode for the node, e.g. 'full', 'teaser'...
* @return
* An array of the requested links.
*
*/
function hook_link($type, $object, $build_mode) {
$links = array();
if ($type == 'comment') {
$links = comment_links($object, FALSE);
return $links;
}
return $links;
}
/**
* Perform alterations before links on a comment are rendered. One popular use of
* this hook is to modify/remove links from other modules. If you want to add a link
* to the links section of a node, use hook_link instead.
*
* @param $links
* Nested array of links for the node keyed by providing module.
* @param $node
* A node object that contains the links.
*/
function hook_link_alter(array &$links, $node) {
foreach ($links as $module => $link) {
if (strpos($module, 'taxonomy_term') !== FALSE) {
// Link back to the forum and not the taxonomy term page
$links[$module]['href'] = str_replace('taxonomy/term', 'forum', $link['href']);
}
}
}
/**
* Perform alterations profile items before they are rendered. You may omit/add/re-sort/re-categorize, etc.
*