Posted By

eethann on 08/15/07


Tagged

php textmate drupal phptemplate theming


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

basicmagic
chucktrukk


phptemplae page template based on uri


 / Published in: PHP
 

  1. <?php
  2. function _phptemplate_variables($hook, $vars) {
  3. switch ($hook) {
  4. case 'page':
  5. // this is a hack to suggest template files based on request uri
  6. // to suplement standard arg-based suggestions. this allows for
  7. // aliases to be taken into account
  8. $request_uri = $_SERVER['REQUEST_URI'];
  9. $request_uri = str_replace('my_statement','application',$request_uri);
  10. $suggestion = 'page';
  11. $suggestions = array();
  12. $matches = explode('/',$request_uri);
  13. $num_matches = count($matches);
  14. //ignore the first match, since the URI is of the form /path/to/uri
  15. for ($i=1;$i<$num_matches;$i++) {
  16. $suggestion .= '-'. $matches[$i];
  17. $suggestions[] = $suggestion;
  18. }
  19. $vars['template_files'] = $suggestions; // array($section_template);
  20. break;
  21. // any additional code here
  22. }
  23. return $vars;
  24. }
  25. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: berkes on September 21, 2007

woa! This is seriously unsafe. It allows me to include and/or run an aribtrary file on your server. Please anyone looking at this: don't use this code. $request_uri, $suggestions and so forth must be sanitised at the VERY least. But even then, they should best be checked against a whitelist of template files allowed to be included.

You need to login to post a comment.