Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
db8c6f69
authored
2010-06-02 15:45:53 +0000
by
Chris Boden
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Promoted changes/fixes to 0.2 for Echologics launch (23:31)
1 parent
c0593fe0
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
144 additions
and
97 deletions
com/Auth/Auth.php
com/Branding/Branding.php
com/Branding/views/header.php
com/PagePermissions/PagePermissions.php
com/PagePermissions/views/form.php
com/ShortCodes/ShortCodes.php
lib/MenuWidget.php
lib/Validation.php
lib/WP_Option.php
addEvent.js → scripts/addEvent.js
fireEvent.js → scripts/fireEvent.js
xmlhttpHandler.js → scripts/xmlhttpHandler.js
tz-tools.php
wp_functions.php
com/Auth/Auth.php
View file @
db8c6f6
...
...
@@ -33,7 +33,7 @@ class Auth {
}
$auth
=
_signon
(
Array
(
'user_login'
=>
$username
'user_login'
=>
esc_sql
(
$username
)
,
'user_password'
=>
esc_sql
(
$password
)
,
'remember'
=>
$remember
));
...
...
@@ -63,9 +63,23 @@ class Auth {
}
public
static
function
register
(
$user_data
=
Array
(),
$registration_method
)
{
require_once
(
ABSPATH
.
WPINC
.
DIRECTORY_SEPARATOR
.
'registration.php'
);
$valid
=
new
Auth_Validation
(
$user_data
);
if
(
count
(
$valid
->
errors
)
>
0
)
{
throw
new
BadMethodCallException
(
implode
(
"
\n
"
,
$valid
->
errors
));
}
public
static
function
activate
()
{
array_filter
(
$user_data
,
'esc_sql'
);
$id
=
(
int
)
_insert_user
(
$user_data
);
global
$wpdb
;
$wpdb
->
query
(
"UPDATE `
{
$wpdb
->
users
}
` SET `user_status` = 1 WHERE `ID` =
{
$id
}
"
);
return
$id
;
}
public
static
function
activate
(
$username
,
$activation_key
)
{
do_action
(
self
::
ACTION_ACTIVATE
,
$user_id
);
}
...
...
@@ -74,64 +88,49 @@ class Auth {
}
}
class
Auth_Validation
{
public
static
$errors
=
Array
();
class
Auth_Validation
extends
Validation
{
/**
* @rule Not blank
* @rule Valid WordPress username
* @returns Boolean
*/
p
ublic
static
function
username
(
$val
)
{
p
rotected
function
username
(
$val
)
{
if
(
empty
(
$val
))
{
self
::
$errors
[]
=
'Username is blank'
;
return
false
;
throw
new
Exception
(
'Username is blank'
);
}
require_once
(
ABSPATH
.
WPINC
.
DIRECTORY_SEPARATOR
.
'registration.php'
);
if
(
!
validate_username
(
$val
))
{
self
::
$errors
[]
=
'Username must be at least 4 characters, letters and numbers only'
;
return
false
;
throw
new
Exception
(
'Username must be at least 4 characters, letters and numbers only'
);
}
if
(
username_exists
(
$_POST
[
'reg_username'
]))
{
self
::
$errors
[]
=
'Username already exists'
;
return
false
;
throw
new
Exception
(
'Username already exists'
);
}
return
true
;
}
/**
* @rule Not blank
* @returns Boolean
*/
p
ublic
static
function
password
(
$val
)
{
p
rotected
function
password
(
$val
)
{
if
(
empty
(
$val
))
{
self
::
$errors
[]
=
'Password can not be blank'
;
return
false
;
throw
new
Exception
(
'Password can not be blank'
);
}
self
::
$pass_check
=
$val
;
return
true
;
}
/**
* @rule Valid email address (*@*.*)
* @returns Boolean
*/
p
ublic
static
function
email
(
$val
)
{
p
rotected
function
email
(
$val
)
{
if
(
!
(
boolean
)
filter_var
(
$val
,
FILTER_VALIDATE_EMAIL
))
{
self
::
$errors
[]
=
'Invalid email address'
;
return
false
;
throw
new
Exception
(
'Invalid email address'
);
}
if
(
false
!==
email_exists
(
$val
))
{
self
::
$errors
[]
=
'Email address already registered'
;
return
false
;
throw
new
Exception
(
'Email address already registered'
);
}
return
true
;
}
}
?>
\ No newline at end of file
...
...
com/Branding/Branding.php
View file @
db8c6f6
...
...
@@ -7,7 +7,7 @@ class Branding {
class
Branding_Actions
{
public
static
function
admin_print_styles
()
{
_enqueue_style
(
'branding-style'
,
plugin
s_url
(
'css/tenzing.css'
,
__FILE__
));
_enqueue_style
(
'branding-style'
,
TzTools
::
tool
s_url
(
'css/tenzing.css'
,
__FILE__
));
}
public
static
function
admin_head
()
{
...
...
@@ -22,7 +22,7 @@ class Branding_Actions {
}
public
static
function
login_head
()
{
echo
'<link rel="stylesheet" type="text/css" href="'
.
plugin
s_url
(
'css/tz_login.css'
,
__FILE__
)
.
'" />'
;
echo
'<link rel="stylesheet" type="text/css" href="'
.
TzTools
::
tool
s_url
(
'css/tz_login.css'
,
__FILE__
)
.
'" />'
;
}
}
...
...
com/Branding/views/header.php
View file @
db8c6f6
...
...
@@ -8,6 +8,8 @@
}
else
{
echo
(
$current_user
->
user_login
);
}
?>
</a>
|
<a
href=
"
<?php
echo
wp_logout_url
();
?>
"
>
Log Out
</a>
?>
</a>
|
<a
href=
"
<?php
echo
get_settings
(
'siteurl'
);
?>
"
>
Home
</a>
|
<a
href=
"
<?php
echo
_logout_url
();
?>
"
>
Log Out
</a>
</div>
</div>
\ No newline at end of file
...
...
com/PagePermissions/PagePermissions.php
View file @
db8c6f6
...
...
@@ -70,7 +70,7 @@ class PagePermissions {
}
// Meta value hasn't been set, getting settings defaults
if
(
''
===
$data
=
get_custom_data
(
self
::
META
,
$post_id
))
{
if
(
NULL
===
$data
=
array_shift
(
get_post_meta
(
$post_id
,
self
::
META
)
))
{
$data
=
Array
(
self
::
ELE_SEL
=>
$settings
[
self
::
ELE_SEL
],
self
::
ELE_CUST
=>
$settings
[
self
::
ELE_CUST
]);
}
...
...
@@ -201,10 +201,10 @@ class PagePermissionsAdmin {
}
public
static
function
viewMetaBox
(
$post
,
$box_info
)
{
$selected
=
(
$post
->
ID
==
0
?
self
::
getOptions
()
:
get_custom_data
(
PagePermissions
::
META
,
$post
->
ID
));
$selected
=
(
$post
->
ID
==
0
?
self
::
getOptions
()
:
array_shift
(
get_post_meta
(
$post
->
ID
,
PagePermissions
::
META
)
));
// If the post doesn't have the field saved get defaults
if
(
empty
(
$selected
))
{
if
(
is_null
(
$selected
))
{
$selected
=
self
::
getOptions
();
}
...
...
@@ -262,6 +262,27 @@ class PagePermissions_Actions {
if
(
$file
==
'/wp-admin/media-new.php'
&&
!
PagePermissions
::
is_admin
())
{
header
(
"Location: "
.
$file
.
"?flash=0"
);
}
// This is hackey, but WP does't have hooks for this for some reason...
// Ideally this is in its own `edit_attachment` method...but that isn't working
if
(
isset
(
$_POST
[
'action'
])
&&
$_POST
[
'action'
]
==
'editattachment'
)
{
$real_id
=
$_POST
[
'attachment_id'
];
$current
=
array_shift
(
get_post_meta
(
$real_id
,
PagePermissions
::
META
));
$new
=
Array
();
$new
[
PagePermissions
::
ELE_SEL
]
=
$_POST
[
PagePermissions
::
ELE_SEL
];
if
(
isset
(
$_POST
[
PagePermissions
::
ELE_CUST
]))
{
$new
[
PagePermissions
::
ELE_CUST
]
=
$_POST
[
PagePermissions
::
ELE_CUST
];
}
else
{
$new
[
PagePermissions
::
ELE_CUST
]
=
Array
();
}
if
(
is_null
(
$current
))
{
add_post_meta
(
$real_id
,
PagePermissions
::
META
,
$new
,
true
);
}
else
{
update_post_meta
(
$real_id
,
PagePermissions
::
META
,
$new
);
}
}
}
public
static
function
admin_menu
()
{
...
...
@@ -274,8 +295,8 @@ class PagePermissions_Actions {
public
static
function
admin_print_scripts
()
{
$innerhtml
=
''
;
if
(
'0'
!==
(
$change_field
=
(
isset
(
$_GET
[
'attachment_id'
])
?
'attachments['
.
$_GET
[
'attachment_id'
]
.
']['
.
PagePermissions
::
META
.
']'
:
'0'
)))
{
$selected
=
get_custom_data
(
PagePermissions
::
META
,
$_GET
[
'attachment_id'
]
);
if
(
empty
(
$selected
))
{
$selected
=
array_shift
(
get_post_meta
(
$_GET
[
'attachment_id'
],
PagePermissions
::
META
)
);
if
(
is_null
(
$selected
))
{
$selected
=
PagePermissionsAdmin
::
getOptions
();
}
...
...
@@ -285,16 +306,13 @@ class PagePermissions_Actions {
ob_end_clean
();
}
_enqueue_script
(
'page-permissions'
,
plugin
s_url
(
'PagePermissions.js'
,
__FILE__
));
_enqueue_script
(
'page-permissions'
,
TzTools
::
tool
s_url
(
'PagePermissions.js'
,
__FILE__
));
_localize_script
(
'page-permissions'
,
'TzPagePermissionsData'
,
Array
(
'trigger'
=>
PagePermissions
::
ELE_SEL
,
'focus'
=>
PagePermissions
::
OPT_CUST
,
'change_field'
=>
$change_field
,
'innerHTML'
=>
rawurlencode
(
$innerhtml
)
));
//attachments[304][accessible_to_roles]
//a:2:{s:14:"general_access";s:1:"1";s:5:"roles";a:1:{s:6:"editor";s:1:"1";}}
}
public
static
function
save_post
(
$post_id
)
{
...
...
@@ -305,7 +323,7 @@ class PagePermissions_Actions {
if
(
false
===
(
$real_id
=
_is_post_revision
(
$post_id
)))
{
$real_id
=
$post_id
;
}
$current
=
get_custom_data
(
PagePermissions
::
META
,
$real_id
);
$current
=
array_shift
(
get_post_meta
(
$real_id
,
PagePermissions
::
META
)
);
$new
=
Array
();
$new
[
PagePermissions
::
ELE_SEL
]
=
$_POST
[
PagePermissions
::
ELE_SEL
];
...
...
@@ -315,7 +333,7 @@ class PagePermissions_Actions {
$new
[
PagePermissions
::
ELE_CUST
]
=
Array
();
}
if
(
empty
(
$current
))
{
if
(
is_null
(
$current
))
{
add_post_meta
(
$real_id
,
PagePermissions
::
META
,
$new
,
true
);
}
else
{
update_post_meta
(
$real_id
,
PagePermissions
::
META
,
$new
);
...
...
com/PagePermissions/views/form.php
View file @
db8c6f6
com/ShortCodes/ShortCodes.php
View file @
db8c6f6
...
...
@@ -110,7 +110,7 @@ class ShortCodes_Actions {
public
static
function
admin_print_scripts
()
{
if
(
$GLOBALS
[
'editing'
])
{
_enqueue_script
(
'shortcoder'
,
plugin
s_url
(
'shortcoder.js'
,
__FILE__
),
Array
(
'jquery'
));
_enqueue_script
(
'shortcoder'
,
TzTools
::
tool
s_url
(
'shortcoder.js'
,
__FILE__
),
Array
(
'jquery'
));
echo
"<script type=
\"
text/javascript
\"
>
\n
/* <![CDATA[ */
\n
"
;
echo
'var TzRegisteredShortCodes = '
.
json_encode
(
ShortCodes
::
getRegistered
());
...
...
lib/MenuWidget.php
View file @
db8c6f6
...
...
@@ -4,7 +4,7 @@ class MenuWidget extends WP_Widget {
register_widget
(
__CLASS__
);
if
(
is_admin
())
{
_enqueue_script
(
'tz-menu-widget'
,
plugin
s_url
(
'MenuWidget.js'
,
__FILE__
),
Array
(
'addEvent'
));
_enqueue_script
(
'tz-menu-widget'
,
TzTools
::
tool
s_url
(
'MenuWidget.js'
,
__FILE__
),
Array
(
'addEvent'
));
}
}
...
...
lib/Validation.php
0 → 100644
View file @
db8c6f6
<?php
abstract
class
Validation
{
/**
* Associative array of valid fields
* @type Array
* @public
* @read-only
*/
private
$valid
=
Array
();
/**
* Associative array if invalid fields
* @type Array
* @public
* @read-only
*/
private
$errors
=
Array
();
/**
* @param {Array} $data Associative array of data to validate
*/
final
public
function
__construct
(
Array
$data
)
{
foreach
(
$data
as
$key
=>
$val
)
{
if
(
method_exists
(
$this
,
$key
))
{
try
{
call_user_func
(
Array
(
$this
,
$key
),
$val
);
$this
->
valid
[
$key
]
=
$val
;
}
catch
(
Exception
$e
)
{
$this
->
errors
[
$key
]
=
$e
->
getMessage
();
}
}
}
}
/**
* @private
*/
final
public
function
__get
(
$key
)
{
$private
=
$key
;
if
(
isset
(
$this
->
$private
))
{
return
$this
->
$private
;
}
}
}
?>
lib/WP_Option.php
View file @
db8c6f6
...
...
@@ -11,17 +11,20 @@ class WP_Option implements ArrayAccess, Countable {
$this
->
_ns
=
$ns
;
$this
->
_data
=
get_option
(
$ns
);
$changed
=
false
;
if
(
is_array
(
$defaults
))
{
foreach
(
$this
->
_data
as
$key
=>
$val
)
{
$defaults
[
$key
]
=
$val
;
foreach
(
$defaults
as
$key
=>
$val
)
{
if
(
!
isset
(
$this
->
_data
[
$key
]))
{
$this
->
_data
[
$key
]
=
$val
;
$changed
=
true
;
}
}
}
if
(
$this
->
_data
!=
$defaults
)
{
$this
->
_data
=
$defaults
;
if
(
$changed
)
{
$this
->
save
();
}
}
}
public
function
offsetExists
(
$var
)
{
return
(
isset
(
$this
->
_data
[
$var
])
?
true
:
false
);
...
...
addEvent.js
→
scripts/
addEvent.js
View file @
db8c6f6
File moved
fireEvent.js
→
scripts/
fireEvent.js
View file @
db8c6f6
File moved
xmlhttpHandler.js
→
scripts/
xmlhttpHandler.js
View file @
db8c6f6
File moved
tz-tools.php
View file @
db8c6f6
...
...
@@ -2,28 +2,28 @@
/*
Plugin Name: Tenzing Tools
Version: 0.2
Description: Various classes to help out with stuff
Author: Tenzing
Description: Various classes and functions to help out with stuff
*/
if
(
version_compare
(
PHP_VERSION
,
'5.2.2'
)
!==
1
)
{
die
(
'PHP version 5.2.2 or greater is required'
);
}
TzTools
::
load
();
TzTools
::
make
();
class
TzTools
{
public
static
function
load
()
{
public
static
function
make
()
{
spl_autoload_register
(
Array
(
__CLASS__
,
'autoloader'
));
require_once
(
dirname
(
__FILE__
)
.
DIRECTORY_SEPARATOR
.
'wp_functions.php'
);
_register_script
(
'addEvent'
,
plugins_url
(
'
addEvent.js'
,
__FILE__
));
_register_script
(
'xmlhttpHandler'
,
plugins_url
(
'
xmlhttpHandler.js'
,
__FILE__
));
_register_script
(
'fireEvent'
,
plugins_url
(
'
fireEvent.js'
,
__FILE__
));
_register_script
(
'addEvent'
,
self
::
tools_url
(
'scripts/
addEvent.js'
,
__FILE__
));
_register_script
(
'xmlhttpHandler'
,
self
::
tools_url
(
'scripts/
xmlhttpHandler.js'
,
__FILE__
));
_register_script
(
'fireEvent'
,
self
::
tools_url
(
'scripts/
fireEvent.js'
,
__FILE__
));
// This is (hopefully) getting canned in 3.0
add_action
(
'widgets_init'
,
Array
(
'MenuWidget'
,
'init'
));
self
::
import
(
'ShortCodes'
);
if
(
defined
(
'TZ_DEBUG'
)
&&
TZ_DEBUG
===
true
)
{
self
::
import
(
'Debug'
);
}
}
public
static
function
import
(
$com
)
{
...
...
@@ -40,6 +40,14 @@ class TzTools {
include
(
$file
);
}
}
public
static
function
tools_url
(
$script
,
$base_file
=
false
)
{
$base_dir
=
(
false
===
$base_file
?
dirname
(
__FILE__
)
:
dirname
(
$base_file
));
$rel_path
=
str_replace
(
ABSPATH
,
''
,
$base_dir
);
$script
=
site_url
()
.
'/'
.
$rel_path
.
'/'
.
$script
;
return
$script
;
}
}
function
add_actions
(
$class
)
{
...
...
@@ -65,42 +73,4 @@ function add_filters($class) {
add_filter
(
$method
->
name
,
Array
(
$class
,
$method
->
name
));
}
}
function
get_custom_data
(
$name
,
$post_id
=
false
)
{
if
(
false
===
$type
=
get_post_type
(
$post_id
))
{
throw
new
InvalidArgumentException
(
"Post
{
$post_id
}
does not exist"
);
}
$raw_data
=
call_user_func_array
(
"_custom_
{
$type
}
"
,
Array
(
$post_id
,
$name
));
if
(
null
===
$raw_data
)
{
return
''
;
}
return
$raw_data
;
}
function
_custom_attachment
(
$post_id
,
$custom_name
)
{
if
(
false
===
(
$tax_object
=
get_the_terms
(
$post_id
,
$custom_name
)))
{
return
''
;
}
$tax_data
=
array_shift
(
$tax_object
);
return
$tax_data
->
name
;
}
function
_custom_page
(
$post_id
,
$custom_name
)
{
$custom
=
get_post_meta
(
$post_id
,
$custom_name
);
return
array_shift
(
$custom
);
}
function
_custom_post
()
{
$args
=
func_get_args
();
return
call_user_func_array
(
'_custom_page'
,
$args
);
}
function
_custom_revision
()
{
$args
=
func_get_args
();
return
call_user_func_array
(
'_custom_page'
,
$args
);
}
?>
...
...
wp_functions.php
View file @
db8c6f6
...
...
@@ -149,4 +149,14 @@ function _update_user() {
$params
=
func_get_args
();
return
call_user_func_array
(
'wp'
.
__FUNCTION__
,
$params
);
}
function
_make_link_relative
()
{
$params
=
func_get_args
();
return
call_user_func_array
(
'wp'
.
__FUNCTION__
,
$params
);
}
function
_logout_url
()
{
$params
=
func_get_args
();
return
call_user_func_array
(
'wp'
.
__FUNCTION__
,
$params
);
}
?>
...
...
Please
register
or
sign in
to post a comment