| ... | ... |
@@ -26,4 +26,41 @@ class Class_Rucy_Component {
|
| 26 | 26 |
unset( $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item'] ); |
| 27 | 27 |
return $post_types; |
| 28 | 28 |
} |
| 29 |
+ |
|
| 30 |
+ public function get_post_meta_keys() {
|
|
| 31 |
+ $post_meta_keys = new stdClass(); |
|
| 32 |
+ $post_meta_keys->accept = 'rc_reserv_accept'; |
|
| 33 |
+ $post_meta_keys->content = 'rc_reserv_content'; |
|
| 34 |
+ $post_meta_keys->date = 'rc_reserv_date'; |
|
| 35 |
+ $post_meta_keys->feature_img = 'rc_reserv_feature_image'; |
|
| 36 |
+ $post_meta_keys->accept_feature_img = 'rc_reserv_accept_feature_image'; |
|
| 37 |
+ $post_meta_keys->accept_update = 'rc_reserv_accept_post_update'; |
|
| 38 |
+ return $post_meta_keys; |
|
| 39 |
+ } |
|
| 40 |
+ |
|
| 41 |
+ public function get_post_rc_meta( $post_id = "" ) {
|
|
| 42 |
+ $base = $this->get_post_meta_keys(); |
|
| 43 |
+ $res = new stdClass(); |
|
| 44 |
+ if( $post_id > 0 ) {
|
|
| 45 |
+ foreach ( $base as $key => $value ) {
|
|
| 46 |
+ $res->$key = get_post_meta( $post_id, $value, true ); |
|
| 47 |
+ } |
|
| 48 |
+ } |
|
| 49 |
+ return $res; |
|
| 50 |
+ } |
|
| 51 |
+ |
|
| 52 |
+ public function save_rc_post_meta_base( $post_id, $post_meta_key, array $post ) {
|
|
| 53 |
+ if ( is_array( $post ) ) {
|
|
| 54 |
+ $post_data = ""; |
|
| 55 |
+ if ( isset( $post[$post_meta_key] ) ) {
|
|
| 56 |
+ $post_data = $post[$post_meta_key]; |
|
| 57 |
+ } |
|
| 58 |
+ $meta = get_post_meta( $post_id, $post_meta_key, true ); |
|
| 59 |
+ if ( $meta != $post_data ) {
|
|
| 60 |
+ update_post_meta( $post_id, $post_meta_key, $post_data, $meta ); |
|
| 61 |
+ } elseif ( $post_data == "" ) {
|
|
| 62 |
+ delete_post_meta( $post_id, $post_meta_key ); |
|
| 63 |
+ } |
|
| 64 |
+ } |
|
| 65 |
+ } |
|
| 29 | 66 |
} |
| 30 | 67 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,202 @@ |
| 0 |
+<?php |
|
| 1 |
+/** |
|
| 2 |
+ * |
|
| 3 |
+ * |
|
| 4 |
+ * @author Nita |
|
| 5 |
+ */ |
|
| 6 |
+require_once RC_PLUGIN_DIR . '/inc/class-rucy-component.php'; |
|
| 7 |
+ |
|
| 8 |
+class Class_Rucy_Editer {
|
|
| 9 |
+ public $post_metas; |
|
| 10 |
+ public $post_meta_keys; |
|
| 11 |
+ public $support_post_types; |
|
| 12 |
+ public $current_post_content; |
|
| 13 |
+ |
|
| 14 |
+ public function add_rucy_metabox() {
|
|
| 15 |
+ $component = new Class_Rucy_Component(); |
|
| 16 |
+ $support_post_types = $component->get_support_post_type(); |
|
| 17 |
+ foreach ( $support_post_types as $post_type ) {
|
|
| 18 |
+ add_meta_box( 'rucy_metabox', 'Rucy - Reservation Update Content -', array( $this, 'add_rucy_editor_box' ), $post_type, 'normal', 'high' ); |
|
| 19 |
+ } |
|
| 20 |
+ } |
|
| 21 |
+ |
|
| 22 |
+ public function add_rucy_editor_box() {
|
|
| 23 |
+ global $post; |
|
| 24 |
+ $component = new Class_Rucy_Component(); |
|
| 25 |
+ $current_year = date_i18n( 'Y' ); |
|
| 26 |
+ $support_post_types = $component->get_support_post_type(); |
|
| 27 |
+ $this->support_post_types = $support_post_types; |
|
| 28 |
+ $this->post_meta_keys = $component->get_post_meta_keys(); |
|
| 29 |
+ $this->post_metas = $component->get_post_rc_meta( $post->ID ); |
|
| 30 |
+ $this->current_post_content = $post->post_content; |
|
| 31 |
+ $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
|
| 32 |
+ |
|
| 33 |
+ $reserve_date = ( $this->post_metas->date == "" ) ? date_i18n( 'Y-m-d H:i:s' ) : $this->post_metas->date; |
|
| 34 |
+ $arr_reserve_date = getdate(strtotime( $reserve_date ) ); |
|
| 35 |
+ $arr_date = array( |
|
| 36 |
+ 'rc_year' => date_i18n( 'Y', $arr_reserve_date[0] ), |
|
| 37 |
+ 'rc_month' => date_i18n( 'm', $arr_reserve_date[0] ), |
|
| 38 |
+ 'rc_day' => date_i18n( 'd', $arr_reserve_date[0] ), |
|
| 39 |
+ 'rc_hour' => date_i18n( 'H', $arr_reserve_date[0] ), |
|
| 40 |
+ 'rc_minutes' => date_i18n( 'i', $arr_reserve_date[0] ), |
|
| 41 |
+ ); |
|
| 42 |
+ $reserve_content = ( $this->post_metas->content == "" ) ? $this->current_post_content : $this->post_metas->content; |
|
| 43 |
+?> |
|
| 44 |
+<div id="rc-post-wrap" class="curtime"> |
|
| 45 |
+ <input type="hidden" id="schroeder" name="schroeder" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>" /> |
|
| 46 |
+ <label for="<?php echo $this->post_meta_keys->accept; ?>" class="rc_accept"><input type="checkbox" id="<?php echo $this->post_meta_keys->accept; ?>" name="<?php echo $this->post_meta_keys->accept; ?>" value="1" <?php echo ( $this->post_metas->accept == "1" ) ? "checked" : ""; ?> /> <?php _e('Accept reserve update content.',RC_TXT_DOMAIN) ?></label>
|
|
| 47 |
+ <div class="rc-datetime" id="timestamp"> |
|
| 48 |
+ <?php _e( 'UpdateTime', RC_TXT_DOMAIN ); ?> : <strong><?php echo date_i18n( 'Y/m/d @ H:i', strtotime( $reserve_date ) ); ?></strong> |
|
| 49 |
+ </div> |
|
| 50 |
+ <a href="#edit-reservdate" class="edit-timestamp rc-datetime-edit"><?php _e( 'Edit' ); ?></a> |
|
| 51 |
+ <div class="rc-datetime-wrap"> |
|
| 52 |
+ <select name="rc_year" id=""> |
|
| 53 |
+ <?php for( $y = $current_year; $y <= ( $current_year + 3); $y++ ): |
|
| 54 |
+ $selected_y = ( $y == date_i18n( 'Y', $arr_reserve_date[0] ) ) ? "selected" : ""; ?> |
|
| 55 |
+ <option value="<?php echo $y; ?>" <?php echo $selected_y; ?>><?php echo $y; ?></option> |
|
| 56 |
+ <?php endfor; ?> |
|
| 57 |
+ </select> / |
|
| 58 |
+ <select name="rc_month" id=""> |
|
| 59 |
+ <?php for( $i = 1; $i <= 12; $i++ ): |
|
| 60 |
+ $m = sprintf( "%02d", $i ); |
|
| 61 |
+ $selected_m = ( $m == date_i18n( 'm', $arr_reserve_date[0] ) ) ? "selected" : ""; |
|
| 62 |
+ ?> |
|
| 63 |
+ <option value="<?php echo $m; ?>" <?php echo $selected_m; ?>><?php echo $m; ?></option> |
|
| 64 |
+ <?php endfor; ?> |
|
| 65 |
+ </select> / |
|
| 66 |
+ <select name="rc_day" id=""> |
|
| 67 |
+ <?php for( $d = 1; $d<=31; $d++ ): |
|
| 68 |
+ $d = sprintf( "%02d", $d ); |
|
| 69 |
+ $selected_d = ( $d == date_i18n( 'd', $arr_reserve_date[0] ) ) ? "selected" : ""; |
|
| 70 |
+ ?> |
|
| 71 |
+ <option value="<?php echo $d; ?>" <?php echo $selected_d; ?>><?php echo $d; ?></option> |
|
| 72 |
+ <?php endfor; ?> |
|
| 73 |
+ </select>@ |
|
| 74 |
+ <select name="rc_hour" id=""> |
|
| 75 |
+ <?php for( $h = 0; $h <= 23; $h++ ): |
|
| 76 |
+ $h = sprintf("%02d",$h);
|
|
| 77 |
+ $selected_h = ( $h == date_i18n( 'H', $arr_reserve_date[0] ) ) ? "selected" : ""; |
|
| 78 |
+ ?> |
|
| 79 |
+ <option value="<?php echo $h; ?>" <?php echo $selected_h; ?>><?php echo $h; ?></option> |
|
| 80 |
+ <?php endfor; ?> |
|
| 81 |
+ </select>: |
|
| 82 |
+ <select name="rc_minutes" id=""> |
|
| 83 |
+ <?php for( $min = 0; $min <= 59; $min++ ): |
|
| 84 |
+ $min = sprintf( "%02d", $min ); |
|
| 85 |
+ $selected_min = ( $min == date_i18n( 'i', $arr_reserve_date[0] ) ) ? "selected" : ""; |
|
| 86 |
+ ?> |
|
| 87 |
+ <option value="<?php echo $min; ?>" <?php echo $selected_min; ?>><?php echo $min; ?></option> |
|
| 88 |
+ <?php endfor; ?> |
|
| 89 |
+ </select> |
|
| 90 |
+ <a href="#edit-reservdate" class="rc-datetime-update button"><?php _e('OK',RC_TXT_DOMAIN) ?></a>
|
|
| 91 |
+ <a href="#edit-reservdate" class="rc-datetime-cancel"><?php _e('Cancel',RC_TXT_DOMAIN) ?></a>
|
|
| 92 |
+ </div> |
|
| 93 |
+ <?php foreach ( $arr_date as $k => $v ): ?> |
|
| 94 |
+ <input type="hidden" name="<?php echo $k; ?>_cr" id="<?php echo $k; ?>_cr" value="<?php echo $v; ?>" /> |
|
| 95 |
+ <?php endforeach; ?> |
|
| 96 |
+ <div id="rc-accept-update-update"> |
|
| 97 |
+ <label for="rc-accept-update-postdate"> |
|
| 98 |
+ <input type="checkbox" name="<?php echo $this->post_meta_keys->accept_update; ?>" value="1" id="rc-accept-update-postdate" class="rc-accept-update-postdate" <?php echo ( $this->post_metas->accept_update == "1" ) ? "checked" : ""; ?> /> <?php _e('Accept reserve update post date.', RC_TXT_DOMAIN); ?>
|
|
| 99 |
+ </label> |
|
| 100 |
+ </div> |
|
| 101 |
+<?php if( array_search( 'rc_update_postdate', $dismissed ) === false ): |
|
| 102 |
+ $pointer_content = '<h3>' . __( 'Attention - reservation update UpdateTime', RC_TXT_DOMAIN ) . '</h3>'; |
|
| 103 |
+ $pointer_content .= '<p>' . __( "If update UpdateTime, this post\'s permalink is changed by permalink settings.", RC_TXT_DOMAIN ) . '</p>'; |
|
| 104 |
+ ?> |
|
| 105 |
+ <script type="text/javascript"> |
|
| 106 |
+ jQuery(document).ready(function(){
|
|
| 107 |
+ // show notice pointer update postdate. |
|
| 108 |
+ jQuery('#rc-accept-update-update').pointer({
|
|
| 109 |
+ content : '<?php echo $pointer_content; ?>', |
|
| 110 |
+ buttons : function(e, t){
|
|
| 111 |
+ return jQuery('<a class="close" href="#"><?php _e( 'Do not show future', RC_TXT_DOMAIN ) ?></a>').bind('click.pointer',function(e){
|
|
| 112 |
+ e.preventDefault(); |
|
| 113 |
+ t.element.pointer('close');
|
|
| 114 |
+ }); |
|
| 115 |
+ }, |
|
| 116 |
+ position : { edge : "top", align : "left"},
|
|
| 117 |
+ close : function(){
|
|
| 118 |
+ jQuery.post("<?php echo admin_url( 'admin-ajax.php' ); ?>", {
|
|
| 119 |
+ action : 'dismiss-wp-pointer', |
|
| 120 |
+ pointer : 'rc_update_postdate' |
|
| 121 |
+ }); |
|
| 122 |
+ } |
|
| 123 |
+ }).pointer('open');
|
|
| 124 |
+ }); |
|
| 125 |
+ </script> |
|
| 126 |
+<?php endif; ?> |
|
| 127 |
+</div> |
|
| 128 |
+<?php |
|
| 129 |
+ wp_editor( $reserve_content, $this->post_meta_keys->content ); |
|
| 130 |
+ /* |
|
| 131 |
+ * support feature image reservation. |
|
| 132 |
+ */ |
|
| 133 |
+ if( current_theme_supports('post-thumbnails') ):
|
|
| 134 |
+?> |
|
| 135 |
+<fieldset> |
|
| 136 |
+<h3><?php echo __( 'Featured Image for Reservation Update', RC_TXT_DOMAIN ); ?></h3> |
|
| 137 |
+<label class="rc_feature_accept"> |
|
| 138 |
+ <input type="checkbox" name="<?php echo $this->post_meta_keys->accept_feature_img; ?>" value="1" <?php echo ( $this->post_metas->accept_feature_img == "1") ? "checked" : ""; ?>> <?php _e( 'Accept reserve update feature image.', RC_TXT_DOMAIN ); ?> |
|
| 139 |
+</label> |
|
| 140 |
+<div class="rc_feature_image_uploader"> |
|
| 141 |
+ <p><button id="rc_feature_image_upload" class="button rc-feature-uploader-button <?php echo ( $this->post_metas->feature_img != '' ) ? ' has_image' : ''; ?>"><?php _e( 'Set featured image for Reservation', RC_TXT_DOMAIN ); ?></button></p> |
|
| 142 |
+<div class="rc-feature-image-uploader__ctrl"> |
|
| 143 |
+ <div class="rc-feature-image-preview"> |
|
| 144 |
+ <?php |
|
| 145 |
+ if ( ! empty( $this->post_metas->feature_img ) ) {
|
|
| 146 |
+ echo $this->post_metas->feature_img; |
|
| 147 |
+ } |
|
| 148 |
+ ?> |
|
| 149 |
+ </div> |
|
| 150 |
+</div> |
|
| 151 |
+<p><button class="button rc_remove_feature_image"><?php _e( 'Remove Featured image for Reservation', RC_TXT_DOMAIN ); ?></button></p> |
|
| 152 |
+<input type="hidden" id="rc_feature_image" name="<?php echo $this->post_meta_keys->feature_img; ?>" value="<?php echo $this->post_metas->feature_img; ?>" /> |
|
| 153 |
+</div> |
|
| 154 |
+</fieldset> |
|
| 155 |
+<?php |
|
| 156 |
+ endif; |
|
| 157 |
+ } |
|
| 158 |
+ |
|
| 159 |
+// save post meta |
|
| 160 |
+ public function save_rc_post_meta( $post_id ) {
|
|
| 161 |
+ $component = new Class_Rucy_Component(); |
|
| 162 |
+ if( !isset( $_POST ) && !isset( $_POST['post_type'] ) ) {
|
|
| 163 |
+ return; |
|
| 164 |
+ } |
|
| 165 |
+ if(isset( $_POST['schroeder'] ) && !wp_verify_nonce( $_POST['schroeder'], plugin_basename( __FILE__ ) ) ) {
|
|
| 166 |
+ return; |
|
| 167 |
+ } |
|
| 168 |
+ if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
|
| 169 |
+ return; |
|
| 170 |
+ } |
|
| 171 |
+ $accept_post_types = $component->get_support_post_type(); |
|
| 172 |
+ if ( !in_array( $_POST['post_type'], $accept_post_types ) ) {
|
|
| 173 |
+ return; |
|
| 174 |
+ } |
|
| 175 |
+ $post_meta_keys = $component->get_post_meta_keys(); |
|
| 176 |
+ $date = mktime( $_POST['rc_hour'], $_POST['rc_minutes'], 00, $_POST['rc_month'], $_POST['rc_day'], $_POST['rc_year'] ); |
|
| 177 |
+ if( $date ) {
|
|
| 178 |
+ $_POST[$post_meta_keys->date] = date_i18n( 'Y-m-d H:i:s', $date ); |
|
| 179 |
+ } else {
|
|
| 180 |
+ $_POST[$post_meta_keys->date] = ""; |
|
| 181 |
+ } |
|
| 182 |
+ if( !isset( $_POST[$post_meta_keys->accept] ) || $_POST[$post_meta_keys->accept] != "1" ){
|
|
| 183 |
+ $_POST[$post_meta_keys->accept] = "0"; |
|
| 184 |
+ } |
|
| 185 |
+ // save post meta |
|
| 186 |
+ $meta_keys = array( 'accept', 'content', 'date', 'feature_img', 'accept_feature_img', 'accept_update' ); |
|
| 187 |
+ foreach ( $meta_keys as $mk ) {
|
|
| 188 |
+ $component->save_rc_post_meta_base( $post_id, $post_meta_keys->$mk, $_POST ); |
|
| 189 |
+ } |
|
| 190 |
+ // regist reserve update content |
|
| 191 |
+ if ( $_POST[$post_meta_keys->accept] == "1" ) {
|
|
| 192 |
+ $reserve_date = strtotime( get_gmt_from_date( $_POST[$post_meta_keys->date] ) . " GMT" ); |
|
| 193 |
+ if ( in_array( $_POST['post_type'], $accept_post_types ) ) {
|
|
| 194 |
+ wp_schedule_single_event( $reserve_date, RC_CRON_HOOK, array( $post_id ) ); |
|
| 195 |
+ } |
|
| 196 |
+ } else if ( $_POST[$post_meta_keys->accept] == "0" || !isset ( $_POST[$post_meta_keys->accept] ) ) {
|
|
| 197 |
+ // delete schedule |
|
| 198 |
+ wp_clear_scheduled_hook(RC_CRON_HOOK, array($post_id)); |
|
| 199 |
+ } |
|
| 200 |
+ } |
|
| 201 |
+} |
| ... | ... |
@@ -20,6 +20,7 @@ load_plugin_textdomain( RC_TXT_DOMAIN, false, 'rucy/lang' ); |
| 20 | 20 |
|
| 21 | 21 |
require_once RC_PLUGIN_DIR . '/inc/class-rucy-component.php'; |
| 22 | 22 |
require_once RC_PLUGIN_DIR . '/inc/class-rucy-setting.php'; |
| 23 |
+require_once RC_PLUGIN_DIR . '/inc/class-rucy-editor.php'; |
|
| 23 | 24 |
|
| 24 | 25 |
class Rucy_Class {
|
| 25 | 26 |
public $support_post_type = array(); |
| ... | ... |
@@ -27,10 +28,13 @@ class Rucy_Class {
|
| 27 | 27 |
public function __construct() {
|
| 28 | 28 |
register_activation_hook( plugin_basename(__FILE__), array( $this, 'activate_plugin' ) ); |
| 29 | 29 |
add_action('admin_enqueue_scripts', array( $this, 'enqueue_style_script' ));
|
| 30 |
- add_action( 'wp_admin', array( $this, 'enqueue_pointer_menu' ) ); |
|
| 30 |
+ add_action( 'admin_menu', array( $this, 'enqueue_pointer_menu' ) ); |
|
| 31 | 31 |
$setting = new Class_Rucy_Setting(); |
| 32 | 32 |
add_action( 'admin_menu', array( $setting, 'set_admin_menu' ) ); |
| 33 | 33 |
add_action( 'admin_notices', array( $setting, 'set_admin_notices' ) ); |
| 34 |
+ $editor = new Class_Rucy_Editer(); |
|
| 35 |
+ add_action( 'admin_menu', array( $editor, 'add_rucy_metabox' ) ); |
|
| 36 |
+ add_action( 'save_post', array( $editor, 'save_rc_post_meta' ) ); |
|
| 34 | 37 |
} |
| 35 | 38 |
|
| 36 | 39 |
public function activate_plugin() {
|