Skip to content

Commit 9f2b70d

Browse files
author
Ilia Alshanetsky
committed
Added .phps support to Apache 2. It can be enabled by adding
AddType application/x-httpd-php-source .phps to httpd.conf
1 parent df837e6 commit 9f2b70d

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

sapi/apache2filter/sapi_apache2.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "SAPI.h"
2828

2929
#include "ext/standard/php_smart_str.h"
30+
#include "ext/standard/php_standard.h"
3031

3132
#include "apr_strings.h"
3233
#include "ap_config.h"
@@ -440,12 +441,23 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
440441
php_apache_request_ctor(f, ctx TSRMLS_CC);
441442

442443
apr_file_name_get(&path, ((apr_bucket_file *) b->data)->fd);
443-
zfd.type = ZEND_HANDLE_FILENAME;
444-
zfd.filename = (char *) path;
445-
zfd.free_filename = 0;
446-
zfd.opened_path = NULL;
447-
448-
php_execute_script(&zfd TSRMLS_CC);
444+
445+
/* Determine if we need to parse the file or show the source */
446+
if (!strncmp(ctx->r->handler, "application/x-httpd-php", sizeof("application/x-httpd-php"))) {
447+
zfd.type = ZEND_HANDLE_FILENAME;
448+
zfd.filename = (char *) path;
449+
zfd.free_filename = 0;
450+
zfd.opened_path = NULL;
451+
452+
php_execute_script(&zfd TSRMLS_CC);
453+
} else {
454+
zend_syntax_highlighter_ini syntax_highlighter_ini;
455+
456+
php_get_highlight_struct(&syntax_highlighter_ini);
457+
458+
highlight_file((char *)path, &syntax_highlighter_ini TSRMLS_CC);
459+
}
460+
449461
php_apache_request_dtor(f TSRMLS_CC);
450462

451463
ctx->request_processed = 1;
@@ -560,10 +572,13 @@ static void php_add_filter(request_rec *r, ap_filter_t *f)
560572

561573
static void php_insert_filter(request_rec *r)
562574
{
563-
if (r->content_type &&
564-
strcmp(r->content_type, "application/x-httpd-php") == 0) {
565-
php_add_filter(r, r->output_filters);
566-
php_add_filter(r, r->input_filters);
575+
int content_type_len = strlen("application/x-httpd-php");
576+
577+
if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) {
578+
if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", strlen("-source"))) {
579+
php_add_filter(r, r->output_filters);
580+
php_add_filter(r, r->input_filters);
581+
}
567582
}
568583
}
569584

0 commit comments

Comments
 (0)