You are here

function advanced_forum_link_alter in Advanced Forum 6.2

Implementation of hook_link_alter().

File

./advanced_forum.module, line 440
Enables the look and feel of other popular forum software.

Code

function advanced_forum_link_alter(&$links, $node, $comment = NULL) {
  if (empty($comment)) {
    $object = $node;
    $object_type = 'node';
  }
  else {
    $object = $comment;
    $object_type = 'comment';
  }

  // Check if we are altering links on a node that is displayed in a teaser.
  // @TODO: Find out if there's a better way to tell if this is a teaser.
  $teaser = !(arg(0) == 'node' && arg(1) > 0);
  if (advanced_forum_is_styled($object, $teaser, $object_type)) {

    // Change first post from "add comment" to "reply" if it isn't already.
    if (!empty($links['comment_add'])) {
      $links['comment_add']['title'] = t('reply');
    }

    // List the keys we are interested in.
    $affected_keys = array(
      'post_edit',
      'comment_edit',
      'post_delete',
      'comment_delete',
      'quote',
      'comment_add',
      'comment_reply',
      'comment_mover_node_prune',
      'comment_mover_comment_prune',
    );

    // Add extra span tags for image replacement.
    foreach ($links as $key => $link) {
      if (in_array($key, $affected_keys)) {
        $current_classes = empty($links[$key]['attributes']['class']) ? '' : $links[$key]['attributes']['class'];
        $links[$key]['attributes']['class'] = "{$current_classes} af-button-small";
        $links[$key]['title'] = '<span>' . $links[$key]['title'] . '</span>';
        $links[$key]['html'] = TRUE;
      }
    }

    // Put the links in a consistent order.
    foreach ($affected_keys as $key) {
      if (isset($links[$key])) {
        $temp = $links[$key];
        unset($links[$key]);
        $links[$key] = $temp;
      }
    }
  }
}