Changeset 963075
- Timestamp:
- 08/09/2014 05:20:01 PM (12 years ago)
- Location:
- simple-parse-push-service/trunk
- Files:
-
- 6 edited
-
readme.txt (modified) (3 diffs)
-
screenshot-1.png (modified) (previous)
-
screenshot-2.png (modified) (previous)
-
screenshot-3.png (modified) (previous)
-
simpar_import_admin.php (modified) (8 diffs)
-
simpleParsePS.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-parse-push-service/trunk/readme.txt
r836709 r963075 4 4 Tags: parse, push notification, push, notification, mobile, smartphone, send, ios, android, channels 5 5 Requires at least: 3.3 6 Tested up to: 3. 87 Stable tag: 1. 26 Tested up to: 3.9.2 7 Stable tag: 1.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 16 16 You 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). 17 17 18 **NOTICE:** 18 19 In order to use this plugin you MUST have an account with Parse.com and cURL ENABLED. 20 21 **WARNING:** 22 Wordpress, 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). 23 SO, 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/> 24 Keep that in mind! 19 25 20 26 == Installation == … … 36 42 37 43 1. Plugin's settings menu. 38 2. Plugin's Push Notification dashboard 39 3. Add/Edit post, meta box 44 2. Plugin's settings menu (channels and post types to add a meta box). 45 3. Plugin's Push Notification dashboard 46 4. All push notifications for scheduled posts. 47 5. Add/Edit post, meta box 40 48 41 49 == 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. 42 55 43 56 = 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' )) { 4 7 //Form data sent 5 8 $sppsAppName = $_POST['simpar_appName']; … … 28 31 update_option('simpar_includePostID', 'false'); 29 32 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 30 43 $sppsSaveLastMessage = ''; 31 44 if (isset($_POST['simpar_saveLastMessage'])) { … … 58 71 $sppsMetaBoxPriority = $_POST['simpar_metaBoxPriority']; 59 72 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 } 60 81 ?> 61 82 <div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div> … … 80 101 $sppsIncludePostID = ' checked="checked"'; 81 102 103 $sppsDiscardScheduledPosts = ''; 104 if (get_option('simpar_discardScheduledPosts') == 'true') 105 $sppsDiscardScheduledPosts = ' checked="checked"'; 106 82 107 $sppsPushChannels = get_option('simpar_pushChannels'); 83 108 … … 93 118 94 119 95 if ( $_POST['simpar_push_hidden'] == 'Y') {120 if (isset( $_POST['simpar_push_hidden'] ) && ( $_POST['simpar_push_hidden'] == 'Y' )) { 96 121 $msg = $_POST['simpar_push_message']; 97 122 $badge = $_POST['simpar_push_badge']; … … 115 140 116 141 117 142 <?php 143 ////////////////// 144 // Main content // 145 ////////////////// 146 ?> 118 147 119 148 … … 178 207 <td><input type="checkbox" name="simpar_includePostID" <?php echo $sppsIncludePostID; ?> > Auto include post_ID as extra parameter 179 208 <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> 180 215 </td> 181 216 </tr> … … 220 255 </tr> 221 256 </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 222 304 <p class="submit"> 223 305 <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 2 2 /** 3 3 * @package Simple_Parse_Push_Service 4 * @version 1. 24 * @version 1.3 5 5 */ 6 6 /* 7 7 Plugin Name: Simple Parse Push Service 8 8 Plugin 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 8or 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.9 Description: 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. 10 10 Author: Tsolis Dimitris - Sotiris 11 Version: 1. 211 Version: 1.3 12 12 Author URI: 13 13 License: GPLv2 or later … … 15 15 */ 16 16 17 if (!defined('SPPS_VERSION')) define('SPPS_VERSION', '1.2'); 17 /* 18 * Global variables 19 * 20 */ 21 $scheduledPosts = array(); 22 23 if (!defined('SPPS_VERSION')) define('SPPS_VERSION', '1.3'); 18 24 19 25 ///////////////////////////////////////////////////////// … … 39 45 return; 40 46 } else { 47 global $scheduledPosts; 48 $scheduledPosts = get_option('simpar_scheduled_message_options'); 49 if ($scheduledPosts == '') { 50 $scheduledPosts = array(); 51 } 52 53 41 54 $sppsMetaBoxPriority = get_option('simpar_metaBoxPriority'); 42 55 if ($sppsMetaBoxPriority == '') { … … 44 57 } 45 58 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 54 79 } 55 80 } … … 91 116 echo '<input id="simpar_pushBadge" type="text" name="simpar_pushBadge" value"'.__("", 'simpar_context').'" size=\"10\"<br/><br/>'; 92 117 93 echo '<input id="simpar_titleCheckBox" type="checkbox" name="simpar_titleCheckBox"'.$checked.'> Send title as message .<br/><br/>';118 echo '<input id="simpar_titleCheckBox" type="checkbox" name="simpar_titleCheckBox"'.$checked.'> Send title as message (ignore the textbox above).<br/><br/>'; 94 119 echo '<input id="simpar_includePostIDCheckBox" type="checkbox" name="simpar_includePostIDCheckBox"'.$includePostIDChecked.'> Include postID as extra param.<br/><br/>'; 95 120 … … 100 125 } 101 126 127 ///////////// 128 // Helpers // 129 ///////////// 130 function 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 138 function 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 151 function 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 169 function 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 102 203 //////////////////////////// 103 204 // send push notification // 104 205 //////////////////////////// 105 206 function 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) 108 214 return $post_ID; 109 215 110 if (get_option('simpar_saveLastMessage') == 'true')111 update_option('simpar_lastMessage', $message);112 else113 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'];124 216 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')); 127 218 128 219 return $post_ID; 220 } 221 222 function 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 247 function 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' ); 129 290 } 130 291 … … 133 294 ////////////////////////// 134 295 function simpar_admin() { 135 //include('simpar_import_admin.php');136 296 include('simpar_import_admin.php'); 137 297 } 138 298 299 function simpar_submenu() { 300 include('simpar_import_pending_notf.php'); 301 } 302 139 303 function 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 * ============================================ */ 321 function my_admin_head_script() { 322 wp_enqueue_script( 'admin-pending-notf-js', plugin_dir_url( __FILE__ ).'js/pendingNotificationsAdmin.js' ); 323 } 324 325 142 326 143 327 //////////////////////////////////////// … … 157 341 delete_option('simpar_doNotIncludeChannel'); 158 342 delete_option('simpar_pushChannels'); 343 delete_option('simpar_scheduled_message_options'); 344 delete_option('simpar_hide_warning'); 345 delete_option('simpar_discardScheduledPosts'); 159 346 /*Remove any other options you may add in this plugin and clear any plugin cron jobs */ 160 347 } … … 166 353 add_action('admin_init', 'simpar_admin_init', 1); 167 354 add_action('admin_menu', 'simpar_admin_actions'); 168 add_action('publish_post', 'simpar_send_post'); 355 add_action('future_to_publish', 'simpar_future_to_publish'); 356 add_action( 'transition_post_status', 'simpar_save_post', 10, 3 ); 169 357 register_uninstall_hook(__FILE__, 'simpar_plugin_on_uninstall'); 170 358
Note: See TracChangeset
for help on using the changeset viewer.