Plugin Directory

Changeset 1628720


Ignore:
Timestamp:
04/03/2017 10:34:28 PM (9 years ago)
Author:
racanu
Message:

More code reorganization

Location:
keep-in-touch/trunk
Files:
2 added
2 edited

Legend:

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

    r1628704 r1628720  
    1515
    1616        $sql = "CREATE TABLE $table_name (
     17            full_name TINYTEXT DEFAULT '' NOT NULL,
    1718            email TINYTEXT DEFAULT '' NOT NULL,
    1819            status SET('pending_activation','active','pending_removal') DEFAULT 'pending_activation' NOT NULL,
  • keep-in-touch/trunk/keep-in-touch.php

    r1628704 r1628720  
    6262    }
    6363
     64    static private function is_null_or_empty_string($string)
     65    {
     66        return (!isset($string) || trim($string)==='');
     67    }
     68
     69    static private function return_same_page()
     70    {
     71        if (wp_get_referer())
     72            wp_safe_redirect(wp_get_referer());
     73        else
     74            wp_safe_redirect(get_home_url());
     75    }
     76
    6477    static private function handle_virtual_page()
    6578    {
    66         if (isset($_POST['keep_in_touch_submit']) and isset($_POST['keep_in_touch_email']))
    67             self::handle_subscribe(sanitize_email($_POST['keep_in_touch_email']), isset($_POST['keep_in_touch_email_reference']) ? sanitize_text_field($_POST['keep_in_touch_email_reference']) : NULL);
    68         //else if (isset($_GET['subscribe']))
    69         //  self::handle_subscribe_first_step(sanitize_text_field($_GET['subscribe']));
     79        if (isset($_POST['keep_in_touch_submit']))
     80            self::handle_submit();
    7081        else if (isset($_GET['unsubscribe']))
    7182            self::handle_unsubscribe(sanitize_text_field($_GET['unsubscribe']));
     
    7384            self::handle_confirmation_code(sanitize_text_field($_GET['confirmation_code']));
    7485    }
     86
     87    static private function handle_submit()
     88    {
     89        if (self::is_null_or_empty_string($_POST['keep_in_touch_email']))
     90            self::return_same_page();
     91
     92        $email = sanitize_email($_POST['keep_in_touch_email']);
     93        if (!isset($_POST['keep_in_touch_email_reference']))
     94            self::handle_subscribe_first_step($email);
     95        else if (sanitize_email($_POST['keep_in_touch_email_reference']) == $email)
     96            self::handle_subscribe_second_step($email);
     97        else
     98            Keep_In_Touch_Msg::emit_invalid_anti_robot_check($email, $email_reference);
     99    }
    75100   
    76     static private function handle_subscribe($email, $email_reference)
     101    static private function handle_subscribe_first_step($email)
    77102    {
    78         if (!isset($email_reference))
    79         {
    80             Keep_In_Touch_Msg::emit_subscription_anti_robot($email);
    81         }
     103        Keep_In_Touch_Msg::emit_subscription_anti_robot($email);
     104    }
     105
     106    static private function handle_subscribe_second_step($email)
     107    {
     108        $confirmation_code = Keep_In_Touch_Utils::generate_unique_id(20);
     109        if (Keep_In_Touch_Db::register_subscription_request($email, $confirmation_code))
     110            Keep_In_Touch_Msg::emit_confirm_subscription($email, $confirmation_code);
    82111        else
    83         {
    84             $confirmation_code = Keep_In_Touch_Utils::generate_unique_id(20);
    85 
    86             if ($email != $email_reference)
    87                 Keep_In_Touch_Msg::emit_invalid_anti_robot_check($email, $email_reference);
    88             else if (Keep_In_Touch_Db::register_subscription_request($email, $confirmation_code))
    89                 Keep_In_Touch_Msg::emit_confirm_subscription($email, $confirmation_code);
    90             else
    91                 Keep_In_Touch_Msg::emit_subscription_request_failed($email);
    92         }
     112            Keep_In_Touch_Msg::emit_subscription_request_failed($email);
    93113    }
    94114
Note: See TracChangeset for help on using the changeset viewer.