| | 1 | <?php |
|---|
| | 2 | include 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 |
|---|
| | 6 | define("PRODUCTION_SERVER", false); |
|---|
| | 7 | class 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 | |
|---|
| | 75 | class 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 | ?> |