Source Code Documentation


pro\s2member-pro\includes\classes\remote-ops.inc.php


  1. <?php
  2. /**
  3. * s2Member Pro Remote Operations API.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * This WordPress® plugin (s2Member Pro) is comprised of two parts:
  10. *
  11. * o (1) Its PHP code is licensed under the GPL license, as is WordPress®.
  12. * You should have received a copy of the GNU General Public License,
  13. * along with this software. In the main directory, see: /licensing/
  14. * If not, see: {@link http://www.gnu.org/licenses/}.
  15. *
  16. * o (2) All other parts of (s2Member Pro); including, but not limited to:
  17. * the CSS code, some JavaScript code, images, and design;
  18. * are licensed according to the license purchased.
  19. * See: {@link http://www.s2member.com/prices/}
  20. *
  21. * Unless you have our prior written consent, you must NOT directly or indirectly license,
  22. * sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
  23. * or make an offer to do any of these things. All of these things are strictly
  24. * prohibited with part (2) of the s2Member Pro Module.
  25. *
  26. * Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
  27. * (i.e. new features, bug fixes, updates, improvements); along with full access
  28. * to our video tutorial library: {@link http://www.s2member.com/videos/}
  29. *
  30. * @package s2Member\API_Remote_Ops
  31. * @since 110713
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit("Do not access this file directly.");
  35.  
  36. if (!class_exists ("c_ws_plugin__s2member_pro_remote_ops"))
  37. {
  38. /**
  39. * s2Member Pro Remote Operations API.
  40. *
  41. * @package s2Member\API_Remote_Ops
  42. * @since 110713
  43. */
  44. class c_ws_plugin__s2member_pro_remote_ops
  45. {
  46. /**
  47. * Handles Remote Operation communications.
  48. *
  49. * @package s2Member\API_Remote_Ops
  50. * @since 110713
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution with a serialized array on success, or a string beginning with `Error:` on failure.
  55. */
  56. public static function remote_ops ()
  57. {
  58. if (!empty ($_GET["s2member_pro_remote_op"]) && !empty ($_POST["s2member_pro_remote_op"]))
  59. {
  60. c_ws_plugin__s2member_no_cache::no_cache_constants (true);
  61.  
  62. status_header(200);
  63. header("Content-Type: text/plain; charset=UTF-8");
  64. while (@ob_end_clean ()); // Clean any existing output buffers.
  65.  
  66. if (is_array ($op = maybe_unserialize (c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST["s2member_pro_remote_op"])))))
  67. {
  68. if (is_array ($op = /* Now trim again, in case of serialized array. */c_ws_plugin__s2member_utils_strings::trim_deep ($op)))
  69. {
  70. if (!empty ($op["api_key"]) && $op["api_key"] === c_ws_plugin__s2member_pro_remote_ops::remote_ops_key_gen ())
  71. {
  72. if (!empty ($op["op"]) && is_callable ("c_ws_plugin__s2member_pro_remote_ops_in::" . $op["op"]))
  73. exit(call_user_func ("c_ws_plugin__s2member_pro_remote_ops_in::" . $op["op"], $op));
  74.  
  75. exit('Error: $_POST["s2member_pro_remote_op"]["op"] is empty or invalid.');
  76. }
  77. exit('Error: $_POST["s2member_pro_remote_op"]["api_key"] is empty or invalid.');
  78. }
  79. exit('Error: $_POST["s2member_pro_remote_op"] is NOT a serialized array.');
  80. }
  81. exit('Error: $_POST["s2member_pro_remote_op"] is NOT a serialized array.');
  82. }
  83. }
  84. /**
  85. * Test if this WordPress® instance is a specific Remote Operation.
  86. *
  87. * @package s2Member\API_Remote_Ops
  88. * @since 110713
  89. *
  90. * @param str $_op The Remote Operation to test this instance against.
  91. * @return bool True if instance is the specified Operation, else false.
  92. */
  93. public static function is_remote_op ($_op = FALSE)
  94. {
  95. if (!empty ($_GET["s2member_pro_remote_op"]) && !empty ($_POST["s2member_pro_remote_op"]))
  96. if (is_array ($op = maybe_unserialize (c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST["s2member_pro_remote_op"])))))
  97. if (is_array ($op = /* Now trim again, in case of serialized array. */c_ws_plugin__s2member_utils_strings::trim_deep ($op)))
  98. if (!empty ($op["api_key"]) && $op["api_key"] === c_ws_plugin__s2member_pro_remote_ops::remote_ops_key_gen ())
  99. if (!empty ($op["op"]) && $op["op"] === $_op)
  100. return true;
  101. return false;
  102. }
  103. /**
  104. * Generates an API Key, for Remote Operations.
  105. *
  106. * @package s2Member\API_Remote_Ops
  107. * @since 110713
  108. *
  109. * @return str An API Key. It's an MD5 Hash, 32 chars, URL-safe.
  110. */
  111. public static function remote_ops_key_gen ()
  112. {
  113. global /* Multisite Networking. */ $current_site, $current_blog;
  114.  
  115. if (is_multisite () && !is_main_site ())
  116. $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt ($current_blog->domain . $current_blog->path, false, false));
  117.  
  118. else // Else it's a standard API Key; not on a Multisite Network, or not on the Main Site anyway.
  119. $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt (preg_replace ("/\:[0-9]+$/", "", $_SERVER["HTTP_HOST"]), false, false));
  120.  
  121. return apply_filters("ws_plugin__s2member_pro_remote_ops_key", (!empty ($key)) ? $key : "");
  122. }
  123. }
  124. }
  125. ?>

pro\s2member-pro\includes\classes\remote-ops.inc.php

Source Code Documentation