admin-toolbar.php
5 years ago
admin.php
3 years ago
cache.php
3 years ago
cdn.php
3 years ago
clearing-specific-pages.php
3 years ago
cli.php
3 years ago
column.php
6 years ago
css-utilities.php
3 years ago
index.html
11 years ago
js-utilities.php
3 years ago
preload.php
3 years ago
single-preload.php
3 years ago
wp-polls.php
9 years ago
clearing-specific-pages.php
114 lines
| 1 | <?php |
| 2 | class ClearingSpecificPagesWPFC{ |
| 3 | |
| 4 | public static function remove(){ |
| 5 | if(!wp_verify_nonce($_POST["security"], 'wpfc-save-csp-ajax-nonce')){ |
| 6 | die( 'Security check' ); |
| 7 | } |
| 8 | |
| 9 | $_POST["order"] = sanitize_text_field($_POST["order"]); |
| 10 | |
| 11 | $urls = get_option("WpFastestCacheCSP"); |
| 12 | |
| 13 | if(!empty($urls)){ |
| 14 | foreach ($urls as $key => $value) { |
| 15 | if($value->order == ($_POST["order"])){ |
| 16 | unset($urls[$key]); |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | if(empty($urls)){ |
| 22 | delete_option("WpFastestCacheCSP"); |
| 23 | }else{ |
| 24 | update_option("WpFastestCacheCSP", $urls, 1, "no"); |
| 25 | } |
| 26 | |
| 27 | wp_send_json_success(); |
| 28 | } |
| 29 | |
| 30 | public function check_url(){ |
| 31 | $home_url = parse_url(get_option("home"), PHP_URL_HOST); |
| 32 | $specific_url = parse_url($_POST["url"], PHP_URL_HOST); |
| 33 | |
| 34 | if($home_url == $specific_url){ |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | public function check_wild_card(){ |
| 42 | if(preg_match("/[^\/]\(\.\*\)/", $_POST["url"])){ |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | if(substr_count($_POST["url"], "(.*)") > 1){ |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | public static function save(){ |
| 54 | if(!wp_verify_nonce($_POST["security"], 'wpfc-save-csp-ajax-nonce')){ |
| 55 | die( 'Security check' ); |
| 56 | } |
| 57 | |
| 58 | if(!self::check_url()){ |
| 59 | wp_send_json_error("The URL must start with ".parse_url(get_option("home"), PHP_URL_SCHEME)."//".parse_url(get_option("home"), PHP_URL_HOST)); |
| 60 | } |
| 61 | |
| 62 | if(!self::check_wild_card()){ |
| 63 | wp_send_json_error("Wrong Wild Card Usage"); |
| 64 | } |
| 65 | |
| 66 | $_POST["url"] = sanitize_url($_POST["url"]); |
| 67 | $_POST["order"] = sanitize_text_field($_POST["order"]); |
| 68 | |
| 69 | $urls = get_option("WpFastestCacheCSP"); |
| 70 | $url = (object)array("url" => $_POST["url"], "order" => $_POST["order"]); |
| 71 | |
| 72 | if(!is_array($urls)){ |
| 73 | $urls = array(); |
| 74 | |
| 75 | array_push($urls, $url); |
| 76 | |
| 77 | add_option("WpFastestCacheCSP", $urls, 1, "no"); |
| 78 | }else{ |
| 79 | $is_update = false; |
| 80 | |
| 81 | foreach ($urls as $key => &$value) { |
| 82 | if($value->order == ($_POST["order"])){ |
| 83 | $is_update = true; |
| 84 | $value->url = $_POST["url"]; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if(!$is_update){ |
| 89 | array_push($urls, $url); |
| 90 | } |
| 91 | |
| 92 | update_option("WpFastestCacheCSP", $urls, 1, "no"); |
| 93 | } |
| 94 | |
| 95 | wp_send_json_success(); |
| 96 | } |
| 97 | |
| 98 | public static function get_list(){ |
| 99 | if(!wp_verify_nonce($_POST["security"], 'wpfc-save-csp-ajax-nonce')){ |
| 100 | die( 'Security check' ); |
| 101 | } |
| 102 | |
| 103 | $urls = get_option("WpFastestCacheCSP"); |
| 104 | |
| 105 | if(!is_array($urls)){ |
| 106 | $urls = array(); |
| 107 | } |
| 108 | |
| 109 | wp_send_json_success($urls); |
| 110 | |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | ?> |