| @@ -6,9 +6,8 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | declare( strict_types=1 ); |
| 9 | 9 | |
| 10 | - | |
| 11 | 10 | namespace Packetery\Module; |
| 12 | 11 | |
| 13 | 12 | use Packetery\Nette\Http\Request; |
| 14 | 13 | |
| @@ -40,15 +39,17 @@ | ||
| 40 | 39 | * |
| 41 | 40 | * @return bool |
| 42 | 41 | */ |
| 43 | 42 | public function isOrderGridPage(): bool { |
| 43 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 44 | 44 | global $pagenow, $typenow, $plugin_page; |
| 45 | 45 | |
| 46 | - if ( Helper::isHposEnabled() ) { | |
| 47 | - return 'admin.php' === $pagenow && 'wc-orders' === $plugin_page && false === in_array( $this->request->getQuery( 'action' ), [ 'edit', 'new' ], true ); | |
| 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; | |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - return 'edit.php' === $pagenow && 'shop_order' === $typenow; | |
| 51 | + return $pagenow === 'edit.php' && $typenow === 'shop_order'; | |
| 51 | 52 | } |
| 52 | 53 | |
| 53 | 54 | /** |
| 54 | 55 | * Tells if requesting user is at order detail page. |
| @@ -55,15 +56,17 @@ | ||
| 55 | 56 | * |
| 56 | 57 | * @return bool |
| 57 | 58 | */ |
| 58 | 59 | public function isOrderDetailPage(): bool { |
| 60 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 59 | 61 | global $pagenow, $typenow, $plugin_page; |
| 60 | 62 | |
| 61 | - if ( Helper::isHposEnabled() ) { | |
| 62 | - return 'admin.php' === $pagenow && 'wc-orders' === $plugin_page && 'edit' === $this->request->getQuery( 'action' ); | |
| 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'; | |
| 63 | 66 | } |
| 64 | 67 | |
| 65 | - return 'post.php' === $pagenow && 'shop_order' === $typenow; | |
| 68 | + return $pagenow === 'post.php' && $typenow === 'shop_order'; | |
| 66 | 69 | } |
| 67 | 70 | |
| 68 | 71 | /** |
| 69 | 72 | * Tells if requesting user is at product detail page. |
| @@ -72,9 +75,9 @@ | ||
| 72 | 75 | */ |
| 73 | 76 | private function isProductDetailPage(): bool { |
| 74 | 77 | global $pagenow, $typenow; |
| 75 | 78 | |
| 76 | - return 'post.php' === $pagenow && 'product' === $typenow; | |
| 79 | + return $pagenow === 'post.php' && $typenow === 'product'; | |
| 77 | 80 | } |
| 78 | 81 | |
| 79 | 82 | /** |
| 80 | 83 | * Tells if requesting user is at product create page. |
| @@ -83,9 +86,9 @@ | ||
| 83 | 86 | */ |
| 84 | 87 | private function isProductCreatePage(): bool { |
| 85 | 88 | global $pagenow, $typenow; |
| 86 | 89 | |
| 87 | - return 'post-new.php' === $pagenow && 'product' === $typenow; | |
| 90 | + return $pagenow === 'post-new.php' && $typenow === 'product'; | |
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | /** |
| 91 | 94 | * Tells if requesting user is at product page. |
| @@ -100,9 +103,9 @@ | ||
| 100 | 103 | * Tells if requesting user is at page using packetery confirm. |
| 101 | 104 | * |
| 102 | 105 | * @return bool |
| 103 | 106 | */ |
| 104 | - public function isPacketeryConfirmPage(): bool { | |
| 107 | + public function isConfirmModalPage(): bool { | |
| 105 | 108 | return $this->isOrderDetailPage() || $this->isOrderGridPage(); |
| 106 | 109 | } |
| 107 | 110 | |
| 108 | 111 | /** |
| @@ -112,9 +115,9 @@ | ||
| 112 | 115 | */ |
| 113 | 116 | public function isProductCategoryGridPage(): bool { |
| 114 | 117 | global $pagenow; |
| 115 | 118 | |
| 116 | - 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; | |
| 117 | 120 | } |
| 118 | 121 | |
| 119 | 122 | /** |
| 120 | 123 | * Tells if requesting user is at product category grid page. |
| @@ -123,7 +126,45 @@ | ||
| 123 | 126 | */ |
| 124 | 127 | public function isProductCategoryDetailPage(): bool { |
| 125 | 128 | global $pagenow; |
| 126 | 129 | |
| 127 | - 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'; | |
| 128 | 169 | } |
| 129 | 170 | } |