AJAX
5 months ago
Admin_Page
5 months ago
Click_Tracking
5 months ago
ColumnOptions
6 months ago
Cron
9 months ago
Custom_WordPress_Columns
8 months ago
Data_Pruning
5 months ago
Date_Picker
5 months ago
Date_Range
5 months ago
Ecommerce
5 months ago
Email_Reports
5 months ago
Examiner
11 months ago
Favicon
5 months ago
Form_Submissions
5 months ago
Integrations
6 months ago
Interval
1 year ago
Journey
5 months ago
Migrations
5 months ago
Models
5 months ago
Overview
5 months ago
Public_API
5 months ago
Rows
5 months ago
Statistics
5 months ago
Tables
5 months ago
Utils
5 months ago
Views
5 months ago
WooCommerceOrderMetaBox
5 months ago
Admin_Bar_Stats.php
5 months ago
Appearance.php
1 year ago
Campaign_Builder.php
5 months ago
Capability_Manager.php
1 year ago
Chart.php
9 months ago
Chart_Data.php
1 year ago
Click_Tracking.php
1 year ago
Cron_Job.php
5 months ago
Cron_Manager.php
5 months ago
Current_Traffic_Finder.php
1 year ago
Dashboard_Options.php
6 months ago
Dashboard_Widget.php
2 years ago
Database.php
8 months ago
Database_Manager.php
5 months ago
Empty_Report_Option.php
2 years ago
Env.php
6 months ago
Examiner_Config.php
11 months ago
FetchFaviconsJob.php
5 months ago
Filters.php
5 months ago
Geo_Database_Health_Check_Job.php
9 months ago
Geo_Database_Manager.php
6 months ago
Geoposition.php
1 year ago
Icon_Directory.php
6 months ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
10 months ago
Independent_Analytics.php
5 months ago
Interrupt.php
1 year ago
Known_Referrers.php
6 months ago
MainWP.php
1 year ago
Map.php
9 months ago
Map_Data.php
1 year ago
Migration_Fixer_Job.php
5 months ago
Patch.php
1 year ago
Payload_Validator.php
9 months ago
Plugin_Conflict_Detector.php
6 months ago
Plugin_Group.php
6 months ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
5 months ago
Quick_Stats.php
11 months ago
REST_API.php
6 months ago
Real_Time.php
5 months ago
Report.php
1 year ago
Report_Finder.php
6 months ago
Report_Options_Parser.php
9 months ago
Resource_Identifier.php
9 months ago
Settings.php
6 months ago
Sort_Configuration.php
9 months ago
Tables.php
8 months ago
Track_Resource_Changes.php
1 year ago
View_Counter.php
6 months ago
Views_Over_Time_Finder.php
1 year ago
VisitorSaltRefreshInterval.php
6 months ago
WP_Option_Cache_Bust.php
2 years ago
Payload_Validator.php
90 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Utils\Salt; |
| 6 | // TODO - Use this in REST_API and View |
| 7 | /** @internal */ |
| 8 | class Payload_Validator |
| 9 | { |
| 10 | private $payload; |
| 11 | private $signature; |
| 12 | private ?bool $is_valid = null; |
| 13 | public function __construct(string $payload, string $signature) |
| 14 | { |
| 15 | $this->payload = $payload; |
| 16 | $this->signature = $signature; |
| 17 | } |
| 18 | public function is_valid() : bool |
| 19 | { |
| 20 | if ($this->is_valid === null) { |
| 21 | $this->is_valid = $this->validate(); |
| 22 | } |
| 23 | return $this->is_valid; |
| 24 | } |
| 25 | public function payload() : ?array |
| 26 | { |
| 27 | if (!$this->is_valid()) { |
| 28 | return null; |
| 29 | } |
| 30 | return \json_decode($this->payload, \true); |
| 31 | } |
| 32 | public function resource() : ?array |
| 33 | { |
| 34 | if (!$this->is_valid()) { |
| 35 | return null; |
| 36 | } |
| 37 | $payload = $this->payload(); |
| 38 | $query = \IAWP\Illuminate_Builder::new()->from(\IAWP\Tables::resources())->where('resource', '=', $payload['resource']); |
| 39 | switch ($payload['resource']) { |
| 40 | case 'singular': |
| 41 | $query->where('singular_id', '=', $payload['singular_id']); |
| 42 | break; |
| 43 | case 'author_archive': |
| 44 | $query->where('author_id', '=', $payload['author_id']); |
| 45 | break; |
| 46 | case 'date_archive': |
| 47 | $query->where('date_archive', '=', $payload['date_archive']); |
| 48 | break; |
| 49 | case 'post_type_archive': |
| 50 | $query->where('post_type', '=', $payload['post_type']); |
| 51 | break; |
| 52 | case 'term_archive': |
| 53 | $query->where('term_id', '=', $payload['term_id']); |
| 54 | break; |
| 55 | case 'search': |
| 56 | $query->where('search_query', '=', $payload['search_query']); |
| 57 | break; |
| 58 | case 'home': |
| 59 | break; |
| 60 | case '404': |
| 61 | $query->where('not_found_url', '=', $payload['not_found_url']); |
| 62 | break; |
| 63 | case 'virtual_page': |
| 64 | $query->where('virtual_page_id', '=', $payload['virtual_page_id']); |
| 65 | break; |
| 66 | } |
| 67 | $row = $query->first(); |
| 68 | if (!\is_object($row)) { |
| 69 | return null; |
| 70 | } |
| 71 | return (array) $row; |
| 72 | } |
| 73 | private function validate() : bool |
| 74 | { |
| 75 | $signature = \md5(Salt::request_payload_salt() . $this->payload); |
| 76 | if ($signature !== $this->signature) { |
| 77 | return \false; |
| 78 | } |
| 79 | $decoded_payload = \json_decode($this->payload, \true); |
| 80 | if ($decoded_payload === null) { |
| 81 | return \false; |
| 82 | } |
| 83 | return \true; |
| 84 | } |
| 85 | public static function new(string $payload, string $signature) |
| 86 | { |
| 87 | return new self($payload, $signature); |
| 88 | } |
| 89 | } |
| 90 |