Posted By

metareason on 03/20/08


Tagged

drupal 9l


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

metareason
basicmagic


Group menu block only shown on og nodes or views very hacky


 / Published in: PHP
 

URL: http://www.ninelanterns.com.au

Very hacky and site specific, uses ogsetgroup_context() to check if node is in a group, but also treats nodes that start with path groups/group-name-here/... as in group 'context group-name-here'

  1. //***********************
  2. // paste this in block body
  3. //***********************
  4.  
  5. <?php
  6. // get the current group nid if we can
  7. $group_node = og_set_group_context();
  8. $gid02 = $group_node->nid;
  9. $gid = (int)$gid02;
  10. if ($gid02 === null) { // bork: couldn't get the group nid, see Og Tracker patch for possible solution?? http://drupal.org/node/66145
  11. // HACK: get the internal (source) url from the first part of the path with arg, expecting to find 'group/group-name'
  12. $group_url = drupal_lookup_path('source', arg(0).'/'.arg(1));
  13. // extract the group node id, load the node and get the title
  14. $group_url_exploded = explode('/', $group_url);
  15. $gid = $group_url_exploded[1];
  16. $group_node = node_load($gid);
  17. }
  18.  
  19. $group_title = $group_node->title;
  20.  
  21.  
  22. $group_path = drupal_get_path_alias('node/'.$gid);
  23.  
  24. // assumes this block is built on a node that's in a group
  25.  
  26. // build the links
  27. $items[] = l(t('Forum'), 'forums/'.substr($group_path, 6).'/group-discussion');
  28. $items[] = l(t('Events'), $group_path.'/events');
  29. $items[] = l(t('Photos'), $group_path.'/photos');
  30. $items[] = l(t('Links'), $group_path.'/links');
  31. $items[] = l(t('Resources'), $group_path.'/resources');
  32.  
  33. print '<h2 class = "title">'.$group_title.'</h2>';
  34.  
  35. // We theme our array of links as an unordered list.
  36. print theme('item_list', $items);
  37. ?>
  38.  
  39.  
  40. //***********************
  41. // paste this in block visibility php
  42. //***********************
  43.  
  44. <?php
  45. $match = FALSE;
  46.  
  47. // get the current group nid
  48. $group_node = og_set_group_context();
  49. $gid02 = $group_node->nid;
  50. $gid = (int)$gid02;
  51. if ($gid02 === null) $gid = 0;
  52.  
  53. // are we on a group page?
  54. // HACK: second param to also show this on group views generated pages
  55. // TODO: fix this crapness: (substr($_SERVER["REQUEST_URI"], 0, 7) == '/group/')
  56.  
  57. if (($gid != 0) || (substr($_SERVER["REQUEST_URI"], 0, 7) == '/group/')) {
  58. global $user;
  59. // is the user a member of this group?
  60. if ($user->og_groups[$gid]['nid'] == $gid) {
  61. $match = TRUE;
  62. }
  63. }
  64.  
  65. return $match;
  66. ?>

Report this snippet  

You need to login to post a comment.