Viewing Source of Example: viewsource


<?php

/*
* View Source Example
*
* This example simply renders the source for a given example, so that we may
* inspect them from within the browser.
*/

if (empty ($parameters['example'])) {
    
// default to viewing self
    
$parameters['example'] = 'viewsource';
} elseif (
preg_match ('/[^a-zA-Z0-9_-]/', $parameters['example'])) {
    
// check for illegal characters in example name
    
return '';
}

if (!
in_array ($parameters['type'], array ('boxes', 'forms', 'html'))) {
    
// if type is not in list, assume default of 'boxes' (for viewing self)
    
$parameters['type'] = 'boxes';
}

$extensions = array (
    
'boxes' => '/index.php',
    
'forms' => '/index.php',
    
'html' => '.spt',
);

ob_start ();
highlight_file ('inc/app/example/' . $parameters['type'] . '/' . $parameters['example'] . $extensions[$parameters['type']]);
$parameters['source'] = ob_get_contents ();
ob_end_clean ();

echo
template_simple ('viewsource.spt', $parameters);
exit;

?>

Back