admin
2 weeks ago
core
5 days ago
class-activator.php
2 weeks ago
class-assets.php
2 months ago
class-builder-page.php
5 months ago
class-deactivator.php
3 years ago
class-debug-info.php
6 months ago
class-feed-ajax.php
1 year ago
class-feed-block.php
2 weeks ago
class-feed-deserializer.php
11 months ago
class-feed-old.php
4 years ago
class-feed-page.php
11 months ago
class-feed-serializer.php
9 months ago
class-feed-shortcode.php
2 years ago
class-feed-widget.php
8 months ago
class-plugin-overview-ajax.php
1 year ago
class-plugin-overview.php
5 months ago
class-plugin-settings.php
2 days ago
class-plugin-support.php
1 year ago
class-plugin.php
2 months ago
class-post-types.php
3 years ago
class-reviews-cron.php
1 year ago
class-settings-save.php
2 months ago
class-view.php
2 days ago
index.php
4 years ago
page-setting-advance.php
2 weeks ago
page-setting-fig.php
1 year ago
page-setting-support.php
4 years ago
class-feed-serializer.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes; |
| 4 | |
| 5 | class Feed_Serializer { |
| 6 | |
| 7 | public function __construct() { |
| 8 | add_action('admin_post_' . Post_Types::FEED_POST_TYPE . '_save', array($this, 'feed_save'), 30); |
| 9 | } |
| 10 | |
| 11 | public function feed_save() { |
| 12 | |
| 13 | $raw_data_array = $_POST[Post_Types::FEED_POST_TYPE]; |
| 14 | |
| 15 | $post_id = $this->save($raw_data_array['post_id'], $raw_data_array['title'], $raw_data_array['content']); |
| 16 | |
| 17 | // NOT: $referer = empty(wp_get_referer()) ? $raw_data_array['current_url'] : wp_get_referer(); |
| 18 | // COZ: Fatal error: Can't use function return value in write context in .../includes/class-feed-serializer.php on line ... |
| 19 | $referer = wp_get_referer(); |
| 20 | $referer = empty($referer) ? sanitize_text_field(wp_unslash($raw_data_array['current_url'])) : wp_get_referer(); |
| 21 | |
| 22 | wp_safe_redirect( |
| 23 | add_query_arg(array( |
| 24 | Post_Types::FEED_POST_TYPE . '_id' => $post_id, |
| 25 | ), $referer) |
| 26 | ); |
| 27 | exit; |
| 28 | } |
| 29 | |
| 30 | public function save($post_id, $title, $content) { |
| 31 | |
| 32 | if (!current_user_can('manage_options')) { |
| 33 | die('The account you\'re logged in to doesn\'t have permission to access this page.'); |
| 34 | } |
| 35 | |
| 36 | check_admin_referer('grw_wpnonce', 'grw_nonce'); |
| 37 | |
| 38 | $post_id = wp_insert_post(array( |
| 39 | 'ID' => sanitize_text_field(wp_unslash($post_id)), |
| 40 | 'post_title' => sanitize_text_field(wp_unslash($title)), |
| 41 | 'post_content' => $this->sanitize_json(wp_unslash($content)), |
| 42 | 'post_type' => Post_Types::FEED_POST_TYPE, |
| 43 | 'post_status' => 'publish', |
| 44 | )); |
| 45 | return $post_id; |
| 46 | } |
| 47 | |
| 48 | function sanitize_json($json) { |
| 49 | $arr = json_decode($json, true, 512, JSON_INVALID_UTF8_SUBSTITUTE); |
| 50 | if (json_last_error() !== JSON_ERROR_NONE) { |
| 51 | // TODO: log |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | $this->sanitize_json_recurs($arr); |
| 56 | return wp_json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
| 57 | } |
| 58 | |
| 59 | function sanitize_json_recurs(&$input) { |
| 60 | if (!is_array($input)) return; |
| 61 | |
| 62 | foreach ($input as $key => &$value) { |
| 63 | if (is_array($value)) { |
| 64 | $this->sanitize_json_recurs($value); |
| 65 | continue; |
| 66 | } |
| 67 | |
| 68 | if (is_string($key) && is_string($value)) { |
| 69 | if (stripos($key, 'url') !== false) { |
| 70 | $value = esc_url_raw($value); |
| 71 | } else { |
| 72 | $value = sanitize_textarea_field($value); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | unset($value); |
| 77 | } |
| 78 | } |
| 79 |