Plugin Directory

Changeset 2865959


Ignore:
Timestamp:
02/15/2023 07:51:22 PM (3 years ago)
Author:
andrija
Message:

v1.3.2

Location:
jane-menu/trunk
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • jane-menu/trunk/classes/StoreConfigs/Current_Store_Config.php

    r2854692 r2865959  
    33 * Core - Config
    44 *
     5 * @since    1.3.0
     6 *
    57 */
    68
     
    1214/**
    1315 * Everything related to the Store Config from the current URL request
     16 *
     17 * @since    1.3.0
     18 *
    1419 */
    1520class Current_Store_Config{
     
    1823     * The static instance will be saved here
    1924     *
     25     * @since    1.3.0
     26     *
    2027     * @var Current_Store_Config
    2128     */
     
    2532     * ID of the current Store Config
    2633     *
     34     * @since    1.3.0
     35     *
    2736     * @var int|null    Store Config ID if found, otherwise null
    2837     */
     
    3241     * Store Config
    3342     *
     43     * @since    1.3.0
     44     *
    3445     * @var int|null    Store Config, otherwise null
    3546     */
     
    3950     * Template location for the current request
    4051     *
     52     * @since    1.3.0
     53     *
    4154     * @var string      Full path
    4255     */
     
    4457   
    4558    /**
     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    /**
    4687     * Main constructor
    4788     *
    4889     * @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
    4993     *
    5094     * @return   void
     
    72116     * Returns the singleton instance
    73117     *
     118     * @since    1.3.0
     119     *
    74120     * @return   Current_Store_Config
    75121     */
     
    84130    }
    85131   
     132   
    86133    /**
    87134     * Gets the Store Config of the current request
     
    90137     *
    91138     * @uses     IHeartJane\WebMenu\Constants\DB_TABLE_NAME Constants\DB_TABLE_NAME
     139     *
     140     * @since    1.3.0
    92141     *
    93142     * @return   object|null     Returns the Store Config if found, otherwise null
     
    123172     * The template can either be for the sitemap or the front end page.
    124173     *
    125      * @uses     IHeartJane\WebMenu\Constants\SITEMAP_FILE_NAME_BASE    Constants\SITEMAP_FILE_NAME_BASE
    126      * @uses     IHeartJane\WebMenu\Constants\SITEMAP_FILE_NAME_FULL    Constants\SITEMAP_FILE_NAME_FULL
    127174     * @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
    128180     *
    129181     * @return   string     Full path for the template file, empty string if no current Store Config
     
    135187        }
    136188       
    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',
    140279        ];
    141280       
    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   
    146296   
    147297    /**
    148298     * Returns the ID of the current Store Config
    149299     *
     300     * @since    1.3.0
     301     *
    150302     * @return   int|null    Store Config ID if found, otherwise null
    151303     */
     
    158310     * Returns the current Store Config object
    159311     *
     312     * @since    1.3.0
     313     *
    160314     * @return   object|null    Store Config object, otherwise null
    161315     */
     
    166320   
    167321    /**
     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    /**
    168335     * Returns the current template path if it will need to be replaced
    169336     *
     337     * @since    1.3.0
     338     *
    170339     * @return   string     Full path for the template file, empty string if no current Store Config
    171340     */
     
    175344    }
    176345   
     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   
    177382}
  • jane-menu/trunk/classes/StoreConfigs/Table_List.php

    r2854692 r2865959  
    66namespace IHeartJane\WebMenu\StoreConfigs;
    77
     8use IHeartJane\WebMenu\Sitemap;
    89use IHeartJane\WebMenu\Constants;
    910
     
    1920    /**
    2021     * Main constructor
     22     *
     23     * @since    1.0.0
    2124     *
    2225     * @return   void
     
    4447     * Message to show if no designation found
    4548     *
     49     * @since    1.0.0
     50     *
    4651     * @return void
    4752     */
     
    5762     * @param  string  $column_name
    5863     *
     64     * @since    1.0.0
     65     * @since    1.3.0  Added the Page column
     66     *
    5967     * @return string
    6068     */
     
    8492     * Gets the column names
    8593     *
     94     * @since    1.0.0
     95     * @since    1.3.0  Added the Page column
     96     *
    8697     * @return array
    8798     */
     
    106117     * @param    object     $item   The item that we have in our row (Store Config)
    107118     *
     119     * @since    1.0.0
     120     * @since    1.3.0  The main column is the Page column
     121     *
    108122     * @return   string     Item title and row actions HTML
    109123     */
     
    133147     * Gets sortable columns
    134148     *
     149     * @since    1.0.0
     150     *
    135151     * @return array
    136152     */
     
    149165     * Set the bulk actions
    150166     *
     167     * @since    1.0.0
     168     *
    151169     * @return array
    152170     */
     
    165183     * @param  object  $item
    166184     *
     185     * @since    1.0.0
     186     *
    167187     * @return string
    168188     */
     
    179199     * @uses     IHeartJane\WebMenu\StoreConfigs\get_filtered_configs()     StoreConfigs\get_filtered_configs()
    180200     * @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
    181205     *
    182206     * @return void
    183207     */
    184208    function prepare_items(){
    185 
    186         // delete
     209       
     210        $delete = false;
     211
     212        // single delete
    187213        if( isset( $_GET['action'] ) && $_GET['page'] == Constants\ADMIN_PAGE_NAME && $_GET['action'] == "delete" ){
    188214           
     
    190216
    191217            delete_config( [ $store_config_id ] );
    192         }
    193 
    194         // bulk delete action
     218           
     219            $delete = true;
     220        }
     221
     222        // bulk delete
    195223        if( isset( $_POST['action'] ) && $_POST['page'] == Constants\ADMIN_PAGE_NAME && $_POST['action'] == "trash" ){
    196224           
     
    198226           
    199227            delete_config( $store_config_ids );
    200         }
     228           
     229            $delete = true;
     230        }
     231       
     232        if( $delete ){
     233           
     234            Sitemap\update_remote_sitemap();
     235        }
     236       
    201237       
    202238        $search = isset( $_REQUEST['s'] ) ? wp_unslash( trim( sanitize_text_field( $_REQUEST['s'] ) ) ) : '';
  • jane-menu/trunk/constants.php

    r2854692 r2865959  
    88 * Store config list can be found there.
    99 *
     10 * @since 1.0.0
     11 *
    1012 * @var string
    1113 */
     
    1618 * The table is used to store the configs.
    1719 *
     20 * @since 1.0.0
     21 *
    1822 * @var string
    1923 */
     
    2125
    2226/**
    23  * Base name for the sitemap file.
    24  * Only the base name without the extension.
     27 * Custom option name for the Sitemap Enabled option.
    2528 *
    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
    4030 *
    4131 * @var string
     
    4737 * Has a trailing slash.
    4838 *
     39 * @since 1.0.0
     40 *
    4941 * @var string
    5042 */
     
    5446 * Full path of the main plugin folder.
    5547 * Has a trailing slash.
     48 *
     49 * @since 1.0.0
    5650 *
    5751 * @var string
     
    6357 * Has a trailing slash.
    6458 *
     59 * @since 1.3.0
     60 *
    6561 * @var string
    6662 */
    6763define( '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 */
     72define( '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 */
     81define( '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 */
     91define( 'IHeartJane\WebMenu\Constants\SITEMAP_DIR', trailingslashit( wp_upload_dir()['basedir'] ) . 'jane-menu/' );
  • jane-menu/trunk/jane-menu.php

    r2854692 r2865959  
    99 * Plugin URI:          https://www.iheartjane.com/plugins/jane-menu-plugin
    1010 * Description:         Dispensary manager to display partner product menu.
    11  * Version:             1.3.0
     11 * Version:             1.3.2
    1212 * Requires at least:   5.9
    1313 * Requires PHP:        7.4
     
    2323 * Saved in the database to be able to manually check if the table structure needs an update.
    2424 *
     25 * @since 1.3.0
     26 *
    2527 * @var string
    2628 */
    27 define( 'IHeartJane\WebMenu\Constants\PLUGIN_VER', "1.3.0" );
     29define( 'IHeartJane\WebMenu\Constants\PLUGIN_VER', "1.3.2" );
    2830
    2931/**
    3032 * The filename of the main plugin file including the path.
    3133 * Used for plugin activation/deactivation hooks.
     34 *
     35 * @since 1.3.0
    3236 *
    3337 * @var string
  • jane-menu/trunk/readme.txt

    r2854695 r2865959  
    22Contributors: danaatiheartjane, andrija
    33Tags: jane, catalog, pos
    4 Stable tag: 1.3.0
     4Stable tag: 1.3.2
    55Requires at least: 5.9
    66Tested up to: 6.1.1
     
    1919
    2020This 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  
    1919            <table class="form-table">
    2020                <tbody>
    21                     <tr class="row-store-id">
     21                    <tr class="row-store-id" style="display: none;">
    2222                        <th scope="row">
    2323                            <label for="menu_options"><?php _e( 'Menu Type', 'iheartjane' ); ?></label>
     
    6161            $list_table = new \IHeartJane\WebMenu\StoreConfigs\Table_List();
    6262            $list_table->prepare_items();
    63             $list_table->search_box( 'search', 'search_id' );
     63            $list_table->search_box( 'Search', 'search_id' );
    6464            $list_table->display();
    6565        ?>
  • jane-menu/trunk/templates/store-menu.php

    r2854692 r2865959  
    99global $jane__current_config;
    1010
    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 ){
     11if( $jane__current_config->get_template_response_code() !== 200 ){
    2312   
    2413    status_header( 404 );
     
    2918status_header( 200 );
    3019
    31 echo $body;
     20
     21echo '<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>';
     32echo '</html>';
     33
     34
Note: See TracChangeset for help on using the changeset viewer.