CTX Feed – WooCommerce Product Feed Manager Plugin - Version 3.1.34

Version Description

(2019-10-9) = * Resolve duplicate filename conflict. * Fix undefined variable. * Check if function exists before declaration (Resolve error on Pro Version activation.

Download this release

Release Info

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

Code changes from version 3.1.33 to 3.1.34

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://webappick.com
4
  Tags:woocommerce,google product feed,facebook product feed,woocommerce product feed,woocommerce,
5
  Requires at least: 3.6
6
  Tested Up To: 5.2
7
- Stable tag: 3.1.33
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -304,6 +304,11 @@ Using pro version:
304
 
305
  == Changelog ==
306
 
 
 
 
 
 
307
  = 3.1.33 (2019-10-7) =
308
  * Add copy to clip board
309
  * Fix performance issue on feed add/edit screen
4
  Tags:woocommerce,google product feed,facebook product feed,woocommerce product feed,woocommerce,
5
  Requires at least: 3.6
6
  Tested Up To: 5.2
7
+ Stable tag: 3.1.34
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
304
 
305
  == Changelog ==
306
 
307
+ = 3.1.34 (2019-10-9) =
308
+ * Resolve duplicate filename conflict.
309
+ * Fix undefined variable.
310
+ * Check if function exists before declaration (Resolve error on Pro Version activation.
311
+
312
  = 3.1.33 (2019-10-7) =
313
  * Add copy to clip board
314
  * Fix performance issue on feed add/edit screen
admin/partials/templates/custom_edit-feed.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  $dropDown = new Woo_Feed_Dropdown();
3
  $product = new Woo_Feed_Products();
4
  $product->load_attributes();
@@ -9,16 +10,14 @@ if(!isset($feedRules['ftporsftp'])){
9
  }
10
 
11
  ?>
 
12
  <div class="wrap" id="Feed">
13
  <h2><?php echo _e('WooCommerce Product Feed', 'woo-feed'); ?></h2>
14
  <table class="widefat fixed">
15
  <tbody>
16
  <tr>
17
- <td align="center"><b><a target="_blank"
18
- href="http://webappick.helpscoutdocs.com/article/17-woocommerce-product-feed">Help
19
- & Docs</a></b></td>
20
- <td align="center"><b><a style="color:#ee264a;" target="_blank"
21
- href="https://www.youtube.com/channel/UCzy3G9pA3yVgo0YZc-yJmfw">VIDEOS</a></b>
22
  </td>
23
  <td>Contact <b style="color:#2CC185;">support@webappick.com</b> for support.</td>
24
  </tr>
@@ -27,7 +26,8 @@ if(!isset($feedRules['ftporsftp'])){
27
  <br/>
28
 
29
  <form action="" name="feed" id="updatefeed" method="post" autocomplete="disabled">
30
-
 
31
  <?php wp_nonce_field('wf_edit_feed'); ?>
32
 
33
  <table class=" widefat fixed">
1
  <?php
2
+ /** @noinspection PhpUndefinedVariableInspection */
3
  $dropDown = new Woo_Feed_Dropdown();
4
  $product = new Woo_Feed_Products();
5
  $product->load_attributes();
10
  }
11
 
12
  ?>
13
+ <!--suppress SpellCheckingInspection, HtmlFormInputWithoutLabel, HtmlDeprecatedAttribute -->
14
  <div class="wrap" id="Feed">
15
  <h2><?php echo _e('WooCommerce Product Feed', 'woo-feed'); ?></h2>
16
  <table class="widefat fixed">
17
  <tbody>
18
  <tr>
19
+ <td align="center"><b><a target="_blank" href="http://webappick.helpscoutdocs.com/article/17-woocommerce-product-feed">Help & Docs</a></b></td>
20
+ <td align="center"><b><a style="color:#ee264a;" target="_blank" href="https://www.youtube.com/channel/UCzy3G9pA3yVgo0YZc-yJmfw">VIDEOS</a></b>
 
 
 
21
  </td>
22
  <td>Contact <b style="color:#2CC185;">support@webappick.com</b> for support.</td>
23
  </tr>
26
  <br/>
27
 
28
  <form action="" name="feed" id="updatefeed" method="post" autocomplete="disabled">
29
+ <input type="hidden" name="feed_name" value="<?php echo $fname; ?>">
30
+ <input type="hidden" name="feed_id" value="<?php echo $feedId; ?>">
31
  <?php wp_nonce_field('wf_edit_feed'); ?>
32
 
33
  <table class=" widefat fixed">
admin/partials/woo-feed-edit-template.php CHANGED
@@ -10,7 +10,7 @@
10
  * @subpackage Woo_Feed/admin/partial
11
  * @author Ohidul Islam <wahid@webappick.com>
12
  */
13
-
14
  $dropDown = new Woo_Feed_Dropdown();
15
  $product = new Woo_Feed_Products();
16
  $product->load_attributes();
@@ -27,14 +27,15 @@ if(!isset($feedRules['ftporsftp'])){
27
  $AttributesDropdown = $feedRules['provider'] . "AttributesDropdown";
28
  //echo "<pre>";print_r($feedRules);
29
  ?>
 
30
  <div class="wrap" id="Feed">
31
  <h2><?php echo _e('WooCommerce Product Feed', 'woo-feed'); ?></h2>
32
  <?php echo WPFFWMessage()->infoMessage1(); ?>
33
 
34
  <form action="" name="feed" method="post" id="updatefeed" autocomplete="disabled" >
35
-
 
36
  <?php wp_nonce_field('wf_edit_feed'); ?>
37
-
38
  <table class=" widefat fixed">
39
  <thead>
40
  <tr>
10
  * @subpackage Woo_Feed/admin/partial
11
  * @author Ohidul Islam <wahid@webappick.com>
12
  */
13
+ /** @noinspection PhpUndefinedVariableInspection */
14
  $dropDown = new Woo_Feed_Dropdown();
15
  $product = new Woo_Feed_Products();
16
  $product->load_attributes();
27
  $AttributesDropdown = $feedRules['provider'] . "AttributesDropdown";
28
  //echo "<pre>";print_r($feedRules);
29
  ?>
30
+ <!--suppress SpellCheckingInspection, HtmlFormInputWithoutLabel, HtmlDeprecatedAttribute -->
31
  <div class="wrap" id="Feed">
32
  <h2><?php echo _e('WooCommerce Product Feed', 'woo-feed'); ?></h2>
33
  <?php echo WPFFWMessage()->infoMessage1(); ?>
34
 
35
  <form action="" name="feed" method="post" id="updatefeed" autocomplete="disabled" >
36
+ <input type="hidden" name="feed_name" value="<?php echo $fname; ?>">
37
+ <input type="hidden" name="feed_id" value="<?php echo $feedId; ?>">
38
  <?php wp_nonce_field('wf_edit_feed'); ?>
 
39
  <table class=" widefat fixed">
40
  <thead>
41
  <tr>
includes/classes/class-woo-feed-products.php CHANGED
@@ -8,8 +8,7 @@
8
  * @subpackage Woo_Feed/includes
9
  * @author Ohidul Islam <wahid@webappick.com>
10
  */
11
- class Woo_Feed_Products
12
- {
13
 
14
  /**
15
  * Contain all parent product information for the plugin.
@@ -1777,8 +1776,7 @@ class Woo_Feed_Products
1777
  *
1778
  * @return string
1779
  */
1780
- public function attributeDropdown($selected = "")
1781
- {
1782
  $attributes = array(
1783
  "id" => "Product Id",
1784
  "title" => "Product Title",
@@ -1834,7 +1832,7 @@ class Woo_Feed_Products
1834
 
1835
  # Primary Attributes
1836
  $str = "<option></option>";
1837
- $sltd = "";
1838
  $str .= "<optgroup label='Primary Attributes'>";
1839
  foreach ($attributes as $key => $value) {
1840
  /** @noinspection HtmlUnknownAttribute */
@@ -1851,6 +1849,7 @@ class Woo_Feed_Products
1851
  if ($images) {
1852
  $str .= "<optgroup label='Image Attributes'>";
1853
  foreach ($images as $key => $value) {
 
1854
  $str .= sprintf(
1855
  '<option value="%s"%s>%s</option>',
1856
  $key,
@@ -1866,6 +1865,7 @@ class Woo_Feed_Products
1866
  if ($vAttributes) {
1867
  $str .= "<optgroup label='Product Attributes'>";
1868
  foreach ($vAttributes as $key => $value) {
 
1869
  $str .= sprintf(
1870
  '<option value="%s"%s>%s</option>',
1871
  $key,
8
  * @subpackage Woo_Feed/includes
9
  * @author Ohidul Islam <wahid@webappick.com>
10
  */
11
+ class Woo_Feed_Products {
 
12
 
13
  /**
14
  * Contain all parent product information for the plugin.
1776
  *
1777
  * @return string
1778
  */
1779
+ public function attributeDropdown( $selected = "" ) {
 
1780
  $attributes = array(
1781
  "id" => "Product Id",
1782
  "title" => "Product Title",
1832
 
1833
  # Primary Attributes
1834
  $str = "<option></option>";
1835
+ $is_selected = false;
1836
  $str .= "<optgroup label='Primary Attributes'>";
1837
  foreach ($attributes as $key => $value) {
1838
  /** @noinspection HtmlUnknownAttribute */
1849
  if ($images) {
1850
  $str .= "<optgroup label='Image Attributes'>";
1851
  foreach ($images as $key => $value) {
1852
+ /** @noinspection HtmlUnknownAttribute */
1853
  $str .= sprintf(
1854
  '<option value="%s"%s>%s</option>',
1855
  $key,
1865
  if ($vAttributes) {
1866
  $str .= "<optgroup label='Product Attributes'>";
1867
  foreach ($vAttributes as $key => $value) {
1868
+ /** @noinspection HtmlUnknownAttribute */
1869
  $str .= sprintf(
1870
  '<option value="%s"%s>%s</option>',
1871
  $key,
woo-feed.php CHANGED
@@ -15,7 +15,7 @@
15
  * Plugin Name: WooCommerce Product Feed
16
  * Plugin URI: https://webappick.com/
17
  * Description: This plugin generate WooCommerce product feed for Shopping Engines like Google Shopping,Facebook Product Feed,eBay,Amazon,Idealo and many more..
18
- * Version: 3.1.33
19
  * Author: WebAppick
20
  * Author URI: https://webappick.com/
21
  * License: GPL v2
@@ -27,16 +27,14 @@
27
  *
28
  */
29
 
30
- // If this file is called directly, abort.
31
- if (!defined('WPINC')) {
32
- die;
33
- }
34
  // Exit if accessed directly
35
- if (!defined('ABSPATH')) {
36
- exit;
37
- }
38
 
39
- define( 'WOO_FEED_VERSION', '3.1.33' );
 
 
 
 
40
 
41
  /**
42
  * Plugin Path with trailing slash
@@ -49,1162 +47,1236 @@ define( 'WOO_FEED_Path', plugin_dir_path( __FILE__ ) );
49
  */
50
  define( 'WOO_FEED_Admin_Path', WOO_FEED_Path . 'admin/' );
51
 
52
- /**
53
- * The core plugin class that is used to define internationalization,
54
- * admin-specific hooks, and public-facing site hooks.
55
- */
56
- require plugin_dir_path(__FILE__) . 'includes/class-woo-feed.php';
57
-
58
-
59
- /**
60
- * The code that runs during plugin activation.
61
- * This action is documented in includes/class-woo-feed-activator.php
62
- */
63
-
64
- function activate_woo_feed()
65
- {
66
- require plugin_dir_path(__FILE__) . 'includes/class-woo-feed-activator.php';
67
- Woo_Feed_Activator::activate();
68
  }
69
-
70
- /**
71
- * The code that runs during plugin deactivation.
72
- * This action is documented in includes/class-woo-feed-deactivator.php
73
- */
74
- function deactivate_woo_feed()
75
- {
76
- require plugin_dir_path(__FILE__) . 'includes/class-woo-feed-deactivator.php';
77
- Woo_Feed_Deactivator::deactivate();
 
78
  }
79
-
80
- register_activation_hook(__FILE__, 'activate_woo_feed');
81
- register_deactivation_hook(__FILE__, 'deactivate_woo_feed');
82
-
83
- /**
84
- * Begins execution of the plugin.
85
- *
86
- * Since everything within the plugin is registered via hooks,
87
- * then kicking off the plugin from this point in the file does
88
- * not affect the page life cycle.
89
- *
90
- * @since 1.0.0
91
- */
92
- function run_woo_feed()
93
- {
94
- $plugin = new Woo_Feed();
95
- $plugin->run();
96
  }
97
-
98
- run_woo_feed();
99
-
100
- # Custom Cron Recurrences
101
- function custom_cron_job_custom_recurrence($schedules)
102
- {
103
- $interval = get_option('wf_schedule');
104
- $schedules['woo_feed_corn'] = array(
105
- 'display' => __('Woo Feed Update Interval', 'woo-feed'),
106
- 'interval' => $interval,
107
- );
108
-
109
- return $schedules;
 
 
110
  }
111
-
112
- # Update the schedule interval
113
- add_filter('cron_schedules', 'custom_cron_job_custom_recurrence');
114
- add_action('woo_feed_update', 'woo_feed_cron_update_feed');
115
- add_action('woo_feed_update_single_feed', 'woo_feed_cron_update_single_feed');
116
-
117
- # Load Feed Templates
118
- add_action('wp_ajax_get_feed_merchant', 'feed_merchant_view');
119
- function feed_merchant_view()
120
- {
121
- check_ajax_referer('wpf_feed_nonce');
122
- /** @noinspection PhpUnusedLocalVariableInspection */
123
- $dropDown = new Woo_Feed_Dropdown();
124
- /** @noinspection PhpUnusedLocalVariableInspection */
125
- $product = new Woo_Feed_Products();
126
- /** @noinspection PhpUnusedLocalVariableInspection */
127
- $attributes = new Woo_Feed_Default_Attributes();
128
- /** @noinspection PhpUnusedLocalVariableInspection */
129
- $merchant = $provider = sanitize_text_field($_POST['merchant']);
130
- if(strpos($merchant,'amazon')!==false){
131
- include plugin_dir_path(__FILE__) . "admin/partials/templates/amazon_add-feed.php";
132
- }
133
- else if($merchant == 'smartly.io')
134
- {
135
- include plugin_dir_path(__FILE__) . "admin/partials/templates/google_add-feed.php";
136
- }
137
- else{
138
- include plugin_dir_path(__FILE__) . "admin/partials/templates/". $merchant . "_add-feed.php";
139
- }
140
- die();
141
  }
142
-
143
-
144
- /*
145
- * Update Feed Information
146
- */
147
- function woo_feed_add_update($info = "", $name = "")
148
- {
149
- set_time_limit(0);
150
- if (count($info) && isset($info['provider'])) {
151
- # GEt Post data
152
- if ($info['provider'] == 'google' || $info['provider'] == 'adroll' || $info['provider'] == 'smartly.io') {
153
- $merchant = "Woo_Feed_Google";
154
- } elseif ($info['provider'] == 'pinterest') {
155
- $merchant = "Woo_Feed_Pinterest";
156
- } elseif ($info['provider'] == 'facebook') {
157
- $merchant = "Woo_Feed_Facebook";
158
- }elseif (strpos($info['provider'],'amazon') !==FALSE) {
159
- $merchant = "Woo_Feed_Amazon";
160
- } else {
161
- $merchant = "Woo_Feed_Custom";
162
- }
163
-
164
-
165
- $feedService = sanitize_text_field($info['provider']);
166
- $fileName = str_replace(" ", "", sanitize_text_field($info['filename']));
167
- $type = sanitize_text_field($info['feedType']);
168
-
169
- $feedRules = $info;
170
-
171
- # Get Feed info
172
- $products = new Woo_Generate_Feed($merchant, $feedRules);
173
- $getString = $products->getProducts();
174
-
175
- if($type=='csv'){
176
- $csvHead[0]=$getString['header'];
177
- if(!empty($csvHead) && !empty($getString['body'])){
178
- $string=array_merge($csvHead,$getString['body']);
179
- }else{
180
- $string=array();
181
- }
182
- }else{
183
- $string=$getString['header'].$getString['body'].$getString['footer'];
184
- }
185
-
186
- # Check If any products founds
187
- if ($string && !empty($string)) {
188
-
189
- $upload_dir = wp_upload_dir();
190
- $base = $upload_dir['basedir'];
191
-
192
- # Save File
193
- $path = $base . "/woo-feed/" . $feedService . "/" . $type;
194
- $file = $path . "/" . $fileName . "." . $type;
195
- $save = new Woo_Feed_Savefile();
196
- if ($type == "csv") {
197
- $saveFile = $save->saveCSVFile($path, $file, $string, $info);
198
- } else {
199
- $saveFile = $save->saveFile($path, $file, $string);
200
- }
201
-
202
- # FTP File Upload Info
203
- $ftpHost = sanitize_text_field($info['ftphost']);
204
- $ftpUser = sanitize_text_field($info['ftpuser']);
205
- $ftpPassword = sanitize_text_field($info['ftppassword']);
206
- $ftpPath = sanitize_text_field($info['ftppath']);
207
- $ftpPort = isset($info['ftpport']) && !empty($info['ftpport'])?sanitize_text_field($info['ftpport']):21;
208
- $ftpEnabled = sanitize_text_field($info['ftpenabled']);
209
-
210
- $ftporsftp = isset($info['ftporsftp'])?sanitize_text_field($info['ftporsftp']):"ftp";
211
-
212
-
213
- try{
214
- if ($type == "json") {
215
- $type="csv";
216
- }
217
- # Upload file to ftp server
218
- if ($ftpEnabled) {
219
- if($ftporsftp == "ftp") {
220
- $ftp = new FTPClient();
221
- if ($ftp->connect($ftpHost, $ftpUser, $ftpPassword,false,$ftpPort)){
222
- $ftp->uploadFile($file, $fileName . "." . $type);
223
- }
224
- } elseif ($ftporsftp == "sftp" && extension_loaded ( 'ssh2' )) {
225
- $sftp = new SFTPConnection($ftpHost, $ftpPort);
226
- $sftp->login($ftpUser, $ftpPassword);
227
- $sftp->uploadFile($file, "/".$fileName . "." . $type);
228
- }
229
- }
230
- }catch (Exception $e){
231
-
232
- }
233
-
234
- # Save Info into database
235
- $url = $upload_dir['baseurl'] . "/woo-feed/" . $feedService . "/" . $type . "/" . $fileName . "." . $type;
236
- $feedInfo = array(
237
- 'feedrules' => $feedRules,
238
- 'url' => $url,
239
- 'last_updated' => date("Y-m-d H:i:s"),
240
- 'status'=>1
241
- );
242
-
243
-
244
- if (!empty($name) && $name != "wf_feed_" . $fileName) {
245
- delete_option($name);
246
- }
247
-
248
- $update = update_option('wf_feed_' . $fileName, serialize($feedInfo));
249
- if ($saveFile) {
250
- $getInfo = unserialize(get_option('wf_feed_' . $fileName));
251
- $url = $getInfo['url'];
252
- return $url;
253
- } else {
254
- return false;
255
- }
256
- }
257
- }
258
-
259
- return false;
260
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
 
262
- /**
263
- * Sanitize array post
264
- *
265
- * @param $array
266
- *
267
- * @return array
268
- */
269
- function woo_feed_array_sanitize($array)
270
- {
271
- $newArray = array();
272
- if (count($array)) {
273
- foreach ($array as $key => $value) {
274
- if (is_array($value)) {
275
- foreach ($value as $key2 => $value2) {
276
- if (is_array($value2)) {
277
- foreach ($value2 as $key3 => $value3) {
278
- $newArray[$key][$key2][$key3] = sanitize_text_field($value3);
279
- }
280
- } else {
281
- $newArray[$key][$key2] = sanitize_text_field($value2);
282
- }
283
- }
284
- } else {
285
- $newArray[$key] = sanitize_text_field($value);
286
- }
287
- }
288
- }
289
- return $newArray;
 
 
 
 
 
290
  }
291
-
292
  #======================================================================================================================*
293
  #
294
  # Ajax Feed Making Development Start
295
  #
296
  #======================================================================================================================*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
 
299
- /**
300
- * Count Total Products
301
- */
302
 
303
- add_action('wp_ajax_get_product_information', 'woo_feed_get_product_information');
304
- function woo_feed_get_product_information(){
305
- check_ajax_referer('wpf_feed_nonce');
306
-
307
- if(woo_feed_wc_version_check(3.2)){
308
- $query=new WC_Product_Query(array(
309
- 'limit' => -1,
310
- 'status' => 'publish',
311
- 'orderby' => 'date',
312
- 'order' => 'DESC',
313
- 'type' => array('variable','variation','simple','grouped','external'),
314
- 'return' => 'ids',
315
- ));
316
- $products=$query->get_products();
317
- $totalProducts=count($products);
318
- }else{
319
- $products=wp_count_posts('product');
320
- $variations=wp_count_posts('product_variation');
321
- $totalProducts=$products->publish + $variations->publish;
322
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
 
 
 
 
 
 
 
 
324
 
325
- $data=array('product'=>$totalProducts);
 
 
326
 
327
- if($totalProducts>0){
328
- $data['success']=true;
329
- wp_send_json_success($data);
330
- }else{
331
- $data['success']=false;
332
- $data['message']='No products found. Add product before generating the feed.';
333
- wp_send_json_error($data);
334
- }
335
 
336
- wp_die();
337
- }
338
 
339
 
340
- /**
341
- * Check WooCommerce Version
342
- * @param string $version
343
- * @return bool
344
- */
345
- function woo_feed_wc_version_check( $version = '3.0' ) {
346
- if ( class_exists( 'WooCommerce' ) ) {
347
- global $woocommerce;
348
- if ( version_compare( $woocommerce->version, $version, ">=" ) ) {
349
- return true;
 
 
 
 
 
 
 
 
350
  }
351
  }
352
- return false;
353
- }
354
-
355
- function woo_feed_generate_feed_data($info){
356
-
357
- try{
358
- if (count($info) && isset($info['provider'])) {
359
- # GEt Post data
360
- if ($info['provider'] == 'google' || $info['provider'] == 'adroll' || $info['provider'] == 'smartly.io') {
361
- $merchant = "Woo_Feed_Google";
362
- } elseif ($info['provider'] == 'pinterest') {
363
- $merchant = "Woo_Feed_Pinterest";
364
- } elseif ($info['provider'] == 'facebook') {
365
- $merchant = "Woo_Feed_Facebook";
366
- }elseif (strpos($info['provider'],'amazon') !==FALSE) {
367
- $merchant = "Woo_Feed_Amazon";
368
- }elseif ($info['provider'] == 'custom2') {
369
- $merchant = "Woo_Feed_Custom2";
370
- } else {
371
- $merchant = "Woo_Feed_Custom";
372
- }
373
-
374
- $feedService = sanitize_text_field($info['provider']);
375
- $fileName = str_replace(" ", "", sanitize_text_field($info['filename']));
376
- $type = sanitize_text_field($info['feedType']);
377
-
378
- $feedRules = $info;
379
-
380
- # Get Feed info
381
- $products = new Woo_Generate_Feed($merchant, $feedRules);
382
- $feed = $products->getProducts();
383
- if(isset($feed['body']) && !empty($feed['body'])){
384
- $feedHeader="wf_store_feed_header_info_".$fileName;
385
- $feedBody="wf_store_feed_body_info_".$fileName;
386
- $feedFooter="wf_store_feed_footer_info_".$fileName;
387
- $prevFeed= woo_feed_get_batch_feed_info($feedService,$type,$feedBody);
388
- if($prevFeed){
389
- if($type=='csv'){
390
- if(!empty($prevFeed)){
391
- $newFeed=array_merge($prevFeed, $feed['body']);
392
- woo_feed_save_batch_feed_info($feedService,$type,$newFeed,$feedBody);
393
- }
394
- }else{
395
- $newFeed=$prevFeed.$feed['body'];
396
- woo_feed_save_batch_feed_info($feedService,$type,$newFeed,$feedBody);
397
- }
398
-
399
- }else{
400
- woo_feed_save_batch_feed_info($feedService,$type,$feed['body'],$feedBody);
401
- }
402
- woo_feed_save_batch_feed_info($feedService,$type,$feed['header'],$feedHeader);
403
- woo_feed_save_batch_feed_info($feedService,$type,$feed['footer'],$feedFooter);
404
-
405
- return true;
406
- }else{
407
- return false;
408
- }
409
- }
410
- }catch (Exception $e){
411
- return false;
412
- }
413
- return false;
414
  }
 
 
 
 
415
 
416
- /**
417
- * Save batch feed info into file
418
- * @param $feedService
419
- * @param $type
420
- * @param $string
421
- * @param $fileName
422
- * @return bool
423
- */
424
- function woo_feed_save_batch_feed_info($feedService,$type,$string,$fileName){
425
-
426
- $upload_dir = wp_upload_dir();
427
- $base = $upload_dir['basedir'];
428
- $ext=$type;
429
- if ($type == "csv") {
430
- $string=json_encode($string);
431
- $ext="json";
432
- }
433
- # Save File
434
- $path = $base . "/woo-feed/" . $feedService . "/" . $type;
435
- $file = $path . "/" . $fileName . "." . $ext;
436
- $save = new Woo_Feed_Savefile();
437
- return $save->saveFile($path, $file, $string);
438
- }
439
 
440
- function woo_feed_get_batch_feed_info($feedService,$type,$fileName){
441
-
442
- $upload_dir = wp_upload_dir();
443
- $base = $upload_dir['basedir'];
444
- $ext=$type;
445
- if ($type == "csv") {
446
- $ext="json";
447
- }
448
- # Save File
449
- $path = $base . "/woo-feed/" . $feedService . "/" . $type;
450
- $file = $path . "/" . $fileName . "." . $ext;
451
-
452
- if ($type == "csv" && file_exists($file)) {
453
- return (file_get_contents($file))?json_decode(file_get_contents($file),true):false;
454
- }else if(file_exists($file)){
455
- return file_get_contents($file);
456
- }
457
- return false;
458
- }
459
 
460
- /**
461
- * Remove temporary feed files
462
- * @param $files
463
- * @return bool
464
- */
465
- function woo_feed_unlink_tempFiles($files){
466
- if(!empty($files)){
467
- foreach ($files as $key=>$file){
468
- if(file_exists($file)){
469
- unlink($file);
470
- }
471
- }
472
- return true;
473
- }
474
- return false;
475
- }
476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
- add_action('wp_ajax_make_batch_feed', 'woo_feed_make_batch_feed');
479
- add_action('wp_ajax_nopriv_make_batch_feed', 'woo_feed_make_batch_feed');
480
- function woo_feed_make_batch_feed(){
481
- check_ajax_referer('wpf_feed_nonce');
482
-
483
- $limit=sanitize_text_field($_POST['limit']);
484
- $offset=sanitize_text_field($_POST['offset']);
485
- $feedName=sanitize_text_field(str_replace("wf_feed_","",$_POST['feed']));
486
- $feedInfo=get_option($feedName);
487
-
488
- if(!$feedInfo){
489
- $getFeedConfig=unserialize(get_option($feedName));
490
- $feedInfo=$getFeedConfig['feedrules'];
491
- }
492
-
493
- if($offset==0){
494
- $fileName = str_replace(" ", "",$feedInfo['filename']);
495
- $type = $feedInfo['feedType'];
496
- $feedService = $feedInfo['provider'];
497
- if ($type == "csv") {
498
- $type="json";
499
- }
500
-
501
- $upload_dir = wp_upload_dir();
502
- $base = $upload_dir['basedir'];
503
- $path = $base . "/woo-feed/" . $feedService . "/" . $type;
504
-
505
- $tempFiles['headerFile'] =$path . "/" . "wf_store_feed_header_info_".$fileName . "." . $type;
506
- $tempFiles['bodyFile'] =$path . "/" . "wf_store_feed_body_info_".$fileName . "." . $type;
507
- $tempFiles['footerFile'] =$path . "/" . "wf_store_feed_footer_info_".$fileName . "." . $type;
508
-
509
- woo_feed_unlink_tempFiles($tempFiles);
510
- }
511
-
512
-
513
- $feedInfo['Limit']=$limit;
514
- $feedInfo['Offset']=$offset;
515
-
516
- $feed_data=woo_feed_generate_feed_data($feedInfo);
517
- if($feed_data){
518
- $data=array(
519
- "success"=>true,
520
- "products"=>"yes",
521
- );
522
- wp_send_json_success($data);
523
- die();
524
- }else{
525
- $data=array(
526
- "success"=>true,
527
- "products"=>"no",
528
- );
529
- wp_send_json_success($data);
530
- die();
531
- }
532
- }
533
 
534
- add_action('wp_ajax_save_feed_file', 'woo_feed_save_feed_file');
535
- add_action('wp_ajax_nopriv_save_feed_file', 'woo_feed_save_feed_file');
536
- function woo_feed_save_feed_file(){
537
-
538
- check_ajax_referer('wpf_feed_nonce');
539
- $feed=str_replace("wf_feed_", "",$_REQUEST['feed']);
540
-
541
- $info=get_option($feed);
542
-
543
- if(!$info){
544
- $getInfo=unserialize(get_option($_REQUEST['feed']));
545
- $info=$getInfo['feedrules'];
546
- }
547
-
548
- $feedService = $info['provider'];
549
- $fileName = str_replace(" ", "",$info['filename']);
550
- $type = $info['feedType'];
551
-
552
- $feedHeader=woo_feed_get_batch_feed_info($feedService,$type,"wf_store_feed_header_info_".$fileName);
553
- $feedBody=woo_feed_get_batch_feed_info($feedService,$type,"wf_store_feed_body_info_".$fileName);
554
- $feedFooter=woo_feed_get_batch_feed_info($feedService,$type,"wf_store_feed_footer_info_".$fileName);
555
-
556
- if($type=='csv'){
557
- $csvHead[0]=$feedHeader;
558
- if(!empty($csvHead) && !empty($feedBody)){
559
- $string=array_merge($csvHead,$feedBody);
560
- }else{
561
- $string=array();
562
- }
563
- }else{
564
- $string=$feedHeader.$feedBody.$feedFooter;
565
- }
566
-
567
- $upload_dir = wp_upload_dir();
568
- $base = $upload_dir['basedir'];
569
- $path = $base . "/woo-feed/" . $feedService . "/" . $type;
570
- $saveFile = false;
571
- # Check If any products founds
572
- if ($string && !empty($string)) {
573
- # Save File
574
- $file = $path . "/" . $fileName . "." . $type;
575
- $save = new Woo_Feed_Savefile();
576
- if ($type == "csv") {
577
- $saveFile = $save->saveCSVFile($path, $file, $string, $info);
578
- } else {
579
- $saveFile = $save->saveFile($path, $file, $string);
580
- }
581
- }else{
582
- $data=array("success"=>false,"message"=>"No Product Found with your feed configuration. Please configure the feed properly.");
583
- wp_send_json_error($data);
584
- wp_die();
585
- }
586
-
587
-
588
- # Save Info into database
589
- $url = $upload_dir['baseurl'] . "/woo-feed/" . $feedService . "/" . $type . "/" . $fileName . "." . $type;
590
- $feedInfo = array(
591
- 'feedrules' => $info,
592
- 'url' => $url,
593
- 'last_updated' => date("Y-m-d H:i:s"),
594
- );
595
-
596
- $feedOldInfo=unserialize(get_option("wf_feed_".$fileName));
597
- if(isset($feedOldInfo['status'])){
598
- $feedInfo['status']=$feedOldInfo['status'];
599
- }else{
600
- $feedInfo['status']=1;
601
- }
602
 
603
- if (!empty($name) && $name != "wf_feed_" . $fileName) {
604
- delete_option($name);
605
- }
606
-
607
- //delete_option("wf_config".$fileName);
608
- delete_option("wf_store_feed_header_info_".$fileName);
609
- delete_option("wf_store_feed_body_info_".$fileName);
610
- delete_option("wf_store_feed_footer_info_".$fileName);
611
- if ($type == "csv") {
612
- $type="json";
613
- }
614
-
615
-
616
- # Remove Temp feed files
617
- $tempFiles['headerFile'] =$path . "/" . "wf_store_feed_header_info_".$fileName . "." . $type;
618
- $tempFiles['bodyFile'] =$path . "/" . "wf_store_feed_body_info_".$fileName . "." . $type;
619
- $tempFiles['footerFile'] =$path . "/" . "wf_store_feed_footer_info_".$fileName . "." . $type;
620
-
621
- woo_feed_unlink_tempFiles($tempFiles);
622
-
623
- $update = update_option('wf_feed_' . $fileName, serialize($feedInfo));
624
- if ($saveFile) {
625
-
626
- # FTP File Upload Info
627
- $ftpHost = $info['ftphost'];
628
- $ftpUser = $info['ftpuser'];
629
- $ftpPassword = $info['ftppassword'];
630
- $ftpPath = $info['ftppath'];
631
- $ftpEnabled = $info['ftpenabled'];
632
- $ftporsftp = isset($info['ftporsftp'])?$info['ftporsftp']:"ftp";
633
- $ftpPort = isset($info['ftpport']) && !empty($info['ftpport'])?$info['ftpport']:21;
634
- try{
635
- if ($type == "json") {
636
- $type="csv";
637
- }
638
- # Upload file to ftp server
639
- if ($ftpEnabled) {
640
- if($ftporsftp == "ftp") {
641
- $ftp = new FTPClient();
642
- if ($ftp->connect($ftpHost, $ftpUser, $ftpPassword,false,$ftpPort)){
643
- $ftp->uploadFile($file, $fileName . "." . $type);
644
- }
645
- } elseif ($ftporsftp == "sftp" && extension_loaded ( 'ssh2' )) {
646
- $sftp = new SFTPConnection($ftpHost, $ftpPort);
647
- $sftp->login($ftpUser, $ftpPassword);
648
- $sftp->uploadFile($file, "/".$fileName . "." . $type);
649
- }
650
- }
651
- }catch (Exception $e){
652
-
653
- }
654
-
655
-
656
- $getInfo = unserialize(get_option('wf_feed_' . $fileName));
657
- $url = $getInfo['url'];
658
-
659
-
660
- $cat=woo_feed_check_google_category($feedInfo);
661
-
662
- $data=array(
663
- "info"=>$feedInfo,
664
- "url"=>$url,
665
- "cat"=>$cat,
666
- "message"=>"Feed Making Complete",
667
- );
668
- wp_send_json_success($data);
669
- } else {
670
- $data=array("success"=>false,"message"=>"Failed to save feed file. Please confirm that your WordPress directory have Read and Write permission.");
671
- wp_send_json_error($data);
672
- }
673
-
674
- wp_die();
675
- }
676
 
677
- /** Check google product category added or not after making a feed.
678
- * @param $feedInfo
679
- * @return string
680
- */
681
- function woo_feed_check_google_category($feedInfo){
682
-
683
- # Check Google Product Category for Google & Facebook Template and show message
684
- $checkCategory=$feedInfo['feedrules']['mattributes'];
685
- $checkCategoryType=$feedInfo['feedrules']['type'];
686
- $merchant=$feedInfo['feedrules']['provider'];
687
- $cat="yes";
688
-
689
- if(in_array($merchant,array('google','facebook')) && in_array("current_category",$checkCategory)){
690
- $catKey=array_search('current_category',$checkCategory);
691
- if($checkCategoryType[$catKey]=="pattern"){
692
- $checkCategoryValue=$feedInfo['feedrules']['default'];
693
  }else{
694
- $checkCategoryValue=$feedInfo['feedrules']['attributes'];
695
  }
696
 
697
- if(empty($checkCategoryValue[$catKey])){
698
- $cat="no";
699
  }
700
- }
701
- return $cat;
702
- }
703
 
704
- /**
705
- * Generate Feed
706
- */
 
 
 
 
707
 
708
- function woo_feed_generate_feed()
709
- {
710
- if (isset($_POST['provider'])) {
711
-
712
- # Verify Nonce
713
- $retrieved_nonce = $_REQUEST['_wpnonce'];
714
- if (!wp_verify_nonce($retrieved_nonce, 'woo_feed_form_nonce' ) ) {
715
- wp_die( 'Failed security check' );
716
- }
717
-
718
-
719
- // ini_set('display_errors', 1);
720
- // ini_set('display_startup_errors', 1);
721
- // error_reporting(E_ALL);
722
- // $process = woo_feed_add_update($_POST);
723
- //
724
- // if ($process) {
725
- // $message = "<b>Feed Making Complete. Feed URL: <a style='font-weight: bold;color:green;' target='_blank' href=$process>$process</a></b>";
726
- // update_option('wpf_message', $message);
727
- // wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=success"));
728
- // } else {
729
- // update_option('wpf_message', 'Failed To Make Feed');
730
- // wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=error"));
731
- // }
732
-
733
- # Save feed info
734
- $fileName = "wf_config".str_replace(" ", "", sanitize_text_field($_POST['filename']));
735
- update_option($fileName,$_POST);
736
-
737
- # Schedule Cron
738
- $arg=array(sanitize_text_field($_POST['filename']));
739
- wp_schedule_event(time(), 'woo_feed_corn', 'woo_feed_update_single_feed',$arg);
740
-
741
-
742
- require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-manage-list.php';
743
- } else {
744
- echo "<div class='notice notice-warning is-dismissible'><p>" . __("You are awesome for using <b>WooCommerce Product Feed</b>. Free version works great for up to <b>2000 products including variations.</b>", 'woo-feed') . "</p></div>";
745
- require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-admin-display.php';
746
- }
747
- }
748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
 
750
- /**
751
- * Manage Feeds
752
- */
753
- function woo_feed_manage_feed()
754
- {
755
- // Manage action for category mapping
756
- if (isset($_GET['action']) && $_GET['action'] == 'edit-feed') {
757
- $fname = sanitize_text_field($_GET['feed']);
758
- if (count($_POST) && isset($_POST['provider']) && isset($_POST['edit-feed'])) {
759
-
760
- # Verify Nonce
761
- $retrieved_nonce = $_REQUEST['_wpnonce'];
762
- if (!wp_verify_nonce($retrieved_nonce, 'wf_edit_feed' ) ) {
763
- wp_die( 'Failed security check' );
764
- }
765
-
766
- // $process = woo_feed_add_update($_POST, $fname);
767
- // if ($process) {
768
- // $message = "<b>Feed Updated Successfully. Feed URL: <a style='font-weight: bold;color:green;' target='_blank' href=$process>$process</a></b>";
769
- // update_option('wpf_message', $message);
770
- // //wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=success"));
771
- // } else {
772
- // update_option('wpf_message', 'Failed To Update Feed');
773
- // // wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=error"));
774
- // }
775
-
776
- $fileName = "wf_config".str_replace(" ", "", sanitize_text_field($_POST['filename']));
777
- update_option($fileName,$_POST);
778
- require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-manage-list.php';
779
- wp_die();
780
- }
781
-
782
- $merchants=array(
783
- "custom","fruugo",
784
- "twenga","pricespy",
785
- "prisjakt","amazon",
786
- "adwords","polyvore",
787
- "bol","pricerunner",
788
- "adform","bonanza",
789
- "leeguide","real",
790
- "crowdfox","jet",
791
- "wish","google_local_inventory",
792
- "google_local", "zap.co.il",
793
- "fruugo.au", "myshopping.com.au",
794
- "smartly.io", "stylight.com",
795
- "nextad", "skinflint.co.uk",
796
- "yahoo_nfa",
797
- "comparer.be",
798
- "dooyoo",
799
- "hintaseuranta.fi",
800
- "incurvy",
801
- "kijiji.ca",
802
- "marktplaats.nl",
803
- "rakuten",
804
- "shopalike.fr",
805
- "spartoo.fi",
806
- "webmarchand",
807
- "fashiola",
808
- 'vergelijk_comparer'
809
- ,"kieskeurig.nl",
810
- 'beslist.nl',
811
- "billiger.de",
812
- "vertaa.fi",
813
- "cdiscount.fr",
814
- "fnac.fr",
815
- "idealo",
816
- "miinto.nl",
817
- "fyndiq.se",
818
- "criteo",
819
- "avantlink",
820
- "shareasale",
821
- "walmart",
822
- "modina.de"
823
- );
824
-
825
- if (isset($fname)) {
826
- $feedInfo = unserialize(get_option($fname));
827
- $provider = strtolower($feedInfo['feedrules']['provider']);
828
- $feedRules = $feedInfo['feedrules'];
829
- //$provider == "custom" ||$provider == "twenga" || $provider == "pricespy" || $provider == "prisjakt" || $provider == "amazon" || $provider == "adwords"
830
- if (in_array($provider,$merchants)) {
831
- require plugin_dir_path(__FILE__) . "admin/partials/templates/custom_edit-feed.php";
832
- } else {
833
- require plugin_dir_path(__FILE__) . "admin/partials/woo-feed-edit-template.php";
834
- }
835
- }
836
- } else {
837
- # Update Interval
838
- if (isset($_POST['wf_schedule'])) {
839
- if (update_option('wf_schedule', sanitize_text_field($_POST['wf_schedule']))) {
840
- wp_clear_scheduled_hook('woo_feed_update');
841
- add_filter('cron_schedules', 'custom_cron_job_custom_recurrence');
842
- wp_schedule_event(time(), 'woo_feed_corn', 'woo_feed_update');
843
- }
844
- }
845
-
846
- require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-manage-list.php';
847
- }
848
  }
849
-
850
- /**
851
- * Difference between free and premium plugin
852
- */
853
- function woo_feed_pro_vs_free(){
854
- require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-pro-vs-free.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
855
  }
856
-
857
- /**
858
- * Feed config
859
- */
860
- function woo_feed_config_feed(){
861
- if(isset($_POST['wa_woo_feed_config'])) {
862
- update_option("woo_feed_per_batch",sanitize_text_field($_POST['limit']));
863
- if(isset($_POST['enable_error_debugging']))
864
- {
865
- update_option("woo_feed_enable_error_debugging", sanitize_text_field($_POST['enable_error_debugging']));
866
- }
867
- else
868
- {
869
- update_option("woo_feed_enable_error_debugging", "off");
870
- }
871
- }
872
-
873
- require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-config.php';
874
  }
875
-
876
- /*
877
- * Scheduled Action Hook
878
- */
879
- add_action('wp_ajax_getFeedInfoForCronUpdate', 'woo_feed_getFeedInfoForCronUpdate');
880
- add_action('wp_ajax_nopriv_getFeedInfoForCronUpdate', 'woo_feed_getFeedInfoForCronUpdate');
881
- function woo_feed_getFeedInfoForCronUpdate(){
882
-
883
- check_ajax_referer('wpf_feed_nonce');
884
- global $wpdb;
885
- $var = "wf_feed_";
886
- $query = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
887
- $result = $wpdb->get_results($query, 'ARRAY_A');
888
- $feeds=array();
889
- foreach ($result as $key => $value) {
890
- $feedInfo = unserialize(get_option($value['option_name']));
891
- $feeds["wf_config".$value['option_name']]=$feedInfo['last_updated'];
892
- }
893
-
894
- $return = array(
895
- 'data' => $feeds,
896
- );
897
-
898
- wp_send_json($return);
899
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
900
 
901
-
902
- /**
903
- * Update feed status
904
- */
905
- add_action('wp_ajax_update_feed_status', 'woo_feed_update_feed_status');
906
- function woo_feed_update_feed_status(){
907
- if(!empty($_POST['feedName'])){
908
- $feedInfo = unserialize(get_option($_POST['feedName']));
909
- $feedInfo['status'] = $_POST['status'];
910
- $data = array('status' => true);
911
- update_option($_POST['feedName'],serialize($feedInfo));
912
- return wp_send_json_success($data);
913
- }else{
914
- $data = array('status' => false);
915
- return wp_send_json_error($data);
916
  }
917
- wp_die();
918
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
919
 
 
 
 
920
 
921
- /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
922
  * Scheduled Action Hook
923
  */
924
- function woo_feed_cron_update_feed()
925
- {
926
- global $wpdb;
927
- $var = "wf_feed_";
928
- $query = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
929
- $result = $wpdb->get_results($query, 'ARRAY_A');
930
- foreach ($result as $key => $value) {
931
- $feedInfo = unserialize(get_option($value['option_name']));
932
- if(!isset($feedInfo['status']) || $feedInfo['status'] != "0") {
933
- woo_feed_add_update( $feedInfo['feedrules'] );
934
- }
935
- }
 
 
936
  }
937
-
938
-
939
- /*
940
  * Scheduled Action Hook
941
  */
942
- function woo_feed_cron_update_single_feed($feedname)
943
- {
944
- global $wpdb;
945
 
946
- $feedname = "wf_feed_".$feedname[0];
947
 
948
 
949
 
950
- $result = $wpdb->get_results(
951
- $wpdb->prepare( "
952
  SELECT * FROM $wpdb->options
953
  WHERE option_name = %s",
954
- $feedname
955
- )
956
- ,'ARRAY_A');
957
-
958
-
959
- if(!empty($result)){
960
- foreach ($result as $key => $value) {
961
- $feedInfo = unserialize(get_option($value['option_name']));
962
- if(!isset($feedInfo['status']) || $feedInfo['status'] != "0") {
963
- woo_feed_add_update( $feedInfo['feedrules'] );
964
- }
965
- }
966
- }
967
- }
968
-
969
- /**
970
- * Add Go to Pro and Documentation link
971
- */
972
-
973
-
974
- add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'woo_feed_plugin_action_links' );
975
- function woo_feed_plugin_action_links( $links ) {
976
-
977
- if ( array_key_exists( 'deactivate', $links ) ) {
978
- $links['deactivate'] = str_replace( '<a', '<a class="wpf-deactivate-link"', $links['deactivate'] );
979
  }
980
- $links[] = '<a style="color:green;" href="https://webappick.com/plugin/woocommerce-product-feed-pro/?utm_source=freePlugin&utm_medium=go_premium&utm_campaign=free_to_pro&utm_term=wooFeed" target="_blank">' . __( '<b>Get Pro</b>', 'Woo Feed' ) . '</a>';
981
- $links[] = '<a style="color:#8e44ad;" href="http://webappick.helpscoutdocs.com/" target="_blank">' . __( 'Documentation', 'Woo Feed' ) . '</a>';
982
-
983
- return $links;
984
  }
 
 
 
 
 
 
 
 
 
 
 
985
 
986
-
987
- add_action( 'admin_footer', 'woo_feed_deactivate_scripts' );
988
-
989
-
990
- // uninstall reason
991
- add_action( 'wp_ajax_woo-feed-submit-uninstall-reason', 'woo_feed_uninstall_reason_submission' );
992
-
993
- function woo_feed_get_uninstall_reasons() {
994
-
995
- $reasons = array(
996
- array(
997
- 'id' => 'could-not-understand',
998
- 'text' => 'I couldn\'t understand how to make it work',
999
- 'type' => 'textarea',
1000
- 'placeholder' => 'Would you like us to assist you?'
1001
- ),
1002
- array(
1003
- 'id' => 'found-better-plugin',
1004
- 'text' => 'I found a better plugin',
1005
- 'type' => 'text',
1006
- 'placeholder' => 'Which plugin?'
1007
- ),
1008
- array(
1009
- 'id' => 'not-have-that-feature',
1010
- 'text' => 'The plugin is great, but I need specific feature that you don\'t support',
1011
- 'type' => 'textarea',
1012
- 'placeholder' => 'Could you tell us more about that feature?'
1013
- ),
1014
- array(
1015
- 'id' => 'is-not-working',
1016
- 'text' => 'The plugin is not working',
1017
- 'type' => 'textarea',
1018
- 'placeholder' => 'Could you tell us a bit more whats not working?'
1019
- ),
1020
- array(
1021
- 'id' => 'looking-for-other',
1022
- 'text' => 'It\'s not what I was looking for',
1023
- 'type' => '',
1024
- 'placeholder' => ''
1025
- ),
1026
- array(
1027
- 'id' => 'did-not-work-as-expected',
1028
- 'text' => 'The plugin didn\'t work as expected',
1029
- 'type' => 'textarea',
1030
- 'placeholder' => 'What did you expect?'
1031
- ),
1032
- array(
1033
- 'id' => 'other',
1034
- 'text' => 'Other',
1035
- 'type' => 'textarea',
1036
- 'placeholder' => 'Could you tell us a bit more?'
1037
- ),
1038
- );
1039
-
1040
- return $reasons;
1041
  }
1042
-
1043
- /**
1044
- * Plugin deactivation uninstall reason submission
1045
- *
1046
- * @return void
1047
- */
1048
- function woo_feed_uninstall_reason_submission(){
1049
- global $wpdb;
1050
-
1051
- if ( ! isset( $_POST['reason_id'] ) ) { // WPCS: CSRF ok, Input var ok.
1052
- wp_send_json_error();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1053
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
1054
 
1055
- $CurUser = new WP_User(get_current_user_id());
1056
 
1057
- $data = array(
1058
- 'reason_id' => sanitize_text_field( $_POST['reason_id'] ), // WPCS: CSRF ok, Input var ok.
1059
- 'plugin' => "Woo Feed Free",
1060
- 'url' => home_url(),
1061
- 'user_email' => $CurUser->data->user_email,
1062
- 'user_name' => $CurUser->data->display_name,
1063
- 'reason_info' => isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '',
1064
- 'software' => $_SERVER['SERVER_SOFTWARE'],
1065
- 'php_version' => phpversion(),
1066
- 'mysql_version' => $wpdb->db_version(),
1067
- 'wp_version' => get_bloginfo( 'version' ),
1068
- 'locale' => get_locale(),
1069
- 'multisite' => is_multisite() ? 'Yes' : 'No'
1070
- );
1071
 
1072
 
1073
- woo_feed_send_request( $data, 'uninstall_reason' );
1074
- wp_send_json_success();
1075
 
 
 
1076
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1077
 
1078
- function woo_feed_send_request( $params, $route ) {
1079
- $api_url = "https://track.webappick.com/api/receive-uninstall-tracking";
1080
- return wp_remote_post($api_url, array(
1081
- 'method' => 'POST',
1082
- 'timeout' => 45,
1083
- 'redirection' => 5,
1084
- 'httpversion' => '1.0',
1085
- 'blocking' => false,
1086
- 'headers' => array( 'user-agent' => 'Webappick/' . md5( esc_url( home_url() ) ) . ';' ),
1087
- 'body' => $params,
1088
- 'cookies' => array()
1089
- )
1090
- );
1091
-
1092
  }
1093
- /**
1094
- * Handle the plugin deactivation feedback
1095
- *
1096
- * @return void
1097
- */
1098
- function woo_feed_deactivate_scripts() {
1099
-
1100
- global $pagenow;
 
 
 
 
 
1101
 
1102
- if ( 'plugins.php' != $pagenow ) {
1103
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1104
  }
1105
-
1106
- $reasons = woo_feed_get_uninstall_reasons();
1107
- ?>
1108
- <!--pop up modal-->
1109
- <div class="wpf_deactive_plugin-modal" id="wpf_deactive_plugin-modal">
1110
- <div class="wpf_deactive_plugin-modal-wrap">
1111
- <div class="wpf_deactive_plugin-modal-header">
1112
- <h3><?php _e( 'If you have a moment, please let us know why you are deactivating:', 'woo-feed' ); ?></h3>
1113
- </div>
1114
-
1115
- <div class="wpf_deactive_plugin-modal-body">
1116
- <ul class="reasons">
1117
- <?php foreach ($reasons as $reason) { ?>
1118
- <li data-type="<?php echo esc_attr( $reason['type'] ); ?>" data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>">
1119
- <label><input type="radio" name="selected-reason" value="<?php echo $reason['id']; ?>"> <?php echo $reason['text']; ?></label>
1120
- </li>
1121
- <?php } ?>
1122
- </ul>
1123
- </div>
1124
-
1125
- <div class="wpf_deactive_plugin-modal-footer">
1126
- <a href="#" class="dont-bother-me"><?php _e( 'I rather wouldn\'t say', 'Woo Feed' ); ?></a>
1127
- <button class="button-secondary"><?php _e( 'Submit & Deactivate', 'Woo Feed' ); ?></button>
1128
- <button class="button-primary"><?php _e( 'Cancel', 'Woo Feed' ); ?></button>
1129
- </div>
1130
- </div>
1131
- </div>
1132
-
1133
- <?php
1134
  }
1135
-
1136
- add_action('wp_ajax_get_ssh2_status', 'woo_feed_get_ssh2_status');
1137
- function woo_feed_get_ssh2_status() {
1138
- check_ajax_referer( 'wpf_feed_nonce' );
1139
- $php_extension = get_loaded_extensions();
1140
- if(extension_loaded ( 'ssh2' )) {
1141
- wp_send_json_success('exists');
1142
- } else {
1143
- wp_send_json_success('not exists');
1144
- }
1145
-
1146
  }
1147
-
1148
- add_action( 'admin_notices', 'woo_feed_review_notice' );
1149
-
1150
- function woo_feed_review_notice() {
1151
- $options = get_option('woo_feed_review_notice');
1152
- $installDate=get_option('woo-feed-activation-time');
1153
- $installDate=strtotime('-16 days',$installDate);
1154
-
1155
- $notice = '<div class="woo-feed-review-notice notice notice-info is-dismissible">';
1156
- $notice .= '<p><b>:) We have spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating. Your opinion matters a lot to us. It helps us to get better. Thanks for using <i>WooCommerce Product Feed</i>.</b></p>';
1157
- $notice .= '<ul>';
1158
- $notice .= '<li><a val="later" href="#">Remind me later</a></li>';
1159
- $notice .= '<li><a val="never" href="#">I would not</a></li>';
1160
- $notice .= '<li><a val="given" href="#" target="_blank">Review Here</a></li>';
1161
- $notice .= '</ul>';
1162
- $notice .= '</div>';
1163
-
1164
- if(!$options && time()>= $installDate + (60*60*24*15)){
1165
- echo $notice;
1166
- } else if(is_array($options)) {
1167
- if((!array_key_exists('review_notice',$options)) || ($options['review_notice'] =='later' && time()>=($options['updated_at'] + (60*60*24*30) ))){
1168
- echo $notice;
1169
- }
1170
- }
1171
  }
1172
-
1173
-
1174
-
1175
- /**
1176
- * Show Review request admin notice
1177
- */
1178
- add_action('wp_ajax_woo_feed_save_review_notice', 'woo_feed_save_review_notice');
1179
- function woo_feed_save_review_notice() {
1180
- $notice = sanitize_text_field($_POST['notice']);
1181
- $value['review_notice'] = $notice;
1182
- $value['updated_at'] = time();
1183
-
1184
- update_option('woo_feed_review_notice',$value);
1185
- wp_send_json_success($value);
1186
  }
1187
-
1188
- /**
1189
- * Show notice if WPML installed
1190
- */
1191
- add_action( 'admin_notices', 'woo_feed_wpml_notice' );
1192
- function woo_feed_wpml_notice() {
1193
- if (class_exists('SitePress') && get_option('woo_feed_wpml_notice') == false) {
1194
- $wpml_notice = '<div class="woo-feed-wpml-notice notice notice-success is-dismissible">';
1195
- $wpml_notice .= '<p>You are awesome for using <b>WooCommerce Product Feed</b>.
1196
  Using the <b><a href="https://webappick.com/plugin/woocommerce-product-feed-pro/" target="_blank">Premium</a></b> version you can make multilingual feed for your WPML languages.</p>';
1197
- $wpml_notice .= '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>';
1198
- $wpml_notice .= '</div>';
1199
- echo $wpml_notice;
1200
- }
 
 
1201
  }
1202
-
1203
- add_action('wp_ajax_woo_feed_save_wpml_notice', 'woo_feed_save_wpml_notice');
1204
- function woo_feed_save_wpml_notice() {
1205
- $notice = true;
1206
- $value['wpml_notice'] = $notice;
1207
- update_option('woo_feed_wpml_notice',$value);
1208
-
1209
- wp_send_json_success();
 
1210
  }
 
15
  * Plugin Name: WooCommerce Product Feed
16
  * Plugin URI: https://webappick.com/
17
  * Description: This plugin generate WooCommerce product feed for Shopping Engines like Google Shopping,Facebook Product Feed,eBay,Amazon,Idealo and many more..
18
+ * Version: 3.1.34
19
  * Author: WebAppick
20
  * Author URI: https://webappick.com/
21
  * License: GPL v2
27
  *
28
  */
29
 
 
 
 
 
30
  // Exit if accessed directly
31
+ if (!defined('ABSPATH')) die();
 
 
32
 
33
+ /**
34
+ * Plugin Version
35
+ * @var string
36
+ */
37
+ define( 'WOO_FEED_VERSION', '3.1.34' );
38
 
39
  /**
40
  * Plugin Path with trailing slash
47
  */
48
  define( 'WOO_FEED_Admin_Path', WOO_FEED_Path . 'admin/' );
49
 
50
+ if( ! class_exists( 'Woo_Feed' ) ) {
51
+ /**
52
+ * The core plugin class that is used to define internationalization,
53
+ * admin-specific hooks, and public-facing site hooks.
54
+ */
55
+ require plugin_dir_path(__FILE__) . 'includes/class-woo-feed.php';
 
 
 
 
 
 
 
 
 
 
56
  }
57
+ if( ! function_exists( 'activate_woo_feed' ) ) {
58
+ /**
59
+ * The code that runs during plugin activation.
60
+ * This action is documented in includes/class-woo-feed-activator.php
61
+ */
62
+ function activate_woo_feed() {
63
+ require plugin_dir_path(__FILE__) . 'includes/class-woo-feed-activator.php';
64
+ Woo_Feed_Activator::activate();
65
+ }
66
+ register_activation_hook(__FILE__, 'activate_woo_feed');
67
  }
68
+ if( ! function_exists( 'deactivate_woo_feed' ) ) {
69
+ /**
70
+ * The code that runs during plugin deactivation.
71
+ * This action is documented in includes/class-woo-feed-deactivator.php
72
+ */
73
+ function deactivate_woo_feed() {
74
+ require plugin_dir_path(__FILE__) . 'includes/class-woo-feed-deactivator.php';
75
+ Woo_Feed_Deactivator::deactivate();
76
+ }
77
+ register_deactivation_hook(__FILE__, 'deactivate_woo_feed');
 
 
 
 
 
 
 
78
  }
79
+ if( ! function_exists( 'run_woo_feed' ) ) {
80
+ /**
81
+ * Begins execution of the plugin.
82
+ *
83
+ * Since everything within the plugin is registered via hooks,
84
+ * then kicking off the plugin from this point in the file does
85
+ * not affect the page life cycle.
86
+ *
87
+ * @since 1.0.0
88
+ */
89
+ function run_woo_feed() {
90
+ $plugin = new Woo_Feed();
91
+ $plugin->run();
92
+ }
93
+ run_woo_feed();
94
  }
95
+ if( ! function_exists( 'custom_cron_job_custom_recurrence' ) ) {
96
+ # Custom Cron Recurrences
97
+ function custom_cron_job_custom_recurrence($schedules)
98
+ {
99
+ $interval = get_option('wf_schedule');
100
+ $schedules['woo_feed_corn'] = array(
101
+ 'display' => __('Woo Feed Update Interval', 'woo-feed'),
102
+ 'interval' => $interval,
103
+ );
104
+
105
+ return $schedules;
106
+ }
107
+ add_filter('cron_schedules', 'custom_cron_job_custom_recurrence');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
+ if( ! function_exists( 'feed_merchant_view' ) ) {
110
+ # Load Feed Templates
111
+ function feed_merchant_view()
112
+ {
113
+ check_ajax_referer('wpf_feed_nonce');
114
+ /** @noinspection PhpUnusedLocalVariableInspection */
115
+ $dropDown = new Woo_Feed_Dropdown();
116
+ /** @noinspection PhpUnusedLocalVariableInspection */
117
+ $product = new Woo_Feed_Products();
118
+ /** @noinspection PhpUnusedLocalVariableInspection */
119
+ $attributes = new Woo_Feed_Default_Attributes();
120
+ /** @noinspection PhpUnusedLocalVariableInspection */
121
+ $merchant = $provider = sanitize_text_field($_POST['merchant']);
122
+ if(strpos($merchant,'amazon')!==false){
123
+ include plugin_dir_path(__FILE__) . "admin/partials/templates/amazon_add-feed.php";
124
+ }
125
+ else if($merchant == 'smartly.io')
126
+ {
127
+ include plugin_dir_path(__FILE__) . "admin/partials/templates/google_add-feed.php";
128
+ }
129
+ else{
130
+ include plugin_dir_path(__FILE__) . "admin/partials/templates/". $merchant . "_add-feed.php";
131
+ }
132
+ die();
133
+ }
134
+ add_action('wp_ajax_get_feed_merchant', 'feed_merchant_view');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  }
136
+ if( ! function_exists( 'woo_feed_add_update' ) ) {
137
+ /**
138
+ * Update Feed Information
139
+ */
140
+ function woo_feed_add_update($info = "", $name = "")
141
+ {
142
+ set_time_limit(0);
143
+ if (count($info) && isset($info['provider'])) {
144
+ # GEt Post data
145
+ if ($info['provider'] == 'google' || $info['provider'] == 'adroll' || $info['provider'] == 'smartly.io') {
146
+ $merchant = "Woo_Feed_Google";
147
+ } elseif ($info['provider'] == 'pinterest') {
148
+ $merchant = "Woo_Feed_Pinterest";
149
+ } elseif ($info['provider'] == 'facebook') {
150
+ $merchant = "Woo_Feed_Facebook";
151
+ }elseif (strpos($info['provider'],'amazon') !==FALSE) {
152
+ $merchant = "Woo_Feed_Amazon";
153
+ } else {
154
+ $merchant = "Woo_Feed_Custom";
155
+ }
156
+
157
+
158
+ $feedService = sanitize_text_field($info['provider']);
159
+ $fileName = str_replace(" ", "", sanitize_text_field($info['filename']));
160
+ $type = sanitize_text_field($info['feedType']);
161
+
162
+ $feedRules = $info;
163
+
164
+ # Get Feed info
165
+ $products = new Woo_Generate_Feed($merchant, $feedRules);
166
+ $getString = $products->getProducts();
167
+
168
+ if($type=='csv'){
169
+ $csvHead[0]=$getString['header'];
170
+ if(!empty($csvHead) && !empty($getString['body'])){
171
+ $string=array_merge($csvHead,$getString['body']);
172
+ }else{
173
+ $string=array();
174
+ }
175
+ }else{
176
+ $string=$getString['header'].$getString['body'].$getString['footer'];
177
+ }
178
+
179
+ # Check If any products founds
180
+ if ($string && !empty($string)) {
181
+
182
+ $upload_dir = wp_upload_dir();
183
+ $base = $upload_dir['basedir'];
184
+
185
+ # Save File
186
+ $path = $base . "/woo-feed/" . $feedService . "/" . $type;
187
+ $file = $path . "/" . $fileName . "." . $type;
188
+ $save = new Woo_Feed_Savefile();
189
+ if ($type == "csv") {
190
+ $saveFile = $save->saveCSVFile($path, $file, $string, $info);
191
+ } else {
192
+ $saveFile = $save->saveFile($path, $file, $string);
193
+ }
194
+
195
+ # FTP File Upload Info
196
+ $ftpHost = sanitize_text_field($info['ftphost']);
197
+ $ftpUser = sanitize_text_field($info['ftpuser']);
198
+ $ftpPassword = sanitize_text_field($info['ftppassword']);
199
+ $ftpPath = sanitize_text_field($info['ftppath']);
200
+ $ftpPort = isset($info['ftpport']) && !empty($info['ftpport'])?sanitize_text_field($info['ftpport']):21;
201
+ $ftpEnabled = sanitize_text_field($info['ftpenabled']);
202
+
203
+ $ftporsftp = isset($info['ftporsftp'])?sanitize_text_field($info['ftporsftp']):"ftp";
204
+
205
+
206
+ try{
207
+ if ($type == "json") {
208
+ $type="csv";
209
+ }
210
+ # Upload file to ftp server
211
+ if ($ftpEnabled) {
212
+ if($ftporsftp == "ftp") {
213
+ $ftp = new FTPClient();
214
+ if ($ftp->connect($ftpHost, $ftpUser, $ftpPassword,false,$ftpPort)){
215
+ $ftp->uploadFile($file, $fileName . "." . $type);
216
+ }
217
+ } elseif ($ftporsftp == "sftp" && extension_loaded ( 'ssh2' )) {
218
+ $sftp = new SFTPConnection($ftpHost, $ftpPort);
219
+ $sftp->login($ftpUser, $ftpPassword);
220
+ $sftp->uploadFile($file, "/".$fileName . "." . $type);
221
+ }
222
+ }
223
+ }catch (Exception $e){
224
+
225
+ }
226
+
227
+ # Save Info into database
228
+ $url = $upload_dir['baseurl'] . "/woo-feed/" . $feedService . "/" . $type . "/" . $fileName . "." . $type;
229
+ $feedInfo = array(
230
+ 'feedrules' => $feedRules,
231
+ 'url' => $url,
232
+ 'last_updated' => date("Y-m-d H:i:s"),
233
+ 'status'=>1
234
+ );
235
+
236
+
237
+ if (!empty($name) && $name != "wf_feed_" . $fileName) {
238
+ delete_option($name);
239
+ }
240
+
241
+ $update = update_option('wf_feed_' . $fileName, serialize($feedInfo));
242
+ if ($saveFile) {
243
+ $getInfo = unserialize(get_option('wf_feed_' . $fileName));
244
+ $url = $getInfo['url'];
245
+ return $url;
246
+ } else {
247
+ return false;
248
+ }
249
+ }
250
+ }
251
 
252
+ return false;
253
+ }
254
+ }
255
+ if( ! function_exists( 'woo_feed_array_sanitize' ) ) {
256
+ /**
257
+ * Sanitize array post
258
+ *
259
+ * @param $array
260
+ *
261
+ * @return array
262
+ */
263
+ function woo_feed_array_sanitize($array)
264
+ {
265
+ $newArray = array();
266
+ if (count($array)) {
267
+ foreach ($array as $key => $value) {
268
+ if (is_array($value)) {
269
+ foreach ($value as $key2 => $value2) {
270
+ if (is_array($value2)) {
271
+ foreach ($value2 as $key3 => $value3) {
272
+ $newArray[$key][$key2][$key3] = sanitize_text_field($value3);
273
+ }
274
+ } else {
275
+ $newArray[$key][$key2] = sanitize_text_field($value2);
276
+ }
277
+ }
278
+ } else {
279
+ $newArray[$key] = sanitize_text_field($value);
280
+ }
281
+ }
282
+ }
283
+ return $newArray;
284
+ }
285
  }
 
286
  #======================================================================================================================*
287
  #
288
  # Ajax Feed Making Development Start
289
  #
290
  #======================================================================================================================*
291
+ if( ! function_exists( 'woo_feed_get_product_information' ) ) {
292
+ /**
293
+ * Count Total Products
294
+ */
295
+ function woo_feed_get_product_information(){
296
+ check_ajax_referer('wpf_feed_nonce');
297
+
298
+ if(woo_feed_wc_version_check(3.2)){
299
+ $query=new WC_Product_Query(array(
300
+ 'limit' => -1,
301
+ 'status' => 'publish',
302
+ 'orderby' => 'date',
303
+ 'order' => 'DESC',
304
+ 'type' => array('variable','variation','simple','grouped','external'),
305
+ 'return' => 'ids',
306
+ ));
307
+ $products=$query->get_products();
308
+ $totalProducts=count($products);
309
+ }else{
310
+ $products=wp_count_posts('product');
311
+ $variations=wp_count_posts('product_variation');
312
+ $totalProducts=$products->publish + $variations->publish;
313
+ }
314
 
315
 
316
+ $data=array('product'=>$totalProducts);
 
 
317
 
318
+ if($totalProducts>0){
319
+ $data['success']=true;
320
+ wp_send_json_success($data);
321
+ }else{
322
+ $data['success']=false;
323
+ $data['message']='No products found. Add product before generating the feed.';
324
+ wp_send_json_error($data);
325
+ }
326
+
327
+ wp_die();
 
 
 
 
 
 
 
 
 
328
  }
329
+ add_action('wp_ajax_get_product_information', 'woo_feed_get_product_information');
330
+ }
331
+ if( ! function_exists( 'woo_feed_wc_version_check' ) ) {
332
+ /**
333
+ * Check WooCommerce Version
334
+ * @param string $version
335
+ * @return bool
336
+ */
337
+ function woo_feed_wc_version_check( $version = '3.0' ) {
338
+ if ( class_exists( 'WooCommerce' ) ) {
339
+ global $woocommerce;
340
+ if ( version_compare( $woocommerce->version, $version, ">=" ) ) {
341
+ return true;
342
+ }
343
+ }
344
+ return false;
345
+ }
346
+ }
347
+ if( ! function_exists( 'woo_feed_generate_feed_data' ) ) {
348
+ function woo_feed_generate_feed_data($info){
349
+
350
+ try{
351
+ if (count($info) && isset($info['provider'])) {
352
+ # GEt Post data
353
+ if ($info['provider'] == 'google' || $info['provider'] == 'adroll' || $info['provider'] == 'smartly.io') {
354
+ $merchant = "Woo_Feed_Google";
355
+ } elseif ($info['provider'] == 'pinterest') {
356
+ $merchant = "Woo_Feed_Pinterest";
357
+ } elseif ($info['provider'] == 'facebook') {
358
+ $merchant = "Woo_Feed_Facebook";
359
+ }elseif (strpos($info['provider'],'amazon') !==FALSE) {
360
+ $merchant = "Woo_Feed_Amazon";
361
+ }elseif ($info['provider'] == 'custom2') {
362
+ $merchant = "Woo_Feed_Custom2";
363
+ } else {
364
+ $merchant = "Woo_Feed_Custom";
365
+ }
366
+
367
+ $feedService = sanitize_text_field($info['provider']);
368
+ $fileName = str_replace(" ", "", sanitize_text_field($info['filename']));
369
+ $type = sanitize_text_field($info['feedType']);
370
+
371
+ $feedRules = $info;
372
+
373
+ # Get Feed info
374
+ $products = new Woo_Generate_Feed($merchant, $feedRules);
375
+ $feed = $products->getProducts();
376
+ if(isset($feed['body']) && !empty($feed['body'])){
377
+ $feedHeader="wf_store_feed_header_info_".$fileName;
378
+ $feedBody="wf_store_feed_body_info_".$fileName;
379
+ $feedFooter="wf_store_feed_footer_info_".$fileName;
380
+ $prevFeed= woo_feed_get_batch_feed_info($feedService,$type,$feedBody);
381
+ if($prevFeed){
382
+ if($type=='csv'){
383
+ if(!empty($prevFeed)){
384
+ $newFeed=array_merge($prevFeed, $feed['body']);
385
+ woo_feed_save_batch_feed_info($feedService,$type,$newFeed,$feedBody);
386
+ }
387
+ }else{
388
+ $newFeed=$prevFeed.$feed['body'];
389
+ woo_feed_save_batch_feed_info($feedService,$type,$newFeed,$feedBody);
390
+ }
391
+
392
+ }else{
393
+ woo_feed_save_batch_feed_info($feedService,$type,$feed['body'],$feedBody);
394
+ }
395
+ woo_feed_save_batch_feed_info($feedService,$type,$feed['header'],$feedHeader);
396
+ woo_feed_save_batch_feed_info($feedService,$type,$feed['footer'],$feedFooter);
397
+
398
+ return true;
399
+ }else{
400
+ return false;
401
+ }
402
+ }
403
+ }catch (Exception $e){
404
+ return false;
405
+ }
406
+ return false;
407
+ }
408
+ }
409
+ if( ! function_exists( 'woo_feed_save_batch_feed_info' ) ) {
410
+ /**
411
+ * Save batch feed info into file
412
+ * @param $feedService
413
+ * @param $type
414
+ * @param $string
415
+ * @param $fileName
416
+ * @return bool
417
+ */
418
+ function woo_feed_save_batch_feed_info($feedService,$type,$string,$fileName){
419
+
420
+ $upload_dir = wp_upload_dir();
421
+ $base = $upload_dir['basedir'];
422
+ $ext=$type;
423
+ if ($type == "csv") {
424
+ $string=json_encode($string);
425
+ $ext="json";
426
+ }
427
+ # Save File
428
+ $path = $base . "/woo-feed/" . $feedService . "/" . $type;
429
+ $file = $path . "/" . $fileName . "." . $ext;
430
+ $save = new Woo_Feed_Savefile();
431
+ return $save->saveFile($path, $file, $string);
432
+ }
433
+ }
434
+ if( ! function_exists( 'woo_feed_get_batch_feed_info' ) ) {
435
+ function woo_feed_get_batch_feed_info($feedService,$type,$fileName){
436
+
437
+ $upload_dir = wp_upload_dir();
438
+ $base = $upload_dir['basedir'];
439
+ $ext=$type;
440
+ if ($type == "csv") {
441
+ $ext="json";
442
+ }
443
+ # Save File
444
+ $path = $base . "/woo-feed/" . $feedService . "/" . $type;
445
+ $file = $path . "/" . $fileName . "." . $ext;
446
+
447
+ if ($type == "csv" && file_exists($file)) {
448
+ return (file_get_contents($file))?json_decode(file_get_contents($file),true):false;
449
+ }else if(file_exists($file)){
450
+ return file_get_contents($file);
451
+ }
452
+ return false;
453
+ }
454
+ }
455
+ if( ! function_exists( 'woo_feed_unlink_tempFiles' ) ) {
456
+ /**
457
+ * Remove temporary feed files
458
+ * @param $files
459
+ * @return bool
460
+ */
461
+ function woo_feed_unlink_tempFiles($files){
462
+ if(!empty($files)){
463
+ foreach ($files as $key=>$file){
464
+ if(file_exists($file)){
465
+ unlink($file);
466
+ }
467
+ }
468
+ return true;
469
+ }
470
+ return false;
471
+ }
472
+ }
473
+ if( ! function_exists( 'woo_feed_make_batch_feed' ) ) {
474
+ function woo_feed_make_batch_feed(){
475
+ check_ajax_referer('wpf_feed_nonce');
476
+
477
+ $limit=sanitize_text_field($_POST['limit']);
478
+ $offset=sanitize_text_field($_POST['offset']);
479
+ $feedName=sanitize_text_field(str_replace("wf_feed_","",$_POST['feed']));
480
+ $feedInfo=get_option($feedName);
481
+
482
+ if(!$feedInfo){
483
+ $getFeedConfig=unserialize(get_option($feedName));
484
+ $feedInfo=$getFeedConfig['feedrules'];
485
+ }
486
 
487
+ if($offset==0){
488
+ $fileName = str_replace(" ", "",$feedInfo['filename']);
489
+ $type = $feedInfo['feedType'];
490
+ $feedService = $feedInfo['provider'];
491
+ if ($type == "csv") {
492
+ $type="json";
493
+ }
494
 
495
+ $upload_dir = wp_upload_dir();
496
+ $base = $upload_dir['basedir'];
497
+ $path = $base . "/woo-feed/" . $feedService . "/" . $type;
498
 
499
+ $tempFiles['headerFile'] =$path . "/" . "wf_store_feed_header_info_".$fileName . "." . $type;
500
+ $tempFiles['bodyFile'] =$path . "/" . "wf_store_feed_body_info_".$fileName . "." . $type;
501
+ $tempFiles['footerFile'] =$path . "/" . "wf_store_feed_footer_info_".$fileName . "." . $type;
 
 
 
 
 
502
 
503
+ woo_feed_unlink_tempFiles($tempFiles);
504
+ }
505
 
506
 
507
+ $feedInfo['Limit']=$limit;
508
+ $feedInfo['Offset']=$offset;
509
+
510
+ $feed_data=woo_feed_generate_feed_data($feedInfo);
511
+ if($feed_data){
512
+ $data=array(
513
+ "success"=>true,
514
+ "products"=>"yes",
515
+ );
516
+ wp_send_json_success($data);
517
+ die();
518
+ }else{
519
+ $data=array(
520
+ "success"=>true,
521
+ "products"=>"no",
522
+ );
523
+ wp_send_json_success($data);
524
+ die();
525
  }
526
  }
527
+ add_action('wp_ajax_make_batch_feed', 'woo_feed_make_batch_feed');
528
+ add_action('wp_ajax_nopriv_make_batch_feed', 'woo_feed_make_batch_feed');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  }
530
+ if( ! function_exists( 'woo_feed_save_feed_file' ) ) {
531
+ add_action('wp_ajax_save_feed_file', 'woo_feed_save_feed_file');
532
+ add_action('wp_ajax_nopriv_save_feed_file', 'woo_feed_save_feed_file');
533
+ function woo_feed_save_feed_file(){
534
 
535
+ check_ajax_referer('wpf_feed_nonce');
536
+ $feed=str_replace("wf_feed_", "",$_REQUEST['feed']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
 
538
+ $info=get_option($feed);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
539
 
540
+ if(!$info){
541
+ $getInfo=unserialize(get_option($_REQUEST['feed']));
542
+ $info=$getInfo['feedrules'];
543
+ }
 
 
 
 
 
 
 
 
 
 
 
 
544
 
545
+ $feedService = $info['provider'];
546
+ $fileName = str_replace(" ", "",$info['filename']);
547
+ $type = $info['feedType'];
548
+
549
+ $feedHeader=woo_feed_get_batch_feed_info($feedService,$type,"wf_store_feed_header_info_".$fileName);
550
+ $feedBody=woo_feed_get_batch_feed_info($feedService,$type,"wf_store_feed_body_info_".$fileName);
551
+ $feedFooter=woo_feed_get_batch_feed_info($feedService,$type,"wf_store_feed_footer_info_".$fileName);
552
+
553
+ if($type=='csv'){
554
+ $csvHead[0]=$feedHeader;
555
+ if(!empty($csvHead) && !empty($feedBody)){
556
+ $string=array_merge($csvHead,$feedBody);
557
+ }else{
558
+ $string=array();
559
+ }
560
+ }else{
561
+ $string=$feedHeader.$feedBody.$feedFooter;
562
+ }
563
 
564
+ $upload_dir = wp_upload_dir();
565
+ $base = $upload_dir['basedir'];
566
+ $path = $base . "/woo-feed/" . $feedService . "/" . $type;
567
+ $saveFile = false;
568
+ # Check If any products founds
569
+ if ($string && !empty($string)) {
570
+ # Save File
571
+ $file = $path . "/" . $fileName . "." . $type;
572
+ $save = new Woo_Feed_Savefile();
573
+ if ($type == "csv") {
574
+ $saveFile = $save->saveCSVFile($path, $file, $string, $info);
575
+ } else {
576
+ $saveFile = $save->saveFile($path, $file, $string);
577
+ }
578
+ }else{
579
+ $data=array("success"=>false,"message"=>"No Product Found with your feed configuration. Please configure the feed properly.");
580
+ wp_send_json_error($data);
581
+ wp_die();
582
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
 
585
+ # Save Info into database
586
+ $url = $upload_dir['baseurl'] . "/woo-feed/" . $feedService . "/" . $type . "/" . $fileName . "." . $type;
587
+ $feedInfo = array(
588
+ 'feedrules' => $info,
589
+ 'url' => $url,
590
+ 'last_updated' => date("Y-m-d H:i:s"),
591
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
 
593
+ $feedOldInfo=unserialize(get_option("wf_feed_".$fileName));
594
+ if(isset($feedOldInfo['status'])){
595
+ $feedInfo['status']=$feedOldInfo['status'];
 
 
 
 
 
 
 
 
 
 
 
 
 
596
  }else{
597
+ $feedInfo['status']=1;
598
  }
599
 
600
+ if (!empty($name) && $name != "wf_feed_" . $fileName) {
601
+ delete_option($name);
602
  }
 
 
 
603
 
604
+ //delete_option("wf_config".$fileName);
605
+ delete_option("wf_store_feed_header_info_".$fileName);
606
+ delete_option("wf_store_feed_body_info_".$fileName);
607
+ delete_option("wf_store_feed_footer_info_".$fileName);
608
+ if ($type == "csv") {
609
+ $type="json";
610
+ }
611
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
 
613
+ # Remove Temp feed files
614
+ $tempFiles['headerFile'] =$path . "/" . "wf_store_feed_header_info_".$fileName . "." . $type;
615
+ $tempFiles['bodyFile'] =$path . "/" . "wf_store_feed_body_info_".$fileName . "." . $type;
616
+ $tempFiles['footerFile'] =$path . "/" . "wf_store_feed_footer_info_".$fileName . "." . $type;
617
+
618
+ woo_feed_unlink_tempFiles($tempFiles);
619
+
620
+ $update = update_option('wf_feed_' . $fileName, serialize($feedInfo));
621
+ if ($saveFile) {
622
+
623
+ # FTP File Upload Info
624
+ $ftpHost = $info['ftphost'];
625
+ $ftpUser = $info['ftpuser'];
626
+ $ftpPassword = $info['ftppassword'];
627
+ $ftpPath = $info['ftppath'];
628
+ $ftpEnabled = $info['ftpenabled'];
629
+ $ftporsftp = isset($info['ftporsftp'])?$info['ftporsftp']:"ftp";
630
+ $ftpPort = isset($info['ftpport']) && !empty($info['ftpport'])?$info['ftpport']:21;
631
+ try{
632
+ if ($type == "json") {
633
+ $type="csv";
634
+ }
635
+ # Upload file to ftp server
636
+ if ($ftpEnabled) {
637
+ if($ftporsftp == "ftp") {
638
+ $ftp = new FTPClient();
639
+ if ($ftp->connect($ftpHost, $ftpUser, $ftpPassword,false,$ftpPort)){
640
+ $ftp->uploadFile($file, $fileName . "." . $type);
641
+ }
642
+ } elseif ($ftporsftp == "sftp" && extension_loaded ( 'ssh2' )) {
643
+ $sftp = new SFTPConnection($ftpHost, $ftpPort);
644
+ $sftp->login($ftpUser, $ftpPassword);
645
+ $sftp->uploadFile($file, "/".$fileName . "." . $type);
646
+ }
647
+ }
648
+ }catch (Exception $e){
649
+
650
+ }
651
+
652
+
653
+ $getInfo = unserialize(get_option('wf_feed_' . $fileName));
654
+ $url = $getInfo['url'];
655
+
656
+
657
+ $cat=woo_feed_check_google_category($feedInfo);
658
+
659
+ $data=array(
660
+ "info"=>$feedInfo,
661
+ "url"=>$url,
662
+ "cat"=>$cat,
663
+ "message"=>"Feed Making Complete",
664
+ );
665
+ wp_send_json_success($data);
666
+ } else {
667
+ $data=array("success"=>false,"message"=>"Failed to save feed file. Please confirm that your WordPress directory have Read and Write permission.");
668
+ wp_send_json_error($data);
669
+ }
670
 
671
+ wp_die();
672
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  }
674
+ if( ! function_exists( 'woo_feed_check_google_category' ) ) {
675
+ /** Check google product category added or not after making a feed.
676
+ * @param $feedInfo
677
+ * @return string
678
+ */
679
+ function woo_feed_check_google_category($feedInfo){
680
+
681
+ # Check Google Product Category for Google & Facebook Template and show message
682
+ $checkCategory=$feedInfo['feedrules']['mattributes'];
683
+ $checkCategoryType=$feedInfo['feedrules']['type'];
684
+ $merchant=$feedInfo['feedrules']['provider'];
685
+ $cat="yes";
686
+
687
+ if(in_array($merchant,array('google','facebook')) && in_array("current_category",$checkCategory)){
688
+ $catKey=array_search('current_category',$checkCategory);
689
+ if($checkCategoryType[$catKey]=="pattern"){
690
+ $checkCategoryValue=$feedInfo['feedrules']['default'];
691
+ }else{
692
+ $checkCategoryValue=$feedInfo['feedrules']['attributes'];
693
+ }
694
+
695
+ if(empty($checkCategoryValue[$catKey])){
696
+ $cat="no";
697
+ }
698
+ }
699
+ return $cat;
700
+ }
701
  }
702
+ if( ! function_exists( 'woo_feed_get_file_dir' ) ) {
703
+ /**
704
+ * Get Feed Directory
705
+ * @param string $provider
706
+ * @param string $feedType
707
+ * @return string
708
+ */
709
+ function woo_feed_get_file_dir( $provider, $feedType ) {
710
+ $upload_dir = wp_upload_dir();
711
+ $base = $upload_dir['basedir'];
712
+ return $base . "/woo-feed/" . $provider . "/" . $feedType;
713
+ }
 
 
 
 
 
 
714
  }
715
+ if( ! function_exists( 'woo_feed_sanitize_form_fields' ) ) {
716
+ /**
717
+ * Sanitize Form Fields ($_POST Array)
718
+ * @param array $data
719
+ * @return array
720
+ */
721
+ function woo_feed_sanitize_form_fields( $data ) {
722
+ foreach( $data as $k => $v ) {
723
+ if( is_array( $v ) ) $v = woo_feed_sanitize_form_fields( $v );
724
+ else {
725
+ $v = sanitize_text_field( $v );
726
+ $v = trim( $v );
727
+ }
728
+ $data[$k] = $v;
729
+ }
730
+ return $data;
731
+ }
 
 
 
 
 
 
 
732
  }
733
+ if( ! function_exists( 'woo_feed_unique_feed_slug' ) ) {
734
+ /**
735
+ * Generate Unique slug for feed.
736
+ * @see wp_unique_post_slug()
737
+ * @param string $slug
738
+ * @param int $feedId
739
+ * @return string
740
+ */
741
+ function woo_feed_unique_feed_slug( $slug, $feedId = null ) {
742
+ global $wpdb;
743
+ /** @noinspection SpellCheckingInspection */
744
+ $disallowed = array( 'siteurl', 'home', 'blogname', 'blogdescription', 'users_can_register', 'admin_email' );
745
+ if( $feedId && $feedId > 0 ) {
746
+ $checkSql = "SELECT option_name FROM $wpdb->options WHERE option_name = %s AND option_id != %d LIMIT 1";
747
+ $nameCheck = $wpdb->get_var( $wpdb->prepare( $checkSql, $slug, $feedId ) );
748
+ } else {
749
+ $checkSql = "SELECT option_name FROM $wpdb->options WHERE option_name = %s LIMIT 1";
750
+ $nameCheck = $wpdb->get_var( $wpdb->prepare( $checkSql, $slug ) );
751
+ }
752
+ if( $nameCheck || in_array( $slug, $disallowed ) ) {
753
+ $suffix = 2;
754
+ do {
755
+ $altName = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
756
+ if( $feedId && $feedId > 0 ) {
757
+ $nameCheck = $wpdb->get_var( $wpdb->prepare( $checkSql, $altName, $feedId ) );
758
+ } else {
759
+ $nameCheck = $wpdb->get_var( $wpdb->prepare( $checkSql, $altName ) );
760
+ }
761
+ $suffix++;
762
+ } while ( $nameCheck );
763
+ $slug = $altName;
764
+ }
765
+ return $slug;
766
+ }
767
+ }
768
+ if( ! function_exists( 'woo_feed_generate_feed' ) ) {
769
+ /**
770
+ * Generate Feed
771
+ */
772
+ function woo_feed_generate_feed() {
773
+ if ( isset( $_POST['provider'], $_POST['_wpnonce'], $_POST['filename'], $_POST['feedType'] ) ) {
774
+ # Verify Nonce
775
+ if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'woo_feed_form_nonce' ) ) {
776
+ wp_die( 'Failed security check' );
777
+ }
778
+ # Check feed type (file ext)
779
+ if( ! in_array( $_POST['feedType'], array( 'xml', 'csv', 'txt', 'tsv' ) ) ) {
780
+ wp_die( 'Invalid Feed Type!' );
781
+ }
782
+ // Sanitize Fields
783
+ $_POST = woo_feed_sanitize_form_fields( $_POST );
784
+ $feedDir = woo_feed_get_file_dir( $_POST['provider'], $_POST['feedType'] );
785
+ $fileName = sanitize_title( $_POST['filename'], '', 'save' );
786
+ // check option name uniqueness ...
787
+ $fileName = woo_feed_unique_feed_slug( $fileName, null );
788
+ $fileName = sanitize_file_name( $fileName . '.' . $_POST['feedType'] );
789
+ $fileName = wp_unique_filename( $feedDir, $fileName );
790
+ $fileName = str_replace( '.' . $_POST['feedType'] , '', $fileName );
791
+ # Option Name
792
+ $fileName = "wf_config" . $fileName;
793
+ # Store Config
794
+ update_option( $fileName, $_POST );
795
+
796
+ # Schedule Cron
797
+ $arg = array( sanitize_text_field( $_POST['filename'] ) );
798
+ wp_schedule_event(time(), 'woo_feed_corn', 'woo_feed_update_single_feed',$arg);
799
+
800
+
801
+ require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-manage-list.php';
802
+ } else {
803
+ echo "<div class='notice notice-warning is-dismissible'><p>" . __("You are awesome for using <b>WooCommerce Product Feed</b>. Free version works great for up to <b>2000 products including variations.</b>", 'woo-feed') . "</p></div>";
804
+ require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-admin-display.php';
805
+ }
806
+ }
807
+ }
808
+ if( ! function_exists( 'woo_feed_manage_feed' ) ) {
809
+ /**
810
+ * Manage Feeds
811
+ */
812
+ function woo_feed_manage_feed() {
813
+ // Manage action for category mapping
814
+ if (isset($_GET['action']) && $_GET['action'] == 'edit-feed') {
815
+ $fname = sanitize_text_field($_GET['feed']);
816
+ if ( count( $_POST ) && isset( $_POST['provider'], $_POST['edit-feed'], $_POST['feed_id'], $_POST['filename'], $_POST['feedType'] ) ) {
817
+ # Verify Nonce
818
+ if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'wf_edit_feed' ) ) {
819
+ wp_die( 'Failed security check' );
820
+ }
821
+ # Check feed type (file ext)
822
+ if( ! in_array( $_POST['feedType'], array( 'xml', 'csv', 'txt', 'tsv' ) ) ) {
823
+ wp_die( 'Invalid Feed Type!' );
824
+ }
825
+ // Sanitize Fields
826
+ $_POST = woo_feed_sanitize_form_fields( $_POST );
827
+ $feedDir = woo_feed_get_file_dir( $_POST['provider'], $_POST['feedType'] );
828
+ $fileName = sanitize_title( $_POST['filename'], '', 'save' );
829
+ // check option name uniqueness ...
830
+ $fileName = woo_feed_unique_feed_slug( $fileName, $_POST['feed_id'] );
831
+ $fileName = sanitize_file_name( $fileName . '.' . $_POST['feedType'] );
832
+ $fileName = wp_unique_filename( $feedDir, $fileName );
833
+ $fileName = str_replace( '.' . $_POST['feedType'] , '', $fileName );
834
+ # Option Name
835
+ $fileName = "wf_config" . $fileName;
836
+ # Store Config
837
+ update_option( $fileName, $_POST );
838
+
839
+ require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-manage-list.php';
840
+ wp_die();
841
+ }
842
+
843
+ $merchants=array(
844
+ "custom","fruugo",
845
+ "twenga","pricespy",
846
+ "prisjakt","amazon",
847
+ "adwords","polyvore",
848
+ "bol","pricerunner",
849
+ "adform","bonanza",
850
+ "leeguide","real",
851
+ "crowdfox","jet",
852
+ "wish","google_local_inventory",
853
+ "google_local", "zap.co.il",
854
+ "fruugo.au", "myshopping.com.au",
855
+ "smartly.io", "stylight.com",
856
+ "nextad", "skinflint.co.uk",
857
+ "yahoo_nfa",
858
+ "comparer.be",
859
+ "dooyoo",
860
+ "hintaseuranta.fi",
861
+ "incurvy",
862
+ "kijiji.ca",
863
+ "marktplaats.nl",
864
+ "rakuten",
865
+ "shopalike.fr",
866
+ "spartoo.fi",
867
+ "webmarchand",
868
+ "fashiola",
869
+ 'vergelijk_comparer'
870
+ ,"kieskeurig.nl",
871
+ 'beslist.nl',
872
+ "billiger.de",
873
+ "vertaa.fi",
874
+ "cdiscount.fr",
875
+ "fnac.fr",
876
+ "idealo",
877
+ "miinto.nl",
878
+ "fyndiq.se",
879
+ "criteo",
880
+ "avantlink",
881
+ "shareasale",
882
+ "walmart",
883
+ "modina.de"
884
+ );
885
+
886
+ if ( isset( $fname ) ) {
887
+ global $wpdb;
888
+ $feedInfo = unserialize( get_option( $fname ) );
889
+ $feedId = $wpdb->get_row( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT 1", $fname ) );
890
+ if( $feedId ) $feedId = $feedId->option_id;
891
+ $provider = strtolower( $feedInfo['feedrules']['provider'] );
892
+ $feedRules = $feedInfo['feedrules'];
893
+ //$provider == "custom" ||$provider == "twenga" || $provider == "pricespy" || $provider == "prisjakt" || $provider == "amazon" || $provider == "adwords"
894
+ if ( in_array( $provider, $merchants ) ) {
895
+ require plugin_dir_path(__FILE__) . "admin/partials/templates/custom_edit-feed.php";
896
+ } else {
897
+ require plugin_dir_path(__FILE__) . "admin/partials/woo-feed-edit-template.php";
898
+ }
899
+ }
900
+ } else {
901
+ # Update Interval
902
+ if ( isset( $_POST['wf_schedule'] ) ) {
903
+ if ( update_option('wf_schedule', sanitize_text_field($_POST['wf_schedule'] ) ) ) {
904
+ wp_clear_scheduled_hook('woo_feed_update');
905
+ add_filter( 'cron_schedules', 'custom_cron_job_custom_recurrence' );
906
+ wp_schedule_event( time(), 'woo_feed_corn', 'woo_feed_update' );
907
+ }
908
+ }
909
+
910
+ require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-manage-list.php';
911
+ }
912
+ }
913
+ }
914
+ if( ! function_exists( 'woo_feed_pro_vs_free' ) ) {
915
+ /**
916
+ * Difference between free and premium plugin
917
+ */
918
+ function woo_feed_pro_vs_free(){
919
+ require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-pro-vs-free.php';
920
+ }
921
+ }
922
+ if( ! function_exists( 'woo_feed_config_feed' ) ) {
923
+ /**
924
+ * Feed config
925
+ */
926
+ function woo_feed_config_feed(){
927
+ if(isset($_POST['wa_woo_feed_config'])) {
928
+ update_option("woo_feed_per_batch",sanitize_text_field($_POST['limit']));
929
+ if(isset($_POST['enable_error_debugging']))
930
+ {
931
+ update_option("woo_feed_enable_error_debugging", sanitize_text_field($_POST['enable_error_debugging']));
932
+ }
933
+ else
934
+ {
935
+ update_option("woo_feed_enable_error_debugging", "off");
936
+ }
937
+ }
938
 
939
+ require plugin_dir_path(__FILE__) . 'admin/partials/woo-feed-config.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
940
  }
 
941
  }
942
+ if( ! function_exists( 'woo_feed_getFeedInfoForCronUpdate' ) ) {
943
+ /**
944
+ * Scheduled Action Hook
945
+ */
946
+ function woo_feed_getFeedInfoForCronUpdate(){
947
+
948
+ check_ajax_referer('wpf_feed_nonce');
949
+ global $wpdb;
950
+ $var = "wf_feed_";
951
+ $query = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
952
+ $result = $wpdb->get_results($query, 'ARRAY_A');
953
+ $feeds=array();
954
+ foreach ($result as $key => $value) {
955
+ $feedInfo = unserialize(get_option($value['option_name']));
956
+ $feeds["wf_config".$value['option_name']]=$feedInfo['last_updated'];
957
+ }
958
 
959
+ $return = array(
960
+ 'data' => $feeds,
961
+ );
962
 
963
+ wp_send_json($return);
964
+ }
965
+ add_action('wp_ajax_getFeedInfoForCronUpdate', 'woo_feed_getFeedInfoForCronUpdate');
966
+ add_action('wp_ajax_nopriv_getFeedInfoForCronUpdate', 'woo_feed_getFeedInfoForCronUpdate');
967
+ }
968
+ if( ! function_exists( 'woo_feed_update_feed_status' ) ) {
969
+ /**
970
+ * Update feed status
971
+ */
972
+ function woo_feed_update_feed_status(){
973
+ if(!empty($_POST['feedName'])){
974
+ $feedInfo = unserialize(get_option($_POST['feedName']));
975
+ $feedInfo['status'] = $_POST['status'];
976
+ $data = array('status' => true);
977
+ update_option($_POST['feedName'],serialize($feedInfo));
978
+ return wp_send_json_success($data);
979
+ }else{
980
+ $data = array('status' => false);
981
+ return wp_send_json_error($data);
982
+ }
983
+ wp_die();
984
+ }
985
+ add_action('wp_ajax_update_feed_status', 'woo_feed_update_feed_status');
986
+ }
987
+ if( ! function_exists( 'woo_feed_cron_update_feed' ) ) {
988
+ /*
989
  * Scheduled Action Hook
990
  */
991
+ function woo_feed_cron_update_feed()
992
+ {
993
+ global $wpdb;
994
+ $var = "wf_feed_";
995
+ $query = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
996
+ $result = $wpdb->get_results($query, 'ARRAY_A');
997
+ foreach ($result as $key => $value) {
998
+ $feedInfo = unserialize(get_option($value['option_name']));
999
+ if(!isset($feedInfo['status']) || $feedInfo['status'] != "0") {
1000
+ woo_feed_add_update( $feedInfo['feedrules'] );
1001
+ }
1002
+ }
1003
+ }
1004
+ add_action('woo_feed_update', 'woo_feed_cron_update_feed');
1005
  }
1006
+ if( ! function_exists( 'woo_feed_cron_update_single_feed' ) ) {
1007
+ /*
 
1008
  * Scheduled Action Hook
1009
  */
1010
+ function woo_feed_cron_update_single_feed($feedname)
1011
+ {
1012
+ global $wpdb;
1013
 
1014
+ $feedname = "wf_feed_".$feedname[0];
1015
 
1016
 
1017
 
1018
+ $result = $wpdb->get_results(
1019
+ $wpdb->prepare( "
1020
  SELECT * FROM $wpdb->options
1021
  WHERE option_name = %s",
1022
+ $feedname
1023
+ )
1024
+ ,'ARRAY_A');
1025
+
1026
+
1027
+ if(!empty($result)){
1028
+ foreach ($result as $key => $value) {
1029
+ $feedInfo = unserialize(get_option($value['option_name']));
1030
+ if(!isset($feedInfo['status']) || $feedInfo['status'] != "0") {
1031
+ woo_feed_add_update( $feedInfo['feedrules'] );
1032
+ }
1033
+ }
1034
+ }
 
 
 
 
 
 
 
 
 
 
 
 
1035
  }
1036
+ add_action('woo_feed_update_single_feed', 'woo_feed_cron_update_single_feed');
 
 
 
1037
  }
1038
+ if( ! function_exists( 'woo_feed_plugin_action_links' ) ) {
1039
+ /**
1040
+ * Add Go to Pro and Documentation link
1041
+ */
1042
+ function woo_feed_plugin_action_links( $links ) {
1043
+
1044
+ if ( array_key_exists( 'deactivate', $links ) ) {
1045
+ $links['deactivate'] = str_replace( '<a', '<a class="wpf-deactivate-link"', $links['deactivate'] );
1046
+ }
1047
+ $links[] = '<a style="color:green;" href="https://webappick.com/plugin/woocommerce-product-feed-pro/?utm_source=freePlugin&utm_medium=go_premium&utm_campaign=free_to_pro&utm_term=wooFeed" target="_blank">' . __( '<b>Get Pro</b>', 'Woo Feed' ) . '</a>';
1048
+ $links[] = '<a style="color:#8e44ad;" href="http://webappick.helpscoutdocs.com/" target="_blank">' . __( 'Documentation', 'Woo Feed' ) . '</a>';
1049
 
1050
+ return $links;
1051
+ }
1052
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'woo_feed_plugin_action_links' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1053
  }
1054
+ if( ! function_exists( 'woo_feed_get_uninstall_reasons' ) ) {
1055
+ // uninstall reason
1056
+ function woo_feed_get_uninstall_reasons() {
1057
+
1058
+ $reasons = array(
1059
+ array(
1060
+ 'id' => 'could-not-understand',
1061
+ 'text' => 'I couldn\'t understand how to make it work',
1062
+ 'type' => 'textarea',
1063
+ 'placeholder' => 'Would you like us to assist you?'
1064
+ ),
1065
+ array(
1066
+ 'id' => 'found-better-plugin',
1067
+ 'text' => 'I found a better plugin',
1068
+ 'type' => 'text',
1069
+ 'placeholder' => 'Which plugin?'
1070
+ ),
1071
+ array(
1072
+ 'id' => 'not-have-that-feature',
1073
+ 'text' => 'The plugin is great, but I need specific feature that you don\'t support',
1074
+ 'type' => 'textarea',
1075
+ 'placeholder' => 'Could you tell us more about that feature?'
1076
+ ),
1077
+ array(
1078
+ 'id' => 'is-not-working',
1079
+ 'text' => 'The plugin is not working',
1080
+ 'type' => 'textarea',
1081
+ 'placeholder' => 'Could you tell us a bit more whats not working?'
1082
+ ),
1083
+ array(
1084
+ 'id' => 'looking-for-other',
1085
+ 'text' => 'It\'s not what I was looking for',
1086
+ 'type' => '',
1087
+ 'placeholder' => ''
1088
+ ),
1089
+ array(
1090
+ 'id' => 'did-not-work-as-expected',
1091
+ 'text' => 'The plugin didn\'t work as expected',
1092
+ 'type' => 'textarea',
1093
+ 'placeholder' => 'What did you expect?'
1094
+ ),
1095
+ array(
1096
+ 'id' => 'other',
1097
+ 'text' => 'Other',
1098
+ 'type' => 'textarea',
1099
+ 'placeholder' => 'Could you tell us a bit more?'
1100
+ ),
1101
+ );
1102
+
1103
+ return $reasons;
1104
  }
1105
+ }
1106
+ if( ! function_exists( 'woo_feed_uninstall_reason_submission' ) ) {
1107
+ /**
1108
+ * Plugin deactivation uninstall reason submission
1109
+ *
1110
+ * @return void
1111
+ */
1112
+ function woo_feed_uninstall_reason_submission(){
1113
+ global $wpdb;
1114
+
1115
+ if ( ! isset( $_POST['reason_id'] ) ) { // WPCS: CSRF ok, Input var ok.
1116
+ wp_send_json_error();
1117
+ }
1118
 
1119
+ $CurUser = new WP_User(get_current_user_id());
1120
 
1121
+ $data = array(
1122
+ 'reason_id' => sanitize_text_field( $_POST['reason_id'] ), // WPCS: CSRF ok, Input var ok.
1123
+ 'plugin' => "Woo Feed Free",
1124
+ 'url' => home_url(),
1125
+ 'user_email' => $CurUser->data->user_email,
1126
+ 'user_name' => $CurUser->data->display_name,
1127
+ 'reason_info' => isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '',
1128
+ 'software' => $_SERVER['SERVER_SOFTWARE'],
1129
+ 'php_version' => phpversion(),
1130
+ 'mysql_version' => $wpdb->db_version(),
1131
+ 'wp_version' => get_bloginfo( 'version' ),
1132
+ 'locale' => get_locale(),
1133
+ 'multisite' => is_multisite() ? 'Yes' : 'No'
1134
+ );
1135
 
1136
 
1137
+ woo_feed_send_request( $data, 'uninstall_reason' );
1138
+ wp_send_json_success();
1139
 
1140
+ }
1141
+ add_action( 'wp_ajax_woo-feed-submit-uninstall-reason', 'woo_feed_uninstall_reason_submission' );
1142
  }
1143
+ if( ! function_exists( 'woo_feed_send_request' ) ) {
1144
+ function woo_feed_send_request( $params, $route ) {
1145
+ $api_url = "https://track.webappick.com/api/receive-uninstall-tracking";
1146
+ return wp_remote_post($api_url, array(
1147
+ 'method' => 'POST',
1148
+ 'timeout' => 45,
1149
+ 'redirection' => 5,
1150
+ 'httpversion' => '1.0',
1151
+ 'blocking' => false,
1152
+ 'headers' => array( 'user-agent' => 'Webappick/' . md5( esc_url( home_url() ) ) . ';' ),
1153
+ 'body' => $params,
1154
+ 'cookies' => array()
1155
+ )
1156
+ );
1157
 
1158
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
1159
  }
1160
+ if( ! function_exists( 'woo_feed_deactivate_scripts' ) ) {
1161
+ /**
1162
+ * Handle the plugin deactivation feedback
1163
+ *
1164
+ * @return void
1165
+ */
1166
+ function woo_feed_deactivate_scripts() {
1167
+
1168
+ global $pagenow;
1169
+
1170
+ if ( 'plugins.php' != $pagenow ) {
1171
+ return;
1172
+ }
1173
 
1174
+ $reasons = woo_feed_get_uninstall_reasons();
1175
+ ?>
1176
+ <!--pop up modal-->
1177
+ <div class="wpf_deactive_plugin-modal" id="wpf_deactive_plugin-modal">
1178
+ <div class="wpf_deactive_plugin-modal-wrap">
1179
+ <div class="wpf_deactive_plugin-modal-header">
1180
+ <h3><?php _e( 'If you have a moment, please let us know why you are deactivating:', 'woo-feed' ); ?></h3>
1181
+ </div>
1182
+
1183
+ <div class="wpf_deactive_plugin-modal-body">
1184
+ <ul class="reasons">
1185
+ <?php foreach ($reasons as $reason) { ?>
1186
+ <li data-type="<?php echo esc_attr( $reason['type'] ); ?>" data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>">
1187
+ <label><input type="radio" name="selected-reason" value="<?php echo $reason['id']; ?>"> <?php echo $reason['text']; ?></label>
1188
+ </li>
1189
+ <?php } ?>
1190
+ </ul>
1191
+ </div>
1192
+
1193
+ <div class="wpf_deactive_plugin-modal-footer">
1194
+ <a href="#" class="dont-bother-me"><?php _e( 'I rather wouldn\'t say', 'Woo Feed' ); ?></a>
1195
+ <button class="button-secondary"><?php _e( 'Submit & Deactivate', 'Woo Feed' ); ?></button>
1196
+ <button class="button-primary"><?php _e( 'Cancel', 'Woo Feed' ); ?></button>
1197
+ </div>
1198
+ </div>
1199
+ </div>
1200
+
1201
+ <?php
1202
  }
1203
+ add_action( 'admin_footer', 'woo_feed_deactivate_scripts' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1204
  }
1205
+ if( ! function_exists( 'woo_feed_get_ssh2_status' ) ) {
1206
+ function woo_feed_get_ssh2_status() {
1207
+ check_ajax_referer( 'wpf_feed_nonce' );
1208
+ $php_extension = get_loaded_extensions();
1209
+ if(extension_loaded ( 'ssh2' )) {
1210
+ wp_send_json_success('exists');
1211
+ } else {
1212
+ wp_send_json_success('not exists');
1213
+ }
1214
+ }
1215
+ add_action('wp_ajax_get_ssh2_status', 'woo_feed_get_ssh2_status');
1216
  }
1217
+ if( ! function_exists( 'woo_feed_review_notice' ) ) {
1218
+ function woo_feed_review_notice() {
1219
+ $options = get_option('woo_feed_review_notice');
1220
+ $installDate=get_option('woo-feed-activation-time');
1221
+ $installDate=strtotime('-16 days',$installDate);
1222
+
1223
+ $notice = '<div class="woo-feed-review-notice notice notice-info is-dismissible">';
1224
+ $notice .= '<p><b>:) We have spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating. Your opinion matters a lot to us. It helps us to get better. Thanks for using <i>WooCommerce Product Feed</i>.</b></p>';
1225
+ $notice .= '<ul>';
1226
+ $notice .= '<li><a val="later" href="#">Remind me later</a></li>';
1227
+ $notice .= '<li><a val="never" href="#">I would not</a></li>';
1228
+ $notice .= '<li><a val="given" href="#" target="_blank">Review Here</a></li>';
1229
+ $notice .= '</ul>';
1230
+ $notice .= '</div>';
1231
+
1232
+ if(!$options && time()>= $installDate + (60*60*24*15)){
1233
+ echo $notice;
1234
+ } else if(is_array($options)) {
1235
+ if((!array_key_exists('review_notice',$options)) || ($options['review_notice'] =='later' && time()>=($options['updated_at'] + (60*60*24*30) ))){
1236
+ echo $notice;
1237
+ }
1238
+ }
1239
+ }
1240
+ add_action( 'admin_notices', 'woo_feed_review_notice' );
1241
  }
1242
+ if( ! function_exists( 'woo_feed_save_review_notice' ) ) {
1243
+ /**
1244
+ * Show Review request admin notice
1245
+ */
1246
+ function woo_feed_save_review_notice() {
1247
+ $notice = sanitize_text_field($_POST['notice']);
1248
+ $value['review_notice'] = $notice;
1249
+ $value['updated_at'] = time();
1250
+
1251
+ update_option('woo_feed_review_notice',$value);
1252
+ wp_send_json_success($value);
1253
+ }
1254
+ add_action('wp_ajax_woo_feed_save_review_notice', 'woo_feed_save_review_notice');
 
1255
  }
1256
+ if( ! function_exists( 'woo_feed_wpml_notice' ) ) {
1257
+ /**
1258
+ * Show notice if WPML installed
1259
+ */
1260
+ function woo_feed_wpml_notice() {
1261
+ if (class_exists('SitePress') && get_option('woo_feed_wpml_notice') == false) {
1262
+ $wpml_notice = '<div class="woo-feed-wpml-notice notice notice-success is-dismissible">';
1263
+ $wpml_notice .= '<p>You are awesome for using <b>WooCommerce Product Feed</b>.
 
1264
  Using the <b><a href="https://webappick.com/plugin/woocommerce-product-feed-pro/" target="_blank">Premium</a></b> version you can make multilingual feed for your WPML languages.</p>';
1265
+ $wpml_notice .= '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>';
1266
+ $wpml_notice .= '</div>';
1267
+ echo $wpml_notice;
1268
+ }
1269
+ }
1270
+ add_action( 'admin_notices', 'woo_feed_wpml_notice' );
1271
  }
1272
+ if( ! function_exists( 'woo_feed_save_wpml_notice' ) ) {
1273
+ add_action('wp_ajax_woo_feed_save_wpml_notice', 'woo_feed_save_wpml_notice');
1274
+ function woo_feed_save_wpml_notice() {
1275
+ $notice = true;
1276
+ $value['wpml_notice'] = $notice;
1277
+ update_option('woo_feed_wpml_notice',$value);
1278
+
1279
+ wp_send_json_success();
1280
+ }
1281
  }
1282
+ // End of file woo-feed.php