@@ -74,7 +74,7 @@ class TemplateProcessor
74
74
*
75
75
* @var string
76
76
*/
77
- protected $ tempDocumentContentTypes = "" ;
77
+ protected $ tempDocumentContentTypes = '' ;
78
78
79
79
/**
80
80
* new inserted images list
@@ -134,6 +134,7 @@ protected function readPartWithRels($fileName)
134
134
if ($ partRelations !== false ) {
135
135
$ this ->tempDocumentRelations [$ fileName ] = $ partRelations ;
136
136
}
137
+
137
138
return $ this ->fixBrokenMacros ($ this ->zipClass ->getFromName ($ fileName ));
138
139
}
139
140
@@ -269,9 +270,7 @@ public function setValue($search, $replace, $limit = self::MAXIMUM_REPLACEMENTS_
269
270
/**
270
271
* @param mixed $search
271
272
* @param mixed $replace Path to image, or array("path" => xx, "width" => yy, "height" => zz)
272
- * @param integer $limit
273
- *
274
- * @return void
273
+ * @param int $limit
275
274
*/
276
275
public function setImageValue ($ search , $ replace , $ limit = self ::MAXIMUM_REPLACEMENTS_DEFAULT )
277
276
{
@@ -281,7 +280,7 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
281
280
}
282
281
283
282
$ replacesList = array ();
284
- if (!is_array ($ replace ) || isset ($ replace [" path " ])) {
283
+ if (!is_array ($ replace ) || isset ($ replace [' path ' ])) {
285
284
$ replacesList [] = $ replace ;
286
285
} else {
287
286
$ replacesList = array_values ($ replace );
@@ -291,31 +290,29 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
291
290
foreach ($ search as $ searchIdx => $ searchString ) {
292
291
$ searchReplace [$ searchString ] = isset ($ replacesList [$ searchIdx ]) ? $ replacesList [$ searchIdx ] : $ replacesList [0 ];
293
292
}
294
- //
295
293
296
294
// define templates
297
295
// result can be verified via "Open XML SDK 2.5 Productivity Tool" (http://www.microsoft.com/en-us/download/details.aspx?id=30425)
298
296
$ imgTpl = '<w:pict><v:shape type="#_x0000_t75" style="width:{WIDTH}px;height:{HEIGHT}px"><v:imagedata r:id="{RID}" o:title=""/></v:shape></w:pict> ' ;
299
297
$ typeTpl = '<Override PartName="/word/media/{IMG}" ContentType="image/{EXT}"/> ' ;
300
298
$ relationTpl = '<Relationship Id="{RID}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/{IMG}"/> ' ;
301
- $ newRelationsTpl = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> ' . "\n" . '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships> ' ;
299
+ $ newRelationsTpl = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> ' . "\n" . '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships> ' ;
302
300
$ newRelationsTypeTpl = '<Override PartName="/{RELS}" ContentType="application/vnd.openxmlformats-package.relationships+xml"/> ' ;
303
301
$ extTransform = array (
304
- " jpg " => " jpeg " ,
305
- " JPG " => " jpeg " ,
306
- " png " => " png " ,
307
- " PNG " => " png " ,
302
+ ' jpg ' => ' jpeg ' ,
303
+ ' JPG ' => ' jpeg ' ,
304
+ ' png ' => ' png ' ,
305
+ ' PNG ' => ' png ' ,
308
306
);
309
- //
310
307
311
308
$ searchParts = array (
312
309
$ this ->getMainPartName () => &$ this ->tempDocumentMainPart ,
313
310
);
314
311
foreach (array_keys ($ this ->tempDocumentHeaders ) as $ headerIndex ) {
315
- $ searchParts [ $ this ->getHeaderName ($ headerIndex ) ] = &$ this ->tempDocumentHeaders [$ headerIndex ];
312
+ $ searchParts [$ this ->getHeaderName ($ headerIndex )] = &$ this ->tempDocumentHeaders [$ headerIndex ];
316
313
}
317
314
foreach (array_keys ($ this ->tempDocumentFooters ) as $ headerIndex ) {
318
- $ searchParts [ $ this ->getFooterName ($ headerIndex ) ] = &$ this ->tempDocumentFooters [$ headerIndex ];
315
+ $ searchParts [$ this ->getFooterName ($ headerIndex )] = &$ this ->tempDocumentFooters [$ headerIndex ];
319
316
}
320
317
321
318
foreach ($ searchParts as $ partFileName => &$ partContent ) {
@@ -330,13 +327,13 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
330
327
// get image path and size
331
328
$ width = 115 ;
332
329
$ height = 70 ;
333
- if (is_array ($ replace ) && isset ($ replace [" path " ])) {
334
- $ imgPath = $ replace [" path " ];
335
- if (isset ($ replace [" width " ])) {
336
- $ width = $ replace [" width " ];
330
+ if (is_array ($ replace ) && isset ($ replace [' path ' ])) {
331
+ $ imgPath = $ replace [' path ' ];
332
+ if (isset ($ replace [' width ' ])) {
333
+ $ width = $ replace [' width ' ];
337
334
}
338
- if (isset ($ replace [" height " ])) {
339
- $ height = $ replace [" height " ];
335
+ if (isset ($ replace [' height ' ])) {
336
+ $ height = $ replace [' height ' ];
340
337
}
341
338
} else {
342
339
$ imgPath = $ replace ;
@@ -362,11 +359,11 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
362
359
$ this ->tempDocumentNewImages [$ imgPath ] = $ imgName ;
363
360
364
361
// setup type for image
365
- $ xmlImageType = str_replace (array ('{IMG} ' , '{EXT} ' ), array ($ imgName , $ imgExt ), $ typeTpl ) ;
362
+ $ xmlImageType = str_replace (array ('{IMG} ' , '{EXT} ' ), array ($ imgName , $ imgExt ), $ typeTpl );
366
363
$ this ->tempDocumentContentTypes = str_replace ('</Types> ' , $ xmlImageType , $ this ->tempDocumentContentTypes ) . '</Types> ' ;
367
364
}
368
365
369
- $ xmlImage = str_replace (array ('{RID} ' , '{WIDTH} ' , '{HEIGHT} ' ), array ($ rid , $ width , $ height ), $ imgTpl ) ;
366
+ $ xmlImage = str_replace (array ('{RID} ' , '{WIDTH} ' , '{HEIGHT} ' ), array ($ rid , $ width , $ height ), $ imgTpl );
370
367
$ xmlImageRelation = str_replace (array ('{RID} ' , '{IMG} ' ), array ($ rid , $ imgName ), $ relationTpl );
371
368
372
369
if (!isset ($ this ->tempDocumentRelations [$ partFileName ])) {
@@ -381,7 +378,7 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
381
378
$ this ->tempDocumentRelations [$ partFileName ] = str_replace ('</Relationships> ' , $ xmlImageRelation , $ this ->tempDocumentRelations [$ partFileName ]) . '</Relationships> ' ;
382
379
383
380
// collect prepared replaces
384
- $ partSearchReplaces [" <w:t> " . self ::ensureMacroCompleted ($ search ). " </w:t> " ] = $ xmlImage ;
381
+ $ partSearchReplaces [' <w:t> ' . self ::ensureMacroCompleted ($ search ) . ' </w:t> ' ] = $ xmlImage ;
385
382
}
386
383
387
384
if ($ partSearchReplaces ) {
@@ -569,8 +566,6 @@ public function save()
569
566
/**
570
567
* @param string $fileName
571
568
* @param string $xml
572
- *
573
- * @return void
574
569
*/
575
570
protected function savePartWithRels ($ fileName , $ xml )
576
571
{
@@ -699,20 +694,21 @@ protected function getFooterName($index)
699
694
/**
700
695
* Get the name of the relations file for document part.
701
696
*
702
- * @param string $docuemntPartName
697
+ * @param string $documentPartName
703
698
*
704
699
* @return string
705
700
*/
706
701
protected function getRelationsName ($ documentPartName )
707
702
{
708
- return 'word/_rels/ ' . pathinfo ($ documentPartName , PATHINFO_BASENAME ). '.rels ' ;
703
+ return 'word/_rels/ ' . pathinfo ($ documentPartName , PATHINFO_BASENAME ) . '.rels ' ;
709
704
}
710
705
711
706
protected function getNextRelationsIndex ($ documentPartName )
712
707
{
713
708
if (isset ($ this ->tempDocumentRelations [$ documentPartName ])) {
714
709
return substr_count ($ this ->tempDocumentRelations [$ documentPartName ], '<Relationship ' );
715
710
}
711
+
716
712
return 1 ;
717
713
}
718
714
0 commit comments