The attached patch adds .phps file support for Apache 2, allowing Apache 2
users to show prettified source of their scripts, just like their Apache 1
counterparts can.
It is a fairly simple patch, that adds just 2 cmp overhead for this
functionality, so its not too bad imho.
Please review the patch and let me know if there are any objections to it's
addition.
Ilia
Index: sapi_apache2.c
===================================================================
RCS file: /repository/php4/sapi/apache2filter/sapi_apache2.c,v
retrieving revision 1.85
diff -u -3 -p -r1.85 sapi_apache2.c
--- sapi_apache2.c 23 Sep 2002 18:51:34 -0000 1.85
+++ sapi_apache2.c 4 Oct 2002 15:33:46 -0000
@@ -27,6 +27,7 @@
#include "SAPI.h"
#include "ext/standard/php_smart_str.h"
+#include "ext/standard/php_standard.h"
#include "apr_strings.h"
#include "ap_config.h"
@@ -440,12 +441,23 @@ static int php_output_filter(ap_filter_t
php_apache_request_ctor(f, ctx TSRMLS_CC);
apr_file_name_get(&path, ((apr_bucket_file *) b->data)->fd);
- zfd.type = ZEND_HANDLE_FILENAME;
- zfd.filename = (char *) path;
- zfd.free_filename = 0;
- zfd.opened_path = NULL;
-
- php_execute_script(&zfd TSRMLS_CC);
+
+ /* Determine if we need to parse the file or show the source */
+ if (ctx->r->handler[strlen("application/x-httpd-php")] == '\0') {
+ zfd.type = ZEND_HANDLE_FILENAME;
+ zfd.filename = (char *) path;
+ zfd.free_filename = 0;
+ zfd.opened_path = NULL;
+
+ php_execute_script(&zfd TSRMLS_CC);
+ } else {
+ zend_syntax_highlighter_ini syntax_highlighter_ini;
+
+ php_get_highlight_struct(&syntax_highlighter_ini);
+
+ highlight_file((char *)path, &syntax_highlighter_ini TSRMLS_CC);
+ }
+
php_apache_request_dtor(f TSRMLS_CC);
ctx->request_processed = 1;
@@ -560,10 +572,15 @@ static void php_add_filter(request_rec *
static void php_insert_filter(request_rec *r)
{
- if (r->content_type &&
- strcmp(r->content_type, "application/x-httpd-php") == 0) {
- php_add_filter(r, r->output_filters);
- php_add_filter(r, r->input_filters);
+ int content_type_len = strlen("application/x-httpd-php");
+
+ if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) {
+ if (r->content_type[content_type_len] == '\0' ||
+ (r->content_type[content_type_len] == 's' && r->content_type[content_type_len+1] == '\0')) {
+
+ php_add_filter(r, r->output_filters);
+ php_add_filter(r, r->input_filters);
+ }
}
}
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php