Hello

I'm hoping that this is possible.

I will need a global flag set up so that once the flag is triggered, it is updated site wide, for everyone visiting the node. But here's the catch: I only want the node author to be able to trigger the flag. I understand that this may be possible by using Contemplate, and putting an if block around it, but I would really like to keep the flag link inside of Drupals $links variable if I can.

Any ideas?

Thanks

Comments

XBleed’s picture

Status: Active » Closed (duplicate)

I ended up removing the flags from the node view, and manually adding them in the node.tpl.php file with flag_create_link(), I found #304799 and used it for reference.

For anyone interested, here is the code I used:

<?php
	global $user;
	if ($user->uid):
		print '<ul class="links inline">';
		if ($user->uid == $node->uid):
			print '<li>' . flag_create_link('sold', $node->nid) . '</li>';
		else:
			print '<li>' . flag_create_link('report', $node->nid) . '</li>';
			print '<li>' . flag_create_link('favorite', $node->nid) . '</li>';
		endif;
		print '</ul>';
	endif;
?>
minus’s picture

Version: 5.x-1.0-beta6 » 6.x-1.1

#drupal 6

 global $user;
  if ($user->uid) {
    print '<ul class="links inline">';
    if ($user->uid == $node->uid) {
      print '<li>'. flag_create_link('sold', $node->nid) .'</li>';
    }
    else {
      print '<li>'. flag_create_link('report', $node->nid) .'</li>';
      print '<li>'. flag_create_link('bookmark', $node->nid) .'</li>';
    }
    print '</ul>';
  }

I'd really like to thank Keyz_ at irc #drupal-support for this!

mooffie’s picture

kpv’s picture

Version: 6.x-1.1 » 6.x-1.2

Another variant

add case 'view': to flag_nodeapi (flag.module)

case 'view':
  //Preserving $node->uid
  $GLOBALS['content_author'] = $node->uid;

then change flag.tpl.php:

if ($setup) {
    drupal_add_css(drupal_get_path('module', 'flag') .'/theme/flag.css');
    drupal_add_js(drupal_get_path('module', 'flag') .'/theme/flag.js');
  }
  //Add your condition here. For example:
  if($user->uid <> $GLOBALS['content_author']) return;

  //'return' is used to terminate processing of flag.tpl.php (so the link will not be added)
kpv’s picture

Another solution:
Make a module (here hide_flag_favorite.module) and use hook_link_alter

// $Id$
/**
  * @file
  * Hide flag-favorite link for own nodes (replace 'flag-favorite' with 'flag-yourflagname')
  */


/*
* hook_link_alter
*
*/
function hide_flag_favorite_link_alter(&$links, $node){
  global $user;
  
  //replace $links['flag-yourflagname']
  if(isset($links['flag-favorite'])){

    //don't show on own node pages
    if($user->uid == $node->uid){
      unset($links['flag-favorite']);
    }
  }
}