amfphp.module

Tracking 5.x-1.x branch
  1. drupal
    1. 5 contributions/amfphp/amfphp.module
    2. 6 contributions/amfphp/amfphp.module

Functions & methods

NameDescription
amfphp_fix_uid
amfphp_menuImplemenation of hook_menu().
amfphp_method_call
amfphp_requirements
amfphp_server
amfphp_server_error
amfphp_server_info
amfphp_settingsAdmin settings callback.
_amfphp_serialize_lite

File

View source
  1. <?php
  2. /*
  3. * Implementation of hook_requirements()
  4. */
  5. function amfphp_requirements($phase) {
  6. $t = get_t();
  7. // Test AMFPHP version
  8. $requirements['amfphp'] = array(
  9. 'title' => $t('AMFPHP'),
  10. 'value' => $t('1.9 Beta 2'),
  11. );
  12. if (!file_exists(realpath(dirname(__FILE__) . '/amfphp/globals.php'))) {
  13. $requirements['amfphp']['value'] = $t('Not found or wrong version');
  14. $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.');
  15. $requirements['amfphp']['severity'] = REQUIREMENT_ERROR;
  16. }
  17. return $requirements;
  18. }
  19. /**
  20. * Implemenation of hook_menu().
  21. */
  22. function amfphp_menu($may_cache) {
  23. $items = array();
  24. if ($may_cache) {
  25. $items[] = array(
  26. 'path' => 'admin/build/services/settings/amfphp',
  27. 'title' => t('AMFPHP'),
  28. 'callback' => 'drupal_get_form',
  29. 'callback arguments' => array('amfphp_settings'),
  30. 'access' => user_access('administer services'),
  31. 'type' => MENU_LOCAL_TASK,
  32. 'description' => t('amfphp module settings.'),
  33. );
  34. }
  35. return $items;
  36. }
  37. /**
  38. * Admin settings callback.
  39. */
  40. function amfphp_settings() {
  41. // Charsets
  42. $form['charset'] = array(
  43. '#type' => 'fieldset',
  44. '#title' => t('Charset Encodings'),
  45. '#collapsible' => FALSE,
  46. '#collapsed' => FALSE,
  47. );
  48. $form['charset']['charset_method'] = array(
  49. '#type' => 'select',
  50. '#title' => t('Charset method'),
  51. '#options' => array('utf8_decode','iconv','mbstring','recode','none'),
  52. '#default_value' => variable_get('charset_method','iconv'),
  53. );
  54. $form['charset']['charset_php'] = array(
  55. '#type' => 'select',
  56. '#title' => t('Charset PHP'),
  57. '#options' => array('ISO-8859-1','UTF-8','big5','CP950','Shift_JIS','CP932','CP949'),
  58. '#default_value' => variable_get('charset_php','UTF-8'),
  59. );
  60. $form['charset']['charset_sql'] = array(
  61. '#type' => 'select',
  62. '#title' => t('Charset SQL'),
  63. '#options' => array('ISO-8859-1','UTF-8','big5','CP950','Shift_JIS','CP932','CP949'),
  64. '#default_value' => variable_get('charset_sql','ISO-8859-1'),
  65. );
  66. // Exceptions
  67. $form['exceptions'] = array(
  68. '#type' => 'fieldset',
  69. '#title' => t('Exception Settings'),
  70. '#collapsible' => FALSE,
  71. '#collapsed' => FALSE,
  72. );
  73. $form['exceptions']['amfphp_exception_handler'] = array(
  74. '#type' => 'select',
  75. '#title' => t('Select PHP error threshold'),
  76. '#default_value' => variable_get('amfphp_exception_handler', 2039),
  77. '#options' => array(
  78. 2039 => t('E_ALL ^ E_NOTICE'),
  79. 2047 => t('E_ERROR'),
  80. ),
  81. '#description' => t('Configure the PHP error types for which AMFPHP will throw exceptions'),
  82. );
  83. return system_settings_form($form);
  84. }
  85. /*
  86. * Implementation of hook_server_info()
  87. */
  88. function amfphp_server_info() {
  89. return array(
  90. '#name' => 'AMFPHP',
  91. '#path' => 'amfphp'
  92. );
  93. }
  94. /*
  95. * Implementation of hook_server()
  96. * here we include the contents of a gateway.php
  97. */
  98. function amfphp_server() {
  99. $path = drupal_get_path('module', 'amfphp');
  100. define("PRODUCTION_SERVER", !variable_get('services_debug', FALSE));
  101. require_once $path . "/amfphp/globals.php";
  102. require_once $path . "/overrides/AmfphpGateway.php";
  103. $gateway = new AmfphpGateway();
  104. $gateway->setClassPath($servicesPath);
  105. $gateway->setClassMappingsPath($voPath);
  106. $gateway->setCharsetHandler(variable_get('charset_method','utf8_decode'), variable_get('charset_php','ISO-8859-1'), variable_get('charset_sql','ISO-8859-1'));
  107. $gateway->setErrorHandling(variable_get('amfphp_exception_handler', 'E_ALL ^ E_NOTICE'));
  108. if(PRODUCTION_SERVER) {
  109. $gateway->disableDebug();
  110. $gateway->disableStandalonePlayer();
  111. }
  112. $gateway->enableGzipCompression(25*1024);
  113. $gateway->service();
  114. }
  115. /*
  116. * ugly! ugly! ugly!
  117. * we need to use a method call wrapper here to convert all 'uid' values in the result
  118. * to 'userid'. this is because flex uses the property 'uid' in objects and will overwrite
  119. * anything we send with its own value.
  120. */
  121. function amfphp_method_call($method_name, $args) {
  122. // convert all userid to uid
  123. $args = amfphp_fix_uid($args, 0);
  124. $result = services_method_call($method_name, $args);
  125. // convert all uid to userid
  126. $result = amfphp_fix_uid($result);
  127. return $result;
  128. }
  129. /*
  130. * ugly! ugly! ugly!
  131. */
  132. function amfphp_fix_uid($data, $direction = 1) {
  133. $uid = 's:3:"uid";';
  134. $userid = 's:6:"userid";';
  135. $from = ($direction) ? $uid : $userid;
  136. $to = (!$direction) ? $uid : $userid;
  137. $data = _amfphp_serialize_lite($data);
  138. $data = str_replace($from, $to, $data);
  139. $data = unserialize($data);
  140. return $data;
  141. }
  142. /*
  143. * Implementation of hook_server_error()
  144. */
  145. function amfphp_server_error($message) {
  146. trigger_error($message, E_USER_ERROR);
  147. }
  148. /*
  149. * A less memory intesive serializer
  150. * see: http://bugs.php.net/bug.php?id=39736
  151. */
  152. function _amfphp_serialize_lite(&$data, $buf = '') {
  153. if (is_array(&$data)) {
  154. $buf.= "a:" . count(&$data) . ":{";
  155. foreach($data as $key => &$value) {
  156. $buf .= serialize($key) . _amfphp_serialize_lite(&$value);
  157. }
  158. $buf.= "}";
  159. return $buf;
  160. }
  161. else {
  162. return $buf . serialize(&$data);
  163. }
  164. }