@@ -14,41 +14,41 @@ discard block |
||
14 | 14 | |
15 | 15 | |
16 | 16 | public function __construct() { |
17 | - add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) ); |
|
18 | - add_action( 'save_post', array( $this, 'set_event' ) ); |
|
19 | - add_action( 'admin_head', array( $this, 'ping' ) ); |
|
20 | - add_action( 'template_redirect', array( $this, 'ping' ) ); |
|
21 | - add_action( 'init', array( $this, 'init' ) ); |
|
17 | + add_filter('cron_schedules', array($this, 'cron_schedules')); |
|
18 | + add_action('save_post', array($this, 'set_event')); |
|
19 | + add_action('admin_head', array($this, 'ping')); |
|
20 | + add_action('template_redirect', array($this, 'ping')); |
|
21 | + add_action('init', array($this, 'init')); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function init() { |
25 | 25 | $posts = get_posts($this->args); |
26 | 26 | |
27 | - if ( empty($posts) ) |
|
27 | + if (empty($posts)) |
|
28 | 28 | return; |
29 | 29 | |
30 | - foreach ( $posts as $post ) { |
|
31 | - add_action( 'wp_syndicate_' . $post->post_name . '_import', array( $this, 'import' ) ); |
|
30 | + foreach ($posts as $post) { |
|
31 | + add_action('wp_syndicate_' . $post->post_name . '_import', array($this, 'import')); |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | 35 | public function ping() { |
36 | 36 | $posts = get_posts($this->args); |
37 | - if ( empty($posts) ) |
|
37 | + if (empty($posts)) |
|
38 | 38 | return; |
39 | 39 | |
40 | - foreach ( $posts as $post ) { |
|
40 | + foreach ($posts as $post) { |
|
41 | 41 | $key = $post->post_name; |
42 | 42 | $hook = 'wp_syndicate_' . $key . '_import'; |
43 | 43 | |
44 | - if ( !wp_next_scheduled( $hook, array( $post->ID ) ) ) { |
|
44 | + if (!wp_next_scheduled($hook, array($post->ID))) { |
|
45 | 45 | $this->set_event($post->ID); |
46 | - $subject = '[' . get_bloginfo( 'name' ) . ']' . __( 'WP Cron Error', WPSYND_DOMAIN ); |
|
47 | - $msg = sprintf( __( '%s of WP Cron restart, because it stopped.', WPSYND_DOMAIN ), $hook ) . "\n". __( 'action time', WPSYND_DOMAIN ). ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
46 | + $subject = '[' . get_bloginfo('name') . ']' . __('WP Cron Error', WPSYND_DOMAIN); |
|
47 | + $msg = sprintf(__('%s of WP Cron restart, because it stopped.', WPSYND_DOMAIN), $hook) . "\n" . __('action time', WPSYND_DOMAIN) . ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
48 | 48 | $msg .= admin_url(); |
49 | - WP_SYND_logger::get_instance()->error( $subject, $msg ); |
|
50 | - $options = get_option( 'wp_syndicate_options' ); |
|
51 | - wp_mail( $options['error_mail'], $subject, $msg ); |
|
49 | + WP_SYND_logger::get_instance()->error($subject, $msg); |
|
50 | + $options = get_option('wp_syndicate_options'); |
|
51 | + wp_mail($options['error_mail'], $subject, $msg); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | public function cron_schedules($schedules) { |
57 | 57 | $posts = get_posts($this->args); |
58 | 58 | |
59 | - if ( empty($posts) ) { |
|
59 | + if (empty($posts)) { |
|
60 | 60 | return $schedules; |
61 | 61 | } |
62 | 62 | |
63 | - foreach ( $posts as $post ) { |
|
63 | + foreach ($posts as $post) { |
|
64 | 64 | $key = 'wp_syndicate_' . $post->post_name; |
65 | - $interval_min = get_post_meta( $post->ID, 'wp_syndicate-feed-retrieve-term', true ); |
|
66 | - $interval = intval($interval_min)*60; |
|
67 | - $display = get_the_title( $post->ID ); |
|
68 | - $schedules[$key] = array( 'interval' => $interval, 'display' => $display ); |
|
65 | + $interval_min = get_post_meta($post->ID, 'wp_syndicate-feed-retrieve-term', true); |
|
66 | + $interval = intval($interval_min) * 60; |
|
67 | + $display = get_the_title($post->ID); |
|
68 | + $schedules[$key] = array('interval' => $interval, 'display' => $display); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | return $schedules; |
@@ -73,63 +73,63 @@ discard block |
||
73 | 73 | |
74 | 74 | public function set_event($post_id) { |
75 | 75 | |
76 | - if ( wp_is_post_revision($post_id) ) |
|
76 | + if (wp_is_post_revision($post_id)) |
|
77 | 77 | return; |
78 | 78 | |
79 | - if ( 'wp-syndicate' != get_post_type($post_id) ) |
|
79 | + if ('wp-syndicate' != get_post_type($post_id)) |
|
80 | 80 | return; |
81 | 81 | |
82 | - $post = get_post( $post_id ); |
|
83 | - if ( !is_object($post) ) |
|
82 | + $post = get_post($post_id); |
|
83 | + if (!is_object($post)) |
|
84 | 84 | return; |
85 | 85 | |
86 | 86 | $key = $post->post_name; |
87 | - $interval_min = get_post_meta( $post_id, 'wp_syndicate-feed-retrieve-term', true ); |
|
88 | - $interval = intval($interval_min)*60; |
|
87 | + $interval_min = get_post_meta($post_id, 'wp_syndicate-feed-retrieve-term', true); |
|
88 | + $interval = intval($interval_min) * 60; |
|
89 | 89 | $action_time = time() + $interval; |
90 | 90 | |
91 | 91 | $hook = 'wp_syndicate_' . $key . '_import'; |
92 | 92 | $event = 'wp_syndicate_' . $key; |
93 | 93 | |
94 | - if ( wp_next_scheduled( $hook, array( $post_id )) ) |
|
95 | - wp_clear_scheduled_hook( $hook, array( $post_id ) ); |
|
94 | + if (wp_next_scheduled($hook, array($post_id))) |
|
95 | + wp_clear_scheduled_hook($hook, array($post_id)); |
|
96 | 96 | |
97 | - wp_schedule_event( $action_time, $event, $hook, array( $post_id ) ); |
|
98 | - spawn_cron( $action_time ); |
|
97 | + wp_schedule_event($action_time, $event, $hook, array($post_id)); |
|
98 | + spawn_cron($action_time); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | public function import($post_id) { |
102 | 102 | global $allowedposttags; |
103 | 103 | |
104 | - $allowedposttags = apply_filters( 'wp_syndicate_allowedposttags', $allowedposttags ); |
|
104 | + $allowedposttags = apply_filters('wp_syndicate_allowedposttags', $allowedposttags); |
|
105 | 105 | |
106 | - $options = get_option( 'wp_syndicate_options' ); |
|
106 | + $options = get_option('wp_syndicate_options'); |
|
107 | 107 | $post = get_post($post_id); |
108 | 108 | |
109 | - if ( !is_object($post) ) |
|
109 | + if (!is_object($post)) |
|
110 | 110 | return; |
111 | 111 | |
112 | 112 | $this->media_id = $post_id; |
113 | - $feed_url = html_entity_decode(get_post_meta( $post_id, 'wp_syndicate-feed-url', true ), ENT_QUOTES, 'UTF-8'); |
|
113 | + $feed_url = html_entity_decode(get_post_meta($post_id, 'wp_syndicate-feed-url', true), ENT_QUOTES, 'UTF-8'); |
|
114 | 114 | |
115 | - add_action('wp_feed_options', function(&$feed){ |
|
115 | + add_action('wp_feed_options', function(&$feed) { |
|
116 | 116 | $feed->set_timeout(30); |
117 | 117 | $feed->force_feed(true); |
118 | 118 | $feed->enable_cache(false); |
119 | 119 | }, 10); |
120 | 120 | |
121 | - add_filter( 'wp_feed_cache_transient_lifetime' , array( $this, 'return_0' ) ); |
|
122 | - $rss = fetch_feed( $feed_url ); |
|
123 | - remove_filter( 'wp_feed_cache_transient_lifetime' , array( $this, 'return_0' ) ); |
|
124 | - if ( is_wp_error( $rss ) ) { |
|
125 | - $subject = '[' . get_bloginfo( 'name' ) . ']' . __( 'feed import failed', WPSYND_DOMAIN ); |
|
126 | - $msg = sprintf( __( 'An error occurred at a feed retrieval of %s', WPSYND_DOMAIN ), $post->post_name ) . "\n". __( 'action time', WPSYND_DOMAIN ). ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
127 | - $msg .= __( 'below error message', WPSYND_DOMAIN ) . "\n"; |
|
128 | - $msg .= $rss->get_error_message()."\n\n"; |
|
129 | - $msg .= __( 'feed URL', WPSYND_DOMAIN ) . ':' . $feed_url; |
|
130 | - $error_post_id = WP_SYND_logger::get_instance()->error( $subject, $msg ); |
|
121 | + add_filter('wp_feed_cache_transient_lifetime', array($this, 'return_0')); |
|
122 | + $rss = fetch_feed($feed_url); |
|
123 | + remove_filter('wp_feed_cache_transient_lifetime', array($this, 'return_0')); |
|
124 | + if (is_wp_error($rss)) { |
|
125 | + $subject = '[' . get_bloginfo('name') . ']' . __('feed import failed', WPSYND_DOMAIN); |
|
126 | + $msg = sprintf(__('An error occurred at a feed retrieval of %s', WPSYND_DOMAIN), $post->post_name) . "\n" . __('action time', WPSYND_DOMAIN) . ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
127 | + $msg .= __('below error message', WPSYND_DOMAIN) . "\n"; |
|
128 | + $msg .= $rss->get_error_message() . "\n\n"; |
|
129 | + $msg .= __('feed URL', WPSYND_DOMAIN) . ':' . $feed_url; |
|
130 | + $error_post_id = WP_SYND_logger::get_instance()->error($subject, $msg); |
|
131 | 131 | $msg .= admin_url('/post.php?post=' . $error_post_id . '&action=edit'); |
132 | - wp_mail( $options['error_mail'], $subject, $msg ); |
|
132 | + wp_mail($options['error_mail'], $subject, $msg); |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
@@ -139,138 +139,138 @@ discard block |
||
139 | 139 | $rss_items = $rss->get_items(0, 50); |
140 | 140 | $post_ids = array(); |
141 | 141 | $flg = true; |
142 | - $registration_method = get_post_meta( $post_id, 'wp_syndicate-registration-method', true ); |
|
143 | - $post_type = get_post_meta( $post_id, 'wp_syndicate-default-post-type', true ); |
|
144 | - foreach ( $rss_items as $item ) { |
|
142 | + $registration_method = get_post_meta($post_id, 'wp_syndicate-registration-method', true); |
|
143 | + $post_type = get_post_meta($post_id, 'wp_syndicate-default-post-type', true); |
|
144 | + foreach ($rss_items as $item) { |
|
145 | 145 | $this->is_enclosure = false; |
146 | 146 | |
147 | 147 | //投稿ID取得 |
148 | 148 | $slug = $post->post_name . '_' . $item->get_id(); |
149 | - $set_post = get_page_by_path( sanitize_title($slug), OBJECT, $post_type ); |
|
149 | + $set_post = get_page_by_path(sanitize_title($slug), OBJECT, $post_type); |
|
150 | 150 | $set_post_id = $set_post == null ? '' : $set_post->ID; |
151 | 151 | |
152 | - if ( empty($set_post_id) ) { |
|
152 | + if (empty($set_post_id)) { |
|
153 | 153 | global $wpdb; |
154 | - $db_ret = $wpdb->get_row( $wpdb->prepare( "SELECT count(1) as cnt FROM $wpdb->postmeta WHERE meta_key='%s'", $slug) ); |
|
155 | - if ( $db_ret === null || $db_ret->cnt !== '0' ) |
|
154 | + $db_ret = $wpdb->get_row($wpdb->prepare("SELECT count(1) as cnt FROM $wpdb->postmeta WHERE meta_key='%s'", $slug)); |
|
155 | + if ($db_ret === null || $db_ret->cnt !== '0') |
|
156 | 156 | continue; |
157 | 157 | } |
158 | 158 | |
159 | - if ( $registration_method == 'insert' && is_object($set_post) ) { |
|
159 | + if ($registration_method == 'insert' && is_object($set_post)) { |
|
160 | 160 | continue; |
161 | 161 | } |
162 | 162 | |
163 | 163 | $updated = empty($set_post_id) ? false : true; |
164 | - $is_skip = apply_filters( 'wp_syndicate_is_skip', false, $item, $updated, $set_post_id, $post_id ); |
|
165 | - if ( $is_skip ) { |
|
164 | + $is_skip = apply_filters('wp_syndicate_is_skip', false, $item, $updated, $set_post_id, $post_id); |
|
165 | + if ($is_skip) { |
|
166 | 166 | continue; |
167 | 167 | } |
168 | 168 | |
169 | 169 | $post_args = array( |
170 | 170 | 'ID' => $set_post_id, |
171 | 171 | 'post_name' => $slug, |
172 | - 'post_date' => apply_filters( 'wp_syndicate_get_date', $item->get_date('Y/m/d H:i:s'), $post_id ), |
|
173 | - 'post_title' => apply_filters( 'wp_syndicate_get_title', $item->get_title(), $post_id ), |
|
172 | + 'post_date' => apply_filters('wp_syndicate_get_date', $item->get_date('Y/m/d H:i:s'), $post_id), |
|
173 | + 'post_title' => apply_filters('wp_syndicate_get_title', $item->get_title(), $post_id), |
|
174 | 174 | 'post_content' => '', |
175 | 175 | ); |
176 | - if ( !$updated ) { |
|
177 | - $post_args['post_author'] = get_post_meta( $post_id, 'wp_syndicate-author-id', true ); |
|
178 | - $post_args['post_status'] = get_post_meta( $post_id, 'wp_syndicate-default-post-status', true ); |
|
179 | - $post_args['post_type'] = get_post_meta( $post_id, 'wp_syndicate-default-post-type', true ); |
|
176 | + if (!$updated) { |
|
177 | + $post_args['post_author'] = get_post_meta($post_id, 'wp_syndicate-author-id', true); |
|
178 | + $post_args['post_status'] = get_post_meta($post_id, 'wp_syndicate-default-post-status', true); |
|
179 | + $post_args['post_type'] = get_post_meta($post_id, 'wp_syndicate-default-post-type', true); |
|
180 | 180 | } |
181 | 181 | $this->post = new wp_post_helper($post_args); |
182 | 182 | |
183 | 183 | //画像の登録 |
184 | - if ( $updated ) { |
|
185 | - $images = get_attached_media( 'image', $set_post_id ); |
|
186 | - if ( is_array( $images ) ) { |
|
187 | - foreach ( $images as $image ) { |
|
188 | - wp_delete_attachment( $image->ID ); |
|
184 | + if ($updated) { |
|
185 | + $images = get_attached_media('image', $set_post_id); |
|
186 | + if (is_array($images)) { |
|
187 | + foreach ($images as $image) { |
|
188 | + wp_delete_attachment($image->ID); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | - $content = apply_filters( 'the_content', $item->get_content() ); |
|
194 | - if ( $item->get_enclosure() && !empty($item->get_enclosure()->link) ) { |
|
193 | + $content = apply_filters('the_content', $item->get_content()); |
|
194 | + if ($item->get_enclosure() && !empty($item->get_enclosure()->link)) { |
|
195 | 195 | $this->is_enclosure = true; |
196 | - $this->set_enclosure( $item->get_enclosure()->link ); |
|
196 | + $this->set_enclosure($item->get_enclosure()->link); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | $this->match_count = 0; |
200 | - $content = preg_replace_callback( '#<img([^>]*)src=["\']([^"\']+)["\']([^>]*)>#i', array($this, 'update_link'), $content, -1 ); |
|
200 | + $content = preg_replace_callback('#<img([^>]*)src=["\']([^"\']+)["\']([^>]*)>#i', array($this, 'update_link'), $content, -1); |
|
201 | 201 | $this->match_count = 0; |
202 | 202 | $this->post->set(array( |
203 | - 'post_content' => apply_filters( 'wp_syndicate_get_content', $content, $post_id ) |
|
203 | + 'post_content' => apply_filters('wp_syndicate_get_content', $content, $post_id) |
|
204 | 204 | )); |
205 | - $this->post->add_meta( 'wp_syndicate-origin-of-syndication-slug', $post->post_name, true ); |
|
206 | - $this->post->add_meta( 'wp_syndicate-origin-of-syndication-siteurl', $this->host, true ); |
|
205 | + $this->post->add_meta('wp_syndicate-origin-of-syndication-slug', $post->post_name, true); |
|
206 | + $this->post->add_meta('wp_syndicate-origin-of-syndication-siteurl', $this->host, true); |
|
207 | 207 | |
208 | 208 | $update_post_id = $this->post->update(); |
209 | - if ( !$update_post_id ) { |
|
209 | + if (!$update_post_id) { |
|
210 | 210 | $flg = false; |
211 | 211 | } else { |
212 | - update_post_meta( $update_post_id, $slug, 1 ); |
|
213 | - do_action( 'wp_syndicate_save_post', $update_post_id, $item, $updated, $post_id ); |
|
212 | + update_post_meta($update_post_id, $slug, 1); |
|
213 | + do_action('wp_syndicate_save_post', $update_post_id, $item, $updated, $post_id); |
|
214 | 214 | $post_ids[] = $update_post_id; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - if ( $flg ) { |
|
219 | - $subject = '[' . get_bloginfo( 'name' ) . ']' . __( 'feed import success', WPSYND_DOMAIN ); |
|
220 | - $msg = __( 'feed URL:', WPSYND_DOMAIN ) . $feed_url . "\n"; |
|
221 | - $msg .= sprintf( __( 'Feed acquisition completion of %s', WPSYND_DOMAIN ), $post->post_name ) . "\n" . __( 'action time', WPSYND_DOMAIN ). ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
222 | - $msg .= __( 'below ID data updates', WPSYND_DOMAIN ) . "\n"; |
|
223 | - $msg .= implode( "\n", $post_ids ); |
|
224 | - WP_SYND_logger::get_instance()->success( $subject, $msg ); |
|
218 | + if ($flg) { |
|
219 | + $subject = '[' . get_bloginfo('name') . ']' . __('feed import success', WPSYND_DOMAIN); |
|
220 | + $msg = __('feed URL:', WPSYND_DOMAIN) . $feed_url . "\n"; |
|
221 | + $msg .= sprintf(__('Feed acquisition completion of %s', WPSYND_DOMAIN), $post->post_name) . "\n" . __('action time', WPSYND_DOMAIN) . ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
222 | + $msg .= __('below ID data updates', WPSYND_DOMAIN) . "\n"; |
|
223 | + $msg .= implode("\n", $post_ids); |
|
224 | + WP_SYND_logger::get_instance()->success($subject, $msg); |
|
225 | 225 | } else { |
226 | - $subject = '[' . get_bloginfo( 'name' ) . ']' . __( 'feed import failed', WPSYND_DOMAIN ); |
|
227 | - $msg = __( 'feed URL:', WPSYND_DOMAIN ) . $feed_url . "\n"; |
|
228 | - $msg .= sprintf( __( 'Failed to some data registration of %s', WPSYND_DOMAIN ), $post->post_name ) . "\n". __( 'action time', WPSYND_DOMAIN ). ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
229 | - $msg .= __( 'below ID data updates', WPSYND_DOMAIN ) . "\n"; |
|
230 | - $msg .= implode( "\n", $post_ids ); |
|
231 | - $error_post_id = WP_SYND_logger::get_instance()->error( $subject, $msg ); |
|
226 | + $subject = '[' . get_bloginfo('name') . ']' . __('feed import failed', WPSYND_DOMAIN); |
|
227 | + $msg = __('feed URL:', WPSYND_DOMAIN) . $feed_url . "\n"; |
|
228 | + $msg .= sprintf(__('Failed to some data registration of %s', WPSYND_DOMAIN), $post->post_name) . "\n" . __('action time', WPSYND_DOMAIN) . ':' . date_i18n('Y/m/d:H:i:s') . "\n\n\n"; |
|
229 | + $msg .= __('below ID data updates', WPSYND_DOMAIN) . "\n"; |
|
230 | + $msg .= implode("\n", $post_ids); |
|
231 | + $error_post_id = WP_SYND_logger::get_instance()->error($subject, $msg); |
|
232 | 232 | $msg .= admin_url('/post.php?post=' . $error_post_id . '&action=edit'); |
233 | - wp_mail( $options['error_mail'], $subject, $msg ); |
|
233 | + wp_mail($options['error_mail'], $subject, $msg); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | } |
237 | 237 | |
238 | - public function return_0( $seconds ) { |
|
238 | + public function return_0($seconds) { |
|
239 | 239 | return 0; |
240 | 240 | } |
241 | 241 | |
242 | - public function update_link( $matches ) { |
|
242 | + public function update_link($matches) { |
|
243 | 243 | |
244 | - if ( is_array($matches) && array_key_exists(2, $matches) && isset($this->post) && is_object($this->post) && is_a($this->post, 'wp_post_helper') ) { |
|
244 | + if (is_array($matches) && array_key_exists(2, $matches) && isset($this->post) && is_object($this->post) && is_a($this->post, 'wp_post_helper')) { |
|
245 | 245 | $args = array(); |
246 | - $user = get_post_meta( $this->media_id, 'wp_syndicate-basic-auth-user', true ); |
|
247 | - $pass = get_post_meta( $this->media_id, 'wp_syndicate-basic-auth-pass', true ); |
|
248 | - if ( !empty($user) && !empty($pass) ) { |
|
246 | + $user = get_post_meta($this->media_id, 'wp_syndicate-basic-auth-user', true); |
|
247 | + $pass = get_post_meta($this->media_id, 'wp_syndicate-basic-auth-pass', true); |
|
248 | + if (!empty($user) && !empty($pass)) { |
|
249 | 249 | $args = array( |
250 | - 'headers' => array( 'Authorization' => 'Basic ' . base64_encode( $user . ':' . $pass ) ) |
|
250 | + 'headers' => array('Authorization' => 'Basic ' . base64_encode($user . ':' . $pass)) |
|
251 | 251 | ); |
252 | 252 | } |
253 | 253 | |
254 | 254 | $args['timeout'] = 30; |
255 | - if ( $media = remote_get_file($matches[2], '', $args) ) { |
|
255 | + if ($media = remote_get_file($matches[2], '', $args)) { |
|
256 | 256 | |
257 | - if ( $this->is_enclosure === true ) { |
|
257 | + if ($this->is_enclosure === true) { |
|
258 | 258 | $thumnail_flg = false; |
259 | 259 | } else { |
260 | 260 | $thumnail_flg = $this->match_count > 0 ? false : true; |
261 | 261 | } |
262 | 262 | |
263 | - $url = preg_split( '/wp-content/', $media ); |
|
264 | - $url = home_url( 'wp-content' . $url[1] ); |
|
263 | + $url = preg_split('/wp-content/', $media); |
|
264 | + $url = home_url('wp-content' . $url[1]); |
|
265 | 265 | |
266 | - if ( $url == $this->enclosure_url ) { |
|
266 | + if ($url == $this->enclosure_url) { |
|
267 | 267 | $thumnail_flg = true; |
268 | 268 | } |
269 | 269 | |
270 | 270 | $this->post->add_media($media, '', '', '', $thumnail_flg); |
271 | 271 | $this->match_count++; |
272 | 272 | |
273 | - return apply_filters( 'wp_syndicate_return_img', '<img' . $matches[1] . 'src="' . $url . '"' . $matches[3] . '>', $thumnail_flg, $url, $this->enclosure_url, $this->match_count ); |
|
273 | + return apply_filters('wp_syndicate_return_img', '<img' . $matches[1] . 'src="' . $url . '"' . $matches[3] . '>', $thumnail_flg, $url, $this->enclosure_url, $this->match_count); |
|
274 | 274 | } else { |
275 | 275 | return $matches[0]; |
276 | 276 | } |
@@ -279,21 +279,21 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | public function set_enclosure($link) { |
282 | - if ( !empty($link) && is_object($this->post) && is_a($this->post, 'wp_post_helper') ) { |
|
282 | + if (!empty($link) && is_object($this->post) && is_a($this->post, 'wp_post_helper')) { |
|
283 | 283 | $args = array(); |
284 | - $user = get_post_meta( $this->media_id, 'wp_syndicate-basic-auth-user', true ); |
|
285 | - $pass = get_post_meta( $this->media_id, 'wp_syndicate-basic-auth-pass', true ); |
|
286 | - if ( !empty($user) && !empty($pass) ) { |
|
284 | + $user = get_post_meta($this->media_id, 'wp_syndicate-basic-auth-user', true); |
|
285 | + $pass = get_post_meta($this->media_id, 'wp_syndicate-basic-auth-pass', true); |
|
286 | + if (!empty($user) && !empty($pass)) { |
|
287 | 287 | $args = array( |
288 | - 'headers' => array( 'Authorization' => 'Basic ' . base64_encode( $user . ':' . $pass ) ) |
|
288 | + 'headers' => array('Authorization' => 'Basic ' . base64_encode($user . ':' . $pass)) |
|
289 | 289 | ); |
290 | 290 | } |
291 | 291 | |
292 | 292 | $args['timeout'] = 30; |
293 | - if ( $media = remote_get_file($link, '', $args) ) { |
|
293 | + if ($media = remote_get_file($link, '', $args)) { |
|
294 | 294 | $this->post->add_media($media, '', '', '', true); |
295 | - $url = preg_split( '/wp-content/', $media ); |
|
296 | - $url = home_url( 'wp-content' . $url[1] ); |
|
295 | + $url = preg_split('/wp-content/', $media); |
|
296 | + $url = home_url('wp-content' . $url[1]); |
|
297 | 297 | $this->enclosure_url = $url; |
298 | 298 | } |
299 | 299 | } |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | class WP_SYNDICATE { |
3 | 3 | |
4 | 4 | public function __construct() { |
5 | - add_action( 'init', array( $this, 'init' ) ); |
|
6 | - add_action( 'save_post', array( $this, 'save_meta_box' ) ); |
|
5 | + add_action('init', array($this, 'init')); |
|
6 | + add_action('save_post', array($this, 'save_meta_box')); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | public function init() { |
@@ -23,114 +23,114 @@ discard block |
||
23 | 23 | 'edit_published_wp_syndicates', |
24 | 24 | ); |
25 | 25 | |
26 | - $role = get_role( 'administrator' ); |
|
27 | - foreach ( $capabilities as $cap ) { |
|
28 | - $role->add_cap( $cap ); |
|
26 | + $role = get_role('administrator'); |
|
27 | + foreach ($capabilities as $cap) { |
|
28 | + $role->add_cap($cap); |
|
29 | 29 | } |
30 | - register_post_type( 'wp-syndicate', |
|
30 | + register_post_type('wp-syndicate', |
|
31 | 31 | array( |
32 | - 'labels' => array( 'name' => __( 'Syndication', WPSYND_DOMAIN ) ), |
|
32 | + 'labels' => array('name' => __('Syndication', WPSYND_DOMAIN)), |
|
33 | 33 | 'public' => true, |
34 | 34 | 'publicly_queryable' => false, |
35 | 35 | 'has_archive' => false, |
36 | 36 | 'hierarchical' => false, |
37 | - 'supports' => array( 'title' ), |
|
37 | + 'supports' => array('title'), |
|
38 | 38 | 'rewrite' => false, |
39 | 39 | 'can_export' => true, |
40 | 40 | 'menu_position' => 28, |
41 | 41 | 'capability_type' => 'wp_syndicate', |
42 | 42 | 'capabilities' => $capabilities, |
43 | 43 | 'map_meta_cap' => true, |
44 | - 'register_meta_box_cb' => array( $this, 'add_meta_box' ), |
|
44 | + 'register_meta_box_cb' => array($this, 'add_meta_box'), |
|
45 | 45 | )); |
46 | 46 | } |
47 | 47 | |
48 | 48 | public function add_meta_box() { |
49 | 49 | global $hook_suffix; |
50 | 50 | |
51 | - add_meta_box( 'wp_syndicate_meta_box', __( 'configuration', WPSYND_DOMAIN ), array( $this, 'meta_box_wp_syndicate' ),'wp-syndicate' ); |
|
52 | - if ( 'post.php' === $hook_suffix ) { |
|
53 | - add_meta_box( 'wp_syndicate_meta_box_import_test', __( 'Import Test', WPSYND_DOMAIN ), array( $this, 'meta_box_wp_syndicate_import_test' ),'wp-syndicate' ); |
|
51 | + add_meta_box('wp_syndicate_meta_box', __('configuration', WPSYND_DOMAIN), array($this, 'meta_box_wp_syndicate'), 'wp-syndicate'); |
|
52 | + if ('post.php' === $hook_suffix) { |
|
53 | + add_meta_box('wp_syndicate_meta_box_import_test', __('Import Test', WPSYND_DOMAIN), array($this, 'meta_box_wp_syndicate_import_test'), 'wp-syndicate'); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | 57 | public function meta_box_wp_syndicate() { |
58 | - wp_nonce_field( 'wp_syndicate_meta_box', 'wp_syndicate_meta_box_nonce' ); |
|
58 | + wp_nonce_field('wp_syndicate_meta_box', 'wp_syndicate_meta_box_nonce'); |
|
59 | 59 | |
60 | - $feed_url = get_post_meta( get_the_ID(), 'wp_syndicate-feed-url', true ); |
|
61 | - $feed_retrieve_term = get_post_meta( get_the_ID(), 'wp_syndicate-feed-retrieve-term', true ); |
|
62 | - $author_id = get_post_meta( get_the_ID(), 'wp_syndicate-author-id', true ); |
|
60 | + $feed_url = get_post_meta(get_the_ID(), 'wp_syndicate-feed-url', true); |
|
61 | + $feed_retrieve_term = get_post_meta(get_the_ID(), 'wp_syndicate-feed-retrieve-term', true); |
|
62 | + $author_id = get_post_meta(get_the_ID(), 'wp_syndicate-author-id', true); |
|
63 | 63 | $statuses = get_post_statuses(); |
64 | - unset( $statuses['pending'] ); |
|
65 | - $status = get_post_meta( get_the_ID(), 'wp_syndicate-default-post-status', true ); |
|
66 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
67 | - $post_type = get_post_meta( get_the_ID(), 'wp_syndicate-default-post-type', true ); |
|
68 | - $registration_method = get_post_meta( get_the_ID(), 'wp_syndicate-registration-method', true ); |
|
69 | - $user_id = get_post_meta( get_the_ID(), 'wp_syndicate-basic-auth-user', true ); |
|
70 | - $password = get_post_meta( get_the_ID(), 'wp_syndicate-basic-auth-pass', true ); |
|
64 | + unset($statuses['pending']); |
|
65 | + $status = get_post_meta(get_the_ID(), 'wp_syndicate-default-post-status', true); |
|
66 | + $post_types = get_post_types(array('public' => true)); |
|
67 | + $post_type = get_post_meta(get_the_ID(), 'wp_syndicate-default-post-type', true); |
|
68 | + $registration_method = get_post_meta(get_the_ID(), 'wp_syndicate-registration-method', true); |
|
69 | + $user_id = get_post_meta(get_the_ID(), 'wp_syndicate-basic-auth-user', true); |
|
70 | + $password = get_post_meta(get_the_ID(), 'wp_syndicate-basic-auth-pass', true); |
|
71 | 71 | |
72 | 72 | ?> |
73 | 73 | <table class="form-table"> |
74 | -<tr><th><?php esc_html_e( 'feed URL', WPSYND_DOMAIN ) ?></th><td><input type="text" name="wp_syndicate-feed-url" size="40" value="<?php echo esc_attr( $feed_url ); ?>" /></td></tr> |
|
75 | -<tr><th><?php esc_html_e( 'feed retrieve term', WPSYND_DOMAIN ) ?></th><td><input type="number" step="1" min="1" max="999" name="wp_syndicate-feed-retrieve-term" size="20" value="<?php echo esc_attr( $feed_retrieve_term ); ?>" /> <?php esc_html_e( 'min', WPSYND_DOMAIN ) ?></td></tr> |
|
76 | -<tr><th><?php esc_html_e( 'Author ID', WPSYND_DOMAIN ) ?></th><td><input type="text" name="wp_syndicate-author-id" size="7" value="<?php echo esc_attr( $author_id ); ?>" /></td></tr> |
|
77 | -<tr><th><?php esc_html_e( 'Default Post Type', WPSYND_DOMAIN ) ?></th> |
|
74 | +<tr><th><?php esc_html_e('feed URL', WPSYND_DOMAIN) ?></th><td><input type="text" name="wp_syndicate-feed-url" size="40" value="<?php echo esc_attr($feed_url); ?>" /></td></tr> |
|
75 | +<tr><th><?php esc_html_e('feed retrieve term', WPSYND_DOMAIN) ?></th><td><input type="number" step="1" min="1" max="999" name="wp_syndicate-feed-retrieve-term" size="20" value="<?php echo esc_attr($feed_retrieve_term); ?>" /> <?php esc_html_e('min', WPSYND_DOMAIN) ?></td></tr> |
|
76 | +<tr><th><?php esc_html_e('Author ID', WPSYND_DOMAIN) ?></th><td><input type="text" name="wp_syndicate-author-id" size="7" value="<?php echo esc_attr($author_id); ?>" /></td></tr> |
|
77 | +<tr><th><?php esc_html_e('Default Post Type', WPSYND_DOMAIN) ?></th> |
|
78 | 78 | <td> |
79 | 79 | <select name="wp_syndicate-default-post-type"> |
80 | -<?php foreach ( $post_types as $key => $val ) : ?> |
|
81 | - <option <?php selected( $post_type, $key ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $val ); ?></option> |
|
80 | +<?php foreach ($post_types as $key => $val) : ?> |
|
81 | + <option <?php selected($post_type, $key); ?> value="<?php echo esc_attr($key); ?>"><?php echo esc_attr($val); ?></option> |
|
82 | 82 | <?php endforeach; ?> |
83 | 83 | </select> |
84 | 84 | </td></tr> |
85 | -<tr><th><?php esc_html_e( 'Default Post Status', WPSYND_DOMAIN ) ?></th> |
|
85 | +<tr><th><?php esc_html_e('Default Post Status', WPSYND_DOMAIN) ?></th> |
|
86 | 86 | <td> |
87 | 87 | <select name="wp_syndicate-default-post-status"> |
88 | -<?php foreach ( $statuses as $key => $val ) : ?> |
|
89 | - <option <?php selected( $status, $key ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $val ); ?></option> |
|
88 | +<?php foreach ($statuses as $key => $val) : ?> |
|
89 | + <option <?php selected($status, $key); ?> value="<?php echo esc_attr($key); ?>"><?php echo esc_attr($val); ?></option> |
|
90 | 90 | <?php endforeach; ?> |
91 | 91 | </select> |
92 | 92 | </td></tr> |
93 | -<tr><th><?php esc_html_e( 'Registration method', WPSYND_DOMAIN ) ?></th> |
|
93 | +<tr><th><?php esc_html_e('Registration method', WPSYND_DOMAIN) ?></th> |
|
94 | 94 | <td> |
95 | 95 | <select name="wp_syndicate-registration-method"> |
96 | - <option <?php selected( $registration_method, 'insert' ); ?> value="insert">insert only</option> |
|
97 | - <option <?php selected( $registration_method, 'insert-or-update' ); ?> value="insert-or-update">insert or update</option> |
|
96 | + <option <?php selected($registration_method, 'insert'); ?> value="insert">insert only</option> |
|
97 | + <option <?php selected($registration_method, 'insert-or-update'); ?> value="insert-or-update">insert or update</option> |
|
98 | 98 | </select> |
99 | 99 | </td></tr> |
100 | -<tr><th><?php esc_html_e( 'Basic Auth User ID', WPSYND_DOMAIN ) ?></th><td><input type="text" name="wp_syndicate-basic-auth-user" size="40" value="<?php echo esc_attr( $user_id ); ?>" /></td></tr> |
|
101 | -<tr><th><?php esc_html_e( 'Basic Auth Password', WPSYND_DOMAIN ) ?></th><td><input type="password" name="wp_syndicate-basic-auth-pass" size="40" value="<?php echo esc_attr( $password ); ?>" /></td></tr> |
|
102 | -<?php do_action( 'wp_syndicate_add_metabox' ); ?> |
|
100 | +<tr><th><?php esc_html_e('Basic Auth User ID', WPSYND_DOMAIN) ?></th><td><input type="text" name="wp_syndicate-basic-auth-user" size="40" value="<?php echo esc_attr($user_id); ?>" /></td></tr> |
|
101 | +<tr><th><?php esc_html_e('Basic Auth Password', WPSYND_DOMAIN) ?></th><td><input type="password" name="wp_syndicate-basic-auth-pass" size="40" value="<?php echo esc_attr($password); ?>" /></td></tr> |
|
102 | +<?php do_action('wp_syndicate_add_metabox'); ?> |
|
103 | 103 | </table> |
104 | 104 | <?php |
105 | 105 | } |
106 | 106 | |
107 | 107 | public function meta_box_wp_syndicate_import_test($post) { |
108 | - submit_button( 'Save and Test Excute', 'primary', 'wp_syndicate_import_test_excute' ); |
|
108 | + submit_button('Save and Test Excute', 'primary', 'wp_syndicate_import_test_excute'); |
|
109 | 109 | } |
110 | 110 | |
111 | - public function save_meta_box( $post_id ) { |
|
112 | - if ( wp_is_post_revision( $post_id ) || get_post_type() !== 'wp-syndicate' || ! current_user_can( 'edit_wp_syndicate', $post_id ) |
|
113 | - || ! isset( $_POST['wp_syndicate_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wp_syndicate_meta_box_nonce'], 'wp_syndicate_meta_box' ) ) { |
|
111 | + public function save_meta_box($post_id) { |
|
112 | + if (wp_is_post_revision($post_id) || get_post_type() !== 'wp-syndicate' || !current_user_can('edit_wp_syndicate', $post_id) |
|
113 | + || !isset($_POST['wp_syndicate_meta_box_nonce']) || !wp_verify_nonce($_POST['wp_syndicate_meta_box_nonce'], 'wp_syndicate_meta_box')) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | - isset( $_POST['wp_syndicate-feed-url'] ) && update_post_meta( $post_id, 'wp_syndicate-feed-url', esc_url( $_POST['wp_syndicate-feed-url'] ) ); |
|
118 | - isset( $_POST['wp_syndicate-feed-retrieve-term'] ) && update_post_meta( $post_id, 'wp_syndicate-feed-retrieve-term', absint( $_POST['wp_syndicate-feed-retrieve-term'] ) ); |
|
119 | - isset( $_POST['wp_syndicate-author-id'] ) && update_post_meta( $post_id, 'wp_syndicate-author-id', absint( $_POST['wp_syndicate-author-id'] ) ); |
|
120 | - isset( $_POST['wp_syndicate-default-post-status'] ) && update_post_meta( $post_id, 'wp_syndicate-default-post-status', trim( $_POST['wp_syndicate-default-post-status'] ) ); |
|
121 | - isset( $_POST['wp_syndicate-default-post-type'] ) && update_post_meta( $post_id, 'wp_syndicate-default-post-type', trim( $_POST['wp_syndicate-default-post-type'] ) ); |
|
122 | - isset( $_POST['wp_syndicate-registration-method'] ) && update_post_meta( $post_id, 'wp_syndicate-registration-method', trim( $_POST['wp_syndicate-registration-method'] ) ); |
|
123 | - isset( $_POST['wp_syndicate-basic-auth-user'] ) && update_post_meta( $post_id, 'wp_syndicate-basic-auth-user', trim( $_POST['wp_syndicate-basic-auth-user'] ) ); |
|
124 | - isset( $_POST['wp_syndicate-basic-auth-pass'] ) && update_post_meta( $post_id, 'wp_syndicate-basic-auth-pass', trim( $_POST['wp_syndicate-basic-auth-pass'] ) ); |
|
117 | + isset($_POST['wp_syndicate-feed-url']) && update_post_meta($post_id, 'wp_syndicate-feed-url', esc_url($_POST['wp_syndicate-feed-url'])); |
|
118 | + isset($_POST['wp_syndicate-feed-retrieve-term']) && update_post_meta($post_id, 'wp_syndicate-feed-retrieve-term', absint($_POST['wp_syndicate-feed-retrieve-term'])); |
|
119 | + isset($_POST['wp_syndicate-author-id']) && update_post_meta($post_id, 'wp_syndicate-author-id', absint($_POST['wp_syndicate-author-id'])); |
|
120 | + isset($_POST['wp_syndicate-default-post-status']) && update_post_meta($post_id, 'wp_syndicate-default-post-status', trim($_POST['wp_syndicate-default-post-status'])); |
|
121 | + isset($_POST['wp_syndicate-default-post-type']) && update_post_meta($post_id, 'wp_syndicate-default-post-type', trim($_POST['wp_syndicate-default-post-type'])); |
|
122 | + isset($_POST['wp_syndicate-registration-method']) && update_post_meta($post_id, 'wp_syndicate-registration-method', trim($_POST['wp_syndicate-registration-method'])); |
|
123 | + isset($_POST['wp_syndicate-basic-auth-user']) && update_post_meta($post_id, 'wp_syndicate-basic-auth-user', trim($_POST['wp_syndicate-basic-auth-user'])); |
|
124 | + isset($_POST['wp_syndicate-basic-auth-pass']) && update_post_meta($post_id, 'wp_syndicate-basic-auth-pass', trim($_POST['wp_syndicate-basic-auth-pass'])); |
|
125 | 125 | |
126 | - if ( isset( $_POST['wp_syndicate_import_test_excute'] ) ) { |
|
127 | - remove_action( 'save_post', array( $this, 'save_meta_box' ) ); |
|
126 | + if (isset($_POST['wp_syndicate_import_test_excute'])) { |
|
127 | + remove_action('save_post', array($this, 'save_meta_box')); |
|
128 | 128 | $action = new WP_SYND_Action(); |
129 | - $action->import( $post_id ); |
|
130 | - add_action( 'save_post', array( $this, 'save_meta_box' ) ); |
|
129 | + $action->import($post_id); |
|
130 | + add_action('save_post', array($this, 'save_meta_box')); |
|
131 | 131 | } |
132 | 132 | |
133 | - do_action( 'wp_syndicate_save_meta_box', $post_id ); |
|
133 | + do_action('wp_syndicate_save_meta_box', $post_id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | new WP_SYNDICATE(); |