Favorite Countries

Added to 1.1.0.6 and only one code change required. - Favorite Countries

Added to 1.1.0.6 and only one code change required.

by 14Steve14 » Sat Jun 27, 2026 10:41 am

We added this to our 1.1.0.6 site and had a few errors with the ht_zipur_favorite_countries.php in the headertag folder. Not too sure if this is correctly coded, but we made it work.

Here is the one page of code

Code: Select all

<?php

    
/*
* $Id: ht_zipur_favorite_countries.php
* $Loc: /includes/modules/header_tags/
*
* Name: ZipurFavoriteCountries
* Version: 0.3.0
* Release Date: 10/31/2022
* Author: Preston Lord
* 	 phoenixaddons.com / @zipurman / plord@inetx.ca
*
* License: Released under the GNU General Public License
*
* Comments: Copyright (c) 2020: Preston Lord - @zipurman - Intricate Networks Inc.
* 
* 
*   Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* 
*   1. Re-distributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 
*   2. Re-distributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* 
*   3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
* 
*   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* (Packaged with Zipur Bundler v0.2.3)
*/


class ht_zipur_favorite_countries extends abstract_module {
    const CONFIG_KEY_BASE = 'MODULE_CUSTOMER_DATA_ZIPUR_FAVORITE_COUNTRIES_';

    private $pages_to_load = [
        'create_account.php',
        'address_book.php',
        'checkout_new_address.php',
        'address_book_process.php',
    ];

    public function __construct() {
        parent::__construct( __FILE__ );
    }

    public function execute() {
        global $PHP_SELF;

        if ( in_array( basename( $PHP_SELF ), $this->pages_to_load ) || 1 == 1 ) {
            $countries = array_filter( array_map( 'trim', explode( ',', MODULE_CUSTOMER_DATA_ZIPUR_FAVORITE_COUNTRIES_TEXT ) ) );

            $countries_json = json_encode( array_values( $countries ) );

            $scripts = <<<js
<script>
document.addEventListener('DOMContentLoaded', function () {
    var favoriteCountries = {$countries_json};
    var select = document.getElementById('inputCountry');
    if (!select || favoriteCountries.length === 0) {
        return;
    }

    var existingOptions = select.innerHTML;

    var favoriteGroup = document.createElement('optgroup');
    favoriteGroup.label = '';
    favoriteGroup.className = 'zipoptgroup';

    favoriteCountries.forEach(function (countryName) {
        var match = null;
        for (var i = 0; i < select.options.length; i++) {
            if (select.options[i].text.trim() === countryName) {
                match = select.options[i];
                break;
            }
        }
        if (match) {
            var opt = document.createElement('option');
            opt.value = match.value;
            opt.text = countryName;
            favoriteGroup.appendChild(opt);
        }
    });

    if (favoriteGroup.children.length > 0) {
        var existingGroup = document.createElement('optgroup');
        existingGroup.label = '';
        existingGroup.className = 'zipoptgroup';
        existingGroup.innerHTML = existingOptions;

        select.innerHTML = '';
        select.appendChild(favoriteGroup);
        select.appendChild(existingGroup);
    }
});
</script>
js;

            $GLOBALS['Template']->add_block( $scripts, 'footer_scripts' );
        }
    }

    public function get_parameters() {
        return [
            'MODULE_CUSTOMER_DATA_ZIPUR_FAVORITE_COUNTRIES_STATUS' => [
                'title'    => 'Enable Information Links Footer Module',
                'value'    => 'True',
                'desc'     => 'Do you want to allow Zipur Header Messages to be added to the page header?',
                'set_func' => "Config::select_one(['True', 'False'], ",
            ],
            'MODULE_CUSTOMER_DATA_ZIPUR_FAVORITE_COUNTRIES_TEXT' => [
                'title' => 'Your Favorite Countries',
                'value' => '',
                'desc'  => 'Comma Delimted List Example: Canada,United States,Spain',
            ],
        ];
    }
}
14Steve14
Senior Contributor
Posts: 920
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Contact: