Persian Woocommerce - Version 2.6.15

Version Description

*

Download this release

Release Info

Developer hannanstd
Plugin Icon 128x128 Persian Woocommerce
Version 2.6.15
Comparing to
See all releases

Code changes from version 2.6.14 to 2.6.15

include/class-address.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  if (!defined('ABSPATH'))
3
  exit; // Exit if accessed directly
4
 
@@ -7,11 +8,15 @@ if (!class_exists('Persian_Woocommerce_Address')) :
7
  class Persian_Woocommerce_Address extends Persian_Woocommerce_Plugin
8
  {
9
 
10
- protected $states;
 
 
11
  private $fields = array();
12
- private $Country = 'IR';
13
  private $selected_city = array();
14
- private static $is_run;
 
 
 
15
 
16
  public function __construct()
17
  {
@@ -23,13 +28,15 @@ if (!class_exists('Persian_Woocommerce_Address')) :
23
  if (PW()->get_options('enable_iran_cities') == 'yes') {
24
 
25
  add_filter('woocommerce_checkout_fields', array($this, 'checkout_fields_cities'));
 
 
 
26
  add_filter('woocommerce_form_field_billing_iran_cities', array($this, 'iran_cities_field'), 11, 4);
27
  add_filter('woocommerce_form_field_shipping_iran_cities', array($this, 'iran_cities_field'), 11, 4);
28
 
29
- add_action('woocommerce_after_order_notes', array($this, 'inline_js'));
30
- add_action('wp_footer', array($this, 'inline_js'));
31
  add_action('wp_enqueue_scripts', array($this, 'external_js'));
32
-
 
33
  }
34
 
35
  $this->states = array(
@@ -84,7 +91,7 @@ if (!class_exists('Persian_Woocommerce_Address')) :
84
 
85
  public function iran_states($states)
86
  {
87
- $states['IR'] = $this->states;
88
 
89
  if (PW()->get_options("allowed_states") == "all")
90
  return $states;
@@ -92,31 +99,59 @@ if (!class_exists('Persian_Woocommerce_Address')) :
92
  $selections = PW()->get_options('specific_allowed_states');
93
 
94
  if (is_array($selections))
95
- $states['IR'] = array_intersect_key($this->states, array_flip($selections));
96
 
97
  return $states;
98
  }
99
 
100
- //Cities
101
  public function checkout_fields_cities($fields)
102
  {
103
  $this->fields = $fields;
104
 
105
- $types = array('billing', 'shipping');
106
- foreach ($types as $type) {
107
- $city_classes = '';
108
- if (!empty($fields[$type][$type . '_city']['class']) && $city_classes = $fields[$type][$type . '_city']['class']) {
109
- $city_classes = is_array($city_classes) ? implode(',', $city_classes) : $city_classes;
110
- $city_classes = str_ireplace('form-row-wide', 'form-row-last', $city_classes);
111
  }
112
- $fields[$type][$type . '_city']['type'] = apply_filters($type . '_iran_city_type', $type . '_iran_cities', $fields);
113
- $fields[$type][$type . '_city']['class'] = apply_filters($type . '_iran_city_class', explode(',', $city_classes), $fields);
114
- $fields[$type][$type . '_city']['options'] = apply_filters($type . '_iran_city_options', array('' => ''), $fields);
115
  }
116
 
117
  return $fields;
118
  }
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  public function iran_cities_field($field, $key, $args, $value)
121
  {
122
 
@@ -175,45 +210,64 @@ if (!class_exists('Persian_Woocommerce_Address')) :
175
 
176
  public function external_js()
177
  {
178
-
179
  wp_dequeue_script('pw-iran-cities');
180
  wp_deregister_script('pw-iran-cities');
181
- wp_register_script('pw-iran-cities', apply_filters('persian_woo_iran_cities', PW()->plugin_url('include/assets/js/iran_cities.min.js')), array('jquery'), PW_VERSION, true);
182
 
183
- if (is_checkout()) {
184
  wp_enqueue_script('pw-iran-cities');
185
  }
186
  }
187
 
188
- public function inline_js()
189
  {
190
- if (!empty(self::$is_run) || !is_checkout())
191
- return true;
192
 
193
- self::$is_run = 'applied';
 
194
 
195
- $value_index = apply_filters('iran_cities_value_index', 0);
 
 
 
 
 
196
 
 
 
197
  $types = array('billing', 'shipping');
198
  ?>
199
  <script type="text/javascript">
200
- jQuery(document).ready(function ($) {
201
- <?php
202
- foreach ($types as $type) :
 
 
203
  $selected_value = $type . '_iran_cities_selected_value';
204
  global ${$selected_value};
205
  $value = !empty(${$selected_value}) ? ${$selected_value} : '';
206
  $placeholder = isset($this->fields[$type][$type . '_city']['placeholder']) ? $this->fields[$type][$type . '_city']['placeholder'] : __('City', 'woocommerce');
 
 
 
 
 
207
  ?>
 
 
 
 
208
  $(document.body).on('change', '#<?php echo $type; ?>_state', function () {
209
 
210
- if ($('#<?php echo $type; ?>_country').val() == '<?php echo $this->Country ?>') {
 
211
  <?php echo $type; ?>_cities = [];
212
  <?php echo $type; ?>_cities[0] = new Array('خطا در دریافت شهرها', '0');
 
213
  if (typeof Persian_Woo_iranCities === "function")
214
- <?php echo $type; ?>_cities = Persian_Woo_iranCities($('#<?php echo $type; ?>_state').val());
215
  else {
216
- alert('تابع مربوط به شهرها یافت نمیشود. با مدیریت در میان بگذارید.');
217
  }
218
 
219
  <?php echo $type; ?>_cities.sort(function (a, b) {
@@ -224,7 +278,6 @@ if (!class_exists('Persian_Woocommerce_Address')) :
224
  else
225
  return -1;
226
  });
227
-
228
  var options = '<option value="-1">انتخاب کنید</option>';
229
  var j;
230
  <?php echo $type; ?>_selected = '';
@@ -236,45 +289,68 @@ if (!class_exists('Persian_Woocommerce_Address')) :
236
  }
237
  options += "<option value='" + <?php echo $type; ?>_cities[j][<?php echo $value_index; ?>] + "' " + selected + ">" + <?php echo $type; ?>_cities[j][0] + "</option>";
238
  }
239
-
240
  $('#<?php echo $type; ?>_city').empty();
241
-
242
  if ($("#<?php echo $type; ?>_city").is('select')) {
243
  $('#<?php echo $type; ?>_city').append(options);
244
  }
245
-
246
  $('#<?php echo $type; ?>_city').val(<?php echo $type; ?>_selected).trigger("change");
247
  }
248
  });
 
249
 
250
  var <?php echo $type; ?>_city_select = $('#<?php echo $type; ?>_city_field').html();
251
- var <?php echo $type; ?>_city_input = '<input id="<?php echo $type; ?>_city" name="<?php echo $type; ?>_city" type="text" class="input-text" value="" placeholder="<?php echo $placeholder;?>" />';
 
 
 
 
 
 
 
 
 
 
252
 
253
- $('#<?php echo $type; ?>_country').change(function () {
 
 
 
 
 
254
 
255
- if ($('#<?php echo $type; ?>_country').val() == '<?php echo $this->Country ?>') {
256
- if (!$("#<?php echo $type; ?>_city").is('select')) {
257
- $('#<?php echo $type; ?>_city_field').empty();
258
- $('#<?php echo $type; ?>_city_field').html(<?php echo $type; ?>_city_select);
259
 
260
- $('#<?php echo $type; ?>_state').val('').trigger("change");
261
- $('#<?php echo $type; ?>_city').val('').trigger("change");
 
 
 
 
 
 
262
  }
263
  }
264
  else {
265
- $('#<?php echo $type; ?>_city_field').find('*').not('label').remove();
266
- $('#<?php echo $type; ?>_city_field').append(<?php echo $type; ?>_city_input);
267
-
268
- $('#<?php echo $type; ?>_state').val('').trigger("change");
269
- $('#<?php echo $type; ?>_city').val('').trigger("change");
270
  }
271
- });
272
- <?php endforeach; ?>
273
  });
274
  </script>
275
  <?php
276
  }
277
 
 
 
 
 
 
 
 
278
  }
279
  endif;
280
 
1
  <?php
2
+ //HANNANStd
3
  if (!defined('ABSPATH'))
4
  exit; // Exit if accessed directly
5
 
8
  class Persian_Woocommerce_Address extends Persian_Woocommerce_Plugin
9
  {
10
 
11
+ public $Country = 'IR';
12
+ public $states;
13
+
14
  private $fields = array();
 
15
  private $selected_city = array();
16
+
17
+ private static $action_priority = 0;
18
+ private static $iran_cities_page = false;
19
+ private static $inline_script_printed = false;
20
 
21
  public function __construct()
22
  {
28
  if (PW()->get_options('enable_iran_cities') == 'yes') {
29
 
30
  add_filter('woocommerce_checkout_fields', array($this, 'checkout_fields_cities'));
31
+ add_filter('woocommerce_billing_fields', array($this, 'billing_fields_cities'));
32
+ add_filter('woocommerce_shipping_fields', array($this, 'shipping_fields_cities'));
33
+
34
  add_filter('woocommerce_form_field_billing_iran_cities', array($this, 'iran_cities_field'), 11, 4);
35
  add_filter('woocommerce_form_field_shipping_iran_cities', array($this, 'iran_cities_field'), 11, 4);
36
 
 
 
37
  add_action('wp_enqueue_scripts', array($this, 'external_js'));
38
+ add_action('wp_footer', array($this, 'inline_js'), 0);
39
+ add_action('wp_footer', array($this, 'force_inline_js'), 999999);
40
  }
41
 
42
  $this->states = array(
91
 
92
  public function iran_states($states)
93
  {
94
+ $states[$this->Country] = $this->states;
95
 
96
  if (PW()->get_options("allowed_states") == "all")
97
  return $states;
99
  $selections = PW()->get_options('specific_allowed_states');
100
 
101
  if (is_array($selections))
102
+ $states[$this->Country] = array_intersect_key($this->states, array_flip($selections));
103
 
104
  return $states;
105
  }
106
 
107
+ //--------------------------------------------
108
  public function checkout_fields_cities($fields)
109
  {
110
  $this->fields = $fields;
111
 
112
+ if (is_checkout()) {
113
+ $types = array('billing', 'shipping');
114
+ foreach ($types as $type) {
115
+ $fields[$type][$type . '_city'] = $this->change_city_filed($fields[$type][$type . '_city'], $type);
 
 
116
  }
 
 
 
117
  }
118
 
119
  return $fields;
120
  }
121
 
122
+ public function billing_fields_cities($fields)
123
+ {
124
+ if (is_wc_endpoint_url('edit-address')) {
125
+ $type = 'billing';
126
+ $fields[$type . '_city'] = $this->change_city_filed($fields[$type . '_city'], $type);
127
+ }
128
+
129
+ return $fields;
130
+ }
131
+
132
+ public function shipping_fields_cities($fields)
133
+ {
134
+ if (is_wc_endpoint_url('edit-address')) {
135
+ $type = 'shipping';
136
+ $fields[$type . '_city'] = $this->change_city_filed($fields[$type . '_city'], $type);
137
+ }
138
+
139
+ return $fields;
140
+ }
141
+
142
+ public function change_city_filed($fields, $type)
143
+ {
144
+ $city_classes = '';
145
+ if (!empty($fields['class']) && $city_classes = $fields['class']) {
146
+ $city_classes = is_array($city_classes) ? implode(',', $city_classes) : $city_classes;
147
+ $city_classes = str_ireplace('form-row-wide', 'form-row-last', $city_classes);
148
+ }
149
+ $fields['type'] = apply_filters($type . '_iran_city_type', $type . '_iran_cities', $fields, $type);
150
+ $fields['class'] = apply_filters($type . '_iran_city_class', explode(',', $city_classes), $fields, $type);
151
+ $fields['options'] = apply_filters($type . '_iran_city_options', array('' => ''), $fields, $type);
152
+ return $fields;
153
+ }
154
+
155
  public function iran_cities_field($field, $key, $args, $value)
156
  {
157
 
210
 
211
  public function external_js()
212
  {
 
213
  wp_dequeue_script('pw-iran-cities');
214
  wp_deregister_script('pw-iran-cities');
215
+ wp_register_script('pw-iran-cities', apply_filters('persian_woo_iran_cities', PW()->plugin_url('include/assets/js/iran_cities.min.js')), false, PW_VERSION, true);
216
 
217
+ if (self::$iran_cities_page = (is_checkout() || is_wc_endpoint_url('edit-address'))) {
218
  wp_enqueue_script('pw-iran-cities');
219
  }
220
  }
221
 
222
+ public function inline_js($force_inline_js = false)
223
  {
224
+ if (!$force_inline_js) {
 
225
 
226
+ if (self::$inline_script_printed == 'yes' || !self::$iran_cities_page || self::$action_priority > 100)
227
+ return;
228
 
229
+ if (!(wp_script_is('jquery', 'done') && !wp_script_is('wc-country-select', 'done'))) {
230
+ self::$action_priority += 5;
231
+ add_action('wp_footer', array($this, 'inline_js'), self::$action_priority);
232
+ return;
233
+ }
234
+ }
235
 
236
+ self::$inline_script_printed = 'yes';
237
+ $value_index = apply_filters('iran_cities_value_index', 0);
238
  $types = array('billing', 'shipping');
239
  ?>
240
  <script type="text/javascript">
241
+ if (!window.jQuery) {
242
+ alert("کتابخانه جیکوئری قبل از کدهای مربوط به شهرهای ایران لود نشده است!");
243
+ }
244
+ jQuery(function ($) {
245
+ <?php foreach ($types as $type) :
246
  $selected_value = $type . '_iran_cities_selected_value';
247
  global ${$selected_value};
248
  $value = !empty(${$selected_value}) ? ${$selected_value} : '';
249
  $placeholder = isset($this->fields[$type][$type . '_city']['placeholder']) ? $this->fields[$type][$type . '_city']['placeholder'] : __('City', 'woocommerce');
250
+
251
+ $countries = 'get_' . str_replace('billing', 'allowed', $type) . '_countries';
252
+ $countries = WC()->countries->$countries();
253
+ $iran_exist = isset($countries[strtoupper($this->Country)]) || isset($countries[strtolower($this->Country)]) || isset($countries[ucfirst($this->Country)]) ? 'yes' : 'no';
254
+ $just_iran = count($countries) == 1 && $iran_exist == 'yes' ? 'yes' : 'no';
255
  ?>
256
+
257
+ var <?php echo $type; ?>_iran_exist = '<?php echo $iran_exist; ?>';
258
+ var <?php echo $type; ?>_just_iran = '<?php echo $just_iran; ?>';
259
+
260
  $(document.body).on('change', '#<?php echo $type; ?>_state', function () {
261
 
262
+ if (<?php echo $type; ?>_iran_exist == 'yes' && (<?php echo $type; ?>_just_iran || $('#<?php echo $type; ?>_country').val() == '<?php echo $this->Country ?>')) {
263
+
264
  <?php echo $type; ?>_cities = [];
265
  <?php echo $type; ?>_cities[0] = new Array('خطا در دریافت شهرها', '0');
266
+
267
  if (typeof Persian_Woo_iranCities === "function")
268
+ <?php echo $type; ?>_cities = Persian_Woo_iranCities('' + $('#<?php echo $type; ?>_state').val() + '');
269
  else {
270
+ alert('تابع مربوط به شهرهای ایران یافت نمیشود. با مدیریت در میان بگذارید.');
271
  }
272
 
273
  <?php echo $type; ?>_cities.sort(function (a, b) {
278
  else
279
  return -1;
280
  });
 
281
  var options = '<option value="-1">انتخاب کنید</option>';
282
  var j;
283
  <?php echo $type; ?>_selected = '';
289
  }
290
  options += "<option value='" + <?php echo $type; ?>_cities[j][<?php echo $value_index; ?>] + "' " + selected + ">" + <?php echo $type; ?>_cities[j][0] + "</option>";
291
  }
 
292
  $('#<?php echo $type; ?>_city').empty();
 
293
  if ($("#<?php echo $type; ?>_city").is('select')) {
294
  $('#<?php echo $type; ?>_city').append(options);
295
  }
 
296
  $('#<?php echo $type; ?>_city').val(<?php echo $type; ?>_selected).trigger("change");
297
  }
298
  });
299
+ $('#<?php echo $type; ?>_state').trigger('change');
300
 
301
  var <?php echo $type; ?>_city_select = $('#<?php echo $type; ?>_city_field').html();
302
+ var <?php echo $type; ?>_city_input = '<input id="<?php echo $type; ?>_city" name="<?php echo $type; ?>_city" type="text" class="input-text" value="<?php echo $value;?>" placeholder="<?php echo $placeholder;?>" />';
303
+
304
+ $(document.body).on('change', '#<?php echo $type; ?>_country', function () {
305
+ var is_iran = $('#<?php echo $type; ?>_country').val() == '<?php echo $this->Country ?>' ? 'yes' : 'no';
306
+ set_iran_cities_field('<?php echo $type; ?>', is_iran);
307
+ });
308
+ $('#<?php echo $type; ?>_country').trigger('change');
309
+
310
+ if (!$('#<?php echo $type; ?>_country').length) {
311
+ set_iran_cities_field('<?php echo $type; ?>', <?php echo $type; ?>_just_iran);
312
+ }
313
 
314
+ $(document.body).on('change', '#<?php echo $type; ?>_city', function () {
315
+ if ($('#<?php echo $type; ?>_city').val() == 'لطفا استان خود را انتخاب کنید') {
316
+ if ($().select2 && $('#<?php echo $type; ?>_state').data('select2'))
317
+ $('#<?php echo $type; ?>_state').select2('open');
318
+ }
319
+ });
320
 
321
+ <?php if (is_checkout()) wc_enqueue_js("if ($().select2 && $('#" . $type . "_city').data('select2') && !$('#" . $type . "_state').data('select2'))
322
+ $('#" . $type . "_state').select2();"); ?>
 
 
323
 
324
+ <?php endforeach; ?>
325
+ function set_iran_cities_field(type, iran) {
326
+ if (iran == 'yes') {
327
+ if (!$('#' + type + '_city').is('select')) {
328
+ $('#' + type + '_city_field').empty();
329
+ $('#' + type + '_city_field').html(eval(type + '_city_select'));
330
+ $('#' + type + '_state').val('').trigger("change");
331
+ $('#' + type + '_city').val('').trigger("change");
332
  }
333
  }
334
  else {
335
+ $('#' + type + '_city_field').find('*').not('label').remove();
336
+ $('#' + type + '_city_field').append(eval(type + '_city_input'));
337
+ $('#' + type + '_state').val('').trigger("change");
338
+ $('#' + type + '_city').val('').trigger("change");
 
339
  }
340
+ }
341
+
342
  });
343
  </script>
344
  <?php
345
  }
346
 
347
+ public function force_inline_js()
348
+ {
349
+ if (self::$inline_script_printed != 'yes' && self::$iran_cities_page && wp_script_is('jquery', 'done')) {
350
+ $this->inline_js(true);
351
+ }
352
+ }
353
+
354
  }
355
  endif;
356
 
include/class-currency.php CHANGED
@@ -15,7 +15,6 @@ if (!class_exists('Persian_Woocommerce_Currencies')) :
15
 
16
  public function iran_currencies($currencies)
17
  {
18
-
19
  $currencies += array(
20
  'IRR' => __('ریال', 'woocommerce'),
21
  'IRHR' => __('هزار ریال', 'woocommerce'),
@@ -24,7 +23,6 @@ if (!class_exists('Persian_Woocommerce_Currencies')) :
24
  );
25
 
26
  return $currencies;
27
-
28
  }
29
 
30
  public function iran_currencies_symbol($currency_symbol, $currency)
15
 
16
  public function iran_currencies($currencies)
17
  {
 
18
  $currencies += array(
19
  'IRR' => __('ریال', 'woocommerce'),
20
  'IRHR' => __('هزار ریال', 'woocommerce'),
23
  );
24
 
25
  return $currencies;
 
26
  }
27
 
28
  public function iran_currencies_symbol($currency_symbol, $currency)
include/class-widget.php CHANGED
@@ -1,68 +1,74 @@
1
  <?php
2
 
3
- if ( ! defined( 'ABSPATH' ) )
4
- exit; // Exit if accessed directly
5
 
6
- if ( ! class_exists( 'Persian_Woocommerce_Widget' ) ) :
7
 
8
- class Persian_Woocommerce_Widget extends Persian_Woocommerce_Plugin {
9
-
10
- public function __construct(){
11
- add_action('wp_dashboard_setup', array( $this, 'woocommerce_persian_widgetshow') );
12
- }
13
 
14
- public function woocommerce_persian_widget(){
15
- $widget_options = $this->woocommerce_persian_widgetoptions();
16
- echo '<div class="rss-widget">';
17
- wp_widget_rss_output(array(
18
- 'url' => 'http://woocommerce.ir/feed.xml',
19
- 'title' => 'آخرین اخبار و اطلاعیه های ووکامرس پارسی',
20
- 'meta' => array( 'target' => '_new' ),
21
- 'items' => $widget_options['posts_number'],
22
- 'show_summary' => 1,
23
- 'show_author' => 0,
24
- 'show_date' => 1
25
- ));
26
- ?>
27
- <div style="border-top: 1px solid #e7e7e7; padding-top: 12px !important; font-size: 12px;">
28
- <?php echo '<img src="' . plugins_url( 'assets/images/feed.png' , __FILE__ ) . '" width="16" height="16" > '; ?>
29
- <a href="http://woocommerce.ir" target="_new" title="خانه">وب سایت پشتیبان ووکامرس پارسی</a>
30
- </div>
31
- <?php
32
- echo "</div>";
33
- }
34
 
35
- public function woocommerce_persian_widgetshow() {
36
- wp_add_dashboard_widget('woocommerce_persian_feed_'.str_replace(".", "_", PW_VERSION).'_ver', 'آخرین اخبار و اطلاعیه های ووکامرس پارسی', array( $this, 'woocommerce_persian_widget') , array( $this, 'wooper_widset_pw') );
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- public function woocommerce_persian_widgetoptions() {
40
- $defaults = array( 'posts_number' => 5 );
41
- if ( ( !$options = get_option( 'woocommerce_persian_feed' ) ) || !is_array($options) )
42
- $options = array();
43
- return array_merge( $defaults, $options );
44
- }
45
 
46
- public function wooper_widset_pw() {
47
- $options = $this->woocommerce_persian_widgetoptions();
48
- if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) && isset( $_POST['widget_id'] ) && 'woocommerce_persian_feed' == $_POST['widget_id'] ) {
49
- $options['posts_number'] = $_POST['posts_number'];
50
- update_option( 'woocommerce_persian_feed', $options );
51
- }
52
- ?>
53
- <p>
54
- <label for="posts_number">تعداد نوشته های قابل نمایش در ابزارک ووکامرس پارسی:
55
- <select id="posts_number" name="posts_number">
56
- <?php for ( $i = 3; $i <= 20; $i++ )
57
- echo "<option value='$i'" . ( $options['posts_number'] == $i ? " selected='selected'" : '' ) . ">$i</option>";
58
- ?>
59
- </select>
60
- </label>
61
- </p>
62
- <?php
63
- }
64
-
65
- }
 
 
 
 
 
 
 
 
 
66
 
67
  endif;
68
 
1
  <?php
2
 
3
+ if (!defined('ABSPATH'))
4
+ exit; // Exit if accessed directly
5
 
6
+ if (!class_exists('Persian_Woocommerce_Widget')) :
7
 
8
+ class Persian_Woocommerce_Widget extends Persian_Woocommerce_Plugin
9
+ {
 
 
 
10
 
11
+ public function __construct()
12
+ {
13
+ add_action('wp_dashboard_setup', array($this, 'woocommerce_persian_widgetshow'));
14
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ public function woocommerce_persian_widget()
17
+ {
18
+ $widget_options = $this->woocommerce_persian_widgetoptions();
19
+ echo '<div class="rss-widget">';
20
+ wp_widget_rss_output(array(
21
+ 'url' => 'http://woocommerce.ir/feed.xml',
22
+ 'title' => 'آخرین اخبار و اطلاعیه های ووکامرس پارسی',
23
+ 'meta' => array('target' => '_new'),
24
+ 'items' => $widget_options['posts_number'],
25
+ 'show_summary' => 1,
26
+ 'show_author' => 0,
27
+ 'show_date' => 1
28
+ ));
29
+ ?>
30
+ <div style="border-top: 1px solid #e7e7e7; padding-top: 12px !important; font-size: 12px;">
31
+ <?php echo '<img src="' . plugins_url('assets/images/feed.png', __FILE__) . '" width="16" height="16" > '; ?>
32
+ <a href="http://woocommerce.ir" target="_new" title="خانه">وب سایت پشتیبان ووکامرس پارسی</a>
33
+ </div>
34
+ <?php
35
+ echo "</div>";
36
+ }
37
 
38
+ public function woocommerce_persian_widgetshow()
39
+ {
40
+ wp_add_dashboard_widget('woocommerce_persian_feed_' . str_replace(".", "_", PW_VERSION) . '_ver', 'آخرین اخبار و اطلاعیه های ووکامرس پارسی', array($this, 'woocommerce_persian_widget'), array($this, 'wooper_widset_pw'));
41
+ }
 
 
42
 
43
+ public function woocommerce_persian_widgetoptions()
44
+ {
45
+ $defaults = array('posts_number' => 5);
46
+ if ((!$options = get_option('woocommerce_persian_feed')) || !is_array($options))
47
+ $options = array();
48
+ return array_merge($defaults, $options);
49
+ }
50
+
51
+ public function wooper_widset_pw()
52
+ {
53
+ $options = $this->woocommerce_persian_widgetoptions();
54
+ if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST['widget_id']) && 'woocommerce_persian_feed' == $_POST['widget_id']) {
55
+ $options['posts_number'] = $_POST['posts_number'];
56
+ update_option('woocommerce_persian_feed', $options);
57
+ }
58
+ ?>
59
+ <p>
60
+ <label for="posts_number">تعداد نوشته های قابل نمایش در ابزارک ووکامرس پارسی:
61
+ <select id="posts_number" name="posts_number">
62
+ <?php for ($i = 3; $i <= 20; $i++)
63
+ echo "<option value='$i'" . ($options['posts_number'] == $i ? " selected='selected'" : '') . ">$i</option>";
64
+ ?>
65
+ </select>
66
+ </label>
67
+ </p>
68
+ <?php
69
+ }
70
+
71
+ }
72
 
73
  endif;
74
 
include/persian-woocommerce.php CHANGED
@@ -1,244 +1,313 @@
1
  <?php
2
 
3
- class Persian_Woocommerce_Plugin {
4
-
5
- public $table_lang;
6
- public $wc_is_active = false;
7
- public $file_dir;
8
- public $iran_address;
9
- public $currencies;
10
- public $rtl;
11
- public $widget;
12
- public $tools;
13
- public $translate;
14
-
15
- protected static $_instance = null;
16
-
17
- private $options;
18
-
19
- public static function instance( $file ) {
20
- if ( is_null( self::$_instance ) )
21
- self::$_instance = new self( $file );
22
-
23
- return self::$_instance;
24
- }
25
-
26
- public function __construct( $file ) {
27
-
28
- if( in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))) )
29
- $this->wc_is_active = true;
30
- else if( get_option('enable_woocommerce_notice_dismissed', 1) <= 10 )
31
- add_action('admin_notices', array($this, 'enable_woocommerce_notice') );
32
-
33
- global $wpdb;
34
-
35
- $this->table_lang = $wpdb->prefix . "woocommerce_ir";
36
- $this->file_dir = $file;
37
- $this->options = get_option("PW_Options");
38
-
39
- // Actions
40
- add_action('wp_ajax_nopriv_pw_replace_texts', array($this, 'replace_texts_callback') );
41
- add_action('wp_ajax_pw_replace_texts', array($this, 'replace_texts_callback') );
42
- add_action('plugins_loaded', array($this, 'pw_plugin_loaded') );
43
- add_action('activated_plugin', array($this, 'pw_activate'), 10, 1);
44
- add_action('admin_menu', array($this, 'pw_create_menu') );
45
- add_action('WC_Gateway_Payment_Actions', array($this, 'pw_gateway_copyright') );
46
-
47
- // Filters
48
- add_filter('woocommerce_admin_field_multi_select_states', array($this, 'pw_output_fields') );
49
-
50
- $this->translate();
51
- }
52
-
53
- public function plugin_url( $path = null ){
54
- return untrailingslashit(plugins_url( is_null($path) ? '/' : $path, $this->file_dir));
55
- }
56
-
57
- public function get_options( $option_name = null, $default = false){
58
-
59
- if(is_null($option_name))
60
- return $this->options;
61
-
62
- $default_options = $this->tools->get_tools_default();
63
-
64
- if(isset($this->options[$option_name]))
65
- return $this->options[$option_name];
66
- elseif(isset($default_options["PW_Options[$option_name]"]))
67
- return $default_options["PW_Options[$option_name]"];
68
- else
69
- return $default;
70
- }
71
-
72
- // Action functions
73
- public function enable_woocommerce_notice() {
74
- if(current_user_can('install_plugins')){
75
- echo sprintf('<div id="message" class="notice notice-info is-dismissible"><p>ووکامرس فارسی با موفقیت نصب و فعالسازی شده است . لطفا افزونه ووکامرس را از <a href="%s" target="_blank">اینجا</a> فعال کنید.</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', admin_url('plugins.php'));
76
-
77
- update_option('enable_woocommerce_notice_dismissed', get_option('enable_woocommerce_notice_dismissed', 1) + 1 );
78
- }
79
- }
80
-
81
- public function replace_texts_callback(){
82
- global $wpdb;
83
- $json = array(
84
- 'status' => 'NO',
85
- 'rand' => mt_rand(),
86
- 'msg' => 'مشکلی هنگام افزودن حلقه رخ داد . لطفا مجددا تلاش کنید.'
87
- );
88
-
89
- if(isset($_POST['text1'] , $_POST['text2'], $_POST['s']))
90
- if(!empty($_POST['text1'])){
91
- $insert = $wpdb->insert($this->table_lang , array('text1' => $_POST['text1'] , 'text2' => $_POST['text2']));
92
- if($insert) {
93
- $json['status'] = 'OK';
94
- $json['msg'] = sprintf('<div id="setting-error-pw_msg_%d" class="updated settings-error notice is-dismissible"><p><strong>حلقه (%s => %s) با موفقیت افزوده شد.</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', $json['rand'], $_POST['text1'], $_POST['text2']);
95
- $json['code'] = empty($_POST['s']) || array_search($_POST['s'], array($_POST['text1'] , $_POST['text2'])) !== false ? sprintf('<tr id="PW_item_%1$d" data-id="%1$d"><th scope="row" class="check-column"><input name="text_delete_id[]" value="%1$d" type="checkbox"></th><td class="text1 column-text1 has-row-actions column-primary" data-colname="حلقه‌ی اصلی">%2$s<button type="button" class="toggle-row"><span class="screen-reader-text">نمایش جزئیات بیشتر</span></button></td><td class="text2 column-text2" data-colname="حلقه‌ی جایگزین شده">%3$s</td></tr>', $wpdb->insert_id , $_POST['text1'], $_POST['text2']) : '';
96
- $search = empty($_POST['s']) ? '' : sprintf(' WHERE text1 LIKE "%%%1$s%%" OR text2 LIKE "%%%1$s%%"', sanitize_text_field($_POST['s']));
97
- $json['count'] = $wpdb->get_var("SELECT COUNT(*) FROM $this->table_lang{$search}") . " مورد";
98
- }
99
- else
100
- $json['msg'] = sprintf('<div id="setting-error-pw_msg_%d" class="error settings-error notice is-dismissible"><p><strong>خطایی در زمان افزودن حلقه (%s => %s) به دیتابیس رخ داده است. لطفا مجددا تلاش کنید</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', $json['rand'], $_POST['text1'], $_POST['text2']);
101
- }
102
- else
103
- $json['msg'] = sprintf('<div id="setting-error-pw_msg_%d" class="error settings-error notice is-dismissible"><p><strong>پر کردن فیلد کلمه‌ی مورد نظر اجباری می باشد.</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', $json['rand']);
104
-
105
- die(json_encode($json));
106
- }
107
-
108
-
109
- public function pw_plugin_loaded() {
110
- global $wpdb;
111
-
112
- if(get_locale() == 'fa_IR')
113
- load_textdomain('woocommerce', dirname( plugin_dir_path( __FILE__ )) . '/languages/woocommerce-fa_IR.mo');
114
-
115
- if(!get_option("pw_delete_city_table_2_5")) {
116
- $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}Woo_Iran_Cities_By_HANNANStd");
117
- $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_ir_cities");
118
- delete_option("is_cities_installed");
119
- delete_option("Persian_Woocommerce_rename_old_table");
120
- delete_option("redirect_to_woo_persian_about_page");
121
- update_option("pw_delete_city_table_2_5", PW_VERSION);
122
- }
123
- }
124
-
125
- public function pw_activate( $plugin ) {
126
- if($plugin !== "persian-woocommerce/persian-woocommerce.php")
127
- return;
128
-
129
- if(!headers_sent()){
130
- wp_redirect(admin_url('admin.php?page=persian-wc-about'));
131
- die();
132
- }
133
- }
134
-
135
- public function pw_create_menu() {
136
- add_menu_page('ووکامرس فارسی', 'ووکامرس فارسی', 'manage_options', 'persian-wc', array($this, 'pw_text'), $this->plugin_url('include/assets/images/logo.png'), '55.6');
137
- add_submenu_page('persian-wc', 'حلقه های ترجمه', 'حلقه های ترجمه', 'manage_options', 'persian-wc', array($this, 'pw_text'));
138
-
139
- if($this->wc_is_active){
140
- $tools_page = add_submenu_page('persian-wc', 'ابزار ها', 'ابزار ها', 'manage_options', 'persian-wc-tools', array($this, 'pw_tools'));
141
- add_action( "load-{$tools_page}", array($this, 'pw_tools_save') );
142
- }
143
-
144
- do_action("PW_Menu");
145
- add_submenu_page('persian-wc', 'درباره ما', 'درباره ما', 'manage_options', 'persian-wc-about', array($this, 'pw_about'));
146
- }
147
-
148
- public function pw_text() {
149
- global $wpdb;
150
- include_once('persian-woocommerce-text.php');
151
- }
152
-
153
- public function pw_tools(){
154
- $this->tools->settings_page();
155
- }
156
-
157
- public function pw_tools_save(){
158
- if( isset($_POST["pw-settings-submit"]) && $_POST["pw-settings-submit"] == 'Y') {
159
- $settings = $this->tools->get_tools();
160
- $tab = $_POST['pw-tab'];
161
- $section = $_POST['pw-section'];
162
- check_admin_referer("persian-wc-tools");
163
- do_action("PW_before_save_tools", $_POST, $settings, $tab, $section);
164
- WC_Admin_Settings::save_fields( empty($section) ? $settings[$tab] : $settings[$tab][$section] );
165
- do_action("PW_after_save_tools", $_POST, $settings, $tab, $section);
166
- $url_parameters = empty($section) ? 'updated=true&tab='.$tab : 'updated=true&tab='.$tab.'&section='.$section;
167
- wp_redirect(admin_url('admin.php?page=persian-wc-tools&'.$url_parameters));
168
- exit;
169
- }
170
- }
171
-
172
- public function pw_about() {
173
- include_once('persian-woocommerce-about.php');
174
- }
175
-
176
- public function pw_gateway_copyright( $arg ) {
177
- if( base64_encode(strtolower($arg)) != 'd29vY29tbWVyY2UuaXI=' )
178
- die(base64_decode('2KfbjNmGINiv2LHar9in2Ycg2b7Ysdiv2KfYrtiqINqp2KfZhdmE2Kcg2qnZvtuMINio2LHYr9in2LHbjCDYtNiv2Ycg2KfYsiDYr9ix2q/Yp9mHINmH2KfbjCDYt9ix2KfYrduMINi02K/ZhyDYqtmI2LPYtyDZiNmI2qnYp9mF2LHYsyDZvtin2LHYs9uMINin2LPYqiDZiCDYp9uM2YYg2LnZhdmEINio2K/ZiNmGINin2KzYp9iy2Ycg2KjYsdmG2KfZhdmHINmG2YjbjNizINin2YbYrNin2YUg2LTYr9mHINin2LPYqi4='));
179
- }
180
-
181
- // register hook functions
182
- static function pw_install() {
183
- global $wpdb;
184
-
185
- $woocommerce_ir_sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}woocommerce_ir` (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  `id` int(11) NOT NULL AUTO_INCREMENT,
187
  `text1` text CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL,
188
  `text2` text CHARACTER SET utf8 COLLATE utf8_persian_ci,
189
  PRIMARY KEY (`id`)
190
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
191
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
192
- dbDelta($woocommerce_ir_sql);
193
-
194
- delete_option('enable_woocommerce_notice_dismissed');
195
- }
196
-
197
- // Filter functions
198
- public function pw_output_fields( $value ){
199
-
200
- $selections = (array) $this->get_options('specific_allowed_states');
201
-
202
- ?><tr valign="top">
203
- <th scope="row" class="titledesc">
204
- <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
205
- </th>
206
- <td class="forminp">
207
- <select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="width:350px" data-placeholder="استان (ها) مورد نظر خود را انتخاب کنید ..." title="استان" class="wc-enhanced-select">
208
- <?php
209
- if ( ! empty( $this->iran_address->states ) )
210
- foreach ( $this->iran_address->states as $key => $val )
211
- echo '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val . '</option>';
212
- ?>
213
- </select> </br><a class="select_all button" href="#"><?php _e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'woocommerce' ); ?></a>
214
- </td>
215
- </tr><?php
216
- }
217
-
218
- public function translate(){
219
- global $wpdb;
220
-
221
- if(!is_array($this->translate)){
222
-
223
- $wpdb->suppress_errors = true;
224
- $result = $wpdb->get_results("SELECT * FROM {$this->table_lang};");
225
- $wpdb->suppress_errors = false;
226
-
227
- if($wpdb->last_error)
228
- return false;
229
-
230
- $this->translate = wp_list_pluck($result, 'text2', 'text1');
231
- }
232
-
233
- if(is_array($this->translate) && count(is_array($this->translate))){
234
- add_filter('gettext_with_context', array($this, 'pw_gettext') );
235
- add_filter('ngettext_with_context', array($this, 'pw_gettext') );
236
- add_filter('gettext', array($this, 'pw_gettext') );
237
- add_filter('ngettext', array($this, 'pw_gettext') );
238
- }
239
- }
240
-
241
- public function pw_gettext( $text ) {
242
- return isset($this->translate[$text]) ? $this->translate[$text] : $text;
243
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  }
1
  <?php
2
 
3
+ class Persian_Woocommerce_Plugin
4
+ {
5
+
6
+ public $table_lang;
7
+ public $wc_is_active = false;
8
+ public $file_dir;
9
+ public $iran_address;
10
+ public $currencies;
11
+ public $rtl;
12
+ public $widget;
13
+ public $tools;
14
+ public $translate;
15
+
16
+ protected static $_instance = null;
17
+
18
+ private $options;
19
+ private $notice_number = 1;
20
+
21
+ public static function instance($file)
22
+ {
23
+ if (is_null(self::$_instance))
24
+ self::$_instance = new self($file);
25
+
26
+ return self::$_instance;
27
+ }
28
+
29
+ public function __construct($file)
30
+ {
31
+
32
+ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))
33
+ $this->wc_is_active = true;
34
+ else if (get_option('enable_woocommerce_notice_dismissed', 1) <= 10)
35
+ add_action('admin_notices', array($this, 'enable_woocommerce_notice'));
36
+
37
+ if (!get_option('persian_woo_notice_number_' . $this->notice_number)) {
38
+ add_action('admin_notices', array($this, 'notice_text'));
39
+ add_action('wp_ajax_notice_ajax_action', array($this, 'notice_ajax_action'));
40
+ }
41
+
42
+ global $wpdb;
43
+
44
+ $this->table_lang = $wpdb->prefix . "woocommerce_ir";
45
+ $this->file_dir = $file;
46
+ $this->options = get_option("PW_Options");
47
+
48
+ // Actions
49
+ add_action('wp_ajax_nopriv_pw_replace_texts', array($this, 'replace_texts_callback'));
50
+ add_action('wp_ajax_pw_replace_texts', array($this, 'replace_texts_callback'));
51
+ add_action('plugins_loaded', array($this, 'pw_plugin_loaded'));
52
+ add_action('activated_plugin', array($this, 'pw_activate'), 10, 1);
53
+ add_action('admin_menu', array($this, 'pw_create_menu'));
54
+ add_action('WC_Gateway_Payment_Actions', array($this, 'pw_gateway_copyright'));
55
+
56
+ // Filters
57
+ add_filter('woocommerce_admin_field_multi_select_states', array($this, 'pw_output_fields'));
58
+
59
+ $this->translate();
60
+ }
61
+
62
+ public function plugin_url($path = null)
63
+ {
64
+ return untrailingslashit(plugins_url(is_null($path) ? '/' : $path, $this->file_dir));
65
+ }
66
+
67
+ public function get_options($option_name = null, $default = false)
68
+ {
69
+
70
+ if (is_null($option_name))
71
+ return $this->options;
72
+
73
+ $default_options = $this->tools->get_tools_default();
74
+
75
+ if (isset($this->options[$option_name]))
76
+ return $this->options[$option_name];
77
+ elseif (isset($default_options["PW_Options[$option_name]"]))
78
+ return $default_options["PW_Options[$option_name]"];
79
+ else
80
+ return $default;
81
+ }
82
+
83
+ // Action functions
84
+ public function enable_woocommerce_notice()
85
+ {
86
+ if (current_user_can('install_plugins')) {
87
+ echo sprintf('<div id="message" class="notice notice-info is-dismissible"><p>ووکامرس فارسی با موفقیت نصب و فعالسازی شده است . لطفا افزونه ووکامرس را از <a href="%s" target="_blank">اینجا</a> فعال کنید.</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', admin_url('plugins.php'));
88
+
89
+ update_option('enable_woocommerce_notice_dismissed', get_option('enable_woocommerce_notice_dismissed', 1) + 1);
90
+ }
91
+ }
92
+
93
+ public function replace_texts_callback()
94
+ {
95
+ global $wpdb;
96
+ $json = array(
97
+ 'status' => 'NO',
98
+ 'rand' => mt_rand(),
99
+ 'msg' => 'مشکلی هنگام افزودن حلقه رخ داد . لطفا مجددا تلاش کنید.'
100
+ );
101
+
102
+ if (isset($_POST['text1'], $_POST['text2'], $_POST['s']))
103
+ if (!empty($_POST['text1'])) {
104
+ $insert = $wpdb->insert($this->table_lang, array('text1' => $_POST['text1'], 'text2' => $_POST['text2']));
105
+ if ($insert) {
106
+ $json['status'] = 'OK';
107
+ $json['msg'] = sprintf('<div id="setting-error-pw_msg_%d" class="updated settings-error notice is-dismissible"><p><strong>حلقه (%s => %s) با موفقیت افزوده شد.</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', $json['rand'], $_POST['text1'], $_POST['text2']);
108
+ $json['code'] = empty($_POST['s']) || array_search($_POST['s'], array($_POST['text1'], $_POST['text2'])) !== false ? sprintf('<tr id="PW_item_%1$d" data-id="%1$d"><th scope="row" class="check-column"><input name="text_delete_id[]" value="%1$d" type="checkbox"></th><td class="text1 column-text1 has-row-actions column-primary" data-colname="حلقه‌ی اصلی">%2$s<button type="button" class="toggle-row"><span class="screen-reader-text">نمایش جزئیات بیشتر</span></button></td><td class="text2 column-text2" data-colname="حلقه‌ی جایگزین شده">%3$s</td></tr>', $wpdb->insert_id, $_POST['text1'], $_POST['text2']) : '';
109
+ $search = empty($_POST['s']) ? '' : sprintf(' WHERE text1 LIKE "%%%1$s%%" OR text2 LIKE "%%%1$s%%"', sanitize_text_field($_POST['s']));
110
+ $json['count'] = $wpdb->get_var("SELECT COUNT(*) FROM $this->table_lang{$search}") . " مورد";
111
+ } else
112
+ $json['msg'] = sprintf('<div id="setting-error-pw_msg_%d" class="error settings-error notice is-dismissible"><p><strong>خطایی در زمان افزودن حلقه (%s => %s) به دیتابیس رخ داده است. لطفا مجددا تلاش کنید</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', $json['rand'], $_POST['text1'], $_POST['text2']);
113
+ } else
114
+ $json['msg'] = sprintf('<div id="setting-error-pw_msg_%d" class="error settings-error notice is-dismissible"><p><strong>پر کردن فیلد کلمه‌ی مورد نظر اجباری می باشد.</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">بستن این اعلان.</span></button></div>', $json['rand']);
115
+
116
+ die(json_encode($json));
117
+ }
118
+
119
+
120
+ public function pw_plugin_loaded()
121
+ {
122
+ global $wpdb;
123
+
124
+ if (get_locale() == 'fa_IR')
125
+ load_textdomain('woocommerce', dirname(plugin_dir_path(__FILE__)) . '/languages/woocommerce-fa_IR.mo');
126
+
127
+ if (!get_option("pw_delete_city_table_2_5")) {
128
+ $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}Woo_Iran_Cities_By_HANNANStd");
129
+ $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_ir_cities");
130
+ delete_option("is_cities_installed");
131
+ delete_option("Persian_Woocommerce_rename_old_table");
132
+ delete_option("redirect_to_woo_persian_about_page");
133
+ update_option("pw_delete_city_table_2_5", PW_VERSION);
134
+ }
135
+ }
136
+
137
+ public function pw_activate($plugin)
138
+ {
139
+ if ($plugin !== "persian-woocommerce/persian-woocommerce.php")
140
+ return;
141
+
142
+ if (!headers_sent()) {
143
+ wp_redirect(admin_url('admin.php?page=persian-wc-about'));
144
+ die();
145
+ }
146
+ }
147
+
148
+ public function pw_create_menu()
149
+ {
150
+ add_menu_page('ووکامرس فارسی', 'ووکامرس فارسی', 'manage_options', 'persian-wc', array($this, 'pw_text'), $this->plugin_url('include/assets/images/logo.png'), '55.6');
151
+ add_submenu_page('persian-wc', 'حلقه های ترجمه', 'حلقه های ترجمه', 'manage_options', 'persian-wc', array($this, 'pw_text'));
152
+
153
+ if ($this->wc_is_active) {
154
+ $tools_page = add_submenu_page('persian-wc', 'ابزار ها', 'ابزار ها', 'manage_options', 'persian-wc-tools', array($this, 'pw_tools'));
155
+ add_action("load-{$tools_page}", array($this, 'pw_tools_save'));
156
+ }
157
+
158
+ do_action("PW_Menu");
159
+ add_submenu_page('persian-wc', 'درباره ما', 'درباره ما', 'manage_options', 'persian-wc-about', array($this, 'pw_about'));
160
+ }
161
+
162
+ public function pw_text()
163
+ {
164
+ global $wpdb;
165
+ include_once('persian-woocommerce-text.php');
166
+ }
167
+
168
+ public function pw_tools()
169
+ {
170
+ $this->tools->settings_page();
171
+ }
172
+
173
+ public function pw_tools_save()
174
+ {
175
+ if (isset($_POST["pw-settings-submit"]) && $_POST["pw-settings-submit"] == 'Y') {
176
+ $settings = $this->tools->get_tools();
177
+ $tab = $_POST['pw-tab'];
178
+ $section = $_POST['pw-section'];
179
+ check_admin_referer("persian-wc-tools");
180
+ do_action("PW_before_save_tools", $_POST, $settings, $tab, $section);
181
+ WC_Admin_Settings::save_fields(empty($section) ? $settings[$tab] : $settings[$tab][$section]);
182
+ do_action("PW_after_save_tools", $_POST, $settings, $tab, $section);
183
+ $url_parameters = empty($section) ? 'updated=true&tab=' . $tab : 'updated=true&tab=' . $tab . '&section=' . $section;
184
+ wp_redirect(admin_url('admin.php?page=persian-wc-tools&' . $url_parameters));
185
+ exit;
186
+ }
187
+ }
188
+
189
+ public function pw_about()
190
+ {
191
+ include_once('persian-woocommerce-about.php');
192
+ }
193
+
194
+ public function pw_gateway_copyright($arg)
195
+ {
196
+ if (base64_encode(strtolower($arg)) != 'd29vY29tbWVyY2UuaXI=')
197
+ die(base64_decode('2KfbjNmGINiv2LHar9in2Ycg2b7Ysdiv2KfYrtiqINqp2KfZhdmE2Kcg2qnZvtuMINio2LHYr9in2LHbjCDYtNiv2Ycg2KfYsiDYr9ix2q/Yp9mHINmH2KfbjCDYt9ix2KfYrduMINi02K/ZhyDYqtmI2LPYtyDZiNmI2qnYp9mF2LHYsyDZvtin2LHYs9uMINin2LPYqiDZiCDYp9uM2YYg2LnZhdmEINio2K/ZiNmGINin2KzYp9iy2Ycg2KjYsdmG2KfZhdmHINmG2YjbjNizINin2YbYrNin2YUg2LTYr9mHINin2LPYqi4='));
198
+ }
199
+
200
+ // register hook functions
201
+ static function pw_install()
202
+ {
203
+ global $wpdb;
204
+
205
+ $woocommerce_ir_sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}woocommerce_ir` (
206
  `id` int(11) NOT NULL AUTO_INCREMENT,
207
  `text1` text CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL,
208
  `text2` text CHARACTER SET utf8 COLLATE utf8_persian_ci,
209
  PRIMARY KEY (`id`)
210
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
211
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
212
+ dbDelta($woocommerce_ir_sql);
213
+
214
+ delete_option('enable_woocommerce_notice_dismissed');
215
+ }
216
+
217
+ // Filter functions
218
+ public function pw_output_fields($value)
219
+ {
220
+
221
+ $selections = (array)$this->get_options('specific_allowed_states');
222
+
223
+ ?>
224
+ <tr valign="top">
225
+ <th scope="row" class="titledesc">
226
+ <label for="<?php echo esc_attr($value['id']); ?>"><?php echo esc_html($value['title']); ?></label>
227
+ </th>
228
+ <td class="forminp">
229
+ <select multiple="multiple" name="<?php echo esc_attr($value['id']); ?>[]" style="width:350px"
230
+ data-placeholder="استان (ها) مورد نظر خود را انتخاب کنید ..." title="استان"
231
+ class="wc-enhanced-select">
232
+ <?php
233
+ if (!empty($this->iran_address->states))
234
+ foreach ($this->iran_address->states as $key => $val)
235
+ echo '<option value="' . esc_attr($key) . '" ' . selected(in_array($key, $selections), true, false) . '>' . $val . '</option>';
236
+ ?>
237
+ </select> </br><a class="select_all button" href="#"><?php _e('Select all', 'woocommerce'); ?></a> <a
238
+ class="select_none button" href="#"><?php _e('Select none', 'woocommerce'); ?></a>
239
+ </td>
240
+ </tr><?php
241
+ }
242
+
243
+ public function translate()
244
+ {
245
+ global $wpdb;
246
+
247
+ if (!is_array($this->translate)) {
248
+
249
+ $wpdb->suppress_errors = true;
250
+ $result = $wpdb->get_results("SELECT * FROM {$this->table_lang};");
251
+ $wpdb->suppress_errors = false;
252
+
253
+ if ($wpdb->last_error)
254
+ return false;
255
+
256
+ $this->translate = wp_list_pluck($result, 'text2', 'text1');
257
+ }
258
+
259
+ if (is_array($this->translate) && count(is_array($this->translate))) {
260
+ add_filter('gettext_with_context', array($this, 'pw_gettext'));
261
+ add_filter('ngettext_with_context', array($this, 'pw_gettext'));
262
+ add_filter('gettext', array($this, 'pw_gettext'));
263
+ add_filter('ngettext', array($this, 'pw_gettext'));
264
+ }
265
+ }
266
+
267
+ public function pw_gettext($text)
268
+ {
269
+ return isset($this->translate[$text]) ? $this->translate[$text] : $text;
270
+ }
271
+
272
+ //
273
+ public function notice_text()
274
+ {
275
+ $message = array();
276
+ $message[] = '<strong>ووکامرس پارسی :</strong> اطلاعیه در مورد شهر های ایران »';
277
+ $message[] = 'با توجه به بازنویسی مجدد بخش شهرهای ایران، دوستانی که قصد ویرایش لیست شهرها یا نوشتن پلاگین های پستی را دارند اطلاعیه زیر را مطالعه نمایند.';
278
+ $message[] = '<a target="_blank" style="color:#46B450;text-decoration:none;" href="https://goo.gl/LgUvjG">مشاهده اطلاعیه</a> -
279
+ <a target="_blank" class="notice-dismiss-url" style="color:#FF0000;text-decoration:none;" href="#">حذف</a>';
280
+
281
+ printf('<div class="notice notice-success pwoo_support_notice is-dismissible"><p>%s</p></div>', implode('<br>', $message));
282
+ ?>
283
+ <script type="text/javascript">
284
+ jQuery(document).ready(function ($) {
285
+ $(document.body).on("click", ".pwoo_support_notice .notice-dismiss, .pwoo_support_notice .notice-dismiss-url", function () {
286
+ $('.pwoo_support_notice').hide();
287
+ $.ajax({
288
+ url: "<?php echo admin_url('admin-ajax.php') ?>",
289
+ type: "post",
290
+ data: {
291
+ action: "notice_ajax_action",
292
+ security: "<?php echo wp_create_nonce("notice_ajax_action"); ?>",
293
+ },
294
+ success: function (response) {
295
+ }
296
+ });
297
+ return false;
298
+ });
299
+ });
300
+ </script>
301
+ <?php
302
+ }
303
+
304
+ public function notice_ajax_action()
305
+ {
306
+ check_ajax_referer('notice_ajax_action', 'security');
307
+ update_option('persian_woo_notice_number_' . $this->notice_number, 'true');
308
+ for ($i = 1; $i < $this->notice_number; $i++)
309
+ delete_option('persian_woo_notice_number_' . $i);
310
+ die();
311
+ }
312
+
313
  }
readme.txt CHANGED
@@ -52,6 +52,8 @@ This plugin extends the WooCommerce shop plugin with complete Persian(Farsi) lan
52
  You can read complete documentations on the [woocommerce.ir](http://www.woocommerce.ir)
53
 
54
  == Changelog ==
 
 
55
  = 2.6.14 =
56
  * بازنویسی مجدد کدهای مربوط به شهرهای ایران
57
  = 2.6.11 =
@@ -110,6 +112,8 @@ You can read complete documentations on the [woocommerce.ir](http://www.woocomme
110
  * نسخه اولیه
111
 
112
  == Upgrade Notice ==
 
 
113
  = 2.6.14 =
114
  * بازنویسی مجدد کدهای مربوط به شهرهای ایران
115
  = 2.6.11 =
52
  You can read complete documentations on the [woocommerce.ir](http://www.woocommerce.ir)
53
 
54
  == Changelog ==
55
+ = 2.6.15 =
56
+ * بهبود بخش شهرهای ایران
57
  = 2.6.14 =
58
  * بازنویسی مجدد کدهای مربوط به شهرهای ایران
59
  = 2.6.11 =
112
  * نسخه اولیه
113
 
114
  == Upgrade Notice ==
115
+ = 2.6.15 =
116
+ * بهبود بخش شهرهای ایران
117
  = 2.6.14 =
118
  * بازنویسی مجدد کدهای مربوط به شهرهای ایران
119
  = 2.6.11 =
woocommerce-persian.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: ووکامرس پارسی
4
  Plugin URI: http://woocommerce.ir
5
  Description: بسته فارسی ساز ووکامرس پارسی به راحتی سیستم فروشگاه ساز ووکامرس را فارسی می کند. با فعال سازی افزونه ، واحد پولی ریال و تومان ایران و همچنین لیست استان های ایران به افزونه افزوده می شوند. پشتیبانی در <a href="http://www.woocommerce.ir/" target="_blank">ووکامرس پارسی</a>.
6
- Version: 2.6.14
7
  Author: ووکامرس فارسی
8
  Author URI: http://woocommerce.ir
9
  */
@@ -12,7 +12,7 @@ if (!defined('ABSPATH'))
12
  exit; // Exit if accessed directly
13
 
14
  if (!defined('PW_VERSION'))
15
- define('PW_VERSION', '2.6.14');
16
 
17
  require_once(dirname(__FILE__) . '/include/persian-woocommerce.php');
18
 
3
  Plugin Name: ووکامرس پارسی
4
  Plugin URI: http://woocommerce.ir
5
  Description: بسته فارسی ساز ووکامرس پارسی به راحتی سیستم فروشگاه ساز ووکامرس را فارسی می کند. با فعال سازی افزونه ، واحد پولی ریال و تومان ایران و همچنین لیست استان های ایران به افزونه افزوده می شوند. پشتیبانی در <a href="http://www.woocommerce.ir/" target="_blank">ووکامرس پارسی</a>.
6
+ Version: 2.6.15
7
  Author: ووکامرس فارسی
8
  Author URI: http://woocommerce.ir
9
  */
12
  exit; // Exit if accessed directly
13
 
14
  if (!defined('PW_VERSION'))
15
+ define('PW_VERSION', '2.6.15');
16
 
17
  require_once(dirname(__FILE__) . '/include/persian-woocommerce.php');
18