Posted By

metareason on 03/20/08


Tagged

drupal 9l


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

metareason
wbowers
basicmagic


Group Add Content Block Only Shown On Og Nodes Or Views Very Hacky


 / Published in: PHP
 

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

Similar hack to http://snipplr.com/view/5505/group-menu-block-only-shown-on-og-nodes-or-views-very-hacky/

  1. //***********************
  2. // paste this in block body
  3. //***********************
  4.  
  5. <?php
  6.  
  7. // get the current group nid if we can
  8. $group_node = og_set_group_context();
  9. $gid02 = $group_node->nid;
  10. $gid = (int)$gid02;
  11. if ($gid02 === null) { // bork: couldn't get the group nid, see Og Tracker patch for possible solution?? http://drupal.org/node/66145
  12. // HACK: get the internal (source) url from the first part of the path with arg, expecting to find 'group/group-name'
  13. $group_url = drupal_lookup_path('source', arg(0).'/'.arg(1));
  14. // extract the group node id, load the node and get the title
  15. $group_url_exploded = explode('/', $group_url);
  16. $gid = $group_url_exploded[1];
  17. }
  18.  
  19. $group_path = drupal_get_path_alias('node/'.$gid);
  20.  
  21. // TODO: work out how to find the the 7 for each group...
  22. //$items[] = l(t('Forum post'), 'node/add/forum/7', array(), 'gids[]='.$gid);
  23.  
  24. $items[] = l(t('Event'), 'node/add/group-event', array(), 'gids[]='.$gid);
  25. $items[] = l(t('Photo'), 'node/add/group-photo', array(), 'gids[]='.$gid);
  26. $items[] = l(t('Link'), 'node/add/group-link', array(), 'gids[]='.$gid);
  27. $items[] = l(t('Resource (Document)'), 'node/add/group-resource-document', array(), 'gids[]='.$gid);
  28. $items[] = l(t('Resource (Video)'), 'node/add/group-resource-video', array(), 'gids[]='.$gid);
  29. $items[] = l(t('Resource (Audio)'), 'node/add/group-resource-audio', array(), 'gids[]='.$gid);
  30. ?>
  31.  
  32. <h2 class = "title">Add group content:</h2>
  33.  
  34. <?php
  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.