Source Code Documentation


s2member-pro\includes\functions\class-autoloader.inc.php


  1. <?php
  2. /**
  3. * s2Member Pro class autoloader.
  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
  31. * @since 1.5
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit("Do not access this file directly.");
  35. /*
  36. The __autoload function for s2Member Pro classes.
  37. */
  38. if (!function_exists ("ws_plugin__s2member_pro_classes"))
  39. {
  40. /**
  41. * s2Member Pro class autoloader.
  42. *
  43. * The __autoload function for s2Member Pro classes.
  44. * This highly optimizes s2Member Pro. Giving it a much smaller footprint.
  45. * See: {@link http://www.php.net/manual/en/function.spl-autoload-register.php}
  46. *
  47. * @package s2Member
  48. * @since 1.5
  49. *
  50. * @param str $class The class that needs to be loaded. Passed in by PHP itself.
  51. * @return null
  52. */
  53. function ws_plugin__s2member_pro_classes ($class = FALSE) /* Build dynamic __autoload function. */
  54. {
  55. static $c; /* Holds the classes directory location ( location is optimized with a static var ). */
  56. static $c_class_dirs; /* All possible dir & sub-directory locations ( with a static var ). */
  57. /**/
  58. if (strpos ($class, "c_ws_plugin__s2member_pro_") === 0) /* Make sure this is an s2Member Pro class. */
  59. {
  60. $c = (!isset ($c)) ? dirname (dirname (__FILE__)) . "/classes" : $c; /* Configures location of classes. */
  61. $c_class_dirs = (!isset ($c_class_dirs)) ? array_merge (array ($c), _ws_plugin__s2member_pro_classes_scan_dirs_r ($c)) : $c_class_dirs;
  62. /**/
  63. $class = str_replace ("_", "-", str_replace ("c_ws_plugin__s2member_pro_", "", $class));
  64. /**/
  65. foreach ($c_class_dirs as $class_dir) /* Start looking for the class. */
  66. if ($class_dir === $c || strpos ($class, basename ($class_dir)) === 0)
  67. if (file_exists ($class_dir . "/" . $class . ".inc.php"))
  68. {
  69. include_once $class_dir . "/" . $class . ".inc.php";
  70. /**/
  71. break; /* Now stop looking. */
  72. }
  73. }
  74. /**/
  75. return; /* Return for uniformity. */
  76. }
  77. /**
  78. * Scans recursively for class sub-directories.
  79. *
  80. * Used by the s2Member Pro autoloader.
  81. *
  82. * @package s2Member
  83. * @since 1.5
  84. *
  85. * @param str $starting_dir The directory to start scanning from.
  86. * @return str[] An array of class directories.
  87. */
  88. function _ws_plugin__s2member_pro_classes_scan_dirs_r ($starting_dir = FALSE)
  89. {
  90. $dirs = array (); /* Initialize dirs array. */
  91. /**/
  92. foreach (func_get_args () as $starting_dir)
  93. if (is_dir ($starting_dir)) /* Does this directory exist? */
  94. foreach (scandir ($starting_dir) as $dir) /* Scan this directory. */
  95. if ($dir !== "." && $dir !== ".." && is_dir ($dir = $starting_dir . "/" . $dir))
  96. $dirs = array_merge ($dirs, array ($dir), _ws_plugin__s2member_pro_classes_scan_dirs_r ($dir));
  97. /**/
  98. return $dirs; /* Return array of all directories. */
  99. }
  100. /**/
  101. spl_autoload_register("ws_plugin__s2member_pro_classes"); /* Register __autoload. */
  102. }
  103. ?>

s2member-pro\includes\functions\class-autoloader.inc.php

Source Code Documentation