Ticket #1378: amfPhp.2.diff

File amfPhp.2.diff, 11.0 kB (added by getconfused, 1 year ago)
  • SGL/Request/Amf.php

    old new  
     1<?php 
     2 
     3class SGL_Request_Amf extends SGL_Request 
     4{ 
     5    function init() 
     6    { 
     7        //  get config singleton 
     8        $c = &SGL_Config::singleton(); 
     9        $conf = $c->getAll(); 
     10 
     11        //  resolve value for $_SERVER['PHP_SELF'] based in host 
     12        SGL_URL::resolveServerVars($conf); 
     13 
     14        //  get current url object 
     15        $cache = & SGL_Cache::singleton(); 
     16        $cacheId = md5($_SERVER['PHP_SELF']); 
     17 
     18        if ($data = $cache->get($cacheId, 'uri')) { 
     19            $url = unserialize($data); 
     20            SGL::logMessage('URI from cache', PEAR_LOG_DEBUG); 
     21        } else { 
     22            require_once SGL_CORE_DIR . '/UrlParser/SimpleStrategy.php'; 
     23            require_once SGL_CORE_DIR . '/UrlParser/ClassicStrategy.php'; 
     24 
     25            $aStrats = array( 
     26                new SGL_UrlParser_ClassicStrategy(), 
     27                new SGL_UrlParser_SefStrategy(), 
     28                ); 
     29            $url = new SGL_URL($_SERVER['PHP_SELF'], true, $aStrats); 
     30 
     31            $err = $url->init(); 
     32            if (PEAR::isError($err)) { 
     33                return $err; 
     34            } 
     35            $data = serialize($url); 
     36            $cache->save($data, $cacheId, 'uri'); 
     37            SGL::logMessage('URI parsed ####' . $_SERVER['PHP_SELF'] . '####', PEAR_LOG_DEBUG); 
     38        } 
     39        $aQueryData = $url->getQueryData(); 
     40 
     41        if (PEAR::isError($aQueryData)) { 
     42            return $aQueryData; 
     43        } 
     44        //  assign to registry 
     45        $input = &SGL_Registry::singleton(); 
     46        $input->setCurrentUrl($url); 
     47 
     48        //  merge REQUEST AND FILES superglobal arrays 
     49        $this->aProps = array_merge($_GET, $aQueryData, $_POST); 
     50        $this->type = SGL_REQUEST_AMF; 
     51        return true; 
     52    } 
     53} 
     54?> 
  • SGL/FrontController.php

    old new  
    109109        if ($output->conf['site']['outputBuffering']) { 
    110110            ob_end_flush(); 
    111111        } 
     112         
    112113        echo $output->data; 
    113114    } 
    114115 
     
    150151            $input->setFilters($aFilters); 
    151152            $ret = true; 
    152153            break; 
     154             
     155 
     156        case SGL_REQUEST_AMF: 
     157            $aFilters = array( 
     158                'SGL_Task_Init', 
     159                'SGL_Task_SetupORM', 
     160                'SGL_Task_CreateSession', 
     161                'SGL_Task_ExecuteAmfAction', 
     162                ); 
     163            $input->setFilters($aFilters); 
     164            $ret = true; 
     165            break; 
     166             
     167             
    153168        } 
    154169 
    155170        return $ret; 
  • SGL/Task/ExecuteAjaxAction.php

    old new  
    2929        } 
    3030    } 
    3131} 
    32 ?> 
     32?> 
  • SGL/Task/ExecuteAmfAction.php

    old new  
     1<?php 
     2include SGL_LIB_DIR . "/amf-core/app/Gateway.php"; 
     3//You can set this constant appropriately to disable traces and debugging headers 
     4//You will also have the constant available in your classes, for changing 
     5//the mysql server info for example 
     6define("PRODUCTION_SERVER", false); 
     7class SGL_Task_ExecuteAmfAction extends SGL_ProcessRequest 
     8{ 
     9    function process(&$input, &$output) 
     10    { 
     11                SGL::logMessage(null, PEAR_LOG_DEBUG); 
     12        $req = $input->getRequest(); 
     13        $moduleName = $req->getModuleName(); 
     14        $method = $req->getActionName(); 
     15 
     16                $gateway = new SGL_Gateway(); 
     17         
     18                //Set where the services classes are loaded from, *with trailing slash* 
     19                $gateway->setBaseClassPath(SGL_MOD_DIR . '/' .($moduleName) . '/classes/amfservices/'); 
     20                 
     21                //Loose mode means echo'ing or whitespace in your file won't make AMFPHP choke 
     22                $gateway->setLooseMode(true); 
     23                 
     24                //Read above large note for explanation of charset handling 
     25                //The main contributor (Patrick Mineault) is French,  
     26                //so don't be afraid if he forgot to turn off iconv by default! 
     27                //$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1"); 
     28                 
     29                //Error types that will be rooted to the NetConnection debugger 
     30                $gateway->setErrorHandling(E_ALL ^ E_NOTICE); 
     31                 
     32                //choices are php5 (SoapClient), nusoap and pear 
     33                //If you don't plan on using web services with AMFPHP,  
     34                //you can safely let this setting alone 
     35                //Note that for nusoap to work you MUST place the library under /amf-core/lib/nusoap.php 
     36                $gateway->setWebServiceHandler('php5'); 
     37                 
     38                //Adding an adapter mapping will make returns of the mapped typed be intercepted 
     39                //and mapped in adapters/%adapterName%Adapter.php. This works by using get_class 
     40                //So for example, if you return a PEAR resultset object, it is an instance of DB_result 
     41                //And we want this to be processed as a recordset in adapters/peardbAdapter.php, 
     42                //hence the following line: 
     43                $gateway->addAdapterMapping('db_result', 'peardb'); 
     44                //For PDO (PHP 5.1 specific) 
     45                $gateway->addAdapterMapping('pdostatement', 'pdo'); 
     46                //For oo-style MySQLi 
     47                $gateway->addAdapterMapping('mysqli_result', 'mysqli'); 
     48                //For filtered array  
     49                //And for filtered typed array (see adapters/lib/Arrayf.php and Arrayft.php) 
     50                $gateway->addAdapterMapping('arrayf', 'arrayf'); 
     51                $gateway->addAdapterMapping('arrayft', 'arrayft'); 
     52                //And you can add your own after this point... (note lowercase for both args!) 
     53                 
     54                if(PRODUCTION_SERVER) 
     55                { 
     56                        //Disable trace actions 
     57                        $gateway->disableTrace(); 
     58                         
     59                        //Disable debugging headers 
     60                        $gateway->disableDebug(); 
     61                         
     62                        //Disable Service description 
     63                        $gateway->disableServiceDescription(); 
     64                } 
     65                 
     66//              include_once('advancedsettings.php'); 
     67                 
     68                //Service now 
     69                $output->data = $gateway->service(); 
     70                 
     71    } 
     72     
     73} 
     74 
     75class SGL_Gateway extends Gateway { 
     76 
     77        /** 
     78         * The service method runs the gateway application.  It turns the gateway 'on'.  You 
     79         * have to call the service method as the last line of the gateway script after all of the 
     80         * gateway configuration properties have been set. 
     81         *  
     82         * Right now the service method also includes a very primitive debugging mode that 
     83         * just dumps the raw amf input and output to files.  This may change in later versions. 
     84         * The debugging implementation is NOT thread safe so be aware of file corruptions that 
     85         * may occur in concurrent environments. 
     86         */ 
     87 
     88        function service() { 
     89                 
     90                //Set the parameters for the charset handler 
     91                CharsetHandler::setMethod($this->_charsetMethod); 
     92                CharsetHandler::setPhpCharset($this->_charsetPhp); 
     93                CharsetHandler::setSqlCharset($this->_charsetSql); 
     94                 
     95                //Attempt to call charset handler to catch any uninstalled extensions 
     96                $ch = new CharsetHandler('flashtophp'); 
     97                $ch->transliterate('?'); 
     98                 
     99                $ch2 = new CharsetHandler('sqltophp'); 
     100                $ch2->transliterate('?'); 
     101                 
     102                $GLOBALS['amfphp']['actions'] = $this->actions; 
     103                 
     104                NetDebug::initialize(); 
     105                 
     106//              error_reporting($GLOBALS['amfphp']['errorLevel']); 
     107                 
     108                //Enable loose mode if requested 
     109                if($this->_looseMode) 
     110                { 
     111                        ob_start(); 
     112                } 
     113                 
     114                $amf = new AMFObject($GLOBALS["HTTP_RAW_POST_DATA"]);   // create the amf object 
     115                 
     116                if($this->incomingMessagesFolder != NULL) 
     117                { 
     118                        $mt = microtime(); 
     119                        $pieces = explode(' ', $mt); 
     120                        file_put_contents($this->incomingMessagesFolder .  
     121                                'in.' . $pieces[1] . '.' . substr($pieces[0], 2) . ".amf",  
     122                                $GLOBALS["HTTP_RAW_POST_DATA"]); 
     123                } 
     124  
     125                foreach($this->filters as $key => $filter) 
     126                { 
     127                        $filter($amf); //   invoke the first filter in the chain 
     128                } 
     129                 
     130                $output = $amf->outputStream; // grab the output stream 
     131                 
     132                //Clear the current output buffer if requested 
     133                if($this->_looseMode) 
     134                { 
     135                        if($this->_obLogging !== FALSE) 
     136                        { 
     137                                $this->_appendRawDataToFile($this->_obLogging, ob_get_clean()); 
     138                        } 
     139                        else 
     140                        { 
     141                                ob_end_clean(); 
     142                        } 
     143                } 
     144                 
     145                //Send content length header 
     146                //Thanks to Alec Horley for pointing out the necessity 
     147                //of this for FlashComm support 
     148                header(AMFPHP_CONTENT_TYPE); // define the proper header 
     149                header("Content-length: " . strlen($output)); 
     150                 
     151                //Send expire header, apparently helps for SSL 
     152                //Thanks to Gary Rogers for that 
     153                //And also to Lucas Filippi from openAMF list 
     154                //And to Robert Reinhardt who appears to be the first who  
     155                //documented the bug 
     156                //Finally to Gary who appears to have find a solution which works even more reliably 
     157                if($this->useSslFirstMethod) 
     158                { 
     159                        $dateStr = date("D, j M Y ") . date("H:i:s", strtotime("-2 days")); 
     160                        header("Expires: $dateStr GMT"); 
     161                        header("Pragma: no-store"); 
     162                        header("Cache-Control: no-store"); 
     163                } 
     164                //else don't send any special headers at all 
     165 
     166                if($this->outgoingMessagesFolder != NULL) 
     167                { 
     168                        $mt = microtime(); 
     169                        $pieces = explode(' ', $mt); 
     170                        file_put_contents($this->outgoingMessagesFolder .  
     171                                'out.' . $pieces[1] . '.' . substr($pieces[0], 2) . ".amf", $output); 
     172                }            
     173 
     174                return $output; // flush the binary data         
     175        } 
     176         
     177} 
     178?> 
  • SGL/Request.php

    old new  
    4242define('SGL_REQUEST_CLI',       2); 
    4343define('SGL_REQUEST_AJAX',      3); 
    4444define('SGL_REQUEST_XMLRPC',    4); 
     45define('SGL_REQUEST_AMF',       5); 
    4546 
    4647/** 
    4748 * Loads Request driver, provides a number of filtering methods. 
     
    6061            $type = $this->getRequestType(); 
    6162            $typeName = $this->constantToString($type); 
    6263 
     64 
     65        SGL::logMessage($typeName, PEAR_LOG_DEBUG); 
     66             
    6367            $file = SGL_CORE_DIR . '/Request/' . $typeName . '.php'; 
    6468            if (!is_file($file)) { 
    6569              return PEAR::raiseError('Request driver could not be located', 
     
    9498        case SGL_REQUEST_AJAX: 
    9599            $ret = 'Ajax'; 
    96100            break; 
     101             
     102        case SGL_REQUEST_AMF: 
     103            $ret = 'Amf'; 
     104            break; 
    97105        } 
    98106        return $ret; 
    99107    } 
     
    107115                        $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { 
    108116            return SGL_REQUEST_AJAX; 
    109117 
    110         } else { 
     118        } else if(isset($GLOBALS["HTTP_RAW_POST_DATA"]) &&  
     119                                        $GLOBALS["HTTP_RAW_POST_DATA"][0] < 0x0A && 
     120                                        $GLOBALS["HTTP_RAW_POST_DATA"][0] < 0x0A  ) { // the first two bytes of an AMF message should be 0x00|0x01 and 0x00|0x03 
     121                 
     122            return SGL_REQUEST_AMF; 
     123         
     124        }else { 
    111125            return SGL_REQUEST_BROWSER; 
    112126        } 
    113127    }