| @@ -6,12 +6,11 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | declare( strict_types=1 ); |
| 9 | 9 | |
| 10 | - | |
| 11 | 10 | namespace Packetery\Module; |
| 12 | 11 | |
| 13 | -use PacketeryNette\Http\Request; | |
| 12 | +use Packetery\Nette\Http\Request; | |
| 14 | 13 | |
| 15 | 14 | /** |
| 16 | 15 | * Class ContextResolver. |
| 17 | 16 | * |
| @@ -40,11 +39,17 @@ | ||
| 40 | 39 | * |
| 41 | 40 | * @return bool |
| 42 | 41 | */ |
| 43 | 42 | public function isOrderGridPage(): bool { |
| 44 | - global $pagenow, $typenow; | |
| 43 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 44 | + global $pagenow, $typenow, $plugin_page; | |
| 45 | 45 | |
| 46 | - return 'edit.php' === $pagenow && 'shop_order' === $typenow; | |
| 46 | + if ( ModuleHelper::isHposEnabled() ) { | |
| 47 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 48 | + return $pagenow === 'admin.php' && $plugin_page === 'wc-orders' && in_array( $this->request->getQuery( 'action' ), [ 'edit', 'new' ], true ) === false; | |
| 49 | + } | |
| 50 | + | |
| 51 | + return $pagenow === 'edit.php' && $typenow === 'shop_order'; | |
| 47 | 52 | } |
| 48 | 53 | |
| 49 | 54 | /** |
| 50 | 55 | * Tells if requesting user is at order detail page. |
| @@ -51,11 +56,17 @@ | ||
| 51 | 56 | * |
| 52 | 57 | * @return bool |
| 53 | 58 | */ |
| 54 | 59 | public function isOrderDetailPage(): bool { |
| 55 | - global $pagenow, $typenow; | |
| 60 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 61 | + global $pagenow, $typenow, $plugin_page; | |
| 56 | 62 | |
| 57 | - return 'post.php' === $pagenow && 'shop_order' === $typenow; | |
| 63 | + if ( ModuleHelper::isHposEnabled() ) { | |
| 64 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 65 | + return $pagenow === 'admin.php' && $plugin_page === 'wc-orders' && $this->request->getQuery( 'action' ) === 'edit'; | |
| 66 | + } | |
| 67 | + | |
| 68 | + return $pagenow === 'post.php' && $typenow === 'shop_order'; | |
| 58 | 69 | } |
| 59 | 70 | |
| 60 | 71 | /** |
| 61 | 72 | * Tells if requesting user is at product detail page. |
| @@ -64,9 +75,9 @@ | ||
| 64 | 75 | */ |
| 65 | 76 | private function isProductDetailPage(): bool { |
| 66 | 77 | global $pagenow, $typenow; |
| 67 | 78 | |
| 68 | - return 'post.php' === $pagenow && 'product' === $typenow; | |
| 79 | + return $pagenow === 'post.php' && $typenow === 'product'; | |
| 69 | 80 | } |
| 70 | 81 | |
| 71 | 82 | /** |
| 72 | 83 | * Tells if requesting user is at product create page. |
| @@ -75,9 +86,9 @@ | ||
| 75 | 86 | */ |
| 76 | 87 | private function isProductCreatePage(): bool { |
| 77 | 88 | global $pagenow, $typenow; |
| 78 | 89 | |
| 79 | - return 'post-new.php' === $pagenow && 'product' === $typenow; | |
| 90 | + return $pagenow === 'post-new.php' && $typenow === 'product'; | |
| 80 | 91 | } |
| 81 | 92 | |
| 82 | 93 | /** |
| 83 | 94 | * Tells if requesting user is at product page. |
| @@ -92,9 +103,9 @@ | ||
| 92 | 103 | * Tells if requesting user is at page using packetery confirm. |
| 93 | 104 | * |
| 94 | 105 | * @return bool |
| 95 | 106 | */ |
| 96 | - public function isPacketeryConfirmPage(): bool { | |
| 107 | + public function isConfirmModalPage(): bool { | |
| 97 | 108 | return $this->isOrderDetailPage() || $this->isOrderGridPage(); |
| 98 | 109 | } |
| 99 | 110 | |
| 100 | 111 | /** |
| @@ -104,9 +115,9 @@ | ||
| 104 | 115 | */ |
| 105 | 116 | public function isProductCategoryGridPage(): bool { |
| 106 | 117 | global $pagenow; |
| 107 | 118 | |
| 108 | - return 'edit-tags.php' === $pagenow && ProductCategory\Entity::TAXONOMY_NAME === $this->request->getQuery( 'taxonomy' ); | |
| 119 | + return $pagenow === 'edit-tags.php' && $this->request->getQuery( 'taxonomy' ) === ProductCategory\Entity::TAXONOMY_NAME; | |
| 109 | 120 | } |
| 110 | 121 | |
| 111 | 122 | /** |
| 112 | 123 | * Tells if requesting user is at product category grid page. |
| @@ -115,7 +126,45 @@ | ||
| 115 | 126 | */ |
| 116 | 127 | public function isProductCategoryDetailPage(): bool { |
| 117 | 128 | global $pagenow; |
| 118 | 129 | |
| 119 | - return 'term.php' === $pagenow && ProductCategory\Entity::TAXONOMY_NAME === $this->request->getQuery( 'taxonomy' ); | |
| 130 | + return $pagenow === 'term.php' && $this->request->getQuery( 'taxonomy' ) === ProductCategory\Entity::TAXONOMY_NAME; | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Tells if user is at page detail. | |
| 135 | + * | |
| 136 | + * @return bool | |
| 137 | + */ | |
| 138 | + public function isPageDetail(): bool { | |
| 139 | + global $pagenow, $typenow; | |
| 140 | + | |
| 141 | + return $pagenow === 'post.php' && $typenow === 'page'; | |
| 142 | + } | |
| 143 | + | |
| 144 | + private function isShippingZoneDetailPage(): bool { | |
| 145 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 146 | + global $pagenow, $plugin_page; | |
| 147 | + | |
| 148 | + return ( | |
| 149 | + $pagenow === 'admin.php' && | |
| 150 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 151 | + $plugin_page === 'wc-settings' && | |
| 152 | + $this->request->getQuery( 'tab' ) === 'shipping' && | |
| 153 | + $this->request->getQuery( 'zone_id' ) > 0 | |
| 154 | + ); | |
| 155 | + } | |
| 156 | + | |
| 157 | + public function getShippingZoneId(): ?int { | |
| 158 | + if ( $this->isShippingZoneDetailPage() ) { | |
| 159 | + return (int) $this->request->getQuery( 'zone_id' ); | |
| 160 | + } | |
| 161 | + | |
| 162 | + return null; | |
| 163 | + } | |
| 164 | + | |
| 165 | + public function isPluginsOverviewPage(): bool { | |
| 166 | + global $pagenow; | |
| 167 | + | |
| 168 | + return $pagenow === 'plugins.php'; | |
| 120 | 169 | } |
| 121 | 170 | } |