@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | $mustache_template = self::TagCleaner($mustache_template); |
11 | 11 | } |
12 | 12 | |
13 | - $m = new \Mustache_Engine(['escape' => function ($value) { |
|
13 | + $m = new \Mustache_Engine(['escape' => function($value) { |
|
14 | 14 | if (str_replace('*[[DONOTESCAPE]]*', '', $value) != $value) { |
15 | 15 | return str_replace('*[[DONOTESCAPE]]*', '', $value); |
16 | 16 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | return preg_replace_callback( |
33 | 33 | '/{{(.*?)}}/', |
34 | - function ($match) { |
|
34 | + function($match) { |
|
35 | 35 | return strip_tags($match[0]); |
36 | 36 | }, |
37 | 37 | preg_replace("/(?<!{){(?!{)<\/w:t>[\s\S]*?<w:t>{/", '{{', $content) |
@@ -14,6 +14,9 @@ discard block |
||
14 | 14 | ]; |
15 | 15 | } |
16 | 16 | |
17 | + /** |
|
18 | + * @param string $manipulation |
|
19 | + */ |
|
17 | 20 | public function GetImageFromUrl($url, $manipulation) |
18 | 21 | { |
19 | 22 | $allowed_imgs = $this->AllowedContentTypeImages(); |
@@ -37,6 +40,10 @@ discard block |
||
37 | 40 | return false; |
38 | 41 | } |
39 | 42 | |
43 | + /** |
|
44 | + * @param DocxMustache $parent |
|
45 | + * @param string $data |
|
46 | + */ |
|
40 | 47 | public function ResampleImage($parent, $imgs, $k, $data) |
41 | 48 | { |
42 | 49 | \Storage::disk($parent->storageDisk)->put($parent->local_path.'word/media/'.$imgs[$k]['img_file_src'], $data); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $w = (($imgWidth / $imgHeight) * $h); |
55 | 55 | |
56 | 56 | //if height based resize has too large width, do width based resize |
57 | - if ($w>$availableWidth) |
|
57 | + if ($w > $availableWidth) |
|
58 | 58 | { |
59 | 59 | $w = (($imgWidth / $imgHeight) * $availableWidth); |
60 | 60 | $h = (($imgHeight / $imgWidth) * $w); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | //only resize one value, aspectRatio() takes care of the other |
64 | 64 | $h = null; |
65 | 65 | |
66 | - $img_rework->resize($w, $h, function ($constraint) { |
|
66 | + $img_rework->resize($w, $h, function($constraint) { |
|
67 | 67 | $constraint->aspectRatio(); |
68 | 68 | $constraint->upsize(); |
69 | 69 | }); |
@@ -18,9 +18,10 @@ |
||
18 | 18 | { |
19 | 19 | $allowed_imgs = $this->AllowedContentTypeImages(); |
20 | 20 | |
21 | - if (trim($url)) |
|
22 | - if ($img_file_handle = @fopen($url.$manipulation, 'rb')) { |
|
21 | + if (trim($url)) { |
|
22 | + if ($img_file_handle = @fopen($url.$manipulation, 'rb')) { |
|
23 | 23 | $img_data = stream_get_contents($img_file_handle); |
24 | + } |
|
24 | 25 | fclose($img_file_handle); |
25 | 26 | $fi = new \finfo(FILEINFO_MIME); |
26 | 27 |
@@ -101,6 +101,9 @@ discard block |
||
101 | 101 | ->extractTo($this->StoragePath($this->local_path), [$file], \Chumper\Zipper\Zipper::WHITELIST); |
102 | 102 | } |
103 | 103 | |
104 | + /** |
|
105 | + * @param string $file |
|
106 | + */ |
|
104 | 107 | protected function ReadOpenXmlFile($file, $type = 'file') |
105 | 108 | { |
106 | 109 | $this->exctractOpenXmlFile($file); |
@@ -134,6 +137,10 @@ discard block |
||
134 | 137 | } |
135 | 138 | } |
136 | 139 | |
140 | + /** |
|
141 | + * @param string $file |
|
142 | + * @param false|string $folder |
|
143 | + */ |
|
137 | 144 | protected function SaveOpenXmlObjectToFile($xmlObject, $file, $folder) |
138 | 145 | { |
139 | 146 | if ($xmlString = $xmlObject->asXML()) { |
@@ -191,6 +198,9 @@ discard block |
||
191 | 198 | } |
192 | 199 | } |
193 | 200 | |
201 | + /** |
|
202 | + * @param \SimpleXMLElement $main_file |
|
203 | + */ |
|
194 | 204 | protected function FetchReplaceableImages(&$main_file, $ns) |
195 | 205 | { |
196 | 206 | //set up basic arrays to keep track of imgs |
@@ -343,38 +343,38 @@ |
||
343 | 343 | /** |
344 | 344 | * @param string $string |
345 | 345 | */ |
346 | - protected function AnalyseImgUrlString($string) |
|
347 | - { |
|
348 | - $start = '[IMG-REPLACE]'; |
|
349 | - $end = '[/IMG-REPLACE]'; |
|
350 | - |
|
351 | - if($string!=str_replace($start,'',$string) && $string==str_replace($start.$end,'',$string)) |
|
352 | - { |
|
353 | - $string = ' '.$string; |
|
354 | - $ini = strpos($string, $start); |
|
355 | - if ($ini == 0) { |
|
356 | - $url = ''; |
|
357 | - $rest = $string; |
|
358 | - } else { |
|
359 | - $ini += strlen($start); |
|
360 | - $len = ((strpos($string, $end, $ini)) - $ini); |
|
361 | - $url = substr($string, $ini, $len); |
|
362 | - |
|
363 | - $ini = strpos($string, $start); |
|
364 | - $len = strpos($string, $end, $ini + strlen($start)) + strlen($end); |
|
365 | - $rest = substr($string, 0, $ini).substr($string, $len); |
|
366 | - } |
|
367 | - } |
|
368 | - else { |
|
369 | - $url = ''; |
|
370 | - $rest = str_replace(array($start,$end),'',$string); |
|
371 | - } |
|
372 | - |
|
373 | - return [ |
|
374 | - 'url' => trim($url), |
|
375 | - 'rest' => trim($rest), |
|
376 | - ]; |
|
377 | - } |
|
346 | + protected function AnalyseImgUrlString($string) |
|
347 | + { |
|
348 | + $start = '[IMG-REPLACE]'; |
|
349 | + $end = '[/IMG-REPLACE]'; |
|
350 | + |
|
351 | + if($string!=str_replace($start,'',$string) && $string==str_replace($start.$end,'',$string)) |
|
352 | + { |
|
353 | + $string = ' '.$string; |
|
354 | + $ini = strpos($string, $start); |
|
355 | + if ($ini == 0) { |
|
356 | + $url = ''; |
|
357 | + $rest = $string; |
|
358 | + } else { |
|
359 | + $ini += strlen($start); |
|
360 | + $len = ((strpos($string, $end, $ini)) - $ini); |
|
361 | + $url = substr($string, $ini, $len); |
|
362 | + |
|
363 | + $ini = strpos($string, $start); |
|
364 | + $len = strpos($string, $end, $ini + strlen($start)) + strlen($end); |
|
365 | + $rest = substr($string, 0, $ini).substr($string, $len); |
|
366 | + } |
|
367 | + } |
|
368 | + else { |
|
369 | + $url = ''; |
|
370 | + $rest = str_replace(array($start,$end),'',$string); |
|
371 | + } |
|
372 | + |
|
373 | + return [ |
|
374 | + 'url' => trim($url), |
|
375 | + 'rest' => trim($rest), |
|
376 | + ]; |
|
377 | + } |
|
378 | 378 | |
379 | 379 | public function SaveAsPdf() |
380 | 380 | { |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | $ct_file = $this->ReadOpenXmlFile('[Content_Types].xml', 'object'); |
169 | 169 | |
170 | - if (! ($ct_file instanceof \Traversable)) { |
|
170 | + if (!($ct_file instanceof \Traversable)) { |
|
171 | 171 | throw new Exception('Cannot traverse through [Content_Types].xml.'); |
172 | 172 | } |
173 | 173 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | |
184 | 184 | //if content type for jpg has not been set, add it to xml |
185 | 185 | // and save xml to file and add it to the archive |
186 | - if (! $ct_already_set) { |
|
186 | + if (!$ct_already_set) { |
|
187 | 187 | $sxe = $ct_file->addChild('Default'); |
188 | 188 | $sxe->addAttribute('Extension', $imageCt); |
189 | 189 | $sxe->addAttribute('ContentType', 'image/'.$imageCt); |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $start = '[IMG-REPLACE]'; |
349 | 349 | $end = '[/IMG-REPLACE]'; |
350 | 350 | |
351 | - if($string!=str_replace($start,'',$string) && $string==str_replace($start.$end,'',$string)) |
|
351 | + if ($string != str_replace($start, '', $string) && $string == str_replace($start.$end, '', $string)) |
|
352 | 352 | { |
353 | 353 | $string = ' '.$string; |
354 | 354 | $ini = strpos($string, $start); |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | } |
368 | 368 | else { |
369 | 369 | $url = ''; |
370 | - $rest = str_replace(array($start,$end),'',$string); |
|
370 | + $rest = str_replace(array($start, $end), '', $string); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | return [ |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | //wait until process is ready |
388 | 388 | } |
389 | 389 | // executes after the command finishes |
390 | - if (! $process->isSuccessful()) { |
|
390 | + if (!$process->isSuccessful()) { |
|
391 | 391 | throw new \Symfony\Component\Process\Exception\ProcessFailedException($process); |
392 | 392 | } else { |
393 | 393 | $path_parts = pathinfo($this->StoragePath($this->local_path.$this->template_file_name)); |
@@ -364,8 +364,7 @@ |
||
364 | 364 | $len = strpos($string, $end, $ini + strlen($start)) + strlen($end); |
365 | 365 | $rest = substr($string, 0, $ini).substr($string, $len); |
366 | 366 | } |
367 | - } |
|
368 | - else { |
|
367 | + } else { |
|
369 | 368 | $url = ''; |
370 | 369 | $rest = str_replace(array($start,$end),'',$string); |
371 | 370 | } |