CreateDocx.inc 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467
  1. <?php
  2. /**
  3. * Generate a DOCX file
  4. *
  5. * @category Phpdocx
  6. * @package create
  7. * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
  8. * (http://www.2mdc.com)
  9. * @license LGPL
  10. * @version 1.0
  11. * @link http://www.phpdocx.com
  12. * @since File available since Release 1.0
  13. */
  14. error_reporting(E_ALL & ~E_NOTICE);
  15. require_once dirname(__FILE__) . '/AutoLoader.inc';
  16. AutoLoader::load();
  17. /**
  18. * Main class. Methods and vars to generate a DOCX file
  19. *
  20. * @category Phpdocx
  21. * @package create
  22. * @copyright Copyright (c) 2009-2011 Narcea ProduCiones Multimedia S.L.
  23. * (http://www.2mdc.com)
  24. * @license http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php
  25. * @version 1.0
  26. * @link http://www.phpdocx.com
  27. * @since Class available since Release 1.0
  28. */
  29. class CreateDocx
  30. {
  31. const NAMESPACEWORD = 'w';
  32. const SCHEMA_IMAGEDOCUMENT =
  33. 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image';
  34. const SCHEMA_OFFICEDOCUMENT =
  35. 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument';
  36. /**
  37. *
  38. * @access public
  39. * @static
  40. * @var int
  41. */
  42. public static $intIdWord;
  43. /**
  44. *
  45. * @access public
  46. * @var string
  47. */
  48. public $graphicTemplate;
  49. /**
  50. *
  51. * @access public
  52. * @var array
  53. */
  54. public $fileGraphicTemplate;
  55. /**
  56. *
  57. * @access public
  58. * @static
  59. * @var Logger
  60. */
  61. public static $log;
  62. /**
  63. *
  64. * @access private
  65. * @var string
  66. */
  67. private $_contentTypeC;
  68. /**
  69. *
  70. * @access private
  71. * @var string
  72. */
  73. private $_defaultFont;
  74. /**
  75. *
  76. * @access private
  77. * @var string
  78. */
  79. private $_docPropsAppC;
  80. /**
  81. *
  82. * @access private
  83. * @var string
  84. */
  85. private $_docPropsAppT;
  86. /**
  87. *
  88. * @access private
  89. * @var string
  90. */
  91. private $_docPropsCoreC;
  92. /**
  93. *
  94. * @access private
  95. * @var string
  96. */
  97. private $_docPropsCoreT;
  98. /**
  99. *
  100. * @access private
  101. * @var string
  102. */
  103. private $_docPropsCustomC;
  104. /**
  105. *
  106. * @access private
  107. * @var string
  108. */
  109. private $_docPropsCustomT;
  110. /**
  111. *
  112. * @access private
  113. * @var string
  114. */
  115. private static $_encodeUTF;
  116. /**
  117. *
  118. * @access private
  119. * @var string
  120. */
  121. private $_extension;
  122. /**
  123. *
  124. * @access private
  125. * @var int
  126. */
  127. private $_idImgHeader;
  128. /**
  129. *
  130. * @access private
  131. * @var int
  132. */
  133. private $_idRels;
  134. /**
  135. *
  136. * @access private
  137. * @var array
  138. */
  139. private $_idWords;
  140. /**
  141. *
  142. * @access private
  143. * @var string
  144. */
  145. private $_language;
  146. /**
  147. *
  148. * @access private
  149. * @var boolean
  150. */
  151. private $_macro;
  152. /**
  153. *
  154. * @access private
  155. * @var string
  156. */
  157. private $_relsRelsC;
  158. /**
  159. *
  160. * @access private
  161. * @var string
  162. */
  163. private $_relsRelsT;
  164. /**
  165. * Path of temp file to use as DOCX file
  166. *
  167. * @access private
  168. * @var string
  169. */
  170. private $_tempFile;
  171. /**
  172. * Paths of temps files to use as DOCX file
  173. *
  174. * @access private
  175. * @var array
  176. */
  177. private $_tempFileXLSX;
  178. /**
  179. *
  180. * @access private
  181. * @var string
  182. */
  183. private $_wordDocumentC;
  184. /**
  185. *
  186. * @access private
  187. * @var string
  188. */
  189. private $_wordDocumentT;
  190. /**
  191. *
  192. * @access private
  193. * @var string
  194. */
  195. private $_wordEndnotesC;
  196. /**
  197. *
  198. * @access private
  199. * @var string
  200. */
  201. private $_wordEndnotesT;
  202. /**
  203. *
  204. * @access private
  205. * @var string
  206. */
  207. private $_wordFontTableC;
  208. /**
  209. *
  210. * @access private
  211. * @var string
  212. */
  213. private $_wordFontTableT;
  214. /**
  215. *
  216. * @access private
  217. * @var string
  218. */
  219. private $_wordFooterC;
  220. /**
  221. *
  222. * @access private
  223. * @var string
  224. */
  225. private $_wordFooterT;
  226. /**
  227. *
  228. * @access private
  229. * @var string
  230. */
  231. private $_wordFootnotesC;
  232. /**
  233. *
  234. * @access private
  235. * @var string
  236. */
  237. private $_wordFootnotesT;
  238. /**
  239. *
  240. * @access private
  241. * @var string
  242. */
  243. private $_wordHeaderC;
  244. /**
  245. *
  246. * @access private
  247. * @var string
  248. */
  249. private $_wordHeaderT;
  250. /**
  251. *
  252. * @access private
  253. * @var string
  254. */
  255. private $_wordNumberingC;
  256. /**
  257. *
  258. * @access private
  259. * @var string
  260. */
  261. private $_wordNumberingT;
  262. /**
  263. *
  264. * @access private
  265. * @var string
  266. */
  267. private $_wordRelsDocumentRelsC;
  268. /**
  269. *
  270. * @access private
  271. * @var string
  272. */
  273. private $_wordRelsDocumentRelsT;
  274. /**
  275. *
  276. * @access private
  277. * @var string
  278. */
  279. private $_wordRelsFooterRelsC;
  280. /**
  281. *
  282. * @access private
  283. * @var string
  284. */
  285. private $_wordRelsFooterRelsT;
  286. /**
  287. *
  288. * @access private
  289. * @var string
  290. */
  291. private $_wordRelsHeaderRelsC;
  292. /**
  293. *
  294. * @access private
  295. * @var string
  296. */
  297. private $_wordRelsHeaderRelsT;
  298. /**
  299. *
  300. * @access private
  301. * @var string
  302. */
  303. private $_wordSettingsC;
  304. /**
  305. *
  306. * @access private
  307. * @var string
  308. */
  309. private $_wordSettingsT;
  310. /**
  311. *
  312. * @access private
  313. * @var string
  314. */
  315. private $_wordStylesC;
  316. /**
  317. *
  318. * @access private
  319. * @var string
  320. */
  321. private $_wordStylesT;
  322. /**
  323. *
  324. * @access private
  325. * @var string
  326. */
  327. private $_wordThemeThemeT;
  328. /**
  329. *
  330. * @access private
  331. * @var string
  332. */
  333. private $_wordThemeThemeC;
  334. /**
  335. *
  336. * @access private
  337. * @var string
  338. */
  339. private $_wordWebSettingsC;
  340. /**
  341. *
  342. * @access private
  343. * @var string
  344. */
  345. private $_wordWebSettingsT;
  346. /**
  347. *
  348. * @access private
  349. * @var ZipArchive
  350. */
  351. private $_zipDocx;
  352. /**
  353. * Construct
  354. *
  355. * @access public
  356. * @param string $extension File extension. Optional, docx as default
  357. */
  358. public function __construct($extension = 'docx')
  359. {
  360. $this->_idRels = array();
  361. $this->_idWords = array();
  362. Logger::configure(dirname(__FILE__) . '/conf/log4php.properties');
  363. self::$log = Logger::getLogger('phpdocx_error');
  364. $this->_idImgHeader = 1;
  365. $this->_idRels = 1;
  366. self::$intIdWord = 0;
  367. self::$_encodeUTF = 0;
  368. $this->_language = 'en-US';
  369. $this->graphicTemplate = array();
  370. $this->fileGraphicTemplate = array();
  371. $this->_zipDocx = new ZipArchive();
  372. $this->_tempFile = tempnam(sys_get_temp_dir(), 'document');
  373. $this->_zipDocx->open($this->_tempFile, ZipArchive::OVERWRITE);
  374. $this->_extension = $extension;
  375. $this->_relsRelsC = '';
  376. $this->_relsRelsT = '';
  377. $this->_contentTypeC = '';
  378. $this->_docPropsAppC = '';
  379. $this->_docPropsAppT = '';
  380. $this->_docPropsCoreC = '';
  381. $this->_docPropsCoreT = '';
  382. $this->_docPropsCustomC = '';
  383. $this->_docPropsCustomT = '';
  384. $this->_tempFileXLSX = array();
  385. $this->_wordDocumentT = '';
  386. $this->_wordDocumentC = '';
  387. $this->_wordEndnotesC = '';
  388. $this->_wordEndnotesT = '';
  389. $this->_wordFontTableT = '';
  390. $this->_wordFontTableC = '';
  391. $this->_wordFooterC = '';
  392. $this->_wordFooterT = '';
  393. $this->_wordFootnotesC = '';
  394. $this->_wordFootnotesT = '';
  395. $this->_wordHeaderC = '';
  396. $this->_wordHeaderT = '';
  397. $this->_wordNumberingC;
  398. $this->_wordNumberingT;
  399. $this->_wordRelsDocumentRelsC = '';
  400. $this->_wordRelsDocumentRelsT = '';
  401. $this->_wordRelsHeaderRelsC = '';
  402. $this->_wordRelsHeaderRelsT = '';
  403. $this->_wordRelsFooterRelsC = '';
  404. $this->_wordRelsFooterRelsT = '';
  405. $this->_xmlWordSettings = '';
  406. $this->_wordSettingsT = '';
  407. $this->_wordSettingsC = '';
  408. $this->_xmlWordStyles = '';
  409. $this->_wordStylesT = '';
  410. $this->_wordStylesC = '';
  411. $this->_wordThemeThemeT = '';
  412. $this->_wordThemeThemeC = '';
  413. $this->_macro = 0;
  414. $this->_xmlWordWebSettings = '';
  415. $this->generateContentType();
  416. $this->_defaultFont = '';
  417. }
  418. /**
  419. * Destruct
  420. *
  421. * @access public
  422. */
  423. public function __destruct()
  424. {
  425. }
  426. /**
  427. * Magic method, returns current word XML
  428. *
  429. * @access public
  430. * @return string Return current word
  431. */
  432. public function __toString()
  433. {
  434. $this->generateTemplateWordDocument();
  435. return $this->_wordDocumentT;
  436. }
  437. /**
  438. * Setter
  439. *
  440. * @access public
  441. */
  442. public function setXmlContentTypes($xmlContentTypes)
  443. {
  444. $this->_contentTypeC = $xmlContentTypes;
  445. }
  446. /**
  447. * Getter
  448. *
  449. * @access public
  450. */
  451. public function getXmlContentTypes()
  452. {
  453. return $this->_contentTypeC;
  454. }
  455. /**
  456. * Setter
  457. *
  458. * @access public
  459. */
  460. public function setXmlRelsRels($xmlRelsRels)
  461. {
  462. $this->_relsRelsC = $xmlRelsRels;
  463. }
  464. /**
  465. * Getter
  466. *
  467. * @access public
  468. */
  469. public function getXmlRels_Rels()
  470. {
  471. return $this->_relsRelsC;
  472. }
  473. /**
  474. * Setter
  475. *
  476. * @access public
  477. */
  478. public function setXmlDocPropsApp($xmlDocPropsApp)
  479. {
  480. $this->_docPropsAppC = $xmlDocPropsApp;
  481. }
  482. /**
  483. * Getter
  484. *
  485. * @access public
  486. */
  487. public function getXmlDocPropsApp()
  488. {
  489. return $this->_docPropsAppC;
  490. }
  491. /**
  492. * Setter
  493. *
  494. * @access public
  495. */
  496. public function setXmlDocPropsCore($xmlDocPropsCore)
  497. {
  498. $this->_docPropsCoreC = $xmlDocPropsCore;
  499. }
  500. /**
  501. * Getter
  502. *
  503. * @access public
  504. */
  505. public function getXmlDocPropsCore()
  506. {
  507. return $this->_docPropsCoreC;
  508. }
  509. /**
  510. * Setter
  511. *
  512. * @access public
  513. */
  514. public function setXmlWordDocument($xmlWordDocument)
  515. {
  516. $this->_wordDocumentC = $xmlWordDocument;
  517. }
  518. /**
  519. * Getter
  520. *
  521. * @access public
  522. */
  523. public function getXmlWordDocumentContent()
  524. {
  525. return $this->_wordDocumentC;
  526. }
  527. /**
  528. * Setter
  529. *
  530. * @access public
  531. */
  532. public function setXmlWordEndnotes($xmlWordEndnotes)
  533. {
  534. $this->_wordEndnotesC = $xmlWordEndnotes;
  535. }
  536. /**
  537. * Getter
  538. *
  539. * @access public
  540. */
  541. public function getXmlWordEndnotes()
  542. {
  543. return $this->_wordEndnotesC;
  544. }
  545. /**
  546. * Setter
  547. *
  548. * @access public
  549. */
  550. public function setXmlWordFontTable($xmlWordFontTable)
  551. {
  552. $this->_wordFontTableC = $xmlWordFontTable;
  553. }
  554. /**
  555. * Getter
  556. *
  557. * @access public
  558. */
  559. public function getXmlWordFontTable()
  560. {
  561. return $this->_wordFontTableC;
  562. }
  563. /**
  564. * Setter
  565. *
  566. * @access public
  567. */
  568. public function setXmlWordFooter1($xmlWordFooter)
  569. {
  570. $this->_wordFooterC = $xmlWordFooter;
  571. }
  572. /**
  573. * Getter
  574. *
  575. * @access public
  576. */
  577. public function getXmlWordFooter1()
  578. {
  579. return $this->_wordFooterC;
  580. }
  581. /**
  582. * Setter
  583. *
  584. * @access public
  585. */
  586. public function setXmlWordHeader1($xmlWordHeader)
  587. {
  588. $this->_wordHeaderC = $xmlWordHeader;
  589. }
  590. /**
  591. * Getter
  592. *
  593. * @access public
  594. */
  595. public function getXmlWordHeader1()
  596. {
  597. return $this->_wordHeaderC;
  598. }
  599. /**
  600. * Setter
  601. *
  602. * @access public
  603. */
  604. public function setXmlWordRelsDocumentRels($xmlWordRelsDocumentRels)
  605. {
  606. $this->_wordRelsDocumentRelsC = $xmlWordRelsDocumentRels;
  607. }
  608. /**
  609. * Getter
  610. *
  611. * @access public
  612. */
  613. public function getXmlWordRelsDocumentRels()
  614. {
  615. return $this->_wordRelsDocumentRelsC;
  616. }
  617. /**
  618. * Setter
  619. *
  620. * @access public
  621. */
  622. public function setXmlWordSettings($xmlWordSettings)
  623. {
  624. $this->_wordSettingsC = $xmlWordSettings;
  625. }
  626. /**
  627. * Getter
  628. *
  629. * @access public
  630. */
  631. public function getXmlWordSettings()
  632. {
  633. return $this->_wordSettingsC;
  634. }
  635. /**
  636. * Setter
  637. *
  638. * @access public
  639. */
  640. public function setXmlWordStyles($xmlWordStyles)
  641. {
  642. $this->_wordStylesC = $xmlWordStyles;
  643. }
  644. /**
  645. * Getter
  646. *
  647. * @access public
  648. */
  649. public function getXmlWordStyles()
  650. {
  651. return $this->_wordStylesC;
  652. }
  653. /**
  654. * Setter
  655. *
  656. * @access public
  657. */
  658. public function setXmlWordThemeTheme1($xmlWordThemeTheme)
  659. {
  660. $this->_wordThemeThemeC = $xmlWordThemeTheme;
  661. }
  662. /**
  663. * Getter
  664. *
  665. * @access public
  666. */
  667. public function getXmlWordThemeTheme1()
  668. {
  669. return $this->_wordThemeThemeC;
  670. }
  671. /**
  672. * Setter
  673. *
  674. * @access public
  675. */
  676. public function setXmlWordWebSettings($xmlWordWebSettings)
  677. {
  678. $this->_wordWebSettingsC = $xmlWordWebSettings;
  679. }
  680. /**
  681. * Setter
  682. *
  683. * @access public
  684. */
  685. public function getXmlWordWebSettings()
  686. {
  687. return $this->_wordWebSettingsC;
  688. }
  689. /**
  690. * Add a break
  691. *
  692. * @access public
  693. * @param string $type Break type
  694. * Values: 'line', 'page'
  695. */
  696. public function addBreak($type = '')
  697. {
  698. $page = CreatePage::getInstance();
  699. $page->generatePageBreak($type);
  700. $this->_wordDocumentC .= (string) $page;
  701. }
  702. /**
  703. * Add a new font
  704. *
  705. * @access public
  706. * @param array $fonts Fonts to add
  707. */
  708. public function addFont($fonts)
  709. {
  710. $font = CreateFontTable::getInstance();
  711. $font->createFont($fonts);
  712. $this->_wordFontTableC .= (string) $font;
  713. }
  714. /**
  715. * Add a footer
  716. *
  717. * @access public
  718. * @param string $dat Text to add
  719. * @param array $paramsFooter Parameters of footer
  720. * Values: 'pager' (true, false), 'pagerAlignment' (left, right, false)
  721. */
  722. public function addFooter($dat = '', $paramsFooter = '')
  723. {
  724. $footer = CreateFooter::getInstance();
  725. $footer->createFooter($dat, $paramsFooter);
  726. $this->_wordFooterC .= (string) $footer;
  727. $this->generateOVERRIDE(
  728. '/word/footer.xml',
  729. 'application/vnd.openxmlformats-officedocument.wordprocessingml' .
  730. '.footer+xml'
  731. );
  732. }
  733. /**
  734. * Add a graphic
  735. *
  736. * @access public
  737. * @param array $dats Parameters of graphic
  738. * Values: 'color' (1, 2, 3...), 'cornerP' (20, 30...),
  739. * 'cornerX' (20, 30...), 'cornerY' (20, 30...), 'data' (array of values),
  740. * 'font' (Arial, Times New Roman...), 'groupBar' (clustered, stacked),
  741. * 'jc' (center, left, right), 'showPercent' (0, 1), 'sizeX' (10, 11,
  742. * 12...), 'sizeY' (10, 11, 12...), 'textWrap' (0 (inline), 1 (square),
  743. * 2 (front), 3 (back), 4 (up and bottom), 5 (clear)), 'title', 'type'
  744. * (pieChart, barChart, colChart)
  745. */
  746. public function addGraphic($dats)
  747. {
  748. try {
  749. if (isset($dats['data']) && isset($dats['type'])) {
  750. self::$intIdWord++;
  751. $graphic = CreateGraphic::getInstance();
  752. if ($graphic->createGraphic(self::$intIdWord, $dats) != false) {
  753. $this->_zipDocx->addFromString(
  754. 'word/charts/chart' . self::$intIdWord . '.xml',
  755. $graphic->getXmlChart()
  756. );
  757. $this->_wordRelsDocumentRelsC .=
  758. $this->generateRELATIONSHIP(
  759. 'rId' . self::$intIdWord, 'chart',
  760. 'charts/chart' . self::$intIdWord . '.xml'
  761. );
  762. $this->_wordDocumentC .= (string) $graphic;
  763. $this->generateDEFAULT('xlsx', 'application/octet-stream');
  764. $this->generateOVERRIDE(
  765. '/word/charts/chart' . self::$intIdWord . '.xml',
  766. 'application/vnd.openxmlformats-officedocument.' .
  767. 'drawingml.chart+xml'
  768. );
  769. } else {
  770. throw new Exception(
  771. 'There was an error related to the chart.'
  772. );
  773. }
  774. $excel = CreateXlsx::getInstance();
  775. $this->_tempFileXLSX[self::$intIdWord] = tempnam(sys_get_temp_dir(), 'documentxlsx');
  776. if (
  777. $excel->createXlsx(
  778. $this->_tempFileXLSX[self::$intIdWord],
  779. $dats['data'], $dats['type']
  780. ) != false
  781. ) {
  782. $this->_zipDocx->addFile(
  783. $this->_tempFileXLSX[self::$intIdWord],
  784. 'word/embeddings/datos' . self::$intIdWord . '.xlsx'
  785. );
  786. $chartRels = CreateChartRels::getInstance();
  787. $chartRels->createRelationship(self::$intIdWord);
  788. $this->_zipDocx->addFromString(
  789. 'word/charts/_rels/chart' . self::$intIdWord .
  790. '.xml.rels',
  791. (string) $chartRels
  792. );
  793. }
  794. } else {
  795. throw new Exception(
  796. 'Images must have "data" and "type" values.'
  797. );
  798. }
  799. }
  800. catch (Exception $e) {
  801. self::$log->fatal($e->getMessage());
  802. exit();
  803. }
  804. }
  805. /**
  806. * Add a header.
  807. *
  808. * @access public
  809. * @param string $text Text to add
  810. * @param array $paramsHeader Parameters of header
  811. */
  812. public function addHeader($text = 'Header', $paramsHeader = '')
  813. {
  814. $header = CreateHeader::getInstance();
  815. $header->createHeader($text, $paramsHeader);
  816. $this->_wordHeaderC .= (string) $header;
  817. $this->generateOVERRIDE(
  818. '/word/header.xml',
  819. 'application/vnd.openxmlformats-officedocument.wordprocessingml.' .
  820. 'header+xml'
  821. );
  822. }
  823. /**
  824. * Add an image
  825. *
  826. * @access public
  827. * @param array $dats Image to add and paramaters to use
  828. * Values: 'border'(1, 2, 3...), 'borderDiscontinuous' (0, 1),
  829. * 'font' (Arial, Times New Roman...), 'jc' (center, left, right),
  830. * 'name', 'scaling' (50, 100), 'sizeX' (10, 11, 12...), 'sizeY'
  831. * (10, 11, 12...), spacingTop (10, 11...), spacingBottom (10, 11...),
  832. * spacingLeft (10, 11...), spacingRight (10, 11...), 'textWrap'
  833. * (0 (inline), 1 (square), 2 (front), 3 (back), 4 (up and bottom),
  834. * 5 (clear))
  835. */
  836. public function addImage($dats = '')
  837. {
  838. try {
  839. if (isset($dats['name']) && file_exists($dats['name']) == 'true') {
  840. $attrImage = getimagesize($dats['name']);
  841. try {
  842. if ($attrImage['mime'] == 'image/jpg' ||
  843. $attrImage['mime'] == 'image/jpeg' ||
  844. $attrImage['mime'] == 'image/png' ||
  845. $attrImage['mime'] == 'image/gif'
  846. ) {
  847. self::$intIdWord++;
  848. $image = CreateImage::getInstance();
  849. $dats['rId'] = self::$intIdWord;
  850. $image->createImage($dats);
  851. $this->_wordDocumentC .= (string) $image;
  852. $dir = $this->parsePath($dats['name']);
  853. $this->_zipDocx->addFile(
  854. $dats['name'], 'word/media/image' .
  855. self::$intIdWord . '.' .
  856. $dir['extension']
  857. );
  858. $this->generateDEFAULT(
  859. $dir['extension'], $attrImage['mime']
  860. );
  861. if ((string) $image != '')
  862. $this->_wordRelsDocumentRelsC .=
  863. $this->generateRELATIONSHIP(
  864. 'rId' . self::$intIdWord, 'image',
  865. 'media/image' . self::$intIdWord . '.'
  866. . $dir['extension']
  867. );
  868. } else {
  869. throw new Exception('Image format is not supported.');
  870. }
  871. }
  872. catch (Exception $e) {
  873. self::$log->fatal($e->getMessage());
  874. exit();
  875. }
  876. } else {
  877. throw new Exception('Image does not exist.');
  878. }
  879. }
  880. catch (Exception $e) {
  881. self::$log->fatal($e->getMessage());
  882. exit();
  883. }
  884. }
  885. /**
  886. * Add a link
  887. *
  888. * @access public
  889. * @param string $text Text to use as link
  890. * @param string $link URL link
  891. * @param string $font Type of font
  892. * Values: 'Arial', 'Times New Roman'...
  893. */
  894. public function addLink($text = '', $textLink = '', $font = '')
  895. {
  896. $link = CreateLink::getInstance();
  897. $link->createLink($text, $textLink, $font);
  898. $this->_wordDocumentC .= (string) $link;
  899. }
  900. /**
  901. * Add a list
  902. *
  903. * @access public
  904. * @param array $dats Values of the list
  905. * @param array $paramsList Parameters to use
  906. * Values: 'font' (Arial, Times New Roman...),
  907. * 'val' (0 (clear, 1 (inordinate), 2(numerical))
  908. */
  909. public function addList($dats, $paramsList = '')
  910. {
  911. $list = CreateList::getInstance();
  912. $list->createList($dats, $paramsList);
  913. $this->_wordDocumentC .= (string) $list;
  914. }
  915. /**
  916. * Convert a math eq to DOCX
  917. *
  918. * @access public
  919. * @param string $path Path to a file with math eq
  920. */
  921. public function addMathDocx($path)
  922. {
  923. $package = new ZipArchive();
  924. $package->open($path);
  925. $document = $package->getFromName('word/document.xml');
  926. $eqs = preg_split('/<[\/]*m:oMathPara>/', $document);
  927. $this->addMathEq('<m:oMathPara>' . $eqs[1] . '</m:oMathPara>');
  928. $package->close();
  929. }
  930. /**
  931. * Add an existing math eq to DOCX
  932. *
  933. * @access public
  934. * @param string $eq Math eq
  935. */
  936. public function addMathEq($eq)
  937. {
  938. $this->_wordDocumentC .= '<' . CreateDocx::NAMESPACEWORD . ':p>' .
  939. (string) $eq . '</' . CreateDocx::NAMESPACEWORD . ':p>';
  940. }
  941. /**
  942. * Add a paragraph
  943. *
  944. * @access public
  945. * @param string $text Text to add
  946. * @param string $style Style of the paragraph
  947. * @param string $align Align of the paragraph
  948. */
  949. public function addParagraph($text, $style = '', $align = '')
  950. {
  951. $paragraph = CreateText::getInstance();
  952. $paragraph->createParagraph($text, $style, $align);
  953. $this->_wordDocumentC .= (string) $paragraph;
  954. }
  955. /**
  956. * Add a table.
  957. *
  958. * @access public
  959. * @param array $dats Values to add
  960. * @param array $parameters Parameters to use
  961. * Values: 'border' (none, single, double),
  962. * 'border_color' (ffffff, ff0000), 'border_spacing' (0, 1, 2...),
  963. * 'border_sz' (10, 11...), 'font' (Arial, Times New Roman...),
  964. * 'jc' (center, left, right), 'size_col' (1200, 1300...),
  965. * 'TBLSTYLEval' (Cuadrculamedia3-nfasis1, Sombreadomedio1,
  966. * Tablaconcuadrcula, TableGrid)
  967. */
  968. public function addTable($dats, $parameters = '')
  969. {
  970. $table = CreateTable::getInstance();
  971. $table->createTable($dats, $parameters);
  972. $this->_wordDocumentC .= (string) $table;
  973. }
  974. /**
  975. * Add a table of contents (TOC)
  976. *
  977. * @access public
  978. * @param string $font Set font type
  979. * Values: 'Arial', 'Times New Roman'...
  980. */
  981. public function addTableContents($font = '')
  982. {
  983. $tableContents = CreateTableContents::getInstance();
  984. $tableContents->createTableContents($font);
  985. $this->_wordDocumentC .= (string) $tableContents;
  986. }
  987. /**
  988. * Add a text
  989. *
  990. * @access public
  991. * @param mixed $value Text or array of texts to add
  992. * @param array $style Style of text
  993. * Values: 'b' (single), 'color' (ffffff, ff0000...),
  994. * 'font' (Arial, Times New Roman...), 'i' (single),
  995. * 'jc' (both, center, distribute, left, right),
  996. * 'pageBreakBefore' (on, off), 'sz' (1, 2, 3...),
  997. * 'u' (dash, dotted, double, single, wave, words),
  998. * 'widowControl' (on, off), 'wordWrap' (on, off)
  999. */
  1000. public function addText($value, $style = '')
  1001. {
  1002. $text = CreateText::getInstance();
  1003. $text->createText($value, $style);
  1004. $this->_wordDocumentC .= (string) $text;
  1005. }
  1006. /**
  1007. * Add a title
  1008. *
  1009. * @access public
  1010. * @param string $text Text to add
  1011. * @param array $style Style of title
  1012. * Values: 'b' (single), 'color' (ffffff, ff0000...),
  1013. * 'font' (Arial, Times New Roman...), 'i' (single),
  1014. * 'jc' (both, center, distribute, left, right),
  1015. * 'pageBreakBefore' (on, off), 'sz' (1, 2, 3...),
  1016. * 'u' (dash, dotted, double, single, wave, words),
  1017. * 'widowControl' (on, off), 'wordWrap' (on, off)
  1018. */
  1019. public function addTitle($text, $style = '')
  1020. {
  1021. $title = CreateText::getInstance();
  1022. $title->createTitle($text, $style);
  1023. $this->_wordDocumentC .= (string) $title;
  1024. }
  1025. /**
  1026. * Generate a new DOCX file
  1027. *
  1028. * @access public
  1029. * @param string $args[0] File name
  1030. * @param string $args[1] Page style
  1031. * Values: 'bottom' (4000, 4001...), 'left' (4000, 4001...),
  1032. * 'orient' (landscape), 'right' (4000, 4001), 'titlePage' (1),
  1033. * 'top' (4000, 4001)
  1034. */
  1035. public function createDocx()
  1036. {
  1037. $args = func_get_args();
  1038. if (!empty($args[0])) {
  1039. $fileName = $args[0];
  1040. } else {
  1041. $fileName = 'document';
  1042. }
  1043. $this->generateTemplateRelsRels();
  1044. $this->_zipDocx->addFromString('_rels/.rels', $this->_relsRelsT);
  1045. $this->generateTemplateDocPropsApp();
  1046. $this->_zipDocx->addFromString(
  1047. 'docProps/app.xml', $this->_docPropsAppT
  1048. );
  1049. $this->generateTemplateDocPropsCore();
  1050. $this->_zipDocx->addFromString(
  1051. 'docProps/core.xml', $this->_docPropsCoreT
  1052. );
  1053. $this->addStyle($this->_language);
  1054. $this->generateTemplateWordStyles();
  1055. $this->_zipDocx->addFromString(
  1056. 'word/styles.xml', $this->_wordStylesT
  1057. );
  1058. $this->addSettings();
  1059. $this->generateTemplateWordSettings();
  1060. $this->_zipDocx->addFromString(
  1061. 'word/settings.xml', $this->_wordSettingsT
  1062. );
  1063. $this->addWebSettings();
  1064. $this->generateTemplateWordWebSettings();
  1065. $this->_zipDocx->addFromString(
  1066. 'word/webSettings.xml', $this->_wordWebSettingsT
  1067. );
  1068. if (empty($this->_wordFooterC)) {
  1069. $paramsFooter = array(
  1070. 'pagerAlignment' => 'right',
  1071. 'font' => 'Times New Roman'
  1072. );
  1073. $this->addFooter('', $paramsFooter);
  1074. }
  1075. $this->generateTemplateWordFooter();
  1076. if (self::$_encodeUTF) {
  1077. $this->_zipDocx->addFromString(
  1078. 'word/footer.xml', utf8_encode($this->_wordFooterT)
  1079. );
  1080. } else {
  1081. $this->_zipDocx->addFromString(
  1082. 'word/footer.xml', $this->_wordFooterT
  1083. );
  1084. }
  1085. if (!empty($this->_wordHeaderC)) {
  1086. $this->generateTemplateWordHeader();
  1087. if (self::$_encodeUTF) {
  1088. $this->_zipDocx->addFromString(
  1089. 'word/header.xml', utf8_encode($this->_wordHeaderT)
  1090. );
  1091. } else {
  1092. $this->_zipDocx->addFromString(
  1093. 'word/header.xml', $this->_wordHeaderT
  1094. );
  1095. }
  1096. }
  1097. if (!empty($this->_wordRelsHeaderRelsC)) {
  1098. $this->generateTemplateWordRelsHeaderRels();
  1099. $this->_zipDocx->addFromString(
  1100. 'word/_rels/header.xml.rels', $this->_wordRelsHeaderRelsT
  1101. );
  1102. }
  1103. $this->generateOVERRIDE(
  1104. '/word/document.xml',
  1105. 'application/vnd.openxmlformats-officedocument.' .
  1106. 'wordprocessingml.document.main+xml'
  1107. );
  1108. $this->generateTemplateContentType();
  1109. $this->_zipDocx->addFromString(
  1110. '[Content_Types].xml',
  1111. $this->_wordContentTypeT
  1112. );
  1113. $this->generateTemplateWordNumbering();
  1114. $this->_zipDocx->addFromString(
  1115. 'word/numbering.xml', $this->_wordNumberingT
  1116. );
  1117. $this->generateDefaultWordRels();
  1118. if (!empty($this->_wordRelsDocumentRelsC)) {
  1119. $this->generateTemplateWordRelsDocumentRels();
  1120. $this->_zipDocx->addFromString(
  1121. 'word/_rels/document.xml.rels',
  1122. $this->_wordRelsDocumentRelsT
  1123. );
  1124. }
  1125. $arrArgsPage = array();
  1126. if (isset($args[1])) {
  1127. $arrArgsPage = $args[1];
  1128. }
  1129. $this->generateTemplateWordDocument($arrArgsPage);
  1130. if (self::$_encodeUTF) {
  1131. $this->_zipDocx->addFromString(
  1132. 'word/document.xml', utf8_encode($this->_wordDocumentT)
  1133. );
  1134. } else {
  1135. $this->_zipDocx->addFromString(
  1136. 'word/document.xml', $this->_wordDocumentT
  1137. );
  1138. }
  1139. $this->generateDefaultFonts();
  1140. $this->generateTemplateWordFontTable();
  1141. $this->_zipDocx->addFromString(
  1142. 'word/fontTable.xml', $this->_wordFontTableT
  1143. );
  1144. $this->generateTemplateWordThemeTheme1();
  1145. $this->_zipDocx->addFromString(
  1146. 'word/theme/theme1.xml', $this->_wordThemeThemeT
  1147. );
  1148. $this->_zipDocx->close();
  1149. $arrpathFile = pathinfo($fileName);
  1150. copy(
  1151. $this->_tempFile,
  1152. $fileName . '.' . $this->_extension
  1153. );
  1154. }
  1155. /**
  1156. * Change the default font
  1157. *
  1158. * @access public
  1159. * @param string $font The new font
  1160. * Values: 'Arial', 'Times New Roman'...
  1161. */
  1162. public function setDefaultFont($font)
  1163. {
  1164. $this->_defaultFont = $font;
  1165. }
  1166. /**
  1167. * Transform to UTF-8 charset
  1168. *
  1169. * @access public
  1170. */
  1171. public function setEncodeUTF8()
  1172. {
  1173. self::$_encodeUTF = 1;
  1174. }
  1175. /**
  1176. * Change default language.
  1177. * @param $lang Locale: en-US, es-ES...
  1178. * @access public
  1179. */
  1180. public function setLanguage($lang = 'en-US')
  1181. {
  1182. $this->_language = $lang;
  1183. }
  1184. /*** Old API. It will be remove in next version ***/
  1185. /**
  1186. * Add a break
  1187. *
  1188. * @access public
  1189. * @param string $type Break type
  1190. * @deprecated
  1191. */
  1192. public function fAddBreak($type = '')
  1193. {
  1194. $page = CreatePage::getInstance();
  1195. $page->generatePageBreak($type);
  1196. $this->_wordDocumentC .= (string) $page;
  1197. }
  1198. /**
  1199. * Add a new font
  1200. *
  1201. * @access public
  1202. * @param array $fonts Fonts to add
  1203. * @deprecated
  1204. */
  1205. public function fAddFont($fonts)
  1206. {
  1207. $font = CreateFontTable::getInstance();
  1208. $font->createFont($fonts);
  1209. $this->_wordFontTableC .= (string) $font;
  1210. }
  1211. /**
  1212. * Add a footer
  1213. *
  1214. * @access public
  1215. * @param string $dat Text to add
  1216. * @param array $paramsFooter Parameters of footer
  1217. * @deprecated
  1218. */
  1219. public function fAddFooter($dat = '', $paramsFooter = '')
  1220. {
  1221. $footer = CreateFooter::getInstance();
  1222. $footer->createFooter($dat, $paramsFooter);
  1223. $this->_wordFooterC .= (string) $footer;
  1224. $this->generateOVERRIDE(
  1225. '/word/footer.xml',
  1226. 'application/vnd.openxmlformats-officedocument.wordprocessingml' .
  1227. '.footer+xml'
  1228. );
  1229. }
  1230. /**
  1231. * Add a graphic
  1232. *
  1233. * @access public
  1234. * @param array $dats Parameters of graphic
  1235. * @deprecated
  1236. */
  1237. public function fAddGraphic($dats)
  1238. {
  1239. try {
  1240. if (isset($dats['data']) && isset($dats['type'])) {
  1241. self::$intIdWord++;
  1242. $graphic = CreateGraphic::getInstance();
  1243. if ($graphic->createGraphic(self::$intIdWord, $dats) != false) {
  1244. $this->_zipDocx->addFromString(
  1245. 'word/charts/chart' . self::$intIdWord . '.xml',
  1246. $graphic->getXmlChart()
  1247. );
  1248. $this->_wordRelsDocumentRelsC .=
  1249. $this->generateRELATIONSHIP(
  1250. 'rId' . self::$intIdWord, 'chart',
  1251. 'charts/chart' . self::$intIdWord . '.xml'
  1252. );
  1253. $this->_wordDocumentC .= (string) $graphic;
  1254. $this->generateDEFAULT('xlsx', 'application/octet-stream');
  1255. $this->generateOVERRIDE(
  1256. '/word/charts/chart' . self::$intIdWord . '.xml',
  1257. 'application/vnd.openxmlformats-officedocument.' .
  1258. 'drawingml.chart+xml'
  1259. );
  1260. } else {
  1261. throw new Exception(
  1262. 'There was an error related to the chart.'
  1263. );
  1264. }
  1265. $excel = CreateXlsx::getInstance();
  1266. $this->_tempFileXLSX[self::$intIdWord] = tempnam(sys_get_temp_dir(), 'documentxlsx');
  1267. if (
  1268. $excel->createXlsx(
  1269. $this->_tempFileXLSX[self::$intIdWord],
  1270. $dats['data'], $dats['type']
  1271. ) != false
  1272. ) {
  1273. $this->_zipDocx->addFile(
  1274. $this->_tempFileXLSX[self::$intIdWord],
  1275. 'word/embeddings/datos' . self::$intIdWord . '.xlsx'
  1276. );
  1277. $chartRels = CreateChartRels::getInstance();
  1278. $chartRels->createRelationship(self::$intIdWord);
  1279. $this->_zipDocx->addFromString(
  1280. 'word/charts/_rels/chart' . self::$intIdWord .
  1281. '.xml.rels',
  1282. (string) $chartRels
  1283. );
  1284. }
  1285. } else {
  1286. throw new Exception(
  1287. 'Images must have "data" and "type" values.'
  1288. );
  1289. }
  1290. }
  1291. catch (Exception $e) {
  1292. self::$log->fatal($e->getMessage());
  1293. exit();
  1294. }
  1295. }
  1296. /**
  1297. * Add a header.
  1298. *
  1299. * @access public
  1300. * @param string $text Text to add
  1301. * @param array $paramsHeader Parameters of header
  1302. * @deprecated
  1303. */
  1304. public function fAddHeader($text = 'Header', $paramsHeader = '')
  1305. {
  1306. $header = CreateHeader::getInstance();
  1307. $header->createHeader($text, $paramsHeader);
  1308. $this->_wordHeaderC .= (string) $header;
  1309. $this->generateOVERRIDE(
  1310. '/word/header.xml',
  1311. 'application/vnd.openxmlformats-officedocument.wordprocessingml.' .
  1312. 'header+xml'
  1313. );
  1314. }
  1315. /**
  1316. * Add an image
  1317. *
  1318. * @access public
  1319. * @param array $dats Image to add and paramaters to use
  1320. * @deprecated
  1321. */
  1322. public function fAddImage($dats = '')
  1323. {
  1324. try {
  1325. if (isset($dats['name']) && file_exists($dats['name']) == 'true') {
  1326. $attrImage = getimagesize($dats['name']);
  1327. try {
  1328. if ($attrImage['mime'] == 'image/jpg' ||
  1329. $attrImage['mime'] == 'image/jpeg' ||
  1330. $attrImage['mime'] == 'image/png' ||
  1331. $attrImage['mime'] == 'image/gif'
  1332. ) {
  1333. self::$intIdWord++;
  1334. $image = CreateImage::getInstance();
  1335. $dats['rId'] = self::$intIdWord;
  1336. $image->createImage($dats);
  1337. $this->_wordDocumentC .= (string) $image;
  1338. $dir = $this->parsePath($dats['name']);
  1339. $this->_zipDocx->addFile(
  1340. $dats['name'], 'word/media/image' .
  1341. self::$intIdWord . '.' .
  1342. $dir['extension']
  1343. );
  1344. $this->generateDEFAULT(
  1345. $dir['extension'], $attrImage['mime']
  1346. );
  1347. if ((string) $image != '')
  1348. $this->_wordRelsDocumentRelsC .=
  1349. $this->generateRELATIONSHIP(
  1350. 'rId' . self::$intIdWord, 'image',
  1351. 'media/image' . self::$intIdWord . '.'
  1352. . $dir['extension']
  1353. );
  1354. } else {
  1355. throw new Exception('Image format is not supported.');
  1356. }
  1357. }
  1358. catch (Exception $e) {
  1359. self::$log->fatal($e->getMessage());
  1360. exit();
  1361. }
  1362. } else {
  1363. throw new Exception('Image does not exist.');
  1364. }
  1365. }
  1366. catch (Exception $e) {
  1367. self::$log->fatal($e->getMessage());
  1368. exit();
  1369. }
  1370. }
  1371. /**
  1372. * Add a link
  1373. *
  1374. * @access protected
  1375. * @param string $text Text to use as link
  1376. * @param string $link URL link
  1377. * @param string $font Type of font
  1378. * @deprecated
  1379. */
  1380. protected function fAddLink($text = '', $textLink = '', $font = '')
  1381. {
  1382. $link = CreateLink::getInstance();
  1383. $link->createLink($text, $textLink, $font);
  1384. $this->_wordDocumentC .= (string) $link;
  1385. }
  1386. /**
  1387. * Add a list
  1388. *
  1389. * @access public
  1390. * @param array $dats Values of the list
  1391. * @param array $paramsList Parameters to use
  1392. * @deprecated
  1393. */
  1394. public function fAddList($dats, $paramsList = '')
  1395. {
  1396. $list = CreateList::getInstance();
  1397. $list->createList($dats, $paramsList);
  1398. $this->_wordDocumentC .= (string) $list;
  1399. }
  1400. /**
  1401. * Convert a math eq to DOCX
  1402. *
  1403. * @access public
  1404. * @param string $path Path to a file with math eq
  1405. * @deprecated
  1406. */
  1407. public function fAddMathDocx($path)
  1408. {
  1409. $package = new ZipArchive();
  1410. $package->open($path);
  1411. $document = $package->getFromName('word/document.xml');
  1412. $eqs = preg_split('/<[\/]*m:oMathPara>/', $document);
  1413. $this->addMathEq('<m:oMathPara>' . $eqs[1] . '</m:oMathPara>');
  1414. $package->close();
  1415. }
  1416. /**
  1417. * Add an existing math eq to DOCX
  1418. *
  1419. * @access public
  1420. * @param string $eq Math eq
  1421. * @deprecated
  1422. */
  1423. public function fAddMathEq($eq)
  1424. {
  1425. $this->_wordDocumentC .= '<' . CreateDocx::NAMESPACEWORD . ':p>' .
  1426. (string) $eq . '</' . CreateDocx::NAMESPACEWORD . ':p>';
  1427. }
  1428. /**
  1429. * Add a paragraph
  1430. *
  1431. * @access public
  1432. * @param string $text Text to add
  1433. * @param string $style Style of the paragraph
  1434. * @param string $align Align of the paragraph
  1435. * @deprecated
  1436. */
  1437. public function fAddParagraph($text, $style = '', $align = '')
  1438. {
  1439. $paragraph = CreateText::getInstance();
  1440. $paragraph->createParagraph($text, $style, $align);
  1441. $this->_wordDocumentC .= (string) $paragraph;
  1442. }
  1443. /**
  1444. * Add a table.
  1445. *
  1446. * @access public
  1447. * @param array $dats Values to add
  1448. * @param array $parameters Parameters to use
  1449. * @deprecated
  1450. */
  1451. public function fAddTable($dats, $parameters = '')
  1452. {
  1453. $table = CreateTable::getInstance();
  1454. $table->createTable($dats, $parameters);
  1455. $this->_wordDocumentC .= (string) $table;
  1456. }
  1457. /**
  1458. * Add a table of contents (TOC)
  1459. *
  1460. * @access public
  1461. * @param string $font Set font type
  1462. * @deprecated
  1463. */
  1464. public function fAddTableContents($font = '')
  1465. {
  1466. $tableContents = CreateTableContents::getInstance();
  1467. $tableContents->createTableContents($font);
  1468. $this->_wordDocumentC .= (string) $tableContents;
  1469. }
  1470. /**
  1471. * Add a text
  1472. *
  1473. * @access public
  1474. * @param mixed $value Text or array of texts to add
  1475. * @param array $style Style of text
  1476. * @deprecated
  1477. */
  1478. public function fAddText($value, $style = '')
  1479. {
  1480. $text = CreateText::getInstance();
  1481. $text->createText($value, $style);
  1482. $this->_wordDocumentC .= (string) $text;
  1483. }
  1484. /**
  1485. * Add a title
  1486. *
  1487. * @access public
  1488. * @param string $text Text to add
  1489. * @param array $style Style of title
  1490. * @deprecated
  1491. */
  1492. public function fAddTitle($text, $style = '')
  1493. {
  1494. $title = CreateText::getInstance();
  1495. $title->createTitle($text, $style);
  1496. $this->_wordDocumentC .= (string) $title;
  1497. }
  1498. /**
  1499. * Generate a new DOCX file
  1500. *
  1501. * @access public
  1502. * @param string $args[0] File name
  1503. * @deprecated
  1504. */
  1505. public function fCreateDocx()
  1506. {
  1507. $args = func_get_args();
  1508. if (!empty($args[0])) {
  1509. $fileName = $args[0];
  1510. } else {
  1511. $fileName = 'document';
  1512. }
  1513. $this->generateTemplateRelsRels();
  1514. $this->_zipDocx->addFromString('_rels/.rels', $this->_relsRelsT);
  1515. $this->generateTemplateDocPropsApp();
  1516. $this->_zipDocx->addFromString(
  1517. 'docProps/app.xml', $this->_docPropsAppT
  1518. );
  1519. $this->generateTemplateDocPropsCore();
  1520. $this->_zipDocx->addFromString(
  1521. 'docProps/core.xml', $this->_docPropsCoreT
  1522. );
  1523. $this->addStyle($this->_language);
  1524. $this->generateTemplateWordStyles();
  1525. $this->_zipDocx->addFromString(
  1526. 'word/styles.xml', $this->_wordStylesT
  1527. );
  1528. $this->addSettings();
  1529. $this->generateTemplateWordSettings();
  1530. $this->_zipDocx->addFromString(
  1531. 'word/settings.xml', $this->_wordSettingsT
  1532. );
  1533. $this->addWebSettings();
  1534. $this->generateTemplateWordWebSettings();
  1535. $this->_zipDocx->addFromString(
  1536. 'word/webSettings.xml', $this->_wordWebSettingsT
  1537. );
  1538. if (empty($this->_wordFooterC)) {
  1539. $paramsFooter = array(
  1540. 'pagerAlignment' => 'right',
  1541. 'font' => 'Times New Roman'
  1542. );
  1543. $this->addFooter('', $paramsFooter);
  1544. }
  1545. $this->generateTemplateWordFooter();
  1546. if (self::$_encodeUTF) {
  1547. $this->_zipDocx->addFromString(
  1548. 'word/footer.xml', utf8_encode($this->_wordFooterT)
  1549. );
  1550. } else {
  1551. $this->_zipDocx->addFromString(
  1552. 'word/footer.xml', $this->_wordFooterT
  1553. );
  1554. }
  1555. if (!empty($this->_wordHeaderC)) {
  1556. $this->generateTemplateWordHeader();
  1557. if (self::$_encodeUTF) {
  1558. $this->_zipDocx->addFromString(
  1559. 'word/header.xml', utf8_encode($this->_wordHeaderT)
  1560. );
  1561. } else {
  1562. $this->_zipDocx->addFromString(
  1563. 'word/header.xml', $this->_wordHeaderT
  1564. );
  1565. }
  1566. }
  1567. if (!empty($this->_wordRelsHeaderRelsC)) {
  1568. $this->generateTemplateWordRelsHeaderRels();
  1569. $this->_zipDocx->addFromString(
  1570. 'word/_rels/header.xml.rels', $this->_wordRelsHeaderRelsT
  1571. );
  1572. }
  1573. $this->generateOVERRIDE(
  1574. '/word/document.xml',
  1575. 'application/vnd.openxmlformats-officedocument.' .
  1576. 'wordprocessingml.document.main+xml'
  1577. );
  1578. $this->generateTemplateContentType();
  1579. $this->_zipDocx->addFromString(
  1580. '[Content_Types].xml',
  1581. $this->_wordContentTypeT
  1582. );
  1583. $this->generateTemplateWordNumbering();
  1584. $this->_zipDocx->addFromString(
  1585. 'word/numbering.xml', $this->_wordNumberingT
  1586. );
  1587. $this->generateDefaultWordRels();
  1588. if (!empty($this->_wordRelsDocumentRelsC)) {
  1589. $this->generateTemplateWordRelsDocumentRels();
  1590. $this->_zipDocx->addFromString(
  1591. 'word/_rels/document.xml.rels',
  1592. $this->_wordRelsDocumentRelsT
  1593. );
  1594. }
  1595. $arrArgsPage = array();
  1596. if (isset($args[1])) {
  1597. $arrArgsPage = $args[1];
  1598. }
  1599. $this->generateTemplateWordDocument($arrArgsPage);
  1600. if (self::$_encodeUTF) {
  1601. $this->_zipDocx->addFromString(
  1602. 'word/document.xml', utf8_encode($this->_wordDocumentT)
  1603. );
  1604. } else {
  1605. $this->_zipDocx->addFromString(
  1606. 'word/document.xml', $this->_wordDocumentT
  1607. );
  1608. }
  1609. $this->generateDefaultFonts();
  1610. $this->generateTemplateWordFontTable();
  1611. $this->_zipDocx->addFromString(
  1612. 'word/fontTable.xml', $this->_wordFontTableT
  1613. );
  1614. $this->generateTemplateWordThemeTheme1();
  1615. $this->_zipDocx->addFromString(
  1616. 'word/theme/theme1.xml', $this->_wordThemeThemeT
  1617. );
  1618. $this->_zipDocx->close();
  1619. $arrpathFile = pathinfo($fileName);
  1620. copy(
  1621. $this->_tempFile,
  1622. $fileName . '.' . $this->_extension
  1623. );
  1624. }
  1625. /**
  1626. * Change the default font
  1627. *
  1628. * @access public
  1629. * @param string $font The new font
  1630. * @deprecated
  1631. */
  1632. public function fSetDefaultFont($font)
  1633. {
  1634. $this->_defaultFont = $font;
  1635. }
  1636. /*** End old API ***/
  1637. /**
  1638. *
  1639. *
  1640. * @access private
  1641. */
  1642. private function generateContentType()
  1643. {
  1644. $this->generateDEFAULT(
  1645. 'rels', 'application/vnd.openxmlformats-package.relationships+xml'
  1646. );
  1647. $this->generateDEFAULT('xml', 'application/xml');
  1648. $this->generateOVERRIDE(
  1649. '/word/numbering.xml',
  1650. 'application/vnd.openxmlformats-officedocument.wordprocessingml.' .
  1651. 'numbering+xml'
  1652. );
  1653. $this->generateOVERRIDE(
  1654. '/word/styles.xml',
  1655. 'application/vnd.openxmlformats-officedocument.wordprocessingml' .
  1656. '.styles+xml'
  1657. );
  1658. $this->generateOVERRIDE(
  1659. '/docProps/app.xml',
  1660. 'application/vnd.openxmlformats-officedocument.extended-' .
  1661. 'properties+xml'
  1662. );
  1663. $this->generateOVERRIDE(
  1664. '/word/settings.xml', 'application/' .
  1665. 'vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
  1666. );
  1667. $this->generateOVERRIDE(
  1668. '/word/theme/theme1.xml',
  1669. 'application/vnd.openxmlformats-officedocument.theme+xml'
  1670. );
  1671. $this->generateOVERRIDE(
  1672. '/word/fontTable.xml',
  1673. 'application/vnd.openxmlformats-officedocument.wordprocessingml.' .
  1674. 'fontTable+xml'
  1675. );
  1676. $this->generateOVERRIDE(
  1677. '/word/webSettings.xml',
  1678. 'application/vnd.openxmlformats-officedocument.wordprocessingml' .
  1679. '.webSettings+xml'
  1680. );
  1681. if ($this->_wordFooterC != '' || $this->_wordHeaderC != '') {
  1682. $this->generateOVERRIDE(
  1683. '/word/header.xml',
  1684. 'application/vnd.openxmlformats-officedocument.' .
  1685. 'wordprocessingml.header+xml'
  1686. );
  1687. $this->generateOVERRIDE(
  1688. '/word/footer.xml',
  1689. 'application/vnd.openxmlformats-officedocument.' .
  1690. 'wordprocessingml.footer+xml'
  1691. );
  1692. $this->generateOVERRIDE(
  1693. '/word/footnotes.xml',
  1694. 'application/vnd.openxmlformats-officedocument.' .
  1695. 'wordprocessingml.footnotes+xml'
  1696. );
  1697. $this->generateOVERRIDE(
  1698. '/word/endnotes.xml',
  1699. 'application/vnd.openxmlformats-officedocument.' .
  1700. 'wordprocessingml.endnotes+xml'
  1701. );
  1702. }
  1703. $this->generateOVERRIDE(
  1704. '/docProps/core.xml',
  1705. 'application/vnd.openxmlformats-package.core-properties+xml'
  1706. );
  1707. }
  1708. /**
  1709. * Generate SECTPR
  1710. *
  1711. * @access private
  1712. * @param array $args Section style
  1713. */
  1714. private function generateSECTPR($args = '')
  1715. {
  1716. $page = CreatePage::getInstance();
  1717. $page->createSECTPR($args);
  1718. $this->_wordDocumentC .= (string) $page;
  1719. }
  1720. /**
  1721. * Generate ContentType XML template
  1722. *
  1723. * @access private
  1724. */
  1725. private function generateTemplateContentType()
  1726. {
  1727. $this->_wordContentTypeT =
  1728. '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>' .
  1729. '<Types xmlns="http://schemas.openxmlformats.org/package/2006/' .
  1730. 'content-types">' . $this->_contentTypeC . '</Types>';
  1731. }
  1732. /**
  1733. * Generate DocPropsApp XML template
  1734. *
  1735. * @access private
  1736. */
  1737. private function generateTemplateDocPropsApp()
  1738. {
  1739. $this->_docPropsAppT =
  1740. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  1741. '<Properties xmlns="http://schemas.openxmlformats.org/' .
  1742. 'officeDocument/2006/extended-properties" xmlns:vt="' .
  1743. 'http://schemas.openxmlformats.org/officeDocument/2006/' .
  1744. 'docPropsVTypes"><Template>Normal.dotm</Template><TotalTime>' .
  1745. '0</TotalTime><Pages>1</Pages><Words>1</Words><Characters>1'
  1746. . '</Characters><Application>Microsoft Office Word</Application>' .
  1747. '<DocSecurity>4</DocSecurity><Lines>1</Lines><Paragraphs>1' .
  1748. '</Paragraphs><ScaleCrop>false</ScaleCrop><Company>Company' .
  1749. '</Company><LinksUpToDate>false</LinksUpToDate>' .
  1750. '<CharactersWithSpaces>1</CharactersWithSpaces><SharedDoc>' .
  1751. 'false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged>' .
  1752. '<AppVersion>12.0000</AppVersion></Properties>';
  1753. }
  1754. /**
  1755. * Generate DocPropsCore XML template
  1756. *
  1757. * @access private
  1758. */
  1759. private function generateTemplateDocPropsCore()
  1760. {
  1761. date_default_timezone_set('UTC');
  1762. $this->_docPropsCoreT =
  1763. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> ' .
  1764. '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats' .
  1765. '.org/package/2006/metadata/core-properties" ' .
  1766. 'xmlns:dc="http://purl.org/dc/elements/1.1/" ' .
  1767. 'xmlns:dcterms="http://purl.org/dc/terms/" ' .
  1768. 'xmlns:dcmitype="http://purl.org/dc/dcmitype/" ' .
  1769. 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' .
  1770. '<dc:title>Title</dc:title><dc:subject>Subject</dc:subject>' .
  1771. '<dc:creator>2mdc</dc:creator><dc:description>Description' .
  1772. '</dc:description><cp:lastModifiedBy>user' .
  1773. '</cp:lastModifiedBy><cp:revision>1</cp:revision>' .
  1774. '<dcterms:created xsi:type="dcterms:W3CDTF">' . date('c') .
  1775. '</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF' .
  1776. '">' . date('c') . '</dcterms:modified></cp:coreProperties>';
  1777. }
  1778. /**
  1779. * Generate RelsRels XML template
  1780. *
  1781. * @access private
  1782. */
  1783. private function generateTemplateRelsRels()
  1784. {
  1785. $this->_relsRelsT =
  1786. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  1787. '<Relationships xmlns="http://schemas.openxmlformats.org/package/' .
  1788. '2006/relationships">' .
  1789. $this->generateRELATIONSHIP(
  1790. 'rId3', 'extended-properties', 'docProps/app.xml'
  1791. ) .
  1792. '<Relationship Id="rId2" Type="http://schemas.openxmlformats' .
  1793. '.org/package/2006/relationships/metadata/core-properties"' .
  1794. ' Target="docProps/core.xml"/>' .
  1795. $this->generateRELATIONSHIP(
  1796. 'rId1', 'officeDocument', 'word/document.xml'
  1797. );
  1798. $this->_relsRelsT .= '</Relationships>';
  1799. }
  1800. /**
  1801. * Generate WordDocument XML template
  1802. *
  1803. * @access private
  1804. */
  1805. private function generateTemplateWordDocument()
  1806. {
  1807. $arrArgs = func_get_args();
  1808. $this->generateSECTPR($arrArgs[0]);
  1809. if (!empty($this->_wordHeaderC)) {
  1810. $this->_wordDocumentC = str_replace(
  1811. '__GENERATEHEADERREFERENCE__',
  1812. '<' . CreateDocx::NAMESPACEWORD . ':headerReference ' .
  1813. CreateDocx::NAMESPACEWORD . ':type="default" r:id="rId' .
  1814. $this->_idWords['header'] . '"></' .
  1815. CreateDocx::NAMESPACEWORD . ':headerReference>',
  1816. $this->_wordDocumentC
  1817. );
  1818. }
  1819. if (!empty($this->_wordFooterC)) {
  1820. $this->_wordDocumentC = str_replace(
  1821. '__GENERATEFOOTERREFERENCE__',
  1822. '<' . CreateDocx::NAMESPACEWORD . ':footerReference ' .
  1823. CreateDocx::NAMESPACEWORD . ':type="default" r:id="rId' .
  1824. $this->_idWords['footer'] . '"></' .
  1825. CreateDocx::NAMESPACEWORD . ':footerReference>',
  1826. $this->_wordDocumentC
  1827. );
  1828. }
  1829. $this->_wordDocumentT =
  1830. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  1831. '<' . CreateDocx::NAMESPACEWORD . ':document xmlns:ve=' .
  1832. '"http://schemas.openxmlformats.org/markup-compatibility/2006" ' .
  1833. 'xmlns:o="urn:schemas-microsoft-com:office:office"' .
  1834. ' xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006' .
  1835. '/relationships" xmlns:m="http://schemas.openxmlformats.org/' .
  1836. 'officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml"'.
  1837. ' xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/' .
  1838. 'wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:' .
  1839. 'office:word" xmlns:w="http://schemas.openxmlformats.org/' .
  1840. 'wordprocessingml/2006/main" xmlns:wne="http://schemas' .
  1841. '.microsoft.com/office/word/2006/wordml">' .
  1842. '<' . CreateDocx::NAMESPACEWORD . ':body>' .
  1843. $this->_wordDocumentC .
  1844. '</' . CreateDocx::NAMESPACEWORD . ':body>' .
  1845. '</' . CreateDocx::NAMESPACEWORD . ':document>';
  1846. $this->cleanTemplate();
  1847. }
  1848. /**
  1849. * Generate WordEndnotes XML template
  1850. *
  1851. * @access private
  1852. */
  1853. private function generateTemplateWordEndnotes()
  1854. {
  1855. $this->_wordEndnotesT =
  1856. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  1857. '<' . CreateDocx::NAMESPACEWORD . ':endnotes xmlns:ve' .
  1858. '="http://schemas.openxmlformats.org/markup-compatibility/2006" ' .
  1859. 'xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="' .
  1860. 'http://schemas.openxmlformats.org/officeDocument/2006/' .
  1861. 'relationships" xmlns:m="http://schemas.openxmlformats.org/' .
  1862. 'officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:' .
  1863. 'vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006' .
  1864. '/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:' .
  1865. 'office:word" xmlns:w="http://schemas.openxmlformats.org/' .
  1866. 'wordprocessingml/2006/main" xmlns:wne="http://schemas' .
  1867. '.microsoft.com/office/word/2006/wordml">' .
  1868. $this->_wordEndnotesC .
  1869. '</' . CreateDocx::NAMESPACEWORD . ':endnotes>';
  1870. self::$intIdWord++;
  1871. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  1872. 'rId' . self::$intIdWord, 'endnotes', 'endnotes.xml'
  1873. );
  1874. $this->generateOVERRIDE(
  1875. '/word/endnotes.xml',
  1876. 'application/vnd.openxmlformats-officedocument.wordprocessingml' .
  1877. '.endnotes+xml'
  1878. );
  1879. }
  1880. /**
  1881. * Generate WordFontTable XML template
  1882. *
  1883. * @access private
  1884. */
  1885. private function generateTemplateWordFontTable()
  1886. {
  1887. $this->_wordFontTableT =
  1888. '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>' .
  1889. '<' . CreateDocx::NAMESPACEWORD . ':fonts xmlns:r="http://' .
  1890. 'schemas.openxmlformats.org/officeDocument/2006/' .
  1891. 'relationships" xmlns:w="http://schemas.openxmlformats.org/' .
  1892. 'wordprocessingml/2006/main">' . $this->_wordFontTableC .
  1893. '</' . CreateDocx::NAMESPACEWORD . ':fonts>';
  1894. }
  1895. /**
  1896. * Generate WordFooter XML template
  1897. *
  1898. * @access private
  1899. */
  1900. private function generateTemplateWordFooter()
  1901. {
  1902. self::$intIdWord++;
  1903. $this->_idWords['footer'] = self::$intIdWord;
  1904. $this->_wordFooterT =
  1905. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  1906. <' . CreateDocx::NAMESPACEWORD . ':ftr xmlns:ve' .
  1907. '="http://schemas.openxmlformats.org/markup-compatibility/' .
  1908. '2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns' .
  1909. ':r="http://schemas.openxmlformats.org/officeDocument/2006/' .
  1910. 'relationships" xmlns:m="http://schemas.openxmlformats.org/' .
  1911. 'officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml' .
  1912. '" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/' .
  1913. 'wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:' .
  1914. 'office:word" xmlns:w="http://schemas.openxmlformats.org/' .
  1915. 'wordprocessingml/2006/main" xmlns:wne="http://schemas' .
  1916. '.microsoft.com/office/word/2006/wordml">' . $this->_wordFooterC .
  1917. '</' . CreateDocx::NAMESPACEWORD . ':ftr>';
  1918. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  1919. 'rId' . self::$intIdWord, 'footer', 'footer.xml'
  1920. );
  1921. }
  1922. /**
  1923. * Generate WordFootnotes XML template
  1924. *
  1925. * @access private
  1926. */
  1927. private function generateTemplateWordFootnotes()
  1928. {
  1929. $this->_wordFootnotesT =
  1930. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  1931. '<' . CreateDocx::NAMESPACEWORD . ':footnotes xmlns:ve="' .
  1932. 'http://schemas.openxmlformats.org/markup-compatibility/2006" ' .
  1933. 'xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="' .
  1934. 'http://schemas.openxmlformats.org/officeDocument/2006/' .
  1935. 'relationships" xmlns:m="http://schemas.openxmlformats.org/' .
  1936. 'officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:' .
  1937. 'vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006' .
  1938. '/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:' .
  1939. 'office:word" xmlns:w="http://schemas.openxmlformats.org/' .
  1940. 'wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft' .
  1941. '.com/office/word/2006/wordml">' . $this->_wordFootnotesC .
  1942. '</' . CreateDocx::NAMESPACEWORD . ':footnotes>';
  1943. self::$intIdWord++;
  1944. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  1945. 'rId' . self::$intIdWord, 'footnotes', 'footnotes.xml'
  1946. );
  1947. $this->generateOVERRIDE(
  1948. '/word/footnotes.xml',
  1949. 'application/vnd.openxmlformats-officedocument.wordprocessingml' .
  1950. '.footnotes+xml'
  1951. );
  1952. }
  1953. /**
  1954. * Generate WordHeader XML template
  1955. *
  1956. * @access private
  1957. */
  1958. private function generateTemplateWordHeader()
  1959. {
  1960. self::$intIdWord++;
  1961. $this->_idWords['header'] = self::$intIdWord;
  1962. $this->_wordHeaderT = '<?xml version="1.0" encoding="UTF-8" ' .
  1963. 'standalone="yes"?>' .
  1964. '<' . CreateDocx::NAMESPACEWORD .
  1965. ':hdr xmlns:ve="http://schemas.openxmlformats.org/markup' .
  1966. '-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:' .
  1967. 'office:office" xmlns:r="http://schemas.openxmlformats.org/' .
  1968. 'officeDocument/2006/relationships" xmlns:m="http://schemas' .
  1969. '.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:' .
  1970. 'schemas-microsoft-com:vml" xmlns:wp="http://schemas' .
  1971. '.openxmlformats.org/drawingml/2006/wordprocessingDrawing" ' .
  1972. 'xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="' .
  1973. 'http://schemas.openxmlformats.org/wordprocessingml/2006/' .
  1974. 'main" xmlns:wne="http://schemas.microsoft.com/office/word/' .
  1975. '2006/wordml"> ' . $this->_wordHeaderC .
  1976. '</' . CreateDocx::NAMESPACEWORD . ':hdr>';
  1977. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  1978. 'rId' . self::$intIdWord, 'header', 'header.xml'
  1979. );
  1980. }
  1981. /**
  1982. * Generate WordNumbering XML template
  1983. *
  1984. * @access private
  1985. */
  1986. private function generateTemplateWordNumbering()
  1987. {
  1988. $this->_wordNumberingT =
  1989. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  1990. '<w:numbering xmlns:ve="http://schemas.openxmlformats' .
  1991. '.org/markup-compatibility/2006" xmlns:o="urn:schemas-' .
  1992. 'microsoft-com:office:office" xmlns:r="http://schemas' .
  1993. '.openxmlformats.org/officeDocument/2006/relationships" ' .
  1994. 'xmlns:m="http://schemas.openxmlformats.org/officeDocument/' .
  1995. '2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:' .
  1996. 'wp="http://schemas.openxmlformats.org/drawingml/2006/' .
  1997. 'wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com' .
  1998. ':office:word" xmlns:w="http://schemas.openxmlformats.org/' .
  1999. 'wordprocessingml/2006/main" xmlns:wne="http://schemas.' .
  2000. 'microsoft.com/office/word/2006/wordml"><w:abstractNum w:'
  2001. . 'abstractNumId="0"><w:nsid w:val="713727AE"/><w:multiLevelType' .
  2002. ' w:val="hybridMultilevel"/><w:tmpl w:val="F0B4B6B8"/>' .
  2003. '<w:lvl w:ilvl="0" w:tplc="0C0A0001"><w:start w:val="1"/>' .
  2004. '<w:numFmt w:val="bullet"/><w:lvlText w:val=""/><w:lvlJc ' .
  2005. 'w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/>' .
  2006. '</w:pPr><w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" ' .
  2007. 'w:hint="default"/></w:rPr></w:lvl><w:lvl w:ilvl="1" ' .
  2008. 'w:tplc="0C0A0003" w:tentative="1"><w:start w:val="1"/>' .
  2009. '<w:numFmt w:val="bullet"/><w:lvlText w:val="o"/><w:lvlJc ' .
  2010. 'w:val="left"/><w:pPr><w:ind w:left="1440" w:hanging="360"/>' . '
  2011. </w:pPr><w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi=' .
  2012. '"Courier New" w:cs="Courier New" w:hint="default"/></w:rPr>' .
  2013. '</w:lvl><w:lvl w:ilvl="2" w:tplc="0C0A0005" w:tentative="1">' .
  2014. '<w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText ' .
  2015. 'w:val=""/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2160" ' .
  2016. 'w:hanging="360"/></w:pPr><w:rPr><w:rFonts w:ascii="Wingdings" ' .
  2017. 'w:hAnsi="Wingdings" w:hint="default"/></w:rPr></w:lvl><w:lvl ' .
  2018. 'w:ilvl="3" w:tplc="0C0A0001" w:tentative="1"><w:start ' .
  2019. 'w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val=""/>' .
  2020. '<w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2880" w:hanging=' .
  2021. '"360"/></w:pPr><w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi=' .
  2022. '"Symbol" w:hint="default"/></w:rPr></w:lvl><w:lvl w:ilvl="4" ' .
  2023. 'w:tplc="0C0A0003" w:tentative="1"><w:start w:val="1"/>' .
  2024. '<w:numFmt w:val="bullet"/><w:lvlText w:val="o"/><w:lvlJc ' .
  2025. 'w:val="left"/><w:pPr><w:ind w:left="3600" w:hanging="360"/>' .
  2026. '</w:pPr><w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi=' .
  2027. '"Courier New" w:cs="Courier New" w:hint="default"/></w:rPr>' .
  2028. '</w:lvl><w:lvl w:ilvl="5" w:tplc="0C0A0005" w:tentative="1">' .
  2029. '<w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText ' .
  2030. 'w:val=""/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="4320" ' .
  2031. 'w:hanging="360"/></w:pPr><w:rPr><w:rFonts w:ascii="Wingdings" ' .
  2032. 'w:hAnsi="Wingdings" w:hint="default"/></w:rPr></w:lvl><w:lvl ' .
  2033. 'w:ilvl="6" w:tplc="0C0A0001" w:tentative="1"><w:start ' .
  2034. 'w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val=""/>' .
  2035. '<w:lvlJc w:val="left"/><w:pPr><w:ind w:left="5040" ' .
  2036. 'w:hanging="360"/></w:pPr><w:rPr><w:rFonts w:ascii="Symbol" ' .
  2037. 'w:hAnsi="Symbol" w:hint="default"/></w:rPr></w:lvl><w:lvl ' .
  2038. 'w:ilvl="7" w:tplc="0C0A0003" w:tentative="1"><w:start ' .
  2039. 'w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="o"/>' .
  2040. '<w:lvlJc w:val="left"/><w:pPr><w:ind w:left="5760" ' .
  2041. 'w:hanging="360"/></w:pPr><w:rPr><w:rFonts w:ascii="Courier New" ' .
  2042. 'w:hAnsi="Courier New" w:cs="Courier New" w:hint="default"/>' .
  2043. '</w:rPr></w:lvl><w:lvl w:ilvl="8" w:tplc="0C0A0005" ' .
  2044. 'w:tentative="1"><w:start w:val="1"/><w:numFmt w:val="bullet"' .
  2045. '/><w:lvlText w:val=""/><w:lvlJc w:val="left"/><w:pPr><w:ind ' .
  2046. 'w:left="6480" w:hanging="360"/></w:pPr><w:rPr><w:rFonts ' .
  2047. 'w:ascii="Wingdings" w:hAnsi="Wingdings" w:hint="default"/>' .
  2048. '</w:rPr></w:lvl></w:abstractNum><w:num w:numId="1">' .
  2049. '<w:abstractNumId w:val="0"/></w:num></w:numbering>';
  2050. }
  2051. /**
  2052. * Generate WordRelsDocumentRels XML template
  2053. *
  2054. * @access private
  2055. */
  2056. private function generateTemplateWordRelsDocumentRels()
  2057. {
  2058. $this->_wordRelsDocumentRelsT =
  2059. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  2060. '<Relationships xmlns="http://schemas.openxmlformats.org/' .
  2061. 'package/2006/relationships">' . $this->_wordRelsDocumentRelsC .
  2062. '</Relationships>';
  2063. }
  2064. /**
  2065. * Generate WordRelsFooterRels XML template
  2066. *
  2067. * @access private
  2068. */
  2069. private function generateTemplateWordRelsFooterRels()
  2070. {
  2071. $this->_wordRelsFooterRelsT =
  2072. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  2073. '<Relationships xmlns="http://schemas.openxmlformats.org/' .
  2074. 'package/2006/relationships">' . $this->_wordRelsFooterRelsC .
  2075. '</Relationships>';
  2076. }
  2077. /**
  2078. * Generate WordRelsHeaderRels XML template
  2079. *
  2080. * @access private
  2081. */
  2082. private function generateTemplateWordRelsHeaderRels()
  2083. {
  2084. $this->_wordRelsHeaderRelsT =
  2085. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
  2086. '<Relationships xmlns="http://schemas.openxmlformats.org/' .
  2087. 'package/2006/relationships">' . $this->_wordRelsHeaderRelsC .
  2088. '</Relationships>';
  2089. }
  2090. /**
  2091. * Generate WordSettings XML template
  2092. *
  2093. * @access private
  2094. */
  2095. private function generateTemplateWordSettings()
  2096. {
  2097. $this->_wordSettingsT = $this->_wordSettingsC;
  2098. }
  2099. /**
  2100. * Generate WordStyles XML template
  2101. *
  2102. * @access private
  2103. */
  2104. private function generateTemplateWordStyles()
  2105. {
  2106. $this->_wordStylesT =
  2107. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><' .
  2108. CreateDocx::NAMESPACEWORD . ':styles xmlns:r="http://' .
  2109. 'schemas.openxmlformats.org/officeDocument/2006/relationships' .
  2110. '" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/' .
  2111. '2006/main">' . $this->_wordStylesC .
  2112. '</' . CreateDocx::NAMESPACEWORD . ':styles>';
  2113. }
  2114. /**
  2115. * Generate WordThemeTheme1 XML template
  2116. *
  2117. * @access private
  2118. */
  2119. private function generateTemplateWordThemeTheme1()
  2120. {
  2121. $this->addTheme($this->_defaultFont);
  2122. $this->_wordThemeThemeT =
  2123. '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><' .
  2124. CreateTheme1::NAMESPACEWORD . ':theme xmlns:a="http://' .
  2125. 'schemas.openxmlformats.org/drawingml/2006/main" name="' .
  2126. 'Tema de Office">' . $this->_wordThemeThemeC .
  2127. '</' . CreateTheme1::NAMESPACEWORD . ':theme>';
  2128. }
  2129. /**
  2130. * Generate WordWebSettings XML template
  2131. *
  2132. * @access private
  2133. */
  2134. private function generateTemplateWordWebSettings()
  2135. {
  2136. $this->_wordWebSettingsT = $this->_wordWebSettingsC;
  2137. }
  2138. /**
  2139. * Add settings
  2140. *
  2141. * @access private
  2142. */
  2143. private function addSettings()
  2144. {
  2145. $settings = CreateSettings::getInstance();
  2146. $settings->generateSettings();
  2147. $this->_wordSettingsC .= (string) $settings;
  2148. }
  2149. /**
  2150. * Add style
  2151. *
  2152. * @param string lang Language
  2153. * @access private
  2154. */
  2155. private function addStyle($lang = 'en-US')
  2156. {
  2157. $style = CreateStyle::getInstance();
  2158. $style->createStyle($lang);
  2159. $this->_wordStylesC .= (string) $style;
  2160. }
  2161. /**
  2162. * Add theme
  2163. *
  2164. * @access private
  2165. */
  2166. private function addTheme($strFont)
  2167. {
  2168. $theme = CreateTheme1::getInstance();
  2169. $theme->createTheme($strFont);
  2170. $this->_wordThemeThemeC .= (string) $theme;
  2171. }
  2172. /**
  2173. * Add websettings
  2174. *
  2175. * @access private
  2176. */
  2177. private function addWebSettings()
  2178. {
  2179. $webSettings = CreateWebSettings::getInstance();
  2180. $webSettings->generateWebSettings();
  2181. $this->_wordWebSettingsC .= (string) $webSettings;
  2182. }
  2183. /**
  2184. * Clean template
  2185. *
  2186. * @access private
  2187. */
  2188. private function cleanTemplate()
  2189. {
  2190. $this->_wordDocumentT = preg_replace(
  2191. '/__[A-Z]+__/',
  2192. '',
  2193. $this->_wordDocumentT
  2194. );
  2195. }
  2196. /**
  2197. * Generate DEFAULT
  2198. *
  2199. * @access private
  2200. */
  2201. private function generateDEFAULT($extension, $contentType)
  2202. {
  2203. if (
  2204. strpos($this->_contentTypeC, 'Extension="' . $extension)
  2205. === false
  2206. ) {
  2207. $this->_contentTypeC .= '<Default Extension="' .
  2208. $extension . '" ContentType="' . $contentType . '"> </Default>';
  2209. }
  2210. }
  2211. /**
  2212. *
  2213. *
  2214. * @access private
  2215. */
  2216. private function generateDefaultFonts()
  2217. {
  2218. $font = array(
  2219. 'name' => 'Calibri', 'pitch' => 'variable', 'usb0' => 'A00002EF',
  2220. 'usb1' => '4000207B', 'usb2' => '00000000', 'usb3' => '00000000',
  2221. 'csb0' => '0000009F', 'csb1' => '00000000', 'family' => 'swiss',
  2222. 'charset' => '00', 'panose1' => '020F0502020204030204'
  2223. );
  2224. $this->addFont($font);
  2225. $font = array(
  2226. 'name' => 'Times New Roman', 'pitch' => 'variable',
  2227. 'usb0' => 'E0002AEF', 'usb1' => 'C0007841', 'usb2' => '00000009',
  2228. 'usb3' => '00000000', 'csb0' => '000001FF', 'csb1' => '00000000',
  2229. 'family' => 'roman', 'charset' => '00',
  2230. 'panose1' => '02020603050405020304'
  2231. );
  2232. $this->addFont($font);
  2233. $font = array(
  2234. 'name' => 'Cambria', 'pitch' => 'variable', 'usb0' => 'A00002EF',
  2235. 'usb1' => '4000004B', 'usb2' => '00000000', 'usb3' => '00000000',
  2236. 'csb0' => '0000009F', 'csb1' => '00000000', 'family' => 'roman',
  2237. 'charset' => '00', 'panose1' => '02040503050406030204'
  2238. );
  2239. $this->addFont($font);
  2240. }
  2241. /**
  2242. * Generate DefaultWordRels
  2243. *
  2244. * @access private
  2245. */
  2246. private function generateDefaultWordRels()
  2247. {
  2248. self::$intIdWord++;
  2249. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  2250. 'rId' . self::$intIdWord, 'numbering', 'numbering.xml'
  2251. );
  2252. self::$intIdWord++;
  2253. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  2254. 'rId' . self::$intIdWord, 'theme', 'theme/theme1.xml'
  2255. );
  2256. self::$intIdWord++;
  2257. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  2258. 'rId' . self::$intIdWord, 'webSettings', 'webSettings.xml'
  2259. );
  2260. self::$intIdWord++;
  2261. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  2262. 'rId' . self::$intIdWord, 'fontTable', 'fontTable.xml'
  2263. );
  2264. self::$intIdWord++;
  2265. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  2266. 'rId' . self::$intIdWord, 'settings', 'settings.xml'
  2267. );
  2268. self::$intIdWord++;
  2269. $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP(
  2270. 'rId' . self::$intIdWord, 'styles', 'styles.xml'
  2271. );
  2272. }
  2273. /**
  2274. * Generate OVERRIDE
  2275. *
  2276. * @access private
  2277. * @param string $partName
  2278. * @param string $contentType
  2279. */
  2280. private function generateOVERRIDE($partName, $contentType)
  2281. {
  2282. if (
  2283. strpos($this->_contentTypeC, 'PartName="' . $partName . '"')
  2284. === false
  2285. ) {
  2286. $this->_contentTypeC .= '<Override PartName="' .
  2287. $partName . '" ContentType="' . $contentType . '"> </Override>';
  2288. }
  2289. }
  2290. /**
  2291. * Gnerate RELATIONSHIP
  2292. *
  2293. * @access private
  2294. */
  2295. private function generateRELATIONSHIP()
  2296. {
  2297. $arrArgs = func_get_args();
  2298. if ($arrArgs[1] == 'vbaProject')
  2299. $strType =
  2300. 'http://schemas.microsoft.com/office/2006/relationships/vbaProject';
  2301. else
  2302. $strType =
  2303. 'http://schemas.openxmlformats.org/officeDocument/2006/' .
  2304. 'relationships/' . $arrArgs[1];
  2305. return '<Relationship Id="' . $arrArgs[0] . '" Type="' . $strType .
  2306. '" Target="' . $arrArgs[2] . '"></Relationship>';
  2307. }
  2308. /**
  2309. * Parse path dir
  2310. *
  2311. * @access private
  2312. * @param string $dir Directory path
  2313. */
  2314. private function parsePath($dir)
  2315. {
  2316. $barra = 0;
  2317. $path = '';
  2318. if (($barra = strrpos($dir, '/')) !== false) {
  2319. $barra += 1;
  2320. $path = substr($dir, 0, $barra);
  2321. }
  2322. $punto = strpos(substr($dir, $barra), '.');
  2323. $nombre = substr($dir, $barra, $punto);
  2324. $extension = substr($dir, $punto + $barra + 1);
  2325. return array(
  2326. 'path' => $path, 'nombre' => $nombre, 'extension' => $extension
  2327. );
  2328. }
  2329. }