Plugin Directory

Changeset 1680091


Ignore:
Timestamp:
06/16/2017 07:35:16 PM (9 years ago)
Author:
racanu
Message:

Added options reader class and made schedules recurrent

Location:
keep-in-touch/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • keep-in-touch/trunk/class-keep-in-touch-msg.php

    r1644786 r1680091  
    33defined('ABSPATH') or die ('No direct access to this file.');
    44
    5 include_once('class-keep-in-touch-utils.php');
    6 include_once('class-keep-in-touch-db.php');
    7 include_once('class-virtual-page.php');
     5require_once('class-keep-in-touch-utils.php');
     6require_once('class-keep-in-touch-options.php');
     7require_once('class-keep-in-touch-db.php');
     8require_once('class-virtual-page.php');
    89
    910class Keep_In_Touch_Msg
     
    2930    static function emit_subscription_anti_robot($email)
    3031    {
    31         $use_full_name = (get_option('keep_in_touch_use_full_name') == 'yes');
     32        $use_full_name = (Keep_In_Touch_Options::get_option_use_full_name(false) == true);
    3233
    3334        Virtual_Page::create_from_content(array(
     
    117118    static function emit_subscription_confirmation($email, $confirmation_code)
    118119    {
    119         $common_content = wpautop(get_option("keep_in_touch_subscription_confirmation_text"));
     120        $common_content = wpautop(Keep_In_Touch_Options::get_option_subscription_confirmation_text(''));
    120121
    121122        wp_mail(
     
    277278        if ($query->found_posts == 0)
    278279        {
    279             if (!Keep_In_Touch_Utils::bool(get_option('keep_in_touch_send_empty_digest_message')))
     280            if (!Keep_In_Touch_Options::get_option_send_empty_digest_message(false))
    280281                return;
    281             $message = wpautop(get_option('keep_in_touch_empty_digest_message_text'));
     282            $message = wpautop(Keep_In_Touch_Options::get_option_empty_digest_message_text(''));
    282283        }
    283284        else
     
    308309    static private function get_configured_header_image_url()
    309310    {
    310         if (get_option('keep_in_touch_header_image_option') == 'get_header_image')
     311        if (Keep_In_Touch_Options::get_option_header_image_option('') == 'get_header_image')
    311312        {
    312313            return get_header_image();
    313314        }
    314315
    315         if (get_option('keep_in_touch_header_image_option') == 'custom_path')
    316         {
    317             $custom_path = get_option('keep_in_touch_header_image_custom_path');
     316        if (Keep_In_Touch_Options::get_option_header_image_option('') == 'custom_path')
     317        {
     318            $custom_path = Keep_In_Touch_Options::get_option_header_image_custom_path('');
    318319            if (Keep_In_Touch_Utils::starts_with('/', $custom_path))
    319320                return get_home_url(null, $custom_path);
  • keep-in-touch/trunk/class-keep-in-touch-schedule.php

    r1628720 r1680091  
    33defined('ABSPATH') or die ('No direct access to this file.');
    44
    5 include_once(ABSPATH . 'wp-includes/locale.php');
    6 include_once('class-keep-in-touch-utils.php');
    7 include_once('class-keep-in-touch-msg.php');
     5require_once(ABSPATH . 'wp-includes/locale.php');
     6require_once('class-keep-in-touch-utils.php');
     7require_once('class-keep-in-touch-options.php');
     8require_once('class-keep-in-touch-msg.php');
    89
    910class Keep_In_Touch_Schedule
     
    1415        self::reschedule_weekly_event();
    1516    }
    16    
     17
    1718    static function unschedule_events()
    1819    {
     
    2223
    2324    static function handle_daily_event()
    24     {       
     25    {
    2526        Keep_In_Touch_Msg::send_daily_digest();
    26         self::reschedule_daily_event();
     27        //self::reschedule_daily_event();
    2728    }
    2829
     
    3334    }
    3435
     36  static function add_my_schedules($schedules)
     37    {
     38        $schedules['every_minute'] = array(
     39            'interval' => MINUTE_IN_SECONDS,
     40            'display' => __('Every minute')
     41        );
     42        $schedules['weekly'] = array(
     43            'interval' => 7 * DAY_IN_SECONDS,
     44            'display' => __('Weekly')
     45        );
     46        return $schedules;
     47    }
     48
    3549    static private function reschedule_over_one_minute($hook)
    3650    {
    3751        wp_schedule_single_event(
    38             strtotime('today ' . date('H:i', time() + get_option('gmt_offset') * 3600 + 1 * 60) . ' ' . Keep_In_Touch_Utils::format_time_offset(get_option('gmt_offset') * 3600)), 
     52            strtotime('today ' . date('H:i', time() + get_option('gmt_offset') * 3600 + 1 * 60) . ' ' . Keep_In_Touch_Utils::format_time_offset(get_option('gmt_offset') * 3600)),
    3953            $hook
    4054        );
     
    4458    {
    4559        wp_clear_scheduled_hook('keep_in_touch_daily_event_hook');
    46        
    47         $t0 = get_option('keep_in_touch_delivery_time') . ' ' . Keep_In_Touch_Utils::format_time_offset(get_option('gmt_offset') * 3600);
    48         $t1 = strtotime('today ' . $t0);
    49         $t2 = strtotime('tomorrow ' . $t0);
    50         $t = ($t1 > floor(time() / 60) * 60) ? $t1 : $t2;
    51        
    52         wp_schedule_single_event($t, 'keep_in_touch_daily_event_hook');
    53         //self::reschedule_over_one_minute('keep_in_touch_daily_event_hook');
     60        $t = strtotime(Keep_In_Touch_Options::get_option_delivery_time(0, 0));
     61        wp_schedule_event(($t < time()) ? $t + DAY_IN_SECONDS : $t, 'daily', 'keep_in_touch_daily_event_hook');
    5462    }
    55    
     63
    5664    static function reschedule_weekly_event()
    5765    {
    5866        wp_clear_scheduled_hook('keep_in_touch_weekly_event_hook');
    59        
    60         $t0 = get_option('keep_in_touch_delivery_time') . ' ' . Keep_In_Touch_Utils::format_time_offset(get_option('gmt_offset') * 3600);
    61         $t1 = strtotime('sunday ' . $t0);
    62         $t2 = strtotime('next sunday ' . $t0);
     67        //$t0 = Keep_In_Touch_Options::get_option_delivery_time(0, 0) . ' ' . Keep_In_Touch_Utils::format_time_offset(get_option('gmt_offset') * 3600);
     68        $t0 = Keep_In_Touch_Options::convert_option_weekday_to_weekday_name(Keep_In_Touch_Options::get_option_delivery_weekday(0)) . ' ' . Keep_In_Touch_Options::get_option_delivery_time(0, 0);
     69        $t1 = strtotime($t0);
     70        $t2 = strtotime('next ' . $t0);
    6371        $t = ($t1 > floor(time() / 60) * 60) ? $t1 : $t2;
    64        
    65         wp_schedule_single_event($t, 'keep_in_touch_weekly_event_hook');
    66         //self::reschedule_over_one_minute('keep_in_touch_weekly_event_hook');
     72
     73        wp_schedule_event($t2, 'weekly', 'keep_in_touch_weekly_event_hook');
     74    }
     75
     76    static function init()
     77    {
     78        add_action( 'keep_in_touch_daily_event_hook', array( 'Keep_In_Touch_Schedule', 'handle_daily_event' ) );
     79        add_action( 'keep_in_touch_weekly_event_hook', array( 'Keep_In_Touch_Schedule', 'handle_weekly_event' ) );
     80        add_filter( 'cron_schedules', array('Keep_In_Touch_Schedule', 'add_my_schedules' ) );
    6781    }
    6882}
  • keep-in-touch/trunk/class-keep-in-touch-settings.php

    r1644792 r1680091  
    33defined('ABSPATH') or die ('No direct access to this file.');
    44
    5 include_once(ABSPATH . 'wp-includes/locale.php');
    6 include_once('class-keep-in-touch-utils.php');
    7 include_once('class-keep-in-touch-msg.php');
     5require_once(ABSPATH . 'wp-includes/locale.php');
     6require_once('class-keep-in-touch-utils.php');
     7require_once('class-keep-in-touch-options.php');
     8require_once('class-keep-in-touch-msg.php');
    89
    910class Keep_In_Touch_Settings
     
    2223        if ($_POST['form'] == 'keep_in_touch_subscription_settings')
    2324        {
    24             update_option('keep_in_touch_use_full_name', Keep_In_Touch_Utils::options_bool($_POST['use_full_name']));
    25             update_option('keep_in_touch_subscription_confirmation_text', stripslashes(trim($_POST['subscription_confirmation_text'])));
    26             update_option('keep_in_touch_send_empty_digest_message', Keep_In_Touch_Utils::options_bool($_POST['send_empty_digest_message']));
    27             update_option('keep_in_touch_empty_digest_message_text', stripslashes(trim($_POST['empty_digest_message_text'])));
     25            Keep_In_Touch_Options::update_option_use_full_name($_POST['use_full_name']);
     26            Keep_In_Touch_Options::update_option_subscription_confirmation_text($_POST['subscription_confirmation_text']);
     27            Keep_In_Touch_Options::update_option_send_empty_digest_message($_POST['send_empty_digest_message']);
     28            Keep_In_Touch_Options::update_option_empty_digest_message_text($_POST['empty_digest_message_text']);
    2829        }
    2930        else if ($_POST['form'] == 'keep_in_touch_digest_delivery_settings')
    3031        {
    31             update_option('keep_in_touch_delivery_weekday', $_POST['delivery_weekday']);
    32             update_option('keep_in_touch_delivery_time', Keep_In_Touch_Utils::format_time($_POST['delivery_hour'] * 3600 + $_POST['delivery_minute'] * 60));
     32            Keep_In_Touch_Options::update_option_delivery_weekday($_POST['delivery_weekday']);
     33            Keep_In_Touch_Options::update_option_delivery_time($_POST['delivery_hour'], $_POST['delivery_minute']);
    3334            Keep_In_Touch_Schedule::reschedule_daily_event();
    3435            Keep_In_Touch_Schedule::reschedule_weekly_event();
    35             update_option('keep_in_touch_header_image_option', $_POST['header_image_option']);
    36             update_option('keep_in_touch_header_image_custom_path', trim($_POST['header_image_custom_path']));
     36            Keep_In_Touch_Options::update_option_header_image_option($value);
     37            Keep_In_Touch_Options::update_option_header_image_custom_path($_POST['header_image_custom_path']);
    3738        }
    3839        else if ($_POST['form'] == 'keep_in_touch_send_digest_now' and isset($_POST['send_daily_digest']))
     
    6061            <h3 class="hndle"><?php echo __('Subscription settings', 'keep-in-touch'); ?></h3>
    6162            <div class="inside">
    62                 <?php $checked = Keep_In_Touch_Utils::checkbox_state(get_option('keep_in_touch_use_full_name')); ?>
     63                <?php $checked = Keep_In_Touch_Utils::checkbox_state(Keep_In_Touch_Options::get_option_use_full_name(false)); ?>
    6364                <form method="POST" action="<?php echo admin_url('options-general.php?page=keep-in-touch'); ?>">
    6465                    <input type="hidden" name="form" value="keep_in_touch_subscription_settings" />
    6566                    <table class="form-table">
    6667                        <tr>
    67                             <th scope="row"><?php echo __('Request full name', 'keep-in-touch'); ?>/></th>
     68                            <th scope="row"><?php echo __('Request full name', 'keep-in-touch'); ?></th>
    6869                            <td><input type="checkbox" name="use_full_name" value="yes" <?php echo $checked; ?>/></td>
    6970                        </tr>
    7071                        <tr>
    7172                            <th scope="row"><?php echo __('Successful subscription message', 'keep-in-touch'); ?></th>
    72                             <td><textarea type="text" name="subscription_confirmation_text" style="height:8em"><?php echo get_option('keep_in_touch_subscription_confirmation_text'); ?></textarea></td>
    73                         </tr>
    74                         <?php $checked = Keep_In_Touch_Utils::checkbox_state(get_option('keep_in_touch_send_empty_digest_message')); ?>
     73                            <td><textarea type="text" name="subscription_confirmation_text" style="height:8em"><?php echo Keep_In_Touch_Options::get_option_subscription_confirmation_text(''); ?></textarea></td>
     74                        </tr>
     75                        <?php $checked = Keep_In_Touch_Utils::checkbox_state(Keep_In_Touch_Options::get_option_send_empty_digest_message(false)); ?>
    7576                        <tr>
    7677                            <th scope="row"><?php echo __('Send empty digest message', 'keep-in-touch'); ?></th>
     
    7980                        <tr>
    8081                            <th scope="row"><?php echo __('Empty digest message', 'keep-in-touch'); ?></th>
    81                             <td><textarea type="text" name="empty_digest_message_text" style="height:8em"><?php echo get_option('keep_in_touch_empty_digest_message_text'); ?></textarea></td>
     82                            <td><textarea type="text" name="empty_digest_message_text" style="height:8em"><?php echo Keep_In_Touch_Options::get_option_empty_digest_message_text(''); ?></textarea></td>
    8283                        </tr>
    8384                        <tr>
     
    9798        for ($wdi = 0; $wdi < 7; $wdi++)
    9899        {
    99             $selected = (($wdi==get_option('keep_in_touch_delivery_weekday'))?'selected="selected" ':'');
     100            $selected = (($wdi == Keep_In_Touch_Options::get_option_delivery_weekday(0)) ? 'selected="selected" ' : '');
    100101            echo '<option ' . $selected . 'value="' . $wdi . '">' . $wp_locale->get_weekday($wdi) . '</option>';
    101102        }
     
    105106    {
    106107        for ($h = 0; $h < 24; $h++)
    107             echo '<option ' . (($h==self::get_hour(get_option('keep_in_touch_delivery_time')))?'selected="selected" ':'') . 'value="' . sprintf('%02d', $h) . '">' . sprintf('%02d', $h) . '</option>';
     108            echo '<option ' . (($h==self::get_hour(Keep_In_Touch_Options::get_option_delivery_time(0, 0))) ? 'selected="selected" ' : '') . 'value="' . sprintf('%02d', $h) . '">' . sprintf('%02d', $h) . '</option>';
    108109    }
    109110
     
    112113        foreach (array(0, 15, 30, 45) as $m)
    113114        {
    114             $selected = (($m==self::get_minute(get_option('keep_in_touch_delivery_time')))?'selected="selected" ':'');
     115            $selected = (($m==self::get_minute(Keep_In_Touch_Options::get_option_delivery_time(0, 0))) ? 'selected="selected" ' : '');
    115116            $value = sprintf('%02d', $m);
    116117            echo '<option ' . $selected . 'value="' . $value . '">' . $value . '</option>';
     
    156157                            <td>
    157158                                <select name="header_image_option">
    158                                     <option value="get_header_image" <?php echo ((get_option('keep_in_touch_header_image_option') == 'get_header_image') ? 'selected="selected"' : ''); ?>><?php echo __('Use get_header_image()', 'keep-in-touch'); ?></option>
    159                                     <option value="custom_path" <?php echo ((get_option('keep_in_touch_header_image_option') == 'custom_path') ? 'selected="selected"' : ''); ?>><?php echo __('Use custom path', 'keep-in-touch'); ?></option>
     159                                    <option value="get_header_image" <?php echo ((Keep_In_Touch_Options::get_option_header_image_option('') == 'get_header_image') ? 'selected="selected"' : ''); ?>><?php echo __('Use get_header_image()', 'keep-in-touch'); ?></option>
     160                                    <option value="custom_path" <?php echo ((Keep_In_Touch_Options::get_option_header_image_option('') == 'custom_path') ? 'selected="selected"' : ''); ?>><?php echo __('Use custom path', 'keep-in-touch'); ?></option>
    160161                                </select>
    161                                 <input type="text" name="header_image_custom_path" placeholder="<?php echo __('Enter custom path to header image', 'keep-in-touch'); ?>" size="80" value="<?php echo get_option('keep_in_touch_header_image_custom_path'); ?>"/>
     162                                <input type="text" name="header_image_custom_path" placeholder="<?php echo __('Enter custom path to header image', 'keep-in-touch'); ?>" size="80" value="<?php echo Keep_In_Touch_Options::get_option_header_image_custom_path(''); ?>"/>
    162163                            </td>
    163164                        </tr>
     
    259260    static private function generate_subscribers_list()
    260261    {
    261         $use_full_name = (get_option('keep_in_touch_use_full_name', 'no') == 'yes');
     262        $use_full_name = Keep_In_Touch_Options::get_option_use_full_name(false);
    262263        $subscribers = Keep_In_Touch_Db::get_all_confirmed_subscribers();
    263264        echo '<div class="postbox">';
  • keep-in-touch/trunk/class-keep-in-touch-utils.php

    r1638717 r1680091  
    11<?php
    2 
    3 defined('ABSPATH') or die ('No direct access to this file.');
    42
    53class Keep_In_Touch_Utils
     
    141139    }
    142140
    143     static function bool($option)
    144     {
    145         if ((bool)$option and ($option == 'no')) return false;
    146         return (bool)$option;
    147     }
    148 
    149     static function options_bool($option)
    150     {
    151         return (self::bool($option) ? 'yes' : 'no');
    152     }
    153 
    154141    static function checkbox_state($option)
    155142    {
    156         return (self::bool($option) ? 'checked="yes"' : '');
     143        return ($option ? 'checked="yes"' : '');
    157144    }
    158145
  • keep-in-touch/trunk/class-keep-in-touch-widget.php

    r1644786 r1680091  
    33defined('ABSPATH') or die ('No direct access to this file.');
    44
    5 include_once('class-keep-in-touch-utils.php');
     5require_once('class-keep-in-touch-utils.php');
    66
    77class Keep_In_Touch_Widget extends WP_Widget
  • keep-in-touch/trunk/keep-in-touch.php

    r1644786 r1680091  
    1919//define('WP_DEBUG_LOG', true);
    2020
    21 include_once(ABSPATH . 'wp-includes/locale.php');
    22 include_once('class-keep-in-touch-utils.php');
    23 include_once('class-keep-in-touch-db.php');
    24 include_once('class-keep-in-touch-msg.php');
    25 include_once('class-keep-in-touch-settings.php');
    26 include_once('class-keep-in-touch-schedule.php');
    27 include_once('class-keep-in-touch-widget.php');
     21require_once(ABSPATH . 'wp-includes/locale.php');
     22require_once('class-keep-in-touch-utils.php');
     23require_once('class-keep-in-touch-options.php');
     24require_once('class-keep-in-touch-db.php');
     25require_once('class-keep-in-touch-msg.php');
     26require_once('class-keep-in-touch-settings.php');
     27require_once('class-keep-in-touch-schedule.php');
     28require_once('class-keep-in-touch-widget.php');
    2829
    2930
     
    3233    static private function set_initial_options()
    3334    {
    34         if (!get_option('keep_in_touch_use_full_name'))
    35             update_option('keep_in_touch_use_full_name', Keep_In_Touch_Db::db_bool(true));
    36         if (!get_option('keep_in_touch_subscription_confirmation_text'))
    37             update_option('keep_in_touch_subscription_confirmation_text', __(
     35        if (Keep_In_Touch_Options::get_option_use_full_name() == null)
     36            Keep_In_Touch_Options::update_option_use_full_name(true);
     37        if (Keep_In_Touch_Options::get_option_subscription_confirmation_text() == null)
     38            Keep_In_Touch_Options::update_option_subscription_confirmation_text(__(
    3839                'Your subscription is now confirmed. You will be receiving updates from us. Welcome and enjoy!', 'keep-in-touch'));
    39         if (!get_option('keep_in_touch_send_empty_digest_message'))
    40             update_option('keep_in_touch_send_empty_digest_message', Keep_In_Touch_Db::db_bool(true));
    41         if (!get_option('keep_in_touch_empty_digest_message_text'))
    42             update_option('keep_in_touch_empty_digest_message_text', __(
     40        if (Keep_In_Touch_Options::get_option_send_empty_digest_message() == null)
     41            Keep_In_Touch_Options::update_option_send_empty_digest_message(true);
     42        if (Keep_In_Touch_Options::get_option_empty_digest_message_text() == null)
     43            Keep_In_Touch_Options::update_option_empty_digest_message_text(__(
    4344                "As it seems, we haven't been very active lately.\n\n" .
    4445                "There are no new posts.\n\n" .
     
    160161        load_plugin_textdomain('keep-in-touch', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
    161162        self::set_initial_options();
     163
     164        Keep_In_Touch_Schedule::init();
     165
    162166        if (self::is_virtual_page())
    163167            self::handle_virtual_page();
     
    183187add_action( 'admin_enqueue_scripts', array( 'Keep_In_Touch', 'load_css' ) );
    184188add_action( 'admin_menu', array( 'Keep_In_Touch', 'plugin_menu' ) );
    185 add_action( 'keep_in_touch_daily_event_hook', array( 'Keep_In_Touch_Schedule', 'handle_daily_event' ) );
    186 add_action( 'keep_in_touch_weekly_event_hook', array( 'Keep_In_Touch_Schedule', 'handle_weekly_event' ) );
    187189
    188190//How-to:
Note: See TracChangeset for help on using the changeset viewer.