3c4bb773 by Chris Boden

Implemented namespaces

1 parent 943a8b83
1 <?php 1 <?php
2 class Auth {
3 const REG_METH_AUTO_REG = 1;
4 const REG_METH_VALID_EMAIL = 2;
5 2
6 const FORGOT_METH_VALID_EMAIL = 1; 3 namespace Tz\WordPress\Tools\Auth;
7 const FORGOT_METH_RAND_PASS = 2;
8 4
9 const ACTION_ACTIVATE = 'activate_account'; 5 use \Exception, \LogicException, \InvalidArgumentException, \BadMethodCallException;
10 6
11 public static function make() { 7 const REG_METH_AUTO_REG = 1;
12 static $made = false; 8 const REG_METH_VALID_EMAIL = 2;
13 if (true === $made) {
14 throw new Exception('Auth has already been instantiated');
15 }
16 $made = true;
17 9
18 // if _GET activate self::activate(); 10 const FORGOT_METH_VALID_EMAIL = 1;
19 } 11 const FORGOT_METH_RAND_PASS = 2;
20 12
21 /** 13 const ACTION_ACTIVATE = 'activate_account';
14
15 /**
22 * Attempts to login the user 16 * Attempts to login the user
23 * @param {String} $username 17 * @param {String} $username
24 * @param {String} $password 18 * @param {String} $password
...@@ -27,7 +21,7 @@ class Auth { ...@@ -27,7 +21,7 @@ class Auth {
27 * @throws LogicException If headers have already been passed 21 * @throws LogicException If headers have already been passed
28 * @throws InvalidArgumentException If the authentication is invalid 22 * @throws InvalidArgumentException If the authentication is invalid
29 */ 23 */
30 public static function login($username, $password, $remember = true) { 24 function login($username, $password, $remember = true) {
31 if (headers_sent()) { 25 if (headers_sent()) {
32 throw new LogicException('Unable to login because headers have been sent'); 26 throw new LogicException('Unable to login because headers have been sent');
33 } 27 }
...@@ -38,21 +32,20 @@ class Auth { ...@@ -38,21 +32,20 @@ class Auth {
38 , 'remember' => $remember 32 , 'remember' => $remember
39 )); 33 ));
40 34
41 $ref = new ReflectionObject($auth); 35 if (get_class($auth) == 'WP_User') {
42 if ($ref->name == 'WP_User') {
43 return $auth; 36 return $auth;
44 } 37 }
45 38
46 throw new InvalidArgumentException('Invalid username/password'); 39 throw new InvalidArgumentException('Invalid username/password');
47 //$auth->get_error_message()); this would be nice except it links to a wp-page 40 //$auth->get_error_message()); this would be nice except it links to a wp-page
48 } 41 }
49 42
50 /** 43 /**
51 * Attempts to log the user out 44 * Attempts to log the user out
52 * @returns Boolean 45 * @returns Boolean
53 * @throws LogicException If HTTP headers have already been sent 46 * @throws LogicException If HTTP headers have already been sent
54 */ 47 */
55 public static function logout() { 48 function logout() {
56 if (headers_sent()) { 49 if (headers_sent()) {
57 throw new LogicException('Unable to logout because headers have been sent'); 50 throw new LogicException('Unable to logout because headers have been sent');
58 } 51 }
...@@ -60,12 +53,12 @@ class Auth { ...@@ -60,12 +53,12 @@ class Auth {
60 _logout(); 53 _logout();
61 54
62 return true; 55 return true;
63 } 56 }
64 57
65 public static function register($user_data = Array(), $registration_method) { 58 function register($user_data = Array(), $registration_method) {
66 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); 59 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php');
67 60
68 $valid = new Auth_Validation($user_data); 61 $valid = new Validation($user_data);
69 if (count($valid->errors) > 0) { 62 if (count($valid->errors) > 0) {
70 throw new BadMethodCallException(implode("\n", $valid->errors)); 63 throw new BadMethodCallException(implode("\n", $valid->errors));
71 } 64 }
...@@ -77,18 +70,17 @@ class Auth { ...@@ -77,18 +70,17 @@ class Auth {
77 $wpdb->query("UPDATE `{$wpdb->users}` SET `user_status` = 1 WHERE `ID` = {$id}"); 70 $wpdb->query("UPDATE `{$wpdb->users}` SET `user_status` = 1 WHERE `ID` = {$id}");
78 71
79 return $id; 72 return $id;
80 } 73 }
81 74
82 public static function activate($username, $activation_key) { 75 function activate($username, $activation_key) {
83 do_action(self::ACTION_ACTIVATE, $user_id); 76 do_action(ACTION_ACTIVATE, $user_id);
84 } 77 }
85 78
86 public static function forgot_password($username, $forgot_method) { 79 function forgot_password($username, $forgot_method) {
87 80
88 }
89 } 81 }
90 82
91 class Auth_Validation extends Validation { 83 class Validation extends \Tz\Validation {
92 /** 84 /**
93 * @rule Not blank 85 * @rule Not blank
94 * @rule Valid WordPress username 86 * @rule Valid WordPress username
......
1 <?php 1 <?php
2 class Branding {
3 public static function make() {
4 add_actions('Branding_Actions');
5 }
6 }
7 2
8 class Branding_Actions { 3 namespace Tz\WordPress\Tools\Branding;
4 use Tz\WordPress\Tools;
5
6 class Actions {
9 public static function admin_print_styles() { 7 public static function admin_print_styles() {
10 _enqueue_style('branding-style', TzTools::tools_url('css/tenzing.css', __FILE__)); 8 _enqueue_style('branding-style', Tools\url('css/tenzing.css', __FILE__));
11 } 9 }
12 10
13 public static function admin_head() { 11 public static function admin_head() {
...@@ -22,10 +20,9 @@ class Branding_Actions { ...@@ -22,10 +20,9 @@ class Branding_Actions {
22 } 20 }
23 21
24 public static function login_head() { 22 public static function login_head() {
25 echo '<link rel="stylesheet" type="text/css" href="' . TzTools::tools_url('css/tz_login.css', __FILE__) . '" />'; 23 echo '<link rel="stylesheet" type="text/css" href="' . Tools\url('css/tz_login.css', __FILE__) . '" />';
26 } 24 }
27 } 25 }
28 26
29 Branding::make(); 27 Tools\add_actions(__NAMESPACE__ . '\Actions');
30
31 ?> 28 ?>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php 1 <?php
2 class ClientSettings { 2
3 const CAPABILITY = 'edit_client_settings'; 3 namespace Tz\WordPress\Tools\ClientSettings;
4 const ADMIN_PAGE = 'client-settings'; 4
5 5 use Tz\WordPress\Tools;
6 public static function make() { 6
7 static $made = false; 7 const CAPABILITY = 'edit_client_settings';
8 if ($made) { 8 const ADMIN_PAGE = 'client-settings';
9 throw new OverflowException('ClientSettings has already been initialized');
10 }
11 $made = true;
12 9
13 $role = get_role('administrator'); 10 $role = get_role('administrator');
14 $role->add_cap(self::CAPABILITY); 11 $role->add_cap(CAPABILITY);
15 12
16 add_actions('ClientSettings_Actions'); 13 Tools\add_actions(__NAMESPACE__ . '\Actions');
17 }
18 14
19 public static function viewOptionsPage() { 15 function viewOptionsPage() {
20 }
21 } 16 }
22 17
23 // register_setting() 18 // register_setting()
...@@ -29,13 +24,11 @@ class ClientSettings { ...@@ -29,13 +24,11 @@ class ClientSettings {
29 24
30 // do_settings_section() 25 // do_settings_section()
31 26
32 class ClientSettings_Actions { 27 class Actions {
33 public static function admin_menu() { 28 public static function admin_menu() {
34 $display = (current_user_can('manage_options') ? 'Client Settings' : 'Settings'); 29 $display = (current_user_can('manage_options') ? 'Client Settings' : 'Settings');
35 30
36 add_utility_page($display, $display, ClientSettings::CAPABILITY, ClientSettings::ADMIN_PAGE, Array('ClientSettings', 'viewOptionsPage')); 31 add_utility_page($display, $display, CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\viewOptionsPage');
37 } 32 }
38 } 33 }
39
40 ClientSettings::make();
41 ?> 34 ?>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php 1 <?php
2 namespace Tz\WordPress\Tools\PagePermissions;
3
4 use Tz\WordPress\Tools, Tz\WordPress\Tools\ClientSettings;
5
6 use \ReflectionClass, \ReflectionException;
7 use \WP_Option;
8 use \WP_User;
9
2 /** 10 /**
3 * Public API
4 */
5 class PagePermissions {
6 /**
7 * The name of the custom field stored in a post/page 11 * The name of the custom field stored in a post/page
8 * @type String 12 * @type String
9 */ 13 */
10 const META = 'accessible_to_roles'; 14 const META = 'accessible_to_roles';
11 const OPT = ''; 15 const OPT = '';
12 16
13 const ELE_SEL = 'general_access'; 17 const ELE_SEL = 'general_access';
14 const ELE_CUST = 'roles'; 18 const ELE_CUST = 'roles';
15 const ELE_AUTH = 'message_auth'; 19 const ELE_AUTH = 'message_auth';
16 const ELE_CUST_AUTH = 'message_cust_auth'; 20 const ELE_CUST_AUTH = 'message_cust_auth';
17 const ELE_DENIED = 'message_cust_denied'; 21 const ELE_DENIED = 'message_cust_denied';
18 22
19 /** 23 /**
20 * Lookup value for ELE_SEL for all users 24 * Lookup value for ELE_SEL for all users
21 * @type Integer 25 * @type Integer
22 */ 26 */
23 const OPT_ALL = 0; 27 const OPT_ALL = 0;
24 /** 28 /**
25 * Lookup value for ELE_SEL for login required 29 * Lookup value for ELE_SEL for login required
26 * @type Integer 30 * @type Integer
27 */ 31 */
28 const OPT_AUTH = 1; 32 const OPT_AUTH = 1;
29 /** 33 /**
30 * Lookup value for ELE_SEL for custom roles 34 * Lookup value for ELE_SEL for custom roles
31 * @type Integer 35 * @type Integer
32 */ 36 */
33 const OPT_CUST = 2; 37 const OPT_CUST = 2;
38
34 39
40 class Vars {
35 /** 41 /**
36 * WP current user data 42 * WP current user data
37 * @type Array 43 * @type Array
38 */ 44 */
39 private static $current_user = false; 45 public static $current_user = false;
40 46 }
41 public static function init() {
42 if (false !== self::$current_user) {
43 throw new OverflowException('PagePermissions already initialized');
44 }
45 47
46 self::$current_user = _get_current_user(); 48 function make() {
47 } 49 Vars::$current_user = _get_current_user();
50 }
48 51
49 public static function initAjax() { 52 function initAjax() {
50 $selected = unserialize($_POST['string_value']); 53 $selected = unserialize($_POST['string_value']);
51 include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php'); 54 include(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
52 } 55 }
53 56
54 /** 57 /**
55 * The key function in all of this; called by the Theme, 58 * The key function in all of this; called by the Theme,
56 * this determines if the user is able to view the page. 59 * this determines if the user is able to view the page.
57 * @param {Integer} $post_id 60 * @param {Integer} $post_id
58 * @returns {Boolean|String} true if user can view, error message if not 61 * @returns {Boolean|String} true if user can view, error message if not
59 * @throw InvalidArgumentException 62 * @throw InvalidArgumentException
60 */ 63 */
61 public static function current_user_can_view($post_id = false) { 64 function current_user_can_view($post_id = false) {
62 static $settings = false; 65 static $settings = false;
63 if (false === $settings) { 66 if (false === $settings) {
64 $settings = new WP_Option(PagePermissionsAdmin::SETTING_NS); 67 $settings = new WP_Option(SETTING_NS);
65 } 68 }
66 69
67 if (false === $post_id) { 70 if (false === $post_id) {
...@@ -70,17 +73,17 @@ class PagePermissions { ...@@ -70,17 +73,17 @@ class PagePermissions {
70 } 73 }
71 74
72 // Meta value hasn't been set, getting settings defaults 75 // Meta value hasn't been set, getting settings defaults
73 if (NULL === $data = array_shift(get_post_meta($post_id, self::META))) { 76 if (NULL === $data = array_shift(get_post_meta($post_id, META))) {
74 $data = Array(self::ELE_SEL => $settings[self::ELE_SEL], self::ELE_CUST => $settings[self::ELE_CUST]); 77 $data = Array(ELE_SEL => $settings[ELE_SEL], ELE_CUST => $settings[ELE_CUST]);
75 } 78 }
76 79
77 // Anyone has access, God has no limitations 80 // Anyone has access, God has no limitations
78 if ($data[self::ELE_SEL] == self::OPT_ALL || self::is_admin()) { 81 if ($data[ELE_SEL] == OPT_ALL || is_admin()) {
79 return true; 82 return true;
80 } 83 }
81 84
82 // Login required 85 // Login required
83 if ($data[self::ELE_SEL] == self::OPT_AUTH) { 86 if ($data[ELE_SEL] == OPT_AUTH) {
84 // User is logged in 87 // User is logged in
85 if (is_user_logged_in()) { 88 if (is_user_logged_in()) {
86 return true; 89 return true;
...@@ -91,32 +94,32 @@ class PagePermissions { ...@@ -91,32 +94,32 @@ class PagePermissions {
91 } 94 }
92 95
93 // Specific role required 96 // Specific role required
94 if ($data[self::ELE_SEL] == self::OPT_CUST) { 97 if ($data[ELE_SEL] == OPT_CUST) {
95 // User isn't even logged in; send message 98 // User isn't even logged in; send message
96 if (!is_user_logged_in()) { 99 if (!is_user_logged_in()) {
97 return $settings[self::ELE_CUST_AUTH]; 100 return $settings[ELE_CUST_AUTH];
98 } 101 }
99 102
100 // User meets role required 103 // User meets role required
101 if (isset($data[self::ELE_CUST][self::get_user_role()])) { 104 if (isset($data[ELE_CUST][get_user_role()])) {
102 return true; 105 return true;
103 } 106 }
104 107
105 // User is logged in, but doesn't have sufficient privileges, return message 108 // User is logged in, but doesn't have sufficient privileges, return message
106 return $settings[self::ELE_DENIED]; 109 return $settings[ELE_DENIED];
107 } 110 }
108 111
109 // This shouldn't happend; but just in case 112 // This shouldn't happend; but just in case
110 return 'An unknown permission error has occurred'; 113 return 'An unknown permission error has occurred';
111 } 114 }
112 115
113 /** 116 /**
114 * @param {Integer|String} $user Username or ID of user to lookup (or false for current user) 117 * @param {Integer|String} $user Username or ID of user to lookup (or false for current user)
115 * @returns {String} $role The key of the users' role 118 * @returns {String} $role The key of the users' role
116 */ 119 */
117 public static function get_user_role($user = false) { 120 function get_user_role($user = false) {
118 if (false === $user) { 121 if (false === $user) {
119 $user_data = self::$current_user; 122 $user_data = Vars::$current_user;
120 } else { 123 } else {
121 $user_data = new WP_User($user); 124 $user_data = new WP_User($user);
122 } 125 }
...@@ -130,30 +133,41 @@ class PagePermissions { ...@@ -130,30 +133,41 @@ class PagePermissions {
130 $user_role = array_shift($user_roles); 133 $user_role = array_shift($user_roles);
131 134
132 return $user_role; 135 return $user_role;
133 } 136 }
134 137
135 /** 138 /**
136 * Determine if a user is a site administrator 139 * Determine if a user is a site administrator
137 * @param {Integer|String} $user Username or ID of user to lookup (or false for current user) 140 * @param {Integer|String} $user Username or ID of user to lookup (or false for current user)
138 * @returns {Boolean} 141 * @returns {Boolean}
139 */ 142 */
140 public static function is_admin($user = false) { 143 function is_admin($user = false) {
141 return (self::get_user_role($user) == 'administrator' ? true : false); 144 return (get_user_role($user) == 'administrator' ? true : false);
142 } 145 }
143 146
144 /** 147 /**
145 * Get a lookup of all the forum elements 148 * Get a lookup of all the forum elements
146 * @returns {Array} An associative array of the forum elemnts name/values 149 * @returns {Array} An associative array of the forum elemnts name/values
147 */ 150 */
148 public static function getFieldNames() { 151 function getFieldNames() {
149 static $fields = false; 152 static $fields = false;
150 if (false !== $fields) { 153 if (false !== $fields) {
151 return $fields; 154 return $fields;
152 } 155 }
153 156
154 $fields = Array(); 157 $fields = Array();
158 /*
155 $ref = new ReflectionClass(__CLASS__); 159 $ref = new ReflectionClass(__CLASS__);
156 $consts = $ref->getConstants(); 160 $consts = $ref->getConstants();
161 */
162 // Need to do this since 5.3, namespace instead of Class, can't reflect namespaces
163 $consts = Array(
164 'ELE_SEL' => 'general_access'
165 , 'ELE_CUST' => 'roles'
166 , 'ELE_AUTH' => 'message_auth'
167 , 'ELE_CUST_AUTH' => 'message_cust_auth'
168 , 'ELE_DENIED' => 'message_cust_denied'
169 );
170
157 foreach ($consts as $const => $value) { 171 foreach ($consts as $const => $value) {
158 if (substr($const, 0, 4) == 'ELE_') { 172 if (substr($const, 0, 4) == 'ELE_') {
159 $fields[$const] = $value; 173 $fields[$const] = $value;
...@@ -161,105 +175,95 @@ class PagePermissions { ...@@ -161,105 +175,95 @@ class PagePermissions {
161 } 175 }
162 176
163 return $fields; 177 return $fields;
164 }
165 } 178 }
166 179
167 /** 180 namespace Tz\WordPress\Tools\PagePermissions\Admin;
168 * Aministration control
169 */
170 class PagePermissionsAdmin {
171 const CAPABILITY = 'manage_page_permissions';
172 const ADMIN_PAGE = 'page-permission-settings';
173 const SUBMIT_HOOK = 'update_def_page_permissions';
174 const SETTING_NS = 'page_permission_defaults';
175 181
176 public static function make() { 182 use Tz\WordPress\Tools;
177 static $made = false; 183 use Tz\WordPress\Tools\PagePermissions;
178 if ($made) { 184 use Tz\WordPress\Tools\ClientSettings;
179 throw new OverflowException('make has already beed called');
180 }
181 $made = true;
182 185
183 TzTools::import('ClientSettings'); 186 use \WP_Option;
187
188 const CAPABILITY = 'manage_page_permissions';
189 const ADMIN_PAGE = 'page-permission-settings';
190 const SUBMIT_HOOK = 'update_def_page_permissions';
191 const SETTING_NS = 'page_permission_defaults';
192
193 function make() {
194 Tools\import('ClientSettings');
184 195
185 $role = get_role('administrator'); 196 $role = get_role('administrator');
186 $role->add_cap(self::CAPABILITY); 197 $role->add_cap(CAPABILITY);
187 198
188 add_filters('PagePermissionsAdmin_Filters'); 199 Tools\add_filters(__NAMESPACE__ . '\Filters');
189 200
190 if (isset($_POST[self::SUBMIT_HOOK]) && current_user_can(self::CAPABILITY)) { 201 if (isset($_POST[SUBMIT_HOOK]) && current_user_can(CAPABILITY)) {
191 self::submit(); 202 submit();
192 } 203 }
193 204
194 add_actions('PagePermissions_Actions'); 205 Tools\add_actions(__NAMESPACE__ . '\Actions');
195 } 206 }
196 207
197 public static function viewOptionsPage() { 208 function viewOptionsPage() {
198 $selected = self::getOptions(); 209 $selected = getOptions();
199 210
200 include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'settings.php'); 211 include(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'settings.php');
201 } 212 }
202 213
203 public static function viewMetaBox($post, $box_info) { 214 function viewMetaBox($post, $box_info) {
204 $selected = ($post->ID == 0 ? self::getOptions() : array_shift(get_post_meta($post->ID, PagePermissions::META))); 215 $selected = ($post->ID == 0 ? getOptions() : array_shift(get_post_meta($post->ID, PagePermissions\META)));
205 216
206 // If the post doesn't have the field saved get defaults 217 // If the post doesn't have the field saved get defaults
207 if (is_null($selected)) { 218 if (is_null($selected)) {
208 $selected = self::getOptions(); 219 $selected = getOptions();
209 } 220 }
210 221
211 include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php'); 222 include(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
212 } 223 }
213 224
214 /** 225 /**
215 * Handles saving data when a post/page is saved 226 * Handles saving data when a post/page is saved
216 */ 227 */
217 public static function submit() { 228 function submit() {
218 unset($_POST[self::SUBMIT_HOOK]); 229 unset($_POST[SUBMIT_HOOK]);
219 230
220 $options = self::getOptions(); 231 $options = getOptions();
221 $fields = PagePermissions::getFieldNames(); 232 $fields = PagePermissions\getFieldNames();
222 foreach ($fields as $field) { 233 foreach ($fields as $field) {
223 if (isset($_POST[$field])) { 234 if (isset($_POST[$field])) {
224 235 $options[$field] = array_stripslashes($_POST[$field]);
225 // This should probably be done via a recursive fn call or array_walk or something
226 if (is_array($_POST[$field])) {
227 $options[$field] = Array();
228 foreach ($_POST[$field] as $key => $val) {
229 $options[$field][$key] = stripslashes($_POST[$field]);
230 }
231 } else {
232 // not sure if stripslashes should go here or in WP_Options
233 $options[$field] = stripslashes($_POST[$field]);
234 }
235 } else { 236 } else {
236 $options[$field] = ''; 237 $options[$field] = '';
237 } 238 }
238 } 239 }
239 240
240 $options->save(); 241 $options->save();
241 } 242 }
242 243
243 public static function getOptions() { 244 function array_stripslashes($value) {
245 return (is_array($value) ? array_map(__FUNCTION__, $value) : stripslashes($value));
246 }
247
248 function getOptions() {
244 static $options = false; 249 static $options = false;
245 if (false !== $options) { 250 if (false !== $options) {
246 return $options; 251 return $options;
247 } 252 }
248 253
249 $options = new WP_Option(self::SETTING_NS); 254 $options = new WP_Option(SETTING_NS);
250 return $options; 255 return $options;
251 }
252 } 256 }
253 257
254 /** 258 /**
255 * Each method is a handler for it's WordPress `add_action` namesake 259 * Each method is a handler for it's WordPress `add_action` namesake
256 */ 260 */
257 class PagePermissions_Actions { 261 class Actions {
258 public static function init() { 262 public static function init() {
259 register_taxonomy(PagePermissions::META, 'attachment', Array('hierarachical' => false, 'label' => 'Page Permissions', 'query_var' => false)); 263 register_taxonomy(PagePermissions\META, 'attachment', Array('hierarachical' => false, 'label' => 'Page Permissions', 'query_var' => false));
260 264
261 $file = $_SERVER['REQUEST_URI']; 265 $file = $_SERVER['REQUEST_URI'];
262 if ($file == '/wp-admin/media-new.php' && !PagePermissions::is_admin()) { 266 if ($file == '/wp-admin/media-new.php' && !PagePermissions\is_admin()) {
263 header("Location: " . $file . "?flash=0"); 267 header("Location: " . $file . "?flash=0");
264 } 268 }
265 269
...@@ -267,49 +271,49 @@ class PagePermissions_Actions { ...@@ -267,49 +271,49 @@ class PagePermissions_Actions {
267 // Ideally this is in its own `edit_attachment` method...but that isn't working 271 // Ideally this is in its own `edit_attachment` method...but that isn't working
268 if (isset($_POST['action']) && $_POST['action'] == 'editattachment') { 272 if (isset($_POST['action']) && $_POST['action'] == 'editattachment') {
269 $real_id = $_POST['attachment_id']; 273 $real_id = $_POST['attachment_id'];
270 $current = array_shift(get_post_meta($real_id, PagePermissions::META)); 274 $current = array_shift(get_post_meta($real_id, PagePermissions\META));
271 275
272 $new = Array(); 276 $new = Array();
273 $new[PagePermissions::ELE_SEL] = $_POST[PagePermissions::ELE_SEL]; 277 $new[PagePermissions\ELE_SEL] = $_POST[PagePermissions\ELE_SEL];
274 if (isset($_POST[PagePermissions::ELE_CUST])) { 278 if (isset($_POST[PagePermissions\ELE_CUST])) {
275 $new[PagePermissions::ELE_CUST] = $_POST[PagePermissions::ELE_CUST]; 279 $new[PagePermissions\ELE_CUST] = $_POST[PagePermissions\ELE_CUST];
276 } else { 280 } else {
277 $new[PagePermissions::ELE_CUST] = Array(); 281 $new[PagePermissions\ELE_CUST] = Array();
278 } 282 }
279 283
280 if (is_null($current)) { 284 if (is_null($current)) {
281 add_post_meta($real_id, PagePermissions::META, $new, true); 285 add_post_meta($real_id, PagePermissions\META, $new, true);
282 } else { 286 } else {
283 update_post_meta($real_id, PagePermissions::META, $new); 287 update_post_meta($real_id, PagePermissions\META, $new);
284 } 288 }
285 } 289 }
286 } 290 }
287 291
288 public static function admin_menu() { 292 public static function admin_menu() {
289 if (current_user_can(ClientSettings::CAPABILITY)) { 293 if (current_user_can(ClientSettings\CAPABILITY)) {
290 add_submenu_page(ClientSettings::ADMIN_PAGE, 'Permission Defaults', 'Permission Defaults', PagePermissionsAdmin::CAPABILITY, PagePermissionsAdmin::ADMIN_PAGE, Array('PagePermissionsAdmin', 'viewOptionsPage')); 294 add_submenu_page(ClientSettings\ADMIN_PAGE, 'Permission Defaults', 'Permission Defaults', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\viewOptionsPage');
291 add_meta_box('page_permissions', 'Page Permissions', Array('PagePermissionsAdmin', 'viewMetaBox'), 'page', 'side', 'low'); 295 add_meta_box('page_permissions', 'Page Permissions', __NAMESPACE__ . '\viewMetaBox', 'page', 'side', 'low');
292 } 296 }
293 } 297 }
294 298
295 public static function admin_print_scripts() { 299 public static function admin_print_scripts() {
296 $innerhtml = ''; 300 $innerhtml = '';
297 if ('0' !== ($change_field = (isset($_GET['attachment_id']) ? 'attachments[' . $_GET['attachment_id'] . '][' . PagePermissions::META . ']' : '0'))) { 301 if ('0' !== ($change_field = (isset($_GET['attachment_id']) ? 'attachments[' . $_GET['attachment_id'] . '][' . PagePermissions\META . ']' : '0'))) {
298 $selected = array_shift(get_post_meta($_GET['attachment_id'], PagePermissions::META)); 302 $selected = array_shift(get_post_meta($_GET['attachment_id'], PagePermissions\META));
299 if (is_null($selected)) { 303 if (is_null($selected)) {
300 $selected = PagePermissionsAdmin::getOptions(); 304 $selected = getOptions();
301 } 305 }
302 306
303 ob_start(); 307 ob_start();
304 require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php'); 308 require(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
305 $innerhtml = ob_get_contents(); 309 $innerhtml = ob_get_contents();
306 ob_end_clean(); 310 ob_end_clean();
307 } 311 }
308 312
309 _enqueue_script('page-permissions', TzTools::tools_url('PagePermissions.js', __FILE__)); 313 _enqueue_script('page-permissions', Tools\url('PagePermissions.js', __FILE__));
310 _localize_script('page-permissions', 'TzPagePermissionsData', Array( 314 _localize_script('page-permissions', 'TzPagePermissionsData', Array(
311 'trigger' => PagePermissions::ELE_SEL 315 'trigger' => PagePermissions\ELE_SEL
312 , 'focus' => PagePermissions::OPT_CUST 316 , 'focus' => PagePermissions\OPT_CUST
313 , 'change_field' => $change_field 317 , 'change_field' => $change_field
314 , 'innerHTML' => rawurlencode($innerhtml) 318 , 'innerHTML' => rawurlencode($innerhtml)
315 )); 319 ));
...@@ -323,42 +327,34 @@ class PagePermissions_Actions { ...@@ -323,42 +327,34 @@ class PagePermissions_Actions {
323 if (false === ($real_id = _is_post_revision($post_id))) { 327 if (false === ($real_id = _is_post_revision($post_id))) {
324 $real_id = $post_id; 328 $real_id = $post_id;
325 } 329 }
326 $current = array_shift(get_post_meta($real_id, PagePermissions::META)); 330 $current = array_shift(get_post_meta($real_id, PagePermissions\META));
327 331
328 $new = Array(); 332 $new = Array();
329 $new[PagePermissions::ELE_SEL] = $_POST[PagePermissions::ELE_SEL]; 333 $new[PagePermissions\ELE_SEL] = $_POST[PagePermissions\ELE_SEL];
330 if (isset($_POST[PagePermissions::ELE_CUST])) { 334 if (isset($_POST[PagePermissions\ELE_CUST])) {
331 $new[PagePermissions::ELE_CUST] = $_POST[PagePermissions::ELE_CUST]; 335 $new[PagePermissions\ELE_CUST] = $_POST[PagePermissions\ELE_CUST];
332 } else { 336 } else {
333 $new[PagePermissions::ELE_CUST] = Array(); 337 $new[PagePermissions\ELE_CUST] = Array();
334 } 338 }
335 339
336 if (is_null($current)) { 340 if (is_null($current)) {
337 add_post_meta($real_id, PagePermissions::META, $new, true); 341 add_post_meta($real_id, PagePermissions\META, $new, true);
338 } else { 342 } else {
339 update_post_meta($real_id, PagePermissions::META, $new); 343 update_post_meta($real_id, PagePermissions\META, $new);
340 } 344 }
341 } 345 }
342 } 346 }
343 347
344 class PagePermissionsAdmin_Filters { 348 class Filters {
345 public static function image_upload_iframe_src($result) { 349 public static function flash_uploader() {
346 return $result . '&flash=0'; 350 return false;
347 }
348
349 public static function video_upload_iframe_src($result) {
350 return $result . '&flash=0';
351 }
352
353 public static function audio_upload_iframe_src($result) {
354 return $result . '&flash=0';
355 } 351 }
356 } 352 }
357 353
358 if (isset($_POST['tz_pp_ajax'])) { 354 if (isset($_POST['tz_pp_ajax'])) {
359 PagePermissions::initAjax(); 355 PagePermissions\initAjax();
360 } else { 356 } else {
361 PagePermissions::init(); 357 PagePermissions\make();
362 PagePermissionsAdmin::make(); 358 make();
363 } 359 }
364 ?> 360 ?>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php 1 <?php
2
3 namespace Tz\WordPress\Tools\PagePermissions;
4
5 use \WP_Roles;
6 use \UnderflowException;
7
2 if (!isset($selected)) { 8 if (!isset($selected)) {
3 throw new UnderflowException('Current Page Permission settings not provided'); 9 throw new UnderflowException('Current Page Permission settings not provided');
4 } 10 }
5 11
6 $opt_selected = $selected[PagePermissions::ELE_SEL]; 12 $opt_selected = $selected[ELE_SEL];
7 ?> 13 ?>
8 14
9 <select id="<?php echo PagePermissions::ELE_SEL; ?>" name="<?php echo PagePermissions::ELE_SEL; ?>"> 15 <select id="<?php echo ELE_SEL; ?>" name="<?php echo ELE_SEL; ?>">
10 <option value="<?php echo PagePermissions::OPT_ALL . '"' . (PagePermissions::OPT_ALL == $opt_selected ? ' selected' : ''); ?>>Anyone</option> 16 <option value="<?php echo OPT_ALL . '"' . (OPT_ALL == $opt_selected ? ' selected' : ''); ?>>Anyone</option>
11 <option value="<?php echo PagePermissions::OPT_AUTH . '"' . (PagePermissions::OPT_AUTH == $opt_selected ? ' selected' : ''); ?>>Must be Logged In</option> 17 <option value="<?php echo OPT_AUTH . '"' . (OPT_AUTH == $opt_selected ? ' selected' : ''); ?>>Must be Logged In</option>
12 <option value="<?php echo PagePermissions::OPT_CUST . '"' . (PagePermissions::OPT_CUST == $opt_selected ? ' selected' : ''); ?>>Specific Roles</option> 18 <option value="<?php echo OPT_CUST . '"' . (OPT_CUST == $opt_selected ? ' selected' : ''); ?>>Specific Roles</option>
13 </select> 19 </select>
14 20
15 <div id="TzSpecific"> 21 <div id="TzSpecific">
...@@ -20,8 +26,8 @@ ...@@ -20,8 +26,8 @@
20 unset($rc, $roles['administrator']); 26 unset($rc, $roles['administrator']);
21 27
22 foreach ($roles as $key => $display) { 28 foreach ($roles as $key => $display) {
23 $checked = (isset($selected[PagePermissions::ELE_CUST][$key]) ? ' checked' : ''); 29 $checked = (isset($selected[ELE_CUST][$key]) ? ' checked' : '');
24 echo '<br /><input type="checkbox" id="' . $key . '" name="' . PagePermissions::ELE_CUST . '[' . $key . ']" value="1"' . $checked . ' />'; 30 echo '<br /><input type="checkbox" id="' . $key . '" name="' . ELE_CUST . '[' . $key . ']" value="1"' . $checked . ' />';
25 echo '<label for="' . $key . '">' . $display . '</label>'; 31 echo '<label for="' . $key . '">' . $display . '</label>';
26 } 32 }
27 ?> 33 ?>
......
1 <?php require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'form.php'); ?>
...\ No newline at end of file ...\ No newline at end of file
1 <?php require(__DIR__ . DIRECTORY_SEPARATOR . 'form.php'); ?>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php /* 1 <?php
2
3 namespace Tz\WordPress\Tools\PagePermissions;
4
5 use Tz\WordPress\Tools\PagePermissions\Admin;
6
7 /*
2 Idea: Checkbox beside each textarea with option to include registration forum or not 8 Idea: Checkbox beside each textarea with option to include registration forum or not
3 */ ?> 9 */ ?>
4 10
5
6 <div class="wrap"> 11 <div class="wrap">
7 <?php screen_icon(); ?> 12 <?php screen_icon(); ?>
8 <h2>Permission Defaults</h2> 13 <h2>Permission Defaults</h2>
9 14
10 <form method="post"> 15 <form method="post">
11 <input type="hidden" name="<?php echo PagePermissionsAdmin::SUBMIT_HOOK; ?>" value="1" /> 16 <input type="hidden" name="<?php echo Admin\SUBMIT_HOOK; ?>" value="1" />
12 17
13 <h3>Default Option</h3> 18 <h3>Default Option</h3>
14 <?php require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'form.php'); ?> 19 <?php require(__DIR__ . DIRECTORY_SEPARATOR . 'form.php'); ?>
15 20
16 <hr /> 21 <hr />
17 22
...@@ -19,18 +24,18 @@ Idea: Checkbox beside each textarea with option to include registration forum or ...@@ -19,18 +24,18 @@ Idea: Checkbox beside each textarea with option to include registration forum or
19 <h6>(Messages are displayed for given criteria when page permission is not met)</h6> 24 <h6>(Messages are displayed for given criteria when page permission is not met)</h6>
20 25
21 <p> 26 <p>
22 <label for="<?php echo PagePermissions::ELE_AUTH; ?>" />"Must be Logged In" message for un-authenticated visitors</label> 27 <label for="<?php echo ELE_AUTH; ?>" />"Must be Logged In" message for un-authenticated visitors</label>
23 <br /><textarea id="<?php echo PagePermissions::ELE_AUTH; ?>" name="<?php echo PagePermissions::ELE_AUTH; ?>"><?php echo $selected[PagePermissions::ELE_AUTH]; ?></textarea> 28 <br /><textarea id="<?php echo ELE_AUTH; ?>" name="<?php echo ELE_AUTH; ?>"><?php echo $selected[ELE_AUTH]; ?></textarea>
24 </p> 29 </p>
25 30
26 <p> 31 <p>
27 <label for="<?php echo PagePermissions::ELE_CUST_AUTH; ?>" />"Only Specific Roles" message for un-authenticated visitors</label> 32 <label for="<?php echo ELE_CUST_AUTH; ?>" />"Only Specific Roles" message for un-authenticated visitors</label>
28 <br /><textarea id="<?php echo PagePermissions::ELE_CUST_AUTH; ?>" name="<?php echo PagePermissions::ELE_CUST_AUTH; ?>"><?php echo $selected[PagePermissions::ELE_CUST_AUTH]; ?></textarea> 33 <br /><textarea id="<?php echo ELE_CUST_AUTH; ?>" name="<?php echo ELE_CUST_AUTH; ?>"><?php echo $selected[ELE_CUST_AUTH]; ?></textarea>
29 </p> 34 </p>
30 35
31 <p> 36 <p>
32 <label for="<?php echo PagePermissions::ELE_DENIED; ?>" />"Only Specific Roles" message for authenticated users without sufficient privelages</label> 37 <label for="<?php echo ELE_DENIED; ?>" />"Only Specific Roles" message for authenticated users without sufficient privelages</label>
33 <br /><textarea id="<?php echo PagePermissions::ELE_DENIED; ?>" name="<?php echo PagePermissions::ELE_DENIED; ?>"><?php echo $selected[PagePermissions::ELE_DENIED]; ?></textarea> 38 <br /><textarea id="<?php echo ELE_DENIED; ?>" name="<?php echo ELE_DENIED; ?>"><?php echo $selected[ELE_DENIED]; ?></textarea>
34 </p> 39 </p>
35 40
36 <p class="submit"><input type="submit" class="button-primary" value="Save Changes" /></p> 41 <p class="submit"><input type="submit" class="button-primary" value="Save Changes" /></p>
......
1 <?php 1 <?php
2 class ShortCodes extends Singleton {
3 private static $registered = Array();
4 private static $private = Array();
5 2
6 public static function make() { 3 namespace Tz\WordPress\Tools\ShortCodes;
7 add_actions('ShortCodes_Actions'); 4
5 use Tz\WordPress\Tools;
6
7 use \ReflectionClass, \ReflectionMethod, \ReflectionFunction;
8 use \Exception;
9
10 Tools\add_actions(__NAMESPACE__ . '\Actions');
11
12 if (function_exists('rename_function')) {
13 rename_function('add_shortcode', 'wp_add_shortcode');
14
15 function add_shortcode() {
16 $args = func_get_args();
17 call_user_func_array('add', $args);
18 }
8 } 19 }
9 20
10 public static function registerClass($class) { 21 function add_shortcodes($class) {
11 if (!class_exists($class)) { 22 if (!class_exists($class)) {
12 throw new Exception("$class does not exist"); 23 throw new Exception("$class does not exist");
13 } 24 }
...@@ -15,16 +26,20 @@ class ShortCodes extends Singleton { ...@@ -15,16 +26,20 @@ class ShortCodes extends Singleton {
15 $ref = new ReflectionClass($class); 26 $ref = new ReflectionClass($class);
16 $methods = $ref->getMethods(ReflectionMethod::IS_STATIC); 27 $methods = $ref->getMethods(ReflectionMethod::IS_STATIC);
17 foreach ($methods as $method) { 28 foreach ($methods as $method) {
18 self::add($method->name, Array($class, $method->name)); 29 add($method->name, Array($class, $method->name));
19 }
20 } 30 }
31 }
32
33 function registerClass($class) {
34 call_user_func('add_shortcodes', $class);
35 }
21 36
22 public static function add($code, $callback) { 37 function add($code, $callback) {
23 $fn = (function_exists('wp_add_shortcode') ? 'wp_add_shortcode' : 'add_shortcode'); 38 $fn = (function_exists('wp_add_shortcode') ? 'wp_add_shortcode' : 'add_shortcode');
24 call_user_func($fn, $code, $callback); 39 call_user_func($fn, $code, $callback);
25 40
26 if (is_admin()) { 41 if (is_admin()) { // I may want to remove this condition...
27 self::$registered[$code] = Array('code' => $code, 'title' => $code, 'params' => Array(), 'uses_content' => 0); 42 Vars::$registered[$code] = Array('code' => $code, 'title' => $code, 'params' => Array(), 'uses_content' => 0);
28 43
29 if (is_array($callback)) { 44 if (is_array($callback)) {
30 $ref = new ReflectionMethod($callback[0], $callback[1]); 45 $ref = new ReflectionMethod($callback[0], $callback[1]);
...@@ -45,49 +60,49 @@ class ShortCodes extends Singleton { ...@@ -45,49 +60,49 @@ class ShortCodes extends Singleton {
45 $tag = trim($comment, '@'); 60 $tag = trim($comment, '@');
46 } 61 }
47 62
48 if (method_exists(__CLASS__, 'parseTag_' . $tag)) { 63 if (function_exists('parseTag_' . $tag)) {
49 call_user_func_array(Array(__CLASS__, 'parseTag_' . $tag), Array($code, $comment)); 64 call_user_func_array('parseTag_' . $tag, Array($code, $comment));
50 }
51 } 65 }
52 } 66 }
53 } 67 }
54 } 68 }
69 }
55 70
56 public static function parseTag_display($code, $string) { 71 function parseTag_display($code, $string) {
57 $string = trim(str_replace('@display', '', $string)); 72 $string = trim(str_replace('@display', '', $string));
58 self::$registered[$code]['title'] = $string; 73 Vars::$registered[$code]['title'] = $string;
59 } 74 }
60 75
61 public static function parseTag_param($code, $string) { 76 function parseTag_param($code, $string) {
62 $regex = '.*?@param {((?:[a-z][a-z]+))(\\(.*?\\))?} (.*?) (.*?)$'; // Awww yeah! 77 $regex = '.*?@param {((?:[a-z][a-z]+))(\\(.*?\\))?} (.*?) (.*?)$'; // Awww yeah!
63 if ($num = preg_match_all("/" . $regex . "/is", $string, $matches)) { 78 if ($num = preg_match_all("/" . $regex . "/is", $string, $matches)) {
64 self::$registered[$code]['params'][] = Array('name' => $matches[3][0], 'type' => $matches[1][0], 'options' => explode(',', trim($matches[2][0], ')(')), 'desc' => $matches[4][0]); 79 Vars::$registered[$code]['params'][] = Array('name' => $matches[3][0], 'type' => $matches[1][0], 'options' => explode(',', trim($matches[2][0], ')(')), 'desc' => $matches[4][0]);
65 }
66 } 80 }
81 }
67 82
68 public static function parseTag_private($code, $string) { 83 function parseTag_private($code, $string) {
69 self::$private[$code] = 1; 84 Vars::$private[$code] = 1;
70 } 85 }
71 86
72 public static function uses_content($code) { 87 function uses_content($code) {
73 self::$registered[$code]['uses_content'] = 1; 88 Vars::$registered[$code]['uses_content'] = 1;
74 } 89 }
75 90
76 public static function getRegistered() { 91 function getRegistered() {
77 $return = self::$registered; 92 $return = Vars::$registered;
78 foreach (self::$private as $key => $one) { 93 foreach (Vars::$private as $key => $one) {
79 unset($return[$key]); 94 unset($return[$key]);
80 } 95 }
81 96
82 return $return; 97 return $return;
83 } 98 }
84 99
85 public static function drawMetaBox() { 100 function drawMetaBox() {
86 ?> 101 ?>
87 <label for="TzShortCodeList">Tag:</label> 102 <label for="TzShortCodeList">Tag:</label>
88 <select id="TzShortCodeList" name="TzShortCodeList"> 103 <select id="TzShortCodeList" name="TzShortCodeList">
89 <?php 104 <?php
90 $options = ShortCodes::getRegistered(); 105 $options = getRegistered();
91 ksort($options); 106 ksort($options);
92 foreach ($options as $tag => $data) { 107 foreach ($options as $tag => $data) {
93 echo '<option value="' . $tag . '">' . $data['title'] . '</option>'; 108 echo '<option value="' . $tag . '">' . $data['title'] . '</option>';
...@@ -99,42 +114,27 @@ class ShortCodes extends Singleton { ...@@ -99,42 +114,27 @@ class ShortCodes extends Singleton {
99 <input type="button" id="TzInsertSC" value="<?php _e('Insert into post'); ?>" /> 114 <input type="button" id="TzInsertSC" value="<?php _e('Insert into post'); ?>" />
100 </p> 115 </p>
101 <?php 116 <?php
102 }
103 } 117 }
104 118
105 class ShortCodes_Actions { 119 class Actions {
106 public static function admin_menu() { 120 public static function admin_menu() {
107 add_meta_box('TzShortCodes', 'Code Helper', Array('ShortCodes', 'drawMetaBox'), 'post', 'normal'); 121 add_meta_box('TzShortCodes', 'Code Helper', __NAMESPACE__ . '\drawMetaBox', 'post', 'normal');
108 add_meta_box('TzShortCodes', 'Code Helper', Array('ShortCodes', 'drawMetaBox'), 'page', 'normal'); 122 add_meta_box('TzShortCodes', 'Code Helper', __NAMESPACE__ . '\drawMetaBox', 'page', 'normal');
109 } 123 }
110 124
111 public static function admin_print_scripts() { 125 public static function admin_print_scripts() {
112 if ($GLOBALS['editing']) { 126 if ($GLOBALS['editing']) {
113 _enqueue_script('shortcoder', TzTools::tools_url('shortcoder.js', __FILE__), Array('jquery')); 127 _enqueue_script('shortcoder', Tools\url('shortcoder.js', __FILE__), Array('jquery'));
114 128
115 echo "<script type=\"text/javascript\">\n/* <![CDATA[ */\n"; 129 echo "<script type=\"text/javascript\">\n/* <![CDATA[ */\n";
116 echo 'var TzRegisteredShortCodes = ' . json_encode(ShortCodes::getRegistered()); 130 echo 'var TzRegisteredShortCodes = ' . json_encode(getRegistered());
117 echo "\n/* ]]> */</script>\n"; 131 echo "\n/* ]]> */</script>\n";
118 } 132 }
119 } 133 }
120 } 134 }
121 135
122 /** 136 class Vars {
123 * @deprecated 137 public static $registered = Array();
124 */ 138 public static $private = Array();
125 function add_shortcodes($class) {
126 call_user_func(Array('ShortCodes', 'registerClass'), $class);
127 } 139 }
128
129
130 if (function_exists('rename_function')) {
131 rename_function('add_shortcode', 'wp_add_shortcode');
132
133 function add_shortcode() {
134 $args = func_get_args();
135 call_user_func_array(Array('ShortCodes', 'add'), $args);
136 }
137 }
138
139 ShortCodes::make();
140 ?> 140 ?>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php 1 <?php
2
3 namespace Tz;
4
5 use Exception;
6
2 /** 7 /**
3 * Handles data preparation for XMLHTTP responses to xmlhttpHandler script 8 * Handles data preparation for XMLHTTP responses to xmlhttpHandler script
4 * 9 *
......
1 <?php 1 <?php
2
3 namespace Tz;
4
5 use \Exception;
6
2 abstract class Validation { 7 abstract class Validation {
3 /** 8 /**
4 * Associative array of valid fields 9 * Associative array of valid fields
......
1 <?php 1 <?php
2 /* 2 /*
3 Plugin Name: Tenzing Tools 3 Plugin Name: Tenzing Tools
4 Version: 0.3b 4 Version: 0.4b
5 Description: Various classes and functions to help out with stuff 5 Description: Various classes and functions to help out with stuff
6 Author: Tenzing 6 Author: Tenzing
7 */ 7 */
8 8
9 TzTools::make(); 9 namespace Tz\WordPress\Tools;
10 10
11 class TzTools { 11 use \ReflectionClass, \ReflectionMethod;
12 public static function make() { 12 use \Exception;
13 spl_autoload_register(Array(__CLASS__, 'autoloader'));
14 13
15 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wp_functions.php'); 14 spl_autoload_register(__NAMESPACE__ . '\autoloader');
16 15
17 _register_script('addEvent', self::tools_url('scripts/addEvent.js', __FILE__)); 16 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'wp_functions.php');
18 _register_script('xmlhttpHandler', self::tools_url('scripts/xmlhttpHandler.js', __FILE__));
19 _register_script('fireEvent', self::tools_url('scripts/fireEvent.js', __FILE__));
20 17
21 // This is (hopefully) getting canned in 3.0 18 _register_script('addEvent', url('scripts/addEvent.js', __FILE__));
22 add_action('widgets_init', Array('MenuWidget', 'init')); 19 _register_script('xmlhttpHandler', url('scripts/xmlhttpHandler.js', __FILE__));
20 _register_script('fireEvent', url('scripts/fireEvent.js', __FILE__));
23 21
24 self::import('ShortCodes'); 22 import('ShortCodes');
25 if (defined('TZ_DEBUG') && TZ_DEBUG === true) { 23 if (defined('TZ_DEBUG') && TZ_DEBUG === true) {
26 self::import('Debug'); 24 import('Debug');
27 }
28 } 25 }
29 26
30 public static function import($com) { 27 function import($com) {
31 $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'com' . DIRECTORY_SEPARATOR . $com . DIRECTORY_SEPARATOR; 28 $dir = __DIR__ . DIRECTORY_SEPARATOR . 'com' . DIRECTORY_SEPARATOR . $com . DIRECTORY_SEPARATOR;
32 $file = $dir . $com . '.php'; 29 $file = $dir . $com . '.php';
33 if (is_dir($dir) && is_file($file)) { 30 if (is_dir($dir) && is_file($file)) {
34 require_once($file); 31 require_once($file);
35 } 32 }
36 } 33 }
34
35 function autoloader($class) {
36
37 $a = explode('\\', $class);
38 $class = array_pop($a);
37 39
38 public static function autoloader($class) { 40 $file = __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . $class . '.php';
39 $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . $class . '.php';
40 if (is_file($file)) { 41 if (is_file($file)) {
41 include($file); 42 include($file);
42 } 43 }
43 } 44 }
44 45
45 public static function tools_url($script, $base_file = false) { 46 function url($script, $base_file = false) {
46 $base_dir = (false === $base_file ? dirname(__FILE__) : dirname($base_file)); 47 $base_dir = (false === $base_file ? __DIR__ : dirname($base_file));
47 $rel_path = str_replace(ABSPATH, '', $base_dir); 48 $rel_path = str_replace(ABSPATH, '', $base_dir);
48 $script = site_url() . '/' . $rel_path . '/' . $script; 49 $script = site_url() . '/' . $rel_path . '/' . $script;
49 50
50 return $script; 51 return $script;
51 } 52 }
53
54 function tools_url() {
55 $args = func_get_args();
56 call_user_func_array(__NAMESPACE__ . '\url', $args);
52 } 57 }
53 58
54 function add_actions($class) { 59 function add_actions($class) {
......
1 <?php 1 <?php
2
2 /** 3 /**
3 * WordPress strongly advises against using functions that start with "wp_" 4 * WordPress strongly advises against using functions that start with "wp_"
4 * as they are reserved for the core of WordPress and can change with any 5 * as they are reserved for the core of WordPress and can change with any
......