Plugin Directory

Changeset 3147900


Ignore:
Timestamp:
09/07/2024 09:00:05 AM (19 months ago)
Author:
inspireui
Message:

version 4.15.4

Location:
mstore-api
Files:
487 added
7 edited

Legend:

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

    r3134553 r3147900  
    392392    public function register()
    393393    {
     394        if (!get_option( 'users_can_register' )) {
     395            return parent::sendError("disabled_register", "Registration is not enabled.", 400);
     396        }
    394397        $json = file_get_contents('php://input');
    395398        $params = json_decode($json, TRUE);
     
    405408        }
    406409        if (isset($role)) {
    407             if (!in_array($role, ['subscriber', 'wcfm_vendor', 'seller', 'wcfm_delivery_boy', 'driver','owner'], true)) {
     410            if (!in_array($role, ['subscriber', 'wcfm_vendor', 'seller', 'wcfm_delivery_boy', 'driver'], true)) {
    408411                return parent::sendError("invalid_role", "Role is invalid.", 400);
    409412            }
     
    10391042        if (isset($params->avatar)) {
    10401043            $count = 1;
    1041             require_once(ABSPATH . 'wp-admin' . '/includes/file.php');
    1042             require_once(ABSPATH . 'wp-admin' . '/includes/image.php');
    1043             $imgdata = $params->avatar;
    1044             $imgdata = trim($imgdata);
    1045             $imgdata = str_replace('data:image/png;base64,', '', $imgdata);
    1046             $imgdata = str_replace('data:image/jpg;base64,', '', $imgdata);
    1047             $imgdata = str_replace('data:image/jpeg;base64,', '', $imgdata);
    1048             $imgdata = str_replace('data:image/gif;base64,', '', $imgdata);
    1049             $imgdata = str_replace(' ', '+', $imgdata);
    1050             $imgdata = base64_decode($imgdata);
    1051             $f = finfo_open();
    1052             $mime_type = finfo_buffer($f, $imgdata, FILEINFO_MIME_TYPE);
    1053             $type_file = explode('/', $mime_type);
    1054             $avatar = time() . '_' . $count . '.' . $type_file[1];
    1055 
    1056             $uploaddir = wp_upload_dir();
    1057             $myDirPath = $uploaddir["path"];
    1058             $myDirUrl = $uploaddir["url"];
    1059 
    1060             file_put_contents($uploaddir["path"] . '/' . $avatar, $imgdata);
    1061 
    1062             $filename = $myDirUrl . '/' . basename($avatar);
    1063             $wp_filetype = wp_check_filetype(basename($filename), null);
    1064             $uploadfile = $uploaddir["path"] . '/' . basename($filename);
    1065 
    1066             $attachment = array(
    1067                 "post_mime_type" => $wp_filetype["type"],
    1068                 "post_title" => preg_replace("/\.[^.]+$/", "", basename($filename)),
    1069                 "post_content" => "",
    1070                 "post_author" => $user_id,
    1071                 "post_status" => "inherit",
    1072                 'guid' => $myDirUrl . '/' . basename($filename),
    1073             );
    1074 
    1075             $attachment_id = wp_insert_attachment($attachment, $uploadfile);
    1076             $attach_data = apply_filters('wp_generate_attachment_metadata', $attachment, $attachment_id, 'create');
    1077             // $attach_data = wp_generate_attachment_metadata($attachment_id, $uploadfile);
    1078             wp_update_attachment_metadata($attachment_id, $attach_data);
     1044            $attachment_id = upload_image_from_mobile($params->avatar, $count, $user_id);
    10791045            $url = wp_get_attachment_image_src($attachment_id);
    10801046            update_user_meta($user_id, 'user_avatar', $url, '');
    1081 
    10821047        }
    10831048
  • mstore-api/trunk/controllers/flutter-vendor.php

    r3132501 r3147900  
    587587                }
    588588            }
     589            if (isset($request['exclude']) && !empty($request['exclude'])) {
     590                $excluded_ids = array_map('intval', explode(',', $request['exclude']));
     591                if (isset($args['post__not_in'])) {
     592                    $args['post__not_in'] = array_merge($args['post__not_in'], $excluded_ids);
     593                } else {
     594                    $args['post__not_in'] = $excluded_ids;
     595                }
     596            }
    589597            $products = get_posts($args);
    590598        } else {
     
    607615            if (isset($request['lang'])) {
    608616                $params['lang'] = $request['lang'];
     617            }
     618            if(isset($request['is_all_data'])){
     619                $params['is_all_data'] = $request['is_all_data'];
    609620            }
    610621            $req->set_query_params($params);
  • mstore-api/trunk/controllers/flutter-woo.php

    r3132501 r3147900  
    555555            $cart_item_data = (array)apply_filters('woocommerce_add_cart_item_data', $cart_item_data, $product_id, $variation_id, $quantity);
    556556
     557            /// convert array to array string because generate_cart_id using trim(string) function
     558            $variation_array = array();
     559            if ( is_array( $variation ) && ! empty( $variation ) ) {
     560                foreach ( $variation as $key => $value ) {
     561                    if (is_array($value)) {
     562                        $variation_array[$key] = implode(',', $value);
     563                        continue;
     564                    }
     565                    $variation_array[$key] = $value;
     566                }
     567            }
     568            $cart_item_data_array = array();
     569            if ( is_array( $cart_item_data ) && ! empty( $cart_item_data ) ) {
     570                foreach ( $cart_item_data as $key => $value ) {
     571                    if (is_array($value)) {
     572                        $cart_item_data_array[$key] = implode(',', $value);
     573                        continue;
     574                    }
     575                    $cart_item_data_array[$key] = $value;
     576                }
     577            }
    557578            // Generate a ID based on product ID, variation ID, variation data, and other cart item data.
    558             $cart_id = WC()->cart->generate_cart_id($product_id, $variation_id, $variation, $cart_item_data);
     579            $cart_id = WC()->cart->generate_cart_id($product_id, $variation_id, $variation_array, $cart_item_data_array);
    559580
    560581            // Find the cart item key in the existing cart.
  • mstore-api/trunk/controllers/listing-rest-api/class.api.fields.php

    r3132501 r3147900  
    296296                )
    297297            );
     298
     299            register_rest_route('wp/v2', '/job_listing/(?P<id>\d+)/contents', array(
     300                'methods' => 'GET',
     301                'callback' => array(
     302                    $this,
     303                    'get_listing_tabs'
     304                ) ,
     305                'permission_callback' => function () {
     306                    return true;
     307                }
     308            ));
    298309        }
    299310
     
    11741185            return new WP_REST_Response($data, 200);
    11751186
     1187        }
     1188
     1189        function get_listing_tabs($request){
     1190            $listing_id = $request['id'];
     1191            $post = get_post($listing_id);
     1192            $listing = MyListing\Src\Listing::get( $post );
     1193
     1194            if ( ! $listing->type ) {
     1195                return [];
     1196            }
     1197
     1198            $layout = $listing->type->get_layout();
     1199
     1200            $blocks = [];
     1201            foreach ((array) $layout['menu_items'] as $key => &$menu_item){
     1202                if ($menu_item['page'] == 'main' || $menu_item['page'] == 'custom'){
     1203                    if ( empty( $menu_item['layout'] ) ) {
     1204                        $menu_item['layout'] = [];
     1205                    }
     1206
     1207                    if ( empty( $menu_item['sidebar'] ) ) {
     1208                        $menu_item['sidebar'] = [];
     1209                    }
     1210
     1211                    if ( in_array( $menu_item['template'], ['two-columns', 'content-sidebar', 'sidebar-content'] ) ) {
     1212                        $first_col = $menu_item['template'] === 'sidebar-content' ? 'sidebar' : 'layout';
     1213                        $second_col = $first_col === 'layout' ? 'sidebar' : 'layout';
     1214
     1215                        $menu_item[ 'layout' ] = array_merge( $menu_item[ $first_col ], $menu_item[ $second_col ] );
     1216                    }
     1217
     1218                    foreach ( $menu_item['layout'] as $block ){
     1219                        if ( empty( $block['type'] ) ) {
     1220                            $block['type'] = 'default';
     1221                        }
     1222
     1223                        if ( empty( $block['id'] ) ) {
     1224                            $block['id'] = '';
     1225                        }
     1226                        $block->set_listing( $listing );
     1227
     1228                        $block['type'] = $block->get_type();
     1229                        switch ($block['type']) {
     1230                            case 'gallery':
     1231                                $field = $listing->get_field( $block['show_field'], true );
     1232                                if(!$field){
     1233                                    break;
     1234                                }
     1235                                $block['gallery'] = $field->get_value();
     1236                                break;
     1237                            case 'text':
     1238                                $field = $listing->get_field( $block['show_field'], true );
     1239                                if(!$field){
     1240                                    break;
     1241                                }
     1242                                $block['text'] = $field->get_value();
     1243                                break;
     1244                            case 'table':
     1245                            case 'accordion':
     1246                                $block['rows'] = $block->get_formatted_rows( $listing );
     1247                                break;
     1248                            case 'tags':
     1249                                $block['tags'] = $listing->get_field( 'tags' );
     1250                                break;
     1251                            case 'categories':
     1252                                $block['categories'] = $listing->get_field( 'category' );
     1253                                break;
     1254                            case 'author':
     1255                                $author = $listing->get_author();
     1256                                if ( ! ( $author instanceof \MyListing\Src\User && $author->exists() ) ) {
     1257                                    $block['author'] = null;
     1258                                }else{
     1259                                    $avatar = get_user_meta($author->ID, 'user_avatar', true);
     1260                                    if (!isset($avatar) || $avatar == "" || is_bool($avatar)) {
     1261                                        $avatar = get_avatar_url($author->ID);
     1262                                    } else {
     1263                                        $avatar = $avatar[0];
     1264                                    }
     1265                                    $block['author'] = array(
     1266                                        "id" => $author->ID,
     1267                                        "displayname" => $author->display_name,
     1268                                        "firstname" => $author->user_firstname,
     1269                                        "lastname" => $author->last_name,
     1270                                        "nickname" => $author->nickname,
     1271                                        "avatar" => $avatar,
     1272                                    );
     1273                                }
     1274                                break;
     1275                            case 'work_hours':
     1276                                $block['work_hours'] = $listing->get_field( 'work_hours' ) ;
     1277                                break;
     1278                            case 'video':
     1279                                $video_url = $listing->get_field( $block->get_prop( 'show_field' ) );
     1280                                $block['video'] = \MyListing\Helpers::get_video_embed_details( $video_url );
     1281                                break;
     1282                            case 'location':
     1283                                $field = $listing->get_field_object( $block['show_field'], true );
     1284                                if(!$field){
     1285                                    break;
     1286                                }
     1287                                $locations = $field->get_value();
     1288                                $block['locations'] = $locations;
     1289                                break;
     1290                            default:
     1291                     
     1292                                break;
     1293                        }
     1294                        $blocks[] = $block;
     1295                    }
     1296
     1297                }
     1298            }
     1299
     1300            return $blocks;
    11761301        }
    11771302
     
    23422467            return new WP_REST_Response($listings_grouped, 200);
    23432468        }
     2469
     2470
    23442471    }
    23452472
  • mstore-api/trunk/functions/index.php

    r3132501 r3147900  
    765765    $filename = $myDirUrl . '/' . basename($avatar);
    766766    $wp_filetype = wp_check_filetype(basename($filename), null);
     767    if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
     768        throw new Exception( "The uploaded file is not a valid image. Please try again.");
     769    }
     770
    767771    $uploadfile = $uploaddir["path"] . '/' . basename($filename);
    768772
  • mstore-api/trunk/mstore-api.php

    r3134553 r3147900  
    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.3
     6 * Version: 4.15.4
    77 * Author: FluxBuilder
    88 * Author URI: https://fluxbuilder.com
     
    5757class MstoreCheckOut
    5858{
    59     public $version = '4.15.3';
     59    public $version = '4.15.4';
    6060
    6161    public function __construct()
     
    357357
    358358    //new order or update order via API
    359     function track_api_new_order($object,$request, $creating)
     359    function track_api_new_order($object, $request, $creating)
    360360    {
    361         if($creating){
     361        if ($creating) {
    362362            trackNewOrder($object->id);
    363         }else{
     363
     364            // Update order attributes. Requires WooCommerce 8.5.0 or later.
     365            // And make sure you have enabled `Order Attributes` in WooCommerce
     366            // Settings > Advanced > Features.
     367            // See: https://woocommerce.com/document/order-attribution-tracking/
     368            do_action('woocommerce_store_api_checkout_update_order_from_request', $object, $request);
     369        } else {
    364370            $body = $request->get_body_params();
    365             if(isset($body['status'])){
     371            if (isset($body['status'])) {
    366372                sendNotificationForOrderStatusUpdated($object->id, $body['status']);
    367373            }
     
    488494add_filter('woocommerce_rest_product_brand_query', 'flutter_custom_rest_product_brand_query', 10, 2);
    489495add_filter('rest_product_collection_params', 'flutter_custom_rest_product_collection_params', 10, 1);
     496add_filter('posts_pre_query', 'flutter_custom_posts_pre_query', 10, 2);
     497add_filter('found_posts', 'flutter_custom_found_posts', 20, 2);
    490498
    491499/**
     
    745753    return $response;
    746754}
     755
     756/**
     757 * Wordpress REST API: Support Rest API with Relevanssi.
     758 *
     759 * Attaches to 'the_posts' filter hook, checks to see if there's a place for a
     760 * search and runs relevanssi_do_query() if there is.
     761 *
     762 * https://www.relevanssi.com/user-manual/using-relevanssi-outside-search-pages/
     763 *
     764 * @param array    $posts An array of post objects.
     765 * @param WP_Query $query The WP_Query object, default false.
     766 */
     767function flutter_custom_posts_pre_query($posts, $query)
     768{
     769    if ($query->is_search() && defined('REST_REQUEST') && REST_REQUEST) {
     770        if (function_exists('relevanssi_do_query')) {
     771            $posts = relevanssi_do_query($query);
     772            $query->relevanssi_found_posts = $query->found_posts;
     773            return $posts;
     774        }
     775    }
     776    return $posts;
     777}
     778
     779/**
     780 * Wordpress REST API: Customize `found_posts` in Rest API with Relevanssi.
     781 *
     782 * @param int $found_posts The number of posts found.
     783 * @param WP_Query $query The WP_Query object.
     784 */
     785function flutter_custom_found_posts($found_posts, $query)
     786{
     787    if ($query->is_search() && defined('REST_REQUEST') && REST_REQUEST) {
     788        if (function_exists('relevanssi_do_query')) {
     789            return $query->relevanssi_found_posts;
     790        }
     791    }
     792    return $found_posts;
     793}
     794
    747795
    748796// Prepare data before checkout by webview
  • mstore-api/trunk/readme.txt

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