Source Code Documentation


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); /* Send a 200 OK status header. */
  63. header("Content-Type: text/plain; charset=utf-8"); /* Content-Type text/plain with UTF-8. */
  64. eval('while (@ob_end_clean ());'); /* End/clean all output buffers that may or may not exist. */
  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 = c_ws_plugin__s2member_utils_strings::trim_deep ($op))) /* Now trim again, in case of serialized array. */
  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. {
  74. exit(call_user_func ("c_ws_plugin__s2member_pro_remote_ops_in::" . $op["op"], $op));
  75. }
  76. else
  77. exit('Error: $_POST["s2member_pro_remote_op"]["op"] is empty or invalid.');
  78. }
  79. else
  80. exit('Error: $_POST["s2member_pro_remote_op"]["api_key"] is empty or invalid.');
  81. }
  82. else
  83. exit('Error: $_POST["s2member_pro_remote_op"] is NOT a serialized array.');
  84. }
  85. else
  86. exit('Error: $_POST["s2member_pro_remote_op"] is NOT a serialized array.');
  87. }
  88. }
  89. /**
  90. * Test if this WordPress® instance is a specific Remote Operation.
  91. *
  92. * @package s2Member\API_Remote_Ops
  93. * @since 110713
  94. *
  95. * @param str $_op The Remote Operation to test this instance against.
  96. * @return bool True if instance is the specified Operation, else false.
  97. */
  98. public static function is_remote_op ($_op = FALSE)
  99. {
  100. if (!empty ($_GET["s2member_pro_remote_op"]) && !empty ($_POST["s2member_pro_remote_op"]))
  101. if (is_array ($op = maybe_unserialize (c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST["s2member_pro_remote_op"])))))
  102. if (is_array ($op = c_ws_plugin__s2member_utils_strings::trim_deep ($op))) /* Now trim again, in case of serialized array. */
  103. if (!empty ($op["api_key"]) && $op["api_key"] === c_ws_plugin__s2member_pro_remote_ops::remote_ops_key_gen ())
  104. if (!empty ($op["op"]) && $op["op"] === $_op)
  105. return true;
  106. /**/
  107. return false;
  108. }
  109. /**
  110. * Generates an API Key, for Remote Operations.
  111. *
  112. * @package s2Member\API_Remote_Ops
  113. * @since 110713
  114. *
  115. * @return str An API Key. It's an MD5 Hash, 32 chars, URL-safe.
  116. */
  117. public static function remote_ops_key_gen () /* Generate Key. */
  118. {
  119. global $current_site, $current_blog; /* Multisite Networking. */
  120. /**/
  121. if (is_multisite () && !is_main_site ())
  122. $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt ($current_blog->domain . $current_blog->path, false, false));
  123. /**/
  124. else /* Else it's a standard API Key; not on a Multisite Network, or not on the Main Site anyway. */
  125. $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt (preg_replace ("/\:[0-9]+$/", "", $_SERVER["HTTP_HOST"]), false, false));
  126. /**/
  127. return (!empty ($key)) ? $key : ""; /* Else an empty string. */
  128. }
  129. }
  130. }
  131. ?>

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

Source Code Documentation