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
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
......