PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110815
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110815
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / includes / functions / class-autoloader.inc.php

class-autoloader.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110815, at includes/functions/class-autoloader.inc.php

89 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * s2Member class autoloader.
4 *
5 * Defines the __autoload function for s2Member classes.
6 * This highly optimizes s2Member. Giving it a much smaller footprint.
7 * See: {@link http://www.php.net/manual/en/function.spl-autoload-register.php}
8 *
9 * Copyright: © 2009-2011
10 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
11 * ( coded in the USA )
12 *
13 * Released under the terms of the GNU General Public License.
14 * You should have received a copy of the GNU General Public License,
15 * along with this software. In the main directory, see: /licensing/
16 * If not, see: {@link http://www.gnu.org/licenses/}.
17 *
18 * @package s2Member
19 * @since 3.5
20 */
21 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
22 exit ("Do not access this file directly.");
23 /**/
24 if (!function_exists ("ws_plugin__s2member_classes"))
25 {
26 /**
27 * s2Member class autoloader.
28 *
29 * The __autoload function for s2Member classes.
30 * This highly optimizes s2Member. Giving it a much smaller footprint.
31 * See: {@link http://www.php.net/manual/en/function.spl-autoload-register.php}
32 *
33 * @package s2Member
34 * @since 3.5
35 *
36 * @param str $class The class that needs to be loaded. Passed in by PHP itself.
37 * @return null
38 */
39 function ws_plugin__s2member_classes ($class = FALSE) /* Build dynamic __autoload function. */
40 {
41 static $c; /* Holds the classes directory location ( location is optimized with a static var ). */
42 static $c_class_dirs; /* All possible dir & sub-directory locations ( with a static var ). */
43 /**/
44 if (strpos ($class, "c_ws_plugin__s2member_") === 0 && strpos ($class, "c_ws_plugin__s2member_pro_") === false)
45 {
46 $c = (!isset ($c)) ? dirname (dirname (__FILE__)) . "/classes" : $c; /* Configures location of classes. */
47 $c_class_dirs = (!isset ($c_class_dirs)) ? array_merge (array ($c), _ws_plugin__s2member_classes_scan_dirs_r ($c)) : $c_class_dirs;
48 /**/
49 $class = str_replace ("_", "-", str_replace ("c_ws_plugin__s2member_", "", $class));
50 /**/
51 foreach ($c_class_dirs as $class_dir) /* Start looking for the class. */
52 if ($class_dir === $c || strpos ($class, basename ($class_dir)) === 0)
53 if (file_exists ($class_dir . "/" . $class . ".inc.php"))
54 {
55 include_once $class_dir . "/" . $class . ".inc.php";
56 /**/
57 break; /* Now stop looking. */
58 }
59 }
60 /**/
61 return; /* Return for uniformity. */
62 }
63 /**
64 * Scans recursively for class sub-directories.
65 *
66 * Used by the s2Member autoloader.
67 *
68 * @package s2Member
69 * @since 3.5
70 *
71 * @param str $starting_dir The directory to start scanning from.
72 * @return str[] An array of class directories.
73 */
74 function _ws_plugin__s2member_classes_scan_dirs_r ($starting_dir = FALSE)
75 {
76 $dirs = array (); /* Initialize dirs array. */
77 /**/
78 foreach (func_get_args () as $starting_dir)
79 if (is_dir ($starting_dir)) /* Does this directory exist? */
80 foreach (scandir ($starting_dir) as $dir) /* Scan this directory. */
81 if ($dir !== "." && $dir !== ".." && is_dir ($dir = $starting_dir . "/" . $dir))
82 $dirs = array_merge ($dirs, array ($dir), _ws_plugin__s2member_classes_scan_dirs_r ($dir));
83 /**/
84 return $dirs; /* Return array of all directories. */
85 }
86 /**/
87 spl_autoload_register ("ws_plugin__s2member_classes"); /* Register __autoload. */
88 }
89 ?>