How to specify PHP block visibility settings for content types AND loads of urls? I wrote lately some instruction to display a block in two different cases:  


when the content type is [my-content-1] or [my-content-2]  
when the url is /my_page1 or /my_page2  


I found how to do it in Block visible for Specific Content Type AND Specific URL. 

&lt;?php
$match = FALSE;
$types = array('content-petites_annonces' =&gt; 1);
if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' =&gt; $nid));
  $type = $node-&gt;type;
  if (isset($types[$type])) {
    $match = TRUE;
  }
}

if (substr($_SERVER["REQUEST_URI"], 0, 10) == '/petitesan')
{ $match = TRUE;}

if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/content-petites_annonces
")
{ $match = TRUE;}

return $match;
?&gt;


It works fine, I could declare several content types in the first array (I've got 6).
But as for the urls, it only works if I repeat the same line every time (and there are loads of them).

if (substr($_SERVER["REQUEST_URI"], 0) == "/my_page1
        ")
    { $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/my_page2
    ")
    { $match = TRUE;}
...


I am certain there is a more mutualized way to do it.
Is there also a mean to get it working regardless of the pagination, i.e. whithout having to notify every time 

 if (substr($_SERVER["REQUEST_URI"], 0) == "/my_page?page=X 
            ")
            { $match = TRUE;}


Is the answer hidden in the 0, 10 in the precision about the request URI? I didn't even used that line.
This sounds like the perfect use case for something like the Context module. Contexts are triggered and become active, and would save you from writing tons of PHP to get the matching to work in an unlimited number of use cases and edge cases.


  Think of conditions as a set of rules that are checked during page
  load to see what context is active. Any reactions that are associated
  with active contexts are then fired.


Related modules