Browse code

アイキャッチ画像サポート 予約更新用のエディターの「アイキャッチ画像」から設定すると、公開中の設定を書き換えてしまう。 アイキャッチ削除ボタンが重複表示されるなど不具合あり。 一旦ブランチ分けし今後開発する。

nita authored on 2015/04/05 16:09:29
Showing 5 changed files
... ...
@@ -19,3 +19,13 @@
19 19
 .rc-datetime{
20 20
     display: inline-block;
21 21
 }
22
+
23
+.rc_feature_image {
24
+    max-width: 100%;
25
+    max-height: 80%;
26
+    width: 50%;
27
+    height: 50%;
28
+}
29
+.rc_remove_feature_image {
30
+    display: none;
31
+}
22 32
\ No newline at end of file
... ...
@@ -55,5 +55,30 @@ jQuery(document).ready(function(){
55 55
         jQuery('.rc-datetime-edit').show();
56 56
         return false;
57 57
     });
58
+    // reservation feature image uploader
59
+    window.original_send_to_editor = window.send_to_editor;
60
+    window.send_to_editor = function(html){
61
+        fileurl = jQuery('img', html).attr('src');
62
+        jQuery('#rc_feature_image').val(fileurl);
63
+        tb_remove();
64
+        if(jQuery('#rc_feature_image_upload').hasClass('has_image')){
65
+            jQuery('.rc_feature_image').attr('src', fileurl);
66
+            jQuery('.rc_remove_feature_image').show();
67
+        } else {
68
+            var img = jQuery('<img>').attr('src',fileurl).addClass('rc_feature_image size-thumbnail');
69
+            jQuery('#rc_feature_image_upload').addClass('has_image').html(img);
70
+            jQuery('.rc_remove_feature_image').show();
71
+        }
72
+    };
73
+    if(jQuery('#rc_feature_image_upload').hasClass('has_image')){
74
+        jQuery('.rc_remove_feature_image').show();
75
+    }
76
+    jQuery('.rc_remove_feature_image').on('click', function(){
77
+        jQuery('#rc_feature_image').val('');
78
+        var replace_text = jQuery('#rc_feature_image_upload').attr('title');
79
+        jQuery('#rc_feature_image_upload').html(replace_text);
80
+        jQuery(this).hide();
81
+        return false;
82
+    });
58 83
 });
59 84
 
60 85
Binary files a/lang/rucy-ja.mo and b/lang/rucy-ja.mo differ
... ...
@@ -1,8 +1,8 @@
1 1
 msgid ""
2 2
 msgstr ""
3 3
 "Project-Id-Version: rucy\n"
4
-"POT-Creation-Date: 2014-05-04 02:48+0900\n"
5
-"PO-Revision-Date: 2014-05-04 02:48+0900\n"
4
+"POT-Creation-Date: 2015-04-05 15:42+0900\n"
5
+"PO-Revision-Date: 2015-04-05 15:45+0900\n"
6 6
 "Last-Translator: nita <nita@gips.jp>\n"
7 7
 "Language-Team: \n"
8 8
 "Language: ja\n"
... ...
@@ -15,110 +15,111 @@ msgstr ""
15 15
 "X-Poedit-KeywordsList: __;_e\n"
16 16
 "X-Poedit-SearchPath-0: ..\n"
17 17
 
18
-#: ../rucy.php:88
18
+#: ../rucy.php:105
19 19
 msgid "Accept reserve update content."
20 20
 msgstr "予約更新を行う"
21 21
 
22
-#: ../rucy.php:91
22
+#: ../rucy.php:108
23 23
 msgid "UpdateTime"
24 24
 msgstr "更新日時"
25 25
 
26
-#: ../rucy.php:93
26
+#: ../rucy.php:110
27 27
 msgid "Edit"
28 28
 msgstr "編集"
29 29
 
30
-#: ../rucy.php:108
30
+#: ../rucy.php:160
31 31
 msgid "OK"
32 32
 msgstr "OK"
33 33
 
34
-#: ../rucy.php:109
34
+#: ../rucy.php:161
35 35
 msgid "Cancel"
36 36
 msgstr "キャンセル"
37 37
 
38
-#: ../rucy.php:235
38
+#: ../rucy.php:185
39
+msgid "Featured Image for Reservation Update"
40
+msgstr "予約更新用アイキャッチ画像"
41
+
42
+#: ../rucy.php:187
43
+msgid "Accept reserve update feature image."
44
+msgstr "アイキャッチ画像の予約更新を行う"
45
+
46
+#: ../rucy.php:189
47
+msgid "Set featured image Reservation"
48
+msgstr "予約更新用アイキャッチ画像を設定"
49
+
50
+#: ../rucy.php:189
51
+msgid "Set featured image for Reservation"
52
+msgstr "予約更新用アイキャッチ画像を登録する"
53
+
54
+#: ../rucy.php:190
55
+msgid "Remove Featured image for Reservation"
56
+msgstr "予約更新用アイキャッチ画像を削除する"
57
+
58
+#: ../rucy.php:335
39 59
 msgid "registered reservation update content _RC_DATETIME_"
40 60
 msgstr "_RC_DATETIME_ に更新するよう予約しました。"
41 61
 
42
-#: ../rucy.php:255
62
+#: ../rucy.php:355
43 63
 msgid "Reservation Update DateTime"
44 64
 msgstr "予約更新日時"
45 65
 
46
-#: ../rucy.php:269
66
+#: ../rucy.php:370
47 67
 msgid "None"
48 68
 msgstr "なし"
49 69
 
50
-#: ../rucy.php:312
70
+#: ../rucy.php:418
51 71
 msgid "post or page is not allow."
52 72
 msgstr "カスタム投稿タイプにpostもしくはpageは入力できません。"
53 73
 
54
-#: ../rucy.php:320
74
+#: ../rucy.php:426
55 75
 msgid "Do not input \"post\" or \"page\". "
56 76
 msgstr "postもしくはpageは入力できません。"
57 77
 
58
-#: ../rucy.php:322
78
+#: ../rucy.php:428
59 79
 msgid "Please input alphabet or numeric. And do not input sequencial commas."
60 80
 msgstr "英数のみ入力してください。また、連続でカンマの入力はできません。"
61 81
 
62
-#: ../rucy.php:324
82
+#: ../rucy.php:430
63 83
 #, fuzzy
64 84
 msgid "Do not input \"attachment\" or \"revision\". "
65 85
 msgstr "postもしくはpageは入力できません。"
66 86
 
67
-#: ../rucy.php:352
87
+#: ../rucy.php:457
88
+msgid "Rucy Settings"
89
+msgstr "予約更新設定"
90
+
91
+#: ../rucy.php:458
68 92
 msgid "Configure content types reservation update."
69 93
 msgstr "予約更新する投稿タイプを設定してください。"
70 94
 
71
-#: ../rucy.php:357
95
+#: ../rucy.php:463
72 96
 msgid "post type"
73 97
 msgstr "投稿タイプ"
74 98
 
75
-#: ../rucy.php:357
99
+#: ../rucy.php:463
76 100
 msgid "Require"
77 101
 msgstr "必須"
78 102
 
79
-#: ../rucy.php:360
103
+#: ../rucy.php:466
80 104
 msgid "post"
81 105
 msgstr "投稿"
82 106
 
83
-#: ../rucy.php:361
107
+#: ../rucy.php:467
84 108
 msgid "page"
85 109
 msgstr "固定ページ"
86 110
 
87
-#: ../rucy.php:372
111
+#: ../rucy.php:478
88 112
 msgid "custom post type"
89 113
 msgstr "カスタム投稿タイプ"
90 114
 
91
-#: ../rucy.php:374
115
+#: ../rucy.php:480
92 116
 msgid "Separated by commas"
93 117
 msgstr "カンマ区切りで入力"
94 118
 
95
-#: ../rucy.php:387
119
+#: ../rucy.php:493
96 120
 msgid "Save Changes"
97 121
 msgstr "変更を保存"
98 122
 
99
-#: ../rucy.php:390
100
-msgid "Contact"
101
-msgstr ""
102
-
103
-#: ../rucy.php:392
104
-msgid ""
105
-"Rucy is maintained by <a href=\"http://profiles.wordpress.org/gips-nita/"
106
-"\">nita</a>.<br>"
107
-msgstr ""
108
-
109
-#: ../rucy.php:393
110
-msgid ""
111
-"If you have found a bug or would like to make a suggestion or contribution "
112
-"why not join the <a href=\"https://wordpress.org/support/plugin/rucy"
113
-"\">Support Form @ wordpress.org</a><br />"
114
-msgstr ""
115
-
116
-#: ../rucy.php:394
117
-msgid ""
118
-"Please consider donating if you like this plugin. I've put a lot of my free "
119
-"time into this plugin and donations help to justify it.<br />"
120
-msgstr ""
121
-
122
-#: ../rucy.php:451
123
+#: ../rucy.php:552
123 124
 msgid "Settings"
124
-msgstr ""
125
+msgstr "設定"
... ...
@@ -16,8 +16,8 @@ define('RC_POSTTYPE_DEFAULT','post,page');
16 16
 define('RC_CRON_HOOK', 'rucy_update_reserved_content');
17 17
 load_plugin_textdomain( RC_TXT_DOMAIN, false, 'rucy/lang');
18 18
 
19
-add_action('admin_enqueue_scripts','rc_load_jscss');
20
-function rc_load_jscss()
19
+add_action('admin_enqueue_scripts','load_rc_jscss');
20
+function load_rc_jscss()
21 21
 {
22 22
     global $hook_suffix;
23 23
     if(in_array($hook_suffix, array('post.php','post-new.php',)))
... ...
@@ -34,12 +34,14 @@ function rc_load_jscss()
34 34
  * @param int $post_id
35 35
  * @return array 
36 36
  */
37
-function getRcMetas($post_id = "")
37
+function get_rc_metas($post_id = "")
38 38
 {
39 39
     $base = array(
40 40
         'accept' => 'rc_reserv_accept',
41 41
         'content' => 'rc_reserv_content',
42
-        'date' => 'rc_reserv_date'
42
+        'date' => 'rc_reserv_date',
43
+        'feature_img' => 'rc_reserv_feature_image',
44
+        'accept_feature_img' => 'rc_reserv_accept_feature_image',
43 45
             );
44 46
     if($post_id > 0)
45 47
     {
... ...
@@ -54,119 +56,147 @@ function getRcMetas($post_id = "")
54 54
 }
55 55
 
56 56
 // add reserv_metabox
57
-add_action('admin_menu', 'add_rucy_metabox_out');
58
-function add_rucy_metabox_out()
57
+add_action('admin_menu', 'add_rc_metabox_out');
58
+function add_rc_metabox_out()
59 59
 {
60
-    $acceptPostType = getRcSetting();
61
-    foreach ($acceptPostType as $postType)
60
+    $accept_post_type = get_rc_setting();
61
+    foreach ($accept_post_type as $post_type)
62 62
     {
63
-        add_meta_box('rucy_metabox','Rucy - Reservation Update Content -','add_rucy_metabox_inside',$postType,'normal','high');
63
+        add_meta_box('rucy_metabox','Rucy - Reservation Update Content -','add_rucy_metabox_inside',$post_type,'normal','high');
64 64
     }
65
-    function add_rucy_metabox_inside()
65
+}
66
+function add_rucy_metabox_inside()
67
+{
68
+    global $post;
69
+    $rc_keys = get_rc_metas();
70
+    $rc_content_name = $rc_keys['content'];
71
+    $rc_accept_name = $rc_keys['accept'];
72
+    $rc_metas = get_rc_metas($post->ID);
73
+    $reserv_accept = $rc_metas['accept'];
74
+    $reserv_date = $rc_metas['date'];
75
+    $reserv_feature_name = $rc_keys['feature_img'];
76
+    $reserv_feature = $rc_metas['feature_img'];
77
+    $reserv_accept_feature_name = $rc_keys['accept_feature_img'];
78
+    $reserv_accept_feature = $rc_metas['accept_feature_img'];
79
+    $thumb_id = get_post_thumbnail_id($post->ID);
80
+    $reserv_feature_width = "255";
81
+    $reserv_feature_height = "255";
82
+    if($thumb_id){
83
+        $image = wp_get_attachment_image_src($thumb_id, 'thumbnail');
84
+        $reserv_feature_width = $image[1];
85
+        $reserv_feature_height = $image[2];
86
+    }
87
+    $reserv_feature_image = ($reserv_feature != '') ? '<img width="'.$reserv_feature_width.'" height="'.$reserv_feature_height.'" class="rc_feature_image" src="'.$reserv_feature.'" />' : '';
88
+    if("" == $reserv_date)
66 89
     {
67
-        global $post;
68
-        $rcKeys = getRcMetas();
69
-        $rc_content_name = $rcKeys['content'];
70
-        $rc_accept_name = $rcKeys['accept'];
71
-        $rcMetas = getRcMetas($post->ID);
72
-        $reserv_accept = $rcMetas['accept'];
73
-        $reserv_date = $rcMetas['date'];
74
-        if("" == $reserv_date)
75
-        {
76
-            $reserv_date = date_i18n('Y-m-d H:i:s');
90
+        $reserv_date = date_i18n('Y-m-d H:i:s');
91
+    }
92
+    $reserv_date_arr = getdate(strtotime($reserv_date));
93
+    $current_y = date_i18n('Y');
94
+    $reserv_content = $rc_metas['content'];
95
+    if("" == $reserv_content)
96
+    {
97
+        $reserv_content = $post->post_content;
98
+    }
99
+?>
100
+<div id="rc-post-wrap" class="curtime">
101
+    <input type="hidden" name="schroeder" id="schroeder" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>"/>
102
+    <label class="rc_accept">
103
+        <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) ?>
104
+    </label>
105
+    <div class="rc-datetime" id="timestamp">
106
+        <?php _e('UpdateTime',RC_TXT_DOMAIN) ?>:<b><?php echo date_i18n("Y/m/d @ H:i", strtotime($reserv_date)); ?></b>
107
+    </div>
108
+    <a href="#edit-reservdate" class="edit-timestamp rc-datetime-edit"><?php _e('Edit') ?></a>
109
+    <div class="rc-datetime-wrap">
110
+        <select name="rc_year">
111
+        <?php 
112
+        for($y = $current_y; $y <= ($current_y + 3); $y++){
113
+            $y_selected = ($y == date_i18n('Y',$reserv_date_arr[0])) ? "selected" : "";
114
+            echo '<option value="'.$y.'" '.$y_selected.'>'.$y.'</option>';
77 115
         }
78
-        $reserv_date_arr = getdate(strtotime($reserv_date));
79
-        $current_y = date_i18n('Y');
80
-        $reserv_content = $rcMetas['content'];
81
-        if("" == $reserv_content)
116
+        ?>
117
+        </select>
118
+        <?php echo '/' ?>
119
+        <select name="rc_month">
120
+        <?php
121
+        for($i = 1; $i <= 12; $i++)
82 122
         {
83
-            $reserv_content = $post->post_content;
123
+            $m = sprintf("%02d",$i);
124
+            $selected = ($m == date_i18n('m',$reserv_date_arr[0])) ? "selected" : "";
125
+            echo '<option value="'.$m.'" '.$selected.'>'.$m.'</option>';
126
+        }
127
+        ?>
128
+        </select><?php echo '/' ?>
129
+        <select name="rc_day">
130
+        <?php 
131
+        for($d = 1; $d<=31; $d++){
132
+            $d = sprintf("%02d",$d);
133
+            $d_selected = ($d == date_i18n('d',$reserv_date_arr[0])) ? "selected" : "";
134
+            echo '<option value="'.$d.'" '.$d_selected.'>'.$d.'</option>';
135
+        }
136
+        ?>
137
+        </select>    
138
+        @
139
+        <select name="rc_hour">
140
+        <?php 
141
+        for($h = 0; $h <= 23; $h++){
142
+            $h = sprintf("%02d",$h);
143
+            $h_selected = ($h == date_i18n('H',$reserv_date_arr[0])) ? "selected" : "";
144
+            echo '<option value="'.$h.'" '.$h_selected.'>'.$h.'</option>';
145
+        }
146
+        ?>
147
+        </select>
148
+        :
149
+        <select name="rc_minutes">
150
+        <?php 
151
+        for($min = 0; $min <= 59; $min++){
152
+            $min = sprintf("%02d",$min);
153
+            $min_selected = ($min == date_i18n('i',$reserv_date_arr[0])) ? "selected" : "";
154
+            echo '<option value="'.$min.'" '.$min_selected.'>'.$min.'</option>';
84 155
         }
85
-    ?>
86
-    <div id="rc-post-wrap" class="curtime">
87
-        <input type="hidden" name="schroeder" id="schroeder" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>"/>
88
-        <label class="rc_accept">
89
-            <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) ?>
90
-        </label>
91
-        <div class="rc-datetime" id="timestamp">
92
-            <?php _e('UpdateTime',RC_TXT_DOMAIN) ?>:<b><?php echo date_i18n("Y/m/d @ H:i", strtotime($reserv_date)); ?></b>
93
-        </div>
94
-        <a href="#edit-reservdate" class="edit-timestamp rc-datetime-edit"><?php _e('Edit') ?></a>
95
-        <div class="rc-datetime-wrap">
96
-            <select name="rc_year">
97
-            <?php 
98
-            for($y = $current_y; $y <= ($current_y + 3); $y++)
99
-            {
100
-                $ySelected = ($y == date_i18n('Y',$reserv_date_arr[0])) ? "selected" : "";
101
-                echo '<option value="'.$y.'" '.$ySelected.'>'.$y.'</option>';
102
-            }
103
-            ?>
104
-            </select>
105
-            <?php echo '/' ?>
106
-            <select name="rc_month">
107
-            <?php
108
-            for($i=1;$i<=12;$i++)
109
-            {
110
-                $m = sprintf("%02d",$i);
111
-                $selected = ($m == date_i18n('m',$reserv_date_arr[0])) ? "selected" : "";
112
-                echo '<option value="'.$m.'" '.$selected.'>'.$m.'</option>';
113
-            }
114
-            ?>
115
-            </select><?php echo '/' ?>
116
-            <select name="rc_day">
117
-            <?php 
118
-            for($d=1;$d<=31;$d++){
119
-                $d = sprintf("%02d",$d);
120
-                $dSelected = ($d == date_i18n('d',$reserv_date_arr[0])) ? "selected" : "";
121
-                echo '<option value="'.$d.'" '.$dSelected.'>'.$d.'</option>';
122
-            }
123
-            ?>
124
-            </select>    
125
-            @
126
-            <select name="rc_hour">
127
-            <?php 
128
-            for($h=0;$h<=23;$h++){
129
-                $h = sprintf("%02d",$h);
130
-                $hSelected = ($h == date_i18n('H',$reserv_date_arr[0])) ? "selected" : "";
131
-                echo '<option value="'.$h.'" '.$hSelected.'>'.$h.'</option>';
132
-            }
133
-            ?>
134
-            </select>
135
-            :
136
-            <select name="rc_minutes">
137
-            <?php 
138
-            for($min=0;$min<=59;$min++){
139
-                $min = sprintf("%02d",$min);
140
-                $minSelected = ($min == date_i18n('i',$reserv_date_arr[0])) ? "selected" : "";
141
-                echo '<option value="'.$min.'" '.$minSelected.'>'.$min.'</option>';
142
-            }
143
-            ?>
144
-            </select>
145
-            <a href="#edit-reservdate" class="rc-datetime-update button"><?php _e('OK',RC_TXT_DOMAIN) ?></a>
146
-            <a href="#edit-reservdate" class="rc-datetime-cancel"><?php _e('Cancel',RC_TXT_DOMAIN) ?></a>
147
-        </div>
148
-        <?php
149
-            $dateArr = array(
150
-                'rc_year' => date_i18n('Y',$reserv_date_arr[0]),
151
-                'rc_month' => date_i18n('m',$reserv_date_arr[0]),
152
-                'rc_day' => date_i18n('d',$reserv_date_arr[0]),
153
-                'rc_hour' => date_i18n('H',$reserv_date_arr[0]),
154
-                'rc_minutes' => date_i18n('i',$reserv_date_arr[0])
155
-            );
156
-            foreach ($dateArr as $k => $v)
157
-            {
158
-                echo '<input type="hidden" name="'.$k.'_cr" id="'.$k.'_cr" value="'.$v.'">';
159
-            }
160 156
         ?>
157
+        </select>
158
+        <a href="#edit-reservdate" class="rc-datetime-update button"><?php _e('OK',RC_TXT_DOMAIN) ?></a>
159
+        <a href="#edit-reservdate" class="rc-datetime-cancel"><?php _e('Cancel',RC_TXT_DOMAIN) ?></a>
161 160
     </div>
161
+    <?php
162
+        $date_arr = array(
163
+            'rc_year' => date_i18n('Y',$reserv_date_arr[0]),
164
+            'rc_month' => date_i18n('m',$reserv_date_arr[0]),
165
+            'rc_day' => date_i18n('d',$reserv_date_arr[0]),
166
+            'rc_hour' => date_i18n('H',$reserv_date_arr[0]),
167
+            'rc_minutes' => date_i18n('i',$reserv_date_arr[0])
168
+        );
169
+        foreach ($date_arr as $k => $v)
170
+        {
171
+            echo '<input type="hidden" name="'.$k.'_cr" id="'.$k.'_cr" value="'.$v.'">';
172
+        }
173
+    ?>
174
+</div>
162 175
 <?php 
163 176
     wp_editor($reserv_content, $rc_content_name);
177
+/*
178
+ * support feature image reservation.
179
+ */
180
+    if( current_theme_supports('post-thumbnails') ) {
181
+?>
182
+<fieldset>
183
+<h3><?php echo __('Featured Image for Reservation Update', RC_TXT_DOMAIN); ?></h3>
184
+<label class="rc_feature_accept">
185
+    <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); ?>
186
+</label>
187
+<p><a href="media-upload.php?type=image&TB_iframe=1&width=753&height=522&post_id=<?php echo $post->ID ?>" class="thickbox<?php echo ($reserv_feature_image != '') ? ' has_image' : ''; ?>" id="rc_feature_image_upload" title="<?php _e('Set featured image Reservation', RC_TXT_DOMAIN) ?>"><?php echo ($reserv_feature_image != '') ? $reserv_feature_image : __('Set featured image for Reservation', RC_TXT_DOMAIN); ?></a></p>
188
+<p><a href="#" class="rc_remove_feature_image"><?php _e('Remove Featured image for Reservation', RC_TXT_DOMAIN) ?></a></p>
189
+<input type="hidden" id="rc_feature_image" name="<?php echo $reserv_feature_name ?>" value="<?php echo $reserv_feature ?>" />
190
+</fieldset>
191
+<?php 
164 192
     }
165 193
 }
166 194
 
167 195
 // save post meta
168
-add_action('save_post','savePostmeta');
169
-function savePostmeta($post_id)
196
+add_action('save_post','save_rc_post_meta');
197
+function save_rc_post_meta($post_id)
170 198
 {
171 199
     if(isset($_POST) && isset($_POST['post_type']))
172 200
     {
... ...
@@ -176,33 +206,33 @@ function savePostmeta($post_id)
176 176
         if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
177 177
             return;
178 178
         }
179
-        $rcKeys = getRcMetas();
180
-        $acceptPostType = getRcSetting();
181
-        if(in_array($_POST['post_type'], $acceptPostType))
179
+        $rc_keys = get_rc_metas();
180
+        $accept_post_type = get_rc_setting();
181
+        if(in_array($_POST['post_type'], $accept_post_type))
182 182
         {
183 183
             $date = mktime($_POST['rc_hour'], $_POST['rc_minutes'], 00, $_POST['rc_month'], $_POST['rc_day'], $_POST['rc_year']);
184 184
             if($date)
185 185
             {
186
-                $_POST[$rcKeys['date']] = date_i18n('Y-m-d H:i:s',$date);
186
+                $_POST[$rc_keys['date']] = date_i18n('Y-m-d H:i:s',$date);
187 187
             } else {
188
-                $_POST[$rcKeys['date']] = "";
188
+                $_POST[$rc_keys['date']] = "";
189 189
             }
190
-            if(!isset($_POST[$rcKeys['accept']]) || $_POST[$rcKeys['accept']] != "1"){
191
-                $_POST[$rcKeys['accept']]  = "0";
190
+            if(!isset($_POST[$rc_keys['accept']]) || $_POST[$rc_keys['accept']] != "1"){
191
+                $_POST[$rc_keys['accept']]  = "0";
192 192
             }
193 193
         }
194
-        foreach ($rcKeys as $key => $val)
194
+        foreach ($rc_keys as $key => $val)
195 195
         {
196
-            savePostMetaBase($post_id, $val);
196
+            save_rc_post_meta_base($post_id, $val);
197 197
         }
198
-        if($_POST[$rcKeys['accept']] == "1")
198
+        if($_POST[$rc_keys['accept']] == "1")
199 199
         {
200
-            $reservDate = strtotime(get_gmt_from_date($_POST[$rcKeys['date']]) . " GMT");
201
-            if(in_array($_POST['post_type'], $acceptPostType) || $_POST['post_type'] != 'revision')
200
+            $reserv_date = strtotime(get_gmt_from_date($_POST[$rc_keys['date']]) . " GMT");
201
+            if(in_array($_POST['post_type'], $accept_post_type) )
202 202
             {
203
-                wp_schedule_single_event($reservDate, RC_CRON_HOOK, array($post_id));
203
+                wp_schedule_single_event($reserv_date, RC_CRON_HOOK, array($post_id));
204 204
             }
205
-        } else if($_POST[$rcKeys['accept']] == "0" || !isset ($_POST[$rcKeys['accept']])) {
205
+        } else if($_POST[$rc_keys['accept']] == "0" || !isset ($_POST[$rc_keys['accept']])) {
206 206
             // delete schedule
207 207
             wp_clear_scheduled_hook(RC_CRON_HOOK, array($post_id));
208 208
         }
... ...
@@ -215,7 +245,7 @@ function savePostmeta($post_id)
215 215
  * @param int $post_id
216 216
  * @param string $post_metakey
217 217
  */
218
-function savePostMetaBase($post_id, $post_metakey)
218
+function save_rc_post_meta_base($post_id, $post_metakey)
219 219
 {
220 220
     if(isset($_POST))
221 221
     {
... ...
@@ -234,19 +264,24 @@ function savePostMetaBase($post_id, $post_metakey)
234 234
 }
235 235
 
236 236
 // update post for wp-cron
237
-add_action('rucy_update_reserved_content', 'updateReservedContent','10',1);
238
-function updateReservedContent($post_id)
237
+add_action('rucy_update_reserved_content', 'update_rc_reserved_content', 10, 1);
238
+function update_rc_reserved_content($post_id)
239 239
 {
240
-    $rcMetas = getRcMetas($post_id);
241
-    if("1" == $rcMetas['accept'])
240
+    $rc_metas = get_rc_metas((int)$post_id);
241
+    if("1" == $rc_metas['accept'])
242 242
     {
243 243
         $updates = array(
244
-            'ID' => $post_id,
245
-            'post_content' => $rcMetas['content'],
244
+            'ID' => (int)$post_id,
245
+            'post_content' => $rc_metas['content'],
246 246
         );
247
-       wp_update_post($updates,true);
247
+        // feature_image
248
+        if(isset($rc_metas['accept_feature_img']) && "1" == $rc_metas['accept_feature_img'] &&
249
+           isset($rc_metas['feature_img']) && $rc_metas['feature_img'] != '') {
250
+            update_rc_post_thumbnail($post_id, $rc_metas['feature_img']);
251
+        }
252
+       $upp = wp_update_post($updates,true);
248 253
     }
249
-    $dels = getRcMetas();
254
+    $dels = get_rc_metas();
250 255
     foreach ($dels as $key => $del)
251 256
     {
252 257
         delete_post_meta($post_id, $del);
... ...
@@ -254,76 +289,113 @@ function updateReservedContent($post_id)
254 254
     wp_clear_scheduled_hook(RC_CRON_HOOK, array($post_id));
255 255
 }
256 256
 
257
+function update_rc_post_thumbnail($post_id, $reserved_post_thumb_path)
258
+{
259
+    include_once(ABSPATH . 'wp-admin/includes/image.php');
260
+    $upload_dir = wp_upload_dir();
261
+    $image_data = file_get_contents($reserved_post_thumb_path);
262
+    $file_name = basename($reserved_post_thumb_path);
263
+    if(wp_mkdir_p($upload_dir['path'])) {
264
+        $file = $upload_dir['path'] . '/' . $file_name;
265
+    } else {
266
+        $file = $upload_dir['basedir'] . '/' . $file_name;
267
+    }
268
+    file_put_contents($file, $image_data);
269
+    $wp_file_type = wp_check_filetype($file_name, null);
270
+    $attachment = array(
271
+        'post_mime_type' => $wp_file_type['type'],
272
+        'post_title' => sanitize_file_name($file_name),
273
+        'post_content' => '',
274
+        'post_status' => 'inherit',
275
+    );
276
+    delete_post_thumbnail($post_id);
277
+    $attachment_id = wp_insert_attachment($attachment, $file, $post_id);
278
+    $attach_data = wp_generate_attachment_metadata($attachment_id, $file);
279
+    if(!empty($attach_data) && !is_wp_error($attach_data)){
280
+        $res = wp_update_attachment_metadata($attachment_id, $attach_data);
281
+        set_post_thumbnail($post_id, $attachment_id);
282
+        
283
+        return $res;
284
+    }
285
+}
286
+
257 287
 // add update message
258
-add_filter('post_updated_messages','addRcMessage');
259
-function addRcMessage($messages)
288
+add_filter('post_updated_messages','add_rc_message');
289
+function add_rc_message($messages)
260 290
 {
261 291
     global  $post, $post_ID;
262
-    $arrPostTypes = getRcSetting(true);
263
-    $postType = get_post_type($post);
264
-    if(in_array($postType, $arrPostTypes))
292
+    $arr_post_types = get_rc_setting(true);
293
+    $post_type = get_post_type($post);
294
+    if(in_array($post_type, $arr_post_types))
265 295
     {
266
-        $rcMetas = getRcMetas($post_ID);
267
-        if("1" == $rcMetas['accept'])
296
+        $rc_metas = get_rc_metas($post_ID);
297
+        if("1" == $rc_metas['accept'])
268 298
         {
269
-            $addMessageDate = date_i18n('Y/m/d @ H:i',  strtotime($rcMetas['date']));
299
+            $add_message_date = date_i18n('Y/m/d @ H:i',  strtotime($rc_metas['date']));
270 300
             $str = __('registered reservation update content _RC_DATETIME_',RC_TXT_DOMAIN);
271
-            $addMessage = '<br>' . strtr($str, array('_RC_DATETIME_' => $addMessageDate));
301
+            $add_message = '<br>' . strtr($str, array('_RC_DATETIME_' => $add_message_date));
272 302
             // published
273
-            $messages[$postType][1] .= $addMessage;
274
-            $messages[$postType][4] .= $addMessage;
275
-            $messages[$postType][6] .= $addMessage;
303
+            $messages[$post_type][1] .= $add_message;
304
+            $messages[$post_type][4] .= $add_message;
305
+            $messages[$post_type][6] .= $add_message;
276 306
             // saved
277
-            $messages[$postType][7] .= $addMessage;
307
+            $messages[$post_type][7] .= $add_message;
278 308
             // submited
279
-            $messages[$postType][8] .= $addMessage;
309
+            $messages[$post_type][8] .= $add_message;
280 310
             // scheduled
281
-            $messages[$postType][9] .= $addMessage;
311
+            $messages[$post_type][9] .= $add_message;
282 312
         }
283 313
     }
284 314
     return $messages;
285 315
 }
286 316
 
287 317
 // add reservation info at postlist
288
-function manageRucyCols($columns) {
289
-    $columns['subtitle'] = __("Reservation Update DateTime", RC_TXT_DOMAIN);
318
+function manage_rucy_cols($columns)
319
+{
320
+    $columns['rucy_reservation_date'] = __("Reservation Update DateTime", RC_TXT_DOMAIN);
290 321
     return $columns;
291 322
 }
292
-function addRucyCol($column_name, $post_id) {
293
-    $rcMetas = getRcMetas($post_id);
323
+
324
+function add_rucy_col($column_name, $post_id)
325
+{
326
+    $rc_metas = get_rc_metas($post_id);
294 327
     $s = "";
295
-    if($column_name == 'subtitle')
296
-    {
297
-        $s = $rcMetas['accept'];
298
-    }
299
-    if($s == "1")
328
+    if($column_name == 'rucy_reservation_date')
300 329
     {
301
-        echo $rcMetas['date'];
302
-    } else {
303
-        echo __('None');
330
+        $s = $rc_metas['accept'];
331
+        if($s == "1")
332
+        {
333
+            echo $rc_metas['date'];
334
+        } else {
335
+            echo __('None');
336
+        }
304 337
     }
305 338
 }
306 339
 
307
-foreach (array('pages','posts') as $p){
308
-    add_filter('manage_'.$p.'_columns', 'manageRucyCols');
309
-    add_action('manage_'.$p.'_custom_column', 'addRucyCol', 10, 2);    
340
+$accept_post_type = get_rc_setting();
341
+foreach ($accept_post_type as $p){
342
+    if(in_array($p, array('page', 'post'))) {
343
+        $p .= 's';
344
+    }
345
+    add_filter('manage_'.$p.'_columns', 'manage_rucy_cols');
346
+    add_action('manage_'.$p.'_custom_column', 'add_rucy_col', 10, 2);    
310 347
 }
311 348
 
312 349
 // setting page
313 350
 add_action('admin_menu','admin_menu_rucy');
314 351
 function admin_menu_rucy()
315 352
 {
316
-    add_options_page('Rucy', 'Rucy', 'manage_options',  'rucy', 'addRcSetting');
353
+    add_options_page('Rucy', 'Rucy', 'manage_options',  'rucy', 'add_rc_setting');
317 354
 }
318
-function addRcSetting()
355
+function add_rc_setting()
319 356
 {
320 357
     $post = $_POST;
321
-    $isCheckedPost = "";
322
-    $isCheckedPage = "";
323
-    $customPostTypes = "";
324
-    $errorClass = "form-invalid";
325
-    $basicPostTypes = array('page','post');
326
-    $invalidPostTypes = array('attachment','revision');
358
+    $is_checked_post = "";
359
+    $is_checked_page = "";
360
+    $custom_post_types = "";
361
+    $error_class = "form-invalid";
362
+    $basic_post_types = array('page','post');
363
+    $invalid_post_types = array('attachment','revision');
327 364
     $message = array();
328 365
     $error = 0;
329 366
     if(isset($post['page_options']))
... ...
@@ -332,13 +404,13 @@ function addRcSetting()
332 332
         if(isset($post['rc_post']) && $post['rc_post'] == 'post')
333 333
         {
334 334
             $res .= $post['rc_post'];
335
-            $isCheckedPost = "checked";
335
+            $is_checked_post = "checked";
336 336
         } else {
337 337
             $error += 1;
338 338
         }
339 339
         if(isset($post['rc_page']) && $post['rc_page'] == 'page') {
340 340
             $res .= "," . $post['rc_page'];
341
-            $isCheckedPage = "checked";
341
+            $is_checked_page = "checked";
342 342
         } else {
343 343
             $error += 1;
344 344
         }
... ...
@@ -346,20 +418,20 @@ function addRcSetting()
346 346
             $message['post_page'] = __("post or page is not allow.", RC_TXT_DOMAIN);
347 347
         }
348 348
         if(isset($post['rc_custom_post']) && $post['rc_custom_post'] != "") {
349
-            $customCheck = explode(',', $post['rc_custom_post']);
350
-            foreach ($customCheck as $check)
349
+            $custom_check = explode(',', $post['rc_custom_post']);
350
+            foreach ($custom_check as $check)
351 351
             {
352
-                if(in_array($check, $basicPostTypes))
352
+                if(in_array($check, $basic_post_types))
353 353
                 {
354 354
                     $message['custom_post'] = __('Do not input "post" or "page". ', RC_TXT_DOMAIN);
355 355
                 } else if(!preg_match('/[a-zA-Z0-9_-]/', $check)) {
356 356
                     $message['custom_post'] = __("Please input alphabet or numeric. And do not input sequencial commas.", RC_TXT_DOMAIN);
357
-                } else if(in_array($check, $invalidPostTypes)){
357
+                } else if(in_array($check, $invalid_post_types)){
358 358
                     $message['custom_post'] = __('Do not input "attachment" or "revision". ',RC_TXT_DOMAIN);
359 359
                 }
360 360
             }
361 361
             $res .= "," . $post['rc_custom_post'];
362
-            $customPostTypes = $post['rc_custom_post'];
362
+            $custom_post_types = $post['rc_custom_post'];
363 363
         }
364 364
         if($res != "" && count($message) == 0)
365 365
         {
... ...
@@ -367,32 +439,32 @@ function addRcSetting()
367 367
         }
368 368
     } else {
369 369
         $message = array();
370
-        $arrSetting = getRcSetting();
371
-        $isCheckedPost = (in_array('post', $arrSetting) == TRUE) ? 'checked' : "";
372
-        $isCheckedPage = (in_array('page', $arrSetting) == TRUE) ? 'checked' : "";
373
-        $arrCustomPostTypes = array();
374
-        foreach ($arrSetting as $v)
370
+        $arr_setting = get_rc_setting();
371
+        $is_checked_post = (in_array('post', $arr_setting) == TRUE) ? 'checked' : "";
372
+        $is_checked_page = (in_array('page', $arr_setting) == TRUE) ? 'checked' : "";
373
+        $arr_custom_post_types = array();
374
+        foreach ($arr_setting as $v)
375 375
         {
376
-            if(!in_array($v, $basicPostTypes))
376
+            if(!in_array($v, $basic_post_types))
377 377
             {
378
-                array_push($arrCustomPostTypes, $v);
378
+                array_push($arr_custom_post_types, $v);
379 379
             }
380 380
         }
381
-        $customPostTypes = implode(',', $arrCustomPostTypes);
381
+        $custom_post_types = implode(',', $arr_custom_post_types);
382 382
     }
383 383
 ?>
384 384
 <div class="wrap">
385
-    <h2>Rucy Settings</h2>
385
+    <h2><?php _e('Rucy Settings', RC_TXT_DOMAIN); ?></h2>
386 386
     <p><?php _e('Configure content types reservation update.',RC_TXT_DOMAIN); ?></p>
387 387
     <form method="post" action="#">
388 388
         <?php wp_nonce_field('update-options'); ?>
389 389
         <table class="form-table">
390
-            <tr class="<?php echo (isset($message['post_page']) == true) ? $errorClass : ""; ?>">
390
+            <tr class="<?php echo (isset($message['post_page']) == true) ? $error_class : ""; ?>">
391 391
                 <th><?php _e('post type',RC_TXT_DOMAIN) ?><br><small>*<?php _e('Require',RC_TXT_DOMAIN) ?></small></th>
392 392
                 <td>
393 393
                     <ul>
394
-                        <li><label for="rc_post"><input type="checkbox" id="rc_post" name="rc_post" value="post" <?php echo $isCheckedPost ?>><?php _e('post',RC_TXT_DOMAIN) ?></label></li>
395
-                        <li><label for="rc_page"><input type="checkbox" id="rc_page" name="rc_page" value="page" <?php echo $isCheckedPage ?>><?php _e('page',RC_TXT_DOMAIN) ?></label></li>
394
+                        <li><label for="rc_post"><input type="checkbox" id="rc_post" name="rc_post" value="post" <?php echo $is_checked_post ?>><?php _e('post',RC_TXT_DOMAIN) ?></label></li>
395
+                        <li><label for="rc_page"><input type="checkbox" id="rc_page" name="rc_page" value="page" <?php echo $is_checked_page ?>><?php _e('page',RC_TXT_DOMAIN) ?></label></li>
396 396
                     </ul>
397 397
                     <?php 
398 398
                         if(isset($message['post_page']))
... ...
@@ -402,10 +474,10 @@ function addRcSetting()
402 402
                     ?>
403 403
                 </td>
404 404
             </tr>
405
-            <tr class="<?php echo (isset($message['custom_post']) == true) ? $errorClass : ""; ?>">
405
+            <tr class="<?php echo (isset($message['custom_post']) == true) ? $error_class : ""; ?>">
406 406
                 <th><?php _e('custom post type',RC_TXT_DOMAIN) ?></th>
407 407
                 <td>
408
-                    <input type="text" value="<?php echo $customPostTypes ?>" name="rc_custom_post" placeholder="<?php _e('Separated by commas',RC_TXT_DOMAIN) ?>">
408
+                    <input type="text" value="<?php echo $custom_post_types ?>" name="rc_custom_post" placeholder="<?php _e('Separated by commas',RC_TXT_DOMAIN) ?>">
409 409
                     <?php 
410 410
                         if(isset($message['custom_post']))
411 411
                         {
... ...
@@ -421,27 +493,16 @@ function addRcSetting()
421 421
             <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
422 422
         </p>
423 423
     </form>
424
-    <h3><?php _e("Contact",RC_TXT_DOMAIN) ?></h3>
425
-    <p>
426
-    <?php _e('Rucy is maintained by <a href="http://profiles.wordpress.org/gips-nita/">nita</a>.<br>', RC_TXT_DOMAIN) ?>
427
-    <?php _e('If you have found a bug or would like to make a suggestion or contribution why not join the <a href="https://wordpress.org/support/plugin/rucy">Support Form @ wordpress.org</a><br />',RC_TXT_DOMAIN);?>
428
-    <?php _e("Please consider donating if you like this plugin. I've put a lot of my free time into this plugin and donations help to justify it.<br />",RC_TXT_DOMAIN); ?>
429
-    </p>
430
-    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
431
-        <input type="hidden" name="cmd" value="_donations">
432
-        <input type="hidden" name="business" value="J2GV73KGN5MKN">
433
-        <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif"border="0" name="submit"alt="PayPal - The safer, easier way to pay online!">
434
-    </form>
435 424
 </div>
436 425
 <?php
437 426
 }
438 427
 /**
439 428
  * get post type allowed rucy
440 429
  * 
441
- * @param boolean $isArray
430
+ * @param boolean $is_array
442 431
  * @return string
443 432
  */
444
-function getRcSetting($isArray = true)
433
+function get_rc_setting($is_array = true)
445 434
 {
446 435
     $rc_setting = get_option(RC_SETTING_OPTION_KEY);
447 436
     $res = "";
... ...
@@ -449,7 +510,7 @@ function getRcSetting($isArray = true)
449 449
     {
450 450
         $rc_setting = RC_POSTTYPE_DEFAULT;
451 451
     }
452
-    if($isArray)
452
+    if($is_array)
453 453
     {
454 454
         $res = explode(',', $rc_setting);
455 455
     } else {
... ...
@@ -461,20 +522,20 @@ function getRcSetting($isArray = true)
461 461
 // uninstall
462 462
 if(function_exists('register_uninstall_hook'))
463 463
 {
464
-    register_uninstall_hook(__FILE__, 'goodbyeRucy');
464
+    register_uninstall_hook(__FILE__, 'uninstall_rucy');
465 465
 }
466 466
 // deactivation
467 467
 if(function_exists('register_deactivation_hook'))
468 468
 {
469
-    register_deactivation_hook(__FILE__, 'goodbyeRucy');
469
+    register_deactivation_hook(__FILE__, 'uninstall_rucy');
470 470
 }
471 471
 
472
-function goodbyeRucy()
472
+function uninstall_rucy()
473 473
 {
474 474
     wp_clear_scheduled_hook(RC_CRON_HOOK);
475 475
     delete_option(RC_SETTING_OPTION_KEY);
476 476
     $allposts = get_posts('numberposts=-1&post_status=');
477
-    $meta_keys = getRcMetas();
477
+    $meta_keys = get_rc_metas();
478 478
     foreach ($allposts as $postinfo)
479 479
     {
480 480
         foreach ($meta_keys as $k => $val)
... ...
@@ -485,21 +546,21 @@ function goodbyeRucy()
485 485
 }
486 486
 
487 487
 // link to setting
488
-add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'hiRucy');
489
-function hiRucy($links)
488
+add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'add_rc_setting_link');
489
+function add_rc_setting_link($links)
490 490
 {
491 491
     $links[] = '<a href="' . get_admin_url(null, 'options-general.php?page=rucy') . '">' . __('Settings') . '</a>';
492 492
     return $links;
493 493
 }
494 494
 
495 495
 // activate plugin action
496
-register_activation_hook(plugin_basename(__FILE__), 'helloRucy');
497
-function helloRucy()
496
+register_activation_hook(plugin_basename(__FILE__), 'install_rucy');
497
+function install_rucy()
498 498
 {
499 499
     $rc_setting = get_option(RC_SETTING_OPTION_KEY);
500 500
     if(!$rc_setting)
501 501
     {
502
-        $basicPostTypes = RC_POSTTYPE_DEFAULT;
503
-        update_option(RC_SETTING_OPTION_KEY, $basicPostTypes);
502
+        $basic_post_types = RC_POSTTYPE_DEFAULT;
503
+        update_option(RC_SETTING_OPTION_KEY, $basic_post_types);
504 504
     }
505
-}
506 505
\ No newline at end of file
506
+}