@@ -1,3 +1,3 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | ?> |
3 | 3 | <p><?php echo $content; ?></p> |
4 | 4 | \ No newline at end of file |
@@ -1,3 +1,5 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | ?> |
3 | 5 | <p><?php echo $content; ?></p> |
4 | 6 | \ No newline at end of file |
@@ -19,210 +19,210 @@ |
||
19 | 19 | */ |
20 | 20 | class Segment implements IteratorAggregate, Countable |
21 | 21 | { |
22 | - protected $xml; |
|
23 | - protected $xmlParsed = ''; |
|
24 | - protected $name; |
|
25 | - protected $children = array(); |
|
26 | - protected $vars = array(); |
|
27 | - public $manif_vars = array(); |
|
22 | + protected $xml; |
|
23 | + protected $xmlParsed = ''; |
|
24 | + protected $name; |
|
25 | + protected $children = array(); |
|
26 | + protected $vars = array(); |
|
27 | + public $manif_vars = array(); |
|
28 | 28 | protected $images = array(); |
29 | 29 | protected $odf; |
30 | 30 | protected $file; |
31 | - /** |
|
32 | - * Constructor |
|
33 | - * |
|
34 | - * @param string $name name of the segment to construct |
|
35 | - * @param string $xml XML tree of the segment |
|
36 | - */ |
|
37 | - public function __construct($name, $xml, $odf) |
|
38 | - { |
|
39 | - $this->name = (string) $name; |
|
40 | - $this->xml = (string) $xml; |
|
31 | + /** |
|
32 | + * Constructor |
|
33 | + * |
|
34 | + * @param string $name name of the segment to construct |
|
35 | + * @param string $xml XML tree of the segment |
|
36 | + */ |
|
37 | + public function __construct($name, $xml, $odf) |
|
38 | + { |
|
39 | + $this->name = (string) $name; |
|
40 | + $this->xml = (string) $xml; |
|
41 | 41 | $this->odf = $odf; |
42 | - $zipHandler = $this->odf->getConfig('ZIP_PROXY'); |
|
43 | - $this->file = new $zipHandler(); |
|
44 | - $this->_analyseChildren($this->xml); |
|
45 | - } |
|
46 | - /** |
|
47 | - * Returns the name of the segment |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getName() |
|
52 | - { |
|
53 | - return $this->name; |
|
54 | - } |
|
55 | - /** |
|
56 | - * Does the segment have children ? |
|
57 | - * |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function hasChildren() |
|
61 | - { |
|
62 | - return $this->getIterator()->hasChildren(); |
|
63 | - } |
|
64 | - /** |
|
65 | - * Countable interface |
|
66 | - * |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function count() |
|
70 | - { |
|
71 | - return count($this->children); |
|
72 | - } |
|
73 | - /** |
|
74 | - * IteratorAggregate interface |
|
75 | - * |
|
76 | - * @return Iterator |
|
77 | - */ |
|
78 | - public function getIterator() |
|
79 | - { |
|
80 | - return new RecursiveIteratorIterator(new SegmentIterator($this->children), 1); |
|
81 | - } |
|
82 | - /** |
|
83 | - * Replace variables of the template in the XML code |
|
84 | - * All the children are also called |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function merge() |
|
89 | - { |
|
90 | - $this->xmlParsed .= str_replace(array_keys($this->vars), array_values($this->vars), $this->xml); |
|
91 | - if ($this->hasChildren()) { |
|
92 | - foreach ($this->children as $child) { |
|
93 | - $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed=="")?$child->merge():$child->xmlParsed, $this->xmlParsed); |
|
94 | - $child->xmlParsed = ''; |
|
95 | - //Store all image names used in child segments in current segment array |
|
42 | + $zipHandler = $this->odf->getConfig('ZIP_PROXY'); |
|
43 | + $this->file = new $zipHandler(); |
|
44 | + $this->_analyseChildren($this->xml); |
|
45 | + } |
|
46 | + /** |
|
47 | + * Returns the name of the segment |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getName() |
|
52 | + { |
|
53 | + return $this->name; |
|
54 | + } |
|
55 | + /** |
|
56 | + * Does the segment have children ? |
|
57 | + * |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function hasChildren() |
|
61 | + { |
|
62 | + return $this->getIterator()->hasChildren(); |
|
63 | + } |
|
64 | + /** |
|
65 | + * Countable interface |
|
66 | + * |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function count() |
|
70 | + { |
|
71 | + return count($this->children); |
|
72 | + } |
|
73 | + /** |
|
74 | + * IteratorAggregate interface |
|
75 | + * |
|
76 | + * @return Iterator |
|
77 | + */ |
|
78 | + public function getIterator() |
|
79 | + { |
|
80 | + return new RecursiveIteratorIterator(new SegmentIterator($this->children), 1); |
|
81 | + } |
|
82 | + /** |
|
83 | + * Replace variables of the template in the XML code |
|
84 | + * All the children are also called |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function merge() |
|
89 | + { |
|
90 | + $this->xmlParsed .= str_replace(array_keys($this->vars), array_values($this->vars), $this->xml); |
|
91 | + if ($this->hasChildren()) { |
|
92 | + foreach ($this->children as $child) { |
|
93 | + $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed=="")?$child->merge():$child->xmlParsed, $this->xmlParsed); |
|
94 | + $child->xmlParsed = ''; |
|
95 | + //Store all image names used in child segments in current segment array |
|
96 | 96 | foreach ($child->manif_vars as $file) |
97 | - $this->manif_vars[] = $file; |
|
98 | - $child->manif_vars=array(); |
|
99 | - } |
|
100 | - } |
|
101 | - $reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/smU"; |
|
102 | - $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed); |
|
103 | - $this->file->open($this->odf->getTmpfile()); |
|
104 | - foreach ($this->images as $imageKey => $imageValue) { |
|
97 | + $this->manif_vars[] = $file; |
|
98 | + $child->manif_vars=array(); |
|
99 | + } |
|
100 | + } |
|
101 | + $reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/smU"; |
|
102 | + $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed); |
|
103 | + $this->file->open($this->odf->getTmpfile()); |
|
104 | + foreach ($this->images as $imageKey => $imageValue) { |
|
105 | 105 | if ($this->file->getFromName('Pictures/' . $imageValue) === false) { |
106 | 106 | $this->file->addFile($imageKey, 'Pictures/' . $imageValue); |
107 | 107 | } |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | - $this->file->close(); |
|
111 | - return $this->xmlParsed; |
|
112 | - } |
|
113 | - /** |
|
114 | - * Analyse the XML code in order to find children |
|
115 | - * |
|
116 | - * @param string $xml |
|
117 | - * @return Segment |
|
118 | - */ |
|
119 | - protected function _analyseChildren($xml) |
|
120 | - { |
|
121 | - // $reg2 = "#\[!--\sBEGIN\s([\S]*)\s--\](?:<\/text:p>)?(.*)(?:<text:p\s.*>)?\[!--\sEND\s(\\1)\s--\]#sm"; |
|
122 | - $reg2 = "#\[!--\sBEGIN\s([\S]*)\s--\](.*)\[!--\sEND\s(\\1)\s--\]#smU"; |
|
123 | - preg_match_all($reg2, $xml, $matches); |
|
124 | - for ($i = 0, $size = count($matches[0]); $i < $size; $i++) { |
|
125 | - if ($matches[1][$i] != $this->name) { |
|
126 | - $this->children[$matches[1][$i]] = new self($matches[1][$i], $matches[0][$i], $this->odf); |
|
127 | - } else { |
|
128 | - $this->_analyseChildren($matches[2][$i]); |
|
129 | - } |
|
130 | - } |
|
131 | - return $this; |
|
132 | - } |
|
133 | - /** |
|
134 | - * Assign a template variable to replace |
|
135 | - * |
|
136 | - * @param string $key |
|
137 | - * @param string $value |
|
138 | - * @throws SegmentException |
|
139 | - * @return Segment |
|
140 | - */ |
|
141 | - public function setVars($key, $value, $encode = true, $charset = 'ISO-8859') |
|
142 | - { |
|
143 | - if (strpos($this->xml, $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')) === false) { |
|
144 | - throw new SegmentException("var $key not found in {$this->getName()}"); |
|
145 | - } |
|
110 | + $this->file->close(); |
|
111 | + return $this->xmlParsed; |
|
112 | + } |
|
113 | + /** |
|
114 | + * Analyse the XML code in order to find children |
|
115 | + * |
|
116 | + * @param string $xml |
|
117 | + * @return Segment |
|
118 | + */ |
|
119 | + protected function _analyseChildren($xml) |
|
120 | + { |
|
121 | + // $reg2 = "#\[!--\sBEGIN\s([\S]*)\s--\](?:<\/text:p>)?(.*)(?:<text:p\s.*>)?\[!--\sEND\s(\\1)\s--\]#sm"; |
|
122 | + $reg2 = "#\[!--\sBEGIN\s([\S]*)\s--\](.*)\[!--\sEND\s(\\1)\s--\]#smU"; |
|
123 | + preg_match_all($reg2, $xml, $matches); |
|
124 | + for ($i = 0, $size = count($matches[0]); $i < $size; $i++) { |
|
125 | + if ($matches[1][$i] != $this->name) { |
|
126 | + $this->children[$matches[1][$i]] = new self($matches[1][$i], $matches[0][$i], $this->odf); |
|
127 | + } else { |
|
128 | + $this->_analyseChildren($matches[2][$i]); |
|
129 | + } |
|
130 | + } |
|
131 | + return $this; |
|
132 | + } |
|
133 | + /** |
|
134 | + * Assign a template variable to replace |
|
135 | + * |
|
136 | + * @param string $key |
|
137 | + * @param string $value |
|
138 | + * @throws SegmentException |
|
139 | + * @return Segment |
|
140 | + */ |
|
141 | + public function setVars($key, $value, $encode = true, $charset = 'ISO-8859') |
|
142 | + { |
|
143 | + if (strpos($this->xml, $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')) === false) { |
|
144 | + throw new SegmentException("var $key not found in {$this->getName()}"); |
|
145 | + } |
|
146 | 146 | $value = $encode ? htmlspecialchars($value) : $value; |
147 | 147 | $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; |
148 | - $this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = str_replace("\n", "<text:line-break/>", $value); |
|
149 | - return $this; |
|
150 | - } |
|
151 | - /** |
|
152 | - * Assign a template variable as a picture |
|
153 | - * |
|
154 | - * @param string $key name of the variable within the template |
|
155 | - * @param string $value path to the picture |
|
156 | - * @param string $page anchor to page number (or -1 if anchor-type is aschar) |
|
157 | - * @param string $width width of picture (keep original if null) |
|
158 | - * @param string $height height of picture (keep original if null) |
|
159 | - * @param string $offsetX offset by horizontal (not used if $page = -1) |
|
160 | - * @param string $offsetY offset by vertical (not used if $page = -1) |
|
161 | - * @throws OdfException |
|
162 | - * @return Segment |
|
163 | - */ |
|
164 | - public function setImage($key, $value, $page=null, $width=null, $height=null, $offsetX=null, $offsetY=null) |
|
165 | - { |
|
166 | - $filename = strtok(strrchr($value, '/'), '/.'); |
|
167 | - $file = substr(strrchr($value, '/'), 1); |
|
168 | - $size = @getimagesize($value); |
|
169 | - if ($size === false) { |
|
170 | - throw new OdfException("Invalid image"); |
|
171 | - } |
|
172 | - if (!$width && !$height) { |
|
173 | - list ($width, $height) = $size; |
|
174 | - $width *= Odf::PIXEL_TO_CM; |
|
175 | - $height *= Odf::PIXEL_TO_CM; |
|
176 | - } |
|
177 | - $anchor = $page == -1 ? 'text:anchor-type="aschar"' : "text:anchor-type=\"page\" text:anchor-page-number=\"{$page}\" svg:x=\"{$offsetX}cm\" svg:y=\"{$offsetY}cm\""; |
|
178 | - $xml = <<<IMG |
|
148 | + $this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = str_replace("\n", "<text:line-break/>", $value); |
|
149 | + return $this; |
|
150 | + } |
|
151 | + /** |
|
152 | + * Assign a template variable as a picture |
|
153 | + * |
|
154 | + * @param string $key name of the variable within the template |
|
155 | + * @param string $value path to the picture |
|
156 | + * @param string $page anchor to page number (or -1 if anchor-type is aschar) |
|
157 | + * @param string $width width of picture (keep original if null) |
|
158 | + * @param string $height height of picture (keep original if null) |
|
159 | + * @param string $offsetX offset by horizontal (not used if $page = -1) |
|
160 | + * @param string $offsetY offset by vertical (not used if $page = -1) |
|
161 | + * @throws OdfException |
|
162 | + * @return Segment |
|
163 | + */ |
|
164 | + public function setImage($key, $value, $page=null, $width=null, $height=null, $offsetX=null, $offsetY=null) |
|
165 | + { |
|
166 | + $filename = strtok(strrchr($value, '/'), '/.'); |
|
167 | + $file = substr(strrchr($value, '/'), 1); |
|
168 | + $size = @getimagesize($value); |
|
169 | + if ($size === false) { |
|
170 | + throw new OdfException("Invalid image"); |
|
171 | + } |
|
172 | + if (!$width && !$height) { |
|
173 | + list ($width, $height) = $size; |
|
174 | + $width *= Odf::PIXEL_TO_CM; |
|
175 | + $height *= Odf::PIXEL_TO_CM; |
|
176 | + } |
|
177 | + $anchor = $page == -1 ? 'text:anchor-type="aschar"' : "text:anchor-type=\"page\" text:anchor-page-number=\"{$page}\" svg:x=\"{$offsetX}cm\" svg:y=\"{$offsetY}cm\""; |
|
178 | + $xml = <<<IMG |
|
179 | 179 | <draw:frame draw:style-name="fr1" draw:name="$filename" {$anchor} svg:width="{$width}cm" svg:height="{$height}cm" draw:z-index="3"><draw:image xlink:href="Pictures/$file" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame> |
180 | 180 | IMG; |
181 | - $this->images[$value] = $file; |
|
182 | - $this->manif_vars[] = $file; //save image name as array element |
|
183 | - $this->setVars($key, $xml, false); |
|
184 | - return $this; |
|
185 | - } |
|
186 | - /** |
|
187 | - * Shortcut to retrieve a child |
|
188 | - * |
|
189 | - * @param string $prop |
|
190 | - * @return Segment |
|
191 | - * @throws SegmentException |
|
192 | - */ |
|
193 | - public function __get($prop) |
|
194 | - { |
|
195 | - if (array_key_exists($prop, $this->children)) { |
|
196 | - return $this->children[$prop]; |
|
197 | - } else { |
|
198 | - throw new SegmentException('child ' . $prop . ' does not exist'); |
|
199 | - } |
|
200 | - } |
|
201 | - /** |
|
202 | - * Proxy for setVars |
|
203 | - * |
|
204 | - * @param string $meth |
|
205 | - * @param array $args |
|
206 | - * @return Segment |
|
207 | - */ |
|
208 | - public function __call($meth, $args) |
|
209 | - { |
|
210 | - try { |
|
211 | - array_unshift($args,$meth); |
|
212 | - return call_user_func_array(array($this,'setVars'),$args); |
|
213 | - } catch (SegmentException $e) { |
|
214 | - throw new SegmentException("method $meth nor var $meth exist"); |
|
215 | - } |
|
216 | - } |
|
217 | - /** |
|
218 | - * Returns the parsed XML |
|
219 | - * |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function getXmlParsed() |
|
223 | - { |
|
224 | - return $this->xmlParsed; |
|
225 | - } |
|
181 | + $this->images[$value] = $file; |
|
182 | + $this->manif_vars[] = $file; //save image name as array element |
|
183 | + $this->setVars($key, $xml, false); |
|
184 | + return $this; |
|
185 | + } |
|
186 | + /** |
|
187 | + * Shortcut to retrieve a child |
|
188 | + * |
|
189 | + * @param string $prop |
|
190 | + * @return Segment |
|
191 | + * @throws SegmentException |
|
192 | + */ |
|
193 | + public function __get($prop) |
|
194 | + { |
|
195 | + if (array_key_exists($prop, $this->children)) { |
|
196 | + return $this->children[$prop]; |
|
197 | + } else { |
|
198 | + throw new SegmentException('child ' . $prop . ' does not exist'); |
|
199 | + } |
|
200 | + } |
|
201 | + /** |
|
202 | + * Proxy for setVars |
|
203 | + * |
|
204 | + * @param string $meth |
|
205 | + * @param array $args |
|
206 | + * @return Segment |
|
207 | + */ |
|
208 | + public function __call($meth, $args) |
|
209 | + { |
|
210 | + try { |
|
211 | + array_unshift($args,$meth); |
|
212 | + return call_user_func_array(array($this,'setVars'),$args); |
|
213 | + } catch (SegmentException $e) { |
|
214 | + throw new SegmentException("method $meth nor var $meth exist"); |
|
215 | + } |
|
216 | + } |
|
217 | + /** |
|
218 | + * Returns the parsed XML |
|
219 | + * |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function getXmlParsed() |
|
223 | + { |
|
224 | + return $this->xmlParsed; |
|
225 | + } |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | ?> |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | require 'SegmentIterator.php'; |
3 | 3 | class SegmentException extends Exception |
4 | 4 | {} |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct($name, $xml, $odf) |
38 | 38 | { |
39 | - $this->name = (string) $name; |
|
40 | - $this->xml = (string) $xml; |
|
39 | + $this->name = (string)$name; |
|
40 | + $this->xml = (string)$xml; |
|
41 | 41 | $this->odf = $odf; |
42 | 42 | $zipHandler = $this->odf->getConfig('ZIP_PROXY'); |
43 | 43 | $this->file = new $zipHandler(); |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | $this->xmlParsed .= str_replace(array_keys($this->vars), array_values($this->vars), $this->xml); |
91 | 91 | if ($this->hasChildren()) { |
92 | 92 | foreach ($this->children as $child) { |
93 | - $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed=="")?$child->merge():$child->xmlParsed, $this->xmlParsed); |
|
93 | + $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed == "") ? $child->merge() : $child->xmlParsed, $this->xmlParsed); |
|
94 | 94 | $child->xmlParsed = ''; |
95 | 95 | //Store all image names used in child segments in current segment array |
96 | 96 | foreach ($child->manif_vars as $file) |
97 | 97 | $this->manif_vars[] = $file; |
98 | - $child->manif_vars=array(); |
|
98 | + $child->manif_vars = array(); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | $reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/smU"; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @throws OdfException |
162 | 162 | * @return Segment |
163 | 163 | */ |
164 | - public function setImage($key, $value, $page=null, $width=null, $height=null, $offsetX=null, $offsetY=null) |
|
164 | + public function setImage($key, $value, $page = null, $width = null, $height = null, $offsetX = null, $offsetY = null) |
|
165 | 165 | { |
166 | 166 | $filename = strtok(strrchr($value, '/'), '/.'); |
167 | 167 | $file = substr(strrchr($value, '/'), 1); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | <draw:frame draw:style-name="fr1" draw:name="$filename" {$anchor} svg:width="{$width}cm" svg:height="{$height}cm" draw:z-index="3"><draw:image xlink:href="Pictures/$file" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame> |
180 | 180 | IMG; |
181 | 181 | $this->images[$value] = $file; |
182 | - $this->manif_vars[] = $file; //save image name as array element |
|
182 | + $this->manif_vars[] = $file; //save image name as array element |
|
183 | 183 | $this->setVars($key, $xml, false); |
184 | 184 | return $this; |
185 | 185 | } |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | public function __call($meth, $args) |
209 | 209 | { |
210 | 210 | try { |
211 | - array_unshift($args,$meth); |
|
212 | - return call_user_func_array(array($this,'setVars'),$args); |
|
211 | + array_unshift($args, $meth); |
|
212 | + return call_user_func_array(array($this, 'setVars'), $args); |
|
213 | 213 | } catch (SegmentException $e) { |
214 | 214 | throw new SegmentException("method $meth nor var $meth exist"); |
215 | 215 | } |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | require 'SegmentIterator.php'; |
3 | 5 | class SegmentException extends Exception |
4 | 6 | {} |
@@ -93,8 +95,9 @@ discard block |
||
93 | 95 | $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed=="")?$child->merge():$child->xmlParsed, $this->xmlParsed); |
94 | 96 | $child->xmlParsed = ''; |
95 | 97 | //Store all image names used in child segments in current segment array |
96 | - foreach ($child->manif_vars as $file) |
|
97 | - $this->manif_vars[] = $file; |
|
98 | + foreach ($child->manif_vars as $file) { |
|
99 | + $this->manif_vars[] = $file; |
|
100 | + } |
|
98 | 101 | $child->manif_vars=array(); |
99 | 102 | } |
100 | 103 | } |
@@ -21,11 +21,11 @@ |
||
21 | 21 | { |
22 | 22 | protected $zipArchive; |
23 | 23 | protected $filename; |
24 | - /** |
|
25 | - * Class constructor |
|
26 | - * |
|
27 | - * @throws PhpZipProxyException |
|
28 | - */ |
|
24 | + /** |
|
25 | + * Class constructor |
|
26 | + * |
|
27 | + * @throws PhpZipProxyException |
|
28 | + */ |
|
29 | 29 | public function __construct() |
30 | 30 | { |
31 | 31 | if (! class_exists('ZipArchive')) { |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | require_once 'ZipInterface.php'; |
3 | 3 | class PhpZipProxyException extends Exception |
4 | 4 | { } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function __construct() |
30 | 30 | { |
31 | - if (! class_exists('ZipArchive')) { |
|
31 | + if (!class_exists('ZipArchive')) { |
|
32 | 32 | throw new PhpZipProxyException('Zip extension not loaded - check your php settings, PHP5.2 minimum with zip extension |
33 | 33 | is required for using PhpZipProxy'); ; |
34 | 34 | } |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Fichier de définition du modèle des taxinomies / File for term model definition |
4 | 6 | * |
@@ -20,115 +20,115 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class Odf |
22 | 22 | { |
23 | - protected $config = array( |
|
24 | - 'ZIP_PROXY' => 'PclZipProxy', |
|
25 | - 'DELIMITER_LEFT' => '{', |
|
26 | - 'DELIMITER_RIGHT' => '}', |
|
23 | + protected $config = array( |
|
24 | + 'ZIP_PROXY' => 'PclZipProxy', |
|
25 | + 'DELIMITER_LEFT' => '{', |
|
26 | + 'DELIMITER_RIGHT' => '}', |
|
27 | 27 | 'PATH_TO_TMP' => null |
28 | 28 | ); |
29 | - protected $file; |
|
30 | - protected $contentXml; |
|
31 | - protected $manifestXml; // To store content of manifest.xml file |
|
32 | - protected $tmpfile; |
|
33 | - protected $images = array(); |
|
34 | - protected $vars = array(); |
|
35 | - protected $manif_vars = array(); // array to store image names |
|
36 | - protected $segments = array(); |
|
37 | - const PIXEL_TO_CM = 0.026458333; |
|
38 | - /** |
|
39 | - * Class constructor |
|
40 | - * |
|
41 | - * @param string $filename the name of the odt file |
|
42 | - * @throws OdfException |
|
43 | - */ |
|
44 | - public function __construct($filename, $config = array()) |
|
45 | - { |
|
46 | - if (! is_array($config)) { |
|
47 | - throw new OdfException('Configuration data must be provided as array'); |
|
48 | - } |
|
49 | - foreach ($config as $configKey => $configValue) { |
|
50 | - if (array_key_exists($configKey, $this->config)) { |
|
51 | - $this->config[$configKey] = $configValue; |
|
52 | - } |
|
53 | - } |
|
54 | - if (! class_exists($this->config['ZIP_PROXY'])) { |
|
55 | - throw new OdfException($this->config['ZIP_PROXY'] . ' class not found - check your php settings'); |
|
56 | - } |
|
57 | - $zipHandler = $this->config['ZIP_PROXY']; |
|
58 | - $this->file = new $zipHandler(); |
|
59 | - if ($this->file->open($filename) !== true) { |
|
60 | - throw new OdfException("Error while Opening the file '$filename' - Check your odt file"); |
|
61 | - } |
|
62 | - if (($this->contentXml = $this->file->getFromName('content.xml')) === false) { |
|
63 | - throw new OdfException("Nothing to parse - check that the content.xml file is correctly formed"); |
|
64 | - } |
|
65 | - if (($this->manifestXml = $this->file->getFromName('META-INF/manifest.xml')) === false) { |
|
66 | - throw new OdfException("Something is wrong with META-INF/manifest.xm in source file '$filename'"); |
|
67 | - } |
|
29 | + protected $file; |
|
30 | + protected $contentXml; |
|
31 | + protected $manifestXml; // To store content of manifest.xml file |
|
32 | + protected $tmpfile; |
|
33 | + protected $images = array(); |
|
34 | + protected $vars = array(); |
|
35 | + protected $manif_vars = array(); // array to store image names |
|
36 | + protected $segments = array(); |
|
37 | + const PIXEL_TO_CM = 0.026458333; |
|
38 | + /** |
|
39 | + * Class constructor |
|
40 | + * |
|
41 | + * @param string $filename the name of the odt file |
|
42 | + * @throws OdfException |
|
43 | + */ |
|
44 | + public function __construct($filename, $config = array()) |
|
45 | + { |
|
46 | + if (! is_array($config)) { |
|
47 | + throw new OdfException('Configuration data must be provided as array'); |
|
48 | + } |
|
49 | + foreach ($config as $configKey => $configValue) { |
|
50 | + if (array_key_exists($configKey, $this->config)) { |
|
51 | + $this->config[$configKey] = $configValue; |
|
52 | + } |
|
53 | + } |
|
54 | + if (! class_exists($this->config['ZIP_PROXY'])) { |
|
55 | + throw new OdfException($this->config['ZIP_PROXY'] . ' class not found - check your php settings'); |
|
56 | + } |
|
57 | + $zipHandler = $this->config['ZIP_PROXY']; |
|
58 | + $this->file = new $zipHandler(); |
|
59 | + if ($this->file->open($filename) !== true) { |
|
60 | + throw new OdfException("Error while Opening the file '$filename' - Check your odt file"); |
|
61 | + } |
|
62 | + if (($this->contentXml = $this->file->getFromName('content.xml')) === false) { |
|
63 | + throw new OdfException("Nothing to parse - check that the content.xml file is correctly formed"); |
|
64 | + } |
|
65 | + if (($this->manifestXml = $this->file->getFromName('META-INF/manifest.xml')) === false) { |
|
66 | + throw new OdfException("Something is wrong with META-INF/manifest.xm in source file '$filename'"); |
|
67 | + } |
|
68 | 68 | |
69 | - $this->file->close(); |
|
69 | + $this->file->close(); |
|
70 | 70 | |
71 | - $tmp = tempnam($this->config['PATH_TO_TMP'], md5(uniqid())); |
|
72 | - copy($filename, $tmp); |
|
73 | - $this->tmpfile = $tmp; |
|
74 | - $this->_moveRowSegments(); |
|
75 | - } |
|
76 | - /** |
|
77 | - * Assing a template variable |
|
78 | - * |
|
79 | - * @param string $key name of the variable within the template |
|
80 | - * @param string $value replacement value |
|
81 | - * @param bool $encode if true, special XML characters are encoded |
|
82 | - * @throws OdfException |
|
83 | - * @return odf |
|
84 | - */ |
|
85 | - public function setVars($key, $value, $encode = true, $charset = 'ISO-8859') |
|
86 | - { |
|
87 | - if (strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']) === false) { |
|
88 | - throw new OdfException("var $key not found in the document"); |
|
89 | - } |
|
90 | - $value = $encode ? htmlspecialchars($value) : $value; |
|
91 | - $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; |
|
92 | - $this->vars[$this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']] = str_replace("\n", "<text:line-break/>", $value); |
|
93 | - return $this; |
|
94 | - } |
|
95 | - /** |
|
96 | - * Assign a template variable as a picture |
|
97 | - * |
|
98 | - * @param string $key name of the variable within the template |
|
99 | - * @param string $value path to the picture |
|
100 | - * @throws OdfException |
|
101 | - * @return odf |
|
102 | - */ |
|
103 | - public function setImage($key, $value) |
|
104 | - { |
|
105 | - $filename = strtok(strrchr($value, '/'), '/.'); |
|
106 | - $file = substr(strrchr($value, '/'), 1); |
|
107 | - $size = @getimagesize($value); |
|
108 | - if ($size === false) { |
|
109 | - throw new OdfException("Invalid image"); |
|
110 | - } |
|
111 | - list ($width, $height) = $size; |
|
112 | - $width *= self::PIXEL_TO_CM; |
|
113 | - $height *= self::PIXEL_TO_CM; |
|
114 | - $xml = <<<IMG |
|
71 | + $tmp = tempnam($this->config['PATH_TO_TMP'], md5(uniqid())); |
|
72 | + copy($filename, $tmp); |
|
73 | + $this->tmpfile = $tmp; |
|
74 | + $this->_moveRowSegments(); |
|
75 | + } |
|
76 | + /** |
|
77 | + * Assing a template variable |
|
78 | + * |
|
79 | + * @param string $key name of the variable within the template |
|
80 | + * @param string $value replacement value |
|
81 | + * @param bool $encode if true, special XML characters are encoded |
|
82 | + * @throws OdfException |
|
83 | + * @return odf |
|
84 | + */ |
|
85 | + public function setVars($key, $value, $encode = true, $charset = 'ISO-8859') |
|
86 | + { |
|
87 | + if (strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']) === false) { |
|
88 | + throw new OdfException("var $key not found in the document"); |
|
89 | + } |
|
90 | + $value = $encode ? htmlspecialchars($value) : $value; |
|
91 | + $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; |
|
92 | + $this->vars[$this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']] = str_replace("\n", "<text:line-break/>", $value); |
|
93 | + return $this; |
|
94 | + } |
|
95 | + /** |
|
96 | + * Assign a template variable as a picture |
|
97 | + * |
|
98 | + * @param string $key name of the variable within the template |
|
99 | + * @param string $value path to the picture |
|
100 | + * @throws OdfException |
|
101 | + * @return odf |
|
102 | + */ |
|
103 | + public function setImage($key, $value) |
|
104 | + { |
|
105 | + $filename = strtok(strrchr($value, '/'), '/.'); |
|
106 | + $file = substr(strrchr($value, '/'), 1); |
|
107 | + $size = @getimagesize($value); |
|
108 | + if ($size === false) { |
|
109 | + throw new OdfException("Invalid image"); |
|
110 | + } |
|
111 | + list ($width, $height) = $size; |
|
112 | + $width *= self::PIXEL_TO_CM; |
|
113 | + $height *= self::PIXEL_TO_CM; |
|
114 | + $xml = <<<IMG |
|
115 | 115 | <draw:frame draw:style-name="fr1" draw:name="$filename" text:anchor-type="char" svg:width="{$width}cm" svg:height="{$height}cm" draw:z-index="3"><draw:image xlink:href="Pictures/$file" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame> |
116 | 116 | IMG; |
117 | - $this->images[$value] = $file; |
|
118 | - $this->manif_vars[] = $file; //save image name as array element |
|
119 | - $this->setVars($key, $xml, false); |
|
120 | - return $this; |
|
121 | - } |
|
122 | - /** |
|
123 | - * Move segment tags for lines of tables |
|
124 | - * Called automatically within the constructor |
|
125 | - * |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - private function _moveRowSegments() |
|
129 | - { |
|
130 | - // Search all possible rows in the document |
|
131 | - $reg1 = "#<table:table-row[^>]*>(.*)</table:table-row>#smU"; |
|
117 | + $this->images[$value] = $file; |
|
118 | + $this->manif_vars[] = $file; //save image name as array element |
|
119 | + $this->setVars($key, $xml, false); |
|
120 | + return $this; |
|
121 | + } |
|
122 | + /** |
|
123 | + * Move segment tags for lines of tables |
|
124 | + * Called automatically within the constructor |
|
125 | + * |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + private function _moveRowSegments() |
|
129 | + { |
|
130 | + // Search all possible rows in the document |
|
131 | + $reg1 = "#<table:table-row[^>]*>(.*)</table:table-row>#smU"; |
|
132 | 132 | preg_match_all($reg1, $this->contentXml, $matches); |
133 | 133 | for ($i = 0, $size = count($matches[0]); $i < $size; $i++) { |
134 | 134 | // Check if the current row contains a segment row.* |
@@ -146,189 +146,189 @@ discard block |
||
146 | 146 | $this->contentXml = str_replace($matches[0][$i], $replacedXML, $this->contentXml); |
147 | 147 | } |
148 | 148 | } |
149 | - } |
|
150 | - /** |
|
151 | - * Merge template variables |
|
152 | - * Called automatically for a save |
|
153 | - * |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - private function _parse() |
|
157 | - { |
|
158 | - $this->contentXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->contentXml); |
|
159 | - } |
|
160 | - /** |
|
161 | - * Add the merged segment to the document |
|
162 | - * |
|
163 | - * @param Segment $segment |
|
164 | - * @throws OdfException |
|
165 | - * @return odf |
|
166 | - */ |
|
167 | - public function mergeSegment(Segment $segment) |
|
168 | - { |
|
169 | - if (! array_key_exists($segment->getName(), $this->segments)) { |
|
170 | - throw new OdfException($segment->getName() . 'cannot be parsed, has it been set yet ?'); |
|
171 | - } |
|
172 | - $string = $segment->getName(); |
|
149 | + } |
|
150 | + /** |
|
151 | + * Merge template variables |
|
152 | + * Called automatically for a save |
|
153 | + * |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + private function _parse() |
|
157 | + { |
|
158 | + $this->contentXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->contentXml); |
|
159 | + } |
|
160 | + /** |
|
161 | + * Add the merged segment to the document |
|
162 | + * |
|
163 | + * @param Segment $segment |
|
164 | + * @throws OdfException |
|
165 | + * @return odf |
|
166 | + */ |
|
167 | + public function mergeSegment(Segment $segment) |
|
168 | + { |
|
169 | + if (! array_key_exists($segment->getName(), $this->segments)) { |
|
170 | + throw new OdfException($segment->getName() . 'cannot be parsed, has it been set yet ?'); |
|
171 | + } |
|
172 | + $string = $segment->getName(); |
|
173 | 173 | // $reg = '@<text:p[^>]*>\[!--\sBEGIN\s' . $string . '\s--\](.*)\[!--.+END\s' . $string . '\s--\]<\/text:p>@smU'; |
174 | 174 | $reg = '@\[!--\sBEGIN\s' . $string . '\s--\](.*)\[!--.+END\s' . $string . '\s--\]@smU'; |
175 | - $this->contentXml = preg_replace($reg, $segment->getXmlParsed(), $this->contentXml); |
|
176 | - return $this; |
|
177 | - } |
|
178 | - /** |
|
179 | - * Display all the current template variables |
|
180 | - * |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public function printVars() |
|
184 | - { |
|
185 | - return print_r('<pre>' . print_r($this->vars, true) . '</pre>', true); |
|
186 | - } |
|
187 | - /** |
|
188 | - * Display the XML content of the file from odt document |
|
189 | - * as it is at the moment |
|
190 | - * |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function __toString() |
|
194 | - { |
|
195 | - return $this->contentXml; |
|
196 | - } |
|
197 | - /** |
|
198 | - * Display loop segments declared with setSegment() |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function printDeclaredSegments() |
|
203 | - { |
|
204 | - return '<pre>' . print_r(implode(' ', array_keys($this->segments)), true) . '</pre>'; |
|
205 | - } |
|
206 | - /** |
|
207 | - * Declare a segment in order to use it in a loop |
|
208 | - * |
|
209 | - * @param string $segment |
|
210 | - * @throws OdfException |
|
211 | - * @return Segment |
|
212 | - */ |
|
213 | - public function setSegment($segment) |
|
214 | - { |
|
215 | - if (array_key_exists($segment, $this->segments)) { |
|
216 | - return $this->segments[$segment]; |
|
217 | - } |
|
218 | - // $reg = "#\[!--\sBEGIN\s$segment\s--\]<\/text:p>(.*)<text:p\s.*>\[!--\sEND\s$segment\s--\]#sm"; |
|
219 | - $reg = "#\[!--\sBEGIN\s$segment\s--\](.*)\[!--\sEND\s$segment\s--\]#sm"; |
|
220 | - if (preg_match($reg, html_entity_decode($this->contentXml), $m) == 0) { |
|
221 | - throw new OdfException("'$segment' segment not found in the document"); |
|
222 | - } |
|
223 | - $this->segments[$segment] = new Segment($segment, $m[1], $this); |
|
224 | - return $this->segments[$segment]; |
|
225 | - } |
|
226 | - /** |
|
227 | - * Save the odt file on the disk |
|
228 | - * |
|
229 | - * @param string $file name of the desired file |
|
230 | - * @throws OdfException |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function saveToDisk($file = null) |
|
234 | - { |
|
235 | - if ($file !== null && is_string($file)) { |
|
236 | - if (file_exists($file) && !(is_file($file) && is_writable($file))) { |
|
237 | - throw new OdfException('Permission denied : can\'t create ' . $file); |
|
238 | - } |
|
239 | - $this->_save(); |
|
240 | - copy($this->tmpfile, $file); |
|
241 | - } else { |
|
242 | - $this->_save(); |
|
243 | - } |
|
244 | - } |
|
245 | - /** |
|
246 | - * Internal save |
|
247 | - * |
|
248 | - * @throws OdfException |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - private function _save() |
|
252 | - { |
|
253 | - $this->file->open($this->tmpfile); |
|
254 | - $this->_parse(); |
|
255 | - if (! $this->file->addFromString('content.xml', $this->contentXml) ) { |
|
256 | - throw new OdfException('Error during file export addFromString'); |
|
257 | - } |
|
175 | + $this->contentXml = preg_replace($reg, $segment->getXmlParsed(), $this->contentXml); |
|
176 | + return $this; |
|
177 | + } |
|
178 | + /** |
|
179 | + * Display all the current template variables |
|
180 | + * |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public function printVars() |
|
184 | + { |
|
185 | + return print_r('<pre>' . print_r($this->vars, true) . '</pre>', true); |
|
186 | + } |
|
187 | + /** |
|
188 | + * Display the XML content of the file from odt document |
|
189 | + * as it is at the moment |
|
190 | + * |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function __toString() |
|
194 | + { |
|
195 | + return $this->contentXml; |
|
196 | + } |
|
197 | + /** |
|
198 | + * Display loop segments declared with setSegment() |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function printDeclaredSegments() |
|
203 | + { |
|
204 | + return '<pre>' . print_r(implode(' ', array_keys($this->segments)), true) . '</pre>'; |
|
205 | + } |
|
206 | + /** |
|
207 | + * Declare a segment in order to use it in a loop |
|
208 | + * |
|
209 | + * @param string $segment |
|
210 | + * @throws OdfException |
|
211 | + * @return Segment |
|
212 | + */ |
|
213 | + public function setSegment($segment) |
|
214 | + { |
|
215 | + if (array_key_exists($segment, $this->segments)) { |
|
216 | + return $this->segments[$segment]; |
|
217 | + } |
|
218 | + // $reg = "#\[!--\sBEGIN\s$segment\s--\]<\/text:p>(.*)<text:p\s.*>\[!--\sEND\s$segment\s--\]#sm"; |
|
219 | + $reg = "#\[!--\sBEGIN\s$segment\s--\](.*)\[!--\sEND\s$segment\s--\]#sm"; |
|
220 | + if (preg_match($reg, html_entity_decode($this->contentXml), $m) == 0) { |
|
221 | + throw new OdfException("'$segment' segment not found in the document"); |
|
222 | + } |
|
223 | + $this->segments[$segment] = new Segment($segment, $m[1], $this); |
|
224 | + return $this->segments[$segment]; |
|
225 | + } |
|
226 | + /** |
|
227 | + * Save the odt file on the disk |
|
228 | + * |
|
229 | + * @param string $file name of the desired file |
|
230 | + * @throws OdfException |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function saveToDisk($file = null) |
|
234 | + { |
|
235 | + if ($file !== null && is_string($file)) { |
|
236 | + if (file_exists($file) && !(is_file($file) && is_writable($file))) { |
|
237 | + throw new OdfException('Permission denied : can\'t create ' . $file); |
|
238 | + } |
|
239 | + $this->_save(); |
|
240 | + copy($this->tmpfile, $file); |
|
241 | + } else { |
|
242 | + $this->_save(); |
|
243 | + } |
|
244 | + } |
|
245 | + /** |
|
246 | + * Internal save |
|
247 | + * |
|
248 | + * @throws OdfException |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + private function _save() |
|
252 | + { |
|
253 | + $this->file->open($this->tmpfile); |
|
254 | + $this->_parse(); |
|
255 | + if (! $this->file->addFromString('content.xml', $this->contentXml) ) { |
|
256 | + throw new OdfException('Error during file export addFromString'); |
|
257 | + } |
|
258 | 258 | |
259 | - $lastpos=strrpos($this->manifestXml, "\n", -15); //find second last newline in the manifest.xml file |
|
260 | - $manifdata = ""; |
|
259 | + $lastpos=strrpos($this->manifestXml, "\n", -15); //find second last newline in the manifest.xml file |
|
260 | + $manifdata = ""; |
|
261 | 261 | |
262 | - //Enter all images description in $manifdata variable |
|
262 | + //Enter all images description in $manifdata variable |
|
263 | 263 | |
264 | - foreach ($this->manif_vars as $val) |
|
265 | - { |
|
266 | - $ext = substr(strrchr($val, '.'), 1); |
|
267 | - $manifdata = $manifdata.'<manifest:file-entry manifest:media-type="image/'.$ext.'" manifest:full-path="Pictures/'.$val.'"/>'."\n"; |
|
268 | - } |
|
269 | - //Place content of $manifdata variable in manifest.xml file at appropriate place |
|
270 | - $this->manifestXml = substr_replace($this->manifestXml, "\n".$manifdata, $lastpos+1, 0); |
|
264 | + foreach ($this->manif_vars as $val) |
|
265 | + { |
|
266 | + $ext = substr(strrchr($val, '.'), 1); |
|
267 | + $manifdata = $manifdata.'<manifest:file-entry manifest:media-type="image/'.$ext.'" manifest:full-path="Pictures/'.$val.'"/>'."\n"; |
|
268 | + } |
|
269 | + //Place content of $manifdata variable in manifest.xml file at appropriate place |
|
270 | + $this->manifestXml = substr_replace($this->manifestXml, "\n".$manifdata, $lastpos+1, 0); |
|
271 | 271 | |
272 | - if (! $this->file->addFromString('META-INF/manifest.xml', $this->manifestXml)) { |
|
273 | - throw new OdfException('Error during manifest file export'); |
|
274 | - } |
|
275 | - foreach ($this->images as $imageKey => $imageValue) { |
|
276 | - $this->file->addFile($imageKey, 'Pictures/' . $imageValue); |
|
277 | - } |
|
278 | - $this->file->close(); // seems to bug on windows CLI sometimes |
|
279 | - } |
|
280 | - /** |
|
281 | - * Export the file as attached file by HTTP |
|
282 | - * |
|
283 | - * @param string $name (optionnal) |
|
284 | - * @throws OdfException |
|
285 | - * @return void |
|
286 | - */ |
|
287 | - public function exportAsAttachedFile($name="") |
|
288 | - { |
|
289 | - $this->_save(); |
|
290 | - if (headers_sent($filename, $linenum)) { |
|
291 | - throw new OdfException("headers already sent ($filename at $linenum)"); |
|
292 | - } |
|
272 | + if (! $this->file->addFromString('META-INF/manifest.xml', $this->manifestXml)) { |
|
273 | + throw new OdfException('Error during manifest file export'); |
|
274 | + } |
|
275 | + foreach ($this->images as $imageKey => $imageValue) { |
|
276 | + $this->file->addFile($imageKey, 'Pictures/' . $imageValue); |
|
277 | + } |
|
278 | + $this->file->close(); // seems to bug on windows CLI sometimes |
|
279 | + } |
|
280 | + /** |
|
281 | + * Export the file as attached file by HTTP |
|
282 | + * |
|
283 | + * @param string $name (optionnal) |
|
284 | + * @throws OdfException |
|
285 | + * @return void |
|
286 | + */ |
|
287 | + public function exportAsAttachedFile($name="") |
|
288 | + { |
|
289 | + $this->_save(); |
|
290 | + if (headers_sent($filename, $linenum)) { |
|
291 | + throw new OdfException("headers already sent ($filename at $linenum)"); |
|
292 | + } |
|
293 | 293 | |
294 | - if( $name == "" ) |
|
295 | - { |
|
296 | - $name = md5(uniqid()) . ".odt"; |
|
297 | - } |
|
294 | + if( $name == "" ) |
|
295 | + { |
|
296 | + $name = md5(uniqid()) . ".odt"; |
|
297 | + } |
|
298 | 298 | |
299 | - header('Content-type: application/vnd.oasis.opendocument.text'); |
|
300 | - header('Content-Disposition: attachment; filename="'.$name.'"'); |
|
301 | - readfile($this->tmpfile); |
|
302 | - } |
|
303 | - /** |
|
304 | - * Returns a variable of configuration |
|
305 | - * |
|
306 | - * @return string The requested variable of configuration |
|
307 | - */ |
|
308 | - public function getConfig($configKey) |
|
309 | - { |
|
310 | - if (array_key_exists($configKey, $this->config)) { |
|
311 | - return $this->config[$configKey]; |
|
312 | - } |
|
313 | - return false; |
|
314 | - } |
|
315 | - /** |
|
316 | - * Returns the temporary working file |
|
317 | - * |
|
318 | - * @return string le chemin vers le fichier temporaire de travail |
|
319 | - */ |
|
320 | - public function getTmpfile() |
|
321 | - { |
|
322 | - return $this->tmpfile; |
|
323 | - } |
|
324 | - /** |
|
325 | - * Delete the temporary file when the object is destroyed |
|
326 | - */ |
|
327 | - public function __destruct() { |
|
328 | - if (file_exists($this->tmpfile)) { |
|
329 | - unlink($this->tmpfile); |
|
330 | - } |
|
331 | - } |
|
299 | + header('Content-type: application/vnd.oasis.opendocument.text'); |
|
300 | + header('Content-Disposition: attachment; filename="'.$name.'"'); |
|
301 | + readfile($this->tmpfile); |
|
302 | + } |
|
303 | + /** |
|
304 | + * Returns a variable of configuration |
|
305 | + * |
|
306 | + * @return string The requested variable of configuration |
|
307 | + */ |
|
308 | + public function getConfig($configKey) |
|
309 | + { |
|
310 | + if (array_key_exists($configKey, $this->config)) { |
|
311 | + return $this->config[$configKey]; |
|
312 | + } |
|
313 | + return false; |
|
314 | + } |
|
315 | + /** |
|
316 | + * Returns the temporary working file |
|
317 | + * |
|
318 | + * @return string le chemin vers le fichier temporaire de travail |
|
319 | + */ |
|
320 | + public function getTmpfile() |
|
321 | + { |
|
322 | + return $this->tmpfile; |
|
323 | + } |
|
324 | + /** |
|
325 | + * Delete the temporary file when the object is destroyed |
|
326 | + */ |
|
327 | + public function __destruct() { |
|
328 | + if (file_exists($this->tmpfile)) { |
|
329 | + unlink($this->tmpfile); |
|
330 | + } |
|
331 | + } |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | ?> |
335 | 335 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | require 'zip/PclZipProxy.php'; |
3 | 3 | require 'zip/PhpZipProxy.php'; |
4 | 4 | require 'Segment.php'; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | ); |
29 | 29 | protected $file; |
30 | 30 | protected $contentXml; |
31 | - protected $manifestXml; // To store content of manifest.xml file |
|
31 | + protected $manifestXml; // To store content of manifest.xml file |
|
32 | 32 | protected $tmpfile; |
33 | 33 | protected $images = array(); |
34 | 34 | protected $vars = array(); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function __construct($filename, $config = array()) |
45 | 45 | { |
46 | - if (! is_array($config)) { |
|
46 | + if (!is_array($config)) { |
|
47 | 47 | throw new OdfException('Configuration data must be provided as array'); |
48 | 48 | } |
49 | 49 | foreach ($config as $configKey => $configValue) { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $this->config[$configKey] = $configValue; |
52 | 52 | } |
53 | 53 | } |
54 | - if (! class_exists($this->config['ZIP_PROXY'])) { |
|
54 | + if (!class_exists($this->config['ZIP_PROXY'])) { |
|
55 | 55 | throw new OdfException($this->config['ZIP_PROXY'] . ' class not found - check your php settings'); |
56 | 56 | } |
57 | 57 | $zipHandler = $this->config['ZIP_PROXY']; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | <draw:frame draw:style-name="fr1" draw:name="$filename" text:anchor-type="char" svg:width="{$width}cm" svg:height="{$height}cm" draw:z-index="3"><draw:image xlink:href="Pictures/$file" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame> |
116 | 116 | IMG; |
117 | 117 | $this->images[$value] = $file; |
118 | - $this->manif_vars[] = $file; //save image name as array element |
|
118 | + $this->manif_vars[] = $file; //save image name as array element |
|
119 | 119 | $this->setVars($key, $xml, false); |
120 | 120 | return $this; |
121 | 121 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function mergeSegment(Segment $segment) |
168 | 168 | { |
169 | - if (! array_key_exists($segment->getName(), $this->segments)) { |
|
169 | + if (!array_key_exists($segment->getName(), $this->segments)) { |
|
170 | 170 | throw new OdfException($segment->getName() . 'cannot be parsed, has it been set yet ?'); |
171 | 171 | } |
172 | 172 | $string = $segment->getName(); |
@@ -252,11 +252,11 @@ discard block |
||
252 | 252 | { |
253 | 253 | $this->file->open($this->tmpfile); |
254 | 254 | $this->_parse(); |
255 | - if (! $this->file->addFromString('content.xml', $this->contentXml) ) { |
|
255 | + if (!$this->file->addFromString('content.xml', $this->contentXml)) { |
|
256 | 256 | throw new OdfException('Error during file export addFromString'); |
257 | 257 | } |
258 | 258 | |
259 | - $lastpos=strrpos($this->manifestXml, "\n", -15); //find second last newline in the manifest.xml file |
|
259 | + $lastpos = strrpos($this->manifestXml, "\n", -15); //find second last newline in the manifest.xml file |
|
260 | 260 | $manifdata = ""; |
261 | 261 | |
262 | 262 | //Enter all images description in $manifdata variable |
@@ -264,12 +264,12 @@ discard block |
||
264 | 264 | foreach ($this->manif_vars as $val) |
265 | 265 | { |
266 | 266 | $ext = substr(strrchr($val, '.'), 1); |
267 | - $manifdata = $manifdata.'<manifest:file-entry manifest:media-type="image/'.$ext.'" manifest:full-path="Pictures/'.$val.'"/>'."\n"; |
|
267 | + $manifdata = $manifdata . '<manifest:file-entry manifest:media-type="image/' . $ext . '" manifest:full-path="Pictures/' . $val . '"/>' . "\n"; |
|
268 | 268 | } |
269 | 269 | //Place content of $manifdata variable in manifest.xml file at appropriate place |
270 | - $this->manifestXml = substr_replace($this->manifestXml, "\n".$manifdata, $lastpos+1, 0); |
|
270 | + $this->manifestXml = substr_replace($this->manifestXml, "\n" . $manifdata, $lastpos + 1, 0); |
|
271 | 271 | |
272 | - if (! $this->file->addFromString('META-INF/manifest.xml', $this->manifestXml)) { |
|
272 | + if (!$this->file->addFromString('META-INF/manifest.xml', $this->manifestXml)) { |
|
273 | 273 | throw new OdfException('Error during manifest file export'); |
274 | 274 | } |
275 | 275 | foreach ($this->images as $imageKey => $imageValue) { |
@@ -284,20 +284,20 @@ discard block |
||
284 | 284 | * @throws OdfException |
285 | 285 | * @return void |
286 | 286 | */ |
287 | - public function exportAsAttachedFile($name="") |
|
287 | + public function exportAsAttachedFile($name = "") |
|
288 | 288 | { |
289 | 289 | $this->_save(); |
290 | 290 | if (headers_sent($filename, $linenum)) { |
291 | 291 | throw new OdfException("headers already sent ($filename at $linenum)"); |
292 | 292 | } |
293 | 293 | |
294 | - if( $name == "" ) |
|
294 | + if ($name == "") |
|
295 | 295 | { |
296 | 296 | $name = md5(uniqid()) . ".odt"; |
297 | 297 | } |
298 | 298 | |
299 | 299 | header('Content-type: application/vnd.oasis.opendocument.text'); |
300 | - header('Content-Disposition: attachment; filename="'.$name.'"'); |
|
300 | + header('Content-Disposition: attachment; filename="' . $name . '"'); |
|
301 | 301 | readfile($this->tmpfile); |
302 | 302 | } |
303 | 303 | /** |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Fichier de définition du modèle des taxinomies / File for term model definition |
4 | 6 | * |
@@ -15,42 +15,42 @@ |
||
15 | 15 | */ |
16 | 16 | class SegmentIterator implements RecursiveIterator |
17 | 17 | { |
18 | - private $ref; |
|
19 | - private $key; |
|
20 | - public function __construct(array $ref) |
|
21 | - { |
|
22 | - $this->ref = $ref; |
|
23 | - $this->key = 0; |
|
24 | - $this->keys = array_keys($this->ref); |
|
25 | - } |
|
26 | - public function hasChildren() |
|
27 | - { |
|
28 | - return $this->valid() && $this->current() instanceof Segment; |
|
29 | - } |
|
30 | - public function current() |
|
31 | - { |
|
32 | - return $this->ref[$this->keys[$this->key]]; |
|
33 | - } |
|
34 | - function getChildren() |
|
35 | - { |
|
36 | - return new self($this->current()->children); |
|
37 | - } |
|
38 | - public function key() |
|
39 | - { |
|
40 | - return $this->key; |
|
41 | - } |
|
42 | - public function valid() |
|
43 | - { |
|
44 | - return array_key_exists($this->key, $this->keys); |
|
45 | - } |
|
46 | - public function rewind() |
|
47 | - { |
|
48 | - $this->key = 0; |
|
49 | - } |
|
50 | - public function next() |
|
51 | - { |
|
52 | - $this->key ++; |
|
53 | - } |
|
18 | + private $ref; |
|
19 | + private $key; |
|
20 | + public function __construct(array $ref) |
|
21 | + { |
|
22 | + $this->ref = $ref; |
|
23 | + $this->key = 0; |
|
24 | + $this->keys = array_keys($this->ref); |
|
25 | + } |
|
26 | + public function hasChildren() |
|
27 | + { |
|
28 | + return $this->valid() && $this->current() instanceof Segment; |
|
29 | + } |
|
30 | + public function current() |
|
31 | + { |
|
32 | + return $this->ref[$this->keys[$this->key]]; |
|
33 | + } |
|
34 | + function getChildren() |
|
35 | + { |
|
36 | + return new self($this->current()->children); |
|
37 | + } |
|
38 | + public function key() |
|
39 | + { |
|
40 | + return $this->key; |
|
41 | + } |
|
42 | + public function valid() |
|
43 | + { |
|
44 | + return array_key_exists($this->key, $this->keys); |
|
45 | + } |
|
46 | + public function rewind() |
|
47 | + { |
|
48 | + $this->key = 0; |
|
49 | + } |
|
50 | + public function next() |
|
51 | + { |
|
52 | + $this->key ++; |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | ?> |
57 | 57 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | /** |
3 | 3 | * Segments iterator |
4 | 4 | * You need PHP 5.2 at least |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | public function next() |
51 | 51 | { |
52 | - $this->key ++; |
|
52 | + $this->key++; |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Fichier de définition du modèle des taxinomies / File for term model definition |
4 | 6 | * |
@@ -1,31 +1,31 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | /** |
3 | 3 | * Author: Christophe DALOZ DE LOS RIOS - Eoxia dev team <[email protected]> |
4 | 4 | */ |
5 | 5 | |
6 | -if ( extension_loaded('gd') ) { |
|
6 | +if (extension_loaded('gd')) { |
|
7 | 7 | global $ajax; |
8 | 8 | |
9 | 9 | $upload_dir = wp_upload_dir(); |
10 | 10 | |
11 | - DEFINE( 'WPS_BARCODE_VERSION', 1.0 ); |
|
12 | - DEFINE( 'WPS_BARCODE_PATH', str_replace( "\\", "/", plugin_dir_path( __FILE__ ) ) ); |
|
13 | - DEFINE( 'WPS_BARCODE_URL', str_replace( str_replace( "\\", "/", ABSPATH), |
|
14 | - site_url() . '/', WPS_BARCODE_PATH ) ); |
|
15 | - DEFINE( 'WPS_BARCODE_JSCRIPTS', plugins_url('/assets/js', __FILE__) ); |
|
16 | - DEFINE( 'WPS_BARCODE_FONTS', WPS_BARCODE_PATH.'assets/fonts' ); |
|
17 | - DEFINE( 'WPS_BARCODE_UPLOAD', $upload_dir[ 'basedir' ] . '/wps_barcode/'); |
|
11 | + DEFINE('WPS_BARCODE_VERSION', 1.0); |
|
12 | + DEFINE('WPS_BARCODE_PATH', str_replace("\\", "/", plugin_dir_path(__FILE__))); |
|
13 | + DEFINE('WPS_BARCODE_URL', str_replace(str_replace("\\", "/", ABSPATH), |
|
14 | + site_url() . '/', WPS_BARCODE_PATH)); |
|
15 | + DEFINE('WPS_BARCODE_JSCRIPTS', plugins_url('/assets/js', __FILE__)); |
|
16 | + DEFINE('WPS_BARCODE_FONTS', WPS_BARCODE_PATH . 'assets/fonts'); |
|
17 | + DEFINE('WPS_BARCODE_UPLOAD', $upload_dir['basedir'] . '/wps_barcode/'); |
|
18 | 18 | |
19 | 19 | /** Load plugin translation */ |
20 | - load_plugin_textdomain( 'wps_barcode', false, dirname( plugin_basename( __FILE__ ) ).'/languages/' ); |
|
20 | + load_plugin_textdomain('wps_barcode', false, dirname(plugin_basename(__FILE__)) . '/languages/'); |
|
21 | 21 | |
22 | 22 | /** Define the templates directories */ |
23 | - DEFINE( 'WPS_BARCODE_TEMPLATES_TPL_DIR', WPS_BARCODE_PATH . '/templates/'); |
|
23 | + DEFINE('WPS_BARCODE_TEMPLATES_TPL_DIR', WPS_BARCODE_PATH . '/templates/'); |
|
24 | 24 | |
25 | - require_once( WPS_BARCODE_PATH . 'controller/wps_barcode.ctr.php' ); |
|
26 | - require_once( WPS_BARCODE_PATH . 'controller/wps_barcode_settings.ctr.php' ); |
|
27 | - require_once( WPS_BARCODE_PATH . 'controller/wps_barcode_metabox.ctr.php' ); |
|
28 | - require_once( WPS_BARCODE_PATH . 'controller/wps_barcode_ajax.ctr.php' ); |
|
25 | + require_once(WPS_BARCODE_PATH . 'controller/wps_barcode.ctr.php'); |
|
26 | + require_once(WPS_BARCODE_PATH . 'controller/wps_barcode_settings.ctr.php'); |
|
27 | + require_once(WPS_BARCODE_PATH . 'controller/wps_barcode_metabox.ctr.php'); |
|
28 | + require_once(WPS_BARCODE_PATH . 'controller/wps_barcode_ajax.ctr.php'); |
|
29 | 29 | |
30 | 30 | new wps_barcode(); |
31 | 31 | new wps_barcode_settings(); |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Fichier de définition du modèle des taxinomies / File for term model definition |
4 | 6 | * |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | class wps_barcode { |
3 | 5 | public function __construct() { |
4 | 6 | global $post_ID; |
@@ -80,22 +82,18 @@ discard block |
||
80 | 82 | $conf['normal_country_code'], |
81 | 83 | 'enterprise' => |
82 | 84 | $conf['normal_enterprise_code'],'ID' => $ref); |
83 | - } |
|
84 | - else if ( $conf['type'] === 'internal' ) { |
|
85 | + } else if ( $conf['type'] === 'internal' ) { |
|
85 | 86 | $pDate = new DateTime($post->post_date); |
86 | 87 | $date = $pDate->format('my'); |
87 | 88 | |
88 | 89 | if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || |
89 | 90 | $post->post_type === WPSHOP_IDENTIFIER_PRODUCT) { |
90 | 91 | $type = $conf['internal_product']; |
91 | - } |
|
92 | - else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
|
92 | + } else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
|
93 | 93 | $type = $conf['internal_invoice_client']; |
94 | - } |
|
95 | - else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
|
94 | + } else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
|
96 | 95 | $type = $conf['internal_coupons']; |
97 | - } |
|
98 | - else { |
|
96 | + } else { |
|
99 | 97 | $type = '000'; |
100 | 98 | } |
101 | 99 | |
@@ -149,15 +147,13 @@ discard block |
||
149 | 147 | $conf['normal_country_code'], |
150 | 148 | 'enterprise' => |
151 | 149 | $conf['normal_enterprise_code'],'ID' => $ref); |
152 | - } |
|
153 | - else if ( $conf['type'] === 'internal' ) { |
|
150 | + } else if ( $conf['type'] === 'internal' ) { |
|
154 | 151 | $pDate = new DateTime($post->post_date); |
155 | 152 | $date = $pDate->format('my'); |
156 | 153 | |
157 | 154 | if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
158 | 155 | $type = $conf['internal_coupons']; |
159 | - } |
|
160 | - else { |
|
156 | + } else { |
|
161 | 157 | $type = '000'; |
162 | 158 | } |
163 | 159 | |
@@ -221,21 +217,17 @@ discard block |
||
221 | 217 | 'enterprise' => $conf['normal_enterprise_code'], |
222 | 218 | 'ID' => $ref, |
223 | 219 | ); |
224 | - } |
|
225 | - else if ( $conf['type'] === 'internal' ) { |
|
220 | + } else if ( $conf['type'] === 'internal' ) { |
|
226 | 221 | $pDate = new DateTime($post->post_date); |
227 | 222 | $date = $pDate->format('my'); |
228 | 223 | |
229 | 224 | if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || $post->post_type === WPSHOP_IDENTIFIER_PRODUCT) { |
230 | 225 | $type = $conf['internal_product']; |
231 | - } |
|
232 | - else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
|
226 | + } else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
|
233 | 227 | $type = $conf['internal_invoice_client']; |
234 | - } |
|
235 | - else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
|
228 | + } else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
|
236 | 229 | $type = $conf['internal_coupons']; |
237 | - } |
|
238 | - else { |
|
230 | + } else { |
|
239 | 231 | $type = '000'; |
240 | 232 | } |
241 | 233 | |
@@ -256,8 +248,7 @@ discard block |
||
256 | 248 | 'message' => sprintf( __('Change barcode: %s replacing %s for %s object ID', 'wps_barcode'), '<b>'.sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ).'</b>', '<b>'.$barcode.'</b>', '<b>'.$post_ID.'</b>') ), 0); |
257 | 249 | |
258 | 250 | $barcode = sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ); |
259 | - } |
|
260 | - else { |
|
251 | + } else { |
|
261 | 252 | wpeologs_ctr::log_datas_in_files( 'wps_barcode', |
262 | 253 | array( |
263 | 254 | 'object_id' => $post_ID, |
@@ -266,8 +257,7 @@ discard block |
||
266 | 257 | |
267 | 258 | $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] = $barcode; |
268 | 259 | } |
269 | - } |
|
270 | - else { |
|
260 | + } else { |
|
271 | 261 | /** On met à jour l'attribut barcode */ |
272 | 262 | $products = new wps_product_ctr(); |
273 | 263 | $products->update_the_attribute_for_product($post_ID, 'varchar', 'barcode', $barcode); |
@@ -308,8 +298,7 @@ discard block |
||
308 | 298 | |
309 | 299 | $id = $array['normal']['ID']; |
310 | 300 | |
311 | - } |
|
312 | - else if ( array_key_exists('internal', $array) ) { |
|
301 | + } else if ( array_key_exists('internal', $array) ) { |
|
313 | 302 | $code.= $array['internal']['type']; |
314 | 303 | $code .= $array['internal']['date']; |
315 | 304 | $code .= $array['internal']['ID']; |
@@ -1,11 +1,11 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wps_barcode { |
3 | 3 | public function __construct() { |
4 | 4 | global $post_ID; |
5 | 5 | |
6 | - add_action( 'admin_init', array($this, 'add_scripts') ); |
|
6 | + add_action('admin_init', array($this, 'add_scripts')); |
|
7 | 7 | $this->install(); |
8 | - add_action( 'save_post', array($this, 'insert_barcode' ) ); |
|
8 | + add_action('save_post', array($this, 'insert_barcode')); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /*Create config informations*/ |
18 | 18 | $conf = get_option('wps_barcode'); |
19 | 19 | |
20 | - if ( empty($conf) ) { |
|
20 | + if (empty($conf)) { |
|
21 | 21 | $conf['generate_barcode'] = false; |
22 | 22 | $conf['type'] = 'internal'; |
23 | 23 | $conf['internal_client'] = '040'; |
@@ -36,20 +36,20 @@ discard block |
||
36 | 36 | add_option('wps_barcode', $conf); |
37 | 37 | |
38 | 38 | /*Adding barcode for existing products*/ |
39 | - $posts = get_posts( array('posts_per_page' => -1 ,'post_type' => 'wpshop_product')); |
|
40 | - foreach ( $posts as $post ) { |
|
39 | + $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpshop_product')); |
|
40 | + foreach ($posts as $post) { |
|
41 | 41 | $meta = get_post_meta($post->ID); |
42 | 42 | |
43 | 43 | $attr = wpshop_attributes_set::getAttributeSetDetails($meta['_wpshop_product_attribute_set_id']); |
44 | 44 | $output_order = array(); |
45 | 45 | |
46 | - if ( count($attr) > 0 ) { |
|
47 | - if (!empty($attr) ) { |
|
48 | - foreach ( $attr as $product_attr_group_id => |
|
46 | + if (count($attr) > 0) { |
|
47 | + if (!empty($attr)) { |
|
48 | + foreach ($attr as $product_attr_group_id => |
|
49 | 49 | $product_attr_group_detail) { |
50 | - foreach ( $product_attr_group_detail['attribut'] |
|
50 | + foreach ($product_attr_group_detail['attribut'] |
|
51 | 51 | as $position => $attribute_def) { |
52 | - if ( !empty($attribute_def->code) |
|
52 | + if (!empty($attribute_def->code) |
|
53 | 53 | AND $attribute_def->code === 'barcode') { |
54 | 54 | |
55 | 55 | $types_with_barcode = array( |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
61 | 61 | ); |
62 | 62 | |
63 | - if ( !empty( $post->post_type ) && |
|
64 | - in_array( $post->post_type, |
|
65 | - $types_with_barcode ) ) { |
|
63 | + if (!empty($post->post_type) && |
|
64 | + in_array($post->post_type, |
|
65 | + $types_with_barcode)) { |
|
66 | 66 | |
67 | 67 | $ref = ''; |
68 | 68 | |
69 | - if ( strlen($post->ID) < 5 ) { |
|
70 | - $length = 5-strlen($post->ID); |
|
69 | + if (strlen($post->ID) < 5) { |
|
70 | + $length = 5 - strlen($post->ID); |
|
71 | 71 | for ($i = 0; $i < $length; $i++) { |
72 | 72 | $ref .= '0'; |
73 | 73 | } |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | |
76 | 76 | $ref .= strval($post->ID); |
77 | 77 | |
78 | - if ( $conf['type'] === 'normal' ) { |
|
78 | + if ($conf['type'] === 'normal') { |
|
79 | 79 | $array['normal'] = array('country' => |
80 | 80 | $conf['normal_country_code'], |
81 | 81 | 'enterprise' => |
82 | - $conf['normal_enterprise_code'],'ID' => $ref); |
|
82 | + $conf['normal_enterprise_code'], 'ID' => $ref); |
|
83 | 83 | } |
84 | - else if ( $conf['type'] === 'internal' ) { |
|
84 | + else if ($conf['type'] === 'internal') { |
|
85 | 85 | $pDate = new DateTime($post->post_date); |
86 | 86 | $date = $pDate->format('my'); |
87 | 87 | |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | 'entity_id' => $post->ID, |
111 | 111 | 'user_id' => $post->post_author, |
112 | 112 | 'value' => $barcode, |
113 | - 'creation_date_value' => date( 'Y-m-d H:i:s' )); |
|
113 | + 'creation_date_value' => date('Y-m-d H:i:s')); |
|
114 | 114 | |
115 | 115 | |
116 | - $query = $wpdb->prepare( " |
|
116 | + $query = $wpdb->prepare(" |
|
117 | 117 | SELECT * |
118 | 118 | FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
119 | 119 | WHERE entity_id = %d |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | SELECT id |
122 | 122 | FROM " . WPSHOP_DBT_ATTRIBUTE . " |
123 | 123 | WHERE code = %s |
124 | - )" , $post->ID, 'barcode' ); |
|
125 | - $result = $wpdb->get_results( $query, ARRAY_A ); |
|
124 | + )" , $post->ID, 'barcode'); |
|
125 | + $result = $wpdb->get_results($query, ARRAY_A); |
|
126 | 126 | |
127 | - if ( empty($result) ) { |
|
128 | - $wpdb->insert($table_prefix. |
|
127 | + if (empty($result)) { |
|
128 | + $wpdb->insert($table_prefix . |
|
129 | 129 | 'wpshop__attribute_value_varchar', $data); |
130 | - } elseif( empty( $result[0]['value'] ) ) { |
|
131 | - $wpdb->update($table_prefix. |
|
132 | - 'wpshop__attribute_value_varchar', $data, array( 'value_id' => $result[0]['value_id'] ) ); |
|
130 | + } elseif (empty($result[0]['value'])) { |
|
131 | + $wpdb->update($table_prefix . |
|
132 | + 'wpshop__attribute_value_varchar', $data, array('value_id' => $result[0]['value_id'])); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
@@ -140,17 +140,17 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | /*Adding barcode for existing coupon*/ |
143 | - $posts = get_posts( array('posts_per_page' => -1 ,'post_type' => 'wpshop_shop_coupon') ); |
|
144 | - foreach ( $posts as $post ) { |
|
143 | + $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpshop_shop_coupon')); |
|
144 | + foreach ($posts as $post) { |
|
145 | 145 | $meta = get_post_meta($post->ID); |
146 | - if ( empty($meta['wpshop_coupon_barcode']) ) { |
|
147 | - if ( $conf['type'] === 'normal' ) { |
|
146 | + if (empty($meta['wpshop_coupon_barcode'])) { |
|
147 | + if ($conf['type'] === 'normal') { |
|
148 | 148 | $array['normal'] = array('country' => |
149 | 149 | $conf['normal_country_code'], |
150 | 150 | 'enterprise' => |
151 | - $conf['normal_enterprise_code'],'ID' => $ref); |
|
151 | + $conf['normal_enterprise_code'], 'ID' => $ref); |
|
152 | 152 | } |
153 | - else if ( $conf['type'] === 'internal' ) { |
|
153 | + else if ($conf['type'] === 'internal') { |
|
154 | 154 | $pDate = new DateTime($post->post_date); |
155 | 155 | $date = $pDate->format('my'); |
156 | 156 | |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | |
164 | 164 | $ref = ''; |
165 | 165 | var_dump($post->ID); |
166 | - if ( strlen($post->ID) < 5 ) { |
|
167 | - $length = 5-strlen($post->ID); |
|
166 | + if (strlen($post->ID) < 5) { |
|
167 | + $length = 5 - strlen($post->ID); |
|
168 | 168 | for ($i = 0; $i < $length; $i++) { |
169 | 169 | $ref .= '0'; |
170 | 170 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * Verifty post identifier and run a barcode generator |
187 | 187 | * @param string $post_ID Ident of post |
188 | 188 | */ |
189 | - public function insert_barcode( $post_ID ) { |
|
189 | + public function insert_barcode($post_ID) { |
|
190 | 190 | global $wpdb; |
191 | 191 | |
192 | 192 | $types_with_barcode = array( |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
198 | 198 | ); |
199 | 199 | |
200 | - $post = get_post( $post_ID ); |
|
200 | + $post = get_post($post_ID); |
|
201 | 201 | |
202 | 202 | /** Si c'est un type qui est dans le tableau $types_with_barcode */ |
203 | - if ( !empty( $post->post_type ) && in_array( $post->post_type, |
|
204 | - $types_with_barcode ) ) { |
|
203 | + if (!empty($post->post_type) && in_array($post->post_type, |
|
204 | + $types_with_barcode)) { |
|
205 | 205 | |
206 | 206 | $conf = get_option('wps_barcode'); |
207 | 207 | $ref = ''; |
208 | 208 | |
209 | - if ( strlen($post_ID) < 5 ) { |
|
210 | - $length = 5-strlen($post_ID); |
|
209 | + if (strlen($post_ID) < 5) { |
|
210 | + $length = 5 - strlen($post_ID); |
|
211 | 211 | for ($i = 0; $i < $length; $i++) { |
212 | 212 | $ref .= '0'; |
213 | 213 | } |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | |
216 | 216 | $ref .= strval($post_ID); |
217 | 217 | |
218 | - if ( $conf['type'] === 'normal' ) { |
|
218 | + if ($conf['type'] === 'normal') { |
|
219 | 219 | $array['normal'] = array( |
220 | 220 | 'country' => $conf['normal_country_code'], |
221 | 221 | 'enterprise' => $conf['normal_enterprise_code'], |
222 | 222 | 'ID' => $ref, |
223 | 223 | ); |
224 | 224 | } |
225 | - else if ( $conf['type'] === 'internal' ) { |
|
225 | + else if ($conf['type'] === 'internal') { |
|
226 | 226 | $pDate = new DateTime($post->post_date); |
227 | 227 | $date = $pDate->format('my'); |
228 | 228 | |
@@ -248,21 +248,21 @@ discard block |
||
248 | 248 | |
249 | 249 | $barcode = $this->wps_generate_barcode($array); |
250 | 250 | /** For add a product */ |
251 | - $barcode = !empty( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ) ? sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ) : ''; |
|
252 | - if ( isset($barcode) ) { |
|
251 | + $barcode = !empty($_REQUEST['wpshop_product_attribute']['varchar']['barcode']) ? sanitize_text_field($_REQUEST['wpshop_product_attribute']['varchar']['barcode']) : ''; |
|
252 | + if (isset($barcode)) { |
|
253 | 253 | if ($barcode !== '') { |
254 | - wpeologs_ctr::log_datas_in_files( 'wps_barcode', |
|
254 | + wpeologs_ctr::log_datas_in_files('wps_barcode', |
|
255 | 255 | array( |
256 | 256 | 'object_id' => $post_ID, |
257 | - 'message' => sprintf( __('Change barcode: %s replacing %s for %s object ID', 'wps_barcode'), '<b>'.sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ).'</b>', '<b>'.$barcode.'</b>', '<b>'.$post_ID.'</b>') ), 0); |
|
257 | + 'message' => sprintf(__('Change barcode: %s replacing %s for %s object ID', 'wps_barcode'), '<b>' . sanitize_text_field($_REQUEST['wpshop_product_attribute']['varchar']['barcode']) . '</b>', '<b>' . $barcode . '</b>', '<b>' . $post_ID . '</b>') ), 0); |
|
258 | 258 | |
259 | - $barcode = sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ); |
|
259 | + $barcode = sanitize_text_field($_REQUEST['wpshop_product_attribute']['varchar']['barcode']); |
|
260 | 260 | } |
261 | 261 | else { |
262 | - wpeologs_ctr::log_datas_in_files( 'wps_barcode', |
|
262 | + wpeologs_ctr::log_datas_in_files('wps_barcode', |
|
263 | 263 | array( |
264 | 264 | 'object_id' => $post_ID, |
265 | - 'message' => sprintf( __('Adding barcode: %s for %s object ID', 'wps_barcode'), '<b>'.$barcode.'</b>', '<b>'.$post_ID.'</b>') ), |
|
265 | + 'message' => sprintf(__('Adding barcode: %s for %s object ID', 'wps_barcode'), '<b>' . $barcode . '</b>', '<b>' . $post_ID . '</b>') ), |
|
266 | 266 | 0); |
267 | 267 | |
268 | 268 | // $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] = $barcode; |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function add_scripts() { |
283 | 283 | wp_enqueue_script('jquery'); |
284 | - wp_enqueue_script( 'wps_barcode_printelement', WPS_BARCODE_JSCRIPTS.'/jquery.printElement.js' ); |
|
285 | - wp_enqueue_script( 'wps_barcode', WPS_BARCODE_JSCRIPTS.'/wps.backend.wps_barcode.js' ); |
|
284 | + wp_enqueue_script('wps_barcode_printelement', WPS_BARCODE_JSCRIPTS . '/jquery.printElement.js'); |
|
285 | + wp_enqueue_script('wps_barcode', WPS_BARCODE_JSCRIPTS . '/wps.backend.wps_barcode.js'); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | |
303 | 303 | $conf = get_option('wps_barcode'); |
304 | 304 | |
305 | - if ( array_key_exists('normal', $array) ) { |
|
305 | + if (array_key_exists('normal', $array)) { |
|
306 | 306 | $code .= $array['normal']['country']; |
307 | 307 | $code .= $array['normal']['enterprise']; |
308 | 308 | $code .= $array['normal']['ID']; |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | $id = $array['normal']['ID']; |
311 | 311 | |
312 | 312 | } |
313 | - else if ( array_key_exists('internal', $array) ) { |
|
314 | - $code.= $array['internal']['type']; |
|
313 | + else if (array_key_exists('internal', $array)) { |
|
314 | + $code .= $array['internal']['type']; |
|
315 | 315 | $code .= $array['internal']['date']; |
316 | 316 | $code .= $array['internal']['ID']; |
317 | 317 | |
@@ -320,15 +320,15 @@ discard block |
||
320 | 320 | |
321 | 321 | $gencode = $barcode->checksum($code); |
322 | 322 | |
323 | - $barcode->writeLog( sprintf( __("Checksum generate: %s from %s <br />", |
|
324 | - 'wps_barcode'), '<b>'.$gencode.'</b>', |
|
325 | - '<b>'.$code.'</b>') ); |
|
323 | + $barcode->writeLog(sprintf(__("Checksum generate: %s from %s <br />", |
|
324 | + 'wps_barcode'), '<b>' . $gencode . '</b>', |
|
325 | + '<b>' . $code . '</b>')); |
|
326 | 326 | |
327 | - $message = sprintf( __("Log generated by wps_barcodegen for add/update product: <br /> %s", |
|
328 | - 'wps_barcode'), $barcode->getLog() ); |
|
327 | + $message = sprintf(__("Log generated by wps_barcodegen for add/update product: <br /> %s", |
|
328 | + 'wps_barcode'), $barcode->getLog()); |
|
329 | 329 | |
330 | - if ( class_exists('wpeologs_ctr') ) { |
|
331 | - wpeologs_ctr::log_datas_in_files( 'wps_barcode', array('object_id' => $id, 'message' => $message), 0); |
|
330 | + if (class_exists('wpeologs_ctr')) { |
|
331 | + wpeologs_ctr::log_datas_in_files('wps_barcode', array('object_id' => $id, 'message' => $message), 0); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | return $gencode; |
@@ -1,9 +1,9 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | |
3 | 3 | class wps_barcode_settings { |
4 | 4 | public function __construct() { |
5 | 5 | add_filter('wpshop_options', array(&$this, 'add_options'), 10); |
6 | - add_action( 'admin_init', array( &$this, 'declare_options' ) ); |
|
6 | + add_action('admin_init', array(&$this, 'declare_options')); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /** |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | public function add_options($option_group) { |
15 | 15 | $option_group['wpshop_barcode_options'] = |
16 | - array( 'label' => __('Barcode', 'wps_barcode'), |
|
16 | + array('label' => __('Barcode', 'wps_barcode'), |
|
17 | 17 | 'subgroups' => array( |
18 | 18 | 'wpshop_barcode_options' => array('class' => |
19 | 19 | ' wpshop_admin_box_options_barcode'), |
@@ -32,16 +32,16 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function declare_options() { |
34 | 34 | register_setting('wpshop_options', 'wps_barcode', |
35 | - array( $this, 'validate_options') ); |
|
35 | + array($this, 'validate_options')); |
|
36 | 36 | |
37 | 37 | add_settings_section('wpshop_barcode_type_options', |
38 | - '<span class="dashicons dashicons-format-chat"></span>'. |
|
38 | + '<span class="dashicons dashicons-format-chat"></span>' . |
|
39 | 39 | __('WPShop Barcode configuration', 'wps_barcode'), |
40 | 40 | array($this, 'welcome_msg'), 'wpshop_barcode_options'); |
41 | 41 | |
42 | 42 | add_settings_field('wpshop_barcode_type_field', |
43 | - __( 'Type of EAN-13 Barcode', 'wps_barcode'), |
|
44 | - array( $this, 'add_type_field'), 'wpshop_barcode_options', |
|
43 | + __('Type of EAN-13 Barcode', 'wps_barcode'), |
|
44 | + array($this, 'add_type_field'), 'wpshop_barcode_options', |
|
45 | 45 | 'wpshop_barcode_type_options'); |
46 | 46 | |
47 | 47 | add_settings_field('wpshop_barcode_display_field', |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | |
53 | 53 | add_settings_section('wpshop_barcode_internal_ccode_options', |
54 | - '<span class="dashicons dashicons-format-chat"></span>'. |
|
54 | + '<span class="dashicons dashicons-format-chat"></span>' . |
|
55 | 55 | __('WPShop Barcode internal code configuration', 'wps_barcode'), |
56 | 56 | array($this, 'internal_code_section'), 'wpshop_barcode_options_internal'); |
57 | 57 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | array($this, 'add_do_provider_field'), 'wpshop_barcode_options_internal', |
101 | 101 | 'wpshop_barcode_internal_ccode_options'); |
102 | 102 | add_settings_section('wpshop_barcode_normal_code_options', |
103 | - '<span class="dashicons dashicons-format-chat"></span>'. |
|
103 | + '<span class="dashicons dashicons-format-chat"></span>' . |
|
104 | 104 | __('WPShop Barcode normal code configuration', 'wps_barcode'), |
105 | 105 | array($this, 'normal_code_section'), 'wpshop_barcode_options_normal'); |
106 | 106 | |
@@ -149,35 +149,35 @@ discard block |
||
149 | 149 | $internal['normal_enterprise_code'] = isset($input['normal_enterprise_code']) ? $input['normal_enterprise_code'] : ''; |
150 | 150 | |
151 | 151 | /*Verifiy if 3 or 2 digits are presents*/ |
152 | - if ( !empty($internal['internal_client']) || !empty($internal['internal_provider']) || !empty($internal['internal_invoice_client']) || !empty($internal['internal_do_client']) || !empty($internal['internal_product']) || !empty($internal['internal_invoice_provider']) || !empty($internal['internal_do_provider']) || !empty($internal['normal_country_code']) || !empty($internal['normal_enterprise_code']) ) { |
|
153 | - $internal['internal_client'] = strlen($internal['internal_client']) === 2 ? '0'.$internal['internal_client'] : ( strlen($internal['internal_client']) === 3 ? $internal['internal_client'] : ''); |
|
152 | + if (!empty($internal['internal_client']) || !empty($internal['internal_provider']) || !empty($internal['internal_invoice_client']) || !empty($internal['internal_do_client']) || !empty($internal['internal_product']) || !empty($internal['internal_invoice_provider']) || !empty($internal['internal_do_provider']) || !empty($internal['normal_country_code']) || !empty($internal['normal_enterprise_code'])) { |
|
153 | + $internal['internal_client'] = strlen($internal['internal_client']) === 2 ? '0' . $internal['internal_client'] : (strlen($internal['internal_client']) === 3 ? $internal['internal_client'] : ''); |
|
154 | 154 | |
155 | - $internal['internal_provider'] = strlen($internal['internal_provider']) === 2 ? '0'.$internal['internal_provider'] : (strlen($internal['internal_provider']) === 3 ? $internal['internal_provider'] : ''); |
|
155 | + $internal['internal_provider'] = strlen($internal['internal_provider']) === 2 ? '0' . $internal['internal_provider'] : (strlen($internal['internal_provider']) === 3 ? $internal['internal_provider'] : ''); |
|
156 | 156 | |
157 | - $internal['internal_invoice_client'] = strlen($internal['internal_invoice_client']) === 2 ? '0'.$internal['internal_invoice_client'] : (strlen($internal['internal_invoice_client']) === 3 ? $internal['internal_invoice_client'] : ''); |
|
157 | + $internal['internal_invoice_client'] = strlen($internal['internal_invoice_client']) === 2 ? '0' . $internal['internal_invoice_client'] : (strlen($internal['internal_invoice_client']) === 3 ? $internal['internal_invoice_client'] : ''); |
|
158 | 158 | |
159 | - $internal['internal_do_client'] = strlen($internal['internal_do_client']) === 2 ? '0'.$internal['internal_do_client'] : (strlen($internal['internal_do_client']) === 3 ? $internal['internal_do_client'] : ''); |
|
159 | + $internal['internal_do_client'] = strlen($internal['internal_do_client']) === 2 ? '0' . $internal['internal_do_client'] : (strlen($internal['internal_do_client']) === 3 ? $internal['internal_do_client'] : ''); |
|
160 | 160 | |
161 | - $internal['internal_product'] = strlen($internal['internal_product']) === 2 ? '0'.$internal['internal_product'] : (strlen($internal['internal_product']) === 3 ? $internal['internal_product'] : ''); |
|
161 | + $internal['internal_product'] = strlen($internal['internal_product']) === 2 ? '0' . $internal['internal_product'] : (strlen($internal['internal_product']) === 3 ? $internal['internal_product'] : ''); |
|
162 | 162 | |
163 | - $internal['internal_assets_client'] = strlen($internal['internal_assets_client']) === 2 ? '0'.$internal['internal_assets_client'] : (strlen($internal['internal_assets_client']) === 3 ? $internal['internal_assets_client'] : ''); |
|
163 | + $internal['internal_assets_client'] = strlen($internal['internal_assets_client']) === 2 ? '0' . $internal['internal_assets_client'] : (strlen($internal['internal_assets_client']) === 3 ? $internal['internal_assets_client'] : ''); |
|
164 | 164 | |
165 | - $internal['internal_coupons'] = strlen($internal['internal_coupons']) === 2 ? '0'.$internal['internal_coupons'] : (strlen($internal['internal_coupons']) === 3 ? $internal['internal_coupons'] : ''); |
|
165 | + $internal['internal_coupons'] = strlen($internal['internal_coupons']) === 2 ? '0' . $internal['internal_coupons'] : (strlen($internal['internal_coupons']) === 3 ? $internal['internal_coupons'] : ''); |
|
166 | 166 | |
167 | - $internal['internal_invoice_provider'] = strlen($internal['internal_invoice_provider']) === 2 ? '0'.$internal['internal_invoice_provider'] : (strlen($internal['internal_invoice_provider']) === 3 ? $internal['internal_invoice_provider'] : ''); |
|
167 | + $internal['internal_invoice_provider'] = strlen($internal['internal_invoice_provider']) === 2 ? '0' . $internal['internal_invoice_provider'] : (strlen($internal['internal_invoice_provider']) === 3 ? $internal['internal_invoice_provider'] : ''); |
|
168 | 168 | |
169 | - $internal['internal_do_provider'] = strlen($internal['internal_do_provider']) === 2 ? '0'.$internal['internal_do_provider'] : (strlen($internal['internal_do_provider']) === 3 ? $internal['internal_do_provider'] : ''); |
|
169 | + $internal['internal_do_provider'] = strlen($internal['internal_do_provider']) === 2 ? '0' . $internal['internal_do_provider'] : (strlen($internal['internal_do_provider']) === 3 ? $internal['internal_do_provider'] : ''); |
|
170 | 170 | |
171 | - $internal['normal_country_code'] = strlen($internal['normal_country_code']) === 2 ? '0'.$internal['normal_country_code'] : (strlen($internal['normal_country_code']) === 3 ? $internal['normal_country_code'] : ''); |
|
171 | + $internal['normal_country_code'] = strlen($internal['normal_country_code']) === 2 ? '0' . $internal['normal_country_code'] : (strlen($internal['normal_country_code']) === 3 ? $internal['normal_country_code'] : ''); |
|
172 | 172 | |
173 | - if ( strlen($internal['normal_enterprise_code']) === 1 ) { |
|
174 | - $internal['normal_enterprise_code'] = '000'.$internal['normal_enterprise_code']; |
|
173 | + if (strlen($internal['normal_enterprise_code']) === 1) { |
|
174 | + $internal['normal_enterprise_code'] = '000' . $internal['normal_enterprise_code']; |
|
175 | 175 | } |
176 | - else if ( strlen($internal['normal_enterprise_code']) === 2 ) { |
|
177 | - $internal['normal_enterprise_code'] = '00'.$internal['normal_enterprise_code']; |
|
176 | + else if (strlen($internal['normal_enterprise_code']) === 2) { |
|
177 | + $internal['normal_enterprise_code'] = '00' . $internal['normal_enterprise_code']; |
|
178 | 178 | } |
179 | - else if ( strlen($internal['normal_enterprise_code']) === 3 ) { |
|
180 | - $internal['normal_enterprise_code'] = '0'.$internal['normal_enterprise_code']; |
|
179 | + else if (strlen($internal['normal_enterprise_code']) === 3) { |
|
180 | + $internal['normal_enterprise_code'] = '0' . $internal['normal_enterprise_code']; |
|
181 | 181 | } |
182 | 182 | else { |
183 | 183 | $internal['normal_enterprise_code'] = $internal['normal_enterprise_code']; |
@@ -185,84 +185,84 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | /*Verify if range respected*/ |
188 | - if ( $internal['internal_client'] !== '') { |
|
188 | + if ($internal['internal_client'] !== '') { |
|
189 | 189 | $val = intval($internal['internal_client']); |
190 | - if ( $val < 40 || $val > 49) { |
|
190 | + if ($val < 40 || $val > 49) { |
|
191 | 191 | unset($internal['internal_client']); |
192 | 192 | unset($input['client']); |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if ( $internal['internal_provider'] !== '') { |
|
196 | + if ($internal['internal_provider'] !== '') { |
|
197 | 197 | $val = intval($internal['internal_provider']); |
198 | - if ( $val < 40 || $val > 49) { |
|
198 | + if ($val < 40 || $val > 49) { |
|
199 | 199 | unset($internal['internal_provider']); |
200 | 200 | unset($input['provider']); |
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( $internal['internal_invoice_client'] !== '') { |
|
204 | + if ($internal['internal_invoice_client'] !== '') { |
|
205 | 205 | $val = intval($internal['internal_invoice_client']); |
206 | - if ( $val < 40 || $val > 49) { |
|
206 | + if ($val < 40 || $val > 49) { |
|
207 | 207 | unset($internal['internal_invoice_client']); |
208 | 208 | unset($input['invoice_client']); |
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - if ( $internal['internal_do_client'] !== '') { |
|
212 | + if ($internal['internal_do_client'] !== '') { |
|
213 | 213 | $val = intval($internal['internal_do_client']); |
214 | - if ( $val < 40 || $val > 49) { |
|
214 | + if ($val < 40 || $val > 49) { |
|
215 | 215 | unset($internal['internal_do_client']); |
216 | 216 | unset($input['do_client']); |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - if ( $internal['internal_product'] !== '') { |
|
220 | + if ($internal['internal_product'] !== '') { |
|
221 | 221 | $val = intval($internal['internal_product']); |
222 | - if ( $val < 40 || $val > 49) { |
|
222 | + if ($val < 40 || $val > 49) { |
|
223 | 223 | unset($internal['internal_product']); |
224 | 224 | unset($input['product']); |
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | - if ( $internal['internal_assets_client'] !== '') { |
|
228 | + if ($internal['internal_assets_client'] !== '') { |
|
229 | 229 | $val = intval($internal['internal_assets_client']); |
230 | - if ( $val < 50 || $val > 59) { |
|
230 | + if ($val < 50 || $val > 59) { |
|
231 | 231 | unset($internal['internal_assets_client']); |
232 | 232 | unset($input['assets_client']); |
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - if ( $internal['internal_coupons'] !== '') { |
|
236 | + if ($internal['internal_coupons'] !== '') { |
|
237 | 237 | $val = intval($internal['internal_coupons']); |
238 | - if ( $val < 50 || $val > 59) { |
|
238 | + if ($val < 50 || $val > 59) { |
|
239 | 239 | unset($internal['internal_coupons']); |
240 | 240 | unset($input['coupons']); |
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - if ( $internal['internal_invoice_provider'] !== '') { |
|
244 | + if ($internal['internal_invoice_provider'] !== '') { |
|
245 | 245 | $val = intval($internal['internal_invoice_provider']); |
246 | - if ( $val < 40 || $val > 49) { |
|
246 | + if ($val < 40 || $val > 49) { |
|
247 | 247 | unset($internal['internal_invoice_provider']); |
248 | 248 | unset($input['invoice_provider']); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | - if ( $internal['internal_do_provider'] !== '') { |
|
252 | + if ($internal['internal_do_provider'] !== '') { |
|
253 | 253 | $val = intval($internal['internal_do_provider']); |
254 | - if ( $val < 40 || $val > 49) { |
|
254 | + if ($val < 40 || $val > 49) { |
|
255 | 255 | unset($internal['internal_do_provider']); |
256 | 256 | unset($input['do_provider']); |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | - if ( $internal['normal_country_code'] === '' ) { |
|
260 | + if ($internal['normal_country_code'] === '') { |
|
261 | 261 | unset($internal['normal_country_code']); |
262 | 262 | unset($input['normal_country_code']); |
263 | 263 | } |
264 | 264 | |
265 | - if ( $internal['normal_enterprise_code'] === '' ) { |
|
265 | + if ($internal['normal_enterprise_code'] === '') { |
|
266 | 266 | unset($internal['normal_enterprise_code']); |
267 | 267 | unset($input['normal_enterprise_code']); |
268 | 268 | } |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | * Display message for internal code section |
277 | 277 | */ |
278 | 278 | public function internal_code_section() { |
279 | - _e("Configure your internal codes for automatically generate barcode. The codes are 2 digits, its normal. ". |
|
280 | - "You can put 3 without problems. Please respect the range number following: 040 up to 049.". |
|
279 | + _e("Configure your internal codes for automatically generate barcode. The codes are 2 digits, its normal. " . |
|
280 | + "You can put 3 without problems. Please respect the range number following: 040 up to 049." . |
|
281 | 281 | " For coupons, the range is: 050 up to 059.", 'wps_barcode'); |
282 | 282 | } |
283 | 283 | |
@@ -291,9 +291,9 @@ discard block |
||
291 | 291 | public function add_display_field() { |
292 | 292 | $field = get_option('wps_barcode'); |
293 | 293 | |
294 | - $checked = ( isset($field['generate_barcode']) && $field['generate_barcode'] === 'on') ? 'checked' : ''; |
|
294 | + $checked = (isset($field['generate_barcode']) && $field['generate_barcode'] === 'on') ? 'checked' : ''; |
|
295 | 295 | |
296 | - echo '<input type="checkbox" name="wps_barcode[generate_barcode]" id="barcode_display"'.$checked.'>'; |
|
296 | + echo '<input type="checkbox" name="wps_barcode[generate_barcode]" id="barcode_display"' . $checked . '>'; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -307,13 +307,13 @@ discard block |
||
307 | 307 | |
308 | 308 | echo '<select name="wps_barcode[type]" id="barcode_type">'; |
309 | 309 | |
310 | - if ( !empty($field) && ($field['type'] == 'internal') ) { |
|
311 | - echo '<option value="internal" selected>'.__('Internal', 'wps_barcode').'</option>'; |
|
312 | - echo '<option value="normal">'.__('Normal', 'wps_barcode').'</option>'; |
|
310 | + if (!empty($field) && ($field['type'] == 'internal')) { |
|
311 | + echo '<option value="internal" selected>' . __('Internal', 'wps_barcode') . '</option>'; |
|
312 | + echo '<option value="normal">' . __('Normal', 'wps_barcode') . '</option>'; |
|
313 | 313 | } |
314 | - else if ( !empty($field) && ($field['type'] == 'normal') ) { |
|
315 | - echo '<option value="internal">'.__('Internal', 'wps_barcode').'</option>'; |
|
316 | - echo '<option value="normal" selected>'.__('Normal', 'wps_barcode').'</option>'; |
|
314 | + else if (!empty($field) && ($field['type'] == 'normal')) { |
|
315 | + echo '<option value="internal">' . __('Internal', 'wps_barcode') . '</option>'; |
|
316 | + echo '<option value="normal" selected>' . __('Normal', 'wps_barcode') . '</option>'; |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | echo '</select>'; |
@@ -326,8 +326,8 @@ discard block |
||
326 | 326 | */ |
327 | 327 | public function welcome_msg() { |
328 | 328 | //include(WPS_BARCODE_TEMPLATES_MAIN_DIR.'backend/welcome.tpl.php'); |
329 | - require( wpshop_tools::get_template_part(WPS_BARCODE_PATH, |
|
330 | - WPS_BARCODE_TEMPLATES_TPL_DIR, 'backend', 'welcome/welcome') ); |
|
329 | + require(wpshop_tools::get_template_part(WPS_BARCODE_PATH, |
|
330 | + WPS_BARCODE_TEMPLATES_TPL_DIR, 'backend', 'welcome/welcome')); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | public function add_client_field() { |
337 | 337 | $field = get_option('wps_barcode'); |
338 | 338 | |
339 | - echo '<input type="number" name="wps_barcode[internal_client]" '. |
|
340 | - 'min=40 max=49 value="'.$field['internal_client'].'" />'; |
|
339 | + echo '<input type="number" name="wps_barcode[internal_client]" ' . |
|
340 | + 'min=40 max=49 value="' . $field['internal_client'] . '" />'; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | public function add_provider_field() { |
347 | 347 | $field = get_option('wps_barcode'); |
348 | 348 | |
349 | - echo '<input type="number" name="wps_barcode[internal_provider]" '. |
|
350 | - 'min=40 max=49 value="'.$field['internal_provider'].'" />'; |
|
349 | + echo '<input type="number" name="wps_barcode[internal_provider]" ' . |
|
350 | + 'min=40 max=49 value="' . $field['internal_provider'] . '" />'; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | public function add_invoice_client_field() { |
357 | 357 | $field = get_option('wps_barcode'); |
358 | 358 | |
359 | - echo '<input type="number" name="wps_barcode[internal_invoice_client]" '. |
|
360 | - 'min=40 max=49 value="'.$field['internal_invoice_client'].'" />'; |
|
359 | + echo '<input type="number" name="wps_barcode[internal_invoice_client]" ' . |
|
360 | + 'min=40 max=49 value="' . $field['internal_invoice_client'] . '" />'; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | public function add_do_client_field() { |
367 | 367 | $field = get_option('wps_barcode'); |
368 | 368 | |
369 | - echo '<input type="number" name="wps_barcode[internal_do_client]" '. |
|
370 | - 'min=40 max=49 value="'.$field['internal_do_client'].'" />'; |
|
369 | + echo '<input type="number" name="wps_barcode[internal_do_client]" ' . |
|
370 | + 'min=40 max=49 value="' . $field['internal_do_client'] . '" />'; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | public function add_product_field() { |
377 | 377 | $field = get_option('wps_barcode'); |
378 | 378 | |
379 | - echo '<input type="number" name="wps_barcode[internal_product]" '. |
|
380 | - 'min=40 max=49 value="'.$field['internal_product'].'" />'; |
|
379 | + echo '<input type="number" name="wps_barcode[internal_product]" ' . |
|
380 | + 'min=40 max=49 value="' . $field['internal_product'] . '" />'; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | public function add_assets_client_field() { |
387 | 387 | $field = get_option('wps_barcode'); |
388 | 388 | |
389 | - echo '<input type="number" name="wps_barcode[internal_assets_client]" '. |
|
390 | - 'min=50 max=59 value="'.$field['internal_assets_client'].'" />'; |
|
389 | + echo '<input type="number" name="wps_barcode[internal_assets_client]" ' . |
|
390 | + 'min=50 max=59 value="' . $field['internal_assets_client'] . '" />'; |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -396,8 +396,8 @@ discard block |
||
396 | 396 | public function add_coupons_field() { |
397 | 397 | $field = get_option('wps_barcode'); |
398 | 398 | |
399 | - echo '<input type="number" name="wps_barcode[internal_coupons]" '. |
|
400 | - 'min=50 max=59 value="'.$field['internal_coupons'].'" />'; |
|
399 | + echo '<input type="number" name="wps_barcode[internal_coupons]" ' . |
|
400 | + 'min=50 max=59 value="' . $field['internal_coupons'] . '" />'; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -406,8 +406,8 @@ discard block |
||
406 | 406 | public function add_invoice_provider_field() { |
407 | 407 | $field = get_option('wps_barcode'); |
408 | 408 | |
409 | - echo '<input type="number" name="wps_barcode[internal_invoice_provider]" '. |
|
410 | - 'min=40 max=49 value="'.$field['internal_invoice_provider'].'" />'; |
|
409 | + echo '<input type="number" name="wps_barcode[internal_invoice_provider]" ' . |
|
410 | + 'min=40 max=49 value="' . $field['internal_invoice_provider'] . '" />'; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | public function add_do_provider_field() { |
417 | 417 | $field = get_option('wps_barcode'); |
418 | 418 | |
419 | - echo '<input type="number" name="wps_barcode[internal_do_provider]" '. |
|
420 | - 'min=40 max=49 value="'.$field['internal_do_provider'].'" />'; |
|
419 | + echo '<input type="number" name="wps_barcode[internal_do_provider]" ' . |
|
420 | + 'min=40 max=49 value="' . $field['internal_do_provider'] . '" />'; |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -426,8 +426,8 @@ discard block |
||
426 | 426 | public function add_country_code_field() { |
427 | 427 | $field = get_option('wps_barcode'); |
428 | 428 | |
429 | - echo '<input type="number" name="wps_barcode[normal_country_code]" '. |
|
430 | - 'value="'.$field['normal_country_code'].'" />'; |
|
429 | + echo '<input type="number" name="wps_barcode[normal_country_code]" ' . |
|
430 | + 'value="' . $field['normal_country_code'] . '" />'; |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | public function add_enterprise_code_field() { |
437 | 437 | $field = get_option('wps_barcode'); |
438 | 438 | |
439 | - echo '<input type="number" name="wps_barcode[normal_enterprise_code]" '. |
|
440 | - 'value="'.$field['normal_enterprise_code'].'" />'; |
|
439 | + echo '<input type="number" name="wps_barcode[normal_enterprise_code]" ' . |
|
440 | + 'value="' . $field['normal_enterprise_code'] . '" />'; |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | |
3 | 5 | class wps_barcode_settings { |
4 | 6 | public function __construct() { |
@@ -172,14 +174,11 @@ discard block |
||
172 | 174 | |
173 | 175 | if ( strlen($internal['normal_enterprise_code']) === 1 ) { |
174 | 176 | $internal['normal_enterprise_code'] = '000'.$internal['normal_enterprise_code']; |
175 | - } |
|
176 | - else if ( strlen($internal['normal_enterprise_code']) === 2 ) { |
|
177 | + } else if ( strlen($internal['normal_enterprise_code']) === 2 ) { |
|
177 | 178 | $internal['normal_enterprise_code'] = '00'.$internal['normal_enterprise_code']; |
178 | - } |
|
179 | - else if ( strlen($internal['normal_enterprise_code']) === 3 ) { |
|
179 | + } else if ( strlen($internal['normal_enterprise_code']) === 3 ) { |
|
180 | 180 | $internal['normal_enterprise_code'] = '0'.$internal['normal_enterprise_code']; |
181 | - } |
|
182 | - else { |
|
181 | + } else { |
|
183 | 182 | $internal['normal_enterprise_code'] = $internal['normal_enterprise_code']; |
184 | 183 | } |
185 | 184 | } |
@@ -310,8 +309,7 @@ discard block |
||
310 | 309 | if ( !empty($field) && ($field['type'] == 'internal') ) { |
311 | 310 | echo '<option value="internal" selected>'.__('Internal', 'wps_barcode').'</option>'; |
312 | 311 | echo '<option value="normal">'.__('Normal', 'wps_barcode').'</option>'; |
313 | - } |
|
314 | - else if ( !empty($field) && ($field['type'] == 'normal') ) { |
|
312 | + } else if ( !empty($field) && ($field['type'] == 'normal') ) { |
|
315 | 313 | echo '<option value="internal">'.__('Internal', 'wps_barcode').'</option>'; |
316 | 314 | echo '<option value="normal" selected>'.__('Normal', 'wps_barcode').'</option>'; |
317 | 315 | } |
@@ -261,7 +261,7 @@ |
||
261 | 261 | $wps_message->wpshop_prepared_email($email, |
262 | 262 | 'WPSHOP_QUOTATION_UPDATE_MESSAGE', |
263 | 263 | array( 'order_id' => $object['object_id'], |
264 | - 'customer_first_name' => $first_name, |
|
264 | + 'customer_first_name' => $first_name, |
|
265 | 265 | 'customer_last_name' => $last_name, |
266 | 266 | 'order_date' => current_time('mysql', 0), |
267 | 267 | 'order_content' => '', |
@@ -1,132 +1,132 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wps_orders_in_back_office { |
3 | 3 | |
4 | 4 | function __construct() { |
5 | 5 | // Template loading |
6 | 6 | $this->template_dir = WPS_ORDERS_PATH . WPS_ORDERS_DIR . "/templates/"; |
7 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes') ); |
|
7 | + add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
8 | 8 | |
9 | 9 | // Ajax actions |
10 | - add_action('wp_ajax_wpshop_add_private_comment_to_order', array( $this, 'wpshop_add_private_comment_to_order' ) ); |
|
11 | - add_action('wp_ajax_wps_order_refresh_product_listing', array( $this, 'refresh_product_list' ) ); |
|
12 | - add_action('wp_ajax_wps_add_product_to_order_admin', array( $this, 'wps_add_product_to_order_admin' ) ); |
|
13 | - add_action('wp_ajax_wps_refresh_cart_order', array( $this, 'refresh_cart_order' ) ); |
|
14 | - add_action('wp_ajax_wps_refresh_payments_order', array( $this, 'refresh_payments_order' ) ); |
|
15 | - add_action('wp_ajax_wps_update_product_qty_in_admin', array( $this, 'wps_update_product_qty_in_admin' ) ); |
|
16 | - add_action('wp_ajax_wps_order_load_product_variations', array( $this, 'wps_order_load_product_variations' ) ); |
|
17 | - add_action('wp_ajax_wps-orders-update-cart-informations', array( $this, 'wps_orders_update_cart_informations' ) ); |
|
18 | - add_action('wp_ajax_wps_reverify_payment_invoice_ref', array( $this, 'wps_reverify_payment_invoice_ref' ) ); |
|
10 | + add_action('wp_ajax_wpshop_add_private_comment_to_order', array($this, 'wpshop_add_private_comment_to_order')); |
|
11 | + add_action('wp_ajax_wps_order_refresh_product_listing', array($this, 'refresh_product_list')); |
|
12 | + add_action('wp_ajax_wps_add_product_to_order_admin', array($this, 'wps_add_product_to_order_admin')); |
|
13 | + add_action('wp_ajax_wps_refresh_cart_order', array($this, 'refresh_cart_order')); |
|
14 | + add_action('wp_ajax_wps_refresh_payments_order', array($this, 'refresh_payments_order')); |
|
15 | + add_action('wp_ajax_wps_update_product_qty_in_admin', array($this, 'wps_update_product_qty_in_admin')); |
|
16 | + add_action('wp_ajax_wps_order_load_product_variations', array($this, 'wps_order_load_product_variations')); |
|
17 | + add_action('wp_ajax_wps-orders-update-cart-informations', array($this, 'wps_orders_update_cart_informations')); |
|
18 | + add_action('wp_ajax_wps_reverify_payment_invoice_ref', array($this, 'wps_reverify_payment_invoice_ref')); |
|
19 | 19 | |
20 | 20 | // WP General actions |
21 | - add_action( 'admin_enqueue_scripts', array( $this, 'wps_orders_scripts') ); |
|
22 | - add_action( 'admin_enqueue_scripts', array( $this, 'wps_orders_scripts_texts' ), 20 ); |
|
23 | - add_action('save_post', array( $this, 'save_order_custom_informations')); |
|
21 | + add_action('admin_enqueue_scripts', array($this, 'wps_orders_scripts')); |
|
22 | + add_action('admin_enqueue_scripts', array($this, 'wps_orders_scripts_texts'), 20); |
|
23 | + add_action('save_post', array($this, 'save_order_custom_informations')); |
|
24 | 24 | |
25 | 25 | // WP Filters |
26 | - add_filter( 'wps_order_saving_admin_extra_action', array( $this, 'wps_notif_user_on_order_saving'), 100, 2 ); |
|
26 | + add_filter('wps_order_saving_admin_extra_action', array($this, 'wps_notif_user_on_order_saving'), 100, 2); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Add scripts |
31 | 31 | */ |
32 | 32 | function wps_orders_scripts() { |
33 | - wp_enqueue_script( 'wps_orders_backend', WPS_ORDERS_URL.WPS_ORDERS_DIR.'/assets/backend/js/wps_orders.js' ); |
|
33 | + wp_enqueue_script('wps_orders_backend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/backend/js/wps_orders.js'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | function wps_orders_scripts_texts() { |
37 | - wp_localize_script( 'wps_orders_backend', 'message_confirm_reload', __( 'Are you sure you want to refresh your browser?', 'wpshop' ) ); |
|
38 | - wp_localize_script( 'wps_orders_backend', 'message_error_reverify_payment_invoice_ref', __( 'Error detected.', 'wpshop' ) ); |
|
37 | + wp_localize_script('wps_orders_backend', 'message_confirm_reload', __('Are you sure you want to refresh your browser?', 'wpshop')); |
|
38 | + wp_localize_script('wps_orders_backend', 'message_error_reverify_payment_invoice_ref', __('Error detected.', 'wpshop')); |
|
39 | 39 | } |
40 | 40 | /** |
41 | 41 | * Add meta boxes |
42 | 42 | */ |
43 | 43 | function add_meta_boxes() { |
44 | 44 | global $post; |
45 | - $order_post_meta = get_post_meta( $post->ID, '_wpshop_order_status', true ); |
|
45 | + $order_post_meta = get_post_meta($post->ID, '_wpshop_order_status', true); |
|
46 | 46 | |
47 | 47 | /** Box Order Payments **/ |
48 | - add_meta_box('wpshop_order_payment', '<span class="dashicons dashicons-money"></span> '.__('Order payment', 'wpshop'),array($this, 'display_order_payments_box'),WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
48 | + add_meta_box('wpshop_order_payment', '<span class="dashicons dashicons-money"></span> ' . __('Order payment', 'wpshop'), array($this, 'display_order_payments_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
49 | 49 | /** Box for customer order comment */ |
50 | - add_meta_box('wpshop_order_customer_comment', '<span class="dashicons dashicons-format-status"></span> '.__('Order customer comment', 'wpshop'),array( $this, 'order_customer_comment_box'),WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
50 | + add_meta_box('wpshop_order_customer_comment', '<span class="dashicons dashicons-format-status"></span> ' . __('Order customer comment', 'wpshop'), array($this, 'order_customer_comment_box'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'); |
|
51 | 51 | /** Historic sales **/ |
52 | - add_meta_box('wpshop_product_order_historic', __('Sales informations', 'wpshop'), array( $this, 'meta_box_product_sale_informations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'low'); |
|
52 | + add_meta_box('wpshop_product_order_historic', __('Sales informations', 'wpshop'), array($this, 'meta_box_product_sale_informations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'low'); |
|
53 | 53 | /** Box with the complete order content */ |
54 | - if ( 'completed' != $order_post_meta && 'pos' != $order_post_meta ) : |
|
55 | - add_meta_box('wpshop_product_list', '<span class="dashicons dashicons-archive"></span> ' . __('Product List', 'wpshop'),array($this, 'wps_products_listing_for_quotation'),WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
54 | + if ('completed' != $order_post_meta && 'pos' != $order_post_meta) : |
|
55 | + add_meta_box('wpshop_product_list', '<span class="dashicons dashicons-archive"></span> ' . __('Product List', 'wpshop'), array($this, 'wps_products_listing_for_quotation'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
56 | 56 | endif; |
57 | 57 | /** Box with the complete order content */ |
58 | - add_meta_box( 'wpshop_order_content', '<span class="dashicons dashicons-cart"></span> '.__('Order content', 'wpshop'), array( $this, 'meta_box_order_content'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
58 | + add_meta_box('wpshop_order_content', '<span class="dashicons dashicons-cart"></span> ' . __('Order content', 'wpshop'), array($this, 'meta_box_order_content'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
59 | 59 | /** Box Private order comments **/ |
60 | - add_meta_box('wpshop_order_private_comments', '<span class="dashicons dashicons-format-chat"></span> '.__('Comments', 'wpshop'), array( $this, 'meta_box_private_comment'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
60 | + add_meta_box('wpshop_order_private_comments', '<span class="dashicons dashicons-format-chat"></span> ' . __('Comments', 'wpshop'), array($this, 'meta_box_private_comment'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'normal', 'low'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * METABOX CONTENT - Display Customer comments on order in administration panel |
65 | 65 | * @param object $order |
66 | 66 | */ |
67 | - function order_customer_comment_box( $order ) { |
|
67 | + function order_customer_comment_box($order) { |
|
68 | 68 | global $wpdb; |
69 | 69 | $output = ''; |
70 | - if ( !empty($order) && !empty($order->ID) ) { |
|
71 | - $query = $wpdb->prepare('SELECT post_excerpt FROM ' .$wpdb->posts. ' WHERE ID = %d', $order->ID); |
|
72 | - $comment = $wpdb->get_var( $query ); |
|
73 | - require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "customer_comment_on_order_box") ); |
|
70 | + if (!empty($order) && !empty($order->ID)) { |
|
71 | + $query = $wpdb->prepare('SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order->ID); |
|
72 | + $comment = $wpdb->get_var($query); |
|
73 | + require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "customer_comment_on_order_box")); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * METABOX CONTENT - Display an order historic of product in administration product panel |
79 | 79 | */ |
80 | - function meta_box_product_sale_informations () { |
|
80 | + function meta_box_product_sale_informations() { |
|
81 | 81 | global $post; |
82 | 82 | $product_id = $post->ID; |
83 | - $variations = wpshop_products::get_variation( $product_id ); |
|
84 | - $order_status = unserialize( WPSHOP_ORDER_STATUS ); |
|
85 | - $color_label = array( 'awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge', 'pos' => 'bleu'); |
|
83 | + $variations = wpshop_products::get_variation($product_id); |
|
84 | + $order_status = unserialize(WPSHOP_ORDER_STATUS); |
|
85 | + $color_label = array('awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge', 'pos' => 'bleu'); |
|
86 | 86 | // Get datas |
87 | 87 | $sales_informations = array(); |
88 | 88 | /** Query **/ |
89 | - $data_to_compare = '"item_id";s:' .strlen($product_id). ':"' .$product_id. '";'; |
|
90 | - $query_args = array( 'posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array( array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE') ) ); |
|
91 | - $orders = new WP_Query( $query_args ); |
|
92 | - if ( !empty($orders) && !empty($orders->posts) ) { |
|
93 | - foreach( $orders->posts as $order ) { |
|
94 | - $order_meta = get_post_meta( $order->ID, '_order_postmeta', true ); |
|
95 | - $order_info = get_post_meta( $order->ID, '_order_info', true ); |
|
89 | + $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
90 | + $query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE'))); |
|
91 | + $orders = new WP_Query($query_args); |
|
92 | + if (!empty($orders) && !empty($orders->posts)) { |
|
93 | + foreach ($orders->posts as $order) { |
|
94 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
95 | + $order_info = get_post_meta($order->ID, '_order_info', true); |
|
96 | 96 | $sales_informations[] = array( |
97 | - 'order_key' => ( !empty($order_meta) && !empty($order_meta['order_key']) ) ? $order_meta['order_key'] : '', |
|
98 | - 'order_date' => ( !empty($order_meta) && !empty($order_meta['order_date']) ) ? $order_meta['order_date'] : '', |
|
99 | - 'customer_firstname' => ( !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name']) ) ? $order_info['billing']['address']['address_first_name'] : '', |
|
100 | - 'customer_name' => ( !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name']) ) ? $order_info['billing']['address']['address_last_name'] : '', |
|
101 | - 'customer_email' => ( !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email']) ) ? $order_info['billing']['address']['address_user_email'] : '', |
|
97 | + 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
98 | + 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
99 | + 'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '', |
|
100 | + 'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '', |
|
101 | + 'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '', |
|
102 | 102 | 'order_id' => $order->ID, |
103 | 103 | 'order_status' => $order_meta['order_status'] |
104 | 104 | ); |
105 | 105 | } |
106 | 106 | } |
107 | 107 | // Display results |
108 | - require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product_order_historic") ); |
|
108 | + require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product_order_historic")); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | 112 | * METABOX CONTENT - Payments Box in Orders panel |
113 | 113 | * @param string $order |
114 | 114 | */ |
115 | - function display_order_payments_box( $order ) { |
|
115 | + function display_order_payments_box($order) { |
|
116 | 116 | $order_status = unserialize(WPSHOP_ORDER_STATUS); |
117 | 117 | $order_postmeta = get_post_meta($order->ID, '_order_postmeta', true); |
118 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "wps_order_payment_box") ); |
|
118 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "wps_order_payment_box")); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | 122 | * METABOX CONTENT - Display an lsiting of products to make quotation in backend |
123 | 123 | */ |
124 | 124 | function wps_products_listing_for_quotation($post) { |
125 | - $letters = array( 'ALL', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); |
|
126 | - $current_letter = sanitize_title( $letters[1] ); |
|
125 | + $letters = array('ALL', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); |
|
126 | + $current_letter = sanitize_title($letters[1]); |
|
127 | 127 | $wps_product_mdl = new wps_product_mdl(); |
128 | - $products = $wps_product_mdl->get_products_by_letter( $current_letter ); |
|
129 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing") ); |
|
128 | + $products = $wps_product_mdl->get_products_by_letter($current_letter); |
|
129 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing")); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | function meta_box_private_comment() { |
136 | 136 | global $post; |
137 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_private_comments") ); |
|
137 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_private_comments")); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | */ |
143 | 143 | function meta_box_order_content() { |
144 | 144 | global $post_id; |
145 | - unset( $_SESSION['cart'] ); |
|
146 | - echo do_shortcode( '[wps_cart oid="' .$post_id. '" cart_type="admin-panel"]'); |
|
145 | + unset($_SESSION['cart']); |
|
146 | + echo do_shortcode('[wps_cart oid="' . $post_id . '" cart_type="admin-panel"]'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | |
@@ -153,68 +153,68 @@ discard block |
||
153 | 153 | function save_order_custom_informations() { |
154 | 154 | global $wpdb; |
155 | 155 | |
156 | - $post_ID = !empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0; |
|
156 | + $post_ID = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0; |
|
157 | 157 | // Check if it is an order save action |
158 | - if ( !empty($post_ID) && ( get_post_type($post_ID) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) ) { |
|
158 | + if (!empty($post_ID) && (get_post_type($post_ID) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER)) { |
|
159 | 159 | //Define Customer ID |
160 | - $user_id = ( !empty( $_REQUEST['wps_customer_id'] ) ) ? (int) $_REQUEST['wps_customer_id'] : get_current_user_id(); |
|
160 | + $user_id = (!empty($_REQUEST['wps_customer_id'])) ? (int)$_REQUEST['wps_customer_id'] : get_current_user_id(); |
|
161 | 161 | |
162 | 162 | // Order MetaData |
163 | - $order_meta = get_post_meta( $post_ID, '_order_postmeta', true); |
|
163 | + $order_meta = get_post_meta($post_ID, '_order_postmeta', true); |
|
164 | 164 | |
165 | 165 | // Save General information of order's attached customer |
166 | - $wpdb->update( $wpdb->posts, array('post_parent' => $user_id, 'post_status' => 'publish'), array('ID' => $post_ID) ); |
|
167 | - update_post_meta( $post_ID, '_wpshop_order_customer_id', $user_id ); |
|
166 | + $wpdb->update($wpdb->posts, array('post_parent' => $user_id, 'post_status' => 'publish'), array('ID' => $post_ID)); |
|
167 | + update_post_meta($post_ID, '_wpshop_order_customer_id', $user_id); |
|
168 | 168 | $order_meta['customer_id'] = $user_id; |
169 | - if ( empty($order_meta['order_key']) ) { |
|
170 | - $order_meta['order_key'] = !empty($order_meta['order_key']) ? $order_meta['order_key'] : (!empty($order_meta['order_status']) && ($order_meta['order_status']!='awaiting_payment') ? wpshop_orders::get_new_order_reference() : ''); |
|
169 | + if (empty($order_meta['order_key'])) { |
|
170 | + $order_meta['order_key'] = !empty($order_meta['order_key']) ? $order_meta['order_key'] : (!empty($order_meta['order_status']) && ($order_meta['order_status'] != 'awaiting_payment') ? wpshop_orders::get_new_order_reference() : ''); |
|
171 | 171 | $order_meta['order_temporary_key'] = (isset($order_meta['order_temporary_key']) && ($order_meta['order_temporary_key'] != '')) ? $order_meta['order_temporary_key'] : wpshop_orders::get_new_pre_order_reference(); |
172 | 172 | } |
173 | 173 | $order_meta['order_status'] = (isset($order_meta['order_status']) && ($order_meta['order_status'] != '')) ? $order_meta['order_status'] : 'awaiting_payment'; |
174 | 174 | $order_meta['order_date'] = (isset($order_meta['order_date']) && ($order_meta['order_date'] != '')) ? $order_meta['order_date'] : current_time('mysql', 0); |
175 | 175 | $order_meta['order_currency'] = wpshop_tools::wpshop_get_currency(true); |
176 | 176 | |
177 | - $billing_adress_id = ( !empty( $_REQUEST['wps_order_selected_address'] ) && empty( $_REQUEST['wps_order_selected_address']['billing'] ) ) ? (int) $_REQUEST['wps_order_selected_address']['billing'] : 0; |
|
177 | + $billing_adress_id = (!empty($_REQUEST['wps_order_selected_address']) && empty($_REQUEST['wps_order_selected_address']['billing'])) ? (int)$_REQUEST['wps_order_selected_address']['billing'] : 0; |
|
178 | 178 | |
179 | 179 | // Order Attached Addresses save |
180 | - if( !empty( $billing_adress_id ) ) { |
|
180 | + if (!empty($billing_adress_id)) { |
|
181 | 181 | // Informations |
182 | - $order_informations = get_post_meta( $post_ID, '_order_info', true ); |
|
183 | - $order_informations = ( !empty($order_informations) ) ? $order_informations : array(); |
|
184 | - $billing_address_option = get_option( 'wpshop_billing_address' ); |
|
185 | - $billing_address_option = ( !empty($billing_address_option) && !empty( $billing_address_option['choice'] ) ) ? $billing_address_option['choice'] : ''; |
|
182 | + $order_informations = get_post_meta($post_ID, '_order_info', true); |
|
183 | + $order_informations = (!empty($order_informations)) ? $order_informations : array(); |
|
184 | + $billing_address_option = get_option('wpshop_billing_address'); |
|
185 | + $billing_address_option = (!empty($billing_address_option) && !empty($billing_address_option['choice'])) ? $billing_address_option['choice'] : ''; |
|
186 | 186 | |
187 | 187 | // Billing datas |
188 | - $order_informations['billing'] = array( 'id' => $billing_address_option, |
|
188 | + $order_informations['billing'] = array('id' => $billing_address_option, |
|
189 | 189 | 'address_id' => $billing_adress_id, |
190 | - 'address' => get_post_meta( $billing_adress_id, '_wpshop_address_metadata', true ) |
|
190 | + 'address' => get_post_meta($billing_adress_id, '_wpshop_address_metadata', true) |
|
191 | 191 | ); |
192 | 192 | // Shipping datas |
193 | - $shipping_adress_id = ( !empty( $_REQUEST['wps_order_selected_address'] ) && empty( $_REQUEST['wps_order_selected_address']['shipping'] ) ) ? (int) $_REQUEST['wps_order_selected_address']['shipping'] : 0; |
|
193 | + $shipping_adress_id = (!empty($_REQUEST['wps_order_selected_address']) && empty($_REQUEST['wps_order_selected_address']['shipping'])) ? (int)$_REQUEST['wps_order_selected_address']['shipping'] : 0; |
|
194 | 194 | |
195 | - if( !empty( $shipping_adress_id ) ) { |
|
196 | - $shipping_address_option = get_option( 'wpshop_shipping_address_choice' ); |
|
197 | - $shipping_address_option = ( !empty($shipping_address_option) && !empty($shipping_address_option['choice']) ) ? $shipping_address_option['choice'] : ''; |
|
198 | - $order_informations['shipping'] = array( 'id' => $shipping_address_option, |
|
195 | + if (!empty($shipping_adress_id)) { |
|
196 | + $shipping_address_option = get_option('wpshop_shipping_address_choice'); |
|
197 | + $shipping_address_option = (!empty($shipping_address_option) && !empty($shipping_address_option['choice'])) ? $shipping_address_option['choice'] : ''; |
|
198 | + $order_informations['shipping'] = array('id' => $shipping_address_option, |
|
199 | 199 | 'address_id' => $shipping_adress_id, |
200 | - 'address' => get_post_meta( $shipping_adress_id, '_wpshop_address_metadata', true ) |
|
200 | + 'address' => get_post_meta($shipping_adress_id, '_wpshop_address_metadata', true) |
|
201 | 201 | ); |
202 | 202 | } |
203 | - update_post_meta( $post_ID, '_order_info', $order_informations ); |
|
203 | + update_post_meta($post_ID, '_order_info', $order_informations); |
|
204 | 204 | } |
205 | 205 | |
206 | - $wpshop_admin_order_payment_received = !empty( $_REQUEST['wpshop_admin_order_payment_received'] ) ? (array)$_REQUEST['wpshop_admin_order_payment_received'] : array(); |
|
207 | - $wpshop_admin_order_payment_received['method'] = !empty( $wpshop_admin_order_payment_received['method'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['method'] ) : ''; |
|
208 | - $wpshop_admin_order_payment_received['payment_reference'] = !empty( $wpshop_admin_order_payment_received['payment_reference'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['payment_reference'] ) : ''; |
|
209 | - $wpshop_admin_order_payment_received['date'] = !empty( $wpshop_admin_order_payment_received['date'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['date'] ) : ''; |
|
210 | - $wpshop_admin_order_payment_received['received_amount'] = !empty( $wpshop_admin_order_payment_received['received_amount'] ) ? sanitize_text_field( $wpshop_admin_order_payment_received['received_amount'] ) : ''; |
|
211 | - $action_triggered_from = !empty( $_REQUEST['action_triggered_from'] ) ? sanitize_text_field( $action_triggered_from ) : ''; |
|
212 | - $whsop_admin_order_payment_reference = !empty( $_REQUEST['wpshop_admin_order_payment_reference'] ) ? sanitize_text_field( $_REQUEST['wpshop_admin_order_payment_reference'] ) : ''; |
|
206 | + $wpshop_admin_order_payment_received = !empty($_REQUEST['wpshop_admin_order_payment_received']) ? (array)$_REQUEST['wpshop_admin_order_payment_received'] : array(); |
|
207 | + $wpshop_admin_order_payment_received['method'] = !empty($wpshop_admin_order_payment_received['method']) ? sanitize_text_field($wpshop_admin_order_payment_received['method']) : ''; |
|
208 | + $wpshop_admin_order_payment_received['payment_reference'] = !empty($wpshop_admin_order_payment_received['payment_reference']) ? sanitize_text_field($wpshop_admin_order_payment_received['payment_reference']) : ''; |
|
209 | + $wpshop_admin_order_payment_received['date'] = !empty($wpshop_admin_order_payment_received['date']) ? sanitize_text_field($wpshop_admin_order_payment_received['date']) : ''; |
|
210 | + $wpshop_admin_order_payment_received['received_amount'] = !empty($wpshop_admin_order_payment_received['received_amount']) ? sanitize_text_field($wpshop_admin_order_payment_received['received_amount']) : ''; |
|
211 | + $action_triggered_from = !empty($_REQUEST['action_triggered_from']) ? sanitize_text_field($action_triggered_from) : ''; |
|
212 | + $whsop_admin_order_payment_reference = !empty($_REQUEST['wpshop_admin_order_payment_reference']) ? sanitize_text_field($_REQUEST['wpshop_admin_order_payment_reference']) : ''; |
|
213 | 213 | |
214 | 214 | // Add a Payment to Order MetaData |
215 | - if ( !empty($wpshop_admin_order_payment_received['wpshop_admin_order_payment_received']) && !empty($wpshop_admin_order_payment_received['wpshop_admin_order_payment_received']['method']) |
|
215 | + if (!empty($wpshop_admin_order_payment_received['wpshop_admin_order_payment_received']) && !empty($wpshop_admin_order_payment_received['wpshop_admin_order_payment_received']['method']) |
|
216 | 216 | && !empty($wpshop_admin_order_payment_received['wpshop_admin_order_payment_received']['date']) && !empty($wpshop_admin_order_payment_received['wpshop_admin_order_payment_received']['received_amount']) && |
217 | - ( $action_triggered_from == 'add_payment' || !empty($whsop_admin_order_payment_reference) ) ) { |
|
217 | + ($action_triggered_from == 'add_payment' || !empty($whsop_admin_order_payment_reference))) { |
|
218 | 218 | |
219 | 219 | $received_payment_amount = $wpshop_admin_order_payment_received['received_amount']; |
220 | 220 | // Payment Params |
@@ -227,34 +227,34 @@ discard block |
||
227 | 227 | 'date' => current_time('mysql', 0), |
228 | 228 | 'received_amount' => $received_payment_amount |
229 | 229 | ); |
230 | - $order_meta = wpshop_payment::check_order_payment_total_amount($post_ID, $params_array, 'completed', $order_meta, false ); |
|
230 | + $order_meta = wpshop_payment::check_order_payment_total_amount($post_ID, $params_array, 'completed', $order_meta, false); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | //Round final amount |
234 | - $order_meta['order_grand_total'] = number_format( round($order_meta['order_grand_total'], 2), 2, '.', ''); |
|
235 | - $order_meta['order_total_ttc'] = number_format( round($order_meta['order_total_ttc'], 2), 2, '.', ''); |
|
236 | - $order_meta['order_amount_to_pay_now'] = number_format( round($order_meta['order_amount_to_pay_now'], 2), 2, '.', ''); |
|
234 | + $order_meta['order_grand_total'] = number_format(round($order_meta['order_grand_total'], 2), 2, '.', ''); |
|
235 | + $order_meta['order_total_ttc'] = number_format(round($order_meta['order_total_ttc'], 2), 2, '.', ''); |
|
236 | + $order_meta['order_amount_to_pay_now'] = number_format(round($order_meta['order_amount_to_pay_now'], 2), 2, '.', ''); |
|
237 | 237 | |
238 | 238 | // Payment Pre-Fill |
239 | - if ( empty( $order_meta['order_payment'] ) ) { |
|
239 | + if (empty($order_meta['order_payment'])) { |
|
240 | 240 | $order_meta['order_payment']['customer_choice']['method'] = ''; |
241 | - $order_meta['order_payment']['received'][] = array('waited_amount' => ( !empty($order_meta) && !empty($order_meta['order_grand_total']) ) ? number_format($order_meta['order_grand_total'],2,'.', '') : 0 ); |
|
241 | + $order_meta['order_payment']['received'][] = array('waited_amount' => (!empty($order_meta) && !empty($order_meta['order_grand_total'])) ? number_format($order_meta['order_grand_total'], 2, '.', '') : 0); |
|
242 | 242 | } |
243 | 243 | |
244 | - $data['post_ID'] = !empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0; |
|
245 | - $data['markascanceled_order_hidden_indicator'] = !empty( $_REQUEST['markascanceled_order_hidden_indicator' ] ) ? sanitize_text_field( $_REQUEST['markascanceled_order_hidden_indicator'] ) : ''; |
|
246 | - $data['resendordertocustomer_order_hidden_indicator'] = !empty( $_REQUEST['resendordertocustomer_order_hidden_indicator' ] ) ? sanitize_text_field( $_REQUEST['resendordertocustomer_order_hidden_indicator'] ) : ''; |
|
247 | - $data['action_triggered_from'] = !empty( $_REQUEST['action_triggered_from' ] ) ? sanitize_text_field( $_REQUEST['action_triggered_from'] ) : ''; |
|
248 | - $data['notif_the_customer'] = !empty( $_REQUEST['notif_the_customer' ] ) ? sanitize_text_field( $_REQUEST['notif_the_customer'] ) : ''; |
|
244 | + $data['post_ID'] = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0; |
|
245 | + $data['markascanceled_order_hidden_indicator'] = !empty($_REQUEST['markascanceled_order_hidden_indicator']) ? sanitize_text_field($_REQUEST['markascanceled_order_hidden_indicator']) : ''; |
|
246 | + $data['resendordertocustomer_order_hidden_indicator'] = !empty($_REQUEST['resendordertocustomer_order_hidden_indicator']) ? sanitize_text_field($_REQUEST['resendordertocustomer_order_hidden_indicator']) : ''; |
|
247 | + $data['action_triggered_from'] = !empty($_REQUEST['action_triggered_from']) ? sanitize_text_field($_REQUEST['action_triggered_from']) : ''; |
|
248 | + $data['notif_the_customer'] = !empty($_REQUEST['notif_the_customer']) ? sanitize_text_field($_REQUEST['notif_the_customer']) : ''; |
|
249 | 249 | // Apply a filter to make credit, notificate the customer and generate billing actions |
250 | - $order_meta = apply_filters( 'wps_order_saving_admin_extra_action', $order_meta, $data ); |
|
250 | + $order_meta = apply_filters('wps_order_saving_admin_extra_action', $order_meta, $data); |
|
251 | 251 | |
252 | 252 | // Save Shipping informations & Order status |
253 | - update_post_meta( $post_ID, '_wpshop_order_shipping_date', $order_meta['order_shipping_date']); |
|
254 | - update_post_meta( $post_ID, '_wpshop_order_status', $order_meta['order_status']); |
|
253 | + update_post_meta($post_ID, '_wpshop_order_shipping_date', $order_meta['order_shipping_date']); |
|
254 | + update_post_meta($post_ID, '_wpshop_order_status', $order_meta['order_status']); |
|
255 | 255 | |
256 | 256 | // Save Metadata |
257 | - update_post_meta( $post_ID, '_order_postmeta', $order_meta); |
|
257 | + update_post_meta($post_ID, '_order_postmeta', $order_meta); |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | * @param array $posted_datas |
265 | 265 | * @return array |
266 | 266 | */ |
267 | - function wps_notif_user_on_order_saving( $order_metadata, $posted_datas ) { |
|
268 | - if( !empty($posted_datas['notif_the_customer']) && $posted_datas['notif_the_customer']=='on' ) { |
|
267 | + function wps_notif_user_on_order_saving($order_metadata, $posted_datas) { |
|
268 | + if (!empty($posted_datas['notif_the_customer']) && $posted_datas['notif_the_customer'] == 'on') { |
|
269 | 269 | $wps_message = new wps_message_ctr(); |
270 | 270 | /* Get order current content */ |
271 | 271 | $user = get_post_meta($posted_datas['post_ID'], '_order_info', true); |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | $first_name = $user['billing']['address']['address_first_name']; |
275 | 275 | $last_name = $user['billing']['address']['address_last_name']; |
276 | 276 | |
277 | - $object = array('object_type'=>'order','object_id'=>(int)$_REQUEST['post_ID']); |
|
277 | + $object = array('object_type'=>'order', 'object_id'=>(int)$_REQUEST['post_ID']); |
|
278 | 278 | /* Envoie du message de confirmation de commande au client */ |
279 | - if ( empty( $order_metadata['order_key'] ) ) { |
|
279 | + if (empty($order_metadata['order_key'])) { |
|
280 | 280 | $wps_message->wpshop_prepared_email($email, |
281 | 281 | 'WPSHOP_QUOTATION_UPDATE_MESSAGE', |
282 | - array( 'order_id' => $object['object_id'], |
|
282 | + array('order_id' => $object['object_id'], |
|
283 | 283 | 'customer_first_name' => $first_name, |
284 | 284 | 'customer_last_name' => $last_name, |
285 | 285 | 'order_date' => current_time('mysql', 0), |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | $wps_message->wpshop_prepared_email( |
295 | 295 | $email, |
296 | 296 | 'WPSHOP_ORDER_UPDATE_MESSAGE', |
297 | - array( 'customer_first_name' => $first_name, |
|
297 | + array('customer_first_name' => $first_name, |
|
298 | 298 | 'customer_last_name' => $last_name, |
299 | 299 | 'order_key' => $order_metadata['order_key'], |
300 | 300 | 'order_billing_address' => '', |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | 'order_addresses' => '', |
303 | 303 | 'order_addresses' => '', |
304 | 304 | 'order_billing_address' => '', |
305 | - 'order_shipping_address' => '' ), |
|
305 | + 'order_shipping_address' => ''), |
|
306 | 306 | $object); |
307 | 307 | } |
308 | 308 | } |
@@ -313,25 +313,25 @@ discard block |
||
313 | 313 | * AJAX - Add a private comment to order |
314 | 314 | */ |
315 | 315 | function wpshop_add_private_comment_to_order() { |
316 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
316 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
317 | 317 | |
318 | - if ( !wp_verify_nonce( $_wpnonce, 'wpshop_add_private_comment_to_order' ) ) |
|
318 | + if (!wp_verify_nonce($_wpnonce, 'wpshop_add_private_comment_to_order')) |
|
319 | 319 | wp_die(); |
320 | 320 | |
321 | 321 | $status = false; $result = ''; |
322 | - $order_id = ( !empty($_POST['oid']) ) ? intval($_POST['oid']) : null; |
|
323 | - $comment = ( !empty($_POST['comment']) ) ? wpshop_tools::varSanitizer($_POST['comment']) : null; |
|
324 | - $send_email = ( !empty($_POST['send_email']) ) ? wpshop_tools::varSanitizer($_POST['send_email']) : null; |
|
325 | - $copy_to_administrator = ( !empty($_POST['copy_to_administrator']) ) ? wpshop_tools::varSanitizer($_POST['copy_to_administrator']) : null; |
|
322 | + $order_id = (!empty($_POST['oid'])) ? intval($_POST['oid']) : null; |
|
323 | + $comment = (!empty($_POST['comment'])) ? wpshop_tools::varSanitizer($_POST['comment']) : null; |
|
324 | + $send_email = (!empty($_POST['send_email'])) ? wpshop_tools::varSanitizer($_POST['send_email']) : null; |
|
325 | + $copy_to_administrator = (!empty($_POST['copy_to_administrator'])) ? wpshop_tools::varSanitizer($_POST['copy_to_administrator']) : null; |
|
326 | 326 | |
327 | - if ( !empty($comment) && !empty($order_id) ) { |
|
327 | + if (!empty($comment) && !empty($order_id)) { |
|
328 | 328 | $wps_back_office_orders_mdl = new wps_back_office_orders_mdl(); |
329 | - $new_comment = $wps_back_office_orders_mdl->add_private_comment($order_id, $comment, $send_email, false, $copy_to_administrator ); |
|
330 | - if($new_comment) { |
|
331 | - $order_private_comment = get_post_meta( $order_id, '_order_private_comments', true ); |
|
329 | + $new_comment = $wps_back_office_orders_mdl->add_private_comment($order_id, $comment, $send_email, false, $copy_to_administrator); |
|
330 | + if ($new_comment) { |
|
331 | + $order_private_comment = get_post_meta($order_id, '_order_private_comments', true); |
|
332 | 332 | $oid = $order_id; |
333 | 333 | ob_start(); |
334 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_sended_private_comments") ); |
|
334 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "order-private-comments/wps_orders_sended_private_comments")); |
|
335 | 335 | $result = ob_get_contents(); |
336 | 336 | ob_end_clean(); |
337 | 337 | $status = true; |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | $result = __('An error was occured', 'wpshop'); |
342 | 342 | } |
343 | 343 | |
344 | - $response = array( 'status' => $status, 'response' => $result ); |
|
345 | - echo json_encode( $response ); |
|
344 | + $response = array('status' => $status, 'response' => $result); |
|
345 | + echo json_encode($response); |
|
346 | 346 | wp_die(); |
347 | 347 | } |
348 | 348 | |
@@ -350,29 +350,29 @@ discard block |
||
350 | 350 | * AJAX - Refresh product listing in order back-office |
351 | 351 | */ |
352 | 352 | function refresh_product_list() { |
353 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
353 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
354 | 354 | |
355 | - if ( !wp_verify_nonce( $_wpnonce, 'refresh_product_list' ) ) |
|
355 | + if (!wp_verify_nonce($_wpnonce, 'refresh_product_list')) |
|
356 | 356 | wp_die(); |
357 | 357 | |
358 | 358 | $status = false; $response = ''; |
359 | - $letter = ( !empty($_POST['letter']) ) ? sanitize_title( $_POST['letter'] ) : ''; |
|
360 | - $oid = !empty( $_POST['oid'] ) ? (int) $_POST['oid'] : 0; |
|
359 | + $letter = (!empty($_POST['letter'])) ? sanitize_title($_POST['letter']) : ''; |
|
360 | + $oid = !empty($_POST['oid']) ? (int)$_POST['oid'] : 0; |
|
361 | 361 | |
362 | - if( !empty($oid) ) { |
|
363 | - $post = get_post( $oid ); |
|
362 | + if (!empty($oid)) { |
|
363 | + $post = get_post($oid); |
|
364 | 364 | } |
365 | - if( !empty($letter) ) { |
|
365 | + if (!empty($letter)) { |
|
366 | 366 | $current_letter = $letter; |
367 | 367 | $wps_product_mdl = new wps_product_mdl(); |
368 | - $products = $wps_product_mdl->get_products_by_letter( $letter ); |
|
368 | + $products = $wps_product_mdl->get_products_by_letter($letter); |
|
369 | 369 | ob_start(); |
370 | - require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing_table") ); |
|
370 | + require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "backend", "product-listing/wps_orders_product_listing_table")); |
|
371 | 371 | $response = ob_get_contents(); |
372 | 372 | ob_end_clean(); |
373 | 373 | $status = true; |
374 | 374 | } |
375 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
375 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
376 | 376 | wp_die(); |
377 | 377 | } |
378 | 378 | |
@@ -380,41 +380,41 @@ discard block |
||
380 | 380 | * AJAX - Add product to order in back-office panel |
381 | 381 | */ |
382 | 382 | function wps_add_product_to_order_admin() { |
383 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
383 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
384 | 384 | |
385 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_add_product_to_order_admin' ) ) |
|
385 | + if (!wp_verify_nonce($_wpnonce, 'wps_add_product_to_order_admin')) |
|
386 | 386 | wp_die(); |
387 | 387 | |
388 | 388 | $status = false; $response = ''; $product_have_variations = false; |
389 | 389 | // Sended vars |
390 | - $product_id = ( !empty($_POST['pid']) ) ? intval( $_POST['pid']) : null; |
|
391 | - $order_id = ( !empty($_POST['oid']) ) ? intval( $_POST['oid']) : null; |
|
392 | - $product_qty = ( !empty($_POST['qty']) ) ? intval( $_POST['qty']) : 1; |
|
390 | + $product_id = (!empty($_POST['pid'])) ? intval($_POST['pid']) : null; |
|
391 | + $order_id = (!empty($_POST['oid'])) ? intval($_POST['oid']) : null; |
|
392 | + $product_qty = (!empty($_POST['qty'])) ? intval($_POST['qty']) : 1; |
|
393 | 393 | |
394 | - if( !empty($order_id) && !empty($product_id) ) { |
|
394 | + if (!empty($order_id) && !empty($product_id)) { |
|
395 | 395 | $wps_orders = new wps_orders_ctr(); |
396 | 396 | $product_datas = wpshop_products::get_product_data($product_id, false, '"publish", "free_product"'); |
397 | 397 | // Check if product have variations |
398 | - $have_variations_checking = wpshop_products::get_variation( $product_id ); |
|
399 | - if( !empty($have_variations_checking) ) { |
|
398 | + $have_variations_checking = wpshop_products::get_variation($product_id); |
|
399 | + if (!empty($have_variations_checking)) { |
|
400 | 400 | $product_have_variations = true; |
401 | 401 | } |
402 | 402 | else { |
403 | 403 | // Get Metadatas |
404 | - $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
|
404 | + $order_metadata = get_post_meta($order_id, '_order_postmeta', true); |
|
405 | 405 | // Calcul cart informations |
406 | 406 | $wps_cart = new wps_cart(); |
407 | - $order_metadata = $wps_cart->calcul_cart_information( array( $product_id => array( 'product_id' => $product_id, 'product_qty' => $product_qty ) ), '', $order_metadata, true, false ); |
|
407 | + $order_metadata = $wps_cart->calcul_cart_information(array($product_id => array('product_id' => $product_id, 'product_qty' => $product_qty)), '', $order_metadata, true, false); |
|
408 | 408 | // Update Metadatas |
409 | - update_post_meta( $order_id, '_order_postmeta', $order_metadata ); |
|
409 | + update_post_meta($order_id, '_order_postmeta', $order_metadata); |
|
410 | 410 | $status = true; |
411 | 411 | } |
412 | 412 | $status = true; |
413 | 413 | } |
414 | 414 | |
415 | - $_wpnonce = wp_create_nonce( 'wps_order_load_product_variations' ); |
|
415 | + $_wpnonce = wp_create_nonce('wps_order_load_product_variations'); |
|
416 | 416 | |
417 | - echo json_encode( array( '_wpnonce' => $_wpnonce, 'status' => $status, 'response' => $response, 'variations_exist' => $product_have_variations ) ); |
|
417 | + echo json_encode(array('_wpnonce' => $_wpnonce, 'status' => $status, 'response' => $response, 'variations_exist' => $product_have_variations)); |
|
418 | 418 | wp_die(); |
419 | 419 | } |
420 | 420 | |
@@ -422,18 +422,18 @@ discard block |
||
422 | 422 | * AJAX - Refresh cart in administration |
423 | 423 | */ |
424 | 424 | function refresh_cart_order() { |
425 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
425 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
426 | 426 | |
427 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) |
|
427 | + if (!wp_verify_nonce($_wpnonce, 'wps_pos_order_content')) |
|
428 | 428 | wp_die(); |
429 | 429 | |
430 | 430 | $status = false; $response = ''; |
431 | - $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null; |
|
432 | - if( !empty($order_id) ) { |
|
433 | - $response = do_shortcode( '[wps_cart oid="' .$order_id. '" cart_type="admin-panel"]'); |
|
431 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null; |
|
432 | + if (!empty($order_id)) { |
|
433 | + $response = do_shortcode('[wps_cart oid="' . $order_id . '" cart_type="admin-panel"]'); |
|
434 | 434 | $status = true; |
435 | 435 | } |
436 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
436 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
437 | 437 | wp_die(); |
438 | 438 | } |
439 | 439 | |
@@ -441,21 +441,21 @@ discard block |
||
441 | 441 | * AJAX - Refresh cart in administration |
442 | 442 | */ |
443 | 443 | function refresh_payments_order() { |
444 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
444 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
445 | 445 | |
446 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) |
|
446 | + if (!wp_verify_nonce($_wpnonce, 'wps_pos_order_content')) |
|
447 | 447 | wp_die(); |
448 | 448 | |
449 | 449 | $status = false; $response = ''; |
450 | - $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null; |
|
451 | - if( !empty($order_id) ) { |
|
450 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null; |
|
451 | + if (!empty($order_id)) { |
|
452 | 452 | ob_start(); |
453 | - echo $this->display_order_payments_box( get_post( $order_id ) ); |
|
453 | + echo $this->display_order_payments_box(get_post($order_id)); |
|
454 | 454 | $response = ob_get_contents(); |
455 | 455 | ob_end_clean(); |
456 | 456 | $status = true; |
457 | 457 | } |
458 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
458 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
459 | 459 | wp_die(); |
460 | 460 | } |
461 | 461 | |
@@ -463,28 +463,28 @@ discard block |
||
463 | 463 | * AJAX - Update product Quantity in Back-office Panel |
464 | 464 | */ |
465 | 465 | function wps_update_product_qty_in_admin() { |
466 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
466 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
467 | 467 | |
468 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) |
|
468 | + if (!wp_verify_nonce($_wpnonce, 'wps_pos_order_content')) |
|
469 | 469 | wp_die(); |
470 | 470 | |
471 | 471 | $status = false; $response = ''; |
472 | - $product_id = ( !empty($_POST['product_id']) ) ? wpshop_tools::varSanitizer( $_POST['product_id'] ) : null; |
|
473 | - $order_id = ( !empty($_POST['order_id']) ) ? intval( $_POST['order_id'] ) : null; |
|
474 | - $product_qty = ( !empty($_POST['qty']) ) ? intval( $_POST['qty'] ) : 0; |
|
472 | + $product_id = (!empty($_POST['product_id'])) ? wpshop_tools::varSanitizer($_POST['product_id']) : null; |
|
473 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : null; |
|
474 | + $product_qty = (!empty($_POST['qty'])) ? intval($_POST['qty']) : 0; |
|
475 | 475 | |
476 | - if( !empty($product_id) && !empty($order_id) ) { |
|
476 | + if (!empty($product_id) && !empty($order_id)) { |
|
477 | 477 | // Get Metadatas |
478 | - $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
|
478 | + $order_metadata = get_post_meta($order_id, '_order_postmeta', true); |
|
479 | 479 | // Calcul cart informations |
480 | 480 | $wps_cart = new wps_cart(); |
481 | - $order_metadata = $wps_cart->calcul_cart_information( array( $product_id => array( 'product_id' => $product_id, 'product_qty' => $product_qty ) ), '', $order_metadata, true, false ); |
|
481 | + $order_metadata = $wps_cart->calcul_cart_information(array($product_id => array('product_id' => $product_id, 'product_qty' => $product_qty)), '', $order_metadata, true, false); |
|
482 | 482 | // Update Metadatas |
483 | - update_post_meta( $order_id, '_order_postmeta', $order_metadata ); |
|
483 | + update_post_meta($order_id, '_order_postmeta', $order_metadata); |
|
484 | 484 | $status = true; |
485 | 485 | } |
486 | 486 | |
487 | - echo json_encode( array( 'status' => $status ) ); |
|
487 | + echo json_encode(array('status' => $status)); |
|
488 | 488 | wp_die(); |
489 | 489 | } |
490 | 490 | |
@@ -492,15 +492,15 @@ discard block |
||
492 | 492 | * AJAX - Load Product Variations in ThickBox on Add product to order action |
493 | 493 | */ |
494 | 494 | function wps_order_load_product_variations() { |
495 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
495 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
496 | 496 | |
497 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_order_load_product_variations' ) ) |
|
497 | + if (!wp_verify_nonce($_wpnonce, 'wps_order_load_product_variations')) |
|
498 | 498 | wp_die(); |
499 | 499 | |
500 | - $product_id = ( !empty($_GET['pid']) ) ? intval( $_GET['pid']) : null; |
|
501 | - $order_id = ( !empty($_GET['oid']) ) ? intval( $_GET['oid']) : null; |
|
502 | - $qty = ( !empty($_GET['qty']) ) ? intval( $_GET['qty']) : 1; |
|
503 | - echo '<div class="wps-boxed"><span class="wps-h5">'.__( 'Select your variations', 'wpshop' ).'</span>'.wpshop_products::wpshop_variation($product_id, true, $order_id, $qty ).'<a href="#" class="wps-bton-first-mini-rounded alignRight wps-orders-add_variation_product"><i class="wps-icon-basket"></i> ' .__( 'Add to cart', 'wpshop' ). '</a>'.'</div>'; |
|
500 | + $product_id = (!empty($_GET['pid'])) ? intval($_GET['pid']) : null; |
|
501 | + $order_id = (!empty($_GET['oid'])) ? intval($_GET['oid']) : null; |
|
502 | + $qty = (!empty($_GET['qty'])) ? intval($_GET['qty']) : 1; |
|
503 | + echo '<div class="wps-boxed"><span class="wps-h5">' . __('Select your variations', 'wpshop') . '</span>' . wpshop_products::wpshop_variation($product_id, true, $order_id, $qty) . '<a href="#" class="wps-bton-first-mini-rounded alignRight wps-orders-add_variation_product"><i class="wps-icon-basket"></i> ' . __('Add to cart', 'wpshop') . '</a>' . '</div>'; |
|
504 | 504 | wp_die(); |
505 | 505 | } |
506 | 506 | |
@@ -508,67 +508,67 @@ discard block |
||
508 | 508 | * AJAX - Update cart informations |
509 | 509 | */ |
510 | 510 | function wps_orders_update_cart_informations() { |
511 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
511 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
512 | 512 | |
513 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_update_cart_informations' ) ) |
|
513 | + if (!wp_verify_nonce($_wpnonce, 'wps_orders_update_cart_informations')) |
|
514 | 514 | wp_die(); |
515 | 515 | |
516 | 516 | $status = false; |
517 | - $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : ''; |
|
518 | - $shipping_cost = ( !empty($_POST['shipping_cost']) ) ? wpshop_tools::varSanitizer($_POST['shipping_cost']) : ''; |
|
519 | - $discount_value = ( !empty($_POST['discount_amount']) ) ? wpshop_tools::varSanitizer($_POST['discount_amount']) : ''; |
|
520 | - $discount_type = ( !empty($_POST['discount_type']) ) ? wpshop_tools::varSanitizer($_POST['discount_type']) : ''; |
|
517 | + $order_id = (!empty($_POST['order_id'])) ? intval($_POST['order_id']) : ''; |
|
518 | + $shipping_cost = (!empty($_POST['shipping_cost'])) ? wpshop_tools::varSanitizer($_POST['shipping_cost']) : ''; |
|
519 | + $discount_value = (!empty($_POST['discount_amount'])) ? wpshop_tools::varSanitizer($_POST['discount_amount']) : ''; |
|
520 | + $discount_type = (!empty($_POST['discount_type'])) ? wpshop_tools::varSanitizer($_POST['discount_type']) : ''; |
|
521 | 521 | |
522 | 522 | |
523 | - if( !empty($order_id) ) { |
|
524 | - $order_meta = get_post_meta( $order_id, '_order_postmeta', true ); |
|
523 | + if (!empty($order_id)) { |
|
524 | + $order_meta = get_post_meta($order_id, '_order_postmeta', true); |
|
525 | 525 | $order_meta['order_shipping_cost'] = $shipping_cost; |
526 | 526 | |
527 | 527 | //Add discounts if exists |
528 | - if( !empty($discount_value) && !empty($discount_type) ) { |
|
528 | + if (!empty($discount_value) && !empty($discount_type)) { |
|
529 | 529 | $order_meta['order_discount_type'] = $discount_type; |
530 | 530 | $order_meta['order_discount_value'] = $discount_value; |
531 | 531 | } |
532 | 532 | $wps_cart = new wps_cart(); |
533 | - $order_meta = $wps_cart->calcul_cart_information( array(), '', $order_meta, true ); |
|
534 | - update_post_meta( $order_id, '_order_postmeta', $order_meta ); |
|
533 | + $order_meta = $wps_cart->calcul_cart_information(array(), '', $order_meta, true); |
|
534 | + update_post_meta($order_id, '_order_postmeta', $order_meta); |
|
535 | 535 | $status = true; |
536 | 536 | } |
537 | 537 | |
538 | - echo json_encode( array( 'status' => $status) ); |
|
538 | + echo json_encode(array('status' => $status)); |
|
539 | 539 | wp_die(); |
540 | 540 | } |
541 | 541 | |
542 | 542 | function wps_reverify_payment_invoice_ref() { |
543 | - $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
543 | + $_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
544 | 544 | |
545 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reverify_payment_invoice_ref' ) ) |
|
545 | + if (!wp_verify_nonce($_wpnonce, 'wps_reverify_payment_invoice_ref')) |
|
546 | 546 | wp_die(); |
547 | 547 | |
548 | 548 | $status = true; |
549 | - $inputs = !empty( $_POST['inputs'] ) ? (array) $_POST['inputs'] : false; |
|
549 | + $inputs = !empty($_POST['inputs']) ? (array)$_POST['inputs'] : false; |
|
550 | 550 | |
551 | 551 | if (!$inputs) |
552 | 552 | $status = false; |
553 | 553 | |
554 | - if( $status ) { |
|
554 | + if ($status) { |
|
555 | 555 | $inputs_clone = $inputs; |
556 | 556 | $inputs = array(); |
557 | - foreach( $inputs_clone as $var ) { |
|
558 | - if( isset( $var['key'] ) && isset( $var['value'] ) ) { |
|
557 | + foreach ($inputs_clone as $var) { |
|
558 | + if (isset($var['key']) && isset($var['value'])) { |
|
559 | 559 | $inputs[$var['key']] = $var['value']; |
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | - ( isset( $inputs['order_id'] ) ) ? $order_id = $inputs['order_id'] : $status = $order_id = false; |
|
564 | - ( isset( $inputs['index_payment'] ) ) ? $index_payment = $inputs['index_payment'] : $status = $index_payment = false; |
|
563 | + (isset($inputs['order_id'])) ? $order_id = $inputs['order_id'] : $status = $order_id = false; |
|
564 | + (isset($inputs['index_payment'])) ? $index_payment = $inputs['index_payment'] : $status = $index_payment = false; |
|
565 | 565 | } |
566 | 566 | |
567 | - if( $status ) { |
|
568 | - $status = wpshop_payment::reverify_payment_invoice_ref( $order_id, $index_payment ); |
|
567 | + if ($status) { |
|
568 | + $status = wpshop_payment::reverify_payment_invoice_ref($order_id, $index_payment); |
|
569 | 569 | } |
570 | 570 | |
571 | - echo json_encode( array( 'status' => $status ) ); |
|
571 | + echo json_encode(array('status' => $status)); |
|
572 | 572 | wp_die(); |
573 | 573 | } |
574 | 574 | } |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | class wps_orders_in_back_office { |
3 | 5 | |
4 | 6 | function __construct() { |
@@ -289,8 +291,7 @@ discard block |
||
289 | 291 | 'order_shipping_address' => '' |
290 | 292 | ) |
291 | 293 | ); |
292 | - } |
|
293 | - else { |
|
294 | + } else { |
|
294 | 295 | $wps_message->wpshop_prepared_email( |
295 | 296 | $email, |
296 | 297 | 'WPSHOP_ORDER_UPDATE_MESSAGE', |
@@ -315,8 +316,9 @@ discard block |
||
315 | 316 | function wpshop_add_private_comment_to_order() { |
316 | 317 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
317 | 318 | |
318 | - if ( !wp_verify_nonce( $_wpnonce, 'wpshop_add_private_comment_to_order' ) ) |
|
319 | - wp_die(); |
|
319 | + if ( !wp_verify_nonce( $_wpnonce, 'wpshop_add_private_comment_to_order' ) ) { |
|
320 | + wp_die(); |
|
321 | + } |
|
320 | 322 | |
321 | 323 | $status = false; $result = ''; |
322 | 324 | $order_id = ( !empty($_POST['oid']) ) ? intval($_POST['oid']) : null; |
@@ -336,8 +338,7 @@ discard block |
||
336 | 338 | ob_end_clean(); |
337 | 339 | $status = true; |
338 | 340 | } |
339 | - } |
|
340 | - else { |
|
341 | + } else { |
|
341 | 342 | $result = __('An error was occured', 'wpshop'); |
342 | 343 | } |
343 | 344 | |
@@ -352,8 +353,9 @@ discard block |
||
352 | 353 | function refresh_product_list() { |
353 | 354 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
354 | 355 | |
355 | - if ( !wp_verify_nonce( $_wpnonce, 'refresh_product_list' ) ) |
|
356 | - wp_die(); |
|
356 | + if ( !wp_verify_nonce( $_wpnonce, 'refresh_product_list' ) ) { |
|
357 | + wp_die(); |
|
358 | + } |
|
357 | 359 | |
358 | 360 | $status = false; $response = ''; |
359 | 361 | $letter = ( !empty($_POST['letter']) ) ? sanitize_title( $_POST['letter'] ) : ''; |
@@ -382,8 +384,9 @@ discard block |
||
382 | 384 | function wps_add_product_to_order_admin() { |
383 | 385 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
384 | 386 | |
385 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_add_product_to_order_admin' ) ) |
|
386 | - wp_die(); |
|
387 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_add_product_to_order_admin' ) ) { |
|
388 | + wp_die(); |
|
389 | + } |
|
387 | 390 | |
388 | 391 | $status = false; $response = ''; $product_have_variations = false; |
389 | 392 | // Sended vars |
@@ -398,8 +401,7 @@ discard block |
||
398 | 401 | $have_variations_checking = wpshop_products::get_variation( $product_id ); |
399 | 402 | if( !empty($have_variations_checking) ) { |
400 | 403 | $product_have_variations = true; |
401 | - } |
|
402 | - else { |
|
404 | + } else { |
|
403 | 405 | // Get Metadatas |
404 | 406 | $order_metadata = get_post_meta( $order_id, '_order_postmeta', true ); |
405 | 407 | // Calcul cart informations |
@@ -424,8 +426,9 @@ discard block |
||
424 | 426 | function refresh_cart_order() { |
425 | 427 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
426 | 428 | |
427 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) |
|
428 | - wp_die(); |
|
429 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) { |
|
430 | + wp_die(); |
|
431 | + } |
|
429 | 432 | |
430 | 433 | $status = false; $response = ''; |
431 | 434 | $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null; |
@@ -443,8 +446,9 @@ discard block |
||
443 | 446 | function refresh_payments_order() { |
444 | 447 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
445 | 448 | |
446 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) |
|
447 | - wp_die(); |
|
449 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) { |
|
450 | + wp_die(); |
|
451 | + } |
|
448 | 452 | |
449 | 453 | $status = false; $response = ''; |
450 | 454 | $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : null; |
@@ -465,8 +469,9 @@ discard block |
||
465 | 469 | function wps_update_product_qty_in_admin() { |
466 | 470 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
467 | 471 | |
468 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) |
|
469 | - wp_die(); |
|
472 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_pos_order_content' ) ) { |
|
473 | + wp_die(); |
|
474 | + } |
|
470 | 475 | |
471 | 476 | $status = false; $response = ''; |
472 | 477 | $product_id = ( !empty($_POST['product_id']) ) ? wpshop_tools::varSanitizer( $_POST['product_id'] ) : null; |
@@ -494,8 +499,9 @@ discard block |
||
494 | 499 | function wps_order_load_product_variations() { |
495 | 500 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
496 | 501 | |
497 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_order_load_product_variations' ) ) |
|
498 | - wp_die(); |
|
502 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_order_load_product_variations' ) ) { |
|
503 | + wp_die(); |
|
504 | + } |
|
499 | 505 | |
500 | 506 | $product_id = ( !empty($_GET['pid']) ) ? intval( $_GET['pid']) : null; |
501 | 507 | $order_id = ( !empty($_GET['oid']) ) ? intval( $_GET['oid']) : null; |
@@ -510,8 +516,9 @@ discard block |
||
510 | 516 | function wps_orders_update_cart_informations() { |
511 | 517 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
512 | 518 | |
513 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_update_cart_informations' ) ) |
|
514 | - wp_die(); |
|
519 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_update_cart_informations' ) ) { |
|
520 | + wp_die(); |
|
521 | + } |
|
515 | 522 | |
516 | 523 | $status = false; |
517 | 524 | $order_id = ( !empty($_POST['order_id']) ) ? intval($_POST['order_id']) : ''; |
@@ -542,14 +549,16 @@ discard block |
||
542 | 549 | function wps_reverify_payment_invoice_ref() { |
543 | 550 | $_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
544 | 551 | |
545 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reverify_payment_invoice_ref' ) ) |
|
546 | - wp_die(); |
|
552 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_reverify_payment_invoice_ref' ) ) { |
|
553 | + wp_die(); |
|
554 | + } |
|
547 | 555 | |
548 | 556 | $status = true; |
549 | 557 | $inputs = !empty( $_POST['inputs'] ) ? (array) $_POST['inputs'] : false; |
550 | 558 | |
551 | - if (!$inputs) |
|
552 | - $status = false; |
|
559 | + if (!$inputs) { |
|
560 | + $status = false; |
|
561 | + } |
|
553 | 562 | |
554 | 563 | if( $status ) { |
555 | 564 | $inputs_clone = $inputs; |