<?php // ۞// text { encoding:utf-8 ; bom:no ; linebreaks:unix ; tabs:4sp ; }
$csd_version '0.3';

/*
    simple source dump  
    (xhtml version)

    this simply dumps the source file to the screen using php's 
    built-in "highlight_file" function, which probably requires 
    at least php 4.2. 
    
    We than transform the output to xhtml 1.0 strict, which I like.

    note: php5 now does this correctly, so if you have php5, you 
    don't need this!

    usage:

        in your php script, at the bottom, probably..

        // direct access -> dump the php source..
        if ($_SERVER['SCRIPT_FILENAME'] == __FILE__) {
            @include ($_SERVER['DOCUMENT_ROOT'].'/inc/source-dump.php');
            source_dump(__FILE__);
        }


    the option second parameter "embed" can be set to true..

        source_dump("/path/to/file.php", true);
    
    to just return the highlighted string as a string. You could drop
    it into any page with something like..

    <?php echo source_dump($_SERVER['DOCUMENT_ROOT'].'/serv/src/rss/config.php', true); ?>
    
    The only advantage to using this as opposed to plain old highlight_file 
    is that you get xhtml compliant source. 
    
    I think it's a big advantage.

    ;o)
    (or

    
    © 2003-> (or @ corz.org ;o)
*/

// see ya!
function source_dump() {
global 
$csd_version;
$file func_get_arg(0);
if (
func_num_args() > 1) { $embed true; } else { $embed false; }


    
// php syntax highlighting..
    
ini_set('highlight.string','#E53600');
    
ini_set('highlight.comment','#FFAD1D');
    
ini_set('highlight.keyword','#47A35E');
    
ini_set('highlight.bg','#FFFFFF');
    
ini_set('highlight.default','#3F6DAE');
    
ini_set('highlight.html','#0D3D0D');

    
$highlighted highlight_file($filetrue);

    
// switch <span> tags to xhtml-friendly <span>
    // so, reading a source dump of *this* file, will fry your brain!
    
$highlighted str_replace('style="color:''style="color:'$highlighted);
    
$highlighted str_replace('span''span'$highlighted);

    if (!
$embed) {
        
// initialize..
        
if (stristr(@$_SERVER['HTTP_ACCEPT'],'application/xhtml+xml')) {
            
$doc_content 'application/xhtml+xml';
        } else {
            
$doc_content 'text/html';
        }
        die(
'<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="'
.$doc_content.'; charset=utf-8" />
<title>php source dump of '
.basename($file).' (courtesy of corz.org source dumper v'.$csd_version.')</title>
</head>
<body>
<div style="margin:5px">
    '
.$highlighted.'
</div>
</body>
</html>
'
);
    } else {
        return 
$highlighted;
    }
}

// direct access -> let's dump the php source!
if (realpath($_SERVER['SCRIPT_FILENAME']) == realpath(__FILE__)) { source_dump(__FILE__); }

?>