WordPress.org

Plugin Directory

Changeset 995138


Ignore:
Timestamp:
09/23/14 04:14:53 (3 years ago)
Author:
rhj4
Message:

Updated demo code and tested in absence of rhj4-diagnostics

Location:
rhj4-notifications/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • rhj4-notifications/trunk/css/rhj4-notifications.css

    r993970 r995138  
    88    Author     : Bob Jones 
    99*/ 
    10 table.rhj4_plugins_demo { 
     10.rhj4_plugins_demo { 
    1111   background-color: lightgray; 
    1212   border: 1px solid black; 
     13   width: 400px; 
     14   padding-top: 8px; 
     15   padding-bottom: 8px; 
     16   padding-left: 8px; 
     17   padding-right: 8px; 
    1318} 
    1419 
     
    2833    margin-left: 8px; 
    2934    margin-right: 10px; 
     35    vertical-align: top; 
    3036} 
    3137 
     
    4147 
    4248.rhj4_plugins_demo td { 
    43     vertical-align: middle; 
     49    vertical-align: top; 
    4450    color:black; 
     51} 
     52 
     53.rhj4_radio, .rhj4_checkbox { 
     54    height:18px; 
     55    width: 18px; 
     56} 
     57 
     58.rhj4_plugins_shortcode td { 
     59    vertical-align: top; 
    4560} 
    4661 
     
    5065 
    5166.rhj4_plugins_buttons { 
    52     background-color: silver; 
     67   background-color: silver; 
     68   border: 1px solid black; 
     69   margin-top: 15px; 
     70} 
     71 
     72.rhj4_plugin_log { 
     73    vertical-align: top; 
     74} 
     75 
     76.rhj4_plugin_buttons { 
     77    margin-top: 15px; 
    5378} 
    5479 
  • rhj4-notifications/trunk/include/demo.php

    r993970 r995138  
    11<div> 
    2     <table class='rhj4_plugins_demo'> 
     2    <table> 
    33        <tbody> 
    44        <tr> 
    5             <td class='rhj4_plugins_input'>Text: <input id="messageText" type="text" placeholder='Message text...'/></td> 
    6             <td class='rhj4_plugins_comment'>Enter notification text</td> 
    7         </tr> 
    8         <tr> 
    9             <td class='rhj4_plugins_input'>Type: 
    10                 <select id="messageType"> 
     5            <td> 
     6                <div class="rhj4_plugins_demo"> 
     7                    <table> 
     8                        <tr> 
     9                            <td> 
     10                            Text: <input id="messageText" type="text" placeholder='Enter notification text...'/></td> 
     11                        </tr>    
     12                        <tr> 
     13                            <td class='rhj4_plugins_input'>Type: <select id="messageType"> 
    1114<?php 
    1215                //  Get list of currently enabled notification types 
    1316                $notif = RHJ4Notifications::instance(); 
    14                  
     17 
    1518                // Get defaults array - this defines the notification types 
    1619                $types = $notif->defaults; 
     
    3235                echo $options; 
    3336?> 
    34                 </select> 
     37                                </select> 
     38                            </td> 
     39                        </tr> 
     40                        <tr> 
     41                            <td class='rhj4_plugins_input'> 
     42                                <span>Browser:<input name="messageSource" type="radio" value="browser" class='rhj4_radio' /></span> 
     43                                <span>Server:<input name="messageSource" type="radio" value="server" class='rhj4_radio' checked="checked" /> 
     44                            </td> 
     45                        </tr> 
     46                        <tr>          
     47                            <td class='rhj4_plugins_input'>Sticky: 
     48                                <input id="messageIsSticky" type="checkbox" class="rhj4_checkbox" /> 
     49                        Auto-Drain: 
     50                                <input id="autoDrainQueue" type="checkbox" class="rhj4_checkbox" /></td> 
     51                        </tr>        
     52                    </table> 
     53                </div> 
     54                <div> 
     55                    <table class='rhj4_plugins_buttons'> 
     56                        <tr><td>Generate Notifications:  
     57                            <input type="button" value="Single" onclick="do_notification_submit();return false;" /> 
     58                            <input type="button" value="Multiple" onclick="do_notification_submit_all();return false;" /> 
     59                            <span id="queue_size"></span> 
     60                            <input id="drain" type="button" value="Drain Queue" onclick="do_notification_drain_queue();return false;"/> 
     61                            <span id='queuing' class='blink'>Queuing...</span> 
     62                            <input type="button" value="Clear" onclick="do_clear_diagnostic_log();return false;" /> 
     63                            </td> 
     64                        </tr> 
     65                    </table> 
     66                </div> 
     67                </td> 
     68            <td> 
     69                <div class="rhj4_plugins_log"> 
     70<?php 
     71        if (is_plugin_active('rhj4-diagnostics/rhj4_diagnostics.php')) { 
     72            $diags = RHJ4Diagnostics::instance(); 
     73            echo $diags->show();  
     74        } else { 
     75            echo "This demonstration requires the RHJ4 Diagnostics plugin which is not currently enabled."; 
     76        } 
     77?>         
     78                </div> 
    3579            </td> 
    36             <td class='rhj4_plugins_comment'>Select notification type</td> 
    3780        </tr> 
    38         <tr> 
    39             <td class='rhj4_plugins_input'>Source: 
    40                 <span>Browser:<input name="messageSource" type="radio" value="browser" /></span> 
    41                 <span>Server:<input name="messageSource" type="radio" value="server" checked="checked" /> 
    42             </td> 
    43             <td class='rhj4_plugins_comment'>Select notification source</td> 
    44         </tr> 
    45         <tr>          
    46             <td class='rhj4_plugins_input'>Sticky: 
    47                 <input id="messageIsSticky" type="checkbox" /></td>       
    48             <td class='rhj4_plugins_comment'>Check if notification should remain on screen</td></tr>          
    49         <tr><td class='rhj4_plugins_input'>Auto-Drain: 
    50                 <input id="autoDrainQueue" type="checkbox" /> 
    51             <td class='rhj4_plugins_comment'>Check if queue should be drained immediately</td></tr>      
    5281    </table> 
    53     <table class='rhj4_plugins_buttons'> 
    54         <tr><td>Generate Notifications:  
    55             <input type="button" value="Single" onclick="do_notification_submit();return false;" /> 
    56             <input type="button" value="Multiple" onclick="do_notification_submit_all();return false;" /> 
    57             <span id="queue_size"></span> 
    58             <input id="drain" type="button" value="Drain Queue" onclick="do_notification_drain_queue();return false;"/> 
    59             <span id='queuing' class='blink'>Queuing...</span> 
    60         </td></tr></table> 
    6182</div> 
    6283<hr /> 
     
    7798                'source'        => 'Notification Demo'); 
    7899    //  Initialize the plugin 
    79     $diags = RHJ4Diagnostics::instance(); 
     100    if (is_plugin_active('rhj4-diagnostics/rh4_diagnostics.php')) { 
     101        $diags = RHJ4Diagnostics::instance(); 
    80102     
    81     // Set error handler to process all errors 
    82     error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); 
    83     set_error_handler(array($diags,'error_handler')); 
     103        // Set error handler to process all errors 
     104        error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); 
     105        set_error_handler(array($diags,'error_handler')); 
     106    } 
    84107     
    85108    //  Write the plugin name into the output stream 
  • rhj4-notifications/trunk/js/demo.js

    r993970 r995138  
    1717            check_for_autodrain(); 
    1818            do_notification_check_queue(); 
     19            do_show_diagnostic_log(); 
    1920        }); 
    2021     
    2122} 
    2223 
     24function do_show_diagnostic_log() { 
     25    jQuery.diagnostic.show(function(data) { 
     26        jQuery('.plugin_log').html(data); 
     27    }); 
     28} 
     29 
     30function do_clear_diagnostic_log() { 
     31    jQuery.diagnostic.clear(function(data) { 
     32        jQuery('.plugin_log').html(data); 
     33    }); 
     34} 
     35 
    2336function do_notification_submit_single(messageText, messageType, messageIsSticky, handler) { 
    2437    var messageSource = jQuery("input:radio[name='messageSource']:checked").val(); 
    25     jQuery.diagnostic('Type: ' + messageType + ', Source: ' + messageSource + ', Sticky: ' + messageIsSticky + ':[' + messageText + ']', 'notification demo.single'); 
    26     if (messageSource === 'browser') { 
    27         jQuery.notification(messageText, messageType, messageIsSticky); 
    28     } else { 
    29         jQuery.diagnostic('saving message to server', 'notification demo'); 
    30         jQuery.notification.save( 
    31             messageText, messageType, messageIsSticky, 
    32             function(result) { 
    33                 if (handler) { 
    34                     handler(result); 
    35                 } 
     38    try { 
     39        jQuery.diagnostic('Type: ' + messageType + ', Source: ' + messageSource + ', Sticky: ' + messageIsSticky + ':[' + messageText + ']', 'notification demo.single'); 
     40        if (messageSource === 'browser') { 
     41            jQuery.notification(messageText, messageType, messageIsSticky); 
     42        } else { 
     43            jQuery.diagnostic('saving message to server', 'notification demo'); 
     44        } 
     45    } catch (err) { 
     46    } 
     47    jQuery.notification.save( 
     48        messageText, messageType, messageIsSticky, 
     49        function(result) { 
     50            if (handler) { 
     51                handler(result); 
    3652            } 
    37         ); 
    38     } 
     53        } 
     54    ); 
    3955} 
    4056 
     
    152168 
    153169jQuery(document).ready(function (jQuery) { 
    154     jQuery.diagnostic('Notifications Demo loaded','notification demo'); 
     170    try { 
     171        jQuery.diagnostic('Notifications Demo loaded','notification demo'); 
     172    } catch (err) { 
     173    } 
     174     
    155175    hide_queuing(); 
    156176    hide_queue(); 
  • rhj4-notifications/trunk/js/jquery.notifications.js

    r993970 r995138  
    539539        catch (err) { 
    540540            //Handle errors here 
    541             $.diagnostic('Notifications Error: ' + err, 'jGrowl'); 
    542541            return -1; 
    543542        } 
  • rhj4-notifications/trunk/readme.htm

    r994700 r995138  
    7373 
    7474        <h3>Description</h3> 
    75     <p>RHJ4 Notifications solves a problem that has plagued programmers for years: How to communicate with users in a clean, clear and visually consistent fashion regardless of where in the program the message originates.</p> 
     75    <p>RHJ4 Notifications and its sibling, RHJ4 Diagnostics solve problems that have plagued programmers for years: How to communicate with users in a clean, clear and visually consistent fashion regardless of where in the program the message originates.</p> 
    7676 
    7777<p>A notification message can be sent from jQuery code in the browser or from PHP code in the server. Either type of message can be displayed immediately or queued for display after the next page turn.</p> 
     
    133133    <h3>Upgrade Notice</h3> 
    134134    <dl> 
     135                <dt>1.2</dt> 
     136                <dd>Overhauled demo.php to use AJAX calls to RHJ4 Diagnostics. It now displays the current Diagnostic log file updates as they happen.</dd> 
     137                <dt>1.12</dt> 
     138                <dd>Very small cosmetic fixes.</dd> 
    135139        <dt>1.0</dt> 
    136140        <dd>Initial version</dd> 
    137                 <dt>1.12</dt> 
    138                 <dd>Very small cosmetic fixes.</dd> 
    139141    </dl> 
    140142 
  • rhj4-notifications/trunk/readme.txt

    r994700 r995138  
    1313== Description == 
    1414 
    15 RHJ4 Notifications solves a problem that has plagued programmers for years: How to communicate with users in a clean, clear and visually consistent fashion regardless of where in the program the message originates. 
     15RHJ4 Notifications and its sibling, RHJ4 Diagnostics solve problems that have plagued programmers for years: How to communicate with users in a clean, clear and visually consistent fashion regardless of where in the program the message originates. 
    1616 
    1717A notification message can be sent from jQuery code in the browser or from PHP code in the server. Either type of message can be displayed immediately or queued for display after the next page turn. 
     
    6868==  Changelog == 
    6969 
     70= 1.2 = 
     71 
     72Overhauled demo.php to use AJAX calls to RHJ4 Diagnostics. It now displays the current Diagnostic log file updates as they happen. 
     73 
     74= 1.12 =  
     75 
     76Very small cosmetic fixes. 
     77 
    7078= 1.1 = 
    7179 
    7280Completed testing and documentation. First public release. 
    73  
    74 = 1.12 =  
    75  
    76 Very small cosmetic fixes. 
    7781 
    7882== Upgrade Notice == 
  • rhj4-notifications/trunk/rhj4_notifications.php

    r994700 r995138  
    44Plugin URI: http://bellinghamwordpressdevelopers.com/donate/ 
    55Description: Integrates jGrowl jQuery plugin into WordPress, enabling creation of jGrowl messages from anywhere in the code. 
    6 Version: 1.12 
     6Version: 1.2 
    77Author: Bob Jones 
    88Author Email: bob@rhj4.com 
     
    160160        $this->register_scripts_and_styles(); 
    161161 
    162             /** 
    163              * Generate hidden fields required to connect with server code 
    164              */ 
    165             add_action('wp_head', 'rhj4_notifications_generate_hidden_inputs'); 
    166  
    167             /** 
    168              * Enable saving of notifications from javaScript code 
    169              */ 
    170             add_action('wp_ajax_nopriv_rhj4_notifications_save','rhj4_notifications_save'); 
    171  
    172             /** 
    173  
    174              * Enable listing of session notifications 
    175              */ 
    176             add_action('wp_ajax_nopriv_rhj4_notifications_list_by_session','rhj4_notifications_list_by_session'); 
    177             add_action('wp_ajax_nopriv_rhj4_notifications_session_queue_size','rhj4_notifications_session_queue_size'); 
    178  
    179             add_action('wp_ajax_nopriv_rhj4_notifications_delete_by_session','rhj4_notifications_delete_by_session'); 
    180  
    181             /** 
    182              * Enable return of plugin url 
    183              */ 
    184             add_action('wp_ajax_nopriv_rhj4_notifications_plugin_url','rhj4_notifications_plugin_url'); 
    185  
    186             /** 
    187              * Enable return of session id 
    188              */ 
    189             add_action('wp_ajax_nopriv_rhj4_notifications_session_id','rhj4_notifications_session_id'); 
    190                 //this will run when on the frontend 
     162        /** 
     163         * Generate hidden fields required to connect with server code 
     164         */ 
     165        add_action('wp_head', 'rhj4_notifications_generate_hidden_inputs'); 
     166 
     167        /** 
     168         * Enable saving of notifications from javaScript code 
     169         */ 
     170        add_action('wp_ajax_nopriv_rhj4_notifications_save','rhj4_notifications_save'); 
     171 
     172        /** 
     173 
     174         * Enable listing of session notifications 
     175         */ 
     176        add_action('wp_ajax_nopriv_rhj4_notifications_list_by_session','rhj4_notifications_list_by_session'); 
     177        add_action('wp_ajax_nopriv_rhj4_notifications_session_queue_size','rhj4_notifications_session_queue_size'); 
     178 
     179        add_action('wp_ajax_nopriv_rhj4_notifications_delete_by_session','rhj4_notifications_delete_by_session'); 
     180 
     181        /** 
     182         * Enable return of plugin url 
     183         */ 
     184        add_action('wp_ajax_nopriv_rhj4_notifications_plugin_url','rhj4_notifications_plugin_url'); 
     185 
     186        /** 
     187         * Enable return of session id 
     188         */ 
     189        add_action('wp_ajax_nopriv_rhj4_notifications_session_id','rhj4_notifications_session_id'); 
     190 
     191        //this will run when on the frontend 
    191192 
    192193        if (is_admin() ) { 
     
    209210 
    210211    public function activate() { 
    211         rhj4_diagnostic('RHJ4 Notifications Activated'); 
     212        if (is_plugin_active('rhj4-diagnostics/rhj4_diagnostics.php')) { 
     213            rhj4_diagnostic('RHJ4 Notifications Activated'); 
     214        } else { 
     215            echo 'RHJ4 Diagnostics not installed and active'; 
     216        } 
    212217    } 
    213218 
    214219    public function deactivate() { 
    215220        //  We cannot use notification here because it has been deactivated 
    216         rhj4_diagnostic('RHJ4 Notifications Deactivated'); 
    217     } 
    218  
     221    } 
     222 
     223    private function diag($message) { 
     224        if (is_plugin_active('rhj4-diagnostics/rhj4_diagnostics.php')) { 
     225            rhj4_diagnostic($message); 
     226        }  
     227    } 
     228     
    219229    public function render_shortcode($atts) { 
    220230        // 
     
    306316        // Present demo panel 
    307317        if ($atts['demo']) { 
    308             rhj4_diagnostic('Rendering Notifications Demo', 
     318            $this->diag('Rendering Notifications Demo', 
    309319                array('enabled' => true, 'source' => 'RHJ4 Notifications: ')); 
    310320            $path = plugin_dir_path(__FILE__); 
     
    405415 
    406416                    default: 
    407                         if (function_exists(error_log)) { 
    408                             error_log('unknown/invalid option key: ['.$key.']'); 
    409                         } 
     417                        echo 'unknown/invalid option key: ['.$key.']'; 
    410418                } 
    411419            } 
     
    10071015 
    10081016    $notify->save($message, $type, $is_sticky); 
    1009  
     1017    $notify->report("Notification [".$message."]"); 
     1018     
    10101019    // If an error was found, report_database_error will return true 
    10111020    if (!$notify->report_database_error('saving notification')) { 
     
    11441153} 
    11451154 
     1155function rhj4_notifications_start_session() { 
     1156    if(!session_id()) { 
     1157        session_start(); 
     1158    } 
     1159} 
     1160 
     1161function rhj4_notifications_logout() { 
     1162    session_destroy (); 
     1163} 
     1164 
     1165function rhj4_notifications_login() { 
     1166    if(!session_id()) { 
     1167        session_start(); 
     1168    } 
     1169} 
     1170 
     1171function rhj4_notifications_initialize($args = NULL) { 
     1172    $instance = RHJ4Notifications::instance(); 
     1173    if (!$instance->initialized) { 
     1174        $instance->init($args); 
     1175    } 
     1176} 
     1177 
    11461178/** 
    11471179 * Actions to be performed under various conditions 
    11481180 */ 
    11491181 
     1182add_action('wp_logout', 'rhj4_notifications_logout'); 
     1183add_action('wp_login', 'rhj4_notifications_login'); 
    11501184add_action('init', 'rhj4_notifications_start_session', 1); 
    1151 function rhj4_notifications_start_session() { 
    1152     if(!session_id()) { 
    1153         session_start(); 
    1154     } 
    1155 } 
    1156  
    1157 add_action('wp_logout', 'rhj4_notifications_logout'); 
    1158 function rhj4_notifications_logout() { 
    1159     session_destroy (); 
    1160 } 
    1161  
    1162 add_action('wp_login', 'rhj4_notifications_login'); 
    1163 function rhj4_notifications_login() { 
    1164     if(!session_id()) { 
    1165         session_start(); 
    1166     } 
    1167 } 
    1168  
    11691185add_action('init','rhj4_notifications_initialize'); 
    1170 function rhj4_notifications_initialize($args = NULL) { 
    1171     $diags = RHJ4Diagnostics::instance(); 
    1172     if (!$diags->initialized || !$diags->enabled) { 
    1173         $diags->init(array('enabled' => true)); 
    1174     } 
    1175  
    1176     $instance = RHJ4Notifications::instance(); 
    1177     if (!$instance->initialized) { 
    1178         $instance->init($args); 
    1179     } 
    1180  
    1181     if (!empty($diags)) { 
    1182 //        $diags->diagnostic($instance->plugin_name. ' initialized'); 
    1183     } 
    1184 } 
    11851186 
    11861187/** 
Note: See TracChangeset for help on using the changeset viewer.