]> granicus.if.org Git - php/commitdiff
@ Fix stdout support with the swf extension. (Sterling)
authorSterling Hughes <sterling@php.net>
Tue, 15 Aug 2000 17:30:41 +0000 (17:30 +0000)
committerSterling Hughes <sterling@php.net>
Tue, 15 Aug 2000 17:30:41 +0000 (17:30 +0000)
ext/swf/php_swf.h
ext/swf/swf.c

index 6c00a97ef4700f82b503c9041abc0361fed98d3c..891581e4d8a7501914bff0f8ca6ac5ef2eb6bdb9 100644 (file)
@@ -28,6 +28,7 @@ extern zend_module_entry swf_module_entry;
 
 PHP_MINIT_FUNCTION(swf);
 PHP_MINFO_FUNCTION(swf);
+PHP_RINIT_FUNCTION(swf);
 extern void php_swf_define(INTERNAL_FUNCTION_PARAMETERS, int opt);
 extern void php_swf_fill_bitmap(INTERNAL_FUNCTION_PARAMETERS, int opt);
 extern void php_swf_geo_same(INTERNAL_FUNCTION_PARAMETERS, int opt);
@@ -99,6 +100,19 @@ PHP_FUNCTION(swf_translate);
 PHP_FUNCTION(swf_rotate);
 PHP_FUNCTION(swf_posround);
 
+typedef struct {
+       int use_file;
+       char *tmpfile_name;
+} php_swf_globals;
+
+#ifdef ZTS
+#define SWFG(v) (swf_globals->v)
+#define SWFLS_FETCH() php_swf_globals *swf_globals = ts_resource(gd_swf_id)
+#else
+#define SWFG(v) (swf_globals.v)
+#define SWFLS_FETCH()
+#endif
+
 #else
 #define swf_module_ptr NULL
 #endif /* HAVE_FLASH */
index 146d25473c295e4da0e4d99fa20b16cf4dee376b..189d21debf559a4a33a84269e6bdf97b6d1888ad 100644 (file)
 #include "ext/standard/info.h"
 #include "php_swf.h"
 
+#ifdef ZTS
+int swf_globals_id;
+#else
+php_swf_globals swf_globals;
+#endif
+
+
 function_entry swf_functions[] = {
        PHP_FE(swf_openfile,            NULL)
        PHP_FE(swf_closefile,           NULL)
@@ -103,7 +110,7 @@ zend_module_entry swf_module_entry = {
        swf_functions,
        PHP_MINIT(swf),
        NULL,
-       NULL,
+       PHP_RINIT(swf),
        NULL,
        PHP_MINFO(swf),
        STANDARD_MODULE_PROPERTIES
@@ -146,14 +153,19 @@ PHP_MINIT_FUNCTION(swf)
        return SUCCESS;
 }
 
-
+PHP_RINIT_FUNCTION(swf)
+{
+       SWFG(use_file) = 0;
+}
          
 /* {{{ proto void swf_openfile(string name, double xsize, double ysize, double framerate, double r, double g, double b)
    Create a Shockwave Flash file given by name, with width xsize and height ysize at a frame rate of framerate and a background color specified by a red value of r, green value of g and a blue value of b */
 PHP_FUNCTION(swf_openfile)
 {
        zval **name, **sizeX, **sizeY, **frameRate, **r, **g, **b;
-       char *na;
+       char *na, *tmpna;
+       SWFLS_FETCH();
+       
        if (ZEND_NUM_ARGS() != 7 ||
            zend_get_parameters_ex(7, &name, &sizeX, &sizeY, &frameRate, &r, &g, &b) == FAILURE) {
            WRONG_PARAM_COUNT;
@@ -166,18 +178,31 @@ PHP_FUNCTION(swf_openfile)
        convert_to_double_ex(r);
        convert_to_double_ex(g);
        convert_to_double_ex(b);
+
+
+       tmpna = Z_STRVAL_PP(name);
+
+       if (strcasecmp("php://stdout", tmpna) == 0) {
+               na = tempnam(NULL, "php_swf_stdout");
+               unlink((const char *)na);
        
-       na = Z_STRVAL_PP(name);
+               SWFG(use_file) = 0;
+       } else {
+               na = tmpna;
+               SWFG(use_file) = 1;
+       }
 
 #ifdef VIRTUAL_DIR
        if (virtual_filepath(na, &na)) {
                return;
        }
 #endif
-       
-       swf_openfile((strcasecmp("php://stdout", na)==0) ? "STDOUT" : na,
-                        (float)Z_DVAL_PP(sizeX), (float)Z_DVAL_PP(sizeY),
-                        (float)Z_DVAL_PP(frameRate), (float)Z_DVAL_PP(r), (float)Z_DVAL_PP(g), (float)Z_DVAL_PP(b));
+       if (!SWFG(use_file))
+               SWFG(tmpfile_name) = na;
+
+       swf_openfile(na,(float)Z_DVAL_PP(sizeX), (float)Z_DVAL_PP(sizeY),
+                        (float)Z_DVAL_PP(frameRate), (float)Z_DVAL_PP(r), 
+                        (float)Z_DVAL_PP(g), (float)Z_DVAL_PP(b));
 #ifdef VIRTUAL_DIR
        free(na);
 #endif
@@ -188,7 +213,27 @@ PHP_FUNCTION(swf_openfile)
    Close a Shockwave flash file that was opened with swf_openfile */
 PHP_FUNCTION(swf_closefile)
 {
+       SWFLS_FETCH();
+       
        swf_closefile();
+       
+       if (!SWFG(use_file)) {
+               FILE *f;
+               char buf[4096];
+               int b;
+               
+               if ((f = fopen(SWFG(tmpfile_name), "r")) == NULL) {
+                       php_error(E_WARNING, "Cannot create temporary file for stdout support with SWF");
+                       RETURN_NULL();
+               }
+               
+               while ((b = fread(buf, 1, sizeof(buf), f)) > 0)
+                       php_write(buf, b);
+               
+               fclose(f);
+               
+               unlink((const char *)SWFG(tmpfile_name));
+       }
 }
 /* }}} */