| @@ -523,12 +523,29 @@ | ||
| 523 | 523 | $validation['valid'] = false; |
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | + // The default Open Graph and Twitter images are checked in the field | |
| 528 | + // details above only while their feature is switched on, but they are | |
| 529 | + // stored (and shown in the admin preview's src) either way. | |
| 530 | + $flagged = []; | |
| 531 | + foreach ($field_details as $field) { | |
| 532 | + if ('error' === ($field['status'] ?? '')) { | |
| 533 | + $flagged[] = $field['field'] ?? ''; | |
| 534 | + } | |
| 535 | + } | |
| 536 | + foreach (['default_og_image' => 'Default Open Graph image', 'default_twitter_image' => 'Default Twitter Card image'] as $key => $label) { | |
| 537 | + if (!empty($settings[$key]) && !in_array($key, $flagged, true) | |
| 538 | + && !\ThinkRank\Core\Url_Validator::is_http_url($settings[$key])) { | |
| 539 | + $validation['errors'][] = $label . ' must be an http or https URL.'; | |
| 540 | + $validation['valid'] = false; | |
| 541 | + } | |
| 542 | + } | |
| 543 | + | |
| 527 | 544 | // Validate default image |
| 528 | 545 | if (isset($settings['default_image']) && !empty($settings['default_image'])) { |
| 529 | - if (!filter_var($settings['default_image'], FILTER_VALIDATE_URL)) { | |
| 530 | - $validation['errors'][] = 'default_image must be a valid URL'; | |
| 546 | + if (!\ThinkRank\Core\Url_Validator::is_http_url($settings['default_image'])) { | |
| 547 | + $validation['errors'][] = 'default_image must be an http or https URL'; | |
| 531 | 548 | $validation['valid'] = false; |
| 532 | 549 | } else { |
| 533 | 550 | // Check image dimensions and format |
| 534 | 551 | $image_validation = $this->validate_social_image($settings['default_image']); |
| @@ -766,9 +783,12 @@ | ||
| 766 | 783 | } |
| 767 | 784 | |
| 768 | 785 | // Default Image validation |
| 769 | 786 | if (!empty($settings['default_og_image'])) { |
| 770 | - if (filter_var($settings['default_og_image'], FILTER_VALIDATE_URL)) { | |
| 787 | + // http(s) only, and refused rather than warned about: the | |
| 788 | + // value becomes og:image and the admin preview's src, and a | |
| 789 | + // javascript: URL passed is_valid(). | |
| 790 | + if (\ThinkRank\Core\Url_Validator::is_http_url($settings['default_og_image'])) { | |
| 771 | 791 | $field_details[] = [ |
| 772 | 792 | 'field' => 'default_og_image', |
| 773 | 793 | 'label' => 'Default Open Graph image is configured.', |
| 774 | 794 | 'status' => 'valid', |
| @@ -776,11 +796,11 @@ | ||
| 776 | 796 | ]; |
| 777 | 797 | } else { |
| 778 | 798 | $field_details[] = [ |
| 779 | 799 | 'field' => 'default_og_image', |
| 780 | - 'label' => 'Default Open Graph image URL appears invalid.', | |
| 781 | - 'status' => 'warning', | |
| 782 | - 'icon' => '⚠' | |
| 800 | + 'label' => 'Default Open Graph image must be an http or https URL.', | |
| 801 | + 'status' => 'error', | |
| 802 | + 'icon' => '✗' | |
| 783 | 803 | ]; |
| 784 | 804 | } |
| 785 | 805 | } else { |
| 786 | 806 | $field_details[] = [ |
| @@ -900,9 +920,9 @@ | ||
| 900 | 920 | } |
| 901 | 921 | |
| 902 | 922 | // Default Twitter Image validation |
| 903 | 923 | if (!empty($settings['default_twitter_image'])) { |
| 904 | - if (filter_var($settings['default_twitter_image'], FILTER_VALIDATE_URL)) { | |
| 924 | + if (\ThinkRank\Core\Url_Validator::is_http_url($settings['default_twitter_image'])) { | |
| 905 | 925 | $field_details[] = [ |
| 906 | 926 | 'field' => 'default_twitter_image', |
| 907 | 927 | 'label' => 'Default Twitter Card image is configured.', |
| 908 | 928 | 'status' => 'valid', |
| @@ -910,11 +930,11 @@ | ||
| 910 | 930 | ]; |
| 911 | 931 | } else { |
| 912 | 932 | $field_details[] = [ |
| 913 | 933 | 'field' => 'default_twitter_image', |
| 914 | - 'label' => 'Default Twitter Card image URL appears invalid.', | |
| 915 | - 'status' => 'warning', | |
| 916 | - 'icon' => '⚠' | |
| 934 | + 'label' => 'Default Twitter Card image must be an http or https URL.', | |
| 935 | + 'status' => 'error', | |
| 936 | + 'icon' => '✗' | |
| 917 | 937 | ]; |
| 918 | 938 | } |
| 919 | 939 | } else { |
| 920 | 940 | $field_details[] = [ |
| @@ -3035,9 +3055,9 @@ | ||
| 3035 | 3055 | return $validation; |
| 3036 | 3056 | } |
| 3037 | 3057 | |
| 3038 | 3058 | // Check if URL is valid |
| 3039 | - if (!filter_var($image_url, FILTER_VALIDATE_URL)) { | |
| 3059 | + if (!\ThinkRank\Core\Url_Validator::is_http_url($image_url)) { | |
| 3040 | 3060 | $validation['warnings'][] = 'Invalid image URL'; |
| 3041 | 3061 | return $validation; |
| 3042 | 3062 | } |
| 3043 | 3063 | |