Changeset 706934
- Timestamp:
- 05/02/2013 01:03:17 PM (13 years ago)
- Location:
- content-scheduler/trunk
- Files:
-
- 2 added
- 4 edited
-
.gitignore (added)
-
README.md (added)
-
content-scheduler.php (modified) (16 diffs)
-
includes/init-admin.php (modified) (1 diff)
-
includes/process-post.php (modified) (6 diffs)
-
readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
content-scheduler/trunk/content-scheduler.php
r579494 r706934 2 2 /* 3 3 Plugin Name: Content Scheduler 4 Plugin URI: http:// structurewebdev.com/wordpress-plugins/content-scheduler/4 Plugin URI: http://paulekaiser.com/wordpress-plugins/content-scheduler/ 5 5 Description: Set Posts and Pages to automatically expire. Upon expiration, delete, change categories, status, or unstick posts. Also notify admin and author of expiration. 6 Version: 0.9.96 Version: 1.0.0 7 7 Author: Paul Kaiser 8 8 Author URI: http://paulekaiser.com … … 59 59 // adds our plugin options page 60 60 add_action('admin_menu', array($this, 'ContentScheduler_addoptions_page_fn')); 61 // add a cron action for expiration check and notification check61 // add a cron action for expiration check 62 62 // I think this is still valid, even after 3.4 changes 63 63 if ( $this->is_network_site() ) 64 64 { 65 65 add_action ('content_scheduler'.$current_blog->blog_id, array( $this, 'answer_expiration_event') ); 66 add_action ('content_scheduler_notify'.$current_blog->blog_id, array( $this, 'answer_notification_event') );67 66 } 68 67 else 69 68 { 70 69 add_action ('content_scheduler', array( $this, 'answer_expiration_event') ); 71 add_action ('content_scheduler_notify', array( $this, 'answer_notification_event') );72 70 } 73 71 // ========== … … 345 343 } // end draw_min_level_fn() 346 344 347 // 8/8/2011 11:51:41 PM -pk348 // 0.9.7 We are removing this option.349 /*350 // Notify upon expiration?351 function draw_notify_expire_fn()352 {353 // get this plugin's options from the database354 $options = get_option('ContentScheduler_Options');355 // make array of radio button items356 $items = array(357 array('1', __("Notify on expiration", 'contentscheduler'), __("Notify when expiration changes posts / pages.", 'contentscheduler') ),358 array('0', __("Do not notify on expiration", 'contentscheduler'), __("Do not notify when expiration changes posts / pages.", 'contentscheduler') )359 );360 // Step through and spit out each item as radio button361 foreach( $items as $item )362 {363 $checked = ($options['notify-expire'] == $item[0] ) ? ' checked="checked" ' : '';364 echo "<label><input ".$checked." value='$item[0]' name='ContentScheduler_Options[notify-expire]' type='radio' /> $item[1] — $item[2]</label><br />";365 } // end foreach366 } // draw_notify_expire_fn()367 */368 369 // Notify number of days before expiration?370 function draw_notify_before_fn()371 {372 // get this plugin's options from the database373 // This should have a default value of '0'374 $options = get_option('ContentScheduler_Options');375 $input_field = "<input id='notify-before' name='ContentScheduler_Options[notify-before]' size='10' type='text' value='{$options['notify-before']}' />";376 printf( __("Notify %s days before expiration.", 'contentscheduler'), $input_field );377 echo "<br />\n";378 } // end draw_notify_before_fn()379 345 // Show expiration date in columnar lists? 380 346 function draw_show_columns_fn() … … 607 573 $arr_defaults = array 608 574 ( 609 "version" => " 0.9.9",610 "exp-status" => "1",575 "version" => "1.0.0", 576 "exp-status" => "1", 611 577 "exp-period" => "1", 612 578 "chg-status" => "2", … … 619 585 "notify-author" => "0", 620 586 "notify-expire" => "0", 621 "notify-before" => "0",622 587 "min-level" => "level_1", 623 588 "show-columns" => "0", … … 696 661 } 697 662 // We need to update the version string to our current version 698 $options['version'] = " 0.9.8";663 $options['version'] = "1.0.0"; 699 664 // make sure we have added any updated options 700 665 if (!function_exists('array_replace')) … … 721 686 // wp_schedule_event( time(), 'hourly', 'content_scheduler_'.$current_blog_id ); 722 687 } 723 // for notifications724 if( !wp_next_scheduled( 'content_scheduler_notify_'.$current_blog_id ) )725 {726 wp_schedule_event( time(), 'hourly', 'content_scheduler_notify_'.$current_blog_id );727 }728 688 } 729 689 else … … 735 695 wp_schedule_event( time(), 'contsched_usertime', 'content_scheduler' ); 736 696 // wp_schedule_event( time(), 'hourly', 'content_scheduler' ); 737 }738 // for notifications739 if( !wp_next_scheduled( 'content_scheduler_notify' ) )740 {741 wp_schedule_event( time(), 'hourly', 'content_scheduler_notify' );742 697 } 743 698 } … … 815 770 // Make sure tags are alphanumeric and that is all 816 771 // Testing tags-to-add, which should be a comma-delimited list of alphanumerics 772 // trim out space from tags string 773 $input['tags-to-add'] = trim( $input['tags-to-add'] ); 817 774 if ( !empty( $input['tags-to-add'] ) ) 818 775 { 819 776 $input['tags-to-add'] = filter_var( $input['tags-to-add'], FILTER_SANITIZE_STRING ); 820 }821 // Make sure notify-before is an integer value822 if ( empty( $input['notify-before'] ) )823 {824 $input['notify-before'] = '0';825 // return $input;826 }827 else828 {829 // if it's not empty, let's keep moving830 if ( ! sprintf("%u", $input['notify-before']) == $input['notify-before'])831 {832 // register an error, officially833 add_settings_error('ContentScheduler_Options',834 'settings_updated',835 __('Only positive integers are accepted for "Notify before expiration".', 'contentscheduler'),836 'error');837 }838 777 } 839 778 // We need to take inputs from the default expiration time and pack it up into an array. … … 859 798 wp_clear_scheduled_hook('content_scheduler_'.$blog_id); 860 799 wp_schedule_event( time(), 'contsched_usertime', 'content_scheduler_'.$blog_id ); 861 // for notifications862 wp_clear_scheduled_hook('content_scheduler_notify_'.$blog_id);863 wp_schedule_event( time(), 'hourly', 'content_scheduler_notify_'.$current_blog_id );864 800 } 865 801 else … … 869 805 wp_clear_scheduled_hook('content_scheduler'); 870 806 wp_schedule_event( time(), 'contsched_usertime', 'content_scheduler' ); 871 // for notifications872 wp_clear_scheduled_hook('content_scheduler_notify');873 wp_schedule_event( time(), 'hourly', 'content_scheduler_notify' );874 807 } 875 808 // if we had an error, do we still return? Or not? … … 1004 937 $this->setup_timezone(); 1005 938 // Checkbox for "enable scheduling" 1006 $enabled = $_POST['_cs-enable-schedule'];939 $enabled = ( empty( $_POST['_cs-enable-schedule'] ) ? 'Disable' : $_POST['_cs-enable-schedule'] ); 1007 940 // Value should be either 'Enable' or 'Disable'; otherwise something is screwy 1008 941 if( $enabled != 'Enable' AND $enabled != 'Disable' ) … … 1081 1014 $date = ''; 1082 1015 // For debug, we will set to 'INVALID' 1083 $date = 'INVALID';1016 // $date = 'INVALID'; 1084 1017 } 1085 1018 } … … 1211 1144 } // end if 1212 1145 } 1213 // ==================== 1214 // Respond to a daily call from wp-cron checking for notification needs 1215 function answer_notification_event() 1216 { 1217 // we should get our options right now, and decide if we need to proceed or not. 1218 $options = get_option('ContentScheduler_Options'); 1219 // Do we need to process notifications? 1220 if( $options['notify-on'] != '0' ) 1221 { 1222 // We need to process notifications 1223 // Note, these are only notifications that occur as a warning 1224 // BEFORE expiration 1225 $this->process_notifications(); 1226 } // end if 1227 } // end answer_notification_event() 1146 1228 1147 // ========================================================== 1229 1148 // Process Expirations … … 1235 1154 include 'includes/process-expirations.php'; 1236 1155 } // end process_expirations() 1237 // ============================================================= 1238 // Process Notifications 1239 // ============================================================= 1240 function process_notifications() 1241 { 1242 // Check database for posts meeting notification-only criteria 1243 // Hand them off to appropriate functions 1244 include 'includes/process-notifications.php'; 1245 } // end process_notifications() 1246 // ============================================================= 1247 // == Perform NOTIFICATIONs 1248 // ============================================================= 1249 // This function takes an array of arrays. 1250 // The arrays contain a post_id and an array of user_ids 1251 // The function then compiles one email per user and sends it by email. 1252 // This method takes one item in the outside array per Post. 1253 function do_notifications( $posts_to_notify, $why_notify ) 1254 { 1255 // notify people of expiration or pending expiration 1256 include 'includes/send-notifications.php'; 1257 } // end do_notifications() 1156 1258 1157 // 11/23/2010 11:45:27 AM -pk 1259 1158 // Somehow, we need to retrieve the OPTIONS only Once, and then act upon them. … … 1279 1178 include "includes/process-post.php"; 1280 1179 } // end process_custom() 1180 1281 1181 // ================================================================ 1282 1182 // == Conditionally Add Expiration date to Column views -
content-scheduler/trunk/includes/init-admin.php
r479969 r706934 134 134 array($this, 'draw_notify_on_fn'), 135 135 'ContentScheduler_Page_Title', 136 'ContentScheduler_Not_ID'); 137 /* 138 Textbox: Notify before expiration: 'exp-notify-before' 139 * This is a number of days before expiration. 140 */ 141 add_settings_field( 142 'notify-before', 143 __('Notify before expiration:', 'contentscheduler'), 144 array($this, 'draw_notify_before_fn'), 145 'ContentScheduler_Page_Title', 146 'ContentScheduler_Not_ID'); 147 148 // 8/8/2011 11:52:49 PM -pk 149 // We are removing this option 150 /* 151 Checkbox: Notify upon expiration: 'exp-notify-when' 152 */ 153 /* 154 add_settings_field( 155 'notify-expire', 156 __('Notify upon expiration:', 'contentscheduler'), 157 array($this, 'draw_notify_expire_fn'), 158 'ContentScheduler_Page_Title', 159 'ContentScheduler_Not_ID'); 160 */ 161 136 'ContentScheduler_Not_ID'); 162 137 /* 163 138 Checkbox: Notify admin: 'exp-notify-admin' -
content-scheduler/trunk/includes/process-post.php
r479969 r706934 1 1 <?php 2 2 $options = get_option('ContentScheduler_Options'); 3 // STICKINESS (Pages do not have STICKY ability) 4 // Note: This is stored in the options table, and is not part of post_update 5 // get the array of sticky posts 6 // What do we want to do with stickiness? 7 $sticky_change = $options['chg-sticky']; 8 if( $sticky_change == '1' ) 9 { 10 $sticky_posts = get_option('sticky_posts'); 11 if( ! empty( $sticky_posts ) ) 12 { 13 // Remove $postid from the $sticky_posts[] array 14 foreach( $sticky_posts as $key => $stuck_id ) 15 { 16 if( $stuck_id == $postid ) 17 { 18 // remove $key from $sticky_posts 19 unset( $sticky_posts[$key] ); 20 break; 21 } // end if 22 } // end foreach 23 // Get the new array of stickies back into WP 24 update_option('sticky_posts', $sticky_posts); 25 } // end if 26 } // end if 27 3 28 // Now, make the array we would pass to wp_update_post 4 29 // This is a local variable, so each time process_post is called, it will be new … … 65 90 } // end if - checking chg-cat-method 66 91 // ============================================================= 67 // TAGS (Check to see if the post type support post_tag first) 92 // TAGS (Check to see if the post type support post_tag first) 68 93 $proceed = false; 69 94 // Get the post type (we're using this same file for Posts and Custom Post Types) … … 89 114 } // end if for post_tag support 90 115 } // end if for $post_type != post 116 91 117 if( $proceed == true ) 92 118 { 93 // ===========================================================94 119 // First, check to see if we even want to do tags 95 // $tags_to_add = $options['tags-to-add']; // this is a comma-delimited string 96 // turn $tags_to_add into an array 97 // $tags_to_add = explode( ", ", $tags_to_add ); 98 99 // get entire list of tags from content scheduler settings 100 $tags_setting_list = explode( ",", $options['tags-to-add'] ); 101 // for debug 102 103 // make sure we just have a comma-separated list of alphanumeric entries 104 $tags_setting_list = filter_var_array( $tags_setting_list, FILTER_SANITIZE_STRING ); 105 106 // init arrays used for final operations 107 $tags_to_add = array(); 108 $tags_to_remove = array(); 109 $tags_absolute = array(); 110 $final_tag_list = array(); 111 // process the array by: 112 // a. remove spaces from items 113 // b. checking for "-" or "+" as first character 114 // -- i. Adding to appropriate array if there is such a character 115 foreach( $tags_setting_list as $cur_tag ) 116 { 117 // trim any space 118 $cur_tag = trim( $cur_tag ); 119 // we'll do trim() again on the + and - items, since there might be whitespace after the +/- 120 // check to see what the first character of the tag is 121 $first_char = substr( $cur_tag, 0, 1 ); 122 123 switch( $first_char ) 124 { 125 case '+': 126 $tags_to_add[] = trim( substr( $cur_tag, 1 ) ); 127 break; 128 case '-': 129 $tags_to_remove[] = trim( substr( $cur_tag, 1 ) ); 130 break; 131 default: 132 $tags_absolute[] = $cur_tag; 133 } // end switch 134 } // end foreach 135 136 // if $tags_absolute is not empty, then we will set the new tag list to just that array and we are done 137 if( !empty( $tags_absolute ) ) 138 { 139 $final_tag_list = $tags_absolute; 140 } 141 else 142 { 120 $tags_to_add = $options['tags-to-add']; // this is a comma-delimited string 121 if( '' != $tags_to_add ) { 122 // we have some tags to work with 123 $tags_setting_list = explode( ",", $tags_to_add ); 124 // make sure we just have a comma-separated list of alphanumeric entries 125 $tags_setting_list = filter_var_array( $tags_setting_list, FILTER_SANITIZE_STRING ); 126 // init arrays used for final operations 127 $tags_to_add = array(); 128 $tags_to_remove = array(); 129 $final_tag_list = array(); 130 // process the array by: 131 // a. remove spaces from items 132 // b. checking for "-" or "+" as first character 133 // -- i. Adding to appropriate array if there is such a character 134 foreach( $tags_setting_list as $cur_tag ) 135 { 136 // trim any space from front and back 137 $cur_tag = trim( $cur_tag ); 138 // we'll do trim() again on the + and - items, since there might be whitespace after the +/- 139 // check to see what the first character of the tag is 140 $first_char = substr( $cur_tag, 0, 1 ); 141 switch( $first_char ) 142 { 143 case '-': 144 $tags_to_remove[] = trim( substr( $cur_tag, 1 ) ); 145 break; 146 case '+': 147 $tags_to_add[] = trim( substr( $cur_tag, 1 ) ); 148 default: 149 $tags_to_add[] = trim( $cur_tag ); 150 } // end switch 151 } // end foreach 152 143 153 // get the current tags list for this post 144 154 $cur_post_tags = get_the_tags( $postid ); // returns an array of objects … … 147 157 // Make a new array to keep just the current tag list in 148 158 $new_cur_post_tags = array(); 149 // Step through $cur_post_tags objects, getting the 'name' parameter from each150 159 foreach( $cur_post_tags as $tag_object ) 151 160 { 152 161 $new_cur_post_tags[] = $tag_object->name; 153 162 } 154 // Add and remove tags as indicated 155 if ( !empty( $tags_to_remove ) ) 156 { 157 // remove any indicated tags 158 $new_cur_post_tags = array_diff( $new_cur_post_tags, $tags_to_remove ); 163 // Remove tags from current list 164 if( !empty( $tags_to_remove ) ) { 165 $new_cur_post_tags = array_diff( $new_cur_post_tags, $tags_to_remove ); 159 166 } 160 if ( !empty( $tags_to_add ) ) 161 { 162 // add any indicated tags 163 $final_tag_list = array_merge( $new_cur_post_tags, $tags_to_add ); 164 } 167 // Add tags to current list 168 if( !empty( $tags_to_add ) ) { 169 $new_cur_post_tags = array_merge( $new_cur_post_tags, $tags_to_add ); 170 } 171 // now build final tag list. this could be better 172 $final_tag_list = $new_cur_post_tags; 165 173 } 166 174 else … … 168 176 // there were no current tags in the post, so we're just adding 169 177 $final_tag_list = $tags_to_add; 170 } 171 } // end if checking for tags_absolute 172 // now I need all those tags comma delimited again (did we have to go into the array and back out of it to handle the duplicates?) 173 $final_tag_list = implode( ", ", $final_tag_list ); 174 // add the tag list to our $update_post 175 $update_post['tags_input'] = $final_tag_list; 178 } // end if checking for empty current post tag list 179 180 // now I need all those tags comma delimited again (did we have to go into the array and back out of it to handle the duplicates?) 181 $final_tag_list = implode( ", ", $final_tag_list ); 182 // add the tag list to our $update_post 183 $update_post['tags_input'] = $final_tag_list; 184 } // end if for having tags_to_add 176 185 } // endif for $proceed == true 177 186 } // end if for post_type existing 187 178 188 // ============================================================= 179 189 // NOW ACTUALLY UPDATE THE POST RECORD … … 192 202 update_post_meta( $postid, '_cs-enable-schedule', 'Disable' ); 193 203 } 194 // The rest of this stuff is not actually stored in _posts195 // STICKINESS (Pages do not have STICKY ability)196 // Note: This is stored in the options table, and is not part of post_update197 // get the array of sticky posts198 // What do we want to do with stickiness?199 $sticky_change = $options['chg-sticky'];200 if( $sticky_change == '1' )201 {202 $sticky_posts = get_option('sticky_posts');203 if( ! empty( $sticky_posts ) )204 {205 // Remove $postid from the $sticky_posts[] array206 foreach( $sticky_posts as $key => $stuck_id )207 {208 if( $stuck_id == $postid )209 {210 // remove $key from $sticky_posts211 unset( $sticky_posts[$key] );212 break;213 } // end if214 } // end foreach215 // Get the new array of stickies back into WP216 update_option('sticky_posts', $sticky_posts);217 } // end if218 } // end if219 204 ?> -
content-scheduler/trunk/readme.txt
r579494 r706934 7 7 Author: Paul Kaiser (freakingid) 8 8 Requires at least: 2.9 9 Tested up to: 3. 4.110 Stable tag: 0.9.99 Tested up to: 3.5.1 10 Stable tag: 1.0.0 11 11 12 12 Schedule content to automatically expire and change at a certain time, and notify people of expiration. … … 14 14 == Description == 15 15 16 Content Scheduler lets you control when content automatically expires, what to do with that content when it expires, and optionally how toprovide notification to site contributors when the content expired.16 Content Scheduler lets you control when content automatically expires, what to do with that content when it expires, and optionally provide notification to site contributors when the content expired. 17 17 18 18 = Expiration Options = … … 31 31 32 32 * When expiration occurs 33 * A specific number of days before expiration occurs34 33 35 34 This reminder helps you keep content fresh, providing a reminder that content is out of date and needs updated or replaced. Content Scheduler lets you use notification tools without making any changes to content upon expiration, if you'd like. 36 37 = More Information =38 39 Documentation included with the plugin in PDF format.40 Also see the developer's site, [Structure Web Development:](http://structurewebdev.com/)41 35 42 36 == Installation == … … 79 73 80 74 == Changelog == 75 76 = 1.0.0 = 77 * FIX: addition and removal of post tags 78 * CHANGE: removed option for setting absolute list of tags 79 * FIX: multiple unwanted notifications 80 * CHANGE: removed option for sending notifications prior to notification (only happens upon expiration event now) 81 81 82 82 = 0.9.9 = … … 124 124 * First public release. 125 125 126 == Upcoming == 127 128 a. Improved, more standard datepicker for expiration date/time field. 129 b. Removal of irrelevant "seconds" picking from date/time field. 130 c. Explore support for manipulating custom taxonomy terms upon expiration. 131 d. Explore support for manipulating custom meta values upon expiration. 132 e. Explore support for swapping content from a separate post upon expiration. 133 f. Revamped documentation. 134 g. Clean up settings panel. 135 126 136 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.