A Poor Coder's Devel Themer Port for Drupal 5

Ethan's picture

Let me start by saying I’m not proud of this, it is one of those awful awful hacks which I should be ashamed of and appalled that I would even consider, one of those hideous violations of every coding standard known to good coders throughout the world.

What is this horrid, monstrous bit of code hackery I’m referring to? It’s a simple hack to the theme function which provides a very rudimentary version of some of the theme-level information so elegantly and profoundly usefully exposed by Moshe Weitzman’s Devel Themer module. For various reasons, this hack actually isn’t that egregious; for one it is ONLY FOR USE ON DEVELOPMENT SITES, and therefore does not all into that more loathsome category of coding dark secrets which are injected into codebases in the 11th hour to make Drupal conform to non-Drupal-tuned functional specifications. In addition, the hack allows custom processing of theme output to be included in the info dump for themed blocks, and therefore makes incredibly arduous tasks like finding the source of a missing </div> tag a great deal less awful. Let’s face it (with relish): sometimes hacking core is just the best way to debug difficult problems.

So, enough stalling, just what is this horrible, awful, shameful hack I’ve devised. Well, it’s anticlimactically simple, actually. Just insert the following code into the function theme() declaration in theme.inc just above the return call_user_func_array($functions[$function], $args) call:

<?php  
/* BEGIN: poor coders devel themer hack to determine where content is being generated */    
  
if (is_string($rtn)) {
    
$odivs substr_count($rtn'&lt;div');
    
$cdivs substr_count($rtn'&lt;/div');
    
$ne_divs = ($odivs!=$cdivs)?" NE_DIV_TAGS":'';
    return 
"&lt;div class=\"THEMER-DUMP\" style=\"display:none\"&gt;\nSTART: " .
      
$functions[$function] . " ($odivs,$cdivs)$ne_divs\n&lt;/div&gt;" $rtn 
      
"&lt;div class=\"THEMER-DUMP\" style=\"display:none\"&gt;\nEND: " 
      
$functions[$function]    . " ($odivs,$cdivs)\n&lt;/div&gt;";
  } else {
    return 
$rtn;
  }
  
/* END: poor coders devel themer */
?>

This code is tuned for finding unclosed div tags: at the end of every themer output dump is a count of open and close div tags. This was what I needed at the time, but there is no reason why additional data cannot be included. The code should be commented out except when needed and NEVER PUT ON PRODUCTION WEB SITES, but hopefully will be useful to some people (at least until a real port of the Devel Themer functions emerges for Drupal 5).

Comments

Anonymous's picture

ingenious
ingilizce

Anonymous's picture

It is incredible that some people are actually devoting so much time learning and developing these. Thanks for sharing.
ingilizdili

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockcode>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
Are you a robot? We usually like robots, but not in our comments.
By submitting this form, you accept the Mollom privacy policy.