summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-02 11:25:18 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-02 11:25:18 +0000
commiteaf21849a1643087fa014d3cdf528cc17cccb252 (patch)
treeb93deac7b172731fd2d89af65d3dbd5a1fb4acf3
parent065346b3662e0ead6d4e7e0cffdc4d3aed4b2753 (diff)
downloadbrdo-eaf21849a1643087fa014d3cdf528cc17cccb252.tar.gz
brdo-eaf21849a1643087fa014d3cdf528cc17cccb252.tar.bz2
- Accidentically committed two patches at once. Rolled back one of them. Sorry.
-rw-r--r--modules/comment/comment.module123
-rw-r--r--modules/system/system.api.php19
2 files changed, 94 insertions, 48 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 7725ea6ae..526525601 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -822,56 +822,9 @@ function comment_build_content($comment, $build_mode = 'full') {
$comment->content += field_attach_view('comment', $comment, $build_mode);
if (empty($comment->in_preview)) {
- $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;
- }
- }
-
$comment->content['links']['comment'] = array(
'#theme' => 'links',
- '#links' => $links,
+ '#links' => comment_links($comment),
'#attributes' => array('class' => 'links inline'),
);
}
@@ -1371,6 +1324,80 @@ 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.
*
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 550d43431..9c5435275 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -558,6 +558,25 @@ function hook_link($type, $object, $build_mode) {
}
/**
+ * 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.
*
* @param $account