Plugin Directory

Changeset 1574150


Ignore:
Timestamp:
01/13/2017 04:56:35 PM (9 years ago)
Author:
KenazChan
Message:

Major refactoring and bug fixes

Location:
db-error-customizer
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • db-error-customizer/trunk/assets/js/db-error-customizer.js

    r1371180 r1574150  
    11(function( $ ) {
    2  
     2
    33    $(function() {
    44        /*
    55        **  Add Color Picker to all inputs that have 'color-field' class
    66        */
    7         $('.color-field').wpColorPicker();
     7        $('.color-field').wpColorPicker({defaultColor: false});
    88
    99        /*
     
    1111        */
    1212        coreSelectSwitch(false);
    13       coreEmailSwitch();
    14 
    15         /*
    16         **  BG Img upload
    17         */
    18         var file_frame_bg;
    19         var file_frame_logo;
    20         var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
    21         jQuery('#upload_bg_img_button').on('click', function( event ){
    22             event.preventDefault();
    23             var set_to_post_id = $(this).next().val();
    24             // If the media frame already exists, reopen it.
    25             if ( file_frame_bg ) {
    26                 // Set the post ID to what we want
    27                 file_frame_bg.uploader.uploader.param( 'post_id', set_to_post_id );
    28                 // Open frame
    29                 file_frame_bg.open();
    30                 return;
    31             } else {
    32                 // Set the wp.media post id so the uploader grabs the ID we want when initialised
    33                 wp.media.model.settings.post.id = set_to_post_id;
    34             }
    35             // Create the media frame.
    36             file_frame_bg = wp.media.frames.file_frame = wp.media({
    37                 title: 'Select a image to upload',
    38                 button: {
    39                     text: 'Use this image',
    40                 },
    41                 multiple: false // Set to true to allow multiple files to be selected
    42             });
    43             // When an image is selected, run a callback.
    44             file_frame_bg.on( 'select', function() {
    45                 // We set multiple to false so only get one image from the uploader
    46                 attachment = file_frame_bg.state().get('selection').first().toJSON();
    47                 // Do something with attachment.id and/or attachment.url here
    48                 $( '#template_bg_img_url' ).val( attachment.url );
    49                 $( '#template_bg_img_attachment_id' ).val( attachment.id );
    50                 // Restore the main post ID
    51                 wp.media.model.settings.post.id = wp_media_post_id;
    52             });
    53             // Finally, open the modal
    54             file_frame_bg.open();
    55         });
    56 
    57         /*
    58         **  Logo upload
    59         */
    60         jQuery('#upload_logo_button').on('click', function( event ){
    61             event.preventDefault();
    62             var set_to_post_id = $(this).next().val();
    63             // If the media frame already exists, reopen it.
    64             if ( file_frame_logo ) {
    65                 // Set the post ID to what we want
    66                 file_frame_logo.uploader.uploader.param( 'post_id', set_to_post_id );
    67                 // Open frame
    68                 file_frame_logo.open();
    69                 return;
    70             } else {
    71                 // Set the wp.media post id so the uploader grabs the ID we want when initialised
    72                 wp.media.model.settings.post.id = set_to_post_id;
    73             }
    74             // Create the media frame.
    75             file_frame_logo = wp.media.frames.file_frame = wp.media({
    76                 title: 'Select a image to upload',
    77                 button: {
    78                     text: 'Use this image',
    79                 },
    80                 multiple: false // Set to true to allow multiple files to be selected
    81             });
    82             // When an image is selected, run a callback.
    83             file_frame_logo.on( 'select', function() {
    84                 // We set multiple to false so only get one image from the uploader
    85                 attachment = file_frame_logo.state().get('selection').first().toJSON();
    86                 // Do something with attachment.id and/or attachment.url here
    87                 $( '#template_logo_url' ).val( attachment.url );
    88                 $( '#template_logo_attachment_id' ).val( attachment.id );
    89                 // Restore the main post ID
    90                 wp.media.model.settings.post.id = wp_media_post_id;
    91             });
    92             // Finally, open the modal
    93             file_frame_logo.open();
    94         });
    95 
    96         // Restore the main ID when the add media button is pressed
    97         jQuery( 'a.add_media' ).on( 'click', function() {
    98             wp.media.model.settings.post.id = wp_media_post_id;
    99         });
    10013
    10114        /*
    10215        **  Core function handle when template change
    10316        */
    104         function coreSelectSwitch( is_switch ) {
     17        function coreSelectSwitch(isSwitch) {
    10518            d = new Date();
    10619            var selected_template = $('#template_select').val();
    107             $("#template-demo").attr("src", $("#plugin_url").val()+"templates/"+selected_template+".jpg?"+d.getTime());
     20            $("#template-demo").attr("src", $("#plugin_url").text()+"templates/"+selected_template+".jpg?"+d.getTime());
    10821
    10922            // Switcher to decide which option to enable
     
    11427
    11528                // SHOW Bg img
    116                 $("#upload_bg_img_button").removeAttr('disabled');
    117                 $("#template_bg_img_attachment_id").removeAttr('disabled');
    118                 $("#template_bg_img_url").removeAttr('disabled');
    119                 $("#template_bg_img_attachment_id").attr('type','hidden');
    120                 $("#template_bg_img_url").attr('readonly',true);
    121                 $("#template_bg_img_url").closest("tr").css("display", "table-row");
     29                $(".upload-bg-image-group").css("display", "table-row");
    12230
    12331                // SHOW Logo
    124                 $("#upload_logo_button").removeAttr('disabled');
    125                 $("#template_logo_attachment_id").removeAttr('disabled');
    126                 $("#template_logo_url").removeAttr('disabled');
    127                 $("#template_logo_attachment_id").attr('type','hidden');
    128                 $("#template_logo_url").attr('readonly',true);
     32                $("#logo_enabled").closest("tr").css("display", "table-row");
    12933                $("#template_logo_url").closest("tr").css("display", "table-row");
    13034
    13135                // HIDE Youtube ID
    132                 $("#template_youtube_id").attr('disabled','disabled');
    13336                $("#template_youtube_id").closest("tr").css("display", "none");
    13437
     38                // Disable the rest of items
     39                $("input[name=template_font_color]").attr('disabled','disabled');
     40                $("input[name=template_title]").attr('disabled','disabled');
     41                $("input[name=template_title_size]").attr('disabled','disabled');
     42                $("input[name=template_sub_title]").attr('disabled','disabled');
     43                $("input[name=template_sub_title_size]").attr('disabled','disabled');
     44
    13545                // Set default value
    136                 if (is_switch) {
    137                     $("#template_bg_img_url").val($("#plugin_url").val()+"assets/images/template-bg-1.jpg");
     46                $("#template-desc").text("Static background image with your company logo");
     47                if (isSwitch) {
     48                    $("#template_bg_img_url").val($("#plugin_url").text()+"assets/images/template-bg-1.jpg");
    13849                    $("#template_font_color").val("#ffffff");
    139                     $("#template-desc").text("Static background image with your company logo");
    14050                }
    141 
    142                 // Handling to show warning message for free version
    143                 $("#template-free-template").css("display", "table-row");
    144                 $("#template-free-template p").html("Pro template is not included in free version. Please get the <a href='http://codecanyon.net/item/db-error-customizer-manage-database-error-professionally/14715024'>premium</a> version.");
     51                $("input[name=submit_preview], input[name=submit_save]").attr('disabled','disabled');
    14552            } else if (selected_template == "video") {
    14653                // HIDE Bg color
     
    14956
    15057                // HIDE Bg img
    151                 $("#upload_bg_img_button").attr('disabled','disabled');
    152                 $("#template_bg_img_attachment_id").attr('disabled','disabled');
    153                 $("#template_bg_img_url").attr('disabled','disabled');
    154                 $("#template_bg_img_url").closest("tr").css("display", "none");
     58                $(".upload-bg-image-group").css("display", "none");
    15559
    15660                // SHOW Logo
    157                 $("#upload_logo_button").removeAttr('disabled');
    158                 $("#template_logo_attachment_id").removeAttr('disabled');
    159                 $("#template_logo_url").removeAttr('disabled');
    160                 $("#template_logo_attachment_id").attr('type','hidden');
    161                 $("#template_logo_url").attr('readonly',true);
     61                $("#logo_enabled").closest("tr").css("display", "table-row");
    16262                $("#template_logo_url").closest("tr").css("display", "table-row");
    16363
    16464                // SHOW Youtube ID
    165                 $("#template_youtube_id").removeAttr('disabled');
    16665                $("#template_youtube_id").closest("tr").css("display", "table-row");
    16766
     67                // Disable the rest of items
     68                $("input[name=template_font_color]").attr('disabled','disabled');
     69                $("input[name=template_title]").attr('disabled','disabled');
     70                $("input[name=template_title_size]").attr('disabled','disabled');
     71                $("input[name=template_sub_title]").attr('disabled','disabled');
     72                $("input[name=template_sub_title_size]").attr('disabled','disabled');
     73
    16874                // Set default value
    169                 if (is_switch) {
     75                $("#template-desc").text("Full page Youtube video background with your company logo");
     76                if (isSwitch) {
    17077                    $("#template_font_color").val("#ffffff");
    171                     $("#template-desc").text("Full page Youtube video background with your company logo");
    17278                }
    173 
    174                 // Handling to show warning message for free version
    175                 $("#template-free-template").css("display", "table-row");
    176                 $("#template-free-template p").html("Video template is not included in free version. Please get the <a href='http://codecanyon.net/item/db-error-customizer-manage-database-error-professionally/14715024'>premium</a> version.");
    177             } else if (selected_template == "mystery") {
     79                $("input[name=submit_preview], input[name=submit_save]").attr('disabled','disabled');
     80            } else if (selected_template == "mystery"
     81                || selected_template == "snow"
     82                || selected_template == "bubble") {
    17883                // HIDE Bg color
    17984                $("#template_bg_color").attr('disabled','disabled');
     
    18186
    18287                // SHOW Bg img
    183                 $("#upload_bg_img_button").removeAttr('disabled');
    184                 $("#template_bg_img_attachment_id").removeAttr('disabled');
    185                 $("#template_bg_img_url").removeAttr('disabled');
    186                 $("#template_bg_img_attachment_id").attr('type','hidden');
    187                 $("#template_bg_img_url").attr('readonly',true);
    188                 $("#template_bg_img_url").closest("tr").css("display", "table-row");
     88                $(".upload-bg-image-group").css("display", "table-row");
    18989
    19090                // SHOW Logo
    191                 $("#upload_logo_button").removeAttr('disabled');
    192                 $("#template_logo_attachment_id").removeAttr('disabled');
    193                 $("#template_logo_url").removeAttr('disabled');
    194                 $("#template_logo_attachment_id").attr('type','hidden');
    195                 $("#template_logo_url").attr('readonly',true);
     91                $("#logo_enabled").closest("tr").css("display", "table-row");
    19692                $("#template_logo_url").closest("tr").css("display", "table-row");
    19793
    19894                // HIDE Youtube ID
    199                 $("#template_youtube_id").attr('disabled','disabled');
    20095                $("#template_youtube_id").closest("tr").css("display", "none");
    20196
    202                 // Set default value
    203                 if (is_switch) {
    204                     $("#template_bg_img_url").val($("#plugin_url").val()+"assets/images/template-bg-2.jpg");
    205                     $("#template_font_color").val("#ffffff");
    206                     $("#template-desc").text("Interactive moving star with your company logo");
    207                 }
    208 
    209                 // Handling to show warning message for free version
    210                 $("#template-free-template").css("display", "table-row");
    211                 $("#template-free-template p").html("Mystery template is not included in free version. Please get the <a href='http://codecanyon.net/item/db-error-customizer-manage-database-error-professionally/14715024'>premium</a> version.");
    212             } else if (selected_template == "snow") {
    213                 // HIDE Bg color
    214                 $("#template_bg_color").attr('disabled','disabled');
    215                 $("#template_bg_color").closest("tr").css("display", "none");
    216 
    217                 // SHOW Bg img
    218                 $("#upload_bg_img_button").removeAttr('disabled');
    219                 $("#template_bg_img_attachment_id").removeAttr('disabled');
    220                 $("#template_bg_img_url").removeAttr('disabled');
    221                 $("#template_bg_img_attachment_id").attr('type','hidden');
    222                 $("#template_bg_img_url").attr('readonly',true);
    223                 $("#template_bg_img_url").closest("tr").css("display", "table-row");
    224 
    225                 // SHOW Logo
    226                 $("#upload_logo_button").removeAttr('disabled');
    227                 $("#template_logo_attachment_id").removeAttr('disabled');
    228                 $("#template_logo_url").removeAttr('disabled');
    229                 $("#template_logo_attachment_id").attr('type','hidden');
    230                 $("#template_logo_url").attr('readonly',true);
    231                 $("#template_logo_url").closest("tr").css("display", "table-row");
    232 
    233                 // HIDE Youtube ID
    234                 $("#template_youtube_id").attr('disabled','disabled');
    235                 $("#template_youtube_id").closest("tr").css("display", "none");
     97                // Disable the rest of items
     98                $("input[name=template_font_color]").attr('disabled','disabled');
     99                $("input[name=template_title]").attr('disabled','disabled');
     100                $("input[name=template_title_size]").attr('disabled','disabled');
     101                $("input[name=template_sub_title]").attr('disabled','disabled');
     102                $("input[name=template_sub_title_size]").attr('disabled','disabled');
    236103
    237104                // Set default value
    238                 if (is_switch) {
    239                     $("#template_bg_img_url").val($("#plugin_url").val()+"assets/images/template-bg-3.jpg");
    240                     $("#template_font_color").val("#ffffff");
     105                if (selected_template == "mystery") {
     106                    $("#template-desc").text("Interactive moving star with your company logo");
     107                    if (isSwitch) {
     108                        $("#template_bg_img_url").val($("#plugin_url").text()+"assets/images/template-bg-2.jpg");
     109                        $("#template_font_color").val("#ffffff");
     110                    }
     111                } else if (selected_template == "snow") {
    241112                    $("#template-desc").text("Interactive moving snow effect with your company logo");
     113                    if (isSwitch) {
     114                        $("#template_bg_img_url").val($("#plugin_url").text()+"assets/images/template-bg-3.jpg");
     115                        $("#template_font_color").val("#ffffff");
     116                    }
     117                } else if (selected_template == "bubble") {
     118                    $("#template-desc").text("Interactive moving bubble effect with your company logo");
     119                    if (isSwitch) {
     120                        $("#template_bg_img_url").val($("#plugin_url").text()+"assets/images/template-bg-4.jpg");
     121                        $("#template_font_color").val("#ffffff");
     122                    }
    242123                }
    243 
    244                 // Handling to show warning message for free version
    245                 $("#template-free-template").css("display", "table-row");
    246                 $("#template-free-template p").html("Snow template is not included in free version. Please get the <a href='http://codecanyon.net/item/db-error-customizer-manage-database-error-professionally/14715024'>premium</a> version.");
     124                $("input[name=submit_preview], input[name=submit_save]").attr('disabled','disabled');
    247125            } else {
    248126                // SHOW Bg color
     
    251129
    252130                // HIDE Bg img
    253                 $("#upload_bg_img_button").attr('disabled','disabled');
    254                 $("#template_bg_img_attachment_id").attr('disabled','disabled');
    255                 $("#template_bg_img_url").attr('disabled','disabled');
    256                 $("#template_bg_img_url").closest("tr").css("display", "none");
     131                $(".upload-bg-image-group").css("display", "none");
    257132
    258133                // HIDE Logo
    259                 $("#upload_logo_button").attr('disabled','disabled');
    260                 $("#template_logo_attachment_id").attr('disabled','disabled');
    261                 $("#template_logo_url").attr('disabled','disabled');
     134                $("#logo_enabled").closest("tr").css("display", "none");
    262135                $("#template_logo_url").closest("tr").css("display", "none");
    263136
    264137                // HIDE Youtube ID
    265                 $("#template_youtube_id").attr('disabled','disabled');
    266138                $("#template_youtube_id").closest("tr").css("display", "none");
    267139
     140                // Disable the rest of items
     141                $("input[name=template_font_color]").removeAttr('disabled');
     142                $("input[name=template_title]").removeAttr('disabled');
     143                $("input[name=template_title_size]").removeAttr('disabled');
     144                $("input[name=template_sub_title]").removeAttr('disabled');
     145                $("input[name=template_sub_title_size]").removeAttr('disabled');
     146
    268147                // Set default value
    269                 if (is_switch) {
     148                $("#template-desc").text("Basic theme with background color");
     149                if (isSwitch) {
    270150                    $("#template_bg_color").val("#15b5f7");
    271151                    $("#template_font_color").val("#ffffff");
    272                     $("#template-desc").text("Basic theme with background color");
    273152                }
    274 
    275                 // Handling to show warning message for free version
    276                 $("#template-free-template").css("display", "none");
    277             }
    278         }
    279 
    280         /*
    281         **  Core function handle when email alert toggle
    282         */
    283         function coreEmailSwitch() {
    284             if ($("#email_enabled").is(":checked")) {
    285                 // Handling to show warning message for free version
    286                 $("#template-free-email").css("display", "table-row");
    287                 $("#template-free-email p").html("Email alert is not included in free version. Please get the <a href='http://codecanyon.net/item/db-error-customizer-manage-database-error-professionally/14715024'>premium</a> version.");
    288                 $('#email_enabled').attr('checked', false);
    289                 $('#email_enabled').prop('checked', false);
    290             } else {
    291                 $("#email_freq").attr('disabled','disabled');
    292                 $("#email_target").attr('disabled','disabled');
    293                 $("#email_subject").attr('disabled','disabled');
    294                 $("#email_msg").attr('disabled','disabled');
     153                $("input[name=submit_preview], input[name=submit_save]").removeAttr('disabled');
    295154            }
    296155        }
     
    302161            coreSelectSwitch(true);
    303162        });
    304 
    305         /*
    306         **  Handle when email state change
    307         */
    308         jQuery( '#email_enabled' ).on( 'change', function() {
    309             coreEmailSwitch();
    310         });
    311163    });
    312164})( jQuery );
  • db-error-customizer/trunk/db-error-customizer.php

    r1464093 r1574150  
    55Plugin URI:  https://wordpress.org/plugins/db-error-customizer/
    66Description: Allow you to customise a beautiful and useful database error page
    7 Version:     1.3
     7Version:     2.0
    88Author:      Centil Technology
    9 Author URI:  http://centil.co
     9Author URI:  http://dec.centil.co
    1010License:     GPL2
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2020}
    2121
    22 // Construct supported email freq
    23 $email_all_freqs = array("15 Minutes", "1 Hour", "3 Hours", "6 Hours", "12 Hours", "1 Day");
     22// Inlcude common class
     23include_once 'source/setting.php';
     24include_once 'source/builder.php';
    2425
    2526/*
     
    2728 */
    2829function dec_plugin_admin_notices() {
    29     if (!get_option('plugin_activate_notice_shown') && !is_plugin_active(plugin_dir_path(__FILE__).'db-error-customizer.php')) {
     30    if (!get_option('plugin_activate_notice_shown') && !is_plugin_active(Setting::getRootDir().'db-error-customizer.php')) {
    3031        echo "<div class='update-nag'><p>DB Error Customizer is activated but not enabled. Please goto <a href='".admin_url('options-general.php?page=db-error-customizer')."'>DB Error Customizer setting page</a> to proceed setup.</p></div>";
    3132        update_option('plugin_activate_notice_shown', 'true');
     
    4344
    4445    // Delete registered settings
    45     unregister_setting( 'db-error-customizer-settings-group', 'template_select' );
    46     unregister_setting( 'db-error-customizer-settings-group', 'template_bg_color' );
    47     unregister_setting( 'db-error-customizer-settings-group', 'template_bg_img_url' );
    48     unregister_setting( 'db-error-customizer-settings-group', 'template_logo_url' );
    49     unregister_setting( 'db-error-customizer-settings-group', 'template_youtube_id' );
    50     unregister_setting( 'db-error-customizer-settings-group', 'template_font_color' );
    51     unregister_setting( 'db-error-customizer-settings-group', 'template_title' );
    52     unregister_setting( 'db-error-customizer-settings-group', 'template_sub_title' );
    53     unregister_setting( 'db-error-customizer-settings-group', 'email_enabled' );
    54     unregister_setting( 'db-error-customizer-settings-group', 'email_freq' );
    55     unregister_setting( 'db-error-customizer-settings-group', 'email_target' );
    56     unregister_setting( 'db-error-customizer-settings-group', 'email_subject' );
    57     unregister_setting( 'db-error-customizer-settings-group', 'email_msg' );
     46    foreach(Setting::getSettings() as $setting => $configs) {
     47        if ($configs['visibility'] == 'public') {
     48            delete_option( $setting );
     49        }
     50    }
    5851
    5952    // Restore db-error.php to default state
     
    7972 */
    8073function dec_test_server( $mode ) {
     74    $msgErrors = array();
    8175
    8276    // Different condition for different scenario
    83     $is_need_email = false;
    8477    $is_need_preview = false;
    8578    $is_need_save = false;
    8679    $is_need_template = false;
    87 
    88     // Different result
    89     $is_ready_config = false;
    90     $is_ready_preview = false;
    91     $is_ready_save = false;
    92     $is_ready_template = false;
    9380
    9481    // Run different tests based on different test request
     
    9986        $is_need_save = true;
    10087        $is_need_template = true;
    101 
    102         // For Save option, double check if user requested email feature
    103         if (isset($_POST['email_enabled'])
    104             && $_POST['email_enabled']!==''
    105             && isset($_POST['email_target'])
    106             && isset($_POST['email_freq'])
    107             && isset($_POST['email_subject'])
    108             && isset($_POST['email_msg'])) {
    109             $is_need_email = true;
    110         }
    11188    } else {
    11289        // Default test mode to cover all (Except template)
    113         $is_need_email = true;
    11490        $is_need_preview = true;
    11591        $is_need_save = true;
    11692    }
    11793
    118     $msg_config = "";
    119     $msg_preview = "";
    120     $msg_save = "";
    121     $msg_template = "";
    122 
    123     // Run test for email config file
    124     if ($is_need_email) {
    125         if (is_writable(plugin_dir_path(__FILE__)."config.txt")) {
    126             $is_ready_config = true;
    127         } else {
    128             $msg_config = "Not able to write to ".plugin_dir_path(__FILE__)."config.txt. ".
     94    // Run test for preview file
     95    if ($is_need_preview
     96        && !is_writable(Setting::getRootDir()."preview.html")) {
     97        $msgErrors[] = "Not able to write to ".Setting::getRootDir()."preview.html. ".
    12998            "Please temporarily enable <a href='https://codex.wordpress.org/Changing_File_Permissions' target='_blank'>777 write permission</a> to this file to proceed.";
    130         }
    131     }
    132 
    133     // Run test for preview file
    134     if ($is_need_preview) {
    135         if (is_writable(plugin_dir_path(__FILE__)."preview.html")) {
    136             $is_ready_preview = true;
    137         } else {
    138             $msg_preview = "Not able to write to ".plugin_dir_path(__FILE__)."preview.html. ".
    139             "Please temporarily enable <a href='https://codex.wordpress.org/Changing_File_Permissions' target='_blank'>777 write permission</a> to this file to proceed.";
    140         }
    14199    }
    142100
    143101    // Run test for db error file
    144     if ($is_need_save) {
    145         if (is_writable(WP_CONTENT_DIR . "/db-error.php")) {
    146             $is_ready_save = true;
    147         } else {
    148             $msg_save = "Not able to write to ".WP_CONTENT_DIR . "/db-error.php. ".
     102    if ($is_need_save
     103        && !is_writable(WP_CONTENT_DIR . "/db-error.php")) {
     104        $msgErrors[] = "Not able to write to ".WP_CONTENT_DIR . "/db-error.php. ".
    149105            "Please create an empty db-error.php file and temporarily enable <a href='https://codex.wordpress.org/Changing_File_Permissions' target='_blank'>777 write permission</a> to this file to proceed.";
    150         }
    151106    }
    152107
     
    155110        // Sanitize and validate all inputs
    156111        $template_select = sanitize_text_field($_POST['template_select']);
    157         if ($template_select != 'basic'
    158             && $template_select != 'mystery'
    159             && $template_select != 'pro'
    160             && $template_select != 'snow'
    161             && $template_select != 'video') {
     112        if (!in_array($template_select, Setting::getTemplates())) {
    162113            $template_select = 'basic';
    163114        }
    164115
    165         if (is_readable(plugin_dir_path(__FILE__)."templates/".$template_select.".txt")) {
    166             $is_ready_template = true;
    167         } else {
    168             $msg_template = "Not able to read from ".plugin_dir_path(__FILE__)."templates/".$template_select.".txt. ".
    169             "Please enable <a href='https://codex.wordpress.org/Changing_File_Permissions' target='_blank'>644 read permission</a> to this file to proceed.";
     116        if (!is_readable(Setting::getRootDir()."templates/".$template_select.".txt")) {
     117            $msgErrors[] = "Not able to read from ".Setting::getRootDir()."templates/".$template_select.".txt. ".
     118                "Please enable <a href='https://codex.wordpress.org/Changing_File_Permissions' target='_blank'>644 read permission</a> to this file to proceed.";
    170119        }
    171120    }
     
    174123    $status = "pass";
    175124    $msg = "";
    176     if ( $msg_config!="" || $msg_preview!="" || $msg_save!="" || $msg_template!="" ) {
     125    if (count($msgErrors) > 0) {
    177126        $status = "fail";
    178 
    179127        $msg = "<ul>";
    180         if ($msg_config!="") {
    181             $msg .= "<li>".$msg_config."</li>";
    182         }
    183 
    184         if ($msg_preview!="") {
    185             $msg .= "<li>".$msg_preview."</li>";
    186         }
    187 
    188         if ($msg_save!="") {
    189             $msg .= "<li>".$msg_save."</li>";
    190         }
    191 
    192         if ($msg_template!="") {
    193             $msg .= "<li>".$msg_template."</li>";
     128        foreach ($msgErrors as $msgError) {
     129            $msg .= "<li>".$msgError."</li>";
    194130        }
    195131        $msg .= "</ul>";
     
    224160    $info = "";
    225161    $warning = "";
    226     global $email_all_freqs;
    227162
    228163    // Sanitize and validate all inputs
    229164    $input_array = array();
    230     $template_select = null;
    231     if (isset($_POST['template_select'])) {
    232         $template_select = sanitize_text_field($_POST['template_select']);
    233         if ($template_select != 'basic'
    234             && $template_select != 'mystery'
    235             && $template_select != 'pro'
    236             && $template_select != 'snow'
    237             && $template_select != 'video') {
    238             $template_select = 'basic';
    239         }
    240         $input_array['template_select'] = $template_select;
    241     }
    242     $template_bg_color = null;
    243     if (isset($_POST['template_bg_color'])) {
    244         $template_bg_color = sanitize_text_field($_POST['template_bg_color']);
    245         if (!preg_match("/#([a-fA-F0-9]{3}){1,2}\b/", $template_bg_color)) {
    246             $template_bg_color = '#15b5f7';
    247         }
    248         $input_array['template_bg_color'] = $template_bg_color;
    249     }
    250     $template_bg_img_attachment_id = null;
    251     if (isset($_POST['template_bg_img_attachment_id'])) {
    252         $template_bg_img_attachment_id = intval($_POST['template_bg_img_attachment_id']);
    253         if (!$template_bg_img_attachment_id) {
    254             $template_bg_img_attachment_id = '';
    255         }
    256         $input_array['template_bg_img_attachment_id'] = $template_bg_img_attachment_id;
    257     }
    258     $template_bg_img_url = null;
    259     if (isset($_POST['template_bg_img_url'])) {
    260         $template_bg_img_url = esc_url_raw($_POST['template_bg_img_url']);
    261         if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $template_bg_img_url)) {
    262             $template_bg_img_url = plugins_url( 'assets/images/template-bg-1.jpg',  __FILE__ );
    263         }
    264         $input_array['template_bg_img_url'] = $template_bg_img_url;
    265     }
    266     $template_logo_attachment_id = null;
    267     if (isset($_POST['template_logo_attachment_id'])) {
    268         $template_logo_attachment_id = intval($_POST['template_logo_attachment_id']);
    269         if (!$template_logo_attachment_id) {
    270             $template_logo_attachment_id = '';
    271         }
    272         $input_array['template_logo_attachment_id'] = $template_logo_attachment_id;
    273     }
    274     $template_logo_url = null;
    275     if (isset($_POST['template_logo_url'])) {
    276         $template_logo_url = esc_url_raw($_POST['template_logo_url']);
    277         if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $template_logo_url)) {
    278             $template_logo_url = plugins_url( 'assets/images/template-logo-1.png', __FILE__ );
    279         }
    280         $input_array['template_logo_url'] = $template_logo_url;
    281     }
    282     $template_youtube_id = null;
    283     if (isset($_POST['template_youtube_id'])) {
    284         $template_youtube_id = sanitize_text_field($_POST['template_youtube_id']);
    285         $input_array['template_youtube_id'] = $template_youtube_id;
    286     }
    287     $template_font_color = null;
    288     if (isset($_POST['template_font_color'])) {
    289         $template_font_color = sanitize_text_field($_POST['template_font_color']);
    290         if (!preg_match("/#([a-fA-F0-9]{3}){1,2}\b/", $template_font_color)) {
    291             $template_font_color = '#15b5f7';
    292         }
    293         $input_array['template_font_color'] = $template_font_color;
    294     }
    295     $template_title = null;
    296     if (isset($_POST['template_title'])) {
    297         $template_title = sanitize_text_field($_POST['template_title']);
    298         $input_array['template_title'] = $template_title;
    299     }
    300     $template_sub_title = null;
    301     if (isset($_POST['template_sub_title'])) {
    302         $template_sub_title = sanitize_text_field($_POST['template_sub_title']);
    303         $input_array['template_sub_title'] = $template_sub_title;
    304     }
    305     $email_enabled = null;
    306     if (isset($_POST['email_enabled'])) {
    307         $email_enabled = 'checked';
    308         $input_array['email_enabled'] = $email_enabled;
    309     }
    310     $email_freq = null;
    311     if (isset($_POST['email_freq'])) {
    312         $email_freq = sanitize_text_field($_POST['email_freq']);
    313         if (!in_array($email_freq, $email_all_freqs)) {
    314             $email_freq = "1 Hour";
    315         }
    316         $input_array['email_freq'] = $email_freq;
    317     }
    318     $email_target = null;
    319     if (isset($_POST['email_target'])) {
    320         $email_target = sanitize_email($_POST['email_target']);
    321         if (!is_email($email_target)) {
    322             $email_target = get_option('admin_email', '');
    323         }
    324         $input_array['email_target'] = $email_target;
    325     }
    326     $email_subject = null;
    327     if (isset($_POST['email_subject'])) {
    328         $email_subject = sanitize_text_field($_POST['email_subject']);
    329         $input_array['email_subject'] = $email_subject;
    330     }
    331     $email_msg = null;
    332     if (isset($_POST['email_msg'])) {
    333         $email_msg = sanitize_text_field($_POST['email_msg']);
    334         $input_array['email_msg'] = $email_msg;
     165
     166    foreach (Setting::getSettings() as $setting => $configs) {
     167        $input = null;
     168        if (isset($_POST[$setting])) {
     169            // Sanitize input
     170            switch($configs['type']) {
     171                case 'text':
     172                    $input = sanitize_text_field($_POST[$setting]);
     173                    break;
     174                case 'integer':
     175                    $input = intval($_POST[$setting]);
     176                    break;
     177                case 'url':
     178                    $input = esc_url_raw($_POST[$setting]);
     179                    break;
     180                case 'checkbox':
     181                    $input = 'checked';
     182                    break;
     183                case 'email':
     184                    $input = sanitize_email($_POST[$setting]);
     185                    break;
     186                default:
     187                    die("INTERNAL ERROR: TYPE => ".$configs['type']);
     188            }
     189
     190            // Validate input
     191            switch($configs['validate']) {
     192                case 'in_templates':
     193                    if (!in_array($input, Setting::getTemplates())) {
     194                        $input = $configs['default'];
     195                    }
     196                    break;
     197                case 'in_email_freqs':
     198                    if (!in_array($input, Setting::getEmailFreqs())) {
     199                        $input = $configs['default'];
     200                    }
     201                    break;
     202                case 'preg_match':
     203                    if (!preg_match($configs['match'], $input)) {
     204                        if ($configs['type'] == 'url') {
     205                            $input = plugins_url( $configs['default'],  __FILE__ );
     206                        } else {
     207                            $input = $configs['default'];
     208                        }
     209                    }
     210                    break;
     211                case 'is_email':
     212                    if (!is_email($input)) {
     213                        $input = get_option($configs['default'], '');
     214                    }
     215                    break;
     216                case 'empty':
     217                    if (!input) {
     218                        $input = $configs['default'];
     219                    }
     220                    break;
     221                default:
     222                    die("INTERNAL ERROR: VALIDATE => ".$configs['validate']);
     223            }
     224
     225            $input_array[$setting] = $input;
     226
     227            if (isset($_POST['submit_save'])
     228                && $configs['visibility']=='public') {
     229                update_option($setting, $input);
     230            }
     231        } else if ($_POST && $configs['type'] == 'checkbox') {
     232            $input_array[$setting] = '';
     233
     234            if (isset($_POST['submit_save'])
     235                && $configs['visibility']=='public') {
     236                update_option($setting, $input);
     237            }
     238        }
    335239    }
    336240
     
    347251        check_admin_referer( 'submit_preview_save_'.get_current_user_id() );
    348252
    349         // Save all options
    350         if (isset($template_select)) {
    351             update_option('template_select', $template_select);
    352         }
    353         if (isset($template_bg_color)) {
    354             update_option('template_bg_color', $template_bg_color);
    355         }
    356         if (isset($template_bg_img_url)) {
    357             update_option('template_bg_img_url', $template_bg_img_url);
    358         }
    359         if (isset($template_logo_url)) {
    360             update_option('template_logo_url', $template_logo_url);
    361         }
    362         if (isset($template_youtube_id)) {
    363             update_option('template_youtube_id', $template_youtube_id);
    364         }
    365         if (isset($template_font_color)) {
    366             update_option('template_font_color', $template_font_color);
    367         }
    368         if (isset($template_title)) {
    369             update_option('template_title', $template_title);
    370         }
    371         if (isset($template_sub_title)) {
    372             update_option('template_sub_title', $template_sub_title);
    373         }
    374         if (isset($email_enabled)) {
    375             update_option('email_enabled', $email_enabled);
    376         } else {
    377             update_option('email_enabled', '');
    378         }
    379         if (isset($email_freq)) {
    380             update_option('email_freq', $email_freq);
    381         }
    382         if (isset($email_target)) {
    383             update_option('email_target', $email_target);
    384         }
    385         if (isset($email_subject)) {
    386             update_option('email_subject', $email_subject);
    387         }
    388         if (isset($email_msg)) {
    389             update_option('email_msg', $email_msg);
    390         }
    391 
    392253        // Run testing for save
    393254        $result = dec_test_server( "save" );
    394255        if ($result['status'] == "pass") {
    395256            // Proceed to write to db-error.php
    396             $result = dec_template_generator(false, $input_array);
     257            $result = Builder::dec_template_generator(false, $input_array);
    397258        }
    398259    } else if (isset($_POST['submit_preview'])) {
     
    404265        if ($result['status'] == "pass") {
    405266            // Proceed to preview
    406             $result = dec_template_generator(true, $input_array);
     267            $result = Builder::dec_template_generator(true, $input_array);
    407268        }
    408269    }
     
    415276
    416277    // Load supported template
    417     $templates = glob(plugin_dir_path(__FILE__)."templates/*.txt");
    418 
    419     include 'admin-menu.php';
    420 }
    421 
    422 /*
    423  * Templating - Header
    424  */
    425 function dec_template_header() {
    426     $header = "<?php\n";
    427     $header .= "// DB Error Customizer - By Centil.co\n";
    428     $header .= "\$protocol = \$_SERVER['SERVER_PROTOCOL'];\n";
    429     $header .= "if ( 'HTTP/1.1' != \$protocol && 'HTTP/1.0' != \$protocol ) \$protocol = 'HTTP/1.0';\n";
    430     $header .= "header( \"\$protocol 503 Service Unavailable\", true, 503 );\n";
    431     $header .= "header( 'Content-Type: text/html; charset=utf-8' );\n";
    432     $header .= "header( 'Retry-After: 600' );\n\n";
    433     $header .= "if ( !function_exists( 'add_action' ) ) {\n";
    434     $header .= "\techo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';\n";
    435     $header .= "\texit;\n";
    436     $header .= "}\n";
    437     $header .= "?>\n";
    438 
    439     return $header;
    440 }
    441 
    442 /*
    443  * Templating Generator
    444  */
    445 function dec_template_generator($is_preview = false, $fields) {   
    446 
    447     // Special handling for free version to avoid processing other template
    448     if ($fields['template_select'] != "basic") {
    449         return array(
    450             "status"=>"fail",
    451             "msg"=>ucwords($fields['template_select'])." template is not supported in free version. Please get the <a href='http://codecanyon.net/item/db-error-customizer-manage-database-error-professionally/14715024'>Premium version</a> to proceed."
    452         );
    453     }
    454 
    455     // Special handling when it is in not in preview mode. Where email alert may send
    456     $header = "";
    457     if (! $is_preview) {
    458         $header = dec_template_header();
    459     }
    460 
    461     $fh = fopen(plugin_dir_path(__FILE__)."templates/".$fields['template_select'].".txt", 'r');
    462     $content = fread($fh, filesize(plugin_dir_path(__FILE__)."templates/".$fields['template_select'].".txt"));
    463     fclose($fh);
    464 
    465     $content = str_replace("{{SITE_NAME}}", get_bloginfo("name"), $content);
    466     $content = str_replace("{{PLUGIN_URL}}", plugins_url( '/', __FILE__ ), $content);       
    467     if (array_key_exists('template_bg_color', $fields)) {
    468         $content = str_replace("{{BG_COLOR}}", $fields['template_bg_color'], $content);
    469     }
    470     if (array_key_exists('template_bg_img_url', $fields)) {
    471         $content = str_replace("{{BG_IMG_URL}}", $fields['template_bg_img_url'], $content);
    472     }
    473     if (array_key_exists('template_logo_url', $fields)) {
    474         $content = str_replace("{{LOGO_URL}}", $fields['template_logo_url'], $content);
    475     }
    476     if (array_key_exists('template_youtube_id', $fields)) {
    477         $content = str_replace("{{YOUTUBE_ID}}", $fields['template_youtube_id'], $content);
    478     }
    479     if (array_key_exists('template_font_color', $fields)) {
    480         $content = str_replace("{{FONT_COLOR}}", $fields['template_font_color'], $content);
    481     }
    482     if (array_key_exists('template_title', $fields)) {
    483         $content = str_replace("{{TITLE}}", $fields['template_title'], $content);
    484     }
    485     if (array_key_exists('template_sub_title', $fields)) {
    486         $content = str_replace("{{SUB_TITLE}}", $fields['template_sub_title'], $content);
    487     }
    488     if (array_key_exists('email_enabled', $fields) && $fields['email_enabled']!=='' && array_key_exists('email_target', $fields)) {
    489         $content = str_replace("{{EMAIL_TARGET}}", $fields['email_target'], $content);
    490     }
    491 
    492     // If preview, target write into internal preview php file
    493     $file_target = WP_CONTENT_DIR . "/db-error.php";
    494     if ( $is_preview ) {
    495         $file_target = plugin_dir_path(__FILE__)."preview.html";
    496     }
    497 
    498     // Write content to target file
    499     $fh = fopen($file_target, 'w');
    500     fputs($fh, $header . $content);
    501     fclose($fh);
    502 
    503     // Write success. Show status message
    504     if ( $is_preview ) {
    505         return array(
    506             "status"=>"pass",
    507             "msg"=>"Preview page generated successfully! Click <a href='".plugins_url( 'preview.html', __FILE__ )."' target='_blank'>Preview</a> to proceed."
    508         );
    509     } else {
    510         return array(
    511             "status"=>"pass",
    512             "msg"=>"DB error page created/updated successfully!<br><i>Note: If you modified db-error.php file permission earlier, please remember to restore it to 644.</i>"
    513         );
    514     }
    515 }
    516 
    517 /*
    518  * Plugin settings registration
    519  */
    520 function dec_plugin_settings() {
    521     register_setting( 'db-error-customizer-settings-group', 'template_select' );
    522     register_setting( 'db-error-customizer-settings-group', 'template_bg_color' );
    523     register_setting( 'db-error-customizer-settings-group', 'template_bg_img_url' );
    524     register_setting( 'db-error-customizer-settings-group', 'template_logo_url' );
    525     register_setting( 'db-error-customizer-settings-group', 'template_youtube_id' );
    526     register_setting( 'db-error-customizer-settings-group', 'template_font_color' );
    527     register_setting( 'db-error-customizer-settings-group', 'template_title' );
    528     register_setting( 'db-error-customizer-settings-group', 'template_sub_title' );
    529     register_setting( 'db-error-customizer-settings-group', 'email_enabled' );
    530     register_setting( 'db-error-customizer-settings-group', 'email_freq' );
    531     register_setting( 'db-error-customizer-settings-group', 'email_target' );
    532     register_setting( 'db-error-customizer-settings-group', 'email_subject' );
    533     register_setting( 'db-error-customizer-settings-group', 'email_msg' );
    534 }
    535 add_action( 'admin_init', 'dec_plugin_settings' );
     278    $templates = glob(Setting::getRootDir()."templates/*.txt");
     279
     280    include 'source/admin-menu.php';
     281}
    536282?>
  • db-error-customizer/trunk/readme.txt

    r1464093 r1574150  
    44Tags: alert, connection error, customization, database down, database error, email alert, monitor, responsive, template, website down
    55Requires at least: 3.0.1
    6 Tested up to: 4.5.3
    7 Stable tag: trunk
     6Tested up to: 4.7.1
     7Stable tag: 2.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1515Database not responding is a very common issue in hosting a WordPress website. Instead of showing a blank page with an error message **Error establishing a database connection**, DB Error Customizer helps you to handle it professionally. Not only you can easily customize a beautifully designed database error page using our predefined templates, it tells your visitors that everything is under control.
    1616
     17> ### Premium Support
     18> Our team does not always provide active support for the DB Error Customizer plugin on the WordPress.org. One-on-one email support is available to people who bought the [DB Error Customizer Premium](http://dec.centil.co) plugin only.
     19>
     20> Note that the DB Error Customizer Premium plugin has many extra features too, including beautifully designed templates, animation effects and auto email alert. It might be well worth your investment!
     21
    1722Below are the features of DB Error Customizer:
    1823
    19 * Comes with 5 predefined templates:
    20    * [Basic](http://demo.centil.co/db-error-customizer/basic.html) (Customizable error message, background & font color)
    21    * Pro (Customizable error message, logo and background image & font color. Premium version only)
    22    * Mystery (Customizable error message, logo, background image & font color. Premium version only)
    23    * Snow (Customizable error message, logo, background image & font color. Premium version only)
    24    * Video (Customizable error message, logo, background video & font color. Premium version only)
     24* Comes with basic templates and allows you to customize:
     25   * Main message to show your visitor, instead of standard error
     26   * Sub message below main message
     27   * Font size adjustment
     28   * Font color adjustment
     29   * Background color
    2530* Preview customized output before saving
    2631* Inform search engine that the error page is temporarily (HTTP 500 Internal Server Error header) and it should not cache it
    27 * Auto send email alert to your admin when a visitor sees this error (Premium version only)
    28 * Customizable email alert (Email target, subject, content. Premium version only)
    29 * Email alert spam prevention by allowing you to set how often you should receive an email alert. (Premium version only)
    3032
    3133== Installation ==
     
    3335Please refer the official [WordPress Plugin Installation Guide](https://codex.wordpress.org/Managing_Plugins#Installing_Plugins) to proceed. After you've installed and enabled DB Error Customizer, you shall goto **Settings->DB Error Customizer** to customize and setup the error page.
    3436
    35 *Note: If you installed an older version earlier, please disable the plugin and remove it before installing a newer version.*
     37*Note: If you installed an older/premium version earlier, please disable the plugin and remove it before installing a newer version.*
    3638
    3739== Customize DB Error Page ==
     
    4244* **Background Color:** Change background color via color picker.
    4345* **Font Color:** Change main/sub title color via color picker.
    44 * **Background Image:** Not available in free version.
    45 * **Logo:** Change company logo. Recommend to use PNG with width around 200px and height around 200px. You can upload a new image or select an existing one from WordPress Media.
    46 * **Youtube ID:** Not available in free version.
    4746* **Main Title:** The main title of database error page.
     47* **Main Title Size:** The size of main title.
    4848* **Sub Title:** The sub title of database error page.
     49* **Sub Title Size:** The size of sub title.
    4950
    5051**Preview:** When you press Preview button at the bottom of dashboard, a message box will apear at the top of dashboard with message Preview page generated successfully! Click Preview to proceed. You can press the Preview link to launch the preview page.
     
    5859
    5960= How can I check if DB Error Customizer can work on my server? =
    60 In latest release, we've introduced a new feature to allow user to test their server compatibility. You can run the test by pressing Check Compatibility button at the admin page.
     61There is a feature to allow user to test their server compatibility. You can run the test by pressing Check Compatibility button at the admin page.
    6162
    6263= There is an error when I try to preview or setup database error page =
     
    6970* Manually set invalid database configuration in your wp-config.php. Please remember to revert to original setting once you are done.
    7071
    71 = I've enabled email alert feature. However there is no email alert when my database is down =
    72 There are a few possibilities causing this:
    73 
    74 * First, please [check if your website PHP mail() function is working](https://easyengine.io/tutorials/php/test-email-sending/). If your server is using SMTP to send email, please let us know and we'll enhance the plugin to support SMTP email sending.
    75 * Second, make sure your [plugin path]/config.txt file is with [777 permission](https://codex.wordpress.org/Changing_File_Permissions).
    76 * Lastly, it might just because nobody visits your site to trigger the email alert during database down(The plugin requires a user visit to trigger email sending).
    77 
    7872== Support ==
    7973Please refer the developer's site at [Centil Technology](http://centil.co). If you would like to provide feedback/contact or just drop us an email, please feel free to contact us at info[at]centil[dot]co
    8074
    8175== Changelog ==
     76
     77= 2.0 =
     78* Major refactoring and bug fixes
     79* Tested with WordPress 4.7.1
    8280
    8381= 1.3 =
  • db-error-customizer/trunk/templates/basic.txt

    r1371180 r1574150  
    4242
    4343            .title {
    44                 font-size: 96px;
     44                font-size: {{TITLE_SIZE}}px;
    4545            }
    4646
    4747            .sub-title {
    48                 font-size: 36px;
     48                font-size: {{SUB_TITLE_SIZE}}px;
    4949            }
    5050
  • db-error-customizer/trunk/templates/mystery.txt

    r1371180 r1574150  
    1 FREE VERSION
     1--- NA ---
  • db-error-customizer/trunk/templates/pro.txt

    r1371180 r1574150  
    1 FREE VERSION
     1--- NA ---
  • db-error-customizer/trunk/templates/snow.txt

    r1371180 r1574150  
    1 FREE VERSION
     1--- NA ---
  • db-error-customizer/trunk/templates/video.txt

    r1371180 r1574150  
    1 FREE VERSION
     1--- NA ---
Note: See TracChangeset for help on using the changeset viewer.