Posted By

BoNzO on 01/01/10


Tagged

drupal block


Versions (?)

Make a Drupal Block Visible for Entire Site Sections but NOT Specific Sub-sections or Pages


 / Published in: PHP
 

  1. <?php
  2. /* a list a pages to include in standard block include/exclude format (one per line) */
  3. $include = "some/site/section/*
  4. another/page/here
  5. node/34";
  6.  
  7. /* a list a pages to exclude in standard block include/exclude format (one per line) */
  8. $exclude = "some/site/section/page1
  9. some/site/section/page2";
  10.  
  11. /* ----------- DO NOT TOUCH ANYTHING BELOW THIS LINE ----------- */
  12. $match = FALSE;
  13. $path = drupal_get_path_alias($_GET['q']);
  14. $regexp = '/^('. preg_replace(array('/(
  15. ?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($include, '/')) .')$/';
  16. if (preg_match($regexp, $path)) {
  17. $regexp = '/^('. preg_replace(array('/(
  18. ?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($exclude, '/')) .')$/';
  19. if (!preg_match($regexp, $path)) {
  20. $match = TRUE;
  21. }
  22. }
  23. return $match;
  24. ?>

Report this snippet  

You need to login to post a comment.