- <?php
-
- * Implementation of hook_requirements()
- */
- function amfphp_requirements($phase) {
- $t = get_t();
-
-
- $requirements['amfphp'] = array(
- 'title' => $t('AMFPHP'),
- 'value' => $t('1.9 Beta 2'),
- );
-
- if (!file_exists(realpath(dirname(__FILE__) . '/amfphp/globals.php'))) {
- $requirements['amfphp']['value'] = $t('Not found or wrong version');
- $requirements['amfphp']['description'] = $t('You must dowload <a href="http://www.5etdemi.com/blog/archives/2007/01/amfphp-19-beta-2-ridiculously-faster/">AMFPHP 1.9 beta 2</a>, and extract to modules/amfphp/amfphp, or respective site modules directory.');
- $requirements['amfphp']['severity'] = REQUIREMENT_ERROR;
- }
-
- return $requirements;
- }
-
- * Implemenation of hook_menu().
- */
- function amfphp_menu($may_cache) {
- $items = array();
- if ($may_cache) {
- $items[] = array(
- 'path' => 'admin/build/services/settings/amfphp',
- 'title' => t('AMFPHP'),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('amfphp_settings'),
- 'access' => user_access('administer services'),
- 'type' => MENU_LOCAL_TASK,
- 'description' => t('amfphp module settings.'),
- );
- }
- return $items;
- }
-
- * Admin settings callback.
- */
- function amfphp_settings() {
-
- $form['charset'] = array(
- '#type' => 'fieldset',
- '#title' => t('Charset Encodings'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['charset']['charset_method'] = array(
- '#type' => 'select',
- '#title' => t('Charset method'),
- '#options' => array('utf8_decode','iconv','mbstring','recode','none'),
- '#default_value' => variable_get('charset_method','iconv'),
- );
- $form['charset']['charset_php'] = array(
- '#type' => 'select',
- '#title' => t('Charset PHP'),
- '#options' => array('ISO-8859-1','UTF-8','big5','CP950','Shift_JIS','CP932','CP949'),
- '#default_value' => variable_get('charset_php','UTF-8'),
- );
- $form['charset']['charset_sql'] = array(
- '#type' => 'select',
- '#title' => t('Charset SQL'),
- '#options' => array('ISO-8859-1','UTF-8','big5','CP950','Shift_JIS','CP932','CP949'),
- '#default_value' => variable_get('charset_sql','ISO-8859-1'),
- );
-
-
- $form['exceptions'] = array(
- '#type' => 'fieldset',
- '#title' => t('Exception Settings'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['exceptions']['amfphp_exception_handler'] = array(
- '#type' => 'select',
- '#title' => t('Select PHP error threshold'),
- '#default_value' => variable_get('amfphp_exception_handler', 2039),
- '#options' => array(
- 2039 => t('E_ALL ^ E_NOTICE'),
- 2047 => t('E_ERROR'),
- ),
- '#description' => t('Configure the PHP error types for which AMFPHP will throw exceptions'),
- );
-
- return system_settings_form($form);
- }
-
- * Implementation of hook_server_info()
- */
- function amfphp_server_info() {
- return array(
- '#name' => 'AMFPHP',
- '#path' => 'amfphp'
- );
- }
-
- * Implementation of hook_server()
- * here we include the contents of a gateway.php
- */
- function amfphp_server() {
- $path = drupal_get_path('module', 'amfphp');
- define("PRODUCTION_SERVER", !variable_get('services_debug', FALSE));
-
- require_once $path . "/amfphp/globals.php";
- require_once $path . "/overrides/AmfphpGateway.php";
-
- $gateway = new AmfphpGateway();
- $gateway->setClassPath($servicesPath);
- $gateway->setClassMappingsPath($voPath);
- $gateway->setCharsetHandler(variable_get('charset_method','utf8_decode'), variable_get('charset_php','ISO-8859-1'), variable_get('charset_sql','ISO-8859-1'));
- $gateway->setErrorHandling(variable_get('amfphp_exception_handler', 'E_ALL ^ E_NOTICE'));
-
- if(PRODUCTION_SERVER) {
- $gateway->disableDebug();
- $gateway->disableStandalonePlayer();
- }
-
- $gateway->enableGzipCompression(25*1024);
- $gateway->service();
- }
-
- * ugly! ugly! ugly!
- * we need to use a method call wrapper here to convert all 'uid' values in the result
- * to 'userid'. this is because flex uses the property 'uid' in objects and will overwrite
- * anything we send with its own value.
- */
- function amfphp_method_call($method_name, $args) {
-
-
- $args = amfphp_fix_uid($args, 0);
-
- $result = services_method_call($method_name, $args);
-
-
- $result = amfphp_fix_uid($result);
-
- return $result;
- }
-
- * ugly! ugly! ugly!
- */
- function amfphp_fix_uid($data, $direction = 1) {
- $uid = 's:3:"uid";';
- $userid = 's:6:"userid";';
-
- $from = ($direction) ? $uid : $userid;
- $to = (!$direction) ? $uid : $userid;
-
- $data = _amfphp_serialize_lite($data);
- $data = str_replace($from, $to, $data);
- $data = unserialize($data);
-
- return $data;
- }
-
- * Implementation of hook_server_error()
- */
- function amfphp_server_error($message) {
- trigger_error($message, E_USER_ERROR);
- }
-
- * A less memory intesive serializer
- * see: http://bugs.php.net/bug.php?id=39736
- */
- function _amfphp_serialize_lite(&$data, $buf = '') {
- if (is_array(&$data)) {
- $buf.= "a:" . count(&$data) . ":{";
- foreach($data as $key => &$value) {
- $buf .= serialize($key) . _amfphp_serialize_lite(&$value);
- }
- $buf.= "}";
- return $buf;
- }
- else {
- return $buf . serialize(&$data);
- }
- }