Browse code

Merge branch 'develop'

Conflicts:
rucy.php

nita authored on 2015/10/20 01:57:52
Showing 12 changed files
... ...
@@ -32,4 +32,38 @@
32 32
     max-width: 100%;
33 33
     width: 50%;
34 34
     height: auto;
35
-}
36 35
\ No newline at end of file
36
+}
37
+
38
+#rc-rollback-container {
39
+    margin: 16px 0;
40
+    padding-top: 8px;
41
+    border-top: 1px solid #eee;
42
+}
43
+.rc-rollback-datetime-wrap {
44
+    display: none;
45
+    margin: 10px 0;
46
+    line-height: 28px;
47
+}
48
+.rc-rollback-datetime-wrap select {
49
+    line-height: 14px;
50
+    padding: 0;
51
+    vertical-align: top;
52
+    font-size: 12px;
53
+}
54
+.rc-rollback-datetime-wrap input {
55
+    border-width: 1px;
56
+    border-style: solid;
57
+}
58
+.rc-rollback-datetime {
59
+    display: inline-block;
60
+}
61
+
62
+.rc-donation {
63
+    float: left;
64
+    clear: both;
65
+    background-color: #faf096;
66
+    border: 1px solid #faa824;
67
+    border-radius: 3px;
68
+    padding: 0 12px;
69
+    color: #212121;
70
+}
37 71
new file mode 100644
... ...
@@ -0,0 +1,72 @@
0
+<?php
1
+/**
2
+ * Description of class-rucy-componet
3
+ *
4
+ * @author Nita
5
+ */
6
+class Class_Rucy_Component {
7
+    /**
8
+     * 
9
+     * 
10
+     * @return bool 
11
+     */
12
+    public function update_support_post_type( array $post_types ) {
13
+        return update_option( RC_SETTING_OPTION_KEY, $post_types );
14
+    }
15
+    public function get_support_post_type() {
16
+        $res = get_option( RC_SETTING_OPTION_KEY );
17
+        if( !$res ) {
18
+            $res = array( 'post', 'page' );
19
+        } else if ( !is_array( $res ) ) {
20
+            $res = explode( ',' , $res );
21
+        }
22
+        return $res;
23
+    }
24
+    public function get_post_types( $type = 'objects' ) {
25
+        $args = array( 'public' => true, );
26
+        $post_types = get_post_types( $args, $type );
27
+        unset( $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item'] );
28
+        return $post_types;
29
+    }
30
+    
31
+    public function get_post_meta_keys() {
32
+        $post_meta_keys = new stdClass();
33
+        $post_meta_keys->accept = 'rc_reserv_accept';
34
+        $post_meta_keys->content = 'rc_reserv_content';
35
+        $post_meta_keys->date = 'rc_reserv_date';
36
+        $post_meta_keys->feature_img = 'rc_reserv_feature_image';
37
+        $post_meta_keys->accept_feature_img = 'rc_reserv_accept_feature_image';
38
+        $post_meta_keys->accept_update = 'rc_reserv_accept_post_update';
39
+        $post_meta_keys->accept_rollback = 'rc_rollback_accept';
40
+        $post_meta_keys->rollback_date = 'rc_rollback_date';
41
+        $post_meta_keys->accept_rollback_update = 'rc_rollback_accept_update_date';
42
+        $post_meta_keys->accept_rollback_feature_img = 'rc_rollback_accept_feature_image';
43
+        return $post_meta_keys;
44
+    }
45
+    
46
+    public function get_post_rc_meta( $post_id = "" ) {
47
+        $base = $this->get_post_meta_keys();
48
+        $res = new stdClass();
49
+        if( $post_id > 0 ) {
50
+            foreach ( $base as $key => $value ) {
51
+                    $res->$key = get_post_meta( $post_id, $value, true );
52
+            }
53
+        }
54
+        return $res;
55
+    }
56
+    
57
+    public function save_rc_post_meta_base( $post_id, $post_meta_key, array $post ) {
58
+        if ( is_array( $post ) ) {
59
+            $post_data = "";
60
+            if ( isset( $post[$post_meta_key] ) ) {
61
+                $post_data = $post[$post_meta_key];
62
+            }
63
+            $meta = get_post_meta( $post_id, $post_meta_key, true );
64
+            if ( $meta != $post_data ) {
65
+                update_post_meta( $post_id, $post_meta_key, $post_data, $meta );
66
+            } elseif ( $post_data == "" ) {
67
+                delete_post_meta( $post_id, $post_meta_key );
68
+            }
69
+        }
70
+    }
71
+}
0 72
new file mode 100644
... ...
@@ -0,0 +1,131 @@
0
+<?php
1
+/**
2
+ * Description of class-rucy-cron
3
+ *
4
+ * @author Nita
5
+ */
6
+require_once RC_PLUGIN_DIR . '/inc/class-rucy-component.php';
7
+
8
+class Class_Rucy_Cron {
9
+    
10
+    public function update_rc_reserved_content( $post_id ) {
11
+        $component = new Class_Rucy_Component();
12
+        $post_metas = $component->get_post_rc_meta( (int)$post_id );
13
+        if ( $post_metas->accept != "1" ) {
14
+            return;
15
+        }
16
+        // rollback
17
+        $rollback_data = array();
18
+        if( $post_metas->accept_rollback == "1" ) {
19
+            $rollback_data = $this->get_rollback_post( (int)$post_id, $post_metas->accept_rollback_date, $post_metas->accept_rollback_feature_img );
20
+        }
21
+        // set update content
22
+        $updates = array( 
23
+            'ID' => (int)$post_id,    
24
+            'post_content' => apply_filters( 'the_content', $post_metas->content ),
25
+        );
26
+        // set update post date
27
+        if ( $post_metas->accept_update == "1" ) {
28
+            $updates['post_date'] = $post_metas->date;
29
+            $updates['post_date_gmt'] = get_gmt_from_date( $post_metas->date );
30
+        }
31
+        // update post
32
+        remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
33
+        remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
34
+        add_filter( 'content_save_pre', array( $this, 'rc_content_allow_iframe' ) );
35
+        wp_update_post( $updates, true );
36
+        remove_filter( 'content_save_pre', array( $this, 'rc_content_allow_iframe' ) );
37
+        add_filter( 'content_save_pre', 'wp_filter_post_kses' );
38
+        add_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
39
+        // update feature image
40
+        if ( $post_metas->accept_feature_img == "1" && $post_metas->feature_img != "" ) {
41
+            $this->update_post_thumbnail( $post_id, $post_metas->feature_img );
42
+        }
43
+        // delete post metas
44
+        $post_meta_keys = $component->get_post_meta_keys();
45
+        foreach ( $post_meta_keys as $key => $value ) {
46
+            delete_post_meta( $post_id, $value );
47
+        }
48
+        // clear schedule on wp_cron
49
+        wp_clear_scheduled_hook( RC_CRON_HOOK, array( $post_id ) );
50
+        // save post meta for rollback
51
+        if ( $post_metas->accept_rollback == "1" ) {
52
+            $reserve_date = strtotime( get_gmt_from_date( $post_metas->rollback_date ) . "GMT" );
53
+            $this->set_rollback_setting( $post_id, $reserve_date, $rollback_data );
54
+        }
55
+    }
56
+    
57
+    public function rc_content_allow_iframe( $content ) {
58
+        global $allowedposttags;
59
+        // iframe and attribute in iframe
60
+        $allowedposttags['iframe'] = array(
61
+            'class' => array(), 'src' => array(),
62
+            'width' => array(), 'height' => array(),
63
+            'frameborder' => array(), 'scrolling' => array(),
64
+            'marginheight' => array(), 'marginwidth' => array(),
65
+            'srcdoc' => array(), 'sandbox' => array(),
66
+            'seamless' => array(), 'name' => array(),
67
+        );
68
+        return $content;
69
+    }
70
+    
71
+    private function update_post_thumbnail( $post_id, $reserved_post_thumb_path ) {
72
+        include_once(ABSPATH . 'wp-admin/includes/image.php');
73
+        $upload_dir = wp_upload_dir();
74
+        $image_data = file_get_contents( $reserved_post_thumb_path );
75
+        $file_name = basename( $reserved_post_thumb_path );
76
+        
77
+        if( wp_mkdir_p( $upload_dir['path'] ) ) {
78
+           $file = $upload_dir['path'] . '/' . $file_name; 
79
+        } else {
80
+           $file = $upload_dir['basedir'] . '/' . $file_name;
81
+        }
82
+        file_put_contents( $file, $image_data );
83
+        $wp_file_type = wp_check_filetype( $file_name, null );
84
+        $attachment = array(
85
+        'post_mime_type' => $wp_file_type['type'],
86
+        'post_title'     => sanitize_file_name( $file_name ),
87
+        'post_content'   => '',
88
+        'post_status'    => 'inherit',
89
+        );
90
+        delete_post_thumbnail( $post_id );
91
+        $attachment_id = wp_insert_attachment( $attachment, $file, $post_id );
92
+        $attach_data = wp_generate_attachment_metadata( $attachment_id, $file );
93
+        if( !empty( $attach_data ) && !is_wp_error( $attach_data ) ){
94
+            $res = wp_update_attachment_metadata( $attachment_id, $attach_data );
95
+            set_post_thumbnail( $post_id, $attachment_id );
96
+
97
+            return $res;
98
+        }
99
+    }
100
+    
101
+    private function get_rollback_post( $post_id, $accept_rollback_date = "0", $accept_rollback_feature_image = "0" ) {
102
+        $post_data = get_post( $post_id );
103
+        $component = new Class_Rucy_Component();
104
+        $post_meta_keys = $component->get_post_meta_keys();
105
+        
106
+        $res = array(
107
+            $post_meta_keys->content => $post_data->post_content,
108
+            $post_meta_keys->accept => "1",
109
+        );
110
+        if ( $accept_rollback_date == "1" ) {
111
+            $res[$post_meta_keys->accept_update] = "1";
112
+            $res[$post_meta_keys->date] = $post_data->post_date;
113
+        }
114
+        if ( $accept_rollback_feature_image == "1" ) {
115
+            $res[$post_meta_keys->accept_feature_img] = "1";
116
+            $feature_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'full' );
117
+            $res[$post_meta_keys->feature_img] = $feature_image[0];
118
+        }
119
+        
120
+        return $res;
121
+    }
122
+    
123
+    private function set_rollback_setting( $post_id, $reserve_date, array $rollback_data ) {
124
+        $component = new Class_Rucy_Component();
125
+        foreach ( $rollback_data as $key => $value ) {
126
+            $component->save_rc_post_meta_base( (int)$post_id, $key, $rollback_data );
127
+        }
128
+         wp_schedule_single_event( $reserve_date, RC_CRON_HOOK, array( $post_id ) );
129
+    }
130
+}
0 131
new file mode 100644
... ...
@@ -0,0 +1,332 @@
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
+        $reserve_date = ( $this->post_metas->date == "" ) ? date_i18n( 'Y-m-d H:i:s' ) : $this->post_metas->date;
33
+        $arr_reserve_date = getdate(strtotime( $reserve_date ) );
34
+        $arr_date = array(
35
+            'rc_year' => date_i18n( 'Y', $arr_reserve_date[0] ),
36
+            'rc_month' => date_i18n( 'm', $arr_reserve_date[0] ),
37
+            'rc_day' => date_i18n( 'd', $arr_reserve_date[0] ),
38
+            'rc_hour' => date_i18n( 'H', $arr_reserve_date[0] ),
39
+            'rc_minutes' => date_i18n( 'i', $arr_reserve_date[0] ),
40
+                );
41
+        $reserve_content = ( $this->post_metas->content == "" ) ? $this->current_post_content : $this->post_metas->content;
42
+        // rollback settings
43
+        $rollback_date = ( $this->post_metas->rollback_date == "" ) ? date_i18n( 'Y-m-d H:i:s' ) : $this->post_metas->rollback_date;
44
+        $arr_rollback_date = getdate(strtotime( $rollback_date ) );
45
+        $arr_rb_date = array(
46
+            'rc_rb_year' => date_i18n( 'Y', $arr_rollback_date[0] ),
47
+            'rc_rb_month' => date_i18n( 'm', $arr_rollback_date[0] ),
48
+            'rc_rb_day' => date_i18n( 'd', $arr_rollback_date[0] ),
49
+            'rc_rb_hour' => date_i18n( 'H', $arr_rollback_date[0] ),
50
+            'rc_rb_minutes' => date_i18n( 'i', $arr_rollback_date[0] ),
51
+        );
52
+?>
53
+<div id="rc-post-wrap" class="curtime">
54
+    <input type="hidden" id="schroeder" name="schroeder" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>" />
55
+    <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>
56
+    <div class="rc-datetime" id="timestamp">
57
+        <?php _e( 'UpdateTime', RC_TXT_DOMAIN ); ?> : <strong><?php echo date_i18n( 'Y/m/d @ H:i', strtotime( $reserve_date ) ); ?></strong>
58
+    </div>
59
+    <a href="#edit-reservdate" class="edit-timestamp rc-datetime-edit"><?php _e( 'Edit' ); ?></a>
60
+    <div class="rc-datetime-wrap">
61
+        <select name="rc_year" id="">
62
+        <?php  for( $y = $current_year; $y <= ( $current_year + 3); $y++ ): 
63
+            $selected_y = ( $y == date_i18n( 'Y', $arr_reserve_date[0] ) ) ? "selected" : ""; ?>
64
+            <option value="<?php echo $y; ?>" <?php echo $selected_y; ?>><?php echo $y; ?></option>
65
+        <?php endfor; ?>
66
+        </select> / 
67
+        <select name="rc_month" id="">
68
+        <?php for( $i = 1; $i <= 12; $i++ ):
69
+            $m = sprintf( "%02d", $i );
70
+            $selected_m = ( $m == date_i18n( 'm', $arr_reserve_date[0] ) ) ? "selected" : "";
71
+        ?>
72
+            <option value="<?php echo $m; ?>" <?php echo $selected_m; ?>><?php echo $m; ?></option>
73
+        <?php endfor; ?>
74
+        </select> / 
75
+        <select name="rc_day" id="">
76
+        <?php  for( $d = 1; $d<=31; $d++ ):
77
+            $d = sprintf( "%02d", $d );
78
+            $selected_d = ( $d == date_i18n( 'd', $arr_reserve_date[0] ) ) ? "selected" : "";
79
+        ?>
80
+            <option value="<?php echo $d; ?>" <?php echo $selected_d; ?>><?php echo $d; ?></option>
81
+        <?php endfor; ?>
82
+        </select>@
83
+        <select name="rc_hour" id="">
84
+        <?php for( $h = 0; $h <= 23; $h++ ): 
85
+            $h = sprintf("%02d",$h);
86
+            $selected_h = ( $h == date_i18n( 'H', $arr_reserve_date[0] ) ) ? "selected" : "";
87
+        ?>
88
+            <option value="<?php echo $h; ?>" <?php echo $selected_h; ?>><?php echo $h; ?></option>
89
+        <?php endfor; ?>
90
+        </select>:
91
+        <select name="rc_minutes" id="">
92
+        <?php for( $min = 0; $min <= 59; $min++ ): 
93
+            $min = sprintf( "%02d", $min );
94
+            $selected_min = ( $min == date_i18n( 'i', $arr_reserve_date[0] ) ) ? "selected" : "";
95
+            ?>
96
+            <option value="<?php echo $min; ?>" <?php echo $selected_min; ?>><?php echo $min; ?></option>
97
+        <?php endfor; ?>
98
+        </select>
99
+        <a href="#edit-reservdate" class="rc-datetime-update button"><?php _e('OK',RC_TXT_DOMAIN) ?></a>
100
+        <a href="#edit-reservdate" class="rc-datetime-cancel"><?php _e('Cancel',RC_TXT_DOMAIN) ?></a>
101
+    </div>
102
+    <?php foreach ( $arr_date as $k => $v ): ?>
103
+    <input type="hidden" name="<?php echo $k; ?>_cr" id="<?php echo $k; ?>_cr" value="<?php echo $v; ?>" />
104
+    <?php endforeach; ?>
105
+    <div id="rc-accept-update-update">
106
+        <label for="rc-accept-update-postdate">
107
+            <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); ?>
108
+        </label>
109
+    </div>
110
+<?php if( array_search( 'rc_update_postdate', $dismissed ) === false ): 
111
+    $pointer_content = '<h3>' . __( 'Attention - reservation update UpdateTime', RC_TXT_DOMAIN ) . '</h3>';
112
+    $pointer_content .= '<p>' . __( "If update UpdateTime, this post\'s permalink is changed by permalink settings.", RC_TXT_DOMAIN ) . '</p>';
113
+    ?>
114
+    <script type="text/javascript">
115
+        jQuery(document).ready(function(){
116
+            // show notice pointer update postdate.
117
+            jQuery('#rc-accept-update-update').pointer({
118
+                content : '<?php echo $pointer_content; ?>',
119
+                buttons : function(e, t){
120
+                    return jQuery('<a class="close" href="#"><?php _e( 'Do not show future', RC_TXT_DOMAIN ) ?></a>').bind('click.pointer',function(e){
121
+                        e.preventDefault();
122
+                        t.element.pointer('close');
123
+                    });
124
+                },
125
+                position : { edge : "top", align : "left"},
126
+                close : function(){
127
+                    jQuery.post("<?php echo admin_url( 'admin-ajax.php' ); ?>", {
128
+                        action : 'dismiss-wp-pointer',
129
+                        pointer : 'rc_update_postdate'
130
+                    });
131
+                }
132
+            }).pointer('open');
133
+        });
134
+    </script>
135
+<?php endif; ?>
136
+</div>
137
+<?php 
138
+ wp_editor( $reserve_content, $this->post_meta_keys->content );
139
+ /*
140
+  * support feature image reservation.
141
+  */
142
+ if( current_theme_supports('post-thumbnails') ):
143
+?>
144
+<fieldset>
145
+<h3><?php echo __( 'Featured Image for Reservation Update', RC_TXT_DOMAIN ); ?></h3>
146
+<label class="rc_feature_accept">
147
+    <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 ); ?>
148
+</label>
149
+<div class="rc_feature_image_uploader">
150
+    <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>
151
+<div class="rc-feature-image-uploader__ctrl">
152
+    <div class="rc-feature-image-preview">
153
+        <?php
154
+        if ( ! empty( $this->post_metas->feature_img ) ) {
155
+           echo $this->post_metas->feature_img;
156
+        }
157
+        ?> 
158
+    </div>
159
+</div>
160
+<p><button class="button rc_remove_feature_image"><?php _e( 'Remove Featured image for Reservation', RC_TXT_DOMAIN ); ?></button></p>
161
+<input type="hidden" id="rc_feature_image" name="<?php echo $this->post_meta_keys->feature_img; ?>" value="<?php echo $this->post_metas->feature_img; ?>" />
162
+</div>
163
+</fieldset>
164
+<fieldset id="rc-rollback-container" class="curtime">
165
+    <h3><?php _e( 'Setting Rollback post content.', RC_TXT_DOMAIN ); ?></h3>
166
+    <label for="rc-accept-rollback-content">
167
+        <input type="checkbox" name="<?php echo $this->post_meta_keys->accept_rollback ?>" value="1" id="rc-accept-rollback-content" class="rc-accept-rollback-content" <?php echo ( $this->post_metas->accept_rollback == "1" ) ? "checked" : ""; ?> > <?php _e( 'Accept rollback content.', RC_TXT_DOMAIN ); ?>
168
+    </label>
169
+    <div class="rc-rollback-datetime" id="timestamp">
170
+        <?php _e( 'Rollback DateTime', RC_TXT_DOMAIN ); ?> : <strong><?php echo date_i18n("Y/m/d @ H:i", strtotime( $rollback_date ) ); ?></strong>
171
+    </div>
172
+    <a href="#edit-rollback-datetime" class="edit-timestamp rc-rollback-datetime-edit"><?php _e('Edit'); ?></a>
173
+    <div class="rc-rollback-datetime-wrap">
174
+        <select name="rc_rb_year" id="">
175
+    <?php  for( $y = $current_year; $y <= ( $current_year + 3); $y++ ): 
176
+        $selected_y = ( $y == date_i18n( 'Y', $arr_rollback_date[0] ) ) ? "selected" : ""; ?>
177
+        <option value="<?php echo $y; ?>" <?php echo $selected_y; ?>><?php echo $y; ?></option>
178
+    <?php endfor; ?>
179
+    </select> / 
180
+    <select name="rc_rb_month" id="">
181
+    <?php for( $i = 1; $i <= 12; $i++ ):
182
+        $m = sprintf( "%02d", $i );
183
+        $selected_m = ( $m == date_i18n( 'm', $arr_rollback_date[0] ) ) ? "selected" : "";
184
+    ?>
185
+        <option value="<?php echo $m; ?>" <?php echo $selected_m; ?>><?php echo $m; ?></option>
186
+    <?php endfor; ?>
187
+    </select> / 
188
+    <select name="rc_rb_day" id="">
189
+    <?php  for( $d = 1; $d<=31; $d++ ):
190
+        $d = sprintf( "%02d", $d );
191
+        $selected_d = ( $d == date_i18n( 'd', $arr_rollback_date[0] ) ) ? "selected" : "";
192
+    ?>
193
+        <option value="<?php echo $d; ?>" <?php echo $selected_d; ?>><?php echo $d; ?></option>
194
+    <?php endfor; ?>
195
+    </select>@
196
+    <select name="rc_rb_hour" id="">
197
+    <?php for( $h = 0; $h <= 23; $h++ ): 
198
+        $h = sprintf("%02d",$h);
199
+        $selected_h = ( $h == date_i18n( 'H', $arr_rollback_date[0] ) ) ? "selected" : "";
200
+    ?>
201
+        <option value="<?php echo $h; ?>" <?php echo $selected_h; ?>><?php echo $h; ?></option>
202
+    <?php endfor; ?>
203
+    </select>:
204
+    <select name="rc_rb_minutes" id="">
205
+    <?php for( $min = 0; $min <= 59; $min++ ): 
206
+        $min = sprintf( "%02d", $min );
207
+        $selected_min = ( $min == date_i18n( 'i', $arr_rollback_date[0] ) ) ? "selected" : "";
208
+        ?>
209
+        <option value="<?php echo $min; ?>" <?php echo $selected_min; ?>><?php echo $min; ?></option>
210
+    <?php endfor; ?>
211
+    </select>
212
+    <a href="#edit-rollback-datetime" class="rc-rollback-datetime-update button"><?php _e('OK',RC_TXT_DOMAIN) ?></a>
213
+    <a href="#edit-rollback-datetime" class="rc-rollback-datetime-cancel"><?php _e('Cancel',RC_TXT_DOMAIN) ?></a>
214
+    </div>
215
+    <?php foreach ( $arr_rb_date as $k => $v ):  ?>
216
+    <input type="hidden" name="<?php echo $k; ?>_cr" id="<?php echo $k; ?>_cr" value="<?php echo $v; ?>"/>
217
+    <?php endforeach; ?>
218
+    <div id="rc-accept-rollback-updatetime-wrap">
219
+        <label for="rc-accept-rollback-updatetime">
220
+            <input id="rc-accept-rollback-updatetime" type="checkbox" value="1" name="<?php echo $this->post_meta_keys->accept_rollback_update; ?>" <?php echo ( $this->post_metas->accept_rollback_update == "1" ) ? "checked" : ""; ?>> <?php _e( 'Accept Rollback post date.', RC_TXT_DOMAIN ); ?>
221
+        </label>
222
+    </div>
223
+    <?php if( current_theme_supports( 'post-thumbnails' ) ):  ?>
224
+    <div id="rc-accept-rollback-feature-image-wrap">
225
+        <label for="rc-accept-rollback-feature-image">
226
+            <input id="rc-accept-rollback-feature-image" type="checkbox" value="1" name="<?php echo $this->post_meta_keys->accept_rollback_feature_img; ?>" <?php echo ( $this->post_metas->accept_rollback_feature_img == "1" ) ? "checked" : ""; ?>> <?php _e( 'Accept Rollback feature image.', RC_TXT_DOMAIN ); ?>
227
+        </label>
228
+    </div>
229
+    <?php endif; ?>
230
+</fieldset>
231
+<?php 
232
+ endif;
233
+    }
234
+    
235
+// save post meta
236
+    public function save_rc_post_meta( $post_id ) {
237
+        $component = new Class_Rucy_Component();
238
+        if( !isset( $_POST ) && !isset( $_POST['post_type'] ) ) {
239
+            return;
240
+        }
241
+        if(isset( $_POST['schroeder'] ) && !wp_verify_nonce( $_POST['schroeder'], plugin_basename( __FILE__ ) ) ) {
242
+            return;
243
+        }
244
+        if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
245
+            return;
246
+        }
247
+        $accept_post_types = $component->get_support_post_type();
248
+        if ( !in_array( $_POST['post_type'], $accept_post_types ) ) {
249
+            return;
250
+        }
251
+        $post_meta_keys = $component->get_post_meta_keys();
252
+        $date = mktime( $_POST['rc_hour'], $_POST['rc_minutes'], 00, $_POST['rc_month'], $_POST['rc_day'], $_POST['rc_year'] );
253
+        if( $date ) {
254
+            $_POST[$post_meta_keys->date] = date_i18n( 'Y-m-d H:i:s', $date );
255
+        } else {
256
+            $_POST[$post_meta_keys->date] = "";
257
+        }
258
+        if( !isset( $_POST[$post_meta_keys->accept] ) || $_POST[$post_meta_keys->accept] != "1" ){
259
+                $_POST[$post_meta_keys->accept]  = "0";
260
+        }
261
+        // rollback setting
262
+        $rdate = mktime( $_POST['rc_rb_hour'], $_POST['rc_rb_minutes'], 00, $_POST['rc_rb_month'], $_POST['rc_rb_day'], $_POST['rc_rb_year'] );
263
+        if ( $rdate ) {
264
+            $_POST[$post_meta_keys->rollback_date] = date_i18n( 'Y-m-d H:i:s', $rdate );
265
+        } else {
266
+            $_POST[$post_meta_keys->rollback_date] = "";
267
+        }
268
+        if( !isset( $_POST[$post_meta_keys->accept_rollback] ) || $_POST[$post_meta_keys->accept_rollback] != "1" ){
269
+            $_POST[$post_meta_keys->accept_rollback] = "0";
270
+        }
271
+        if( !isset( $_POST[$post_meta_keys->accept_rollback_update] ) || $_POST[$post_meta_keys->accept_rollback_update] != "1" ){
272
+            $_POST[$post_meta_keys->accept_rollback_update] = "0";
273
+        }
274
+        if( !isset( $_POST[$post_meta_keys->accept_rollback_feature_img] ) || $_POST[$post_meta_keys->accept_rollback_feature_img] != "1" ){
275
+            $_POST[$post_meta_keys->accept_rollback_feature_img] = "0";
276
+        }
277
+        // save post meta 
278
+        foreach ( $post_meta_keys as $key => $value ) {
279
+            $component->save_rc_post_meta_base( $post_id, $value, $_POST );
280
+        }
281
+        // regist reserve update content
282
+        if ( $_POST[$post_meta_keys->accept] == "1" ) {
283
+            $reserve_date = strtotime( get_gmt_from_date( $_POST[$post_meta_keys->date] ) . " GMT" );
284
+            if ( in_array( $_POST['post_type'], $accept_post_types ) ) {
285
+                wp_schedule_single_event( $reserve_date, RC_CRON_HOOK, array( $post_id ) );
286
+            }
287
+        } else if ( $_POST[$post_meta_keys->accept] == "0" || !isset ( $_POST[$post_meta_keys->accept] ) ) {
288
+            // delete schedule
289
+            wp_clear_scheduled_hook(RC_CRON_HOOK, array($post_id));
290
+        }
291
+    }
292
+    
293
+    // add update message
294
+    public function add_reservation_message( $messages ) {
295
+        global $post, $post_ID;
296
+        $component = new Class_Rucy_Component();
297
+        $accept_post_types = $component->get_support_post_type();
298
+        $post_type = get_post_type( $post );
299
+        
300
+        if ( !in_array( $post_type, $accept_post_types ) ) {
301
+            return $messages;
302
+        }
303
+        
304
+        $post_metas = $component->get_post_rc_meta( $post_ID );
305
+        if ( $post_metas->accept != "1" ) {
306
+            return $messages;
307
+        }
308
+        
309
+        $add_message_date = date_i18n( 'Y/m/d @ H:i', strtotime( $post_metas->date ) );
310
+        $base_str = __( 'registered reservation update content _RC_DATETIME_', RC_TXT_DOMAIN );
311
+        $add_message = '<br>' . strtr( $base_str, array( '_RC_DATETIME_' => $add_message_date ) );
312
+        
313
+        if( $post_metas->accept_rollback == "1" ) {
314
+            $rollback_date = date_i18n( 'Y/m/d @ H:i', strtotime( $post_metas->rollback_date ) );
315
+            $rollback_base_str = __( 'registered rollback content _RC_ROLLBACK_DATETIME_ ', RC_TXT_DOMAIN );
316
+            $add_message .= '<br>' . strtr( $rollback_base_str , array( '_RC_ROLLBACK_DATETIME_' => $rollback_date ) );
317
+         }
318
+        // published
319
+        $messages[$post_type][1] .= $add_message;
320
+        $messages[$post_type][4] .= $add_message;
321
+        $messages[$post_type][6] .= $add_message;
322
+        // saved
323
+        $messages[$post_type][7] .= $add_message;
324
+        // submited
325
+        $messages[$post_type][8] .= $add_message;
326
+        // scheduled
327
+        $messages[$post_type][9] .= $add_message;
328
+        
329
+        return $messages;
330
+    }
331
+}
0 332
new file mode 100644
... ...
@@ -0,0 +1,93 @@
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_Setting {
9
+    //
10
+    public function set_admin_menu() {
11
+        add_options_page( 'Rucy', 'Rucy', 'manage_options', 'rucy', array( $this, 'add_setting_menu') );
12
+    }
13
+    
14
+    public function add_setting_menu() {
15
+        $component = new Class_Rucy_Component();
16
+        $post_types = $component->get_post_types();
17
+        $support_post_type = $component->get_support_post_type();
18
+        $is_different = false;
19
+        if( ( isset( $_POST['page_options'] ) && $_POST['page_options'] === RC_SETTING_OPTION_KEY )  
20
+           && ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'update-options' ) )
21
+          ) {
22
+            // update post
23
+            $post_support_posts = ( isset($_POST['rc_support_post_types']) ) ? $_POST['rc_support_post_types'] : array();
24
+            if( count( array_diff( $support_post_type, $post_support_posts ) ) ) {
25
+                // different data before post
26
+                $is_different = true;
27
+            }
28
+            $is_update = $component->update_support_post_type( $post_support_posts );
29
+            if ( $is_different && $is_update ) {
30
+                set_transient( RC_SETTING_UPDATE, array( __( 'Success to setting update.', RC_TXT_DOMAIN ) ), 10 );
31
+            } else if ( $is_different === false && $is_update === false ) {
32
+                set_transient( RC_SETTING_UPDATE, array( __( 'Success to setting update.', RC_TXT_DOMAIN ) ), 10 );
33
+            } else if ( $is_different && $is_update === false ) {
34
+                // 更新失敗
35
+                $e = new WP_Error();
36
+                $e->add( 'error', __( 'Failed to setting update.', RC_TXT_DOMAIN ) );
37
+                set_transient( RC_SETTING_ERROR, $e->get_error_messages(), 10 );
38
+            }
39
+            $support_post_type = $component->get_support_post_type();
40
+            wp_safe_redirect( menu_page_url( 'rucy', false ) );
41
+        }
42
+?>
43
+<div class="wrap">
44
+    <h2><?php _e( 'Rucy Settings', RC_TXT_DOMAIN ); ?></h2>
45
+    <p><?php _e( 'Configure content types reservation update.', RC_TXT_DOMAIN ); ?></p>
46
+    <div class="rc-donation">
47
+        <p><?php _e( 'Your contribution will continue to better this plugin.', RC_TXT_DOMAIN ); ?> <a href="http://www.amazon.co.jp/registry/wishlist/27FDI6LJU0X1O" class="button"><?php _e( 'Donate', RC_TXT_DOMAIN ); ?></a></p>
48
+    </div>
49
+    <form method="post" action="#">
50
+        <?php wp_nonce_field('update-options'); ?>
51
+        <table class="form-table">
52
+            <tr class="">
53
+                <th><?php _e( 'post type', RC_TXT_DOMAIN ); ?></th>
54
+                <td>
55
+                    <ul>
56
+                        <?php foreach ( $post_types as $key => $post_type ) { 
57
+                            $checked = ( in_array( $key, $support_post_type ) ) ? 'checked' : '';
58
+                            ?>
59
+                        <li><label for="rc_<?php echo $key; ?>"><input type="checkbox" id="rc_<?php echo $key; ?>" name="rc_support_post_types[]" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $post_type->labels->name; ?></label></li>
60
+                        <?php }  ?>
61
+                    </ul>
62
+                </td>
63
+            </tr>
64
+        </table>
65
+        <input type="hidden" name="action" value="update" />
66
+        <input type="hidden" name="page_options" value="<?php echo RC_SETTING_OPTION_KEY ?>"/>
67
+        <p class="submit">
68
+            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" />
69
+        </p>
70
+    </form>
71
+</div>
72
+<?php 
73
+    }
74
+    
75
+    public function set_admin_notices() {
76
+        $message_class = "";
77
+        if ( $messages = get_transient( RC_SETTING_UPDATE ) ) {
78
+            $message_class = 'updated';
79
+        } else if ( $messages = get_transient( RC_SETTING_ERROR ) ) {
80
+            $message_class = 'error';
81
+        }
82
+?>
83
+<div class="<?php echo $message_class; ?>">
84
+    <ul>
85
+    <?php foreach ( $messages as $message ): ?>
86
+        <li><?php echo esc_html( $message );  ?></li>
87
+    <?php endforeach; ?>
88
+    </ul>
89
+</div>
90
+<?php 
91
+    }
92
+}
... ...
@@ -28,7 +28,7 @@ jQuery(document).ready(function(){
28 28
             jQuery('.rc-datetime-wrap').addClass('form-invalid');
29 29
             return false;
30 30
         }
31
-        jQuery('.rc-datetime > b').html(year + "/" + month + "/" + day + " @ " + hour + ":" + min);
31
+        jQuery('.rc-datetime > strong').html(year + "/" + month + "/" + day + " @ " + hour + ":" + min);
32 32
         jQuery('#rc_year_cr').val(year);
33 33
         jQuery('#rc_month_cr').val(month);
34 34
         jQuery('#rc_day_cr').val(day);
... ...
@@ -45,7 +45,7 @@ jQuery(document).ready(function(){
45 45
         var day = jQuery('#rc_day_cr').val();
46 46
         var hour = jQuery('#rc_hour_cr').val();
47 47
         var min = jQuery('#rc_minutes_cr').val();
48
-        jQuery('.rc-datetime > b').html(year + "/" + month + "/" + day + " @ " + hour + ":" + min);
48
+        jQuery('.rc-datetime > strong').html(year + "/" + month + "/" + day + " @ " + hour + ":" + min);
49 49
         jQuery('select[name="rc_year"]').val(year);
50 50
         jQuery('select[name="rc_month"]').val(month);
51 51
         jQuery('select[name="rc_day"]').val(day);
... ...
@@ -109,6 +109,60 @@ jQuery(document).ready(function(){
109 109
         }
110 110
         
111 111
     });
112
-
112
+    // rollback settings
113
+    jQuery('.rc-rollback-datetime-edit').on('click',function(){
114
+        jQuery(this).hide();
115
+        jQuery('.rc-rollback-datetime-wrap').slideDown('normal');
116
+        return false;
117
+    });
118
+    // edit rollback date
119
+    jQuery('.rc-rollback-datetime-update').on('click', function(){
120
+        var rb_year = jQuery('select[name="rc_rb_year"]').val();
121
+        var rb_month = jQuery('select[name="rc_rb_month"]').val();
122
+        var rb_day = jQuery('select[name="rc_rb_day"]').val();
123
+        var rb_hour = jQuery('select[name="rc_rb_hour"]').val();
124
+        var rb_min = jQuery('select[name="rc_rb_minutes"]').val();
125
+        var rbDate = new Date(rb_year, rb_month - 1, rb_day, rb_hour, rb_min);
126
+        var rb_now = new Date();
127
+        var rb_flg = false;
128
+        if(rbDate.getFullYear() != rb_year || (1 + rbDate.getMonth()) != rb_month || rbDate.getDate() != rb_day || rbDate.getMinutes() != rb_min){
129
+            rb_flg = false;
130
+        } else if (rbDate.getTime() < rb_now.getTime()) {
131
+            rb_flg = false;
132
+        } else {
133
+            rb_flg = true;
134
+        }
135
+        if(rb_flg === true){
136
+            jQuery('.rc-rollback-datetime-wrap').removeClass('form-invalid');
137
+        } else {
138
+            jQuery('.rc-rollback-datetime-wrap').addClass('form-invalid');
139
+            return false;
140
+        }
141
+        jQuery('.rc-rollback-datetime > strong').html(rb_year + "/" + rb_month + "/" + rb_day + " @ " + rb_hour + ":" + rb_min);
142
+        jQuery('#rc_rb_year_cr').val(rb_year);
143
+        jQuery('#rc_rb_month_cr').val(rb_month);
144
+        jQuery('#rc_rb_day_cr').val(rb_day);
145
+        jQuery('#rc_rb_hour_cr').val(rb_hour);
146
+        jQuery('#rc_rb_minutes_cr').val(rb_min);
147
+        jQuery('.rc-rollback-datetime-wrap').slideUp('normal');
148
+        jQuery('.rc-rollback-datetime-edit').show();
149
+    });
150
+    // cancel rollback date
151
+    jQuery('.rc-rollback-datetime-cancel').on('click',function(){
152
+        var rb_year = jQuery('#rc_rb_year_cr').val();
153
+        var rb_month = jQuery('#rc_rb_month_cr').val();
154
+        var rb_day = jQuery('#rc_rb_day_cr').val();
155
+        var rb_hour = jQuery('#rc_rb_hour_cr').val();
156
+        var rb_min = jQuery('#rc_rb_minutes_cr').val();
157
+        jQuery('.rc-rollback-datetime > strong').html(rb_year + "/" + rb_month + "/" + rb_day + " @ " + rb_hour + ":" + rb_min);
158
+        jQuery('select[name="rc_rb_year"]').val(rb_year);
159
+        jQuery('select[name="rc_rb_month"]').val(rb_month);
160
+        jQuery('select[name="rc_rb_day"]').val(rb_day);
161
+        jQuery('select[name="rc_rb_hour"]').val(rb_hour);
162
+        jQuery('select[name="rc_rb_minutes"]').val(rb_min);
163
+        jQuery('.rc-rollback-datetime-wrap').slideUp('normal');
164
+        jQuery('.rc-rollback-datetime-edit').show();
165
+        return false;
166
+    });
113 167
 });
114 168
 
115 169
Binary files a/lang/rucy-ja.mo and b/lang/rucy-ja.mo differ
... ...
@@ -1,11 +1,11 @@
1 1
 msgid ""
2 2
 msgstr ""
3 3
 "Project-Id-Version: rucy\n"
4
-"POT-Creation-Date: 2015-04-08 06:31+0900\n"
5
-"PO-Revision-Date: 2015-04-08 06:31+0900\n"
4
+"POT-Creation-Date: 2015-10-19 03:33+0900\n"
5
+"PO-Revision-Date: 2015-10-19 03:37+0900\n"
6 6
 "Last-Translator: nita <nita@gips.jp>\n"
7 7
 "Language-Team: \n"
8
-"Language: ja\n"
8
+"Language: ja_JP\n"
9 9
 "MIME-Version: 1.0\n"
10 10
 "Content-Type: text/plain; charset=UTF-8\n"
11 11
 "Content-Transfer-Encoding: 8bit\n"
... ...
@@ -13,37 +13,37 @@ msgstr ""
13 13
 "X-Poedit-Basepath: .\n"
14 14
 "Plural-Forms: nplurals=1; plural=0;\n"
15 15
 "X-Poedit-KeywordsList: __;_e\n"
16
-"X-Poedit-SearchPath-0: ..\n"
16
+"X-Poedit-SearchPath-0: ../inc\n"
17 17
 
18
-#: ../rucy.php:112
18
+#: ../inc/class-rucy-editor.php:56
19 19
 msgid "Accept reserve update content."
20 20
 msgstr "予約更新を行う"
21 21
 
22
-#: ../rucy.php:115
22
+#: ../inc/class-rucy-editor.php:58
23 23
 msgid "UpdateTime"
24 24
 msgstr "更新日時"
25 25
 
26
-#: ../rucy.php:117
26
+#: ../inc/class-rucy-editor.php:60 ../inc/class-rucy-editor.php:173
27 27
 msgid "Edit"
28 28
 msgstr "編集"
29 29
 
30
-#: ../rucy.php:167
30
+#: ../inc/class-rucy-editor.php:100 ../inc/class-rucy-editor.php:213
31 31
 msgid "OK"
32 32
 msgstr "OK"
33 33
 
34
-#: ../rucy.php:168
34
+#: ../inc/class-rucy-editor.php:101 ../inc/class-rucy-editor.php:214
35 35
 msgid "Cancel"
36 36
 msgstr "キャンセル"
37 37
 
38
-#: ../rucy.php:185
38
+#: ../inc/class-rucy-editor.php:108
39 39
 msgid "Accept reserve update post date."
40 40
 msgstr "更新日時を更新する"
41 41
 
42
-#: ../rucy.php:191
42
+#: ../inc/class-rucy-editor.php:112
43 43
 msgid "Attention - reservation update UpdateTime"
44 44
 msgstr "注意 - 更新日時の更新について"
45 45
 
46
-#: ../rucy.php:192
46
+#: ../inc/class-rucy-editor.php:113
47 47
 msgid ""
48 48
 "If update UpdateTime, this post\\'s permalink is changed by permalink "
49 49
 "settings."
... ...
@@ -51,95 +51,123 @@ msgstr ""
51 51
 "更新日時を更新すると、パーマリンク設定内容によってはパーマリンクが変更される"
52 52
 "場合があります。"
53 53
 
54
-#: ../rucy.php:200
54
+#: ../inc/class-rucy-editor.php:121
55 55
 msgid "Do not show future"
56 56
 msgstr "今後表示しない"
57 57
 
58
-#: ../rucy.php:227
58
+#: ../inc/class-rucy-editor.php:146
59 59
 msgid "Featured Image for Reservation Update"
60 60
 msgstr "予約更新用アイキャッチ画像"
61 61
 
62
-#: ../rucy.php:229
62
+#: ../inc/class-rucy-editor.php:148
63 63
 msgid "Accept reserve update feature image."
64 64
 msgstr "アイキャッチ画像の予約更新を行う"
65 65
 
66
-#: ../rucy.php:231
67
-msgid "Set featured image Reservation"
68
-msgstr "予約更新用アイキャッチ画像を設定"
69
-
70
-#: ../rucy.php:231
66
+#: ../inc/class-rucy-editor.php:151
71 67
 msgid "Set featured image for Reservation"
72 68
 msgstr "予約更新用アイキャッチ画像を登録する"
73 69
 
74
-#: ../rucy.php:232
70
+#: ../inc/class-rucy-editor.php:161
75 71
 msgid "Remove Featured image for Reservation"
76 72
 msgstr "予約更新用アイキャッチ画像を削除する"
77 73
 
78
-#: ../rucy.php:401
79
-msgid "registered reservation update content _RC_DATETIME_"
80
-msgstr "_RC_DATETIME_ に更新するよう予約しました。"
74
+#: ../inc/class-rucy-editor.php:166
75
+msgid "Setting Rollback post content."
76
+msgstr "ロールバック設定"
81 77
 
82
-#: ../rucy.php:421
83
-msgid "Reservation Update DateTime"
84
-msgstr "予約更新日時"
78
+#: ../inc/class-rucy-editor.php:168
79
+msgid "Accept rollback content."
80
+msgstr "記事のロールバックを行う"
85 81
 
86
-#: ../rucy.php:436
87
-msgid "None"
88
-msgstr "なし"
82
+#: ../inc/class-rucy-editor.php:171
83
+msgid "Rollback DateTime"
84
+msgstr "ロールバック日時"
89 85
 
90
-#: ../rucy.php:484
91
-msgid "post or page is not allow."
92
-msgstr "カスタム投稿タイプにpostもしくはpageは入力できません。"
86
+#: ../inc/class-rucy-editor.php:221
87
+msgid "Accept Rollback post date."
88
+msgstr "更新日時のロールバックを行う"
93 89
 
94
-#: ../rucy.php:492
95
-msgid "Do not input \"post\" or \"page\". "
96
-msgstr "postもしくはpageは入力できません。"
90
+#: ../inc/class-rucy-editor.php:227
91
+msgid "Accept Rollback feature image."
92
+msgstr "アイキャッチ画像のロールバックを行う"
97 93
 
98
-#: ../rucy.php:494
99
-msgid "Please input alphabet or numeric. And do not input sequencial commas."
100
-msgstr "英数のみ入力してください。また、連続でカンマの入力はできません。"
94
+#: ../inc/class-rucy-editor.php:311
95
+msgid "registered reservation update content _RC_DATETIME_"
96
+msgstr "_RC_DATETIME_ に更新するよう予約しました。"
101 97
 
102
-#: ../rucy.php:496
103
-#, fuzzy
104
-msgid "Do not input \"attachment\" or \"revision\". "
105
-msgstr "postもしくはpageは入力できません。"
98
+#: ../inc/class-rucy-editor.php:316
99
+msgid "registered rollback content _RC_ROLLBACK_DATETIME_ "
100
+msgstr "_RC_ROLLBACK_DATETIME_ にロールバックします。"
106 101
 
107
-#: ../rucy.php:523
102
+#: ../inc/class-rucy-setting.php:31 ../inc/class-rucy-setting.php:33
103
+msgid "Success to setting update."
104
+msgstr "設定の更新が完了しました。"
105
+
106
+#: ../inc/class-rucy-setting.php:37
107
+msgid "Failed to setting update."
108
+msgstr "設定の更新に失敗。"
109
+
110
+#: ../inc/class-rucy-setting.php:45
108 111
 msgid "Rucy Settings"
109 112
 msgstr "予約更新設定"
110 113
 
111
-#: ../rucy.php:524
114
+#: ../inc/class-rucy-setting.php:46
112 115
 msgid "Configure content types reservation update."
113 116
 msgstr "予約更新する投稿タイプを設定してください。"
114 117
 
115
-#: ../rucy.php:529
118
+#: ../inc/class-rucy-setting.php:48
119
+msgid "Your contribution will continue to better this plugin."
120
+msgstr "あなたの貢献があれば、このプラグインをもっと良くすることができます。"
121
+
122
+#: ../inc/class-rucy-setting.php:48
123
+msgid "Donate"
124
+msgstr "寄付する"
125
+
126
+#: ../inc/class-rucy-setting.php:54
116 127
 msgid "post type"
117 128
 msgstr "投稿タイプ"
118 129
 
119
-#: ../rucy.php:529
120
-msgid "Require"
121
-msgstr "必須"
130
+#: ../inc/class-rucy-setting.php:69
131
+msgid "Save Changes"
132
+msgstr "変更を保存"
133
+
134
+#~ msgid "Set featured image Reservation"
135
+#~ msgstr "予約更新用アイキャッチ画像を設定"
122 136
 
123
-#: ../rucy.php:532
124
-msgid "post"
125
-msgstr "投稿"
137
+#~ msgid "Reservation Update DateTime"
138
+#~ msgstr "予約更新日時"
126 139
 
127
-#: ../rucy.php:533
128
-msgid "page"
129
-msgstr "固定ページ"
140
+#~ msgid "None"
141
+#~ msgstr "なし"
130 142
 
131
-#: ../rucy.php:544
132
-msgid "custom post type"
133
-msgstr "カスタム投稿タイプ"
143
+#~ msgid "post or page is not allow."
144
+#~ msgstr "カスタム投稿タイプにpostもしくはpageは入力できません。"
134 145
 
135
-#: ../rucy.php:546
136
-msgid "Separated by commas"
137
-msgstr "カンマ区切りで入力"
146
+#~ msgid "Do not input \"post\" or \"page\". "
147
+#~ msgstr "postもしくはpageは入力できません。"
138 148
 
139
-#: ../rucy.php:559
140
-msgid "Save Changes"
141
-msgstr "変更を保存"
149
+#~ msgid ""
150
+#~ "Please input alphabet or numeric. And do not input sequencial commas."
151
+#~ msgstr "英数のみ入力してください。また、連続でカンマの入力はできません。"
152
+
153
+#, fuzzy
154
+#~ msgid "Do not input \"attachment\" or \"revision\". "
155
+#~ msgstr "postもしくはpageは入力できません。"
156
+
157
+#~ msgid "Require"
158
+#~ msgstr "必須"
159
+
160
+#~ msgid "post"
161
+#~ msgstr "投稿"
162
+
163
+#~ msgid "page"
164
+#~ msgstr "固定ページ"
165
+
166
+#~ msgid "custom post type"
167
+#~ msgstr "カスタム投稿タイプ"
168
+
169
+#~ msgid "Separated by commas"
170
+#~ msgstr "カンマ区切りで入力"
142 171
 
143
-#: ../rucy.php:618
144
-msgid "Settings"
145
-msgstr "設定"
172
+#~ msgid "Settings"
173
+#~ msgstr "設定"
... ...
@@ -37,6 +37,13 @@ You can install this plugin directly from your WordPress dashboard:
37 37
 
38 38
 == Changelog ==
39 39
 
40
+= 0.4.0 =
41
+* 2015-10-21
42
+* add post rollback function.
43
+* refactoring
44
+* add plugin icon.
45
+* change banner image.
46
+
40 47
 = 0.3.0 =
41 48
 * 2015-04-09
42 49
 * add "feature image" and "post date" to reservation update.
... ...
@@ -2,634 +2,159 @@
2 2
 /*
3 3
  * Plugin Name: Rucy
4 4
  * Plugin URI: https://github.com/gips/rucy
5
- * Description: Reservation Update (Published) Content.
6
- * Version: 0.3.0
5
+ * Description: Reservation Update "Published" Content(Post & Page).
6
+ * Version: 0.4.0
7 7
  * Author: Nita
8 8
  * License: GPLv2 or later
9 9
  * Text Domain: rucy
10 10
  * Domain Path: /lang
11 11
  */
12
-define('RC_PLUGIN_URL',  plugin_dir_url(__FILE__));
13
-define('RC_SETTING_OPTION_KEY', 'rucy_post_type');
14
-define('RC_TXT_DOMAIN', 'rucy');
15
-define('RC_POSTTYPE_DEFAULT','post,page');
16
-define('RC_CRON_HOOK', 'rucy_update_reserved_content');
17
-load_plugin_textdomain( RC_TXT_DOMAIN, false, 'rucy/lang');
18
-
19
-add_action('admin_enqueue_scripts','load_rc_jscss');
20
-function load_rc_jscss()
21
-{
22
-    global $hook_suffix;
23
-    if(in_array($hook_suffix, array('post.php','post-new.php',)))
24
-    {
25
-        wp_register_style('rucy.css', RC_PLUGIN_URL . '/css/rucy.css',array(),'0.1.0');
26
-        wp_enqueue_style('rucy.css');
27
-        wp_register_script('rucy.js', RC_PLUGIN_URL . '/js/rucy.js', array('jquery'), '0.1.0');
28
-        wp_enqueue_script('rucy.js');
29
-    }
30
-}
31
-
32
-// load js and css for pointer
33
-add_action('admin_menu', 'load_rc_pointer_menu');
34
-function load_rc_pointer_menu() {
35
-    wp_enqueue_script('wp-pointer');
36
-    wp_enqueue_style('wp-pointer');
37
-}
38
-/**
39
- * get rucy post_metas or post_meta keys.
40
- * @param int $post_id
41
- * @return array 
42
- */
43
-function get_rc_metas($post_id = "")
44
-{
45
-    $base = array(
46
-        'accept' => 'rc_reserv_accept',
47
-        'content' => 'rc_reserv_content',
48
-        'date' => 'rc_reserv_date',
49
-        'feature_img' => 'rc_reserv_feature_image',
50
-        'accept_feature_img' => 'rc_reserv_accept_feature_image',
51
-        'accept_update' => 'rc_reserv_accept_post_update',
52
-            );
53
-    if($post_id > 0)
54
-    {
55
-        foreach ($base as $key => $value)
56
-        {
57
-            $res[$key] = get_post_meta($post_id, $value, true);
58
-        }
59
-    } else {
60
-        $res = $base;
61
-    }
62
-    return $res;
63
-}
64
-
65
-// add reserv_metabox
66
-add_action('admin_menu', 'add_rc_metabox_out');
67
-function add_rc_metabox_out()
68
-{
69
-    $accept_post_type = get_rc_setting();
70
-    foreach ($accept_post_type as $post_type)
71
-    {
72
-        add_meta_box('rucy_metabox','Rucy - Reservation Update Content -','add_rucy_metabox_inside',$post_type,'normal','high');
73
-    }
74
-}
75
-function add_rucy_metabox_inside()
76
-{
77
-    global $post;
78
-    $rc_keys = get_rc_metas();
79
-    $rc_content_name = $rc_keys['content'];
80
-    $rc_accept_name = $rc_keys['accept'];
81
-    $rc_metas = get_rc_metas($post->ID);
82
-    $reserv_accept = $rc_metas['accept'];
83
-    $reserv_date = $rc_metas['date'];
84
-    if("" == $reserv_date)
85
-    {
86
-        $reserv_date = date_i18n('Y-m-d H:i:s');
87
-    }
88
-    $reserv_date_arr = getdate(strtotime($reserv_date));
89
-    $current_y = date_i18n('Y');
90
-    $reserv_content = $rc_metas['content'];
91
-    if("" == $reserv_content)
92
-    {
93
-        $reserv_content = $post->post_content;
94
-    }
95
-?>
96
-<div id="rc-post-wrap" class="curtime">
97
-    <input type="hidden" name="schroeder" id="schroeder" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>"/>
98
-    <label class="rc_accept">
99
-        <input type="checkbox" name="<?php echo $rc_accept_name; ?>" value="1" <?php echo ($reserv_accept == "1") ? "checked" : ""; ?>> <?php _e('Accept reserve update content.',RC_TXT_DOMAIN) ?>
100
-    </label>
101
-    <div class="rc-datetime" id="timestamp">
102
-        <?php _e('UpdateTime',RC_TXT_DOMAIN) ?>:<b><?php echo date_i18n("Y/m/d @ H:i", strtotime($reserv_date)); ?></b>
103
-    </div>
104
-    <a href="#edit-reservdate" class="edit-timestamp rc-datetime-edit"><?php _e('Edit') ?></a>
105
-    <div class="rc-datetime-wrap">
106
-        <select name="rc_year">
107
-        <?php 
108
-        for($y = $current_y; $y <= ($current_y + 3); $y++){
109
-            $y_selected = ($y == date_i18n('Y',$reserv_date_arr[0])) ? "selected" : "";
110
-            echo '<option value="'.$y.'" '.$y_selected.'>'.$y.'</option>';
111
-        }
112
-        ?>
113
-        </select>
114
-        <?php echo '/' ?>
115
-        <select name="rc_month">
116
-        <?php
117
-        for($i = 1; $i <= 12; $i++)
118
-        {
119
-            $m = sprintf("%02d",$i);
120
-            $selected = ($m == date_i18n('m',$reserv_date_arr[0])) ? "selected" : "";
121
-            echo '<option value="'.$m.'" '.$selected.'>'.$m.'</option>';
122
-        }
123
-        ?>
124
-        </select><?php echo '/' ?>
125
-        <select name="rc_day">
126
-        <?php 
127
-        for($d = 1; $d<=31; $d++){
128
-            $d = sprintf("%02d",$d);
129
-            $d_selected = ($d == date_i18n('d',$reserv_date_arr[0])) ? "selected" : "";
130
-            echo '<option value="'.$d.'" '.$d_selected.'>'.$d.'</option>';
131
-        }
132
-        ?>
133
-        </select>    
134
-        @
135
-        <select name="rc_hour">
136
-        <?php 
137
-        for($h = 0; $h <= 23; $h++){
138
-            $h = sprintf("%02d",$h);
139
-            $h_selected = ($h == date_i18n('H',$reserv_date_arr[0])) ? "selected" : "";
140
-            echo '<option value="'.$h.'" '.$h_selected.'>'.$h.'</option>';
141
-        }
142
-        ?>
143
-        </select>
144
-        :
145
-        <select name="rc_minutes">
146
-        <?php 
147
-        for($min = 0; $min <= 59; $min++){
148
-            $min = sprintf("%02d",$min);
149
-            $min_selected = ($min == date_i18n('i',$reserv_date_arr[0])) ? "selected" : "";
150
-            echo '<option value="'.$min.'" '.$min_selected.'>'.$min.'</option>';
151
-        }
152
-        ?>
153
-        </select>
154
-        <a href="#edit-reservdate" class="rc-datetime-update button"><?php _e('OK',RC_TXT_DOMAIN) ?></a>
155
-        <a href="#edit-reservdate" class="rc-datetime-cancel"><?php _e('Cancel',RC_TXT_DOMAIN) ?></a>
156
-    </div>
157
-    <?php
158
-        $date_arr = array(
159
-            'rc_year' => date_i18n('Y',$reserv_date_arr[0]),
160
-            'rc_month' => date_i18n('m',$reserv_date_arr[0]),
161
-            'rc_day' => date_i18n('d',$reserv_date_arr[0]),
162
-            'rc_hour' => date_i18n('H',$reserv_date_arr[0]),
163
-            'rc_minutes' => date_i18n('i',$reserv_date_arr[0])
164
-        );
165
-        foreach ($date_arr as $k => $v)
166
-        {
167
-            echo '<input type="hidden" name="'.$k.'_cr" id="'.$k.'_cr" value="'.$v.'">';
168
-        }
169
-    ?>
170
-    <div id="rc-accept-update-update">
171
-        <label for="rc-accept-update-postdate">
172
-            <input id="rc-accept-update-postdate" type="checkbox" name="<?php echo $rc_keys['accept_update']; ?>" value="1" <?php echo ($rc_metas['accept_update'] == '1') ? "checked" : ""; ?> /> <?php _e('Accept reserve update post date.', RC_TXT_DOMAIN); ?>
173
-        </label>
174
-    </div>
175
-    <?php 
176
-    $dismissed = explode(',', get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true));
177
-    if(array_search('rc_update_postdate', $dismissed) === false):
178
-        $pointer_content = '<h3>' . __('Attention - reservation update UpdateTime', RC_TXT_DOMAIN) . '</h3>';
179
-        $pointer_content .= '<p>'.__("If update UpdateTime, this post\'s permalink is changed by permalink settings.", RC_TXT_DOMAIN).'</p>';
180
-    ?>
181
-    <script type="text/javascript">
182
-        jQuery(document).ready(function(){
183
-            // show notice pointer update postdate.
184
-            jQuery('#rc-accept-update-update').pointer({
185
-                content : '<?php echo $pointer_content ?>',
186
-                buttons : function(e, t){
187
-                    return jQuery('<a class="close" href="#"><?php _e('Do not show future', RC_TXT_DOMAIN) ?></a>').bind('click.pointer',function(e){
188
-                        e.preventDefault();
189
-                        t.element.pointer('close');
190
-                    });
191
-                },
192
-                position : { edge : "top", align : "left"},
193
-                close : function(){
194
-                    jQuery.post("<?php echo admin_url('admin-ajax.php'); ?>", {
195
-                        action : 'dismiss-wp-pointer',
196
-                        pointer : 'rc_update_postdate'
197
-                    });
198
-                }
199
-            }).pointer('open');
200
-        });
201
-    </script>
202
-    <?php 
203
-    endif;
204
-    ?>
205
-</div>
206
-<?php 
207
-    wp_editor($reserv_content, $rc_content_name);
208
-/*
209
- * support feature image reservation.
210
- */
211
-    if( current_theme_supports('post-thumbnails') ) {
212
-?>
213
-<fieldset>
214
-<h3><?php echo __('Featured Image for Reservation Update', RC_TXT_DOMAIN); ?></h3>
215
-<label class="rc_feature_accept">
216
-    <input type="checkbox" name="<?php echo $reserv_accept_feature_name; ?>" value="1" <?php echo ($reserv_accept_feature == "1") ? "checked" : ""; ?>> <?php _e('Accept reserve update feature image.', RC_TXT_DOMAIN); ?>
217
-</label>
218
-<div class="rc_feature_image_uploader">
219
-<p><button id="rc_feature_image_upload" class="button rc-feature-uploader-button <?php echo ($reserv_feature_image != '') ? ' has_image' : ''; ?>"><?php  _e('Set featured image for Reservation', RC_TXT_DOMAIN); ?></button></p>
220
-
221
-<div class="rc-feature-image-uploader__ctrl">
222
-    <div class="rc-feature-image-preview">
223
-        <?php
224
-        if ( ! empty( $reserv_feature_image ) ) {
225
-           echo $reserv_feature_image;
226
-        }
227
-        ?> 
228
-    </div>
229
-</div>
230
-
231
-<p><button class="button rc_remove_feature_image"><?php _e('Remove Featured image for Reservation', RC_TXT_DOMAIN) ?></button></p>
232
-<input type="hidden" id="rc_feature_image" name="<?php echo $reserv_feature_name ?>" value="<?php echo $reserv_feature ?>" />
233
-</div>
234
-</fieldset>
235
-<?php 
236
-    }
237
-}
238
-
239
-// save post meta
240
-add_action('save_post','save_rc_post_meta');
241
-function save_rc_post_meta($post_id)
242
-{
243
-    if(isset($_POST) && isset($_POST['post_type']))
244
-    {
245
-        if(isset($_POST['schroeder']) && !wp_verify_nonce($_POST['schroeder'], plugin_basename(__FILE__))){
246
-            return;
247
-        }
248
-        if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
249
-            return;
250
-        }
251
-        $rc_keys = get_rc_metas();
252
-        $accept_post_type = get_rc_setting();
253
-        if(in_array($_POST['post_type'], $accept_post_type))
254
-        {
255
-            $date = mktime($_POST['rc_hour'], $_POST['rc_minutes'], 00, $_POST['rc_month'], $_POST['rc_day'], $_POST['rc_year']);
256
-            if($date)
257
-            {
258
-                $_POST[$rc_keys['date']] = date_i18n('Y-m-d H:i:s',$date);
259
-            } else {
260
-                $_POST[$rc_keys['date']] = "";
12
+define( 'RC_PLUGIN_URL',  plugin_dir_url(__FILE__) );
13
+define( 'RC_PLUGIN_DIR',  untrailingslashit( dirname( __FILE__ ) ) );
14
+define( 'RC_SETTING_OPTION_KEY', 'rucy_post_type' );
15
+define( 'RC_TXT_DOMAIN', 'rucy' );
16
+define( 'RC_CRON_HOOK', 'rucy_update_reserved_content' );
17
+define( 'RC_SETTING_UPDATE', 'rucy_setting_update' );
18
+define( 'RC_SETTING_ERROR', 'rucy_setting_error' );
19
+define( 'RC_VERSION', '0.4.0' );
20
+load_plugin_textdomain( RC_TXT_DOMAIN, false, 'rucy/lang' );
21
+
22
+require_once RC_PLUGIN_DIR . '/inc/class-rucy-component.php';
23
+require_once RC_PLUGIN_DIR . '/inc/class-rucy-setting.php';
24
+require_once RC_PLUGIN_DIR . '/inc/class-rucy-editor.php';
25
+require_once RC_PLUGIN_DIR . '/inc/class-rucy-cron.php';
26
+
27
+class Rucy_Class {
28
+    public $support_post_type = array();
29
+    
30
+    public function __construct() {
31
+        register_activation_hook( plugin_basename(__FILE__), array( $this, 'activate_plugin' ) );
32
+        add_action( 'admin_init', array( $this, 'rucy_upgrade' ) );
33
+        add_action('admin_enqueue_scripts', array( $this, 'enqueue_style_script' ));
34
+        add_action( 'admin_menu', array( $this, 'enqueue_pointer_menu' ) );
35
+        add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_setting_link' ) );
36
+        $setting = new Class_Rucy_Setting();
37
+        add_action( 'admin_menu', array( $setting, 'set_admin_menu' ) );
38
+        add_action( 'admin_notices', array( $setting, 'set_admin_notices' ) );
39
+        $editor = new Class_Rucy_Editer();
40
+        add_action( 'admin_menu', array( $editor, 'add_rucy_metabox' ) );
41
+        add_action( 'save_post', array( $editor, 'save_rc_post_meta' ) );
42
+        add_filter( 'post_updated_messages', array( $editor, 'add_reservation_message' ) );
43
+        $component = new Class_Rucy_Component();
44
+        $accept_post_types = $component->get_support_post_type();
45
+        foreach ( $accept_post_types as $p ) {
46
+            if ( in_array( $p, array( 'page', 'post' ) ) ) {
47
+                $p .= 's';
261 48
             }
262
-            if(!isset($_POST[$rc_keys['accept']]) || $_POST[$rc_keys['accept']] != "1"){
263
-                $_POST[$rc_keys['accept']]  = "0";
49
+            add_filter('manage_'.$p.'_columns', array( $this, 'manage_rucy_cols' ) );
50
+            add_action('manage_'.$p.'_custom_column', array( $this, 'add_rucy_col' ), 10, 2); 
51
+        }
52
+        // update content to reserved content
53
+        $cron = new Class_Rucy_Cron();
54
+        add_action( RC_CRON_HOOK, array( $cron, 'update_rc_reserved_content' ) );
55
+        // deactivation this plugin
56
+        register_deactivation_hook( __FILE__ , array( $this, 'uninstall_rucy' ) );
57
+        // uninstall this plugin
58
+        register_uninstall_hook( __FILE__, array( $this, 'uninstall_rucy' ) );
59
+    }
60
+    
61
+    public function activate_plugin() {
62
+        $this->init_support_post_type();
63
+    }
64
+    
65
+    public function init_support_post_type() {
66
+        $component = new Class_Rucy_Component();
67
+        $this->support_post_type = $component->get_support_post_type();
68
+        $component->update_support_post_type( $this->support_post_type );
69
+    }
70
+    
71
+    /**
72
+     * load css and js for this plugin.
73
+     * 
74
+     * @global type $hook_suffix
75
+     */
76
+    public function enqueue_style_script() {
77
+        global $hook_suffix;
78
+        if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php', 'settings_page_rucy' ) ) ) {
79
+            wp_register_style('rucy.css', RC_PLUGIN_URL . 'css/rucy.css',array(),'0.1.0');
80
+            wp_register_script('rucy.js', RC_PLUGIN_URL . 'js/rucy.js', array('jquery'), '0.1.1');
81
+            wp_enqueue_style('rucy.css');
82
+            wp_enqueue_script('rucy.js');
83
+        }
84
+    }
85
+    
86
+    /**
87
+     * load enqueue script and style for pointer
88
+     */
89
+    public function enqueue_pointer_menu() {
90
+        wp_enqueue_script( 'wp-pointer' );
91
+        wp_enqueue_style( 'wp-pointer' );
92
+    }
93
+    
94
+    public function add_setting_link( $links ) {
95
+        $links[] = '<a href="' . get_admin_url( null, 'options-general.php?page=rucy' ) . '">' . __('Settings') . '</a>';
96
+        return $links;
97
+    }
98
+    
99
+    public function manage_rucy_cols( $columns ) {
100
+        $columns['rucy_reservation_date'] = __( "Reservation Update DateTime", RC_TXT_DOMAIN );
101
+        $columns['rucy_rollback_date'] = __( "Rollback DateTime", RC_TXT_DOMAIN );
102
+        return $columns;
103
+    }
104
+    
105
+    public function add_rucy_col( $column_name, $post_id ) {
106
+        $component = new Class_Rucy_Component();
107
+        $post_metas = $component->get_post_rc_meta( $post_id );
108
+        if ( $column_name == 'rucy_reservation_date' ) {
109
+            if ( $post_metas->accept == "1" ) {
110
+                echo $post_metas->date;
111
+            } else {
112
+                _e( 'None' );