CTX Feed – WooCommerce Product Feed Manager Plugin - Version 4.5.12

Version Description

(2022-12-06) = * Added: Black Friday Notice Banner Remove * Fixed: Yandex xml format feed generation stuck

Download this release

Release Info

Developer wahid0003
Plugin Icon 128x128 CTX Feed – WooCommerce Product Feed Manager Plugin
Version 4.5.12
Comparing to
See all releases

Code changes from version 4.5.11 to 4.5.12

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: WooCommerce Product Feed, WooCommerce, Google Shopping, Google Merchant, F
5
  Requires at least: 4.4
6
  Tested Up To: 6.1
7
  Requires PHP: 5.6
8
- Stable tag: 4.5.11
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -590,6 +590,10 @@ Using pro version:
590
 
591
  == Changelog ==
592
 
 
 
 
 
593
  = 4.5.11 (2022-11-21) =
594
  * Added: Black Friday Notice Banner Added
595
 
5
  Requires at least: 4.4
6
  Tested Up To: 6.1
7
  Requires PHP: 5.6
8
+ Stable tag: 4.5.12
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
590
 
591
  == Changelog ==
592
 
593
+ = 4.5.12 (2022-12-06) =
594
+ * Added: Black Friday Notice Banner Remove
595
+ * Fixed: Yandex xml format feed generation stuck
596
+
597
  = 4.5.11 (2022-11-21) =
598
  * Added: Black Friday Notice Banner Added
599
 
V5/API/RestController.php CHANGED
@@ -2,25 +2,16 @@
2
 
3
  namespace CTXFeed\V5\API;
4
 
5
-
6
-
7
- use CTXFeed\V5\API\V1\DropDownOptionsApi;
8
- use CTXFeed\V5\API\V1\FeedLists;
9
- use CTXFeed\V5\API\V1\MerchantConfig;
10
- use CTXFeed\V5\API\V1\MerchantInfo;
11
- use CTXFeed\V5\API\V1\ProductCategories;
12
- use CTXFeed\V5\API\V1\ProductTaxonomy;
13
- use CTXFeed\V5\API\V1\ProductTitles;
14
- use WP_REST_Controller;
15
 
16
  class RestController extends WP_REST_Controller {
17
 
18
-
19
  /**
20
  * @var array $response ;
21
  */
22
  public $response = [
23
- 'status' => true,
24
  'data' => null,
25
  'extra' => null
26
  ];
@@ -32,25 +23,21 @@ class RestController extends WP_REST_Controller {
32
  */
33
  protected static $_instance = null;
34
 
35
- public function __construct() {
 
 
 
 
 
 
36
  add_action( 'rest_api_init', [ $this, 'register_api' ] );
37
- }
 
 
38
 
39
- public function register_api() {
40
- $classes = [
41
- DropDownOptionsApi::instance(),
42
- ProductTaxonomy::instance(),
43
- ProductTitles::instance(),
44
- ProductCategories::instance(),
45
- MerchantInfo::instance(),
46
- MerchantConfig::instance(),
47
- FeedLists::instance(),
48
- ];
49
- foreach ( $classes as $class ) {
50
- $class->register_routes();
51
- }
52
  }
53
 
 
54
  /**
55
  * Main RestController Instance.
56
  *
@@ -66,6 +53,32 @@ class RestController extends WP_REST_Controller {
66
  return self::$_instance;
67
  }
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  /**
70
  * Cloning is forbidden.
71
  */
@@ -80,54 +93,144 @@ class RestController extends WP_REST_Controller {
80
  _doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'woo-feed' ), WOO_FEED_FREE_VERSION );
81
  }
82
 
 
83
  /**
84
- * Get single item permission to perform current action.
85
  *
86
- * @param $request
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  *
88
- * @return bool
89
  */
90
- public function get_item_permissions_check( $request ) {
91
- if ( current_user_can( 'manage_options' ) ) {
92
- return true;
93
- }
94
 
95
- return true;
 
 
 
 
96
  }
97
 
98
  /**
99
- * Get items permission to perform current action.
100
  *
101
- * @param $request
 
 
 
 
 
 
 
 
 
 
 
 
102
  *
103
- * @return bool
104
  */
105
- public function get_items_permissions_check( $request ) {
106
- if ( current_user_can( 'manage_options' ) ) {
107
- return true;
 
 
 
 
 
 
 
 
108
  }
 
109
 
110
- return false;
111
  }
112
 
113
  /**
114
- * @param $data
 
 
 
115
  *
116
- * @return void
117
  */
118
- public function success( $data ) {
119
- $this->response['status'] = true;
120
- $this->response['data'] = $data;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  }
122
 
123
  /**
124
- * @param $data
125
  *
126
- * @return void
127
  */
128
- public function error( $data ) {
129
- $this->response['status'] = false;
130
- $this->response['data'] = $data;
 
 
 
131
  }
132
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
2
 
3
  namespace CTXFeed\V5\API;
4
 
5
+ use \WP_REST_Controller;
6
+ use \WP_Error;
 
 
 
 
 
 
 
 
7
 
8
  class RestController extends WP_REST_Controller {
9
 
 
10
  /**
11
  * @var array $response ;
12
  */
13
  public $response = [
14
+ 'status' => 200,
15
  'data' => null,
16
  'extra' => null
17
  ];
23
  */
24
  protected static $_instance = null;
25
 
26
+ /**
27
+ * @var $version ;
28
+ */
29
+ private $version = 'v1';
30
+
31
+ protected function __construct() {
32
+ $this->namespace = 'ctxfeed/' . $this->version;
33
  add_action( 'rest_api_init', [ $this, 'register_api' ] );
34
+ add_action( 'rest_api_init', function ( $var ) {
35
+ remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
36
+ }, 15, 1 );
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
+
41
  /**
42
  * Main RestController Instance.
43
  *
53
  return self::$_instance;
54
  }
55
 
56
+ /**
57
+ * Get single item permission to perform current action.
58
+ *
59
+ * @param $request
60
+ *
61
+ * @return bool
62
+ */
63
+ public function get_item_permissions_check( $request ) {
64
+ if ( current_user_can( 'manage_options' ) ) {
65
+ return true;
66
+ }
67
+
68
+ return false;
69
+ }
70
+
71
+
72
+ public function register_api() {
73
+ $uri = trim( $_SERVER['REQUEST_URI'], '/' );
74
+ $uri = explode( '/', $uri );
75
+ $namespace = explode( '/', $this->namespace );
76
+ if ( $namespace[0] === $uri[2] ) {
77
+ self::load_class( $uri[4] )->register_routes();
78
+ }
79
+ }
80
+
81
+
82
  /**
83
  * Cloning is forbidden.
84
  */
93
  _doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'woo-feed' ), WOO_FEED_FREE_VERSION );
94
  }
95
 
96
+
97
  /**
98
+ * @param $data
99
  *
100
+ * @return void|\WP_REST_Response
101
+ */
102
+ public function success( $data, $status = 200 ) {
103
+ $this->response['status'] = $status;
104
+ $this->response['data'] = $data;
105
+
106
+ $response = rest_ensure_response( $this->response );
107
+ $response = $this->add_additional_headers( $response );
108
+
109
+ return $response;
110
+ }
111
+
112
+
113
+ /**
114
+ * @param $data
115
  *
116
+ * @return void|\WP_Error
117
  */
118
+ public function error( $data = '', $code = 'rest_no_data_found', $status = 404 ) {
119
+ $this->response['status'] = $status;
120
+ $this->response['data'] = $data;
 
121
 
122
+ return new WP_Error(
123
+ $code,
124
+ $data,
125
+ [ 'status' => $status ]
126
+ );
127
  }
128
 
129
  /**
130
+ * @param $response
131
  *
132
+ * @return \WP_REST_Response
133
+ */
134
+ protected function add_additional_headers( $response ) {
135
+ $admin_origin = parse_url( admin_url() );
136
+ $response->header( 'Access-Control-Allow-Origin', $admin_origin['host'] );
137
+
138
+ return $response;
139
+ }
140
+
141
+ /**
142
+ * @param $args
143
+ * @param $data
144
+ * @param $response
145
  *
146
+ * @return mixed
147
  */
148
+ protected function maybe_add_pagination( $args, $data, $response ) {
149
+ // Get data according to pagination. If $page and $per_page params are passed in the url.
150
+ $total = count( $data );
151
+ if ( isset( $args['per_page'], $args['page'] ) ) {
152
+ $total_pages = ceil( $total / (int) $args['per_page'] );
153
+ // Set current page data.
154
+ $offset = $args['per_page'] * ( $args['page'] - 1 );
155
+ $this->response['data'] = array_slice( $data, $offset, $args['per_page'] );
156
+ $response = $this->add_pagination_links( $response, $args, $total_pages, $total );
157
+ } else {
158
+ $this->response['data'] = $data;
159
  }
160
+ $response->data = $this->response;
161
 
162
+ return $response;
163
  }
164
 
165
  /**
166
+ * @param $response
167
+ * @param $args
168
+ * @param $total_pages
169
+ * @param $total
170
  *
171
+ * @return mixed
172
  */
173
+ protected function add_pagination_links( $response, $args, $total_pages, $total ) {
174
+
175
+ $url = get_site_url() . '/wp-json/' . $this->namespace . '/' . $this->rest_base . '/?';
176
+
177
+ $page = (int) $args['page'];
178
+ unset( $args['page'] );
179
+ $total_args = count( $args );
180
+ $count = 0;
181
+ foreach ( $args as $arg => $value ) {
182
+ $count ++;
183
+ if ( $count === $total_args ) {
184
+ $url .= $arg . '=' . $value;
185
+ } else {
186
+ $url .= $arg . '=' . $value . '&';
187
+ }
188
+ }
189
+ // Next page link add.
190
+ if ( $total_pages == $page ) {
191
+ $next_url = $url . '&page=' . $page;
192
+ } else {
193
+ $next_page = $page + 1;
194
+ $next_url = $url . '&page=' . $next_page;
195
+ }
196
+ $response->add_link( 'next_page', $next_url );
197
+ // Previous page link add.
198
+ if ( $page == 1 ) {
199
+ $prev_url = $url . '&page=' . $page;
200
+ } else {
201
+ $prev_page = $page - 1;
202
+ $prev_url = $url . '&page=' . $prev_page;
203
+ }
204
+ $response->add_link( 'prev_page', $prev_url );
205
+ // add headers.
206
+ $response->header( 'X-WP-TotalPages', (int) $total_pages );
207
+ $response->header( 'X-WP-Total', (int) $total );
208
+
209
+ return $response;
210
  }
211
 
212
  /**
213
+ * @param $array
214
  *
215
+ * @return bool
216
  */
217
+ protected function is_assoc( $array ) {
218
+ if ( array() === $array ) {
219
+ return false;
220
+ }
221
+
222
+ return ( $array !== array_values( $array ) );
223
  }
224
 
225
+ public function is_prefix_matched( $string, $prefix ) {
226
+ return str_starts_with( $string, $prefix );
227
+ }
228
+
229
+
230
+ private static function load_class( $class = null ) {
231
+ $api_class = array_map( 'ucfirst', explode( '_', $class ) );
232
+ $api_class = implode( '', $api_class );
233
+
234
+ return RestFactory::load( $api_class );
235
+ }
236
  }
V5/API/RestFactory.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CTXFeed\V5\API;
4
+
5
+ class RestFactory {
6
+ public static function load( $class ) {
7
+ $class = "\CTXFeed\V5\API\V1\\" . $class;
8
+ if ( class_exists( $class ) ) {
9
+ return $class::instance();
10
+ }else{
11
+ return null;
12
+ }
13
+ }
14
+ }
V5/API/V1/AttributesMapping.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CTXFeed\V5\API\V1;
4
+
5
+ use CTXFeed\V5\API\RestController;
6
+ use \WP_REST_Server;
7
+
8
+ class AttributesMapping extends RestController {
9
+ /**
10
+ * @var array
11
+ */
12
+ private static $attr_lists = [];
13
+ /**
14
+ * @var string
15
+ */
16
+ private static $prefix = 'wp_attr_mapping_';
17
+ /**
18
+ * The single instance of the class
19
+ *
20
+ * @var AttributesMapping
21
+ *
22
+ */
23
+ protected static $_instance = null;
24
+
25
+ private function __construct() {
26
+ parent::__construct();
27
+ $this->rest_base = 'attributes_mapping';
28
+ }
29
+
30
+ /**
31
+ * Main AttributesMapping Instance.
32
+ *
33
+ * Ensures only one instance of AttributesMapping is loaded or can be loaded.
34
+ *
35
+ * @return AttributesMapping Main instance
36
+ */
37
+ public static function instance() {
38
+ if ( is_null( self::$_instance ) ) {
39
+ self::$_instance = new self();
40
+ }
41
+
42
+ return self::$_instance;
43
+ }
44
+
45
+ /**
46
+ * Register routes.
47
+ * @return void
48
+ */
49
+ public function register_routes() {
50
+ register_rest_route(
51
+ $this->namespace,
52
+ '/' . $this->rest_base,
53
+ [
54
+ /**
55
+ * @endpoint: wp-json/ctxfeed/v1/attributes_mapping
56
+ * @description Will get all feed lists
57
+ *
58
+ *
59
+ * @endpoint wp-json/ctxfeed/v1/attributes_mapping/?page=1&per_page=2
60
+ * @descripton Get paginated value with previous page and next page link
61
+ *
62
+ * @endpoint wp-json/ctxfeed/v1/attributes_mapping/?name=wf_feed_google_shopping
63
+ * @method GET
64
+ * @descripton Get single attribute
65
+ *
66
+ * @param $name String
67
+ *
68
+ * @param $page Number
69
+ * @param $per_page Number
70
+ */
71
+ [
72
+ 'methods' => WP_REST_Server::READABLE,
73
+ 'callback' => [ $this, 'get_items' ],
74
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
75
+ 'args' => [
76
+ 'name' => [
77
+ 'description' => __( 'feed name', 'woo-feed' ),
78
+ 'type' => 'string',
79
+ 'required' => false,
80
+ 'sanitize_callback' => 'sanitize_text_field',
81
+ 'validate_callback' => 'rest_validate_request_arg',
82
+ ],
83
+ 'page' => [
84
+ 'description' => __( 'Page number', 'woo-feed' ),
85
+ 'type' => 'number',
86
+ 'required' => false,
87
+ 'sanitize_callback' => 'absint',
88
+ 'validate_callback' => 'rest_validate_request_arg',
89
+ ],
90
+ 'per_page' => [
91
+ 'description' => __( 'Per page', 'woo-feed' ),
92
+ 'type' => 'number',
93
+ 'required' => false,
94
+ 'sanitize_callback' => 'absint',
95
+ 'validate_callback' => 'rest_validate_request_arg',
96
+ ],
97
+ ],
98
+ ],
99
+ [
100
+ 'methods' => WP_REST_Server::CREATABLE,
101
+ 'callback' => [ $this, 'create_item' ],
102
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
103
+ 'args' => [],
104
+ ],
105
+ [
106
+ 'methods' => WP_REST_Server::EDITABLE,
107
+ 'callback' => [ $this, 'update_item' ],
108
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
109
+ 'args' => [],
110
+ ],
111
+ /**
112
+ * @endpoint wp-json/ctxfeed/v1/attributes_mapping/?name=wf_feed_google_shopping
113
+ * @method DELETE
114
+ * @descripton Delete single attribute
115
+ *
116
+ * @param $name String
117
+ */
118
+ [
119
+ 'methods' => WP_REST_Server::DELETABLE,
120
+ 'callback' => [ $this, 'delete_item' ],
121
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
122
+ 'args' => [
123
+ 'name' => [
124
+ 'description' => __( 'feed name', 'woo-feed' ),
125
+ 'type' => 'string',
126
+ 'required' => true,
127
+ 'sanitize_callback' => 'sanitize_text_field',
128
+ 'validate_callback' => 'rest_validate_request_arg',
129
+ ],
130
+ ],
131
+ ],
132
+
133
+ ]
134
+ );
135
+ }
136
+
137
+ /**
138
+ * @param $request
139
+ *
140
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
141
+ */
142
+ public function update_item( $request ) {
143
+ $body = $request->get_body();
144
+ $body = (array) json_decode( $body );
145
+
146
+ if ( ! $this->is_assoc( $body ) ) {
147
+ return $this->error( __( 'Option name is missing!', 'woo-feed' ) );
148
+ }
149
+
150
+ return $this->create_item( $request );
151
+
152
+ }
153
+
154
+ /**
155
+ * @param $request
156
+ *
157
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
158
+ */
159
+ public function delete_item( $request ) {
160
+ $name = $request->get_param( 'name' );
161
+
162
+ if ( get_option( $name ) ) {
163
+ delete_option( $name );
164
+
165
+ return $this->success( sprintf( __( 'Attribute deleted with name: %s', 'woo-feed' ), $name ) );
166
+ }
167
+
168
+ return $this->error( sprintf( __( 'No attribute found with name: %s', 'woo-feed' ), $name ) );
169
+ }
170
+
171
+ /**
172
+ * @param $request
173
+ *
174
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
175
+ */
176
+ public function create_item( $request ) {
177
+ $option_names = [];
178
+ $body = $request->get_body();
179
+ $body = json_decode( $body );
180
+ // Save option name.
181
+ foreach ( $body as $option_name => $value ) {
182
+ if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
183
+ return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
184
+ }
185
+ $value = (array) $value;
186
+ update_option( $option_name, maybe_serialize( $value ) );
187
+ array_push( $option_names, $option_name );
188
+ }
189
+ // Get option name.
190
+ foreach ( $option_names as $option_name ) {
191
+ $data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
192
+ }
193
+ $this->response['data'] = $data;
194
+
195
+ return rest_ensure_response( $this->response );
196
+ }
197
+
198
+ /**
199
+ * @param $request
200
+ *
201
+ * @return \WP_Error|\WP_REST_Response|null
202
+ */
203
+ public function get_item( $request ) {
204
+ $args = $request->get_params();
205
+ $feed_name = $args['name'];
206
+ global $wpdb;
207
+ $attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
208
+ $this::$attr_lists = $attr_lists;
209
+
210
+ if ( count( $this::$attr_lists ) && $this->is_prefix_matched( $this::$attr_lists[0]['option_name'], self::$prefix ) ) {
211
+ $item = $this->prepare_item_for_response( $this::$attr_lists[0], $request );
212
+
213
+ return $this->success( $item );
214
+ }
215
+
216
+ return $this->error( sprintf( __( 'Not found with: %s or prefix: "'. self::$prefix .'" does\'nt match.', 'woo-feed' ), $feed_name ) );
217
+ }
218
+
219
+ /**
220
+ *
221
+ * @param \WP_REST_Request $request Full details about the request.
222
+ *
223
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
224
+ */
225
+ public function get_items( $request ) {
226
+ $args = $request->get_params();
227
+ if ( isset( $args['name'] ) ) {
228
+ return $this->get_item( $request );
229
+ }
230
+ global $wpdb;
231
+ $attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", self::$prefix.'%' ), 'ARRAY_A' );
232
+ $this::$attr_lists = $attr_lists;
233
+
234
+ $data = $this->get_lists( $request );
235
+
236
+ $response = rest_ensure_response( $this->response );
237
+ $response = $this->maybe_add_pagination( $args, $data, $response );
238
+
239
+ return $response;
240
+ }
241
+
242
+ /**
243
+ * @param $request
244
+ *
245
+ * @return array
246
+ */
247
+ public function get_lists( $request ) {
248
+ $lists = [];
249
+ foreach ( $this::$attr_lists as $attr_list ) {
250
+ $item = $this->prepare_item_for_response( $attr_list, $request );
251
+ $lists[] = $item;
252
+ }
253
+
254
+ return $lists;
255
+ }
256
+
257
+ /**
258
+ * @param $item
259
+ * @param $request
260
+ *
261
+ * @return void|\WP_Error|\WP_REST_Response
262
+ */
263
+ public function prepare_item_for_response( $item, $request ) {
264
+ $item['option_value'] = maybe_unserialize( get_option( $item['option_name'] ) );
265
+
266
+ return $item;
267
+ }
268
+
269
+ }
V5/API/V1/CategoryMapping.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CTXFeed\V5\API\V1;
4
+
5
+ use CTXFeed\V5\API\RestController;
6
+ use \WP_REST_Server;
7
+
8
+ class CategoryMapping extends RestController {
9
+ /**
10
+ * @var array
11
+ */
12
+ private static $category_lists = [];
13
+ /**
14
+ * @var string
15
+ */
16
+ private static $prefix = 'wf_cmapping_';
17
+ /**
18
+ * The single instance of the class
19
+ *
20
+ * @var CategoryMapping
21
+ *
22
+ */
23
+ protected static $_instance = null;
24
+
25
+ private function __construct() {
26
+ parent::__construct();
27
+ $this->rest_base = 'category_mapping';
28
+ }
29
+
30
+ /**
31
+ * Main CategoryMapping Instance.
32
+ *
33
+ * Ensures only one instance of CategoryMapping is loaded or can be loaded.
34
+ *
35
+ * @return CategoryMapping Main instance
36
+ */
37
+ public static function instance() {
38
+ if ( is_null( self::$_instance ) ) {
39
+ self::$_instance = new self();
40
+ }
41
+
42
+ return self::$_instance;
43
+ }
44
+
45
+ /**
46
+ * Register routes.
47
+ * @return void
48
+ */
49
+ public function register_routes() {
50
+ register_rest_route(
51
+ $this->namespace,
52
+ '/' . $this->rest_base,
53
+ [
54
+ /**
55
+ * @endpoint: wp-json/ctxfeed/v1/category_mapping
56
+ * @description Will get all feed lists
57
+ *
58
+ *
59
+ * @endpoint wp-json/ctxfeed/v1/category_mapping/?page=1&per_page=2
60
+ * @descripton Get paginated value with previous page and next page link
61
+ *
62
+ * @endpoint wp-json/ctxfeed/v1/category_mapping/?name=wf_feed_google_shopping
63
+ * @method GET
64
+ * @descripton Get single attribute
65
+ *
66
+ * @param $name String
67
+ *
68
+ * @param $page Number
69
+ * @param $per_page Number
70
+ */
71
+ [
72
+ 'methods' => WP_REST_Server::READABLE,
73
+ 'callback' => [ $this, 'get_items' ],
74
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
75
+ 'args' => [
76
+ 'name' => [
77
+ 'description' => __( 'feed name', 'woo-feed' ),
78
+ 'type' => 'string',
79
+ 'required' => false,
80
+ 'sanitize_callback' => 'sanitize_text_field',
81
+ 'validate_callback' => 'rest_validate_request_arg',
82
+ ],
83
+ 'page' => [
84
+ 'description' => __( 'Page number', 'woo-feed' ),
85
+ 'type' => 'number',
86
+ 'required' => false,
87
+ 'sanitize_callback' => 'absint',
88
+ 'validate_callback' => 'rest_validate_request_arg',
89
+ ],
90
+ 'per_page' => [
91
+ 'description' => __( 'Per page', 'woo-feed' ),
92
+ 'type' => 'number',
93
+ 'required' => false,
94
+ 'sanitize_callback' => 'absint',
95
+ 'validate_callback' => 'rest_validate_request_arg',
96
+ ],
97
+ ],
98
+ ],
99
+ [
100
+ 'methods' => WP_REST_Server::CREATABLE,
101
+ 'callback' => [ $this, 'create_item' ],
102
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
103
+ 'args' => [],
104
+ ],
105
+ [
106
+ 'methods' => WP_REST_Server::EDITABLE,
107
+ 'callback' => [ $this, 'update_item' ],
108
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
109
+ 'args' => [],
110
+ ],
111
+ /**
112
+ * @endpoint wp-json/ctxfeed/v1/category_mapping/?name=wf_feed_google_shopping
113
+ * @method DELETE
114
+ * @descripton Delete single attribute
115
+ *
116
+ * @param $name String
117
+ */
118
+ [
119
+ 'methods' => WP_REST_Server::DELETABLE,
120
+ 'callback' => [ $this, 'delete_item' ],
121
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
122
+ 'args' => [
123
+ 'name' => [
124
+ 'description' => __( 'feed name', 'woo-feed' ),
125
+ 'type' => 'string',
126
+ 'required' => true,
127
+ 'sanitize_callback' => 'sanitize_text_field',
128
+ 'validate_callback' => 'rest_validate_request_arg',
129
+ ],
130
+ ],
131
+ ],
132
+
133
+ ]
134
+ );
135
+ }
136
+
137
+ /**
138
+ * @param $request
139
+ *
140
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
141
+ */
142
+ public function update_item( $request ) {
143
+ $body = $request->get_body();
144
+ $body = (array) json_decode( $body );
145
+
146
+ if ( ! $this->is_assoc( $body ) ) {
147
+ return $this->error( __( 'Option name is missing!', 'woo-feed' ) );
148
+ }
149
+
150
+ return $this->create_item( $request );
151
+
152
+ }
153
+
154
+ /**
155
+ * @param $request
156
+ *
157
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
158
+ */
159
+ public function delete_item( $request ) {
160
+ $name = $request->get_param( 'name' );
161
+
162
+ if ( get_option( $name ) ) {
163
+ delete_option( $name );
164
+
165
+ return $this->success( sprintf( __( 'Attribute deleted with name: %s', 'woo-feed' ), $name ) );
166
+ }
167
+
168
+ return $this->error( sprintf( __( 'No attribute found with name: %s', 'woo-feed' ), $name ) );
169
+ }
170
+
171
+ /**
172
+ * @param $request
173
+ *
174
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
175
+ */
176
+ public function create_item( $request ) {
177
+ $option_names = [];
178
+ $body = $request->get_body();
179
+ $body = json_decode( $body );
180
+ // Save option name.
181
+ foreach ( $body as $option_name => $value ) {
182
+ if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
183
+ return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
184
+ }
185
+ $value = (array) $value;
186
+ update_option( $option_name, maybe_serialize( $value ) );
187
+ array_push( $option_names, $option_name );
188
+ }
189
+ // Get option name.
190
+ foreach ( $option_names as $option_name ) {
191
+ $data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
192
+ }
193
+ $this->response['data'] = $data;
194
+
195
+ return rest_ensure_response( $this->response );
196
+ }
197
+
198
+ /**
199
+ * @param $request
200
+ *
201
+ * @return \WP_Error|\WP_REST_Response|null
202
+ */
203
+ public function get_item( $request ) {
204
+ $args = $request->get_params();
205
+ $feed_name = $args['name'];
206
+ global $wpdb;
207
+ $category_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
208
+ $this::$category_lists = $category_lists;
209
+
210
+ if ( count( $this::$category_lists ) && $this->is_prefix_matched( $this::$category_lists[0]['option_name'], self::$prefix ) ) {
211
+ $item = $this->prepare_item_for_response( $this::$category_lists[0], $request );
212
+
213
+ return $this->success( $item );
214
+ }
215
+
216
+ return $this->error( sprintf( __( 'Not found with: %s or prefix: "'. self::$prefix .'" does\'nt match.', 'woo-feed' ), $feed_name ) );
217
+ }
218
+
219
+ /**
220
+ *
221
+ * @param \WP_REST_Request $request Full details about the request.
222
+ *
223
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
224
+ */
225
+ public function get_items( $request ) {
226
+ $args = $request->get_params();
227
+ if ( isset( $args['name'] ) ) {
228
+ return $this->get_item( $request );
229
+ }
230
+ global $wpdb;
231
+ $category_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", self::$prefix.'%' ), 'ARRAY_A' );
232
+ $this::$category_lists = $category_lists;
233
+
234
+ $data = $this->get_lists( $request );
235
+
236
+ $response = rest_ensure_response( $this->response );
237
+ $response = $this->maybe_add_pagination( $args, $data, $response );
238
+
239
+ return $response;
240
+ }
241
+
242
+ /**
243
+ * @param $request
244
+ *
245
+ * @return array
246
+ */
247
+ public function get_lists( $request ) {
248
+ $lists = [];
249
+ foreach ( $this::$category_lists as $attr_list ) {
250
+ $item = $this->prepare_item_for_response( $attr_list, $request );
251
+ $lists[] = $item;
252
+ }
253
+
254
+ return $lists;
255
+ }
256
+
257
+ /**
258
+ * @param $item
259
+ * @param $request
260
+ *
261
+ * @return void|\WP_Error|\WP_REST_Response
262
+ */
263
+ public function prepare_item_for_response( $item, $request ) {
264
+ $item['option_value'] = maybe_unserialize( get_option( $item['option_name'] ) );
265
+
266
+ return $item;
267
+ }
268
+
269
+ }
V5/API/V1/{DropDownOptionsApi.php → DropDown.php} RENAMED
@@ -5,22 +5,9 @@ namespace CTXFeed\V5\API\V1;
5
  use CTXFeed\V5\API\RestController;
6
  use WP_REST_Server;
7
  use CTXFeed\V5\Common\DropDownOptions;
 
8
 
9
- class DropDownOptionsApi extends RestController {
10
-
11
- /**
12
- * @var $namespace ;
13
- */
14
- public $namespace;
15
- /**
16
- * @var $version ;
17
- */
18
- public $version = 'v1';
19
- /**
20
- * @var $rest_base
21
- */
22
-
23
- protected $rest_base;
24
 
25
  /**
26
  * @var $dropdown
@@ -29,15 +16,15 @@ class DropDownOptionsApi extends RestController {
29
  /**
30
  * The single instance of the class
31
  *
32
- * @var DropDownOptionsApi
33
  *
34
  */
35
  protected static $_instance = null;
36
 
37
- public function __construct() {
38
  parent::__construct();
39
- $this->namespace = 'ctxfeed/' . $this->version;
40
- $this->rest_base = 'dropdown';
41
  $this->dropdown = DropDownOptions::instance();
42
 
43
  }
@@ -47,7 +34,7 @@ class DropDownOptionsApi extends RestController {
47
  *
48
  * Ensures only one instance of DropDownOptionsApi is loaded or can be loaded.
49
  *
50
- * @return DropDownOptionsApi Main instance
51
  */
52
  public static function instance() {
53
  if ( is_null( self::$_instance ) ) {
@@ -64,6 +51,7 @@ class DropDownOptionsApi extends RestController {
64
  [
65
  /**
66
  * @endpoint: wp-json/ctxfeed/v1/dropdown/?type=feed_country
 
67
  * @param $type String will be DropDownOptions class\'s method name
68
  */
69
  [
@@ -78,6 +66,7 @@ class DropDownOptionsApi extends RestController {
78
  ],
79
  ],
80
  ],
 
81
  ]
82
  );
83
  }
@@ -92,16 +81,62 @@ class DropDownOptionsApi extends RestController {
92
  * @return void|\WP_Error|\WP_REST_Response
93
  */
94
  public function get_item( $request ) {
 
95
  $param = $request->get_param( 'type' );
96
 
97
  if ( method_exists( $this->dropdown, $param ) ) {
98
  $this->response['data'] = $this->dropdown::$param( '', false );
99
  } else {
100
- $this->error( __( 'Method Does not exist !', 'woo-feed' ) );
 
 
 
 
 
 
 
 
101
 
102
- return rest_ensure_response( $this->response );
 
 
 
 
 
 
 
103
  }
104
 
105
- return rest_ensure_response( $this->response );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
5
  use CTXFeed\V5\API\RestController;
6
  use WP_REST_Server;
7
  use CTXFeed\V5\Common\DropDownOptions;
8
+ use \WP_Error;
9
 
10
+ class DropDown extends RestController {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  /**
13
  * @var $dropdown
16
  /**
17
  * The single instance of the class
18
  *
19
+ * @var DropDown
20
  *
21
  */
22
  protected static $_instance = null;
23
 
24
+ private function __construct() {
25
  parent::__construct();
26
+
27
+ $this->rest_base = 'drop_down';
28
  $this->dropdown = DropDownOptions::instance();
29
 
30
  }
34
  *
35
  * Ensures only one instance of DropDownOptionsApi is loaded or can be loaded.
36
  *
37
+ * @return DropDown Main instance
38
  */
39
  public static function instance() {
40
  if ( is_null( self::$_instance ) ) {
51
  [
52
  /**
53
  * @endpoint: wp-json/ctxfeed/v1/dropdown/?type=feed_country
54
+ *
55
  * @param $type String will be DropDownOptions class\'s method name
56
  */
57
  [
66
  ],
67
  ],
68
  ],
69
+ 'schema' => [ $this, 'get_item_schema' ],
70
  ]
71
  );
72
  }
81
  * @return void|\WP_Error|\WP_REST_Response
82
  */
83
  public function get_item( $request ) {
84
+
85
  $param = $request->get_param( 'type' );
86
 
87
  if ( method_exists( $this->dropdown, $param ) ) {
88
  $this->response['data'] = $this->dropdown::$param( '', false );
89
  } else {
90
+ return $this->error( __( 'Method Does not exist !', 'woo-feed' ) );
91
+ }
92
+
93
+ $response = $this->success( $this->response['data'] );
94
+ $response->header( 'X-WP-Total', count( $this->dropdown::$param( '', false ) ) );
95
+
96
+ return $response;
97
+ }
98
+
99
 
100
+ /**
101
+ * Retrieves the contact schema, conforming to JSON Schema.
102
+ *
103
+ * @return array
104
+ */
105
+ public function get_item_schema() {
106
+ if ( $this->schema ) {
107
+ return $this->add_additional_fields_schema( $this->schema );
108
  }
109
 
110
+ $schema = [
111
+ '$schema' => 'http://json-schema.org/draft-04/schema#',
112
+ 'title' => 'dropdown',
113
+ 'type' => 'array',
114
+ 'properties' => [
115
+ 'dropdown' => [
116
+ 'description' => __( 'Unique identifier for the object.' ),
117
+ 'type' => 'array',
118
+ 'context' => [ 'view', 'edit' ],
119
+ 'readonly' => false,
120
+ ],
121
+ ]
122
+ ];
123
+
124
+ $this->schema = $schema;
125
+
126
+ return $this->add_additional_fields_schema( $this->schema );
127
  }
128
+
129
+ /**
130
+ * Retrieves the query params for collections.
131
+ *
132
+ * @return array
133
+ */
134
+ public function get_collection_params() {
135
+ $params = parent::get_collection_params();
136
+
137
+ unset( $params['search'] );
138
+
139
+ return $params;
140
+ }
141
+
142
  }
V5/API/V1/DynamicAttributes.php ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CTXFeed\V5\API\V1;
4
+
5
+ use CTXFeed\V5\API\RestController;
6
+ use \WP_REST_Server;
7
+
8
+ class DynamicAttributes extends RestController {
9
+ private static $attr_lists = [];
10
+ private static $prefix = 'wf_dattribute_';
11
+ /**
12
+ * The single instance of the class
13
+ *
14
+ * @var DynamicAttributes
15
+ *
16
+ */
17
+ protected static $_instance = null;
18
+
19
+ private function __construct() {
20
+ parent::__construct();
21
+ $this->rest_base = 'dynamic_attributes';
22
+ }
23
+
24
+ /**
25
+ * Main DynamicAttributes Instance.
26
+ *
27
+ * Ensures only one instance of DynamicAttributes is loaded or can be loaded.
28
+ *
29
+ * @return DynamicAttributes Main instance
30
+ */
31
+ public static function instance() {
32
+ if ( is_null( self::$_instance ) ) {
33
+ self::$_instance = new self();
34
+ }
35
+
36
+ return self::$_instance;
37
+ }
38
+
39
+ /**
40
+ * Register routes.
41
+ * @return void
42
+ */
43
+ public function register_routes() {
44
+ register_rest_route(
45
+ $this->namespace,
46
+ '/' . $this->rest_base,
47
+ [
48
+ /**
49
+ * @endpoint: wp-json/ctxfeed/v1/dynamic_attributes
50
+ * @description Will get all feed lists
51
+ *
52
+ *
53
+ * @endpoint wp-json/ctxfeed/v1/dynamic_attributes/?page=1&per_page=2
54
+ * @descripton Get paginated value with previous page and next page link
55
+ *
56
+ * @endpoint wp-json/ctxfeed/v1/dynamic_attributes/?name=wf_feed_google_shopping
57
+ * @method GET
58
+ * @descripton Get single attribute
59
+ *
60
+ * @param $name String
61
+ *
62
+ * @param $page Number
63
+ * @param $per_page Number
64
+ */
65
+ [
66
+ 'methods' => WP_REST_Server::READABLE,
67
+ 'callback' => [ $this, 'get_items' ],
68
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
69
+ 'args' => [
70
+ 'name' => [
71
+ 'description' => __( 'feed name', 'woo-feed' ),
72
+ 'type' => 'string',
73
+ 'required' => false,
74
+ 'sanitize_callback' => 'sanitize_text_field',
75
+ 'validate_callback' => 'rest_validate_request_arg',
76
+ ],
77
+ 'page' => [
78
+ 'description' => __( 'Page number', 'woo-feed' ),
79
+ 'type' => 'number',
80
+ 'required' => false,
81
+ 'sanitize_callback' => 'absint',
82
+ 'validate_callback' => 'rest_validate_request_arg',
83
+ ],
84
+ 'per_page' => [
85
+ 'description' => __( 'Per page', 'woo-feed' ),
86
+ 'type' => 'number',
87
+ 'required' => false,
88
+ 'sanitize_callback' => 'absint',
89
+ 'validate_callback' => 'rest_validate_request_arg',
90
+ ],
91
+ ],
92
+ ],
93
+ [
94
+ 'methods' => WP_REST_Server::CREATABLE,
95
+ 'callback' => [ $this, 'create_item' ],
96
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
97
+ 'args' => [],
98
+ ],
99
+ [
100
+ 'methods' => WP_REST_Server::EDITABLE,
101
+ 'callback' => [ $this, 'update_item' ],
102
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
103
+ 'args' => [],
104
+ ],
105
+ /**
106
+ * @endpoint wp-json/ctxfeed/v1/dynamic_attributes/?name=wf_feed_google_shopping
107
+ * @method DELETE
108
+ * @descripton Delete single attribute
109
+ *
110
+ * @param $name String
111
+ */
112
+ [
113
+ 'methods' => WP_REST_Server::DELETABLE,
114
+ 'callback' => [ $this, 'delete_item' ],
115
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
116
+ 'args' => [
117
+ 'name' => [
118
+ 'description' => __( 'feed name', 'woo-feed' ),
119
+ 'type' => 'string',
120
+ 'required' => true,
121
+ 'sanitize_callback' => 'sanitize_text_field',
122
+ 'validate_callback' => 'rest_validate_request_arg',
123
+ ],
124
+ ],
125
+ ],
126
+
127
+ ]
128
+ );
129
+ }
130
+
131
+ /**
132
+ * @param $request
133
+ *
134
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
135
+ */
136
+ public function update_item( $request ) {
137
+ $body = $request->get_body();
138
+ $body = (array) json_decode( $body );
139
+
140
+ if ( ! $this->is_assoc( $body ) ) {
141
+ return $this->error( __( 'Option name is missing!', 'woo-feed' ) );
142
+ }
143
+
144
+ return $this->create_item( $request );
145
+
146
+ }
147
+
148
+ /**
149
+ * @param $request
150
+ *
151
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
152
+ */
153
+ public function delete_item( $request ) {
154
+ $name = $request->get_param( 'name' );
155
+
156
+ if ( get_option( $name ) ) {
157
+ delete_option( $name );
158
+
159
+ return $this->success( sprintf( __( 'Attribute deleted with name: %s', 'woo-feed' ), $name ) );
160
+ }
161
+
162
+ return $this->error( sprintf( __( 'No attribute found with name: %s', 'woo-feed' ), $name ) );
163
+ }
164
+
165
+ /**
166
+ * @param $request
167
+ *
168
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
169
+ */
170
+ public function create_item( $request ) {
171
+ $option_names = [];
172
+ $body = $request->get_body();
173
+ $body = json_decode( $body );
174
+ // Save option name.
175
+ foreach ( $body as $option_name => $value ) {
176
+ if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
177
+ return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
178
+ }
179
+ $value = (array) $value;
180
+ update_option( $option_name, maybe_serialize( $value ) );
181
+ array_push( $option_names, $option_name );
182
+ }
183
+ // Get option name.
184
+ foreach ( $option_names as $option_name ) {
185
+ $data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
186
+ }
187
+ $this->response['data'] = $data;
188
+
189
+ return rest_ensure_response( $this->response );
190
+ }
191
+
192
+ /**
193
+ * @param $request
194
+ *
195
+ * @return \WP_Error|\WP_REST_Response|null
196
+ */
197
+ public function get_item( $request ) {
198
+ $args = $request->get_params();
199
+ $feed_name = $args['name'];
200
+ global $wpdb;
201
+ $attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
202
+ $this::$attr_lists = $attr_lists;
203
+ if ( count( $this::$attr_lists ) && $this->is_prefix_matched( $this::$attr_lists[0]['option_name'], self::$prefix ) ) {
204
+ $item = $this->prepare_item_for_response( $this::$attr_lists[0], $request );
205
+
206
+ return $this->success( $item );
207
+ }
208
+
209
+ return $this->error( sprintf( __( 'Not found with: %s or prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ), $feed_name ) );
210
+ }
211
+
212
+ /**
213
+ *
214
+ * @param \WP_REST_Request $request Full details about the request.
215
+ *
216
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
217
+ */
218
+ public function get_items( $request ) {
219
+ $args = $request->get_params();
220
+ if ( isset( $args['name'] ) ) {
221
+ return $this->get_item( $request );
222
+ }
223
+ global $wpdb;
224
+ $attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", self::$prefix.'%' ), 'ARRAY_A' );
225
+ $this::$attr_lists = $attr_lists;
226
+
227
+ $data = $this->get_lists( $request );
228
+
229
+ $response = rest_ensure_response( $this->response );
230
+ $response = $this->maybe_add_pagination( $args, $data, $response );
231
+
232
+ return $response;
233
+ }
234
+
235
+ /**
236
+ * @param $request
237
+ *
238
+ * @return array
239
+ */
240
+ public function get_lists( $request ) {
241
+ $lists = [];
242
+ foreach ( $this::$attr_lists as $attr_list ) {
243
+ $item = $this->prepare_item_for_response( $attr_list, $request );
244
+ $lists[] = $item;
245
+ }
246
+
247
+ return $lists;
248
+ }
249
+
250
+ /**
251
+ * @param $item
252
+ * @param $request
253
+ *
254
+ * @return void|\WP_Error|\WP_REST_Response
255
+ */
256
+ public function prepare_item_for_response( $item, $request ) {
257
+ $item['option_value'] = maybe_unserialize( get_option( $item['option_name'] ) );
258
+
259
+ return $item;
260
+ }
261
+
262
+ }
V5/API/V1/FeedLists.php CHANGED
@@ -6,20 +6,9 @@ use CTXFeed\V5\API\RestController;
6
  use \WP_REST_Server;
7
 
8
  class FeedLists extends RestController {
9
- /**
10
- * @var $namespace ;
11
- */
12
- public $namespace;
13
- /**
14
- * @var $version ;
15
- */
16
- public $version = 'v1';
17
- /**
18
- * @var $rest_base
19
- */
20
-
21
- protected $rest_base = 'feed_lists';
22
 
 
 
23
  /**
24
  * The single instance of the class
25
  *
@@ -28,9 +17,9 @@ class FeedLists extends RestController {
28
  */
29
  protected static $_instance = null;
30
 
31
- public function __construct() {
32
  parent::__construct();
33
- $this->namespace = 'ctxfeed/' . $this->version;
34
  }
35
 
36
  /**
@@ -61,77 +50,152 @@ class FeedLists extends RestController {
61
  * @endpoint: wp-json/ctxfeed/v1/feed_lists
62
  * @description Will get all feed lists
63
  *
64
- * @endpoint http://localhost/azizulhasan/challan/wp-json/ctxfeed/v1/feed_lists/?status=inactive
 
65
  * @description Only inactive feed lists will be returned.
66
- * @param $status String
67
  *
68
  * @endpoint wp-json/ctxfeed/v1/feed_lists/?status=active
 
69
  * @description Only active feed lists will be returned.
 
 
 
 
 
 
 
 
 
 
 
70
  * @param $status String
 
 
71
  */
72
  [
73
  'methods' => WP_REST_Server::READABLE,
74
- 'callback' => [ $this, 'get_feed_lists' ],
75
  'permission_callback' => [ $this, 'get_item_permissions_check' ],
76
  'args' => [
77
- 'status' => [
78
- 'description' => __( 'Is active or inactive', 'woo-feed' ),
79
- 'type' => 'string',
80
- 'required' => false
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  ],
82
  ],
83
- ],
84
  ]
85
  );
86
  }
87
 
88
  /**
89
- *
90
  * @param $request
91
  *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
93
  */
94
- public function get_feed_lists( $request ) {
95
- $status = $request->get_param( 'status' );
 
 
 
 
96
  global $wpdb;
97
- $feed_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", 'wf_feed_%' ), 'ARRAY_A' );
98
-
99
- if ( $status ) {
100
- /**
101
- * True if status is active/inactive
102
- */
103
- if ( 'active' === $status || 'inactive' === $status ) {
104
- $this->response['data'] = $this->get_lists( $feed_lists, $status );
105
  } else {
106
- $this->error( __( 'Status should be active/inactive !', 'woo-feed' ) );
107
  }
108
  } else {
109
- $this->response['data'] = $this->get_lists( $feed_lists );
110
  }
111
 
112
- return rest_ensure_response( $this->response );
 
 
 
113
  }
114
 
115
- public function get_lists( $feed_lists, $status = '' ) {
116
  $lists = [];
117
- if ( $status ) {
118
- foreach ( $feed_lists as $feed_list ) {
119
- $feed_list['option_value'] = maybe_unserialize( get_option( $feed_list['option_name'] ) );
120
- if ( 'active' === $status && 1 === $feed_list['option_value']['status'] ) {
121
- $lists[] = $feed_list;
 
122
  }
123
- if ( 'inactive' === $status && 0 === $feed_list['option_value']['status'] ) {
124
- $lists[] = $feed_list;
125
  }
126
- }
127
- } else {
128
- foreach ( $feed_lists as $feed_list ) {
129
- $feed_list['option_value'] = maybe_unserialize( get_option( $feed_list['option_name'] ) );
130
- $lists[] = $feed_list;
131
  }
132
  }
133
 
134
  return $lists;
135
  }
136
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  }
6
  use \WP_REST_Server;
7
 
8
  class FeedLists extends RestController {
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ private static $status = null;
11
+ private static $feed_lists = [];
12
  /**
13
  * The single instance of the class
14
  *
17
  */
18
  protected static $_instance = null;
19
 
20
+ private function __construct() {
21
  parent::__construct();
22
+ $this->rest_base = 'feed_lists';
23
  }
24
 
25
  /**
50
  * @endpoint: wp-json/ctxfeed/v1/feed_lists
51
  * @description Will get all feed lists
52
  *
53
+ * @endpoint wp-json/ctxfeed/v1/feed_lists/?status=inactive
54
+ * @method GET
55
  * @description Only inactive feed lists will be returned.
56
+ *
57
  *
58
  * @endpoint wp-json/ctxfeed/v1/feed_lists/?status=active
59
+ * @method GET
60
  * @description Only active feed lists will be returned.
61
+ *
62
+ * @endpoint wp-json/ctxfeed/v1/feed_lists/?status=active&page=1&per_page=2
63
+ * @method GET
64
+ * @descripton Get paginated value with previous page and next page link
65
+ *
66
+ *
67
+ * @endpoint wp-json/ctxfeed/v1/feed_lists/?name=wf_feed_google_shopping
68
+ * @method GET
69
+ * @descripton Get single feed
70
+ * @param $name String
71
+ *
72
  * @param $status String
73
+ * @param $page Number
74
+ * @param $per_page Number
75
  */
76
  [
77
  'methods' => WP_REST_Server::READABLE,
78
+ 'callback' => [ $this, 'get_items' ],
79
  'permission_callback' => [ $this, 'get_item_permissions_check' ],
80
  'args' => [
81
+ 'status' => [
82
+ 'description' => __( 'Is active or inactive', 'woo-feed' ),
83
+ 'type' => 'string',
84
+ 'required' => false,
85
+ 'sanitize_callback' => 'sanitize_text_field',
86
+ 'validate_callback' => 'rest_validate_request_arg',
87
+ ],
88
+ 'name' => [
89
+ 'description' => __( 'feed name', 'woo-feed' ),
90
+ 'type' => 'string',
91
+ 'required' => false,
92
+ 'sanitize_callback' => 'sanitize_text_field',
93
+ 'validate_callback' => 'rest_validate_request_arg',
94
+ ],
95
+ 'page' => [
96
+ 'description' => __( 'Page number', 'woo-feed' ),
97
+ 'type' => 'number',
98
+ 'required' => false,
99
+ 'sanitize_callback' => 'absint',
100
+ 'validate_callback' => 'rest_validate_request_arg',
101
+ ],
102
+ 'per_page' => [
103
+ 'description' => __( 'Per page', 'woo-feed' ),
104
+ 'type' => 'number',
105
+ 'required' => false,
106
+ 'sanitize_callback' => 'absint',
107
+ 'validate_callback' => 'rest_validate_request_arg',
108
  ],
109
  ],
110
+ ]
111
  ]
112
  );
113
  }
114
 
115
  /**
 
116
  * @param $request
117
  *
118
+ * @return \WP_Error|\WP_REST_Response|null
119
+ */
120
+ public function get_item( $request ) {
121
+ $args = $request->get_params();
122
+ $feed_name = $args['name'];
123
+ global $wpdb;
124
+ $feed_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
125
+ $this::$feed_lists = $feed_lists;
126
+ if( count( $this::$feed_lists ) ) {
127
+ $item = $this->prepare_item_for_response( $this::$feed_lists[0], $request );
128
+ return $this->success( $item );
129
+ }
130
+
131
+ return $this->error( sprintf( __( 'Not found with: %s ', 'woo-feed' ), $feed_name ) );
132
+ }
133
+
134
+ /**
135
+ *
136
+ * @param \WP_REST_Request $request Full details about the request.
137
+ *
138
  * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
139
  */
140
+ public function get_items( $request ) {
141
+ $args = $request->get_params();
142
+ $this::$status = isset( $args['status'] ) ? $args['status'] : $this::$status;
143
+ if ( isset( $args['name'] ) ) {
144
+ return $this->get_item( $request );
145
+ }
146
  global $wpdb;
147
+ $feed_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", 'wf_feed_%' ), 'ARRAY_A' );
148
+ $this::$feed_lists = $feed_lists;
149
+ if ( $this::$status ) {
150
+ // True if status is active/inactive
151
+ if ( 'active' === $this::$status || 'inactive' === $this::$status ) {
152
+ $data = $this->get_lists( $request );
 
 
153
  } else {
154
+ return $this->error( __( 'Status should be active/inactive !', 'woo-feed' ) );
155
  }
156
  } else {
157
+ $data = $this->get_lists( $request );
158
  }
159
 
160
+ $response = rest_ensure_response( $this->response );
161
+ $response = $this->maybe_add_pagination( $args, $data, $response );
162
+
163
+ return $response;
164
  }
165
 
166
+ public function get_lists( $request ) {
167
  $lists = [];
168
+ foreach ( $this::$feed_lists as $feed_list ) {
169
+ $item = $this->prepare_item_for_response( $feed_list, $request );
170
+ if ( $this::$status ) {
171
+ if ( is_object( $item['option_value'] ) ) {
172
+ $lists[] = $item;
173
+ continue;
174
  }
175
+ if ( 'active' === $this::$status && 1 === $item['option_value']['status'] ) {
176
+ $lists[] = $item;
177
  }
178
+ if ( 'inactive' === $this::$status && 0 === $item['option_value']['status'] ) {
179
+ $lists[] = $item;
180
+ }
181
+ } else {
182
+ $lists[] = $item;
183
  }
184
  }
185
 
186
  return $lists;
187
  }
188
 
189
+ /**
190
+ * @param $item
191
+ * @param $request
192
+ *
193
+ * @return void|\WP_Error|\WP_REST_Response
194
+ */
195
+ public function prepare_item_for_response( $item, $request ) {
196
+ $item['option_value'] = maybe_unserialize( get_option( $item['option_name'] ) );
197
+
198
+ return $item;
199
+ }
200
+
201
  }
V5/API/V1/MerchantConfig.php CHANGED
@@ -2,8 +2,6 @@
2
 
3
  namespace CTXFeed\V5\API\V1;
4
 
5
- namespace CTXFeed\V5\API\V1;
6
-
7
  use CTXFeed\V5\API\RestController;
8
  use CTXFeed\V5\Helper\FeedHelper;
9
  use CTXFeed\V5\Merchant\TemplateConfig;
@@ -13,20 +11,6 @@ use WP_REST_Server;
13
  //TODO: Custom Template 2 React/Js Output Rendering test.
14
 
15
  class MerchantConfig extends RestController {
16
- /**
17
- * @var $namespace ;
18
- */
19
- public $namespace;
20
- /**
21
- * @var $version ;
22
- */
23
- public $version = 'v1';
24
- /**
25
- * @var $rest_base
26
- */
27
-
28
- protected $rest_base = 'merchant_config';
29
-
30
  /**
31
  * The single instance of the class
32
  *
@@ -35,9 +19,9 @@ class MerchantConfig extends RestController {
35
  */
36
  protected static $_instance = null;
37
 
38
- public function __construct() {
39
  parent::__construct();
40
- $this->namespace = 'ctxfeed/' . $this->version;
41
  }
42
 
43
  /**
@@ -67,39 +51,60 @@ class MerchantConfig extends RestController {
67
  [
68
  /**
69
  * @endpoint: wp-json/ctxfeed/v1/merchant_config/?feed=wf_feed_google_shopping_33&type=edit
 
70
  * @description It used for editing. Will get feed configuration based $type and $feed file name.
 
71
  * @param $feed String feed file name
72
  * @param $type String feed type edit/add
73
  *
74
  *
75
  * @endpoint wp-json/ctxfeed/v1/merchant_config/?merchant=google&type=add
 
76
  * @description It used for adding. Will get feed d configuration based $merchant name and $type.
 
77
  * @param $type String feed type edit/add
78
  * @param $merchant String merchant name
79
  *
80
  */
81
  [
82
  'methods' => WP_REST_Server::READABLE,
83
- 'callback' => [ $this, 'get_merchant_config' ],
84
  'permission_callback' => [ $this, 'get_item_permissions_check' ],
85
  'args' => [
86
  'merchant' => [
87
- 'description' => __( 'Merchant name', 'woo-feed' ),
88
- 'type' => 'string',
89
- 'required' => false
 
 
90
  ],
91
  'type' => [
92
- 'description' => __( 'Edit or Add', 'woo-feed' ),
93
- 'type' => 'string',
94
- 'required' => true
 
 
95
  ],
96
  'feed' => [
97
- 'description' => __( 'feed file name', 'woo-feed' ),
98
- 'type' => 'string',
99
- 'required' => false
 
 
100
  ]
101
  ],
102
  ],
 
 
 
 
 
 
 
 
 
 
 
103
  ]
104
  );
105
  }
@@ -110,7 +115,7 @@ class MerchantConfig extends RestController {
110
  *
111
  * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
112
  */
113
- public function get_merchant_config( $request ) {
114
  $merchant = $request->get_param( 'merchant' );
115
  /**
116
  * Configuration type Example: add/edit
@@ -119,38 +124,54 @@ class MerchantConfig extends RestController {
119
  */
120
  $type = $request->get_param( 'type' );
121
  if ( 'add' === $type ) {
122
- /**
123
- * Get Feed merchant configuration like : itemWrapper, itemsWrapper, delimiter, extraHeader etc.
124
- */
125
  $defaultMerchantConfig = TemplateConfig::get( $merchant );
126
  $defaultMerchantConfig['provider'] = $merchant;
127
  $merchant = new Config( $defaultMerchantConfig );
128
  $merchant_config = $merchant->get_config();
129
 
130
- $this->success( $merchant_config );
131
 
132
  } elseif ( 'edit' === $type ) {
133
  $feedName = $request->get_param( 'feed' );
134
- /**
135
- * True if feed name is missing
136
- */
137
  if ( ! $feedName ) {
138
- $this->error( __( 'Feed file name missing!', 'woo-feed' ) );
139
-
140
- return rest_ensure_response( $this->response );
141
  }
142
 
143
  $feedName = FeedHelper::get_feed_option_name( $feedName );
144
  $feedInfo = get_option( 'wf_config' . $feedName, false );
145
 
146
  if ( $feedInfo ) {
147
- $this->success( $feedInfo );
148
  } else {
149
- $this->error( sprintf( __( 'No configuration found with this feed name: %s', 'woo-feed' ), $feedName ) );
150
  }
151
  }
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
- return rest_ensure_response( $this->response );
155
  }
156
  }
2
 
3
  namespace CTXFeed\V5\API\V1;
4
 
 
 
5
  use CTXFeed\V5\API\RestController;
6
  use CTXFeed\V5\Helper\FeedHelper;
7
  use CTXFeed\V5\Merchant\TemplateConfig;
11
  //TODO: Custom Template 2 React/Js Output Rendering test.
12
 
13
  class MerchantConfig extends RestController {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  /**
15
  * The single instance of the class
16
  *
19
  */
20
  protected static $_instance = null;
21
 
22
+ private function __construct() {
23
  parent::__construct();
24
+ $this->rest_base = 'merchant_config';
25
  }
26
 
27
  /**
51
  [
52
  /**
53
  * @endpoint: wp-json/ctxfeed/v1/merchant_config/?feed=wf_feed_google_shopping_33&type=edit
54
+ * @method GET
55
  * @description It used for editing. Will get feed configuration based $type and $feed file name.
56
+ *
57
  * @param $feed String feed file name
58
  * @param $type String feed type edit/add
59
  *
60
  *
61
  * @endpoint wp-json/ctxfeed/v1/merchant_config/?merchant=google&type=add
62
+ * @method GET
63
  * @description It used for adding. Will get feed d configuration based $merchant name and $type.
64
+ *
65
  * @param $type String feed type edit/add
66
  * @param $merchant String merchant name
67
  *
68
  */
69
  [
70
  'methods' => WP_REST_Server::READABLE,
71
+ 'callback' => [ $this, 'get_item' ],
72
  'permission_callback' => [ $this, 'get_item_permissions_check' ],
73
  'args' => [
74
  'merchant' => [
75
+ 'description' => __( 'Merchant name', 'woo-feed' ),
76
+ 'type' => 'string',
77
+ 'required' => false,
78
+ 'sanitize_callback' => 'sanitize_text_field',
79
+ 'validate_callback' => 'rest_validate_request_arg',
80
  ],
81
  'type' => [
82
+ 'description' => __( 'Edit or Add', 'woo-feed' ),
83
+ 'type' => 'string',
84
+ 'required' => true,
85
+ 'sanitize_callback' => 'sanitize_text_field',
86
+ 'validate_callback' => 'rest_validate_request_arg',
87
  ],
88
  'feed' => [
89
+ 'description' => __( 'feed file name', 'woo-feed' ),
90
+ 'type' => 'string',
91
+ 'required' => false,
92
+ 'sanitize_callback' => 'sanitize_text_field',
93
+ 'validate_callback' => 'rest_validate_request_arg',
94
  ]
95
  ],
96
  ],
97
+ /**
98
+ * @endpoint wp-json/ctxfeed/v1/merchant_config
99
+ * @method GET
100
+ * @body json array config file name as key and config as value.
101
+ */
102
+ [
103
+ 'methods' => WP_REST_Server::CREATABLE,
104
+ 'callback' => [ $this, 'create_item' ],
105
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
106
+ 'args' => [],
107
+ ],
108
  ]
109
  );
110
  }
115
  *
116
  * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
117
  */
118
+ public function get_item( $request ) {
119
  $merchant = $request->get_param( 'merchant' );
120
  /**
121
  * Configuration type Example: add/edit
124
  */
125
  $type = $request->get_param( 'type' );
126
  if ( 'add' === $type ) {
127
+ // Get Feed merchant configuration like : itemWrapper, itemsWrapper, delimiter, extraHeader etc.
 
 
128
  $defaultMerchantConfig = TemplateConfig::get( $merchant );
129
  $defaultMerchantConfig['provider'] = $merchant;
130
  $merchant = new Config( $defaultMerchantConfig );
131
  $merchant_config = $merchant->get_config();
132
 
133
+ return $this->success( $merchant_config );
134
 
135
  } elseif ( 'edit' === $type ) {
136
  $feedName = $request->get_param( 'feed' );
137
+ // True if feed name is missing
 
 
138
  if ( ! $feedName ) {
139
+ return $this->error( __( 'Feed file name missing!', 'woo-feed' ) );
 
 
140
  }
141
 
142
  $feedName = FeedHelper::get_feed_option_name( $feedName );
143
  $feedInfo = get_option( 'wf_config' . $feedName, false );
144
 
145
  if ( $feedInfo ) {
146
+ return $this->success( $feedInfo );
147
  } else {
148
+ return $this->error( sprintf( __( 'No configuration found with this feed name: %s', 'woo-feed' ), $feedName ) );
149
  }
150
  }
151
 
152
+ return $this->error( __( 'Type must be either edit/add.', 'woo-feed' ) );
153
+ }
154
+
155
+ /**
156
+ * @param $request
157
+ *
158
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
159
+ */
160
+ public function create_item( $request ) {
161
+ $option_names = [];
162
+ $body = $request->get_body();
163
+ $body = json_decode( $body );
164
+ // Save option name.
165
+ foreach ( $body as $option_name => $value ) {
166
+ $value = (array) $value;
167
+ update_option( $option_name, $value );
168
+ array_push( $option_names, $option_name );
169
+ }
170
+ // Get option name.
171
+ foreach ( $option_names as $option_name ) {
172
+ $data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
173
+ }
174
 
175
+ return $this->success( $data );
176
  }
177
  }
V5/API/V1/MerchantInfo.php CHANGED
@@ -9,19 +9,6 @@ use CTXFeed\V5\Merchant\TemplateInfo;
9
  use WP_REST_Server;
10
 
11
  class MerchantInfo extends RestController {
12
- /**
13
- * @var $namespace ;
14
- */
15
- public $namespace;
16
- /**
17
- * @var $version ;
18
- */
19
- public $version = 'v1';
20
- /**
21
- * @var $rest_base
22
- */
23
-
24
- protected $rest_base = 'merchant_info';
25
 
26
  /**
27
  * The single instance of the class
@@ -31,9 +18,9 @@ class MerchantInfo extends RestController {
31
  */
32
  protected static $_instance = null;
33
 
34
- public function __construct() {
35
  parent::__construct();
36
- $this->namespace = 'ctxfeed/' . $this->version;
37
  }
38
 
39
  /**
9
  use WP_REST_Server;
10
 
11
  class MerchantInfo extends RestController {
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  /**
14
  * The single instance of the class
18
  */
19
  protected static $_instance = null;
20
 
21
+ private function __construct() {
22
  parent::__construct();
23
+ $this->rest_base = 'merchant_info';
24
  }
25
 
26
  /**
V5/API/V1/ProductCategories.php CHANGED
@@ -6,19 +6,6 @@ use CTXFeed\V5\API\RestController;
6
  use \WP_REST_Server;
7
 
8
  class ProductCategories extends RestController {
9
- /**
10
- * @var $namespace ;
11
- */
12
- public $namespace;
13
- /**
14
- * @var $version ;
15
- */
16
- public $version = 'v1';
17
- /**
18
- * @var $rest_base
19
- */
20
-
21
- protected $rest_base = 'categories';
22
 
23
  /**
24
  * The single instance of the class
@@ -28,9 +15,9 @@ class ProductCategories extends RestController {
28
  */
29
  protected static $_instance = null;
30
 
31
- public function __construct() {
32
  parent::__construct();
33
- $this->namespace = 'ctxfeed/' . $this->version;
34
  }
35
 
36
  /**
@@ -58,7 +45,7 @@ class ProductCategories extends RestController {
58
  '/' . $this->rest_base,
59
  [
60
  /**
61
- * @endpoint wp-json/ctxfeed/v1/categories/?search=hoo
62
  * @description will return all categories based on search string.
63
  * @param $search String
64
  *
6
  use \WP_REST_Server;
7
 
8
  class ProductCategories extends RestController {
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  /**
11
  * The single instance of the class
15
  */
16
  protected static $_instance = null;
17
 
18
+ private function __construct() {
19
  parent::__construct();
20
+ $this->rest_base = 'product_categories';
21
  }
22
 
23
  /**
45
  '/' . $this->rest_base,
46
  [
47
  /**
48
+ * @endpoint wp-json/ctxfeed/v1/product_categories/?search=hoo
49
  * @description will return all categories based on search string.
50
  * @param $search String
51
  *
V5/API/V1/ProductTaxonomy.php CHANGED
@@ -8,19 +8,6 @@ use PhpParser\Node\Scalar\String_;
8
  use WP_REST_Server;
9
 
10
  class ProductTaxonomy extends RestController {
11
- /**
12
- * @var $namespace ;
13
- */
14
- public $namespace;
15
- /**
16
- * @var $version ;
17
- */
18
- public $version = 'v1';
19
- /**
20
- * @var $rest_base
21
- */
22
-
23
- protected $rest_base = 'taxonomies';
24
 
25
  /**
26
  * Default country code
@@ -48,9 +35,9 @@ class ProductTaxonomy extends RestController {
48
  */
49
  protected static $_instance = null;
50
 
51
- public function __construct() {
52
  parent::__construct();
53
- $this->namespace = 'ctxfeed/' . $this->version;
54
  }
55
 
56
  /**
@@ -74,12 +61,12 @@ class ProductTaxonomy extends RestController {
74
  '/' . $this->rest_base,
75
  [
76
  /**
77
- * @endpoint wp-json/ctxfeed/v1/taxonomies/?country_code=en-US&merchant=google
78
  * @description will return stored merchant data.
79
  * @param $country_code
80
  * @param $merchant
81
  *
82
- * @endpoint wp-json/ctxfeed/v1/taxonomies/?country_code=en-US&merchant=google&update=true
83
  * @description Download merchant taxonomy file.
84
  * @param $country_code String
85
  * @param $merchant Stirng
8
  use WP_REST_Server;
9
 
10
  class ProductTaxonomy extends RestController {
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  /**
13
  * Default country code
35
  */
36
  protected static $_instance = null;
37
 
38
+ private function __construct() {
39
  parent::__construct();
40
+ $this->rest_base = 'product_taxonomy';
41
  }
42
 
43
  /**
61
  '/' . $this->rest_base,
62
  [
63
  /**
64
+ * @endpoint wp-json/ctxfeed/v1/product_taxonomy/?country_code=en-US&merchant=google
65
  * @description will return stored merchant data.
66
  * @param $country_code
67
  * @param $merchant
68
  *
69
+ * @endpoint wp-json/ctxfeed/v1/product_taxonomy/?country_code=en-US&merchant=google&update=true
70
  * @description Download merchant taxonomy file.
71
  * @param $country_code String
72
  * @param $merchant Stirng
V5/API/V1/ProductTitles.php CHANGED
@@ -6,20 +6,6 @@ use CTXFeed\V5\API\RestController;
6
  use \WP_REST_Server;
7
 
8
  class ProductTitles extends RestController {
9
- /**
10
- * @var $namespace ;
11
- */
12
- public $namespace;
13
- /**
14
- * @var $version ;
15
- */
16
- public $version = 'v1';
17
- /**
18
- * @var $rest_base
19
- */
20
-
21
- protected $rest_base = 'product_titles';
22
-
23
  /**
24
  * The single instance of the class
25
  *
@@ -28,9 +14,9 @@ class ProductTitles extends RestController {
28
  */
29
  protected static $_instance = null;
30
 
31
- public function __construct() {
32
  parent::__construct();
33
- $this->namespace = 'ctxfeed/' . $this->version;
34
  }
35
 
36
  /**
@@ -98,9 +84,8 @@ class ProductTitles extends RestController {
98
  $handle = wc_get_product( $id );
99
  $search_results[ $id ] = strip_tags( $handle->get_formatted_name() );
100
  }
101
- $this->success( [ $search_results ] );
102
 
103
- return rest_ensure_response( $this->response );
104
  }
105
 
106
  }
6
  use \WP_REST_Server;
7
 
8
  class ProductTitles extends RestController {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  /**
10
  * The single instance of the class
11
  *
14
  */
15
  protected static $_instance = null;
16
 
17
+ private function __construct() {
18
  parent::__construct();
19
+ $this->rest_base = 'product_titles';
20
  }
21
 
22
  /**
84
  $handle = wc_get_product( $id );
85
  $search_results[ $id ] = strip_tags( $handle->get_formatted_name() );
86
  }
 
87
 
88
+ return $this->success( [ $search_results ] );
89
  }
90
 
91
  }
V5/API/V1/Settings.php ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CTXFeed\V5\API\V1;
4
+
5
+ use CTXFeed\V5\API\RestController;
6
+ use CTXFeed\V5\Helper\CustomFieldHelper;
7
+ use \WP_REST_Server;
8
+
9
+ class Settings extends RestController {
10
+ private static $settings_lists = [];
11
+ /**
12
+ * @var string
13
+ */
14
+ private static $option_name = 'woo_feed_settings';
15
+ /**
16
+ * The single instance of the class
17
+ *
18
+ * @var Settings
19
+ *
20
+ */
21
+ protected static $_instance = null;
22
+
23
+ private function __construct() {
24
+ parent::__construct();
25
+ $this->rest_base = 'settings';
26
+ }
27
+
28
+ /**
29
+ * Main Settings Instance.
30
+ *
31
+ * Ensures only one instance of Settings is loaded or can be loaded.
32
+ *
33
+ * @return Settings Main instance
34
+ */
35
+ public static function instance() {
36
+ if ( is_null( self::$_instance ) ) {
37
+ self::$_instance = new self();
38
+ }
39
+
40
+ return self::$_instance;
41
+ }
42
+
43
+ /**
44
+ * Register routes.
45
+ * @return void
46
+ */
47
+ public function register_routes() {
48
+ // Default settings
49
+ register_rest_route(
50
+ $this->namespace,
51
+ '/' . $this->rest_base,
52
+ [
53
+ /**
54
+ *
55
+ * @endpoint wp-json/ctxfeed/v1/settings
56
+ * @method GET
57
+ * @descripton Get single attribute
58
+ *
59
+ * @param $name String
60
+ *
61
+ * @param $page Number
62
+ * @param $per_page Number
63
+ */
64
+ [
65
+ 'methods' => WP_REST_Server::READABLE,
66
+ 'callback' => [ $this, 'get_item' ],
67
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
68
+ 'args' => [],
69
+ ],
70
+ [
71
+ 'methods' => WP_REST_Server::EDITABLE,
72
+ 'callback' => [ $this, 'update_item' ],
73
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
74
+ 'args' => [],
75
+ ],
76
+ 'schema' => [ $this, 'get_item_schema' ],
77
+ ],
78
+
79
+ );
80
+ // Custom Fields
81
+ register_rest_route(
82
+ $this->namespace, '/' . $this->rest_base . '/custom_settings',
83
+ /**
84
+ * @endpoint wp-json/ctxfeed/v1/settings/custom_settings
85
+ * @method GET
86
+ * @descripton get custom settings
87
+ *
88
+ * @param $name String
89
+ */
90
+ [
91
+ [
92
+ 'methods' => WP_REST_Server::READABLE,
93
+ 'callback' => [ $this, 'get_custom_fields' ],
94
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
95
+ 'args' => [],
96
+ ]
97
+ ],
98
+ );
99
+ }
100
+
101
+ /**
102
+ * @param $request \WP_REST_Request request body will be []
103
+ *
104
+ *
105
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
106
+ */
107
+ public function get_custom_fields( $request ) {
108
+ $custom_fields = CustomFieldHelper::get_fields();
109
+
110
+ return $this->success( $custom_fields );
111
+ }
112
+
113
+ /**
114
+ * @param $request
115
+ *
116
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
117
+ */
118
+ public function update_item( $request ) {
119
+ $body = $request->get_body();
120
+ $body = self::json_decode( $body );
121
+ update_option( self::$option_name, $body );
122
+ self::$settings_lists = get_option( self::$option_name, [] );
123
+
124
+ return $this->success( self::$settings_lists );
125
+ }
126
+
127
+ private static function json_decode( $body ) {
128
+ $arr = (array) json_decode( $body );
129
+ foreach ( $arr as &$value ) {
130
+ if ( is_object( $value ) ) {
131
+ $value = (array) $value;
132
+ } elseif ( is_string( $value ) ) {
133
+ $value = (string) $value;
134
+ } elseif ( is_array( $value ) ) {
135
+ $value = (array) $value;
136
+ } elseif ( is_int( $value ) ) {
137
+ $value = (int) $value;
138
+ }
139
+ }
140
+
141
+ return $arr;
142
+ }
143
+
144
+ /**
145
+ *
146
+ * @param \WP_REST_Request $request Full details about the request.
147
+ *
148
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
149
+ */
150
+ public function get_item( $request ) {
151
+ self::$settings_lists = \CTXFeed\V5\Utility\Settings::get( 'all' );
152
+
153
+ return $this->success( self::$settings_lists );
154
+ }
155
+
156
+
157
+ /**
158
+ * Get our sample schema for comments.
159
+ */
160
+ public function get_item_schema() {
161
+ if( $this->schema ) {
162
+ return $this->add_additional_fields_schema( $this->schema );
163
+ }
164
+ $schema = array(
165
+ // This tells the spec of JSON Schema we are using which is draft 4.
166
+ '$schema' => 'http://json-schema.org/draft-04/schema#',
167
+ // The title property marks the identity of the resource.
168
+ 'title' => 'comment',
169
+ 'type' => 'object',
170
+ // In JSON Schema you can specify object properties in the properties attribute.
171
+ 'properties' => array(
172
+ 'id' => array(
173
+ 'description' => esc_html__( 'Unique identifier for the object.', 'my-textdomain' ),
174
+ 'type' => 'integer',
175
+ 'context' => array( 'view', 'edit', 'embed' ),
176
+ 'readonly' => true,
177
+ ),
178
+ 'author' => array(
179
+ 'description' => esc_html__( 'The id of the user object, if author was a user.', 'my-textdomain' ),
180
+ 'type' => 'integer',
181
+ ),
182
+ 'content' => array(
183
+ 'description' => esc_html__( 'The content for the object.', 'my-textdomain' ),
184
+ 'type' => 'string',
185
+ ),
186
+ ),
187
+ );
188
+
189
+ $this->schema = $schema;
190
+
191
+ return $this->add_additional_fields_schema( $this->schema );
192
+ }
193
+
194
+ }
V5/API/V1/WPOptions.php ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CTXFeed\V5\API\V1;
4
+
5
+ use CTXFeed\V5\API\RestController;
6
+ use \WP_REST_Server;
7
+
8
+ class WPOptions extends RestController {
9
+ private static $option_lists = [];
10
+ /**
11
+ * @var string
12
+ */
13
+ private static $option_name = 'wpfp_option';
14
+ /**
15
+ * @var string
16
+ */
17
+ private static $prefix = 'wf_option_';
18
+ /**
19
+ * The single instance of the class
20
+ *
21
+ * @var WPOptions
22
+ *
23
+ */
24
+ protected static $_instance = null;
25
+
26
+ private function __construct() {
27
+ parent::__construct();
28
+ $this->rest_base = 'wp_options';
29
+ }
30
+
31
+ /**
32
+ * Main WPOptions Instance.
33
+ *
34
+ * Ensures only one instance of WPOptions is loaded or can be loaded.
35
+ *
36
+ * @return WPOptions Main instance
37
+ */
38
+ public static function instance() {
39
+ if ( is_null( self::$_instance ) ) {
40
+ self::$_instance = new self();
41
+ }
42
+
43
+ return self::$_instance;
44
+ }
45
+
46
+ /**
47
+ * Register routes.
48
+ * @return void
49
+ */
50
+ public function register_routes() {
51
+ register_rest_route(
52
+ $this->namespace,
53
+ '/' . $this->rest_base,
54
+ [
55
+ /**
56
+ * @endpoint: wp-json/ctxfeed/v1/wp_options
57
+ * @description Will get all feed lists
58
+ *
59
+ *
60
+ * @endpoint wp-json/ctxfeed/v1/wp_options/?page=1&per_page=2
61
+ * @descripton Get paginated value with previous page and next page link
62
+ *
63
+ * @endpoint wp-json/ctxfeed/v1/wp_options/?name=wf_feed_google_shopping
64
+ * @method GET
65
+ * @descripton Get single attribute
66
+ *
67
+ * @param $name String
68
+ *
69
+ * @param $page Number
70
+ * @param $per_page Number
71
+ */
72
+ [
73
+ 'methods' => WP_REST_Server::READABLE,
74
+ 'callback' => [ $this, 'get_items' ],
75
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
76
+ 'args' => [
77
+ 'page' => [
78
+ 'description' => __( 'Page number', 'woo-feed' ),
79
+ 'type' => 'number',
80
+ 'required' => false,
81
+ 'sanitize_callback' => 'absint',
82
+ 'validate_callback' => 'rest_validate_request_arg',
83
+ ],
84
+ 'per_page' => [
85
+ 'description' => __( 'Per page', 'woo-feed' ),
86
+ 'type' => 'number',
87
+ 'required' => false,
88
+ 'sanitize_callback' => 'absint',
89
+ 'validate_callback' => 'rest_validate_request_arg',
90
+ ],
91
+ ],
92
+ ],
93
+ [
94
+ 'methods' => WP_REST_Server::CREATABLE,
95
+ 'callback' => [ $this, 'create_item' ],
96
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
97
+ 'args' => [],
98
+ ],
99
+ /**
100
+ * @endpoint wp-json/ctxfeed/v1/wp_options/?name=wf_feed_google_shopping
101
+ * @method DELETE
102
+ * @descripton Delete single attribute
103
+ *
104
+ * @param $name String
105
+ */
106
+ [
107
+ 'methods' => WP_REST_Server::DELETABLE,
108
+ 'callback' => [ $this, 'delete_item' ],
109
+ 'permission_callback' => [ $this, 'get_item_permissions_check' ],
110
+ 'args' => [],
111
+ ],
112
+ ],
113
+ );
114
+ }
115
+
116
+ /**
117
+ * @param $request \WP_REST_Request request body will be []
118
+ *
119
+ *
120
+ * @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
121
+ */
122
+ public function delete_item( $request ) {
123
+ $body = $request->get_body();
124
+ $body = json_decode( $body );
125
+ $this::set_option();
126
+
127
+ foreach ( $body as $option ) {
128
+ if ( isset( self::$option_lists[ $option ] ) ) {
129
+ unset( self::$option_lists[ $option ] );
130
+ }
131
+ }
132
+ self::update_option( self::$option_lists );
133
+
134
+ return $this->success( self::$option_lists );
135
+ }
136
+
137
+ /**
138
+ * @param $request
139
+ *
140
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
141
+ */
142
+ public function create_item( $request ) {
143
+ $body = $request->get_body();
144
+ $body = json_decode( $body );
145
+ $this::set_option();
146
+ // Save option name.
147
+ foreach ( $body as $index => $name ) {
148
+ $option_name = self::$prefix . $name;
149
+ if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
150
+ return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
151
+ }
152
+ self::$option_lists[ $name ] = [
153
+ 'option_id' => $name,
154
+ 'option_name' => $option_name,
155
+ ];
156
+ }
157
+ // Get option name.
158
+ $this::update_option( self::$option_lists );
159
+
160
+ return $this->success( self::$option_lists );
161
+ }
162
+
163
+
164
+ /**
165
+ *
166
+ * @param \WP_REST_Request $request Full details about the request.
167
+ *
168
+ * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
169
+ */
170
+ public function get_items( $request ) {
171
+ $args = $request->get_params();
172
+ if ( isset( $args['name'] ) ) {
173
+ return $this->get_item( $request );
174
+ }
175
+ $this::set_option();
176
+
177
+ $response = rest_ensure_response( $this->response );
178
+ $response = $this->maybe_add_pagination( $args, $this::$option_lists, $response );
179
+
180
+ return $response;
181
+ }
182
+
183
+ /**
184
+ * @return void
185
+ */
186
+ private static function set_option() {
187
+ self::$option_lists = get_option( self::$option_name, [] );
188
+ }
189
+
190
+ /**
191
+ * @param $option_lists
192
+ *
193
+ * @return void
194
+ */
195
+ private static function update_option( $option_lists = [] ) {
196
+ update_option( self::$option_name, $option_lists );
197
+ self::set_option();
198
+ }
199
+ }
V5/Helper/CommonHelper.php CHANGED
@@ -1,10 +1,11 @@
1
  <?php
2
  namespace CTXFeed\V5\Helper;
 
3
  class CommonHelper {
4
 
5
 
6
  public static function supported_product_types() {
7
- return [
8
  'simple',
9
  'variable',
10
  'variation',
@@ -18,7 +19,7 @@ class CommonHelper {
18
  'subscription',
19
  'variable-subscription',
20
  'woosb',
21
- ];
22
  }
23
 
24
  public static function remove_shortcodes( $content ) {
@@ -40,16 +41,15 @@ class CommonHelper {
40
 
41
  public static function add_utm_parameter( $utm, $url ) {
42
 
43
-
44
  if ( ! empty( $utm['utm_source'] ) && ! empty( $utm['utm_medium'] ) && ! empty( $utm['utm_campaign'] ) ) {
45
 
46
- $utm = [
47
  'utm_source' => str_replace( ' ', '+', $utm['utm_source'] ),
48
  'utm_medium' => str_replace( ' ', '+', $utm['utm_medium'] ),
49
  'utm_campaign' => str_replace( ' ', '+', $utm['utm_campaign'] ),
50
  'utm_term' => str_replace( ' ', '+', $utm['utm_term'] ),
51
  'utm_content' => str_replace( ' ', '+', $utm['utm_content'] ),
52
- ];
53
 
54
  $url = add_query_arg( array_filter( $utm ), $url );
55
 
@@ -120,11 +120,56 @@ class CommonHelper {
120
 
121
  global $wpdb;
122
  /** @noinspection SpellCheckingInspection */
123
- $sql = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s";
124
 
125
  // phpcs:ignore
126
 
127
- return $wpdb->get_results( $wpdb->prepare( $sql, $prefix.'%') );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
 
130
  }
1
  <?php
2
  namespace CTXFeed\V5\Helper;
3
+
4
  class CommonHelper {
5
 
6
 
7
  public static function supported_product_types() {
8
+ return array(
9
  'simple',
10
  'variable',
11
  'variation',
19
  'subscription',
20
  'variable-subscription',
21
  'woosb',
22
+ );
23
  }
24
 
25
  public static function remove_shortcodes( $content ) {
41
 
42
  public static function add_utm_parameter( $utm, $url ) {
43
 
 
44
  if ( ! empty( $utm['utm_source'] ) && ! empty( $utm['utm_medium'] ) && ! empty( $utm['utm_campaign'] ) ) {
45
 
46
+ $utm = array(
47
  'utm_source' => str_replace( ' ', '+', $utm['utm_source'] ),
48
  'utm_medium' => str_replace( ' ', '+', $utm['utm_medium'] ),
49
  'utm_campaign' => str_replace( ' ', '+', $utm['utm_campaign'] ),
50
  'utm_term' => str_replace( ' ', '+', $utm['utm_term'] ),
51
  'utm_content' => str_replace( ' ', '+', $utm['utm_content'] ),
52
+ );
53
 
54
  $url = add_query_arg( array_filter( $utm ), $url );
55
 
120
 
121
  global $wpdb;
122
  /** @noinspection SpellCheckingInspection */
123
+ $sql = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s";
124
 
125
  // phpcs:ignore
126
 
127
+ return $wpdb->get_results( $wpdb->prepare( $sql, $prefix . '%' ) );
128
+ }
129
+
130
+ /**
131
+ * Extends wp_strip_all_tags to fix WP_Error object passing issue
132
+ *
133
+ * @param string | WP_Error $string
134
+ *
135
+ * @return string
136
+ * @since 4.5.10
137
+ * */
138
+ public static function woo_feed_strip_all_tags( $string ) {
139
+
140
+ if ( $string instanceof WP_Error ) {
141
+ return '';
142
+ }
143
+
144
+ return wp_strip_all_tags( $string );
145
+
146
+ }
147
+
148
+ /**
149
+ * Remove non supported xml character
150
+ *
151
+ * @param string $value
152
+ *
153
+ * @return string
154
+ *
155
+ * @since 4.5.10
156
+ */
157
+ public static function woo_feed_stripInvalidXml( $value ) {
158
+ $ret = '';
159
+ if ( empty( $value ) ) {
160
+ return $ret;
161
+ }
162
+ $length = strlen( $value );
163
+ for ( $i = 0; $i < $length; $i ++ ) {
164
+ $current = ord( $value[ $i ] );
165
+ if ( ( 0x9 == $current ) || ( 0xA == $current ) || ( 0xD == $current ) || ( ( $current >= 0x20 ) && ( $current <= 0xD7FF ) ) || ( ( $current >= 0xE000 ) && ( $current <= 0xFFFD ) ) || ( ( $current >= 0x10000 ) && ( $current <= 0x10FFFF ) ) ) {
166
+ $ret .= chr( $current );
167
+ } else {
168
+ $ret .= '';
169
+ }
170
+ }
171
+
172
+ return $ret;
173
  }
174
 
175
  }
V5/Output/FormatOutput.php CHANGED
@@ -1,5 +1,6 @@
1
  <?php
2
  namespace CTXFeed\V5\Output;
 
3
  use CTXFeed\V5\Utility\Config;
4
  use CTXFeed\V5\Helper\CommonHelper;
5
  use CTXFeed\V5\Helper\ProductHelper;
@@ -18,12 +19,110 @@ class FormatOutput {
18
  $this->attribute = $attribute;
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  public function get_output( $output, $outputTypes ) {
22
- if ( ! empty( $outputTypes ) && is_array( $outputTypes ) ) {
23
 
 
24
  // Format Output According to output type
25
  if ( in_array( 2, $outputTypes, true ) ) { // Strip Tags
26
- $output = woo_feed_strip_all_tags( html_entity_decode( $output ) );
 
27
  }
28
 
29
  if ( in_array( 4, $outputTypes, true ) ) { // htmlentities
@@ -35,19 +134,7 @@ class FormatOutput {
35
  }
36
 
37
  if ( in_array( 6, $outputTypes, true ) ) { // Format Price
38
- if ( ! empty( $output ) && $output > 0 ) {
39
- $decimals = $this->config->get_price_format()['decimals'];
40
- $decimal_separator = $this->config->get_price_format()['decimal_separator'];
41
- $thousand_separator = $this->config->get_price_format()['thousand_separator'];
42
- $output = (float) $output;
43
-
44
- // TODO: Remove this and make a hook.
45
- if ( "idealo" === $this->config->get_feed_template() ) {
46
- $output = number_format( $output, 2, '.', '' );
47
- } else {
48
- $output = number_format( $output, $decimals, wp_specialchars_decode( wp_unslash( $decimal_separator ) ), wp_specialchars_decode( wp_unslash( $thousand_separator ) ) );
49
- }
50
- }
51
  }
52
 
53
  if ( ! empty( $output ) && $output > 0 && in_array( 7, $outputTypes, true ) ) { // Rounded Price
@@ -56,14 +143,11 @@ class FormatOutput {
56
  }
57
 
58
  if ( in_array( 8, $outputTypes, true ) ) { // Delete Space
59
- $output = htmlentities( $output, null, 'utf-8' );
60
- $output = str_replace( "&nbsp;", " ", $output );
61
- $output = html_entity_decode( $output );
62
- $output = preg_replace( "/\\s+/", ' ', $output );
63
  }
64
 
65
  if ( in_array( 10, $outputTypes, true ) ) { // Remove Invalid Character
66
- $output = woo_feed_stripInvalidXml( $output );
67
  }
68
 
69
  if ( in_array( 11, $outputTypes, true ) ) { // Remove ShortCodes
@@ -111,243 +195,7 @@ class FormatOutput {
111
  }
112
 
113
  if ( in_array( 23, $outputTypes, true ) || in_array( 24, $outputTypes, true ) ) { // parent lang if child empty
114
- $id = $this->product->get_id();
115
-
116
-
117
- //check if the format type is `parent` or `parent_lang_if_empty`
118
- if ( in_array( 23, $outputTypes, true ) ) {
119
- $force_parent = true;
120
- } elseif ( in_array( 24, $outputTypes, true ) ) {
121
- $force_parent = empty( $output );
122
- }
123
-
124
- /**
125
- * when format type is `parent` then force getting parent value
126
- * when format type is `parent_lang_if_empty` then get the parent value on current empty value
127
- */
128
- if ( $force_parent ) {
129
- //when wpml plugin is activated, get parent language post id
130
- if ( class_exists( 'SitePress', false ) ) {
131
- $parent_id = woo_feed_wpml_get_original_post_id( $id );
132
-
133
- //remove wpml term filter
134
- global $sitepress;
135
- remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1 );
136
- remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 1 );
137
- }
138
-
139
- // when polylang plugin is activated, get parent language post id
140
- if ( defined( 'POLYLANG_BASENAME' ) || function_exists( 'PLL' ) ) {
141
- $parent_id = woo_feed_pll_get_original_post_id( $id );
142
- }
143
-
144
- //get attribute value of parent language post id
145
- if ( ! empty( $parent_id ) ) {
146
- $parentProduct = wc_get_product( $parent_id );
147
- $output = ProductHelper::getAttributeValueByType( $this->attribute, $parentProduct, $this->config );
148
- }
149
-
150
- }
151
- }
152
-
153
- }
154
-
155
- return $output;
156
- }
157
-
158
- /**
159
- * Process commands.
160
- *
161
- * @param $output
162
- * @param $commands
163
- *
164
- * @return array|false|mixed|string|string[]|null
165
- */
166
- public function process_command( $output, $commands ) {
167
- // Custom Template 2 return commands as array
168
- if ( ! is_array( $commands ) ) {
169
- $commands = $this->get_functions( $commands );
170
- }
171
-
172
- foreach ( $commands as $command ) {
173
- if ( ! empty( $command ) ) {
174
- $function = $this->get_function( $command );
175
- switch ( $function ) {
176
- case 'substr':
177
- $args = preg_split( '/\s+/', $command );
178
- $output = woo_feed_strip_all_tags( $output );
179
- $output = substr( $output, $args[1], $args[2] );
180
- break;
181
- case 'strip_tags':
182
- $output = woo_feed_strip_all_tags( $output );
183
- break;
184
- case 'htmlentities':
185
- $output = htmlentities( $output );
186
- break;
187
- case 'clear':
188
- $output = woo_feed_stripInvalidXml( $output );
189
- break;
190
- case 'ucwords':
191
- $output = ucwords( mb_strtolower( $output ) );
192
- break;
193
- case 'ucfirst':
194
- $output = ucfirst( mb_strtolower( $output ) );
195
- break;
196
- case 'strtoupper':
197
- $output = mb_strtoupper( $output );
198
- break;
199
- case 'strtolower':
200
- $output = mb_strtolower( $output );
201
- break;
202
- case 'strip_shortcodes':
203
- $output = CommonHelper::remove_shortcodes( $output );
204
- break;
205
- case 'number_format':
206
- $output = $this->format_number( $output, $command );
207
- break;
208
- case 'urltounsecure':
209
- if ( strpos( $output, 'http' ) === 0 ) {
210
- $output = str_replace( 'https://', 'http://', $output );
211
- }
212
- break;
213
- case 'urltosecure':
214
- if ( strpos( $output, 'http' ) === 0 ) {
215
- $output = str_replace( 'http://', 'https://', $output );
216
- }
217
- break;
218
- case 'str_replace':
219
- $output = $this->replace_string( $output, $command );
220
- break;
221
- case 'preg_replace':
222
- $output = $this->replace_string( $output, $command, 'preg_replace' );
223
- break;
224
- case 'only_parent';
225
- $output = $this->get_only_parent( $output );
226
- break;
227
- case 'parent_if_empty';
228
- $output = $this->get_parent_if_empty( $output );
229
- break;
230
- case 'parent';
231
- $output = $this->get_parent( $output );
232
- break;
233
- default:
234
- break;
235
- }
236
- }
237
- }
238
-
239
- return $output;
240
- }
241
-
242
- /**
243
- * Remove shortcodes from string.
244
- *
245
- * @param string $string String to remove shortcodes from.
246
- *
247
- * @return array
248
- */
249
-
250
- private function get_functions( $string ) {
251
- $functions = explode( ',', $string );
252
- $funArray = array();
253
- if ( $functions ) {
254
- foreach ( $functions as $value ) {
255
- if ( ! empty( $value ) ) {
256
- $funArray['formatter'][] = woo_feed_get_string_between( $value, '[', ']' );
257
- }
258
- }
259
- }
260
-
261
- return $funArray;
262
- }
263
-
264
- /**
265
- * php function from string.
266
- *
267
- * @param string $string String to remove shortcodes from.
268
- *
269
- * @return string
270
- */
271
- private function get_function( $string ) {
272
- $function = explode( ' ', $string );
273
-
274
- return $function[0];
275
- }
276
-
277
- /**
278
- * Number Format Output.
279
- *
280
- * @param string $output
281
- * @param string $command
282
- *
283
- * @return string
284
- */
285
- public function format_number( $output, $command ) {
286
- if ( ! empty( $output ) ) {
287
- $args = explode( ' ', $command, 3 );
288
- $arguments = array( 0 => '' );
289
-
290
- if ( isset( $args[1] ) ) {
291
- $arguments[1] = $args[1];
292
- }
293
-
294
- if ( isset( $args[2] ) && 'point' === $args[2] ) {
295
- $arguments[2] = '.';
296
- } elseif ( isset( $args[2] ) && 'comma' === $args[2] ) {
297
- $arguments[2] = ',';
298
- } elseif ( isset( $args[2] ) && 'space' === $args[2] ) {
299
- $arguments[2] = ' ';
300
- }
301
-
302
- if ( isset( $args[3] ) && 'point' === $args[3] ) {
303
- $arguments[3] = '.';
304
- } elseif ( isset( $args[3] ) && 'comma' === $args[3] ) {
305
- $arguments[3] = ',';
306
- } elseif ( isset( $args[3] ) && 'space' === $args[3] ) {
307
- $arguments[3] = ' ';
308
- } else {
309
- $arguments[3] = '';
310
- }
311
-
312
- if ( isset( $arguments[1], $arguments[2], $arguments[3] ) ) {
313
- $output = number_format( $output, $arguments[1], $arguments[2], $arguments[3] );
314
- } elseif ( isset( $arguments[1], $arguments[2] ) ) {
315
- $output = number_format( $output, $arguments[1], $arguments[2], $arguments[3] );
316
- } elseif ( isset( $arguments[1] ) ) {
317
- $output = number_format( $output, $arguments[1] );
318
- } else {
319
- $output = number_format( $output );
320
- }
321
- }
322
-
323
- return $output;
324
- }
325
-
326
- /**
327
- * Remove shortcodes from string.
328
- *
329
- * @param string $output
330
- * @param string $command
331
- *
332
- * @return string
333
- */
334
- private function replace_string( $output, $command, $type = 'str_replace' ) {
335
- $args = explode( '=>', $command, 3 );
336
- if ( array_key_exists( 1, $args ) && array_key_exists( 2, $args ) ) {
337
-
338
- list( $argument1, $argument2 ) = array_map( 'trim', array( $args[1], $args[2] ) );
339
-
340
- if ( false !== strpos( $args[1], 'comma' ) ) {
341
- $argument1 = str_replace( 'comma', ',', $args[1] );
342
- }
343
-
344
- if ( false !== strpos( $args[2], 'comma' ) ) {
345
- $argument2 = str_replace( 'comma', ',', $args[2] );
346
- }
347
- if ( 'str_replace' === $type ) {
348
- $output = str_replace( (string) $argument1, (string) $argument2, $output );
349
- } else {
350
- $output = preg_replace( wp_unslash( $argument1 ), wp_unslash( $argument2 ), $output );
351
  }
352
  }
353
 
@@ -361,7 +209,7 @@ class FormatOutput {
361
  *
362
  * @return string
363
  */
364
- private function get_only_parent( $output ) {
365
  if ( $this->product->is_type( 'variation' ) ) {
366
  $id = $this->product->get_parent_id();
367
  $parent = wc_get_product( $id );
@@ -378,7 +226,7 @@ class FormatOutput {
378
  *
379
  * @return string
380
  */
381
- private function get_parent( $output ) {
382
  if ( $this->product->is_type( 'variation' ) ) {
383
  $id = $this->product->get_parent_id();
384
  $parentProduct = wc_get_product( $id );
@@ -398,7 +246,7 @@ class FormatOutput {
398
  *
399
  * @return string
400
  */
401
- private function get_parent_if_empty( $output ) {
402
  if ( $this->product->is_type( 'variation' ) ) {
403
  $output = ProductHelper::getAttributeValueByType( $this->attribute, $this->product, $this->config );
404
  if ( empty( $output ) ) {
@@ -410,4 +258,4 @@ class FormatOutput {
410
 
411
  return $output;
412
  }
413
- }
1
  <?php
2
  namespace CTXFeed\V5\Output;
3
+
4
  use CTXFeed\V5\Utility\Config;
5
  use CTXFeed\V5\Helper\CommonHelper;
6
  use CTXFeed\V5\Helper\ProductHelper;
19
  $this->attribute = $attribute;
20
  }
21
 
22
+ /**
23
+ * Set price formate
24
+ * @param $output
25
+ *
26
+ * @return void
27
+ */
28
+ private function get_price_format( $output ) {
29
+ if ( ! empty( $output ) && $output > 0 ) {
30
+ $decimals = $this->config->get_number_format()['decimals'];
31
+ $decimal_separator = $this->config->get_number_format()['decimal_separator'];
32
+ $thousand_separator = $this->config->get_number_format()['thousand_separator'];
33
+ $output = (float) $output;
34
+
35
+ // TODO: Remove this and make a hook.
36
+ if ( 'idealo' === $this->config->get_feed_template() ) {
37
+ $output = number_format( $output, 2, '.', '' );
38
+ } else {
39
+ $output = number_format( $output, $decimals, wp_specialchars_decode( wp_unslash( $decimal_separator ) ), wp_specialchars_decode( wp_unslash( $thousand_separator ) ) );
40
+ }
41
+ }
42
+ return $output;
43
+ }
44
+
45
+
46
+
47
+ /**
48
+ * Delete Space
49
+ * @param $output
50
+ *
51
+ * @return array|string|string[]|null
52
+ */
53
+ private function delete_space( $output ) {
54
+ $output = htmlentities( $output, null, 'utf-8' );
55
+ $output = str_replace( '&nbsp;', ' ', $output );
56
+ $output = html_entity_decode( $output );
57
+ return preg_replace( '/\\s+/', ' ', $output );
58
+ }
59
+
60
+
61
+
62
+
63
+ /**
64
+ * Get the parent value on current empty value
65
+ *
66
+ * @param $output
67
+ * @param $outputTypes
68
+ *
69
+ * @return mixed
70
+ */
71
+ private function get_parent_lang_child_is_empty( $output, $outputTypes ) {
72
+ $id = $this->product->get_id();
73
+
74
+ //check if the format type is `parent` or `parent_lang_if_empty`
75
+ if ( in_array( 23, $outputTypes, true ) ) {
76
+ $force_parent = true;
77
+ } elseif ( in_array( 24, $outputTypes, true ) ) {
78
+ $force_parent = empty( $output );
79
+ }
80
+
81
+ /**
82
+ * when format type is `parent` then force getting parent value
83
+ * when format type is `parent_lang_if_empty` then get the parent value on current empty value
84
+ */
85
+ if ( $force_parent ) {
86
+ //when wpml plugin is activated, get parent language post id
87
+ if ( class_exists( 'SitePress', false ) ) {
88
+ $parent_id = woo_feed_wpml_get_original_post_id( $id );
89
+
90
+ //remove wpml term filter
91
+ global $sitepress;
92
+ remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1 );
93
+ remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 1 );
94
+ }
95
+
96
+ // when polylang plugin is activated, get parent language post id
97
+ if ( defined( 'POLYLANG_BASENAME' ) || function_exists( 'PLL' ) ) {
98
+ $parent_id = woo_feed_pll_get_original_post_id( $id );
99
+ }
100
+
101
+ //get attribute value of parent language post id
102
+ if ( ! empty( $parent_id ) ) {
103
+ $parentProduct = wc_get_product( $parent_id );
104
+ $output = ProductHelper::getAttributeValueByType( $this->attribute, $parentProduct, $this->config );
105
+ }
106
+ }
107
+
108
+ return $output;
109
+ }
110
+ /**
111
+ * Get Output
112
+ *
113
+ * @param $output
114
+ * @param $outputTypes
115
+ *
116
+ * @return array|false|int|mixed|string|string[]|null
117
+ */
118
+
119
  public function get_output( $output, $outputTypes ) {
 
120
 
121
+ if ( ! empty( $outputTypes ) && is_array( $outputTypes ) ) {
122
  // Format Output According to output type
123
  if ( in_array( 2, $outputTypes, true ) ) { // Strip Tags
124
+ //return $outputTypes;
125
+ $output = CommonHelper::woo_feed_strip_all_tags( html_entity_decode( $output ) );
126
  }
127
 
128
  if ( in_array( 4, $outputTypes, true ) ) { // htmlentities
134
  }
135
 
136
  if ( in_array( 6, $outputTypes, true ) ) { // Format Price
137
+ $this->get_price_format( $output );
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
140
  if ( ! empty( $output ) && $output > 0 && in_array( 7, $outputTypes, true ) ) { // Rounded Price
143
  }
144
 
145
  if ( in_array( 8, $outputTypes, true ) ) { // Delete Space
146
+ $output = $this->delete_space( $output );
 
 
 
147
  }
148
 
149
  if ( in_array( 10, $outputTypes, true ) ) { // Remove Invalid Character
150
+ $output = CommonHelper::woo_feed_stripInvalidXml( $output );
151
  }
152
 
153
  if ( in_array( 11, $outputTypes, true ) ) { // Remove ShortCodes
195
  }
196
 
197
  if ( in_array( 23, $outputTypes, true ) || in_array( 24, $outputTypes, true ) ) { // parent lang if child empty
198
+ $output = $this->get_parent_lang_child_is_empty( $output, $outputTypes );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  }
200
  }
201
 
209
  *
210
  * @return string
211
  */
212
+ protected function get_only_parent( $output ) {
213
  if ( $this->product->is_type( 'variation' ) ) {
214
  $id = $this->product->get_parent_id();
215
  $parent = wc_get_product( $id );
226
  *
227
  * @return string
228
  */
229
+ protected function get_parent( $output ) {
230
  if ( $this->product->is_type( 'variation' ) ) {
231
  $id = $this->product->get_parent_id();
232
  $parentProduct = wc_get_product( $id );
246
  *
247
  * @return string
248
  */
249
+ protected function get_parent_if_empty( $output ) {
250
  if ( $this->product->is_type( 'variation' ) ) {
251
  $output = ProductHelper::getAttributeValueByType( $this->attribute, $this->product, $this->config );
252
  if ( empty( $output ) ) {
258
 
259
  return $output;
260
  }
261
+ }
V5/Output/OutputCommands.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace CTXFeed\V5\Output;
4
 
 
 
5
 
6
  /**
7
  * Class OutputCommands
@@ -13,6 +15,244 @@ namespace CTXFeed\V5\Output;
13
  * @license https://opensource.org/licenses/gpl-license.php GNU Public License
14
  * @category MyCategory
15
  */
16
- class OutputCommands {
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
2
 
3
  namespace CTXFeed\V5\Output;
4
 
5
+ use CTXFeed\V5\Helper\CommonHelper;
6
+ use CTXFeed\V5\Output\FormatOutput;
7
 
8
  /**
9
  * Class OutputCommands
15
  * @license https://opensource.org/licenses/gpl-license.php GNU Public License
16
  * @category MyCategory
17
  */
18
+ class OutputCommands extends FormatOutput {
19
 
20
+ private $product;
21
+ /**
22
+ * @var Config $config
23
+ */
24
+ private $config;
25
+ private $attribute;
26
+
27
+ private $commands;
28
+
29
+
30
+ public function __construct( $product, $config, $attribute ) {
31
+ parent::__construct( $product, $config, $attribute );
32
+ $this->product = $product;
33
+ $this->config = $config;
34
+ $this->attribute = $attribute;
35
+ }
36
+
37
+ /**
38
+ * Remove shortcodes from string.
39
+ *
40
+ * @param string $output
41
+ * @param string $command
42
+ *
43
+ * @return string
44
+ */
45
+ private function replace_string( $output, $command, $type = 'str_replace' ) {
46
+
47
+ if ( strpos( $command, $type ) && strpos( $this->commands, $type ) ) {
48
+ $command = $this->commands;
49
+ }
50
+
51
+ $args = explode( '=>', $command, 3 );
52
+ if ( array_key_exists( 1, $args ) && array_key_exists( 2, $args ) ) {
53
+
54
+ list( $argument1, $argument2 ) = array_map( 'trim', array( $args[1], $args[2] ) );
55
+
56
+ if ( false !== strpos( $args[1], 'comma' ) ) {
57
+ $argument1 = str_replace( 'comma', ',', $args[1] );
58
+ }
59
+
60
+ if ( false !== strpos( $args[2], 'comma' ) ) {
61
+ $argument2 = str_replace( 'comma', ',', $args[2] );
62
+ }
63
+ if ( 'str_replace' === $type ) {
64
+ $output = str_replace( (string) $argument1, (string) $argument2, $output );
65
+ } else {
66
+ $output = preg_replace( wp_unslash( $argument1 ), wp_unslash( $argument2 ), $output );
67
+ }
68
+ }
69
+
70
+ return $output;
71
+ }
72
+
73
+ /**
74
+ * Number Format Output.
75
+ *
76
+ * @param string $output
77
+ * @param string $command
78
+ *
79
+ * @return string
80
+ */
81
+ public function format_number( $output, $command ) {
82
+ if ( ! empty( $output ) ) {
83
+ $args = explode( ' ', $command, 3 );
84
+ $arguments = array( 0 => '' );
85
+
86
+ if ( isset( $args[1] ) ) {
87
+ $arguments[1] = $args[1];
88
+ }
89
+
90
+ if ( isset( $args[2] ) && 'point' === $args[2] ) {
91
+ $arguments[2] = '.';
92
+ } elseif ( isset( $args[2] ) && 'comma' === $args[2] ) {
93
+ $arguments[2] = ',';
94
+ } elseif ( isset( $args[2] ) && 'space' === $args[2] ) {
95
+ $arguments[2] = ' ';
96
+ }
97
+
98
+ if ( isset( $args[3] ) && 'point' === $args[3] ) {
99
+ $arguments[3] = '.';
100
+ } elseif ( isset( $args[3] ) && 'comma' === $args[3] ) {
101
+ $arguments[3] = ',';
102
+ } elseif ( isset( $args[3] ) && 'space' === $args[3] ) {
103
+ $arguments[3] = ' ';
104
+ } else {
105
+ $arguments[3] = '';
106
+ }
107
+
108
+ if ( isset( $arguments[1], $arguments[2], $arguments[3] ) ) {
109
+ $output = number_format( $output, $arguments[1], $arguments[2], $arguments[3] );
110
+ } elseif ( isset( $arguments[1], $arguments[2] ) ) {
111
+ $output = number_format( $output, $arguments[1], $arguments[2], $arguments[3] );
112
+ } elseif ( isset( $arguments[1] ) ) {
113
+ $output = number_format( $output, $arguments[1] );
114
+ } else {
115
+ $output = number_format( $output );
116
+ }
117
+ }
118
+
119
+ return $output;
120
+ }
121
+
122
+ /**
123
+ * Remove shortcodes from string.
124
+ *
125
+ * @param string $string String to remove shortcodes from.
126
+ *
127
+ * @return array
128
+ */
129
+
130
+ private function get_functions( $string ) {
131
+ $functions = explode( ',', $string );
132
+ $funArray = array();
133
+ if ( $functions ) {
134
+ foreach ( $functions as $value ) {
135
+ if ( ! empty( $value ) ) {
136
+ $funArray['formatter'][] = woo_feed_get_string_between( $value, '[', ']' );
137
+ }
138
+ }
139
+ }
140
+
141
+ return $funArray;
142
+ }
143
+
144
+
145
+ /**
146
+ * php function from string.
147
+ *
148
+ * @param string $string String to remove shortcodes from.
149
+ *
150
+ * @return string
151
+ */
152
+ private function get_function( $string ) {
153
+ $function = explode( ' ', $string );
154
+
155
+ return $function[0];
156
+ }
157
+
158
+ /**
159
+ * @param $string
160
+ *
161
+ * Get function command for str_replace
162
+ *
163
+ * @return mixed|string
164
+ */
165
+ private function get_function_command( $string ) {
166
+ $this->commands = $string;
167
+ $function = explode( '=>', $string );
168
+
169
+ return $function[0];
170
+ }
171
+
172
+ /**
173
+ * Process commands.
174
+ *
175
+ * @param $output
176
+ * @param $commands
177
+ *
178
+ * @return array|false|mixed|string|string[]|null
179
+ */
180
+ public function process_command( $output, $commands ) {
181
+ // Custom Template 2 return commands as array
182
+ if ( ! is_array( $commands ) ) {
183
+ $commands = $this->get_functions( $commands );
184
+ }
185
+
186
+ foreach ( $commands as $command ) {
187
+ if ( ! empty( $command ) ) {
188
+
189
+ $function = $this->get_function( $command );
190
+ $function = $this->get_function_command( $function );
191
+
192
+ switch ( $function ) {
193
+ case 'substr':
194
+ $args = preg_split( '/\s+/', $command );
195
+ $output = CommonHelper::woo_feed_strip_all_tags( $output );
196
+ $output = substr( $output, $args[1], $args[2] );
197
+ break;
198
+ case 'strip_tags':
199
+ $output = CommonHelper::woo_feed_strip_all_tags( $output );
200
+ break;
201
+ case 'htmlentities':
202
+ $output = htmlentities( $output );
203
+ break;
204
+ case 'clear':
205
+ $output = CommonHelper::woo_feed_stripInvalidXml( $output );
206
+ break;
207
+ case 'ucwords':
208
+ $output = ucwords( mb_strtolower( $output ) );
209
+ break;
210
+ case 'ucfirst':
211
+ $output = ucfirst( mb_strtolower( $output ) );
212
+ break;
213
+ case 'strtoupper':
214
+ $output = mb_strtoupper( $output );
215
+ break;
216
+ case 'strtolower':
217
+ $output = mb_strtolower( $output );
218
+ break;
219
+ case 'strip_shortcodes':
220
+ $output = CommonHelper::remove_shortcodes( $output );
221
+ break;
222
+ case 'number_format':
223
+ $output = $this->format_number( $output, $command );
224
+ break;
225
+ case 'urltounsecure':
226
+ if ( strpos( $output, 'http' ) === 0 ) {
227
+ $output = str_replace( 'https://', 'http://', $output );
228
+ }
229
+ break;
230
+ case 'urltosecure':
231
+ if ( strpos( $output, 'http' ) === 0 ) {
232
+ $output = str_replace( 'http://', 'https://', $output );
233
+ }
234
+ break;
235
+ case 'str_replace':
236
+ $output = $this->replace_string( $output, $command );
237
+ break;
238
+ case 'preg_replace':
239
+ $output = $this->replace_string( $output, $command, 'preg_replace' );
240
+ break;
241
+ case 'only_parent';
242
+ $output = $this->get_only_parent( $output );
243
+ break;
244
+ case 'parent_if_empty';
245
+ $output = $this->get_parent_if_empty( $output );
246
+ break;
247
+ case 'parent';
248
+ $output = $this->get_parent( $output );
249
+ break;
250
+ default:
251
+ break;
252
+ }
253
+ }
254
+ }
255
+
256
+ return $output;
257
+ }
258
  }
V5/Query/Query.php CHANGED
@@ -7,12 +7,12 @@ class Query {
7
  */
8
  private $query;
9
 
10
- public function __construct( QueryInterface $query) {
11
 
12
  $this->query = $query;
13
  }
14
 
15
- public function get_ids( ) {
16
  return $this->query->product_ids();
17
  }
18
- }
7
  */
8
  private $query;
9
 
10
+ public function __construct( QueryInterface $query ) {
11
 
12
  $this->query = $query;
13
  }
14
 
15
+ public function get_ids() {
16
  return $this->query->product_ids();
17
  }
18
+ }
V5/Query/QueryFactory.php CHANGED
@@ -20,9 +20,32 @@ class QueryFactory {
20
  $class = WCReviewQuery::class;
21
  }
22
 
 
 
 
 
 
 
 
 
 
 
23
  /**
24
  * @var WPQuery|WCQuery|WCReviewQuery $class Query Class
25
  */
26
- return ( new Query( new $class( $config ,$args) ) )->get_ids();
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
  }
20
  $class = WCReviewQuery::class;
21
  }
22
 
23
+ /**
24
+ * Fires before looping through request product for getting product data
25
+ *
26
+ * @param int[] $productIds
27
+ * @param array $feedConfig
28
+ *
29
+ * @since 3.2.10
30
+ */
31
+ do_action( 'woo_feed_before_product_loop', [], $config->feedInfo );
32
+
33
  /**
34
  * @var WPQuery|WCQuery|WCReviewQuery $class Query Class
35
  */
36
+ $productIds = ( new Query( new $class( $config, $args ) ) )->get_ids();
37
+
38
+
39
+ /**
40
+ * Fires after looping through request product for getting product data
41
+ *
42
+ * @param int[] $productIds
43
+ * @param Config $config
44
+ *
45
+ * @since 3.2.10
46
+ */
47
+ do_action( 'woo_feed_after_product_loop', $productIds, $config->feedInfo );
48
+
49
+ return $productIds;
50
  }
51
  }
V5/Utility/Config.php CHANGED
@@ -11,7 +11,7 @@ class Config {
11
  /**
12
  * @var array|bool
13
  */
14
- private $feedInfo;
15
 
16
  /**
17
  * @var array|bool
11
  /**
12
  * @var array|bool
13
  */
14
+ public $feedInfo;
15
 
16
  /**
17
  * @var array|bool
admin/images/ctx-feed-black-friday-banner-2022.png DELETED
Binary file
includes/classes/class-woo-feed-constants.php CHANGED
@@ -23,7 +23,7 @@ if( ! class_exists("Woo_Feed_Constants") ) {
23
  * @var string
24
  * @since 3.1.6
25
  */
26
- define( 'WOO_FEED_FREE_VERSION', '4.5.11' );
27
  }
28
 
29
  if ( ! defined( 'WOO_FEED_FREE_PATH' ) ) {
23
  * @var string
24
  * @since 3.1.6
25
  */
26
+ define( 'WOO_FEED_FREE_VERSION', '4.5.12' );
27
  }
28
 
29
  if ( ! defined( 'WOO_FEED_FREE_PATH' ) ) {
includes/helper.php CHANGED
@@ -497,7 +497,12 @@ if ( ! function_exists( 'woo_feed_get_merchant_class' ) ) {
497
  } elseif ( strpos( $provider, 'amazon' ) !== false ) {
498
  return 'Woo_Feed_Amazon';
499
  } elseif ( in_array( $provider, woo_feed_get_custom2_merchant(), true ) ) {
500
- return 'Woo_Feed_Custom_XML';
 
 
 
 
 
501
  } else {
502
  return 'Woo_Feed_Custom';
503
  }
@@ -1764,6 +1769,10 @@ if ( ! function_exists( 'woo_feed_strip_all_tags' ) ) {
1764
  *
1765
  * @return string
1766
  * @since 4.4.19
 
 
 
 
1767
  * */
1768
  function woo_feed_strip_all_tags( $string ) {
1769
 
@@ -1896,6 +1905,8 @@ if ( ! function_exists( 'woo_feed_stripInvalidXml' ) ) {
1896
  * @param string $value
1897
  *
1898
  * @return string
 
 
1899
  */
1900
  function woo_feed_stripInvalidXml( $value ) {
1901
  $ret = '';
497
  } elseif ( strpos( $provider, 'amazon' ) !== false ) {
498
  return 'Woo_Feed_Amazon';
499
  } elseif ( in_array( $provider, woo_feed_get_custom2_merchant(), true ) ) {
500
+ if ( defined( 'WOO_FEED_PRO_VERSION' ) ) {
501
+ return 'Woo_Feed_Custom_XML';
502
+ } else {
503
+ return 'Woo_Feed_Custom';
504
+ }
505
+ //return 'Woo_Feed_Custom_XML';
506
  } else {
507
  return 'Woo_Feed_Custom';
508
  }
1769
  *
1770
  * @return string
1771
  * @since 4.4.19
1772
+ <<<<<<< HEAD
1773
+ =======
1774
+ * Function move to V5 module (V5/Helper/CommonHelper)
1775
+ >>>>>>> feature/CTX-276
1776
  * */
1777
  function woo_feed_strip_all_tags( $string ) {
1778
 
1905
  * @param string $value
1906
  *
1907
  * @return string
1908
+ *
1909
+ * Move to V5 module (V5/Helper/CommonHelper)
1910
  */
1911
  function woo_feed_stripInvalidXml( $value ) {
1912
  $ret = '';
woo-feed.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: CTX Feed
11
  * Plugin URI: https://webappick.com/
12
  * Description: Easily generate woocommerce product feed for any marketing channel like Google Shopping(Merchant), Facebook Remarketing, Bing, eBay & more. Support 100+ Merchants.
13
- * Version: 4.5.11
14
  * Author: WebAppick
15
  * Author URI: https://webappick.com/
16
  * License: GPL v2
@@ -134,10 +134,6 @@ if ( ! function_exists( 'run_woo_feed' ) ) {
134
  add_action( 'plugins_loaded', array( $plugin, 'run' ), PHP_INT_MAX );
135
  add_action( 'admin_notices', 'wooFeed_Admin_Notices' );
136
 
137
- if ( isset( $_GET['page'] ) && preg_match( '/^webappick\W+/', $_GET['page'] ) ) {
138
- add_action( 'admin_notices', 'woo_feed_black_friday_notice' );
139
- }
140
-
141
  WooFeedWebAppickAPI::getInstance();
142
 
143
  }
10
  * Plugin Name: CTX Feed
11
  * Plugin URI: https://webappick.com/
12
  * Description: Easily generate woocommerce product feed for any marketing channel like Google Shopping(Merchant), Facebook Remarketing, Bing, eBay & more. Support 100+ Merchants.
13
+ * Version: 4.5.12
14
  * Author: WebAppick
15
  * Author URI: https://webappick.com/
16
  * License: GPL v2
134
  add_action( 'plugins_loaded', array( $plugin, 'run' ), PHP_INT_MAX );
135
  add_action( 'admin_notices', 'wooFeed_Admin_Notices' );
136
 
 
 
 
 
137
  WooFeedWebAppickAPI::getInstance();
138
 
139
  }