| @@ -35,28 +35,10 @@ | ||
| 35 | 35 | 'per_page' => [ |
| 36 | 36 | 'default' => 40, |
| 37 | 37 | 'required' => false |
| 38 | 38 | ], |
| 39 | - 'sort_by' => [ | |
| 40 | - 'default' => 'latest', | |
| 41 | - 'required' => false, | |
| 42 | - 'validate_callback' => function( $param, $request, $key ){ | |
| 43 | - return empty( $param ) || in_array( $param, [ 'latest', 'rating', 'download' ], true ); | |
| 44 | - } | |
| 45 | - ], | |
| 46 | 39 | ] ); |
| 47 | 40 | |
| 48 | - // only number | |
| 49 | - $this->get( 'items/(?P<id>[0-9]+)', [ $this, 'get_item_by_id' ], [ | |
| 50 | - 'id' => [ | |
| 51 | - 'required' => true, | |
| 52 | - ], | |
| 53 | - 'type' => [ | |
| 54 | - 'default' => 'block' | |
| 55 | - ] | |
| 56 | - ] ); | |
| 57 | - | |
| 58 | - // with slug | |
| 59 | 41 | $this->get( 'items/(?P<slug>[a-zA-Z0-9-]+)', [ $this, 'get_item' ], [ |
| 60 | 42 | 'slug' => [ |
| 61 | 43 | 'required' => true, |
| 62 | 44 | ], |
| @@ -105,10 +87,9 @@ | ||
| 105 | 87 | $include_search = $this->get_param( 'include_search' ); |
| 106 | 88 | $page = $this->get_param( 'page', 1, 'intval' ); |
| 107 | 89 | $per_page = $this->get_param( 'per_page', 40, 'intval' ); |
| 108 | 90 | $template_type_id = $this->get_param( 'template_type_id', 0, 'intval' ); |
| 109 | - $categories_raw = $this->get_param( 'categories' ); | |
| 110 | - $sort_by = $this->get_param( 'sort_by', 'latest' ); | |
| 91 | + $category_id = $this->get_param( 'category_id', 0, 'intval' ); | |
| 111 | 92 | |
| 112 | 93 | $dependencies = $request->get_param( 'dependencies' ); |
| 113 | 94 | $tags = $request->get_param( 'tags' ); |
| 114 | 95 | |
| @@ -115,9 +96,8 @@ | ||
| 115 | 96 | $funcArgs = [ |
| 116 | 97 | 'page' => $page, |
| 117 | 98 | 'per_page' => $per_page, |
| 118 | 99 | 'platform' => $platform, |
| 119 | - 'sort_by' => $sort_by, | |
| 120 | 100 | ]; |
| 121 | 101 | |
| 122 | 102 | if ( $plan_type > 1 ) { |
| 123 | 103 | $funcArgs['plan_type'] = $plan_type; |
| @@ -122,13 +102,10 @@ | ||
| 122 | 102 | if ( $plan_type > 1 ) { |
| 123 | 103 | $funcArgs['plan_type'] = $plan_type; |
| 124 | 104 | } |
| 125 | 105 | |
| 126 | - if ( ! empty( $categories_raw ) ) { | |
| 127 | - $decoded = json_decode( $categories_raw, true ); | |
| 128 | - if ( is_array( $decoded ) && ! empty( $decoded ) ) { | |
| 129 | - $funcArgs['categories'] = wp_slash( json_encode( array_values( array_filter( array_map( 'intval', $decoded ) ) ) ) ); | |
| 130 | - } | |
| 106 | + if ( $category_id ) { | |
| 107 | + $funcArgs['category_id'] = $category_id; | |
| 131 | 108 | } |
| 132 | 109 | if ( $template_type_id > 0 ) { |
| 133 | 110 | $funcArgs['template_type_id'] = $template_type_id; |
| 134 | 111 | } |
| @@ -146,11 +123,11 @@ | ||
| 146 | 123 | if ( ! empty( $include_search ) ) { |
| 147 | 124 | $funcArgs['include_search'] = $include_search; |
| 148 | 125 | } |
| 149 | 126 | |
| 150 | - $query = 'total_page, current_page, data { id, fullsite_import, name, price, rating, downloads, type, template_type{ slug }, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, badges }'; | |
| 127 | + $query = 'total_page, current_page, data { id, fullsite_import, name, price, rating, downloads, type, template_type{ slug }, slug, favourite_count, thumbnail, thumbnail2, thumbnail3 }'; | |
| 151 | 128 | if( $type !== 'packs' ) { |
| 152 | - $query = 'total_page, current_page, data { id, name, price, rating, downloads, type, template_type{ slug }, slug, favourite_count, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, thumbnail, pack { id, has_settings }, badges }'; | |
| 129 | + $query = 'total_page, current_page, data { id, name, price, rating, downloads, type, template_type{ slug }, slug, favourite_count, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, thumbnail }'; | |
| 153 | 130 | } |
| 154 | 131 | |
| 155 | 132 | if( $type === false ) { |
| 156 | 133 | return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); |
| @@ -155,24 +132,13 @@ | ||
| 155 | 132 | if( $type === false ) { |
| 156 | 133 | return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); |
| 157 | 134 | } |
| 158 | 135 | |
| 159 | - $transient_key = "_templately_items_" . md5(json_encode([$type, $query, $funcArgs])); | |
| 160 | - $response = false; | |
| 161 | - | |
| 162 | - if ( defined( 'TEMPLATELY_ITEMS_TRANSIENT' ) && constant( 'TEMPLATELY_ITEMS_TRANSIENT' ) ) { | |
| 163 | - $response = Database::get_transient( $transient_key ); | |
| 164 | - } | |
| 165 | - | |
| 166 | - if ( empty( $response ) ) { | |
| 167 | - $response = $this->http()->query( $type, $query, $funcArgs )->post(); | |
| 168 | - | |
| 169 | - if ( ! empty( $response ) && ! is_wp_error( $response ) && defined( 'TEMPLATELY_ITEMS_TRANSIENT' ) && constant( 'TEMPLATELY_ITEMS_TRANSIENT' ) ) { | |
| 170 | - Database::set_transient( $transient_key, $response ); | |
| 171 | - } | |
| 172 | - } | |
| 173 | - | |
| 174 | - return $response; | |
| 136 | + return $this->http()->query( | |
| 137 | + $type, | |
| 138 | + $query, | |
| 139 | + $funcArgs | |
| 140 | + )->post(); | |
| 175 | 141 | } |
| 176 | 142 | |
| 177 | 143 | public function get_item() { |
| 178 | 144 | $slug = $this->get_param( 'slug' ); |
| @@ -191,9 +157,9 @@ | ||
| 191 | 157 | if( $type === false ) { |
| 192 | 158 | return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); |
| 193 | 159 | } |
| 194 | 160 | |
| 195 | - $items_params = 'id, name, rating, type, description, slug, price, features, favourite_count, is_favourite, is_reviewed, thumbnail, downloads, categories{ id, name, slug }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, tags{ name, id }, categories{ name, id }, screenshots{ url }, banner, published_at, updated_at, is_trending, badges, pack{ id, name, slug, items{ id, price, name, type, slug, thumbnail, badges }, has_settings }, live_url, template_type{ id, name, slug }'; | |
| 161 | + $items_params = 'id, name, rating, type, description, slug, price, features, favourite_count, is_favourite, is_reviewed, thumbnail, downloads, categories{ id, name, slug }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, tags{ name, id }, categories{ name, id }, screenshots{ url }, banner, published_at, updated_at, is_trending, badges, pack{ id, name, slug, items{ id, price, name, type, slug, thumbnail } }, live_url, template_type{ id, name, slug }'; | |
| 196 | 162 | $params = 'data { ' . $items_params . ', variations { name, slug, type, platform } }'; |
| 197 | 163 | |
| 198 | 164 | if ( $type == 'packs' ) { |
| 199 | 165 | $params = 'data { id, fullsite_import, ai_compatible, has_settings, has_attachments, name, rating, type, slug, live_url, price, features, favourite_count, is_favourite, is_reviewed, thumbnail, description, tags{ name, id }, banner, published_at, updated_at, is_trending, badges, template_type{ id, name, slug } downloads, categories{ id, name, slug }, items { ' . $items_params . ' }, variations { name, slug, type, platform } }'; |
| @@ -205,23 +171,10 @@ | ||
| 205 | 171 | if (!empty($this->api_key)) { |
| 206 | 172 | $args['api_key'] = $this->api_key; |
| 207 | 173 | } |
| 208 | 174 | |
| 209 | - $transient_key = "_templately_items_" . md5(json_encode([$type, $params, $args])); | |
| 210 | - $response = false; | |
| 175 | + $response = $this->http()->query( $type, $params, $args )->post(); | |
| 211 | 176 | |
| 212 | - if ( defined( 'TEMPLATELY_ITEMS_TRANSIENT' ) && constant( 'TEMPLATELY_ITEMS_TRANSIENT' ) ) { | |
| 213 | - $response = Database::get_transient( $transient_key ); | |
| 214 | - } | |
| 215 | - | |
| 216 | - if ( empty( $response ) ) { | |
| 217 | - $response = $this->http()->query( $type, $params, $args )->post(); | |
| 218 | - | |
| 219 | - if ( ! empty( $response ) && ! is_wp_error( $response ) && defined( 'TEMPLATELY_ITEMS_TRANSIENT' ) && constant( 'TEMPLATELY_ITEMS_TRANSIENT' ) ) { | |
| 220 | - Database::set_transient( $transient_key, $response ); | |
| 221 | - } | |
| 222 | - } | |
| 223 | - | |
| 224 | 177 | if ( is_wp_error( $response ) ) { |
| 225 | 178 | return $response; |
| 226 | 179 | } |
| 227 | 180 | |
| @@ -236,58 +189,8 @@ | ||
| 236 | 189 | |
| 237 | 190 | return current( $response['data'] ); |
| 238 | 191 | } |
| 239 | 192 | |
| 240 | - public function get_item_by_id() { | |
| 241 | - $id = (int) $this->get_param( 'id' ); | |
| 242 | - $_type = $this->get_param( 'type', 'blocks' ); | |
| 243 | - $type = $this->get_query_types( $_type ); | |
| 244 | - | |
| 245 | - if ( empty( $id ) ) { | |
| 246 | - return $this->error( | |
| 247 | - 'invalid_item_slug', | |
| 248 | - __( 'Items id cannot be empty.', 'templately' ), | |
| 249 | - 'items/:id', | |
| 250 | - '400' | |
| 251 | - ); | |
| 252 | - } | |
| 253 | - | |
| 254 | - if( $type === false ) { | |
| 255 | - return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); | |
| 256 | - } | |
| 257 | - | |
| 258 | - $items_params = 'id, name, rating, type, description, slug, price, features, favourite_count, is_favourite, is_reviewed, thumbnail, downloads, categories{ id, name, slug }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, tags{ name, id }, categories{ name, id }, screenshots{ url }, banner, published_at, updated_at, is_trending, badges, pack{ id, name, slug, items{ id, price, name, type, slug, thumbnail, badges }, has_settings }, live_url, template_type{ id, name, slug }'; | |
| 259 | - $params = 'data { ' . $items_params . ', variations { name, slug, type, platform } }'; | |
| 260 | - | |
| 261 | - if ( $type == 'packs' ) { | |
| 262 | - $params = 'data { id, fullsite_import, ai_compatible, has_settings, has_attachments, name, rating, type, slug, live_url, price, features, favourite_count, is_favourite, is_reviewed, thumbnail, description, tags{ name, id }, banner, published_at, updated_at, is_trending, badges, template_type{ id, name, slug } downloads, categories{ id, name, slug }, items { ' . $items_params . ' }, variations { name, slug, type, platform } }'; | |
| 263 | - } | |
| 264 | - | |
| 265 | - $args = [ | |
| 266 | - 'id' => $id, | |
| 267 | - ]; | |
| 268 | - if (!empty($this->api_key)) { | |
| 269 | - $args['api_key'] = $this->api_key; | |
| 270 | - } | |
| 271 | - | |
| 272 | - $response = $this->http()->query( $type, $params, $args )->post(); | |
| 273 | - | |
| 274 | - if ( is_wp_error( $response ) ) { | |
| 275 | - return $response; | |
| 276 | - } | |
| 277 | - | |
| 278 | - if( empty( $response['data'] ) ) { | |
| 279 | - return $this->error( | |
| 280 | - 'invalid_response', | |
| 281 | - __('Item data not found', 'templately'), | |
| 282 | - '/items\/' . $id, | |
| 283 | - '404' | |
| 284 | - ); | |
| 285 | - } | |
| 286 | - | |
| 287 | - return current( $response['data'] ); | |
| 288 | - } | |
| 289 | - | |
| 290 | 193 | public function get_search_results( WP_REST_Request $request ) { |
| 291 | 194 | $keyword = $request->get_param( 'keyword' ); |
| 292 | 195 | $platform = $request->get_param( 'platform' ); |
| 293 | 196 | $query_type = $request->get_param( 'query_type' ); |
| @@ -554,9 +457,9 @@ | ||
| 554 | 457 | 'platform' => $platform, |
| 555 | 458 | ]; |
| 556 | 459 | $response = $this->http()->query( |
| 557 | 460 | 'featuredItems', |
| 558 | - 'data{ id, name, slug, price, type, thumbnail, badges }', | |
| 461 | + 'data{ id, name, slug, price, type, thumbnail }', | |
| 559 | 462 | $funcArgs |
| 560 | 463 | )->post(); |
| 561 | 464 | |
| 562 | 465 | if( ! is_wp_error( $response ) ) { |
| @@ -584,9 +487,9 @@ | ||
| 584 | 487 | 'platform' => $platform, |
| 585 | 488 | ]; |
| 586 | 489 | $response = $this->http()->query( |
| 587 | 490 | 'trendingItems', |
| 588 | - 'data{ id, name, slug, price, type, thumbnail, badges }', | |
| 491 | + 'data{ id, name, slug, price, type, thumbnail }', | |
| 589 | 492 | $funcArgs |
| 590 | 493 | )->post(); |
| 591 | 494 | |
| 592 | 495 | if( ! is_wp_error( $response ) ) { |
| @@ -625,14 +528,14 @@ | ||
| 625 | 528 | |
| 626 | 529 | $funcArgs = [ |
| 627 | 530 | 'id' => $item_id, |
| 628 | 531 | 'type' => $type, |
| 629 | - 'limit' => 4, // Limit to 3 related items | |
| 532 | + 'limit' => 3, // Limit to 3 related items | |
| 630 | 533 | ]; |
| 631 | 534 | |
| 632 | 535 | $response = $this->http()->query( |
| 633 | 536 | 'relatedItems', |
| 634 | - 'id, name, slug, price, type, thumbnail, badges', | |
| 537 | + 'id, name, slug, price, type, thumbnail', | |
| 635 | 538 | $funcArgs |
| 636 | 539 | )->post(); |
| 637 | 540 | |
| 638 | 541 | if( is_wp_error( $response ) ) { |