WordPress.org

Plugin Directory

Changeset 1776562


Ignore:
Timestamp:
11/28/17 02:39:57 (8 weeks ago)
Author:
khaxan
Message:

Refactoring and code improvements
Checked compatibility with WP 4.9

Location:
wp-curtain
Files:
23 added
6 edited

Legend:

Unmodified
Added
Removed
  • wp-curtain/trunk/counter.php

    r817014 r1776562  
    11<div class="clock"></div> 
    2 <script type="text/javascript"> 
    3     var clock; 
    4     $(document).ready(function() { 
    5         var currentDate = new Date(); 
    6         var timestamp = Date.parse(futureDateString); 
    7         if (isNaN(timestamp)) 
    8             return; 
    9         var futureDate  = new Date(futureDateString); 
    10         var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000; 
    11         if(diff<0) 
    12             return; 
    13         if(diff>86400){ 
    14             clock = $('.clock').FlipClock(diff, {clockFace: 'DailyCounter',countdown: true}); 
    15         } 
    16         else{ 
    17             clock = $('.clock').FlipClock(diff, {countdown: true}); 
    18             $('.clock').css('width', 460); 
    19         } 
    20     }); 
    21 </script> 
  • wp-curtain/trunk/login-box.php

    r817014 r1776562  
    1313    </div> 
    1414</div> 
    15 <script> 
    16     $(document).ready(function(){ 
    17         $("#login-slide-down").click(function(){ 
    18             $("#login-box").slideDown(); 
    19             $(this).slideUp(); 
    20         }); 
    21         $("#login-slide-up").click(function(){ 
    22             $("#login-box").slideUp(); 
    23             $("#login-slide-down").slideDown(); 
    24         }); 
    25     }); 
    26 </script> 
  • wp-curtain/trunk/options-panel.php

    r817014 r1776562  
    157157 
    158158function wpc_settings_validation($input){ 
     159    $input = stripslashes_deep($input); 
     160 
    159161    $allowed_html = array( 
    160162                        'a' => array( 
     
    167169                        'strong' => array() 
    168170                    ); 
    169     $input['page_title'] = esc_attr($input['page_title']); 
     171    $input['page_title'] = sanitize_text_field($input['page_title']); 
    170172    $input['page_heading'] = wp_kses($input['page_heading'], $allowed_html); 
    171173    $input['page_description'] = wp_kses($input['page_description'], $allowed_html); 
    172     $input['future_date']['date'] = wp_kses($input['future_date']['date'],array()); 
     174    $input['future_date']['date'] = sanitize_text_field($input['future_date']['date']); 
    173175    $input['future_date']['hh'] = intval($input['future_date']['hh']); 
    174176    $input['future_date']['mm'] = intval($input['future_date']['mm']); 
    175177    $input['future_date']['ss'] = intval($input['future_date']['ss']); 
    176     $input['redirect_url'] = esc_url($input['redirect_url']); 
     178    $input['redirect_url'] = esc_url_raw($input['redirect_url']); 
    177179    return $input; 
    178180} 
     
    198200function wpc_render_settings_field($args){ 
    199201    $option_value = get_option($args['group']); 
     202    $current_value = wpc_get_value($option_value, $args['id']); 
    200203     
    201204    if($args['type'] == 'text'){ 
    202205?> 
    203         <input type="text" id="<?php echo $args['id'] ?>" name="<?php echo $args['group'].'['.$args['id'].']'; ?>" value="<?php echo esc_attr($option_value[$args['id']]); ?>"> 
     206        <input type="text" id="<?php echo $args['id'] ?>" name="<?php echo $args['group'].'['.$args['id'].']'; ?>" value="<?php echo esc_attr($current_value); ?>"> 
    204207        <small><?php echo $args['desc'] ?></small> 
    205208<?php 
     
    209212?> 
    210213        <select name="<?php echo $args['group'].'['.$args['id'].']'; ?>" id="<?php echo $args['id']; ?>"> 
    211             <?php foreach ($args['options'] as $key=>$option) { ?> 
    212                 <option <?php selected($option_value[$args['id']], $key); echo 'value="'.$key.'"'; ?>><?php echo $option; ?></option><?php } ?> 
     214            <?php foreach ($args['options'] as $key => $option) { ?> 
     215                <option <?php selected($current_value, $key); echo 'value="'.$key.'"'; ?>><?php echo esc_html($option); ?></option><?php } ?> 
    213216        </select> 
    214217        <small><?php echo $args['desc']; ?></small> 
     
    219222?>       
    220223        <input type="hidden" name="<?php echo $args['group'].'['.$args['id'].']'; ?>" value="0" /> 
    221         <input type="checkbox" name="<?php echo $args['group'].'['.$args['id'].']'; ?>" id="<?php echo $args['id']; ?>" value="1" <?php checked($option_value[$args['id']]); ?> /> 
     224        <input type="checkbox" name="<?php echo $args['group'].'['.$args['id'].']'; ?>" id="<?php echo $args['id']; ?>" value="1" <?php checked($current_value); ?> /> 
    222225        <small><?php echo $args['desc']; ?></small><div class="clearfix"></div> 
    223226<?php 
     
    226229    { 
    227230?> 
    228         <textarea name="<?php echo $args['group'].'['.$args['id'].']'; ?>" type="<?php echo $args['type']; ?>" cols="" rows=""><?php if ( $option_value[$args['id']] != "") { echo stripslashes(esc_textarea($option_value[$args['id']]) ); } ?></textarea> 
     231        <textarea name="<?php echo $args['group'].'['.$args['id'].']'; ?>" type="<?php echo $args['type']; ?>" cols="" rows=""><?php echo esc_textarea($current_value); ?></textarea> 
    229232        <small><?php echo $args['desc']; ?></small><div class="clearfix"></div> 
    230233<?php 
     
    233236    { 
    234237?> 
    235         <label for="<?php echo $args['id'].'_date'; ?>">Date:</label> <input type="text" style="width:130px;" id="<?php echo $args['id'].'_date'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[date]'; ?>" value="<?php echo esc_attr($option_value[$args['id']]['date']); ?>"> 
    236         <label for="<?php echo $args['id'].'_hh'; ?>">HH:</label> <input type="text" style="width:25px;" id="<?php echo $args['id'].'_hh'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[hh]'; ?>" value="<?php echo esc_attr($option_value[$args['id']]['hh']); ?>"> 
    237         <label for="<?php echo $args['id'].'_mm'; ?>">MM:</label> <input type="text" style="width:25px;" id="<?php echo $args['id'].'_mm'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[mm]'; ?>" value="<?php echo esc_attr($option_value[$args['id']]['mm']); ?>"> 
    238         <label for="<?php echo $args['id'].'_ss'; ?>">SS:</label> <input type="text" style="width:25px;" id="<?php echo $args['id'].'_ss'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[ss]'; ?>" value="<?php echo esc_attr($option_value[$args['id']]['ss']); ?>"> 
     238        <label for="<?php echo $args['id'].'_date'; ?>">Date:</label> <input type="text" style="width:130px;" id="<?php echo $args['id'].'_date'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[date]'; ?>" value="<?php echo esc_attr(wpc_get_value($current_value, 'date')); ?>"> 
     239        <label for="<?php echo $args['id'].'_hh'; ?>">HH:</label> <input type="text" style="width:25px;" id="<?php echo $args['id'].'_hh'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[hh]'; ?>" value="<?php echo esc_attr(wpc_get_value($current_value, 'hh')); ?>"> 
     240        <label for="<?php echo $args['id'].'_mm'; ?>">MM:</label> <input type="text" style="width:25px;" id="<?php echo $args['id'].'_mm'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[mm]'; ?>" value="<?php echo esc_attr(wpc_get_value($current_value, 'mm')); ?>"> 
     241        <label for="<?php echo $args['id'].'_ss'; ?>">SS:</label> <input type="text" style="width:25px;" id="<?php echo $args['id'].'_ss'; ?>" name="<?php echo $args['group'].'['.$args['id'].']'.'[ss]'; ?>" value="<?php echo esc_attr(wpc_get_value($current_value, 'ss')); ?>"> 
    239242        <small><?php echo $args['desc'] ?></small> 
    240243<?php 
    241244    } 
    242245} 
    243  
    244 ?> 
  • wp-curtain/trunk/readme.txt

    r817014 r1776562  
    11=== WP Curtain === 
     2Contributors: wpgurus 
    23Tags: hide, hide wordpress, hide website, password protect, password protection, block site, hide site 
    3 Donate link: http://wpgurus.net/ 
     4Donate link: https://wpgurus.net/wp-curtain/ 
    45Requires at least: 3.0 
    5 Tested up to: 3.6 
    6 Stable tag: 0.1 
     6Tested up to: 4.9 
     7Stable tag: 1.0.0 
    78License: GPLv2 or later 
    89License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    4142= 0.1 = 
    4243* Initial release. 
     44 
     45= 1.0.0 = 
     46* Refactoring and code improvements 
     47* Checked compatibility with WP 4.9 
  • wp-curtain/trunk/template.php

    r817014 r1776562  
    11<!DOCTYPE html> 
    22<head> 
    3     <?php $wpc_settings = get_option("wpc_settings"); ?> 
    4     <title><?php echo $wpc_settings['page_title']?$wpc_settings['page_title']:"We'll be right back"; ?></title> 
     3    <?php $wpc_settings = wpc_get_settings(); ?> 
     4    <title><?php echo $wpc_settings['page_title']; ?></title> 
    55    <?php wp_head(); ?> 
    6     <script type="text/javascript">var futureDateString = '<?php echo $wpc_settings['future_date']['date'].' '.$wpc_settings['future_date']['hh'].':'.$wpc_settings['future_date']['mm'].':'.$wpc_settings['future_date']['ss']; ?>';$ = jQuery;</script> 
    76</head> 
    87<body class="wp-curtain"> 
    98    <div id="container"> 
    109        <div id="content-section"> 
    11             <h1><?php echo $wpc_settings['page_heading']?$wpc_settings['page_heading']:"We'll be right back"; ?></h1> 
    12             <p><?php echo $wpc_settings['page_description']?$wpc_settings['page_description']:"Please try again later"; ?></p> 
     10            <h1><?php echo $wpc_settings['page_heading']; ?></h1> 
     11            <p><?php echo $wpc_settings['page_description']; ?></p> 
    1312        </div> 
    1413        <?php if(!$wpc_settings['disable_timer']) include('counter.php'); ?> 
  • wp-curtain/trunk/wp-curtain.php

    r817019 r1776562  
    22/* 
    33Plugin Name: WP Curtain 
    4 Plugin URI: http://wpgurus.net/ 
     4Plugin URI: https://wpgurus.net/wp-curtain/ 
    55Description: WP Curtain is a simple plugin that allows you to hide your website from the general public and display an elegant countdown timer. 
    6 Version: 0.1 
    7 Author: Hassan Akhtar 
    8 Author URI: http://wpgurus.net/ 
     6Version: 1.0.0 
     7Author: WPGurus 
     8Author URI: https//wpgurus.net/ 
    99License: GPL2 
    1010*/ 
    1111 
    1212function wpc_redirect() { 
    13     $wpc_settings = get_option("wpc_settings"); 
     13    $wpc_settings = wpc_get_settings(); 
    1414    if ( !is_user_logged_in() || !current_user_can($wpc_settings['minimum_role']) ){ 
    1515        include('template.php'); 
     
    2020 
    2121function wpc_scripts_styles(){ 
    22     $wpc_settings = get_option("wpc_settings"); 
     22    $wpc_settings = wpc_get_settings(); 
    2323    wp_enqueue_style('wpc-stylesheet', plugins_url( 'static/css/style.min.css' , __FILE__ ) ); 
     24    wp_enqueue_script('wpc-script', plugins_url( 'static/js/script.js' , __FILE__ ), array('jquery')); 
     25    wp_localize_script('wpc-script', 'wpc_settings', $wpc_settings); 
     26 
    2427    if(!$wpc_settings['disable_timer'] && $wpc_settings['future_date']) 
     28    { 
    2529        wp_enqueue_script('flipclock', plugins_url( 'static/js/flipclock.package.min.js' , __FILE__ ), array('jquery')); 
     30    } 
    2631} 
    2732add_action('wp_enqueue_scripts', 'wpc_scripts_styles', 1); 
    28  
    29  
    30 function wpc_initialize_options(){ 
    31     $wpc_settings = get_option("wpc_settings"); 
    32     if($wpc_settings) 
    33         return; 
    34          
    35     $wpc_settings['minimum_role'] = 'install_plugins'; 
    36     update_option('wpc_settings', $wpc_settings); 
    37 } 
    38 register_activation_hook(__FILE__, 'wpc_initialize_options'); 
    3933 
    4034function wpc_rollback(){ 
     
    4337register_uninstall_hook(__FILE__, 'wpc_rollback'); 
    4438 
     39function wpc_get_settings() 
     40{ 
     41    return wp_parse_args( 
     42        get_option('wpc_settings'), 
     43        array( 
     44            'page_title'        => "We'll be right back", 
     45            'page_heading'      => "We'll be right back", 
     46            'page_description'  => 'Please try again later', 
     47            'disable_timer'     => false, 
     48            'future_date'       => false, 
     49            'disable_login_box' => false, 
     50            'redirect_url'      => '', 
     51            'minimum_role'      => 'install_plugins' 
     52        ) 
     53    ); 
     54} 
     55 
     56function wpc_get_value($array, $key = array()) { 
     57    if (!is_array($key)) { 
     58        $key = array($key); 
     59    } 
     60 
     61    if (!is_array($array)) { 
     62        return NULL; 
     63    } 
     64 
     65    $value = $array; 
     66    foreach ($key as $key_part) { 
     67        $value = isset($value[ $key_part ]) ? $value[ $key_part ] : NULL; 
     68    } 
     69 
     70    return $value; 
     71} 
     72 
    4573include('options-panel.php'); 
Note: See TracChangeset for help on using the changeset viewer.