| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,21 @@ |
| 0 |
+#rc-post-wrap{
|
|
| 1 |
+ margin: 16px 0; |
|
| 2 |
+} |
|
| 3 |
+.rc-datetime-wrap{
|
|
| 4 |
+ display: none; |
|
| 5 |
+ margin: 10px 0; |
|
| 6 |
+ height: 21px; |
|
| 7 |
+} |
|
| 8 |
+.rc-datetime-wrap select{
|
|
| 9 |
+ line-height: 14px; |
|
| 10 |
+ padding: 0; |
|
| 11 |
+ vertical-align: top; |
|
| 12 |
+ font-size: 12px; |
|
| 13 |
+} |
|
| 14 |
+.rc-datetime-wrap input{
|
|
| 15 |
+ border-width: 1px; |
|
| 16 |
+ border-style: solid; |
|
| 17 |
+} |
|
| 18 |
+.rc-datetime{
|
|
| 19 |
+ display: inline-block; |
|
| 20 |
+} |
| 0 | 21 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,50 @@ |
| 0 |
+jQuery(document).ready(function(){
|
|
| 1 |
+ //timecomboBOx show |
|
| 2 |
+ jQuery('.rc-datetime-edit').on('click',function(){
|
|
| 3 |
+ jQuery(this).hide(); |
|
| 4 |
+ jQuery('.rc-datetime-wrap').slideDown('normal');
|
|
| 5 |
+ return false; |
|
| 6 |
+ }); |
|
| 7 |
+ // timecomboBOx close |
|
| 8 |
+ jQuery('.rc-datetime-update').on('click',function(){
|
|
| 9 |
+ var year = jQuery(':text[name="rc_year"]').val();
|
|
| 10 |
+ var month = jQuery('select[name="rc_month"]').val();
|
|
| 11 |
+ var day = jQuery(':text[name="rc_day"]').val();
|
|
| 12 |
+ var hour = jQuery(':text[name="rc_hour"]').val();
|
|
| 13 |
+ var min = jQuery(':text[name="rc_minutes"]').val();
|
|
| 14 |
+ newDate = new Date(year, month - 1, day, hour, min); |
|
| 15 |
+ if(newDate.getFullYear() != year || (1 + newDate.getMonth()) != month || newDate.getDate() != day || newDate.getMinutes() != min){
|
|
| 16 |
+ jQuery('.rc-datetime-wrap').addClass('form-invalid');
|
|
| 17 |
+ return false; |
|
| 18 |
+ } else {
|
|
| 19 |
+ jQuery('.rc-datetime-wrap').removeClass('form-invalid');
|
|
| 20 |
+ } |
|
| 21 |
+ jQuery('.rc-datetime > b').html(year + "/" + month + "/" + day + " @ " + hour + ":" + min);
|
|
| 22 |
+ jQuery('#rc_year_cr').val(year);
|
|
| 23 |
+ jQuery('#rc_month_cr').val(month);
|
|
| 24 |
+ jQuery('#rc_day_cr').val(day);
|
|
| 25 |
+ jQuery('#rc_hour_cr').val(hour);
|
|
| 26 |
+ jQuery('#rc_minutes_cr').val(min);
|
|
| 27 |
+ jQuery('.rc-datetime-wrap').slideUp('normal');
|
|
| 28 |
+ jQuery('.rc-datetime-edit').show();
|
|
| 29 |
+ return false; |
|
| 30 |
+ }); |
|
| 31 |
+ // cancel |
|
| 32 |
+ jQuery('.rc-datetime-cancel').on('click',function(){
|
|
| 33 |
+ var year = jQuery('#rc_year_cr').val();
|
|
| 34 |
+ var month = jQuery('#rc_month_cr').val();
|
|
| 35 |
+ var day = jQuery('#rc_day_cr').val();
|
|
| 36 |
+ var hour = jQuery('#rc_hour_cr').val();
|
|
| 37 |
+ var min = jQuery('#rc_minutes_cr').val();
|
|
| 38 |
+ jQuery('.rc-datetime > b').html(year + "/" + month + "/" + day + " @ " + hour + ":" + min);
|
|
| 39 |
+ jQuery(':text[name="rc_year"]').val(year);
|
|
| 40 |
+ jQuery('select[name="rc_month"]').val(month);
|
|
| 41 |
+ jQuery(':text[name="rc_day"]').val(day);
|
|
| 42 |
+ jQuery(':text[name="rc_hour"]').val(hour);
|
|
| 43 |
+ jQuery(':text[name="rc_minutes"]').val(min);
|
|
| 44 |
+ jQuery('.rc-datetime-wrap').slideUp('normal');
|
|
| 45 |
+ jQuery('.rc-datetime-edit').show();
|
|
| 46 |
+ return false; |
|
| 47 |
+ }); |
|
| 48 |
+}); |
|
| 49 |
+ |
| ... | ... |
@@ -19,16 +19,212 @@ add_action('admin_enqueue_scripts','rc_load_jscss');
|
| 19 | 19 |
function rc_load_jscss() |
| 20 | 20 |
{
|
| 21 | 21 |
global $hook_suffix; |
| 22 |
- $files = array('post.php','post-new.php');
|
|
| 23 |
- if(in_array($hook_suffix, $files)) |
|
| 22 |
+ if(in_array($hook_suffix, array('post.php','post-new.php',)))
|
|
| 24 | 23 |
{
|
| 25 |
- wp_register_style('rucy.css', RC_PLUGIN_URL . 'rucy.css',array(),'0.0.1');
|
|
| 24 |
+ wp_register_style('rucy.css', RC_PLUGIN_URL . '/css/rucy.css',array(),'0.0.1');
|
|
| 26 | 25 |
wp_enqueue_style('rucy.css');
|
| 27 |
- wp_register_script('rucy.js', RC_PLUGIN_URL . 'rucy.js', array('jquery'), '0.0.1');
|
|
| 26 |
+ wp_register_script('rucy.js', RC_PLUGIN_URL . '/js/rucy.js', array('jquery'), '0.0.1');
|
|
| 28 | 27 |
wp_enqueue_script('rucy.js');
|
| 29 | 28 |
} |
| 30 | 29 |
} |
| 31 | 30 |
|
| 31 |
+// |
|
| 32 |
+function getRcMetas($post_id = "") |
|
| 33 |
+{
|
|
| 34 |
+ $res = array(); |
|
| 35 |
+ if($post_id) |
|
| 36 |
+ {
|
|
| 37 |
+ $res = array( |
|
| 38 |
+ 'content' => get_post_meta($post_id,'rc_reserv_content',true), |
|
| 39 |
+ 'accept' => get_post_meta($post_id,'rc_reserv_accept', true), |
|
| 40 |
+ 'date' => get_post_meta($post_id, 'rc_reserv_accept', true), |
|
| 41 |
+ ); |
|
| 42 |
+ } else {
|
|
| 43 |
+ $res = array( |
|
| 44 |
+ 'content' => 'rc_reserv_content', |
|
| 45 |
+ 'accept' => 'rc_reserv_accept', |
|
| 46 |
+ 'date' => 'rc_reserv_date' |
|
| 47 |
+ ); |
|
| 48 |
+ } |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 51 |
+// add reserv_metabox |
|
| 52 |
+add_action('admin_menu', 'add_rucy_metabox_out');
|
|
| 53 |
+function add_rucy_metabox_out() |
|
| 54 |
+{
|
|
| 55 |
+ $acceptPostType = getRcSetting(); |
|
| 56 |
+ foreach ($acceptPostType as $postType) |
|
| 57 |
+ {
|
|
| 58 |
+ add_meta_box('rucy_metabox','Reserve Update Content Y.','add_rucy_metabox_inside',$postType,'normal','high');
|
|
| 59 |
+ } |
|
| 60 |
+ function add_rucy_metabox_inside() |
|
| 61 |
+ {
|
|
| 62 |
+ $rcKeys = getRcMetas(); |
|
| 63 |
+ $rc_content_name = $rcKeys['content']; |
|
| 64 |
+ $rc_accept_name = $rcKeys['accept']; |
|
| 65 |
+ global $post; |
|
| 66 |
+ $rcMetas = getRcMetas($post->ID); |
|
| 67 |
+ $reserv_accept = $rcMetas['accept']; |
|
| 68 |
+ $reserv_date = $rcMetas['date']; |
|
| 69 |
+ if("" == $reserv_date)
|
|
| 70 |
+ {
|
|
| 71 |
+ $reserv_date = $post->post_date; |
|
| 72 |
+ } |
|
| 73 |
+ $reserv_date_arr = getdate(strtotime($reserv_date)); |
|
| 74 |
+ $reserv_content = $rcMetas['content']; |
|
| 75 |
+ if("" == $reserv_content)
|
|
| 76 |
+ {
|
|
| 77 |
+ $reserv_content = $post->post_content; |
|
| 78 |
+ } |
|
| 79 |
+ ?> |
|
| 80 |
+ <div id="rc-post-wrap" class="curtime"> |
|
| 81 |
+ <label class="rc_accept"> |
|
| 82 |
+ <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) ?>
|
|
| 83 |
+ </label> |
|
| 84 |
+ <div class="rc-datetime" id="timestamp"> |
|
| 85 |
+ <?php _e('UpdateTime',RC_TXT_DOMAIN) ?>:<b><?php echo date("Y/m/d @ H:i", strtotime($reserv_date)); ?></b>
|
|
| 86 |
+ </div> |
|
| 87 |
+ <a href="#edit-reservdate" class="edit-timestamp rc-datetime-edit"><?php _e('Edit') ?></a>
|
|
| 88 |
+ <div class="rc-datetime-wrap"> |
|
| 89 |
+ <input type="text" size="4" maxlength="4" name="rc_year" value="<?php echo date('Y',$reserv_date_arr[0]); ?>"><?php echo '/' ?>
|
|
| 90 |
+ <select name="rc_month"> |
|
| 91 |
+ <?php |
|
| 92 |
+ for($i=1;$i<=12;$i++) |
|
| 93 |
+ {
|
|
| 94 |
+ $m = sprintf("%02d",$i);
|
|
| 95 |
+ $selected = ($m == date('m',$reserv_date_arr[0])) ? "selected" : "";
|
|
| 96 |
+ echo '<option value="'.$m.'" '.$selected.'>'.$m.'</option>'; |
|
| 97 |
+ } |
|
| 98 |
+ ?> |
|
| 99 |
+ </select><?php echo '/' ?> |
|
| 100 |
+ <input type="text" size="2" maxlength="2" name="rc_day" value="<?php echo date('d',$reserv_date_arr[0]); ?>">
|
|
| 101 |
+ @ <input type="text" size="2" maxlength="2" name="rc_hour" value="<?php echo date('H',$reserv_date_arr[0]); ?>">:<input type="text" size="2" maxlength="2" name="rc_minutes" value="<?php echo date('i',$reserv_date_arr[0]); ?>">
|
|
| 102 |
+ <a href="#edit-reservdate" class="rc-datetime-update button"><?php _e('OK',RC_TXT_DOMAIN) ?></a>
|
|
| 103 |
+ <a href="#edit-reservdate" class="rc-datetime-cancel"><?php _e('Cancel',RC_TXT_DOMAIN) ?></a>
|
|
| 104 |
+ </div> |
|
| 105 |
+ <?php |
|
| 106 |
+ $dateArr = array( |
|
| 107 |
+ 'rc_year' => date('Y',$reserv_date_arr[0]),
|
|
| 108 |
+ 'rc_month' => date('m',$reserv_date_arr[0]),
|
|
| 109 |
+ 'rc_day' => date('d',$reserv_date_arr[0]),
|
|
| 110 |
+ 'rc_hour' => date('H',$reserv_date_arr[0]),
|
|
| 111 |
+ 'rc_minutes' => date('i',$reserv_date_arr[0])
|
|
| 112 |
+ ); |
|
| 113 |
+ foreach ($dateArr as $k => $v) |
|
| 114 |
+ {
|
|
| 115 |
+ echo '<input type="hidden" name="'.$k.'_cr" id="'.$k.'_cr" value="'.$v.'">'; |
|
| 116 |
+ } |
|
| 117 |
+ ?> |
|
| 118 |
+ </div> |
|
| 119 |
+<?php |
|
| 120 |
+ wp_editor($reserv_content, $rc_content_name); |
|
| 121 |
+ } |
|
| 122 |
+} |
|
| 123 |
+ |
|
| 124 |
+// save post meta |
|
| 125 |
+add_action('save_post','savePostmeta');
|
|
| 126 |
+function savePostmeta($post_id) |
|
| 127 |
+{
|
|
| 128 |
+ if(isset($_POST) && isset($_POST['post_type'])) |
|
| 129 |
+ {
|
|
| 130 |
+ $rcKeys = getRcMetas(); |
|
| 131 |
+ $acceptPostType = getReservPostSetting(); |
|
| 132 |
+ foreach ($acceptPostType as $postType) |
|
| 133 |
+ {
|
|
| 134 |
+ if($_POST['post_type'] == $postType) |
|
| 135 |
+ {
|
|
| 136 |
+ $date = mktime($_POST['rc_hour'], $_POST['rc_minutes'], 00, $_POST['rc_month'], $_POST['rc_day'], $_POST['rc_year']); |
|
| 137 |
+ if($date) |
|
| 138 |
+ {
|
|
| 139 |
+ $_POST[$rcKeys['date']] = date('Y-m-d H:i:s',$date);
|
|
| 140 |
+ } else {
|
|
| 141 |
+ $_POST[$rcKeys['date']] = ""; |
|
| 142 |
+ } |
|
| 143 |
+ $meta_keys = getRcMetas(); |
|
| 144 |
+ } |
|
| 145 |
+ } |
|
| 146 |
+ foreach ($meta_keys as $val) |
|
| 147 |
+ {
|
|
| 148 |
+ savePostMetaBase($post_id, $val); |
|
| 149 |
+ } |
|
| 150 |
+ if($_POST['rc_reserv_date'] != "") |
|
| 151 |
+ {
|
|
| 152 |
+ $reservDate = strtotime(get_gmt_from_date($_POST[$rcKeys['date']]) . " GMT"); |
|
| 153 |
+ if(in_array($_POST['post_type'], $acceptPostType)) |
|
| 154 |
+ {
|
|
| 155 |
+ wp_schedule_single_event($reservDate, 'rucy_update_reserved_content', array($post_id)); |
|
| 156 |
+ } |
|
| 157 |
+ } |
|
| 158 |
+ } |
|
| 159 |
+} |
|
| 160 |
+ |
|
| 161 |
+function savePostMetaBase($post_id, $post_metakey) |
|
| 162 |
+{
|
|
| 163 |
+ if(isset($_POST)) |
|
| 164 |
+ {
|
|
| 165 |
+ $post_data = ""; |
|
| 166 |
+ if(isset($_POST[$post_metakey])) |
|
| 167 |
+ {
|
|
| 168 |
+ $post_data = $_POST[$post_metakey]; |
|
| 169 |
+ } |
|
| 170 |
+ |
|
| 171 |
+ if("" == get_post_meta($post_id, $post_metakey,true))
|
|
| 172 |
+ {
|
|
| 173 |
+ // new |
|
| 174 |
+ add_post_meta($post_id, $post_metakey, $post_data,true); |
|
| 175 |
+ } elseif ($post_data != get_post_meta($post_id, $post_metakey,true)) {
|
|
| 176 |
+ // update |
|
| 177 |
+ update_post_meta($post_id, $post_metakey, $post_data); |
|
| 178 |
+ } elseif("" == $post_data) {
|
|
| 179 |
+ // delete |
|
| 180 |
+ delete_post_meta($post_id, $post_metakey); |
|
| 181 |
+ } |
|
| 182 |
+ } |
|
| 183 |
+} |
|
| 184 |
+ |
|
| 185 |
+// update post for wp-cron |
|
| 186 |
+add_action('wp_reserv_content_update', 'updateReservedContent','10',1);
|
|
| 187 |
+function updateReservedContent($post_id) |
|
| 188 |
+{
|
|
| 189 |
+ $rcMetas = getRcMetas($post_id); |
|
| 190 |
+ if("1" == $rcMetas['accept'])
|
|
| 191 |
+ {
|
|
| 192 |
+ $updates = array( |
|
| 193 |
+ 'ID' => $post_id, |
|
| 194 |
+ 'post_content' => $rcMetas['content'], |
|
| 195 |
+ ); |
|
| 196 |
+ wp_update_post($updates,true); |
|
| 197 |
+ } |
|
| 198 |
+ wp_clear_scheduled_hook('rucy_update_reserved_content', array($post_id));
|
|
| 199 |
+ $dels = getRcMetas(); |
|
| 200 |
+ foreach ($dels as $del) |
|
| 201 |
+ {
|
|
| 202 |
+ delete_post_meta($post_id, $del); |
|
| 203 |
+ } |
|
| 204 |
+} |
|
| 205 |
+ |
|
| 206 |
+// add reservation info at postlist |
|
| 207 |
+function manageRucyCols($columns) {
|
|
| 208 |
+ $columns['subtitle'] = "reservation update content"; |
|
| 209 |
+ return $columns; |
|
| 210 |
+} |
|
| 211 |
+function addRucyCol($column_name, $post_id) {
|
|
| 212 |
+ $rcMetas = getRcMetas($post_id); |
|
| 213 |
+ if($column_name == 'subtitle') |
|
| 214 |
+ {
|
|
| 215 |
+ $s = $rcMetas['accept']; |
|
| 216 |
+ } |
|
| 217 |
+ if($s == "1") |
|
| 218 |
+ {
|
|
| 219 |
+ echo $rcMetas['date']; |
|
| 220 |
+ } else {
|
|
| 221 |
+ echo __('None');
|
|
| 222 |
+ } |
|
| 223 |
+} |
|
| 224 |
+add_filter('manage_posts_columns', 'manageRucyCols');
|
|
| 225 |
+add_action('manage_posts_custom_column', 'addRucyCol', 10, 2);
|
|
| 226 |
+ |
|
| 227 |
+ |
|
| 32 | 228 |
// setting page |
| 33 | 229 |
add_action('admin_menu','admin_menu_rucy');
|
| 34 | 230 |
function admin_menu_rucy() |
| ... | ... |
@@ -67,7 +263,6 @@ function addRcSetting() |
| 67 | 67 |
} |
| 68 | 68 |
if(isset($post['rc_custom_post']) && $post['rc_custom_post'] != "") {
|
| 69 | 69 |
$customCheck = explode(',', $post['rc_custom_post']);
|
| 70 |
- var_dump($customCheck); |
|
| 71 | 70 |
foreach ($customCheck as $check){
|
| 72 | 71 |
if(preg_match('/^page$/', $check) || preg_match('/^post$/', $check))
|
| 73 | 72 |
{
|
| ... | ... |
@@ -160,3 +355,23 @@ function getRcSetting($isArray = true) |
| 160 | 160 |
return $res; |
| 161 | 161 |
} |
| 162 | 162 |
|
| 163 |
+// uninstall |
|
| 164 |
+if(function_exists('register_uninstall_hook'))
|
|
| 165 |
+{
|
|
| 166 |
+ register_uninstall_hook(__FILE__, 'seeyaRucy'); |
|
| 167 |
+} |
|
| 168 |
+ |
|
| 169 |
+function seeyaRucy() |
|
| 170 |
+{
|
|
| 171 |
+ wp_clear_scheduled_hook('rucy_update_reserved_content');
|
|
| 172 |
+ delete_option(RC_SETTING_OPTION_KEY); |
|
| 173 |
+ $allposts = get_posts('numberposts=-1&post_status=');
|
|
| 174 |
+ $meta_keys = getRcMetas(); |
|
| 175 |
+ foreach ($allposts as $postinfo) |
|
| 176 |
+ {
|
|
| 177 |
+ foreach ($meta_keys as $k) |
|
| 178 |
+ {
|
|
| 179 |
+ delete_post_meta($postinfo->ID, $k); |
|
| 180 |
+ } |
|
| 181 |
+ } |
|
| 182 |
+} |