|
1
|
|
|
<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
2
|
|
|
|
|
3
|
|
|
class wps_barcode_metabox { |
|
4
|
|
|
public function __construct() { |
|
5
|
|
|
add_action( 'add_meta_boxes', array($this, 'add_meta_box'), 10, 10 ); |
|
6
|
|
|
add_action( 'admin_enqueue_scripts', array($this, 'add_scripts') ); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Adding JQuery scripts |
|
11
|
|
|
*/ |
|
12
|
|
View Code Duplication |
public function add_scripts() { |
|
|
|
|
|
|
13
|
|
|
global $current_screen; |
|
14
|
|
|
if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_COUPON ), true ) ) |
|
15
|
|
|
return; |
|
16
|
|
|
|
|
17
|
|
|
wp_enqueue_script( 'jquery' ); |
|
18
|
|
|
wp_enqueue_script( 'wps_barcode_printelement', WPS_BARCODE_JSCRIPTS.'/jquery.printElement.js' ); |
|
19
|
|
|
wp_enqueue_script( 'wps_barcode', WPS_BARCODE_JSCRIPTS.'/wps.backend.wps_barcode.js' ); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Adding metabox for wps_barcode |
|
24
|
|
|
*/ |
|
25
|
|
|
public function add_meta_box() { |
|
26
|
|
|
global $wpdb, $table_prefix; |
|
27
|
|
|
|
|
28
|
|
|
$conf = get_option('wps_barcode'); |
|
29
|
|
|
|
|
30
|
|
|
$post = get_post( get_the_ID() ); |
|
31
|
|
|
if ( !empty($post) ) { |
|
32
|
|
|
$query = $wpdb->prepare( " |
|
33
|
|
|
SELECT * |
|
34
|
|
|
FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
|
35
|
|
|
WHERE entity_id = %d |
|
36
|
|
|
AND attribute_id = ( |
|
37
|
|
|
SELECT id |
|
38
|
|
|
FROM " . WPSHOP_DBT_ATTRIBUTE . " |
|
39
|
|
|
WHERE code = %s |
|
40
|
|
|
)" , $post->ID, 'barcode' ); |
|
41
|
|
|
$result = $wpdb->get_results( $query, ARRAY_A ); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
add_meta_box('wps_barcode_product', __('Barcode Manager', 'wps_barcode' ), |
|
44
|
|
|
array( $this, 'meta_box_product' ), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
45
|
|
|
'side','default'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($conf['type'] === 'internal') { |
|
49
|
|
|
add_meta_box('wps_barcode_invoice_client', __('Barcode Manager', 'wps_barcode' ), |
|
50
|
|
|
array( $this, 'meta_box_invoice_client' ), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
|
51
|
|
|
'side','default'); |
|
52
|
|
|
|
|
53
|
|
|
add_meta_box('wps_barcode_coupons', __('Barcode Manager', 'wps_barcode' ), |
|
54
|
|
|
array( $this, 'meta_box_coupons' ), WPSHOP_NEWTYPE_IDENTIFIER_COUPON, |
|
55
|
|
|
'side','default'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Metabox for product page |
|
61
|
|
|
*/ |
|
62
|
|
|
public function meta_box_product() { |
|
63
|
|
|
global $meta, $barcode, $post_ID, $wpdb, $table_prefix, $ajax; |
|
64
|
|
|
|
|
65
|
|
|
require_once('wps_barcodegen.ctr.php'); |
|
66
|
|
|
|
|
67
|
|
|
$barcode = new wps_barcodegen; |
|
68
|
|
|
|
|
69
|
|
|
$ajaxurl = admin_url('admin-ajax.php'); |
|
|
|
|
|
|
70
|
|
|
$ajaxid = $post_ID; |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
$country = '000'; |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/*Select value of barcode*/ |
|
75
|
|
|
$result = $wpdb->get_results( |
|
76
|
|
|
'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR. |
|
77
|
|
|
' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE. |
|
78
|
|
|
' WHERE code = "barcode") AND entity_id="'.$post_ID.'"', ARRAY_A); |
|
79
|
|
|
$meta = !empty($result) ? $result[0]['value'] : ''; |
|
80
|
|
|
|
|
81
|
|
|
/*Get price of product*/ |
|
82
|
|
|
$result = $wpdb->get_results('SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL. |
|
83
|
|
|
' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE. |
|
84
|
|
|
' WHERE code="'.WPSHOP_PRODUCT_PRICE_TTC.'") AND entity_id='.$post_ID, ARRAY_A); |
|
85
|
|
|
|
|
86
|
|
|
if ( !empty($result) && $result[0]['value'] >= 0) { |
|
87
|
|
|
$price = $result[0]['value']; |
|
88
|
|
|
|
|
89
|
|
|
/*Get title of product*/ |
|
90
|
|
|
$post = get_post($post_ID, ARRAY_A); |
|
91
|
|
|
$ref = substr($post['post_title'], 0, 10); |
|
92
|
|
|
|
|
93
|
|
|
chdir('..'); |
|
94
|
|
|
chdir( plugin_dir_path(__FILE__) ); |
|
95
|
|
|
chdir('..'); |
|
96
|
|
|
|
|
97
|
|
|
$conf = get_option('wps_barcode'); |
|
98
|
|
|
|
|
99
|
|
|
if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
|
100
|
|
|
echo $ajax->generate_image($barcode, $meta, __('product', 'wps_barcode'), |
|
101
|
|
|
$price, $ref); |
|
102
|
|
|
} |
|
103
|
|
|
else { |
|
104
|
|
|
echo '<p style="text-align: center"><button class="button '. |
|
105
|
|
|
'button-primary button-large" type="button"'. |
|
106
|
|
|
'id="display_barcode" data-nonce=' . wp_create_nonce( 'imgProduct' ) . '>'. |
|
107
|
|
|
__('Display', 'wps_barcode').'</button></p>'; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
else { |
|
111
|
|
|
$conf = get_option('wps_barcode'); |
|
112
|
|
|
|
|
113
|
|
|
if ( $conf['generate_barcode'] === 'true' ) { |
|
114
|
|
|
echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
|
115
|
|
|
'wps_barcode'), __('product', 'wps_barcode')).'</p>'; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Metabox for command and invoice client |
|
122
|
|
|
*/ |
|
123
|
|
|
public function meta_box_invoice_client() { |
|
124
|
|
|
global $meta, $barcode, $post_ID, $wpdb, $table_prefix; |
|
125
|
|
|
|
|
126
|
|
|
$continue = false; |
|
127
|
|
|
|
|
128
|
|
|
require_once('wps_barcodegen.ctr.php'); |
|
129
|
|
|
|
|
130
|
|
|
$barcode = new wps_barcodegen; |
|
131
|
|
|
|
|
132
|
|
|
$country = '000'; |
|
|
|
|
|
|
133
|
|
|
$result = get_post_meta($post_ID); |
|
134
|
|
|
|
|
135
|
|
|
if ( !empty($result) ) { |
|
136
|
|
|
$order_postmeta = isset( $result['_order_postmeta'] ) ? unserialize($result['_order_postmeta'][0]) : array(); |
|
137
|
|
|
|
|
138
|
|
|
if ( !empty($order_postmeta['order_invoice_date']) ) { |
|
139
|
|
|
$conf = get_option('wps_barcode'); |
|
140
|
|
|
if ($conf['type'] === 'internal') { |
|
141
|
|
|
$type = $conf['internal_invoice_client']; |
|
142
|
|
|
|
|
143
|
|
|
$order_date = isset($order_postmeta['order_invoice_date']) ? |
|
144
|
|
|
$order_postmeta['order_invoice_date'] : |
|
145
|
|
|
$order_postmeta['order_date']; |
|
146
|
|
|
$pDate = new DateTime($order_date); |
|
147
|
|
|
$date = $pDate->format('my'); |
|
148
|
|
|
|
|
149
|
|
|
if ( empty($order_postmeta['order_invoice_ref']) ) { |
|
150
|
|
|
$continue = false; |
|
151
|
|
|
} |
|
152
|
|
|
else { |
|
153
|
|
|
$continue = true; |
|
154
|
|
|
$id = substr($order_postmeta['order_invoice_ref'], 2); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
if ($continue === true) { |
|
158
|
|
|
$code = $type.$date.$id; |
|
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
if ( empty($result['_order_barcode']) ) { |
|
161
|
|
|
$meta = $barcode->checksum($code); |
|
162
|
|
|
add_post_meta($post_ID, '_order_barcode', $meta); |
|
163
|
|
|
} |
|
164
|
|
|
else { |
|
165
|
|
|
$meta = $result['_order_barcode']; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
chdir('..'); |
|
169
|
|
|
chdir( plugin_dir_path(__FILE__) ); |
|
170
|
|
|
chdir('..'); |
|
171
|
|
|
$order_meta = unserialize($result['_order_postmeta'][0]); |
|
172
|
|
|
$title = ( !empty($order_meta['order_invoice_ref']) ) ? $order_meta['order_invoice_ref'] : $order_meta['order_key']; |
|
173
|
|
|
$price = $order_meta['order_grand_total']; |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
|
177
|
|
|
$this->generate_image($barcode, $meta[0], __('order client', 'wps_barcode'), |
|
178
|
|
|
$price, $title ); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
else { |
|
182
|
|
|
echo '<p>'.__('None bardcode generated as customer can not get his bill.', |
|
183
|
|
|
'wps_barcode').'</p>'; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
else { |
|
188
|
|
|
echo '<p>'.__('None bardcode generated as customer can not get his bill.', |
|
189
|
|
|
'wps_barcode').'</p>'; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
else { |
|
193
|
|
|
echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
|
194
|
|
|
'wps_barcode'), 'order client').'</p>'; |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Metabox for coupons client |
|
200
|
|
|
*/ |
|
201
|
|
|
public function meta_box_coupons() { |
|
202
|
|
|
global $meta, $barcode, $post_ID, $wpdb, $table_prefix; |
|
203
|
|
|
|
|
204
|
|
|
$continue = false; |
|
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
require_once('wps_barcodegen.ctr.php'); |
|
207
|
|
|
|
|
208
|
|
|
$barcode = new wps_barcodegen; |
|
209
|
|
|
|
|
210
|
|
|
$country = '000'; |
|
|
|
|
|
|
211
|
|
|
$result = get_post_meta($post_ID); |
|
212
|
|
|
|
|
213
|
|
|
if ( !empty($result) ) { |
|
214
|
|
View Code Duplication |
if ( empty($result['wpshop_coupon_barcode']) ) { |
|
|
|
|
|
|
215
|
|
|
$conf = get_option('wps_barcode'); |
|
216
|
|
|
if ($conf['type'] === 'internal') { |
|
217
|
|
|
$type = $conf['internal_coupons']; |
|
218
|
|
|
|
|
219
|
|
|
$query = $wpdb->get_results('SELECT post_date FROM '. |
|
220
|
|
|
$table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A); |
|
221
|
|
|
|
|
222
|
|
|
$pDate = new DateTime($query[0]['post_date']); |
|
223
|
|
|
$date = $pDate->format('my'); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
$len = strlen($post_ID); |
|
227
|
|
|
$ref = ''; |
|
228
|
|
|
if ( $len < 5 ) { |
|
229
|
|
|
for ($i=0; $i <= $len; $i++) { |
|
230
|
|
|
$ref .= '0'; |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
$id = $ref.$post_ID; |
|
234
|
|
|
$code = $type.$date.$id; |
|
|
|
|
|
|
235
|
|
|
$meta = $barcode->checksum($code); |
|
236
|
|
|
add_post_meta($post_ID, 'wpshop_coupon_barcode', $meta); |
|
237
|
|
|
} |
|
238
|
|
|
else { |
|
239
|
|
|
$meta = $result['wpshop_coupon_barcode'][0]; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
$query = $wpdb->get_results('SELECT post_title FROM '. |
|
243
|
|
|
$table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A); |
|
244
|
|
|
|
|
245
|
|
|
$post = get_post($post_ID, ARRAY_A); |
|
|
|
|
|
|
246
|
|
|
if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
|
247
|
|
|
$ajax->generate_image($barcode, $meta, __('coupon', 'wps_barcode'), |
|
|
|
|
|
|
248
|
|
|
$result['wpshop_coupon_discount_value'][0], $query[0]['post_title'], $post_ID); |
|
249
|
|
|
} |
|
250
|
|
|
else { |
|
251
|
|
|
echo '<p style="text-align: center"><button class="button '. |
|
252
|
|
|
'button-primary button-large" type="button"'. |
|
253
|
|
|
'id="display_barcode">'. |
|
254
|
|
|
__('Display', 'wps_barcode').'</button></p>'; |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
else { |
|
258
|
|
|
echo '<p>'.__('None bardcode generated as coupon has not created.', |
|
259
|
|
|
'wps_barcode').'</p>'; |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* Generate barcode image |
|
265
|
|
|
* @param object $barcode Instance of wps_barcodegen |
|
266
|
|
|
* @param string $meta Numerical code of barcode |
|
267
|
|
|
* @param string $type Texte for complete message |
|
268
|
|
|
* @param string $price Price of product |
|
269
|
|
|
* @param string $title Title of product |
|
270
|
|
|
*/ |
|
271
|
|
|
public function generate_image(&$barcode, $meta, $type, $price, $title, $post_ID = 0) { |
|
272
|
|
|
if ( !extension_loaded('gd') ) { |
|
273
|
|
|
return '<p>'.__('Library GD is requiered.', 'wps_barcode').'</p>'; |
|
274
|
|
|
} |
|
275
|
|
|
if ( !empty($meta) ) { |
|
276
|
|
|
$barcode->setGenerateCode($meta); |
|
277
|
|
|
$binCode = $barcode->getBinCode(); |
|
278
|
|
|
|
|
279
|
|
|
$px = 3.779528; |
|
280
|
|
|
$x = round(66*$px); //249.449 px |
|
281
|
|
|
$y = round(50*$px); //188.976 px |
|
282
|
|
|
$bar_size = round(63.393/72); //0.880 px |
|
283
|
|
|
|
|
284
|
|
|
$len = 0; |
|
285
|
|
|
$test = ''; |
|
286
|
|
|
|
|
287
|
|
View Code Duplication |
while ($len !== strlen($binCode) ) { |
|
|
|
|
|
|
288
|
|
|
$test .= substr($binCode, $len, 7).' '; |
|
289
|
|
|
$len = $len+7; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
$im = imagecreate($x, $y); |
|
293
|
|
|
$background_color = imagecolorallocate($im, 255, 255, 255); |
|
|
|
|
|
|
294
|
|
|
$start = round(5.79*$px); //21.883 |
|
295
|
|
|
|
|
296
|
|
|
/*Write First left guard*/ |
|
297
|
|
|
$this->imgNormalGuard($im, $start, $start+$bar_size, |
|
298
|
|
|
imagecolorallocate($im, 0, 0, 0)); |
|
299
|
|
|
$this->imgNormalGuard($im, $start+($bar_size*2), |
|
300
|
|
|
$start+($bar_size*3), imagecolorallocate($im, 255, 255, 255)); |
|
301
|
|
|
$this->imgNormalGuard($im, $start+($bar_size*4), |
|
302
|
|
|
$start+($bar_size*5), imagecolorallocate($im, 0, 0, 0)); |
|
303
|
|
|
|
|
304
|
|
|
$pos = $start+($bar_size*7); |
|
305
|
|
|
$newPos = $pos+$bar_size; |
|
306
|
|
|
|
|
307
|
|
|
/*Write left barcode*/ |
|
308
|
|
View Code Duplication |
for ($i=0; $i<42 ; $i++) { |
|
|
|
|
|
|
309
|
|
|
if( substr($binCode, $i, 1) === '0' ) { |
|
310
|
|
|
$color = imagecolorallocate($im, 255, 255, 255); |
|
311
|
|
|
} |
|
312
|
|
|
else { |
|
313
|
|
|
$color = imagecolorallocate($im, 0, 0, 0); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
$this->imgSymbole($im, $pos, $newPos, $color); |
|
317
|
|
|
$newPos = $pos+$bar_size; |
|
318
|
|
|
$pos = $newPos+$bar_size; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/*Writer center guard*/ |
|
322
|
|
|
$pos = $newPos; |
|
323
|
|
|
$this->imgNormalGuard($im, $pos, $newPos+$bar_size, |
|
324
|
|
|
imagecolorallocate($im, 255, 255, 255)); |
|
325
|
|
|
$this->imgNormalGuard($im, $pos+($bar_size*2), |
|
326
|
|
|
$newPos+($bar_size*3), imagecolorallocate($im, 0, 0, 0)); |
|
327
|
|
|
$this->imgNormalGuard($im, $pos+($bar_size*4), |
|
328
|
|
|
$newPos+($bar_size*5), imagecolorallocate($im, 255, 255, 255)); |
|
329
|
|
|
$this->imgNormalGuard($im, $pos+($bar_size*6), |
|
330
|
|
|
$newPos+($bar_size*7), imagecolorallocate($im, 0, 0, 0)); |
|
331
|
|
|
$this->imgNormalGuard($im, $pos+($bar_size*8), |
|
332
|
|
|
$newPos+($bar_size*9), imagecolorallocate($im, 255, 255, 255)); |
|
333
|
|
|
|
|
334
|
|
|
$pos = $newPos+($bar_size*10); |
|
335
|
|
|
|
|
336
|
|
|
/*Write right barcode*/ |
|
337
|
|
View Code Duplication |
for ($i=42; $i<84 ; $i++) { |
|
|
|
|
|
|
338
|
|
|
if( substr($binCode, $i, 1) === '0' ) { |
|
339
|
|
|
$color = imagecolorallocate($im, 255, 255, 255); |
|
340
|
|
|
} |
|
341
|
|
|
else { |
|
342
|
|
|
$color = imagecolorallocate($im, 0, 0, 0); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
$newPos = $pos+$bar_size; |
|
346
|
|
|
|
|
347
|
|
|
$this->imgSymbole($im, $pos, $newPos, $color); |
|
348
|
|
|
$pos = $newPos+$bar_size; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/*Write right guard*/ |
|
352
|
|
|
$pos = $newPos+$bar_size; |
|
353
|
|
|
$this->imgNormalGuard($im, $pos, $pos+$bar_size, |
|
354
|
|
|
imagecolorallocate($im, 0, 0, 0)); |
|
355
|
|
|
$this->imgNormalGuard($im, $pos+($bar_size*2), |
|
356
|
|
|
$pos+($bar_size*3), imagecolorallocate($im, 255, 255, 255)); |
|
357
|
|
|
$this->imgNormalGuard($im, $pos+($bar_size*4), |
|
358
|
|
|
$pos+($bar_size*5), imagecolorallocate($im, 0, 0, 0)); |
|
359
|
|
|
|
|
360
|
|
|
$textSize = 16; |
|
361
|
|
|
$font = 'assets/fonts/arialbd.ttf'; |
|
362
|
|
|
imagettftext($im, $textSize, 0, 8, $y-$start-5, |
|
363
|
|
|
imagecolorallocate($im, 0, 0, 0), $font, substr($meta, 0, 1)); |
|
364
|
|
|
|
|
365
|
|
|
$continue = true; |
|
|
|
|
|
|
366
|
|
|
$i = 28; $j = 0; |
|
367
|
|
|
|
|
368
|
|
|
/*Write left number code*/ |
|
369
|
|
View Code Duplication |
while ($j<5) { |
|
|
|
|
|
|
370
|
|
|
$j=$j+1; |
|
371
|
|
|
imagettftext($im, $textSize, 0, $i, $y-$start-5, |
|
372
|
|
|
imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1)); |
|
373
|
|
|
$i = $i+14; |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
/*Write right number code*/ |
|
377
|
|
View Code Duplication |
while ($j<11) { |
|
|
|
|
|
|
378
|
|
|
$j=$j+1; |
|
379
|
|
|
imagettftext($im, $textSize, 0, $i+6, $y-$start-5, |
|
380
|
|
|
imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1)); |
|
381
|
|
|
$i = $i+15; |
|
382
|
|
|
} |
|
383
|
|
|
imagettftext($im, $textSize, 0, $i+4, $y-$start-5, |
|
384
|
|
|
imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j+1, 1)); |
|
385
|
|
|
|
|
386
|
|
|
/*Write ref product and price*/ |
|
387
|
|
|
$textSize = 12; |
|
388
|
|
|
$currency = (wpshop_tools::wpshop_get_currency() === '€') ? "€" : wpshop_tools::wpshop_get_currency(); |
|
389
|
|
|
|
|
390
|
|
View Code Duplication |
if ( $type === __('coupon', 'wps_barcode') ) { |
|
|
|
|
|
|
391
|
|
|
$coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type'); |
|
392
|
|
|
if ( $coupon_postmeta[0] === 'percent' ) { |
|
393
|
|
|
$price = $price.' %'; |
|
394
|
|
|
} |
|
395
|
|
|
else { |
|
396
|
|
|
$price = sprintf( number_format( $price, 2 ). ' '.$currency); |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
else { |
|
400
|
|
|
$price = sprintf( number_format( $price, 2 ). ' '.$currency); |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
imagettftext($im, $textSize, 0, 20, round(6*$px), |
|
404
|
|
|
imagecolorallocate($im, 0, 0, 0), $font, $title); |
|
405
|
|
|
imagettftext($im, $textSize, 0, ($x/2)+40, round(6*$px), |
|
406
|
|
|
imagecolorallocate($im, 0, 0, 0), $font, $price); |
|
407
|
|
|
|
|
408
|
|
|
ob_start(); |
|
409
|
|
|
imagepng($im); |
|
410
|
|
|
$img = ob_get_clean(); |
|
411
|
|
|
|
|
412
|
|
|
echo '<p><img src="data:image/png;base64,'.base64_encode($img). |
|
413
|
|
|
'" id="barcode" width="160" height="90" /></p>'; |
|
414
|
|
|
|
|
415
|
|
|
echo '<p style="text-align: right"><button class="button '. |
|
416
|
|
|
'button-primary button-large" type="button"'. |
|
417
|
|
|
'id="print_barcode">'. |
|
418
|
|
|
__('Print', 'wps_barcode').'</button></p>'; |
|
419
|
|
|
|
|
420
|
|
|
wp_mkdir_p( WPS_BARCODE_UPLOAD ); |
|
421
|
|
|
|
|
422
|
|
|
file_put_contents(WPS_BARCODE_UPLOAD.$meta.'.png', $img); |
|
423
|
|
|
|
|
424
|
|
|
/*Generate ODT File*/ |
|
425
|
|
|
try { |
|
426
|
|
|
if( !class_exists('Odf') ) { |
|
427
|
|
|
require_once(WPS_BARCODE_PATH.'/librairies/odtphp/odf.php'); |
|
428
|
|
|
} |
|
429
|
|
|
$odf = new Odf(WPS_BARCODE_PATH.'assets/medias/avery_a4_991_677.ott'); |
|
430
|
|
|
$odf->setImage('barcode', WPS_BARCODE_UPLOAD.$meta.'.png'); |
|
431
|
|
|
$odf->saveToDisk(WPS_BARCODE_UPLOAD.$meta.'.odt'); |
|
432
|
|
|
} catch (Exception $e) { |
|
433
|
|
|
echo __('Generation problem', 'wps_barcode'); |
|
434
|
|
|
} |
|
435
|
|
|
} |
|
436
|
|
|
else { |
|
437
|
|
|
echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
|
438
|
|
|
'wps_barcode'), $type).'</p>'; |
|
439
|
|
|
} |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
private function generateODT($img) { |
|
|
|
|
|
|
443
|
|
|
|
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
/** |
|
447
|
|
|
* Generate one bar for normal guard |
|
448
|
|
|
* @param resource $image Resource of barcode image generate with GD2 Lib |
|
449
|
|
|
* @param integer $pos X position of start rectangle |
|
450
|
|
|
* @param integer $size Size of rectangle |
|
451
|
|
|
* @param integer $color Color of rectangle |
|
452
|
|
|
*/ |
|
453
|
|
|
private function imgNormalGuard(&$image, $pos, $size, $color) { |
|
454
|
|
|
imagefilledrectangle($image, $pos, 180*0.25,$size, 180-10, $color ); |
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
/** |
|
458
|
|
|
* Generate one bar for barcode |
|
459
|
|
|
* @param resource $image Resource of barcode image generate with GD2 Lib |
|
460
|
|
|
* @param integer $pos X position of start rectangle |
|
461
|
|
|
* @param integer $size Size of rectangle |
|
462
|
|
|
* @param integer $color Color of rectangle |
|
463
|
|
|
*/ |
|
464
|
|
|
private function imgSymbole(&$image, $pos, $size, $color) { |
|
465
|
|
|
imagefilledrectangle($image, $pos, 180*0.25,$size, 180-40, $color ); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
?> |
|
|
|
|
|
|
471
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.