Enable "fancy" PHP source higlighting w/ .phps ?

4 posts / 0 new
Last post
#1 Thu, 06/04/2009 - 07:23
fuscata

Enable "fancy" PHP source higlighting w/ .phps ?

Is there any way to enable automatic highlighing of php source files (.phps extension)?

In a non-suexec environment it's enabled by adding: AddType application/x-httpd-php-source .phps to /etc/apache2/mods-available/php5.conf

Thanks!

Thu, 06/04/2009 - 07:32
andreychek

Depending on your setup -- in the individual domains listed in /etc/apache2/sites-enabled/SITENAME, there may be a number of sections such as:

[code:1]
AddType application/x-httpd-php5 .php5
AddType application/x-httpd-php4 .php
[/code:1]

Try adding the .phps type to one of them, restart Apache, and see if that does the trick.
-Eric

Mon, 01/04/2010 - 11:02 (Reply to #2)
fuscata

I have tried various combinations of the following, in the <Directory ...public_html> section and in the <VirtualHost...> section:

AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php5 .phps
AddHandler fcgid-script .phps
AddHandler application/x-httpd-php-source .phps

I even tried creating an alternate fcgi wrapper script that passed the -s switch to the php binary.

Mon, 12/28/2009 - 18:18 (Reply to #3)
fuscata

On the off chance that anyone else is looking for a solution to this, I was able to solve it by creating my own highlight script, which has the added benefit of generating a complete & valid HTML 4.01 page:

Services > Configure Website > Edit Directives and add (somewhere after "RewriteEngine on"):
RewriteCond %{REQUEST_URI} \.phps$ [NC]
RewriteCond %{REQUEST_URI} !\^source.php
RewriteRule ^(.*)$ /source.php?file=$1 [L]

/home/whatever/public_html/source.php:
<?php
$file = isset($_REQUEST['file']) ? ('/' . trim($_SERVER['DOCUMENT_ROOT'], ' /') . '/' . trim(str_replace('../', '', $_REQUEST['file']), ' /')) : '';
if (strlen($file) > 5 && substr($file, -5) == '.phps' && file_exists($file)):
?>

Source of <?php echo htmlentities(substr(strrchr($file, DIRECTORY_SEPARATOR), 1, -1)); ?>
<?php
echo str_replace('', '', highlight_file($file, TRUE));
?><?php
else:
header('HTTP/1.0 404 Not Found');
?>

404 Not Found

Not Found
The requested URL <?php echo htmlentities($_SERVER['REQUEST_URI']); ?> was not found on this server.
<?php endif; ?>

Topic locked