Plugin Directory

Changeset 963075


Ignore:
Timestamp:
08/09/2014 05:20:01 PM (12 years ago)
Author:
dtsolis
Message:

version 1.3 update

Location:
simple-parse-push-service/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • simple-parse-push-service/trunk/readme.txt

    r836709 r963075  
    44Tags: parse, push notification, push, notification, mobile, smartphone, send, ios, android, channels
    55Requires at least: 3.3
    6 Tested up to: 3.8
    7 Stable tag: 1.2
     6Tested up to: 3.9.2
     7Stable tag: 1.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1616You can send a push notification via admin panel or with a post update/creation. In addition, you can include post's id as extra parameter to use it as you want with your mobile app, select the channels you want to receive notifications or add an extra parameter to the payload (any key/value pair you like).
    1717
     18**NOTICE:**
    1819In order to use this plugin you MUST have an account with Parse.com and cURL ENABLED.
     20
     21**WARNING:**
     22Wordpress, in order to publish a scheduled post, runs a pseudo-cron job WHEN a user visits the site. Any user, any page (admin page or a page a visitor sees).
     23SO, if for example you have scheduled a post for publish at 16:00 and this website doesn't have a hit until 16:50, the post will actually be published at 16:50 and the Push Notification will be sent at 16:50.<br/>
     24Keep that in mind!
    1925
    2026== Installation ==
     
    3642
    37431. Plugin's settings menu.
    38 2. Plugin's Push Notification dashboard
    39 3. Add/Edit post, meta box
     442. Plugin's settings menu (channels and post types to add a meta box).
     453. Plugin's Push Notification dashboard
     464. All push notifications for scheduled posts.
     475. Add/Edit post, meta box
    4048
    4149== Changelog ==
     50
     51= 1.3 =
     52* Stability fixes
     53* Send Push Notification for scheduled posts
     54* Send Push Notification via 'edit menu' for any Post Type. Posts are enabled by default but any other Post Type can be selected from the Settings menu.
    4255
    4356= 1.2 =
  • simple-parse-push-service/trunk/simpar_import_admin.php

    r829486 r963075  
    1 <?php   
    2 
    3     if($_POST['simpar_hidden'] == 'Y') { 
     1<?php 
     2
     3    /////////////////////////////
     4    // Working with Parameters //
     5    /////////////////////////////
     6    if(isset( $_POST['simpar_hidden'] ) && ( $_POST['simpar_hidden'] == 'Y' )) { 
    47        //Form data sent
    58        $sppsAppName = $_POST['simpar_appName']; 
     
    2831            update_option('simpar_includePostID', 'false');
    2932
     33
     34        $sppsDiscardScheduledPosts = '';
     35        if (isset($_POST['simpar_discardScheduledPosts'])) {
     36            update_option('simpar_discardScheduledPosts', 'true');
     37            $sppsDiscardScheduledPosts = ' checked="checked"';
     38        }
     39        else
     40            update_option('simpar_discardScheduledPosts', 'false');
     41
     42
    3043        $sppsSaveLastMessage = '';
    3144        if (isset($_POST['simpar_saveLastMessage'])) { 
     
    5871        $sppsMetaBoxPriority = $_POST['simpar_metaBoxPriority'];
    5972        update_option('simpar_metaBoxPriority', $sppsMetaBoxPriority);
     73
     74
     75        if (isset($_POST['simpar_metabox_pt'])) {
     76            addOrUpdateOption('simpar_metabox_pt', $_POST['simpar_metabox_pt']);
     77        }
     78        else {
     79            delete_option('simpar_metabox_pt');
     80        }
    6081        ?> 
    6182        <div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div> 
     
    80101            $sppsIncludePostID = ' checked="checked"';
    81102
     103        $sppsDiscardScheduledPosts = '';
     104        if (get_option('simpar_discardScheduledPosts') == 'true')
     105            $sppsDiscardScheduledPosts = ' checked="checked"';
     106
    82107        $sppsPushChannels = get_option('simpar_pushChannels');
    83108
     
    93118
    94119
    95     if ($_POST['simpar_push_hidden'] == 'Y') {
     120    if (isset( $_POST['simpar_push_hidden'] ) && ( $_POST['simpar_push_hidden'] == 'Y' )) {
    96121        $msg = $_POST['simpar_push_message'];
    97122        $badge = $_POST['simpar_push_badge'];
     
    115140
    116141
    117 
     142<?php
     143//////////////////
     144// Main content //
     145//////////////////
     146?>
    118147
    119148
     
    178207                                        <td><input type="checkbox" name="simpar_includePostID" <?php echo $sppsIncludePostID; ?> > Auto include post_ID as extra parameter
    179208                                            <p class="description">See the 'Sample Payload' for more technical info.</p>
     209                                        </td>
     210                                    </tr>
     211                                    <tr valign="top">
     212                                        <td scope="row"><label for="tablecell">Discard for scheduled</label></td>
     213                                        <td><input type="checkbox" name="simpar_discardScheduledPosts" <?php echo $sppsDiscardScheduledPosts; ?> > Do not save Push Notification for scheduled posts
     214                                            <p class="description">If this is disabled, every time you schedule a post for future publish, the appropriate Push Notification (if any) will be saved add Pushed with post's publication. Existing (saved) push notifications won't be affected.</p>
    180215                                        </td>
    181216                                    </tr>
     
    220255                                    </tr>
    221256                                </table>
     257
     258
     259                                <!-- settings - post types with metabox enabled -->
     260                                <hr/>
     261                                <table class="form-table">
     262                                    <tr valign="top">
     263                                        <td scope="row">
     264                                            <label for="tablecell">
     265                                                <h3><span><?php echo __( 'Post Types with MetaBox enabled', 'simpar_trdom' ) ?></span></h3>
     266                                            </label>
     267
     268                                            <?php
     269                                                $savedPostTypes = get_option('simpar_metabox_pt');
     270                                           
     271                                                /* Posts are pre-defined
     272                                                =================================== */
     273                                                echo '<input type="checkbox" disabled checked/> Posts <br/>';
     274                                                echo '<input type="hidden" name="simpar_metabox_pt[]" value="post" />';
     275                                           
     276                                                /* Check if pages are selected
     277                                                ==================================== */
     278                                                $sppsSavedPage = '';
     279                                                if (in_array('page', $savedPostTypes))
     280                                                    $sppsSavedPage = ' checked="checked"';
     281                                                // die( print_r($savedPostTypes));
     282                                                echo '<input type="checkbox" name="simpar_metabox_pt[]" value="page"'.$sppsSavedPage.'/> Pages <br/>';
     283                                           
     284
     285                                                /* Check for custom types
     286                                                ==================================== */
     287                                                $args = array('_builtin' => false, );
     288                                                $post_types = get_post_types( $args, 'objects' );
     289                                                foreach ( $post_types as $post_type ) {
     290
     291                                                    $sppsSaved = '';
     292                                                    if (in_array($post_type->name, $savedPostTypes))
     293                                                        $sppsSaved = ' checked="checked"';
     294                                                    echo '<input type="checkbox" name="simpar_metabox_pt[]" value="'.$post_type->name.'" '.$sppsSaved.' />'.$post_type->label.' <br/>';
     295                                                }
     296                                            ?>
     297
     298                                        </td>
     299                                    </tr>
     300                                </table>
     301
     302
     303
    222304                                <p class="submit">
    223305                                    <input type="submit" name="Submit" class="button button-primary" value="<?php _e('Update Options', 'simpar_trdom' ) ?>" />
  • simple-parse-push-service/trunk/simpleParsePS.php

    r836707 r963075  
    22/**
    33 * @package Simple_Parse_Push_Service
    4  * @version 1.2
     4 * @version 1.3
    55 */
    66/*
    77Plugin Name: Simple Parse Push Service
    88Plugin URI: http://wordpress.org/plugins/simple-parse-push-service/
    9 Description: This is a simple implementation for Parse.com Push Service (for iOS, Android, Windows 8 or any other devices may add). You can send a push notification via admin panel or with a post update/creation. In order to use this plugin you MUST have an account with Parse.com and cURL ENABLED.
     9Description: This is a simple implementation for Parse.com Push Service (for iOS, Android, Windows, Windows Phone or any other devices may add). You can send a push notification via admin panel or with a post update/creation. In order to use this plugin you MUST have an account with Parse.com and cURL ENABLED.
    1010Author: Tsolis Dimitris - Sotiris
    11 Version: 1.2
     11Version: 1.3
    1212Author URI:
    1313License: GPLv2 or later
     
    1515*/
    1616
    17 if (!defined('SPPS_VERSION')) define('SPPS_VERSION', '1.2');
     17/*
     18 * Global variables
     19 *
     20 */
     21$scheduledPosts = array();
     22
     23if (!defined('SPPS_VERSION')) define('SPPS_VERSION', '1.3');
    1824
    1925/////////////////////////////////////////////////////////
     
    3945        return;
    4046    } else {
     47        global $scheduledPosts;
     48        $scheduledPosts = get_option('simpar_scheduled_message_options');
     49        if ($scheduledPosts == '') {
     50            $scheduledPosts = array();
     51        }
     52
     53
    4154        $sppsMetaBoxPriority = get_option('simpar_metaBoxPriority');
    4255        if ($sppsMetaBoxPriority == '') {
     
    4457        }
    4558
    46         add_meta_box(
    47             'simpar_tid_post',
    48             'Simple Parse Push Notification',
    49             'simpar_boxcontent',
    50             'post',
    51             'side',
    52             $sppsMetaBoxPriority
    53         );
     59        /*
     60         * Enable meta box and the appropriate hooks
     61         * for each post type available
     62         ======================================================== */
     63       
     64        $savedPostTypes = get_option('simpar_metabox_pt');
     65        foreach ($savedPostTypes as $postType) {
     66            add_meta_box(
     67                'simpar_tid_post',
     68                'Simple Parse Push Notification',
     69                'simpar_boxcontent',
     70                $postType,
     71                'side',
     72                $sppsMetaBoxPriority
     73            );
     74
     75
     76            add_action('publish_'.$postType, 'simpar_send_post');
     77        }
     78       
    5479    }
    5580}
     
    91116    echo '<input id="simpar_pushBadge" type="text" name="simpar_pushBadge" value"'.__("", 'simpar_context').'" size=\"10\"<br/><br/>';
    92117
    93     echo '<input id="simpar_titleCheckBox" type="checkbox" name="simpar_titleCheckBox"'.$checked.'>&nbsp;Send title as message.<br/><br/>';
     118    echo '<input id="simpar_titleCheckBox" type="checkbox" name="simpar_titleCheckBox"'.$checked.'>&nbsp;Send title as message (ignore the textbox above).<br/><br/>';
    94119    echo '<input id="simpar_includePostIDCheckBox" type="checkbox" name="simpar_includePostIDCheckBox"'.$includePostIDChecked.'>&nbsp;Include postID as extra param.<br/><br/>';
    95120
     
    100125}
    101126
     127/////////////
     128// Helpers //
     129/////////////
     130function addOrUpdateOption($option_name, $value) {
     131    if ( get_option( $option_name ) !== false ) {
     132        update_option( $option_name, $value );
     133    } else {
     134        add_option( $option_name, $value );
     135    }
     136}
     137
     138function indexForScheduledPost($post_ID) {
     139    global $scheduledPosts;
     140    $scheduledPosts = get_option( 'simpar_scheduled_message_options' );
     141    $index = -1;
     142    for ($i=0; $i < count( $scheduledPosts ); $i++) {
     143        $tmpArray = $scheduledPosts[$i];
     144        if ( $tmpArray['post_id'] == $post_ID) {
     145            return $i;
     146        }
     147    }
     148    return $index;
     149}
     150
     151function removeScheduledPost($post_ID) {
     152    $index = indexForScheduledPost($post_ID);
     153
     154    global $scheduledPosts;
     155    $scheduledPosts = get_option( 'simpar_scheduled_message_options' );
     156
     157    if ($index > -1) {
     158        $tmpArray = $scheduledPosts[$index];
     159
     160        // remove the scheduled push...
     161        unset( $scheduledPosts[$index] );
     162        $scheduledPosts = array_values( $scheduledPosts );
     163        // ...and save update the cached array
     164        addOrUpdateOption( 'simpar_scheduled_message_options', $scheduledPosts );
     165        $scheduledPosts = get_option( 'simpar_scheduled_message_options' );
     166    }
     167}
     168
     169function metaboxParamsFilter($post_ID) {
     170    $returnArray = array('message' => '',
     171                         'badge' => '',
     172                         'post_id' => null);
     173    $message = null;
     174    if ( isset($_REQUEST['simpar_pushText']) )
     175        $message = $_REQUEST['simpar_pushText'];
     176
     177    if ( !isset($_POST['simpar_nonce']) OR !wp_verify_nonce( $_POST['simpar_nonce'], plugin_basename(__FILE__) ) OR !intval($_POST['simpar_activate']) OR ($message == null && !isset($_POST['simpar_titleCheckBox'])))
     178        return null;
     179
     180    if (get_option('simpar_saveLastMessage') == 'true')
     181        update_option('simpar_lastMessage', $message);
     182    else
     183        update_option('simpar_lastMessage', '');
     184
     185    if (isset($_POST['simpar_titleCheckBox'])) {
     186        $message = html_entity_decode(get_the_title($post_ID),ENT_QUOTES,'UTF-8');
     187    }
     188
     189    $incPostID = null;
     190    if (isset($_POST['simpar_includePostIDCheckBox']))
     191        $incPostID = $post_ID;
     192   
     193    $badge = '';
     194    if ( isset( $_REQUEST['simpar_pushBadge'] ) )
     195        $badge = $_REQUEST['simpar_pushBadge'];
     196
     197    $returnArray['message'] = $message;
     198    $returnArray['badge']   = $badge;
     199    $returnArray['post_id'] = $incPostID;
     200    return $returnArray;
     201}
     202
    102203////////////////////////////
    103204// send push notification //
    104205////////////////////////////
    105206function simpar_send_post($post_ID) {
    106     $message = $_REQUEST['simpar_pushText'];
    107     if ( !wp_verify_nonce( $_POST['simpar_nonce'], plugin_basename(__FILE__) ) OR !intval($_POST['simpar_activate']) OR ($message == null && !isset($_POST['simpar_titleCheckBox'])))
     207    if ( !isset( $_POST['simpar_pushText'] ) ) {
     208        // if false, this post is published automatically and not the time user hit 'publish'
     209        return;
     210    }
     211
     212    $values = metaboxParamsFilter($post_ID);
     213    if ($values == null)
    108214        return $post_ID;
    109215
    110     if (get_option('simpar_saveLastMessage') == 'true')
    111         update_option('simpar_lastMessage', $message);
    112     else
    113         update_option('simpar_lastMessage', '');
    114 
    115     if (isset($_POST['simpar_titleCheckBox'])) {
    116         $message = html_entity_decode(get_the_title($post_ID),ENT_QUOTES,'UTF-8');
    117     }
    118 
    119     $incPostID = null;
    120     if (isset($_POST['simpar_includePostIDCheckBox']))
    121         $incPostID = $post_ID;
    122    
    123     $badge = $_REQUEST['simpar_pushBadge'];
    124216    include('pushFunctionality.php');
    125     sendPushNotification(get_option('simpar_appID'), get_option('simpar_restApi'), $message, $badge, $incPostID, get_option('simpar_pushChannels'));
    126 
     217    sendPushNotification(get_option('simpar_appID'), get_option('simpar_restApi'), $values['message'], $values['badge'], $values['post_id'], get_option('simpar_pushChannels'));
    127218
    128219    return $post_ID;
     220}
     221
     222function simpar_future_to_publish($post) {
     223
     224    $validPostTypes = get_option('simpar_metabox_pt');
     225    if (!in_array($post->post_type, $validPostTypes)) {
     226        return;
     227    }
     228
     229    global $scheduledPosts;
     230    $scheduledPosts = get_option( 'simpar_scheduled_message_options' );
     231    $index = indexForScheduledPost($post->ID);
     232
     233    if ($index > -1) {
     234        $tmpArray = $scheduledPosts[$index];
     235        include('pushFunctionality.php');
     236        sendPushNotification(get_option('simpar_appID'), get_option('simpar_restApi'), $tmpArray['message'], $tmpArray['badge'], $post->ID, get_option('simpar_pushChannels'));
     237
     238        // remove the scheduled push...
     239        unset( $scheduledPosts[$index] );
     240        $scheduledPosts = array_values( $scheduledPosts );
     241        // ...and save update the cached array
     242        addOrUpdateOption( 'simpar_scheduled_message_options', $scheduledPosts );
     243        $scheduledPosts = get_option( 'simpar_scheduled_message_options' );
     244    }
     245}
     246
     247function simpar_save_post($new_status, $old_status, $post) {
     248    if ( get_option('simpar_discardScheduledPosts') == 'true' )
     249        return; // disabled by user
     250
     251
     252    $values = metaboxParamsFilter($post->ID);
     253    if ($values == null)
     254        return $post->ID;
     255
     256    global $scheduledPosts;
     257
     258
     259    $posttime = strtotime($post->post_date); // date to be published
     260    $currtime = time();                      // NOW
     261    $diff = $posttime - $currtime;           // difference (if diff > 0 then the post is scheduled to be published)
     262
     263    if ($new_status != 'future' || ($new_status == 'new' && $diff <= 0)) {
     264        // this means that every check needed, made in 'publish_post' function
     265        // no need to cache any options for future publish
     266        return $post->ID;
     267    }
     268
     269    $validPostTypes = get_option('simpar_metabox_pt');
     270    if (!in_array($post->post_type, $validPostTypes)) {
     271        return;
     272    }
     273
     274
     275    $scheduledPostsInfo = array('message'      => $values['message'],
     276                                'badge'        => $values['badge'],
     277                                'post_type'    => $post->post_type,
     278                                'post_id'      => $post->ID,
     279                                'last_updated' => time());
     280    $index = indexForScheduledPost($post->ID);
     281    $scheduledPosts = get_option('simpar_scheduled_message_options');
     282    if ( $index == -1) {
     283        $scheduledPosts[] = $scheduledPostsInfo;
     284    }
     285    else {
     286        $scheduledPosts[$index] = $scheduledPostsInfo;
     287    }
     288    addOrUpdateOption( 'simpar_scheduled_message_options', $scheduledPosts );
     289    $scheduledPosts = get_option( 'simpar_scheduled_message_options' );
    129290}
    130291
     
    133294//////////////////////////
    134295function simpar_admin() {
    135     //include('simpar_import_admin.php');
    136296    include('simpar_import_admin.php');
    137297}
    138298
     299function simpar_submenu() {
     300    include('simpar_import_pending_notf.php');
     301}
     302
    139303function simpar_admin_actions() { 
    140       add_menu_page("Simple Parse Push Service", "Simple Parse Push Service", 1, "Simple-Parse-Push-Service", "simpar_admin");
    141 
     304
     305    add_menu_page("Simple Parse Push Service", "Simple Parse Push Service", 'manage_options', "Simple-Parse-Push-Service", "simpar_admin");
     306    $pending_notf_page = add_submenu_page( "Simple-Parse-Push-Service", "Settings", "Settings", "manage_options", "Simple-Parse-Push-Service", "simpar_admin" );
     307    $pending_notf_page = add_submenu_page( "Simple-Parse-Push-Service", "Pending Notifications", "Pending Notifications", "manage_options", "spps_pending_notifications", "simpar_submenu" );
     308    add_action( "admin_head-{$pending_notf_page}", 'my_admin_head_script' );
     309
     310    /*
     311     * enqueue javascript to make 'postbox'-es
     312     * act like the dashboard 'postbox'-es
     313     * ======================================================== */
     314    wp_enqueue_script("dashboard");
     315}
     316
     317
     318/*
     319 * Additional javascript or css
     320 * ============================================ */
     321function my_admin_head_script() {
     322    wp_enqueue_script( 'admin-pending-notf-js', plugin_dir_url( __FILE__ ).'js/pendingNotificationsAdmin.js' );
     323}
     324
     325
    142326
    143327////////////////////////////////////////
     
    157341    delete_option('simpar_doNotIncludeChannel');
    158342    delete_option('simpar_pushChannels');
     343    delete_option('simpar_scheduled_message_options');
     344    delete_option('simpar_hide_warning');
     345    delete_option('simpar_discardScheduledPosts');
    159346    /*Remove any other options you may add in this plugin and clear any plugin cron jobs */
    160347}
     
    166353add_action('admin_init', 'simpar_admin_init', 1);
    167354add_action('admin_menu', 'simpar_admin_actions'); 
    168 add_action('publish_post', 'simpar_send_post');
     355add_action('future_to_publish', 'simpar_future_to_publish');
     356add_action( 'transition_post_status', 'simpar_save_post', 10, 3 );
    169357register_uninstall_hook(__FILE__, 'simpar_plugin_on_uninstall');
    170358
Note: See TracChangeset for help on using the changeset viewer.