Changeset 2865959
- Timestamp:
- 02/15/2023 07:51:22 PM (3 years ago)
- Location:
- jane-menu/trunk
- Files:
-
- 1 deleted
- 7 edited
-
classes/StoreConfigs/Current_Store_Config.php (modified) (15 diffs)
-
classes/StoreConfigs/Table_List.php (modified) (12 diffs)
-
constants.php (modified) (6 diffs)
-
jane-menu.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
templates/sitemap-provider.php (deleted)
-
templates/store-config-list.php (modified) (2 diffs)
-
templates/store-menu.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jane-menu/trunk/classes/StoreConfigs/Current_Store_Config.php
r2854692 r2865959 3 3 * Core - Config 4 4 * 5 * @since 1.3.0 6 * 5 7 */ 6 8 … … 12 14 /** 13 15 * Everything related to the Store Config from the current URL request 16 * 17 * @since 1.3.0 18 * 14 19 */ 15 20 class Current_Store_Config{ … … 18 23 * The static instance will be saved here 19 24 * 25 * @since 1.3.0 26 * 20 27 * @var Current_Store_Config 21 28 */ … … 25 32 * ID of the current Store Config 26 33 * 34 * @since 1.3.0 35 * 27 36 * @var int|null Store Config ID if found, otherwise null 28 37 */ … … 32 41 * Store Config 33 42 * 43 * @since 1.3.0 44 * 34 45 * @var int|null Store Config, otherwise null 35 46 */ … … 39 50 * Template location for the current request 40 51 * 52 * @since 1.3.0 53 * 41 54 * @var string Full path 42 55 */ … … 44 57 45 58 /** 59 * Template response code 60 * 61 * @since 1.3.0 62 * 63 * @var int Response code like 200 or 404 64 */ 65 private $template_response_code = null; 66 67 /** 68 * Template content that should go into <head> 69 * 70 * @since 1.3.0 71 * 72 * @var array The content for the head 73 */ 74 private $template_head = []; 75 76 /** 77 * Template content that should go into <body> 78 * 79 * @since 1.3.0 80 * 81 * @var array The content for the body 82 */ 83 private $template_body = []; 84 85 86 /** 46 87 * Main constructor 47 88 * 48 89 * @uses IHeartJane\WebMenu\StoreConfigs\Current_Store_Config\_get_config_from_request_url() Current_Store_Config\_get_config_from_request_url() 90 * @uses IHeartJane\WebMenu\StoreConfigs\Current_Store_Config\_get_template_path() Current_Store_Config\_get_template_path() 91 * 92 * @since 1.3.0 49 93 * 50 94 * @return void … … 72 116 * Returns the singleton instance 73 117 * 118 * @since 1.3.0 119 * 74 120 * @return Current_Store_Config 75 121 */ … … 84 130 } 85 131 132 86 133 /** 87 134 * Gets the Store Config of the current request … … 90 137 * 91 138 * @uses IHeartJane\WebMenu\Constants\DB_TABLE_NAME Constants\DB_TABLE_NAME 139 * 140 * @since 1.3.0 92 141 * 93 142 * @return object|null Returns the Store Config if found, otherwise null … … 123 172 * The template can either be for the sitemap or the front end page. 124 173 * 125 * @uses IHeartJane\WebMenu\Constants\SITEMAP_FILE_NAME_BASE Constants\SITEMAP_FILE_NAME_BASE126 * @uses IHeartJane\WebMenu\Constants\SITEMAP_FILE_NAME_FULL Constants\SITEMAP_FILE_NAME_FULL127 174 * @uses IHeartJane\WebMenu\Constants\TEMPLATES_DIR Constants\TEMPLATES_DIR 175 * 176 * @uses IHeartJane\WebMenu\StoreConfigs\Current_Store_Config\_parse_template() Current_Store_Config\_parse_template() 177 * 178 * @since 1.3.0 179 * @since 1.3.2 The sitemap template processing was abandoned 128 180 * 129 181 * @return string Full path for the template file, empty string if no current Store Config … … 135 187 } 136 188 137 $base_names = [ 138 Constants\SITEMAP_FILE_NAME_BASE, 139 Constants\SITEMAP_FILE_NAME_FULL, 189 $this->_parse_template(); 190 191 return Constants\TEMPLATES_DIR . 'store-menu.php'; 192 } 193 194 /** 195 * Sets the template parts 196 * 197 * The template parts come from an external request and are parsed into head and body properties 198 * 199 * @uses IHeartJane\WebMenu\StoreConfigs\Current_Store_Config\_purge_head_html_elements() Current_Store_Config\_purge_head_html_elements() 200 * 201 * @see https://developer.wordpress.org/reference/classes/WP_Http/request/ 202 * 203 * @since 1.3.0 204 * 205 * @return void The results are saved in the class properties 206 */ 207 private function _parse_template(){ 208 209 $response = wp_safe_remote_get( $this->config->proxy_url, [ "timeout" => 30 ] ); 210 $html = wp_remote_retrieve_body( $response ); 211 212 $this->template_response_code = wp_remote_retrieve_response_code( $response ); 213 214 if( is_wp_error( $response ) || $this->template_response_code !== 200 ){ 215 return; 216 } 217 218 // Helpers\debug_log( $html, "Current_Store_Config-_get_templates_parts-html" ); 219 220 $this->template_head = $this->_get_html_child_elements( $html, 'head' ); 221 $this->template_body = $this->_get_html_child_elements( $html, 'body' ); 222 223 $this->_purge_head_html_elements(); 224 225 // Helpers\debug_log( $this->template_head, "Current_Store_Config-_get_templates_parts-template_head" ); 226 // Helpers\debug_log( $this->template_body, "Current_Store_Config-_get_templates_parts-template_body" ); 227 228 } 229 230 /** 231 * Gets the child elements of an HTML element as an array of strings 232 * 233 * @param string $html String of HTML code 234 * @param string $html_tag Parent element HTML tag 235 * 236 * @since 1.3.0 237 * 238 * @return string[] List of HTML elements 239 */ 240 private function _get_html_child_elements( $html, $html_tag = 'head' ){ 241 242 $elements = []; 243 244 $dom = new \DomDocument(); 245 @$dom->loadHTML( $html ); 246 247 $parent = $dom->getElementsByTagName( $html_tag )->item(0); 248 249 foreach( $parent->childNodes as $element ){ 250 251 $elements[] = $dom->saveHTML( $element ); 252 } 253 254 return $elements; 255 } 256 257 /** 258 * Removes unneeded HTML elements from the <head> 259 * 260 * @since 1.3.0 261 * 262 * @return void It just alters the $this->template_head property 263 */ 264 private function _purge_head_html_elements(){ 265 266 $search = [ 267 'charset="', 268 'http-equiv', 269 'name="viewport', 270 '<title', 271 'mobile-web-app-capable', 272 273 // TODO Do we need GTM? 274 'googletagmanager', 275 'window.dataLayer', 276 277 // TODO Do we need fonts? Seems the same without those, at least on the test site 278 // 'fonts.googleapis', 140 279 ]; 141 280 142 $template_name = in_array( basename( $_SERVER['REQUEST_URI'] ), $base_names ) ? 'sitemap-provider.php' : 'store-menu.php'; 143 144 return Constants\TEMPLATES_DIR . $template_name; 145 } 281 foreach( $this->template_head as $index => $element ){ 282 283 foreach( $search as $search_phrase ){ 284 285 if( strpos( $element, $search_phrase ) !== false ){ 286 287 unset( $this->template_head[ $index ] ); 288 break; 289 } 290 } 291 } 292 293 $this->template_head = array_values( $this->template_head ); 294 } 295 146 296 147 297 /** 148 298 * Returns the ID of the current Store Config 149 299 * 300 * @since 1.3.0 301 * 150 302 * @return int|null Store Config ID if found, otherwise null 151 303 */ … … 158 310 * Returns the current Store Config object 159 311 * 312 * @since 1.3.0 313 * 160 314 * @return object|null Store Config object, otherwise null 161 315 */ … … 166 320 167 321 /** 322 * Returns the current Store Config Page ID 323 * 324 * @since 1.3.0 325 * 326 * @return int|null Store Config Page ID, otherwise null 327 */ 328 public function get_page_id(){ 329 330 return ! empty( $this->config->page_id ) ? $this->config->page_id : null; 331 } 332 333 334 /** 168 335 * Returns the current template path if it will need to be replaced 169 336 * 337 * @since 1.3.0 338 * 170 339 * @return string Full path for the template file, empty string if no current Store Config 171 340 */ … … 175 344 } 176 345 346 /** 347 * Returns the current template response code 348 * 349 * @since 1.3.0 350 * 351 * @return int Response code like 200 or 404 352 */ 353 public function get_template_response_code(){ 354 355 return $this->template_response_code; 356 } 357 358 /** 359 * Returns the current template head elements for injection 360 * 361 * @since 1.3.0 362 * 363 * @return string HTML 364 */ 365 public function get_template_html_head(){ 366 367 return implode( PHP_EOL, $this->template_head ); 368 } 369 370 /** 371 * Returns the current template body elements for injection 372 * 373 * @since 1.3.0 374 * 375 * @return string HTML 376 */ 377 public function get_template_html_body(){ 378 379 return implode( PHP_EOL, $this->template_body ); 380 } 381 177 382 } -
jane-menu/trunk/classes/StoreConfigs/Table_List.php
r2854692 r2865959 6 6 namespace IHeartJane\WebMenu\StoreConfigs; 7 7 8 use IHeartJane\WebMenu\Sitemap; 8 9 use IHeartJane\WebMenu\Constants; 9 10 … … 19 20 /** 20 21 * Main constructor 22 * 23 * @since 1.0.0 21 24 * 22 25 * @return void … … 44 47 * Message to show if no designation found 45 48 * 49 * @since 1.0.0 50 * 46 51 * @return void 47 52 */ … … 57 62 * @param string $column_name 58 63 * 64 * @since 1.0.0 65 * @since 1.3.0 Added the Page column 66 * 59 67 * @return string 60 68 */ … … 84 92 * Gets the column names 85 93 * 94 * @since 1.0.0 95 * @since 1.3.0 Added the Page column 96 * 86 97 * @return array 87 98 */ … … 106 117 * @param object $item The item that we have in our row (Store Config) 107 118 * 119 * @since 1.0.0 120 * @since 1.3.0 The main column is the Page column 121 * 108 122 * @return string Item title and row actions HTML 109 123 */ … … 133 147 * Gets sortable columns 134 148 * 149 * @since 1.0.0 150 * 135 151 * @return array 136 152 */ … … 149 165 * Set the bulk actions 150 166 * 167 * @since 1.0.0 168 * 151 169 * @return array 152 170 */ … … 165 183 * @param object $item 166 184 * 185 * @since 1.0.0 186 * 167 187 * @return string 168 188 */ … … 179 199 * @uses IHeartJane\WebMenu\StoreConfigs\get_filtered_configs() StoreConfigs\get_filtered_configs() 180 200 * @uses IHeartJane\WebMenu\StoreConfigs\get_total_configs_count() StoreConfigs\get_total_configs_count() 201 * @uses IHeartJane\WebMenu\Sitemap\update_remote_sitemap() Sitemap\update_remote_sitemap() 202 * 203 * @since 1.0.0 204 * @since 1.3.2 Updates remote sitemap if anything is deleted 181 205 * 182 206 * @return void 183 207 */ 184 208 function prepare_items(){ 185 186 // delete 209 210 $delete = false; 211 212 // single delete 187 213 if( isset( $_GET['action'] ) && $_GET['page'] == Constants\ADMIN_PAGE_NAME && $_GET['action'] == "delete" ){ 188 214 … … 190 216 191 217 delete_config( [ $store_config_id ] ); 192 } 193 194 // bulk delete action 218 219 $delete = true; 220 } 221 222 // bulk delete 195 223 if( isset( $_POST['action'] ) && $_POST['page'] == Constants\ADMIN_PAGE_NAME && $_POST['action'] == "trash" ){ 196 224 … … 198 226 199 227 delete_config( $store_config_ids ); 200 } 228 229 $delete = true; 230 } 231 232 if( $delete ){ 233 234 Sitemap\update_remote_sitemap(); 235 } 236 201 237 202 238 $search = isset( $_REQUEST['s'] ) ? wp_unslash( trim( sanitize_text_field( $_REQUEST['s'] ) ) ) : ''; -
jane-menu/trunk/constants.php
r2854692 r2865959 8 8 * Store config list can be found there. 9 9 * 10 * @since 1.0.0 11 * 10 12 * @var string 11 13 */ … … 16 18 * The table is used to store the configs. 17 19 * 20 * @since 1.0.0 21 * 18 22 * @var string 19 23 */ … … 21 25 22 26 /** 23 * Base name for the sitemap file. 24 * Only the base name without the extension. 27 * Custom option name for the Sitemap Enabled option. 25 28 * 26 * @var string 27 */ 28 define( 'IHeartJane\WebMenu\Constants\SITEMAP_FILE_NAME_BASE', "sitemap" ); 29 30 /** 31 * Full name for the sitemap file. 32 * Base plus extension. 33 * 34 * @var string 35 */ 36 define( 'IHeartJane\WebMenu\Constants\SITEMAP_FILE_NAME_FULL', "sitemap.xml.gz" ); 37 38 /** 39 * Custom option name for the Sitemap Enabled option. 29 * @since 1.0.0 40 30 * 41 31 * @var string … … 47 37 * Has a trailing slash. 48 38 * 39 * @since 1.0.0 40 * 49 41 * @var string 50 42 */ … … 54 46 * Full path of the main plugin folder. 55 47 * Has a trailing slash. 48 * 49 * @since 1.0.0 56 50 * 57 51 * @var string … … 63 57 * Has a trailing slash. 64 58 * 59 * @since 1.3.0 60 * 65 61 * @var string 66 62 */ 67 63 define( 'IHeartJane\WebMenu\Constants\TEMPLATES_DIR', plugin_dir_path( __FILE__ ) . 'templates/' ); 64 65 /** 66 * Full URL of the remote sitemap. 67 * 68 * @since 1.3.2 69 * 70 * @var string 71 */ 72 define( 'IHeartJane\WebMenu\Constants\SITEMAP_URL', trailingslashit( wp_upload_dir()['baseurl'] ) . 'jane-menu/sitemap.xml' ); 73 74 /** 75 * Full path of the remote sitemap. 76 * 77 * @since 1.3.2 78 * 79 * @var string 80 */ 81 define( 'IHeartJane\WebMenu\Constants\SITEMAP_PATH', trailingslashit( wp_upload_dir()['basedir'] ) . 'jane-menu/sitemap.xml' ); 82 83 /** 84 * Full path of the remote sitemap folder. 85 * Has a trailing slash. 86 * 87 * @since 1.3.2 88 * 89 * @var string 90 */ 91 define( 'IHeartJane\WebMenu\Constants\SITEMAP_DIR', trailingslashit( wp_upload_dir()['basedir'] ) . 'jane-menu/' ); -
jane-menu/trunk/jane-menu.php
r2854692 r2865959 9 9 * Plugin URI: https://www.iheartjane.com/plugins/jane-menu-plugin 10 10 * Description: Dispensary manager to display partner product menu. 11 * Version: 1.3. 011 * Version: 1.3.2 12 12 * Requires at least: 5.9 13 13 * Requires PHP: 7.4 … … 23 23 * Saved in the database to be able to manually check if the table structure needs an update. 24 24 * 25 * @since 1.3.0 26 * 25 27 * @var string 26 28 */ 27 define( 'IHeartJane\WebMenu\Constants\PLUGIN_VER', "1.3. 0" );29 define( 'IHeartJane\WebMenu\Constants\PLUGIN_VER', "1.3.2" ); 28 30 29 31 /** 30 32 * The filename of the main plugin file including the path. 31 33 * Used for plugin activation/deactivation hooks. 34 * 35 * @since 1.3.0 32 36 * 33 37 * @var string -
jane-menu/trunk/readme.txt
r2854695 r2865959 2 2 Contributors: danaatiheartjane, andrija 3 3 Tags: jane, catalog, pos 4 Stable tag: 1.3. 04 Stable tag: 1.3.2 5 5 Requires at least: 5.9 6 6 Tested up to: 6.1.1 … … 19 19 20 20 This plugin allows our customers to easily deploy Jane menus into their websites 21 22 == Changelog == 23 24 = 1.3.2 = 25 * Added: Sitemap index with remote sitemap URLs generated in the uploads folder 26 * Added: The compatibility feature for Yoast where canonical URLs are not used on pages with store menus 27 * Fixed: The issue where sites with Elementor wouldn't display the menu 28 29 = 1.3.1 = 30 * Store menu gets injected into the existing page instead of overwriting it 31 * Shortcode [jane_menu_shortcode] introduced 32 33 = 1.3.0 = 34 * First published version on WordPress.org 35 * Old plugin rewritten from scratch with a new structure encapsulated in namespaces 36 * Store paths are defined by selecting and existing Page instead of custom relative paths -
jane-menu/trunk/templates/store-config-list.php
r2854692 r2865959 19 19 <table class="form-table"> 20 20 <tbody> 21 <tr class="row-store-id" >21 <tr class="row-store-id" style="display: none;"> 22 22 <th scope="row"> 23 23 <label for="menu_options"><?php _e( 'Menu Type', 'iheartjane' ); ?></label> … … 61 61 $list_table = new \IHeartJane\WebMenu\StoreConfigs\Table_List(); 62 62 $list_table->prepare_items(); 63 $list_table->search_box( ' search', 'search_id' );63 $list_table->search_box( 'Search', 'search_id' ); 64 64 $list_table->display(); 65 65 ?> -
jane-menu/trunk/templates/store-menu.php
r2854692 r2865959 9 9 global $jane__current_config; 10 10 11 $url = $jane__current_config->get_config()->proxy_url; 12 13 // For a full list of arguments, see: https://developer.wordpress.org/reference/classes/WP_Http/request/ 14 $args = [ 15 "timeout" => 30, 16 ]; 17 18 $response = wp_safe_remote_get( $url, $args ); 19 $body = wp_remote_retrieve_body( $response ); 20 $code = wp_remote_retrieve_response_code( $response ); 21 22 if( is_wp_error( $response ) || $code !== 200 ){ 11 if( $jane__current_config->get_template_response_code() !== 200 ){ 23 12 24 13 status_header( 404 ); … … 29 18 status_header( 200 ); 30 19 31 echo $body; 20 21 echo '<html>'; 22 echo '<head>'; 23 24 echo $jane__current_config->get_template_html_head(); 25 26 echo '</head>'; 27 echo '<body>'; 28 29 echo $jane__current_config->get_template_html_body(); 30 31 echo '</body>'; 32 echo '</html>'; 33 34
Note: See TracChangeset
for help on using the changeset viewer.