Plugin Directory

Changeset 3166875


Ignore:
Timestamp:
10/11/2024 03:14:02 AM (18 months ago)
Author:
inspireui
Message:

version 4.15.5

Location:
mstore-api
Files:
487 added
9 edited

Legend:

Unmodified
Added
Removed
  • mstore-api/trunk/controllers/flutter-home.php

    r3132501 r3166875  
    149149
    150150            //get products for horizontal layout
    151             $countDataLayout = 0;
     151            $array['HorizonLayout'] = $this->getProductsForHorizonLayout($array["HorizonLayout"], $api, $request);
     152
     153            //get products for dynamic layout
     154            $tabBar = $array['TabBar'];
    152155            $results = [];
    153             $horizontalLayout = $array["HorizonLayout"];
    154             foreach ($horizontalLayout as $layout) {
    155                 if (in_array($layout['layout'], $this->supportedLayouts)) {
    156                     if($countDataLayout <  4){
    157                         $layout["data"] = $this->getProductsByLayout($layout, $api, $request);
    158                         $countDataLayout += 1;
    159                     }
    160                     $results[] = $layout;
    161                 } else {
    162                     if (isset($layout["items"]) && count($layout["items"]) > 0) {
    163                         $items = [];
    164                         foreach ($layout["items"] as $item) {
    165                             if($countDataLayout <  4 && array_key_exists('layout', $item) && in_array($item['layout'], $this->supportedLayouts)){
    166                                 $item["data"] = $this->getProductsByLayout($item, $api, $request);
    167                                 $countDataLayout += 1;
    168                             }
    169                            
    170                             $items[] = $item;
    171                         }
    172                         $layout["items"] = $items;
    173                     }
    174                     $results[] = $layout;
    175                 }
    176             }
    177             $array['HorizonLayout'] = $results;
     156            foreach ($tabBar as $tabBarItem) {
     157                if($tabBarItem['layout'] == 'dynamic' && isset($tabBarItem['configs']) && is_array($tabBarItem['configs']) && isset($tabBarItem['configs']['HorizonLayout'])){
     158                    $tabBarItem['configs']['HorizonLayout'] = $this->getProductsForHorizonLayout($tabBarItem['configs']['HorizonLayout'], $api, $request);
     159                }
     160                $results[] = $tabBarItem;
     161            }
     162            $array['TabBar'] = $results;
    178163
    179164            //get products for vertical layout
     
    196181            return new WP_Error("existed_config", "Config file hasn't been uploaded yet.", array('status' => 400));
    197182        }
     183    }
     184
     185    function getProductsForHorizonLayout($horizonLayout, $api, $request){
     186        $countDataLayout = 0;
     187        $results = [];
     188        foreach ($horizonLayout as $layout) {
     189            if (in_array($layout['layout'], $this->supportedLayouts)) {
     190                if($countDataLayout <  4){
     191                    $layout["data"] = $this->getProductsByLayout($layout, $api, $request);
     192                    $countDataLayout += 1;
     193                }
     194                $results[] = $layout;
     195            } else {
     196                if (isset($layout["items"]) && count($layout["items"]) > 0) {
     197                    $items = [];
     198                    foreach ($layout["items"] as $item) {
     199                        if($countDataLayout <  4 && array_key_exists('layout', $item) && in_array($item['layout'], $this->supportedLayouts)){
     200                            $item["data"] = $this->getProductsByLayout($item, $api, $request);
     201                            $countDataLayout += 1;
     202                        }
     203                        $items[] = $item;
     204                    }
     205                    $layout["items"] = $items;
     206                }
     207                $results[] = $layout;
     208            }
     209        }
     210        return $results;
    198211    }
    199212
  • mstore-api/trunk/controllers/flutter-order.php

    r3069976 r3166875  
    4747                    'methods' => WP_REST_Server::CREATABLE,
    4848                    'callback' => array($this, 'update_item'),
    49                     'permission_callback' => array($this, 'custom_create_item_permissions_check'),
     49                    'permission_callback' => array($this, 'custom_update_item_permissions_check'),
    5050                    'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
    5151                ),
     
    6767                    'methods' => WP_REST_Server::EDITABLE,
    6868                    'callback' => array($this, 'update_item'),
    69                     'permission_callback' => array($this, 'custom_create_item_permissions_check'),
     69                    'permission_callback' => array($this, 'custom_update_item_permissions_check'),
    7070                    'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
    7171                ),
     
    108108            wp_set_current_user($user_id);
    109109            $request->set_body_params($params);
     110            return true;
     111        } else {
     112            $params["customer_id"] = 0;
     113            $request->set_body_params($params);
     114            return true;
     115        }
     116    }
     117
     118    function custom_update_item_permissions_check($request)
     119    {
     120        $cookie = $request->get_header("User-Cookie");
     121        $json = file_get_contents('php://input');
     122        $params = json_decode($json, TRUE);
     123        if (isset($cookie) && $cookie != null) {
     124            $user_id = validateCookieLogin($cookie);
     125            if (is_wp_error($user_id)) {
     126                return false;
     127            }
    110128            return true;
    111129        } else {
  • mstore-api/trunk/controllers/flutter-review.php

    r3068729 r3166875  
    6666            }
    6767
    68             // GET USER ORDERS (COMPLETED + PROCESSING)
     68            if(isset($request['page']) && $request['page'] > 1){
     69                return [];
     70            }
     71
    6972            $customer_orders = wc_get_orders( array(
    7073                'limit' => -1,
    7174                'customer_id' => $user_id,
    72                 'status' => array_values( wc_get_is_paid_statuses() ),
     75                'status' => 'wc-completed',
    7376                'return' => 'ids',
    7477            ) );
  • mstore-api/trunk/controllers/flutter-woo.php

    r3147900 r3166875  
    12341234    public function create_product_review($request)
    12351235    {
     1236        //Validate review product for order
     1237        if(isset($request['comment_meta']) && is_array($request['comment_meta']) && $request['comment_meta']['order_id']){
     1238            $cookie = $request->get_header("User-Cookie");
     1239            if (isset($cookie) && $cookie != null) {
     1240                $user_id = validateCookieLogin($cookie);
     1241                if (is_wp_error($user_id)) {
     1242                    return $user_id;
     1243                }
     1244                $args = array(
     1245                    'id' => $request['comment_meta']['order_id'],
     1246                    'customer_id' => $user_id,
     1247                );
     1248                $orders = wc_get_orders( $args );
     1249                if (count($orders) == 0) {
     1250                    return parent::sendError("no_permission","You don't have the permissions to review this product", 400);
     1251                }
     1252            }else{
     1253                return parent::sendError("cookie_required","User-Cookie is required", 400);
     1254            }
     1255        }
     1256       
    12361257        $images = $request['images'];
    12371258        $controller = new WC_REST_Product_Reviews_Controller();
  • mstore-api/trunk/controllers/listing-rest-api/class.api.fields.php

    r3147900 r3166875  
    528528            $listing_type = $request['listing_type'] ?? 'place';
    529529            $bodyReq = ['proximity_units'=>'km','listing_type'=>$listing_type, 'form_data'=>[
    530                 'page'=>$offset / $limit,
    531                 'per_page'=>$limit,
    532530                'search_keywords'=>'',
    533531                'proximity'=>$radius,
     
    541539                ]
    542540            ];
     541            if(isset($request['per_page']) && $request['per_page'] != -1){
     542                $bodyReq['form_data']['page'] = $offset / $limit;
     543                $bodyReq['form_data']['per_page'] = $limit;
     544            }
    543545            $posts =  myListingExploreListings($bodyReq);
    544546            $items = (array)($posts);
     
    645647        $coupon = (isset($request['coupon'])) ? $request['coupon'] : false;
    646648        $services = (isset($request['services'])) ? $request['services'] : false;
    647 
     649        if (is_array($services) && count($services) > 0) {
     650            $services = array_map(function($item){
     651                return ['service' => sanitize_title($item['service']), 'value'=>$item['value']];
     652            }, $services);
     653        }
    648654        $data['price'] = Listeo_Core_Bookings_Calendar::calculate_price($request['listing_id'], $request['date_start'], $request['date_end'], $multiply, $services, '');
    649655        if (!empty($coupon))
     
    12271233
    12281234                        $block['type'] = $block->get_type();
     1235
     1236                        $valid = true;
    12291237                        switch ($block['type']) {
    12301238                            case 'gallery':
    1231                                 $field = $listing->get_field( $block['show_field'], true );
    1232                                 if(!$field){
     1239                                if ( ! ( $field = $listing->get_field_object( $block->get_prop( 'show_field' ) ) ) ) {
     1240                                    $valid = false;
    12331241                                    break;
    12341242                                }
     
    12361244                                break;
    12371245                            case 'text':
    1238                                 $field = $listing->get_field( $block['show_field'], true );
    1239                                 if(!$field){
     1246                                if ( ! ( $listing->has_field( $block->get_prop( 'show_field' ) ) ) ) {
     1247                                    $valid = false;
    12401248                                    break;
    12411249                                }
     1250                                $field = $listing->get_field( $block['show_field'], true );
    12421251                                $block['text'] = $field->get_value();
    12431252                                break;
    12441253                            case 'table':
    12451254                            case 'accordion':
    1246                                 $block['rows'] = $block->get_formatted_rows( $listing );
     1255                                $rows = $block->get_formatted_rows( $listing );
     1256                                if ( empty( $rows ) ) {
     1257                                    $valid = false;
     1258                                    break;
     1259                                }
     1260                                $block['rows'] = $rows;
    12471261                                break;
    12481262                            case 'tags':
    1249                                 $block['tags'] = $listing->get_field( 'tags' );
     1263                                $terms = $listing->get_field( 'tags' );
     1264                                if ( empty( $terms ) || is_wp_error( $terms ) ) {
     1265                                    $valid = false;
     1266                                    break;
     1267                                }
     1268                                $block['tags'] = $terms;
    12501269                                break;
    12511270                            case 'categories':
    1252                                 $block['categories'] = $listing->get_field( 'category' );
     1271                                $terms = $listing->get_field( 'category' );
     1272                                if ( empty( $terms ) || is_wp_error( $terms ) ) {
     1273                                    $valid = false;
     1274                                    break;
     1275                                }
     1276                                $block['categories'] = $terms;
    12531277                                break;
    12541278                            case 'author':
    12551279                                $author = $listing->get_author();
    12561280                                if ( ! ( $author instanceof \MyListing\Src\User && $author->exists() ) ) {
     1281                                    $valid = false;
    12571282                                    $block['author'] = null;
     1283                                    break;
    12581284                                }else{
    12591285                                    $avatar = get_user_meta($author->ID, 'user_avatar', true);
     
    12741300                                break;
    12751301                            case 'work_hours':
    1276                                 $block['work_hours'] = $listing->get_field( 'work_hours' ) ;
     1302                                $work_hours = $listing->get_field( 'work_hours' ) ;
     1303                                $schedule = new MyListing\Src\Work_Hours( $work_hours );
     1304                                if ( ! $work_hours || $schedule->is_empty() ) {
     1305                                    $valid = false;
     1306                                    break;
     1307                                }
     1308                                $block['work_hours'] = $work_hours ;
    12771309                                break;
    12781310                            case 'video':
    12791311                                $video_url = $listing->get_field( $block->get_prop( 'show_field' ) );
    1280                                 $block['video'] = \MyListing\Helpers::get_video_embed_details( $video_url );
     1312                                $video = \MyListing\Helpers::get_video_embed_details( $video_url );
     1313                                if ( ! ( $video_url && $video ) ) {
     1314                                    $valid = false;
     1315                                    break;
     1316                                }
     1317                                $block['video'] = $video;
    12811318                                break;
    12821319                            case 'location':
    1283                                 $field = $listing->get_field_object( $block['show_field'], true );
    1284                                 if(!$field){
     1320                                $field = $listing->get_field_object( $block->get_prop( 'show_field' ) );
     1321                                if ( ! $field || ! $field->get_value() ) {
     1322                                    $valid = false;
    12851323                                    break;
    12861324                                }
    1287                                 $locations = $field->get_value();
    1288                                 $block['locations'] = $locations;
     1325                                $block['locations'] = $field->get_value();
    12891326                                break;
    12901327                            default:
    1291                      
    12921328                                break;
    12931329                        }
    1294                         $blocks[] = $block;
     1330
     1331                        if ($valid) {
     1332                            $blocks[] = $block;
     1333                        }
    12951334                    }
    12961335
  • mstore-api/trunk/controllers/listing-rest-api/mylisting-functions.php

    r3023244 r3166875  
    1818
    1919    $page = absint( isset($form_data['page']) ? $form_data['page'] : 0 );
    20     $per_page = absint( isset($form_data['per_page']) ? $form_data['per_page'] : c27()->get_setting('general_explore_listings_per_page', 9));
     20    $per_page = isset($form_data['per_page']) ? absint(  $form_data['per_page'])  : -1;
    2121    $orderby = sanitize_text_field( isset($form_data['orderby']) ? $form_data['orderby'] : 'date' );
    22     $context = sanitize_text_field( isset( $form_data['context'] ) ? $form_data['context'] : 'advanced-search' );
    2322    $args = [
    2423        'order' => sanitize_text_field( isset($form_data['order']) ? $form_data['order'] : 'DESC' ),
     
    4342    }
    4443   
    45     if ( $context === 'term-search' ) {
    46         $taxonomy = ! empty( $form_data['taxonomy'] ) ? sanitize_text_field( $form_data['taxonomy'] ) : false;
    47         $term = ! empty( $form_data['term'] ) ? sanitize_text_field( $form_data['term'] ) : false;
    48 
    49         if ( ! $taxonomy || ! $term || ! taxonomy_exists( $taxonomy ) ) {
    50             return [];
    51         }
    52 
    53         $tax_query_operator = apply_filters( 'mylisting/explore/match-all-terms', false ) === true ? 'AND' : 'IN';
    54         $args['tax_query'][] = [
    55             'taxonomy' => $taxonomy,
    56             'field' => 'term_id',
    57             'terms' => $term,
    58             'operator' => $tax_query_operator,
    59             'include_children' => $tax_query_operator !== 'AND',
    60         ];
    61 
    62         // add support for nearby order in single term page
    63         if ( isset( $form_data['proximity'], $form_data['lat'], $form_data['lng'] ) ) {
    64             $proximity = absint( $form_data['proximity'] );
    65             $location = isset( $form_data['search_location'] ) ? sanitize_text_field( stripslashes( $form_data['search_location'] ) ) : false;
    66             $lat = (float) $form_data['lat'];
    67             $lng = (float) $form_data['lng'];
    68             $units = isset($form_data['proximity_units']) && $form_data['proximity_units'] == 'mi' ? 'mi' : 'km';
    69             if ( $lat && $lng && $proximity && $location ) {
    70                 $earth_radius = $units == 'mi' ? 3959 : 6371;
    71                 $sql = $wpdb->prepare( \MyListing\Helpers::get_proximity_sql(), $earth_radius, $lat, $lng, $lat, $proximity );
    72                 $post_ids = (array) $wpdb->get_results( $sql, OBJECT_K );
    73                 if ( empty( $post_ids ) ) { $post_ids = ['none']; }
    74                 $args['post__in'] = array_keys( (array) $post_ids );
    75                 $args['search_location'] = '';
    76             }
    77         }
    78     } else {
    79         foreach ( (array) $type->get_advanced_filters() as $filter ) {
    80             $args = $filter->apply_to_query( $args, $form_data );
    81         }
     44    foreach ( (array) $type->get_advanced_filters() as $filter ) {
     45        $args = $filter->apply_to_query( $args, $form_data );
    8246    }
    83 
     47   
    8448    $result = [];
    85     $listing_wrap = ! empty( $request['listing_wrap'] ) ? sanitize_text_field( $request['listing_wrap'] ) : '';
    86     $listing_wrap = apply_filters( 'mylisting/explore/listing-wrap', $listing_wrap );
    8749
    8850    /**
  • mstore-api/trunk/functions/index.php

    r3147900 r3166875  
    524524            if(!is_string($attr)){
    525525                $check = $attr->is_taxonomy();
     526                $is_image_type = false;
    526527                if ($check) {
    527528                    $taxonomy = $attr->get_taxonomy_object();
    528529                    $label = $taxonomy->attribute_label;
     530                    $is_image_type = $taxonomy->attribute_type == 'image';
    529531                } else {
    530532                    $label = $attr->get_name();
     
    534536                    return ['name'=>$v, 'slug' => $v];
    535537                },$attr["options"]) : $attrOptions;
    536                 $attributesData[] = array_merge($attr->get_data(), ["label" => $label, "name" => urldecode($key)], ['options' =>$attrOptions]);
     538               
     539                $is_image_type = $is_image_type == true && class_exists( 'Woo_Variation_Swatches_Frontend' );
     540                if ($is_image_type) {
     541                     $attrOptions = array_map(function ($item){
     542                        $attachment_id = absint( woo_variation_swatches()->get_frontend()->get_product_attribute_image( $item ) );
     543                        if ($attachment_id) {
     544                            $image         = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
     545                            if ( is_array( $image ) ) {
     546                                $term = $item->to_array();
     547                                $term['image_url'] = esc_url( $image[0] );
     548                                return $term;
     549                            }   
     550                        }
     551                        return $item;
     552                    },$attrOptions);
     553                }
     554               
     555                $attributesData[] = array_merge($attr->get_data(), ["label" => $label, "name" => urldecode($key), 'is_image_type' => $is_image_type], ['options' =>$attrOptions]);
    537556            }
    538557        }
  • mstore-api/trunk/mstore-api.php

    r3147900 r3166875  
    44 * Plugin URI: https://github.com/inspireui/mstore-api
    55 * Description: The MStore API Plugin which is used for the FluxBuilder and FluxStore Mobile App
    6  * Version: 4.15.4
     6 * Version: 4.15.5
    77 * Author: FluxBuilder
    88 * Author URI: https://fluxbuilder.com
     
    5757class MstoreCheckOut
    5858{
    59     public $version = '4.15.4';
     59    public $version = '4.15.5';
    6060
    6161    public function __construct()
     
    250250        if ( $user ) {
    251251            $avatar = get_user_meta( $user->ID, 'user_avatar', true );
    252             if (isset($avatar) && $avatar != "" && !is_bool($avatar)) {
     252            if (isset($avatar) && $avatar !== "" && !is_bool($avatar)) {
    253253                $url = $avatar[0];
    254254            }
     
    911911                // Check user and authentication
    912912                $user = get_userdata($userId);
    913                 if ($user && (!is_user_logged_in() || get_current_user_id() != $userId)) {
     913                if ($user && (!is_user_logged_in() || get_current_user_id() !== $userId)) {
    914914                    wp_set_current_user($userId, $user->user_login);
    915915                    wp_set_auth_cookie($userId);
  • mstore-api/trunk/readme.txt

    r3147900 r3166875  
    44Requires at least: 4.4
    55Tested up to:      6.5.3
    6 Stable tag:        4.15.4
     6Stable tag:        4.15.5
    77License:           GPL-2.0
    88License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    4949
    5050== Changelog ==
     51= 4.15.5 =
     52  * Support Variation Swatches plugin
     53
    5154= 4.15.4 =
    5255  * Fix security issue
Note: See TracChangeset for help on using the changeset viewer.