Review readme.md for commit log at this stage.

This commit is contained in:
Jay Wood
2014-11-09 13:18:03 -05:00
parent 1fd0624928
commit dff22f705e
8 changed files with 193 additions and 169 deletions

View File

@ -60,6 +60,13 @@ Please do not contact me with questions like this. If you cannot be descriptive
## Changelog
### 3.6.0
* Split methods and hooks from main class file, will prevent overhead.
* Moved to use of cookie.js
* Created API file for methods.
* New filters & actions for developers
* Switched CSS priority, to allow custom css to override bg image and opacity
### 3.5.5
* [jgraup](https://github.com/jgraup) - Fixed Menu Positioning
* BUGFIX - Fixed Enter/Exit URLs not being respected.

97
class/admin.class.php Normal file
View File

@ -0,0 +1,97 @@
<?php
class CWV3Admin {
function hooks(){
// Post Meta Box for this.
add_action( 'add_meta_boxes', array( $this, 'cw_meta' ) );
add_action( 'save_post', array( $this, 'cwv3_meta_save' ) );
add_action( 'admin_head', array( $this, 'render_lazy_mans_css' ) );
// Post column filters
add_filter( 'manage_page_posts_columns', array( $this, 'post_cols' ) );
add_filter( 'manage_post_posts_columns', array( $this, 'post_cols' ) );
// Post column info
add_action( 'manage_posts_custom_column', array( $this, 'set_col_data' ) );
add_action( 'manage_pages_custom_column', array( $this, 'set_col_data' ) );
}
public function render_lazy_mans_css() {
echo '<style type="text/css">th#cwv2{width: 32px; text-align:center;} td.column-cwv2{text-align:center;}</style>';
}
public function set_col_data( $col ) {
global $post;
$sw = get_option( 'cwv3_sitewide' );
switch ( $col ) {
case 'cwv2':
if ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) || 'enabled' == $sw[0] ) {
echo '<span style="color:#0F0; font-weight:bold;" class="cw_protected">Yes</span>';
}else {
echo '<span style="color:#F00; font-weight:bold;" class="cw_vulnerable">No</span>';
}
break;
}
}
public function post_cols( $cols ) {
return array_slice( $cols, 0, 1, true ) + array( 'cwv2' => 'CW' ) + array_slice( $cols, 1, count( $array ) - 1, true );
}
public function cw_meta() {
$scr = array( 'post', 'page' );
foreach ( $scr as $screen ) {
add_meta_box( 'cwv3_meta_section',
__( 'CWV3 Security', 'cwv3' ),
array( $this, 'render_metabox' ),
$screen,
'side',
'high'
);
}
}
public function cwv3_meta_save( $post_id ) {
// check isset before access (edit by @jgraup)
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ){
if ( ! current_user_can( 'edit_page', $post_id ) ){
return;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) { return; }
if ( ! isset( $_POST['cwv3_meta'] ) || ! wp_verify_nonce( $_POST['cwv3_meta'], plugin_basename( __FILE__ ) ) ) { return; }
}
}
// check isset before access (edit by @jgraup)
if ( isset( $_POST['cwv3_auth'] ) ){
$mydata = sanitize_text_field( $_POST['cwv3_auth'] );
update_post_meta( $post_id, 'cwv3_auth', $mydata );
}
}
public function render_metabox( $post ) {
wp_nonce_field( plugin_basename( __FILE__ ), 'cwv3_meta' );
$curval = get_post_meta( $post->ID, 'cwv3_auth', true );
$sw = get_option( 'cwv3_sitewide' );
$disabled = $sw[0] == 'enabled' ? true : false;
?>
<label for="cwv3_auth"><?php _e( 'Use authorization for this content', 'cwv3' ); ?>:</label>
<input type="checkbox" id="cwv3_auth" name="cwv3_auth" <?php checked( 'yes', $curval, true ); ?> value="yes" <?php disabled( $disabled ); ?>/><br />
<?php if ( 'enabled' == $sw[0] ) : ?>
<p class="description"><?php _e( 'Cannot be changed while site wide option is enabled.', 'cwv3' ); ?></p>
<?php endif; ?>
<?php
}
}
$cwv3_admin = new CWV3Admin();
$cwv3_admin->hooks();

View File

@ -2,96 +2,22 @@
class CWV3 {
public function CWV3() {
// Styling and such
add_action( 'init', array( &$this, 'register_frontend_data' ) );
public function hooks(){
add_action( 'init', array( $this, 'register_frontend_data' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'load_dependancies' ) );
add_action( 'wp_footer', array( $this, 'render_dialog' ) );
// Post Meta Box for this.
add_action( 'add_meta_boxes', array( $this, 'cw_meta' ) );
add_action( 'save_post', array( $this, 'cwv3_meta_save' ) );
add_action( 'wp_head', array( $this, 'override_css' ) );
// AJAX Handle
add_action( 'wp_ajax_cwv3_ajax', array( $this, 'handle_ajax' ) );
add_action( 'wp_ajax_nopriv_cwv3_ajax', array( $this, 'handle_ajax' ) );
// Post column filters
add_filter( 'manage_page_posts_columns', array( $this, 'post_cols' ) );
add_filter( 'manage_post_posts_columns', array( $this, 'post_cols' ) );
// Post column info
add_action( 'manage_posts_custom_column', array( $this, 'set_col_data' ) );
add_action( 'manage_pages_custom_column', array( $this, 'set_col_data' ) );
add_action( 'admin_head', array( &$this, 'render_lazy_mans_css' ) );
add_action( 'wp_head', array( &$this, 'override_css' ) );
/*add_action( 'wp_ajax_cwv3_ajax', array( $this, 'handle_ajax' ) );
add_action( 'wp_ajax_nopriv_cwv3_ajax', array( $this, 'handle_ajax' ) );*/
}
public function override_css() {
cwv3_the_css();
}
public function render_lazy_mans_css() {
echo '<style type="text/css">th#cwv2{width: 32px; text-align:center;} td.column-cwv2{text-align:center;}</style>';
}
public function set_col_data( $col ) {
global $post;
$sw = get_option( 'cwv3_sitewide' );
switch ( $col ) {
case 'cwv2':
if ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) || 'enabled' == $sw[0] ) {
echo '<span style="color:#0F0; font-weight:bold;" class="cw_protected">Yes</span>';
}else {
echo '<span style="color:#F00; font-weight:bold;" class="cw_vulnerable">No</span>';
}
break;
}
}
public function post_cols( $cols ) {
return array_slice( $cols, 0, 1, true ) + array( 'cwv2' => 'CW' ) + array_slice( $cols, 1, count( $array ) - 1, true );
}
public function cw_meta() {
$scr = array( 'post', 'page' );
foreach ( $scr as $screen ) {
add_meta_box( 'cwv3_meta_section',
__( 'CWV3 Security' ),
array( &$this, 'render_metabox' ),
$screen,
'side',
'high'
);
}
}
public function cwv3_meta_save( $post_id ) {
// check isset before access (edit by @jgraup)
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ){
if ( ! current_user_can( 'edit_page', $post_id ) ){
return;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) { return; }
if ( ! isset( $_POST['cwv3_meta'] ) || ! wp_verify_nonce( $_POST['cwv3_meta'], plugin_basename( __FILE__ ) ) ) { return; }
}
}
// check isset before access (edit by @jgraup)
if ( isset( $_POST['cwv3_auth'] ) ){
$mydata = sanitize_text_field( $_POST['cwv3_auth'] );
update_post_meta( $post_id, 'cwv3_auth', $mydata );
}
}
public function handle_ajax() {
$post_id = intval( $_POST['id'] );
@ -123,29 +49,29 @@ class CWV3 {
$p_ID = ( is_front_page() ) ? -1 : ( is_attachment() ? $post->post_parent : ( is_archive() || is_search() ) ? -2 : $post->ID );
$d = get_option( 'cwv3_denial' );
wp_localize_script( 'cwv3_js', 'cwv3_params', array(
'action' => 'cwv3_ajax',
'nonce' => wp_create_nonce( 'cwv3_ajax_'.$p_ID ),
'admin_url' => admin_url( 'admin-ajax.php' ),
'id' => $p_ID,
'sd' => ( $this->check_data() == false || ( $this->check_data() == 3 && ! empty( $d ) ) ) ? true : false,
'enter' => ! empty( $elink ) ? $elink : '#',
'exit' => ! empty( $exlink ) ? $exlink : 'http://google.com',
'opacity' => get_option( 'cwv3_bg_opacity', 0.85 )
) );
'action' => 'cwv3_ajax',
'nonce' => wp_create_nonce( 'cwv3_ajax_'.$p_ID ),
'admin_url' => admin_url( 'admin-ajax.php' ),
'id' => $p_ID,
'sd' => ( $this->check_data() == false || ( $this->check_data() == 3 && ! empty( $d ) ) ) ? true : false,
'enter' => ! empty( $elink ) ? $elink : '#',
'exit' => ! empty( $exlink ) ? $exlink : 'http://google.com',
'opacity' => get_option( 'cwv3_bg_opacity', 0.85 )
) );
}
public function register_frontend_data() {
// Colorbox w/ MIT License
wp_register_style( 'colorbox', plugins_url( 'js/colorbox.1.5.10/colorbox.css', dirname( __FILE__ ) ), '', '1.4.14', 'ALL' );
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script( 'colorbox_js', plugins_url( "js/colorbox.1.5.10/jquery.colorbox{$min}.js", dirname( __FILE__ ) ), array( 'jquery' ), '1.4.14', true );
// Colorbox w/ MIT License
wp_register_style( 'colorbox', plugins_url( 'js/colorbox.1.5.10/colorbox.css', dirname( __FILE__ ) ), '', '1.5.10', 'ALL' );
wp_register_script( 'colorbox_js', plugins_url( "js/colorbox.1.5.10/jquery.colorbox{$min}.js", dirname( __FILE__ ) ), array( 'jquery' ), '1.5.10', true );
// Jquery Cookie
wp_register_script( 'jquery_cookie', plugins_url( "js/jquery_cookie{$min}.js", dirname( __FILE__ ) ), array( 'jquery' ), '1.4.1', true );
// Main data
wp_register_script( 'cwv3_js', plugins_url( "js/cwv3{$min}.js", dirname( __FILE__ ) ), array( 'colorbox_js', 'jquery_cookie' ), uniqid(), true );
wp_register_script( 'cwv3_js', plugins_url( "js/cwv3{$min}.js", dirname( __FILE__ ) ), array( 'colorbox_js', 'jquery_cookie' ), '3.6.0', true );
wp_register_style( 'cwv3_css', plugins_url( "css/cwv3{$min}.css", dirname( __FILE__ ) ), array( 'colorbox' ), '1.0' );
}
@ -276,51 +202,9 @@ class CWV3 {
}
public function render_dialog() {
$d = get_option( 'cwv3_denial' );
if ( 3 == $this->check_data() && 'enabled' == $d[0] ) {
$dtype = true;
}else {
$dtype = false;
}
$etxt = get_option( 'cwv3_enter_txt', 'Enter' );
$extxt = get_option( 'cwv3_exit_txt', 'Exit' );
$cwv3_title = ( true == $dtype ) ? get_option( 'cwv3_den_title' ) : get_option( 'cwv3_d_title' );
$cwv3_content = ( true == $dtype ) ? get_option( 'cwv3_den_msg' ) : get_option( 'cwv3_d_msg' );
?>
<!-- CWV3 Dialog -->
<div style="display: none">
<div id="cwv3_auth">
<div id="cwv3_title"><?php echo esc_attr( $title ); ?></div>
<div id="cwv3_content"><?php echo wp_kses_post( $cwv3_content ); ?></div>
<div id="cwv3_btns">
<?php if ( true !== $dtype ): ?>
<div id="cwv3_enter"><a href="<?php echo esc_url( $enter_url ); ?>" id="cw_enter_link"><?php echo esc_attr( $etxt ); ?></a></div>
<?php endif; ?>
<div id="cwv3_exit"><a href="<?php echo esc_url( $exit_url ); ?>" id="cw_exit_link"><?php echo esc_attr( $extxt ); ?></a></div>
</div>
</div>
</div>
<!-- END CWV3 Dialog -->
<?php
}
public function render_metabox( $post ) {
wp_nonce_field( plugin_basename( __FILE__ ), 'cwv3_meta' );
$curval = get_post_meta( $post->ID, 'cwv3_auth', true );
$sw = get_option( 'cwv3_sitewide' );
$disabled = $sw[0] == 'enabled' ? true : false;
?>
<label for="cwv3_auth">Use authorization for this content:</label>
<input type="checkbox" id="cwv3_auth" name="cwv3_auth" <?php checked( 'yes', $curval, true ); ?> value="yes" <?php disabled( $disabled ); ?>/><br />
<?php if ( 'enabled' == $sw[0] ) : ?>
<p class="description">Cannot be changed while site wide option is enabled.</p>
<?php endif; ?>
<?php
cwv3_js_dialog();
}
}
new CWV3;
?>
$cwv3_frontend = new CWV3();
$cwv3_frontend->hooks();

View File

@ -7,10 +7,16 @@ Author: Jerry Wood Jr.
Version: 3.6.0
Author URI: http://plugish.com
*/
require_once dirname( __FILE__ ) . '/inc/options.inc.php';
require_once dirname( __FILE__ ) . '/lib/jw_simple_options/simple_options.php';
require_once dirname( __FILE__ ) . '/inc/api.php'
require_once dirname( __FILE__ ) . '/class/main.class.php';
require_once dirname( __FILE__ ) . '/inc/api.php';
if ( is_admin() ){
require_once dirname( __FILE__ ) . '/inc/options.inc.php';
require_once dirname( __FILE__ ) . '/lib/jw_simple_options/simple_options.php';
require_once dirname( __FILE__ ) . '/class/admin.class.php';
$cwv3_options = new JW_SIMPLE_OPTIONS( $cwv3_op_data );
register_uninstall_hook( __FILE__, $cwv3_options->uninstall() );
} else {
require_once dirname( __FILE__ ) . '/class/main.class.php';
}
$cwv3_options = new JW_SIMPLE_OPTIONS( $cwv3_op_data );
register_uninstall_hook( __FILE__, $cwv3_options->uninstall() );

View File

@ -69,4 +69,24 @@
}
.cwv3_exit{
float: right;
width: 40%;
a{
background-color: #F00;
}
}
.cwv3_enter{
float: left;
width: 40%;
a{
background-color: #0C3;
}
}
}

View File

@ -25,62 +25,67 @@ function cwv3_get_css(){
$bg_color_css = ! empty( $color ) ? 'background-color: ' . $color['color'] . ';' : '';
ob_start();
?><style type="text/css"><?php
?>
<!-- CWV3 CSS -->
<style type="text/css">
#cboxOverlay{<?php echo $bg_image_css . $bg_color_css; ?>}
<?php
if ( ! empty( $custom_css ) ){
echo apply_filters( 'cwv3_custom_css', $custom_css );
}
?>#cboxOverlay{
echo $bg_image_css . $bg_color_css;
}<?php
do_action( 'cwv3_after_css' );
?></style><?php
?>
</style>
<!-- END CWV3-CSS -->
<?php
return apply_filters( 'cwv3_css', ob_get_clean() );
}
function cwv3_js_dialog(){
echo cwv3_get_js_dialog();
}
function cwv3_get_js_dialog(){
$exit_text = get_option( 'cwv3_exit_txt', __( 'Exit', 'cwv3' ) );
$enter_text = get_option( 'cwv3_enter_txt', __( 'Enter', 'cwv3' ) );
$exit_text = get_option( 'cwv3_exit_txt', __( 'Exit', 'cwv3' ) );
$enter_text = get_option( 'cwv3_enter_txt', __( 'Enter', 'cwv3' ) );
$cwv3_denial_title = get_option( 'cwv3_den_title', __( 'Access Denied', 'cwv3' ) );
$cwv3_denial_title = get_option( 'cwv3_den_title', __( 'Access Denied', 'cwv3' ) );
$cwv3_denial_message = get_option( 'cwv3_den_msg', __( 'You have been denied access to this content. If you feel this is in error, please contact a site administrator.', 'cwv3' ) );
$cwv3_title = get_option( 'cwv3_den_title', __( 'Access Denied', 'cwv3' ) );
$cwv3_message = get_option( 'cwv3_den_msg', __( 'You have been denied access to this content. If you feel this is in error, please contact a site administrator.', 'cwv3' ) );
$cwv3_title = get_option( 'cwv3_den_title', __( 'Access Denied', 'cwv3' ) );
$cwv3_message = get_option( 'cwv3_den_msg', __( 'The content you are about to view may be considered offensive and/or inappropriate. Furthermore, this content may be considered adult content, if you are not of legal age or are easily offended, you are required to click the exit button.', 'cwv3' ) );
$exit_url = get_option( 'cwv3_exit_link', '#' );
$enter_url = get_option( 'cwv3_enter_link', '#' );
$exit_url = get_option( 'cwv3_exit_link', '#' );
$enter_url = get_option( 'cwv3_enter_link', '#' );
ob_start();
?>
<div id="cwv3_dialog" class="cwv3_dialog js">
<div class="cwv3 auth">
<div class="cwv3_title"><?php echo esc_attr( $cwv3_den_title ); ?></div>
<div class="cwv3_content"><?php echo wp_kses_post( $cwv3_den_msg ); ?></div>
<div class="cwv3_title"><?php echo esc_attr( $cwv3_title ); ?></div>
<div class="cwv3_content"><?php echo wp_kses_post( $cwv3_message ); ?></div>
<div class="cwv3_btns">
<div class="cwv3_enter">
<a href="<?php echo esc_url( $enter_url ); ?>"><?php echo esc_attr( $enter_text ); ) ?></a>
<a href="<?php echo esc_url( $enter_url ); ?>"><?php echo esc_attr( $enter_text ); ?></a>
</div>
<div class="cwv3_exit">
<a href="<?php echo esc_url( $exit_url ); ?>"><?php echo esc_attr( $exit_url ); ) ?></a>
<a href="<?php echo esc_url( $exit_url ); ?>"><?php echo esc_attr( $exit_url ); ?></a>
</div>
</div>
</div>
<div class="cwv3 denied">
<div class="cwv3_title"><?php echo esc_attr( $cwv3_title ); ?></div>
<div class="cwv3_content"><?php echo wp_kses_post( $cwv3_message ); ?></div>
<div class="cwv3_title"><?php echo esc_attr( $cwv3_denial_title ); ?></div>
<div class="cwv3_content"><?php echo wp_kses_post( $cwv3_denial_message ); ?></div>
<div class="cwv3_btns">
<div class="cwv3_exit">
<a href="<?php echo esc_url( $exit_url ); ?>"><?php echo esc_attr( $exit_url ); ) ?></a>
<a href="<?php echo esc_url( $exit_url ); ?>"><?php echo esc_attr( $exit_url ); ?></a>
</div>
</div>
</div>
</div>
<?php
$dialog_output = ob_get_clean();
return apply_filters( 'cwv3_js_dialog_output', $dialog_output );
}

View File

@ -17,7 +17,7 @@ window.cwv3 = ( function( window, document, $ ){
return app;
})( window, document, jQuery );
/*
jQuery(document).ready(function($) {
var enter = $('#cw_enter_link');
var exit = $('#cw_exit_link');
@ -65,4 +65,4 @@ jQuery(document).ready(function($) {
}
});
});*/

View File

@ -83,6 +83,11 @@ Please do not contact me with questions like this. If you cannot be descriptive
== Changelog ==
= 3.6.0 =
* Split methods and hooks from main class file, will prevent overhead.
* Moved to use of cookie.js
* Created API file for methods.
= 3.5.5 =
* [jgraup](https://github.com/jgraup) - Fixed Menu Positioning
* BUGFIX - Fixed Enter/Exit URLs not being respected.