Plugin Directory

Changeset 3440612


Ignore:
Timestamp:
01/15/2026 09:06:35 PM (2 months ago)
Author:
shipo
Message:

Changes to work with PHP 7.4+ version

Location:
shipo/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • shipo/trunk/assets/js/admin.js

    r3395057 r3440612  
    4747        var mapType = el.data('map-type');
    4848        var mapSlug = el.data('map-slug');
    49         // var mapCoord = '46.7725790000,23.5953730000';
    50         initMap(mapType, mapSlug);
     49        var mapCoord = el.data('map-coord');
     50
     51        initMapAdmin(mapType, mapSlug, mapCoord);
    5152    })
     53
     54    /**
     55     * Generate map from Shipo
     56     * @param {*} recipientType @param {*} recipientSlug @param {*} recipientCoord
     57     */
     58
     59    function initMapAdmin(recipientType, recipientSlug, recipientCoord) {
     60        jQuery('<iframe>', {
     61            id: 'mapFrame',
     62            src: '',
     63        }).appendTo('body').hide();
     64
     65        jQuery.ajax({
     66            url: shipoAjax.ajaxurl,
     67            method: 'POST',
     68            dataType: 'json',
     69            data: {
     70                action: 'shipo_get_map',
     71                recipient_slug: recipientSlug,
     72                recipient_type: recipientType,
     73                recipient_coord: recipientCoord,
     74                shipo_nonce: shipoAjax.nonce
     75            },
     76            success: function(response) {
     77                if (response.success) {
     78                    var mapUrl = response.data.url // Assuming response.data contains the map URL
     79                    jQuery("#mapFrame").attr("src", mapUrl);
     80                    jQuery("#mapFrame").show();
     81
     82                    // trimiteComandaCatreIframe();
     83                }
     84            }
     85        });
     86    }
    5287
    5388
  • shipo/trunk/assets/js/checkout.js

    r3415749 r3440612  
    1818        if (cityValue.length >= 3) {
    1919            $.ajax({
    20                 url: shipoAjax.ajaxurl,
     20                url: '/wp-json/shipo/v1/get-cities',
    2121                method: 'POST',
     22                dataType: 'json',
    2223                data: {
    23                     action: 'shipo_get_cities',
    2424                    city: cityValue,
    2525                    shipo_nonce: shipoAjax.nonce
     
    149149        if (streetValue.length >= 3) {
    150150            $.ajax({
    151                 url: shipoAjax.ajaxurl,
     151                url: '/wp-json/shipo/v1/get-address',
    152152                method: 'POST',
     153                dataType: 'json',
    153154                data: {
    154                     action: 'shipo_get_address',
    155155                    city: cityValue,
    156156                    address: streetValue,
  • shipo/trunk/assets/js/map.js

    r3404077 r3440612  
    1111
    1212    jQuery.ajax({
    13         url: shipoAjax.ajaxurl,
     13        url: '/wp-json/shipo/v1/get-map',
    1414        method: 'POST',
    1515        dataType: 'json',
    1616        data: {
    17             action: 'shipo_get_map',
    1817            recipient_slug: recipientSlug,
    1918            recipient_type: recipientType,
  • shipo/trunk/includes/class-shipo-ajax.php

    r3395057 r3440612  
    44 */
    55class Shipo_Ajax {
     6
     7    private static $instance = 'shipo';
     8
    69    /**
    710     * Constructor
    811     */
    912    public function __construct() {
    10         add_action('wp_ajax_shipo_get_cities', array($this, 'get_cities'));
    11         add_action('wp_ajax_nopriv_shipo_get_cities', array($this, 'get_cities'));
    12        
    13         add_action('wp_ajax_shipo_get_address', array($this, 'get_address'));
    14         add_action('wp_ajax_nopriv_shipo_get_address', array($this, 'get_address'));
    15        
    16         add_action('wp_ajax_shipo_get_map', array($this, 'get_map'));
    17         add_action('wp_ajax_nopriv_shipo_get_map', array($this, 'get_map'));
    18        
    19         add_action('wp_ajax_shipo_set_coord', array($this, 'set_coord'));
    20         add_action('wp_ajax_nopriv_shipo_set_coord', array($this, 'set_coord'));
     13        add_action('rest_api_init', array($this, 'register_rest_routes'));
    2114     
    2215        add_action('wp_ajax_shipo_generate_awb', array($this, 'generate_awb'));
    2316
     17        add_action('wp_ajax_shipo_get_map', array($this, 'get_map'));
     18
    2419        add_action('wp_ajax_shipo_report_awb', array($this, 'report_awb'));
    2520
    2621        add_action('wp_ajax_shipo_print_download_awb', array($this, 'print_download_awb'));
    2722    }
     23
     24    /**
     25     * Register REST routes for the plugin
     26     */
     27    public function register_rest_routes() {
     28        // Define route configuration with versioning support
     29        $routes = [
     30            'v1' => [
     31                '/get-cities' => [
     32                    'methods' => 'POST',
     33                    'callback' => [$this, 'get_cities'],
     34                    'permission_callback' => '__return_true',
     35                    'args' => [
     36                        'city' => [
     37                            'required' => true,
     38                            'sanitize_callback' => 'sanitize_text_field'
     39                        ],
     40                        'shipo_nonce' => [
     41                            'required' => true,
     42                            'sanitize_callback' => 'sanitize_text_field'
     43                        ]
     44                    ]
     45                ],
     46                '/get-address' => [
     47                    'methods' => 'POST',
     48                    'callback' => [$this, 'get_address'],
     49                    'permission_callback' => '__return_true',
     50                    'args' => [
     51                        'address' => [
     52                            'required' => true,
     53                            'sanitize_callback' => 'sanitize_text_field'
     54                        ],
     55                        'city' => [
     56                            'required' => true,
     57                            'sanitize_callback' => 'sanitize_text_field'
     58                        ],
     59                        'shipo_nonce' => [
     60                            'required' => true,
     61                            'sanitize_callback' => 'sanitize_text_field'
     62                        ]
     63                    ]
     64                ],
     65                '/get-map' => [
     66                    'methods' => 'POST',
     67                    'callback' => [$this, 'get_map'],
     68                    'permission_callback' => '__return_true',
     69                    'args' => [
     70                        'recipient_slug' => [
     71                            'required' => true,
     72                            'sanitize_callback' => 'sanitize_text_field'
     73                        ],
     74                        'recipient_type' => [
     75                            'required' => true,
     76                            'sanitize_callback' => 'sanitize_text_field'
     77                        ],
     78                        'recipient_coord' => [
     79                            'required' => true,
     80                            'sanitize_callback' => 'sanitize_text_field'
     81                        ],
     82                        'shipo_nonce' => [
     83                            'required' => true,
     84                            'sanitize_callback' => 'sanitize_text_field'
     85                        ]
     86                    ]
     87                ],
     88            ]
     89        ];
     90       
     91        // Register all routes, handling versions
     92        foreach ($routes as $version => $version_routes) {
     93            foreach ($version_routes as $route => $args) {
     94                $namespace = self::$instance . '/' . $version;
     95                register_rest_route($namespace, $route, $args);
     96            }
     97        }
     98    }
    2899   
    29100    /**
    30101     * Get cities
    31102     */
    32     public function get_cities() {
     103    public function get_cities() {       
    33104        // Checks nonce for security
    34105        if (!isset($_POST['shipo_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['shipo_nonce'])), 'shipo_nonce_action')) {
  • shipo/trunk/includes/class-shipo-settings-fields.php

    r3395057 r3440612  
    229229                        $html .= '</div>';
    230230                    }
     231
     232                    $coord = [44.9809810000, 26.0196120000];
    231233                   
    232234                    $html .= '</div>';
    233                     $html .= '<button class="button alt" type="button" data-map-type="locker" data-map-slug="' . esc_attr($courier_slug) . '" ' . ($courier_selected == 'disabled' ? 'disabled="disabled"' : '') . '>' . esc_html__('Select locker', 'shipo') . '</button>';
     235                    $html .= '<button '
     236                        . 'class="button alt" '
     237                        . 'type="button" '
     238                        . 'data-map-type="locker" '
     239                        . 'data-map-coord="' . implode(',', $coord) . '" '
     240                        . 'data-map-slug="' . esc_attr($courier_slug) . '" ' . ($courier_selected == 'disabled' ? 'disabled="disabled"' : '') . '>' . esc_html__('Select locker', 'shipo')
     241                        . '</button>';
    234242                    $html .= '</div>';
    235243                }
  • shipo/trunk/includes/class-shipo-wc-shipping.php

    r3415749 r3440612  
    103103                'data-map-type' => array(),
    104104                'data-map-slug' => array(),
     105                'data-map-coord' => array(),
    105106            ),
    106107            'img' => array(
  • shipo/trunk/readme.txt

    r3415749 r3440612  
    44Requires at least: 4.7
    55Tested up to: 6.9
    6 Stable tag: 1.4
    7 Requires PHP: 8.0
     6Stable tag: 1.5
     7Requires PHP: 7.4
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5959Checkout page improvements:
    6060- Allows users to manually enter a street name in the free text field if the street is not found in the suggestions dropdown list
     61
     62= 1.5 =
     63
     64- Changes have been made to ensure this version can run properly on PHP 7.4+, providing compatibility and stable performance in PHP 7.4+ environments.
  • shipo/trunk/shipo.php

    r3415749 r3440612  
    33 * Plugin Name: Shipo
    44 * Description: Shipo connects your webshop with top couriers instantly, no contract. Ship to address or locker, pay only when parcels are delivered.
    5  * Version: 1.4
     5 * Version: 1.5
    66 * Author: Shipo
    77 * Author URI: https://shipo.ro
     
    1616
    1717// Define plugin constants
    18 define('SHIPO_PLUGIN_VERSION', '1.4.0');
     18define('SHIPO_PLUGIN_VERSION', '1.5.0');
    1919define('SHIPO_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2020define('SHIPO_PLUGIN_URL', plugin_dir_url(__FILE__));
Note: See TracChangeset for help on using the changeset viewer.