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';
22 * Attempts to login the user
23 * @param {String} $username
24 * @param {String} $password
25 * @param {Boolean} $remember
26 * @returns WP_User instance
27 * @throws LogicException If headers have already been passed
28 * @throws InvalidArgumentException If the authentication is invalid
29 */
30 public static function login($username, $password, $remember = true) {
31 if (headers_sent()) {
32 throw new LogicException('Unable to login because headers have been sent');
33 }
34 14
35 $auth = _signon(Array( 15 /**
36 'user_login' => esc_sql($username) 16 * Attempts to login the user
37 , 'user_password' => esc_sql($password) 17 * @param {String} $username
38 , 'remember' => $remember 18 * @param {String} $password
39 )); 19 * @param {Boolean} $remember
20 * @returns WP_User instance
21 * @throws LogicException If headers have already been passed
22 * @throws InvalidArgumentException If the authentication is invalid
23 */
24 function login($username, $password, $remember = true) {
25 if (headers_sent()) {
26 throw new LogicException('Unable to login because headers have been sent');
27 }
40 28
41 $ref = new ReflectionObject($auth); 29 $auth = _signon(Array(
42 if ($ref->name == 'WP_User') { 30 'user_login' => esc_sql($username)
43 return $auth; 31 , 'user_password' => esc_sql($password)
44 } 32 , 'remember' => $remember
33 ));
45 34
46 throw new InvalidArgumentException('Invalid username/password'); 35 if (get_class($auth) == 'WP_User') {
47 //$auth->get_error_message()); this would be nice except it links to a wp-page 36 return $auth;
48 } 37 }
49 38
50 /** 39 throw new InvalidArgumentException('Invalid username/password');
51 * Attempts to log the user out 40 //$auth->get_error_message()); this would be nice except it links to a wp-page
52 * @returns Boolean 41 }
53 * @throws LogicException If HTTP headers have already been sent
54 */
55 public static function logout() {
56 if (headers_sent()) {
57 throw new LogicException('Unable to logout because headers have been sent');
58 }
59
60 _logout();
61 42
62 return true; 43 /**
44 * Attempts to log the user out
45 * @returns Boolean
46 * @throws LogicException If HTTP headers have already been sent
47 */
48 function logout() {
49 if (headers_sent()) {
50 throw new LogicException('Unable to logout because headers have been sent');
63 } 51 }
64 52
65 public static function register($user_data = Array(), $registration_method) { 53 _logout();
66 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php');
67
68 $valid = new Auth_Validation($user_data);
69 if (count($valid->errors) > 0) {
70 throw new BadMethodCallException(implode("\n", $valid->errors));
71 }
72 54
73 array_filter($user_data, 'esc_sql'); 55 return true;
74 $id = (int)_insert_user($user_data); 56 }
75 57
76 global $wpdb; 58 function register($user_data = Array(), $registration_method) {
77 $wpdb->query("UPDATE `{$wpdb->users}` SET `user_status` = 1 WHERE `ID` = {$id}"); 59 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php');
78 60
79 return $id; 61 $valid = new Validation($user_data);
62 if (count($valid->errors) > 0) {
63 throw new BadMethodCallException(implode("\n", $valid->errors));
80 } 64 }
81 65
82 public static function activate($username, $activation_key) { 66 array_filter($user_data, 'esc_sql');
83 do_action(self::ACTION_ACTIVATE, $user_id); 67 $id = (int)_insert_user($user_data);
84 }
85 68
86 public static function forgot_password($username, $forgot_method) { 69 global $wpdb;
87 70 $wpdb->query("UPDATE `{$wpdb->users}` SET `user_status` = 1 WHERE `ID` = {$id}");
88 } 71
72 return $id;
73 }
74
75 function activate($username, $activation_key) {
76 do_action(ACTION_ACTIVATE, $user_id);
77 }
78
79 function forgot_password($username, $forgot_method) {
80
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 {
3 const CAPABILITY = 'edit_client_settings';
4 const ADMIN_PAGE = 'client-settings';
5 2
6 public static function make() { 3 namespace Tz\WordPress\Tools\ClientSettings;
7 static $made = false;
8 if ($made) {
9 throw new OverflowException('ClientSettings has already been initialized');
10 }
11 $made = true;
12 4
13 $role = get_role('administrator'); 5 use Tz\WordPress\Tools;
14 $role->add_cap(self::CAPABILITY);
15 6
16 add_actions('ClientSettings_Actions'); 7 const CAPABILITY = 'edit_client_settings';
17 } 8 const ADMIN_PAGE = 'client-settings';
18 9
19 public static function viewOptionsPage() { 10 $role = get_role('administrator');
20 } 11 $role->add_cap(CAPABILITY);
12
13 Tools\add_actions(__NAMESPACE__ . '\Actions');
14
15 function viewOptionsPage() {
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');
8 }
9 4
10 public static function registerClass($class) { 5 use Tz\WordPress\Tools;
11 if (!class_exists($class)) {
12 throw new Exception("$class does not exist");
13 }
14 6
15 $ref = new ReflectionClass($class); 7 use \ReflectionClass, \ReflectionMethod, \ReflectionFunction;
16 $methods = $ref->getMethods(ReflectionMethod::IS_STATIC); 8 use \Exception;
17 foreach ($methods as $method) {
18 self::add($method->name, Array($class, $method->name));
19 }
20 }
21 9
22 public static function add($code, $callback) { 10 Tools\add_actions(__NAMESPACE__ . '\Actions');
23 $fn = (function_exists('wp_add_shortcode') ? 'wp_add_shortcode' : 'add_shortcode');
24 call_user_func($fn, $code, $callback);
25 11
26 if (is_admin()) { 12 if (function_exists('rename_function')) {
27 self::$registered[$code] = Array('code' => $code, 'title' => $code, 'params' => Array(), 'uses_content' => 0); 13 rename_function('add_shortcode', 'wp_add_shortcode');
28 14
29 if (is_array($callback)) { 15 function add_shortcode() {
30 $ref = new ReflectionMethod($callback[0], $callback[1]); 16 $args = func_get_args();
31 } else { 17 call_user_func_array('add', $args);
32 $ref = new ReflectionFunction($callback);
33 }
34 $api = $ref->getDocComment();
35 $api = explode("\n", $api);
36 array_shift($api);
37 array_pop($api);
38
39 foreach ($api as $key => &$comment) {
40 $comment = trim($comment, ' *');
41
42 if (substr($comment, 0, 1) == '@') {
43 $tag = trim(substr($comment, 1, strpos($comment, ' ')));
44 if (empty($tag)) {
45 $tag = trim($comment, '@');
46 }
47
48 if (method_exists(__CLASS__, 'parseTag_' . $tag)) {
49 call_user_func_array(Array(__CLASS__, 'parseTag_' . $tag), Array($code, $comment));
50 }
51 }
52 }
53 } 18 }
54 } 19 }
55 20
56 public static function parseTag_display($code, $string) { 21 function add_shortcodes($class) {
57 $string = trim(str_replace('@display', '', $string)); 22 if (!class_exists($class)) {
58 self::$registered[$code]['title'] = $string; 23 throw new Exception("$class does not exist");
59 } 24 }
60 25
61 public static function parseTag_param($code, $string) { 26 $ref = new ReflectionClass($class);
62 $regex = '.*?@param {((?:[a-z][a-z]+))(\\(.*?\\))?} (.*?) (.*?)$'; // Awww yeah! 27 $methods = $ref->getMethods(ReflectionMethod::IS_STATIC);
63 if ($num = preg_match_all("/" . $regex . "/is", $string, $matches)) { 28 foreach ($methods as $method) {
64 self::$registered[$code]['params'][] = Array('name' => $matches[3][0], 'type' => $matches[1][0], 'options' => explode(',', trim($matches[2][0], ')(')), 'desc' => $matches[4][0]); 29 add($method->name, Array($class, $method->name));
65 }
66 } 30 }
31 }
32
33 function registerClass($class) {
34 call_user_func('add_shortcodes', $class);
35 }
36
37 function add($code, $callback) {
38 $fn = (function_exists('wp_add_shortcode') ? 'wp_add_shortcode' : 'add_shortcode');
39 call_user_func($fn, $code, $callback);
40
41 if (is_admin()) { // I may want to remove this condition...
42 Vars::$registered[$code] = Array('code' => $code, 'title' => $code, 'params' => Array(), 'uses_content' => 0);
67 43
68 public static function parseTag_private($code, $string) { 44 if (is_array($callback)) {
69 self::$private[$code] = 1; 45 $ref = new ReflectionMethod($callback[0], $callback[1]);
46 } else {
47 $ref = new ReflectionFunction($callback);
48 }
49 $api = $ref->getDocComment();
50 $api = explode("\n", $api);
51 array_shift($api);
52 array_pop($api);
53
54 foreach ($api as $key => &$comment) {
55 $comment = trim($comment, ' *');
56
57 if (substr($comment, 0, 1) == '@') {
58 $tag = trim(substr($comment, 1, strpos($comment, ' ')));
59 if (empty($tag)) {
60 $tag = trim($comment, '@');
61 }
62
63 if (function_exists('parseTag_' . $tag)) {
64 call_user_func_array('parseTag_' . $tag, Array($code, $comment));
65 }
66 }
67 }
70 } 68 }
69 }
70
71 function parseTag_display($code, $string) {
72 $string = trim(str_replace('@display', '', $string));
73 Vars::$registered[$code]['title'] = $string;
74 }
71 75
72 public static function uses_content($code) { 76 function parseTag_param($code, $string) {
73 self::$registered[$code]['uses_content'] = 1; 77 $regex = '.*?@param {((?:[a-z][a-z]+))(\\(.*?\\))?} (.*?) (.*?)$'; // Awww yeah!
78 if ($num = preg_match_all("/" . $regex . "/is", $string, $matches)) {
79 Vars::$registered[$code]['params'][] = Array('name' => $matches[3][0], 'type' => $matches[1][0], 'options' => explode(',', trim($matches[2][0], ')(')), 'desc' => $matches[4][0]);
74 } 80 }
81 }
75 82
76 public static function getRegistered() { 83 function parseTag_private($code, $string) {
77 $return = self::$registered; 84 Vars::$private[$code] = 1;
78 foreach (self::$private as $key => $one) { 85 }
79 unset($return[$key]); 86
80 } 87 function uses_content($code) {
88 Vars::$registered[$code]['uses_content'] = 1;
89 }
81 90
82 return $return; 91 function getRegistered() {
92 $return = Vars::$registered;
93 foreach (Vars::$private as $key => $one) {
94 unset($return[$key]);
83 } 95 }
84 96
85 public static function drawMetaBox() { 97 return $return;
98 }
99
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
...@@ -42,4 +47,4 @@ abstract class Validation { ...@@ -42,4 +47,4 @@ abstract class Validation {
42 } 47 }
43 } 48 }
44 } 49 }
45 ?> 50 ?>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -62,4 +62,4 @@ echo "Here\n"; ...@@ -62,4 +62,4 @@ echo "Here\n";
62 print_r($this->_data); 62 print_r($this->_data);
63 } 63 }
64 } 64 }
65 ?> 65 ?>
...\ No newline at end of file ...\ No newline at end of file
......
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 }
36 } 32 }
33 }
37 34
38 public static function autoloader($class) { 35 function autoloader($class) {
39 $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . $class . '.php';
40 if (is_file($file)) {
41 include($file);
42 }
43 }
44 36
45 public static function tools_url($script, $base_file = false) { 37 $a = explode('\\', $class);
46 $base_dir = (false === $base_file ? dirname(__FILE__) : dirname($base_file)); 38 $class = array_pop($a);
47 $rel_path = str_replace(ABSPATH, '', $base_dir);
48 $script = site_url() . '/' . $rel_path . '/' . $script;
49 39
50 return $script; 40 $file = __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . $class . '.php';
41 if (is_file($file)) {
42 include($file);
51 } 43 }
52 } 44 }
53 45
46 function url($script, $base_file = false) {
47 $base_dir = (false === $base_file ? __DIR__ : dirname($base_file));
48 $rel_path = str_replace(ABSPATH, '', $base_dir);
49 $script = site_url() . '/' . $rel_path . '/' . $script;
50
51 return $script;
52 }
53
54 function tools_url() {
55 $args = func_get_args();
56 call_user_func_array(__NAMESPACE__ . '\url', $args);
57 }
58
54 function add_actions($class) { 59 function add_actions($class) {
55 if (!class_exists($class)) { 60 if (!class_exists($class)) {
56 throw new Exception("$class does not exist"); 61 throw new Exception("$class does not exist");
......
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
......