CreatePage.inc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /**
  3. * Create pages
  4. *
  5. * @category Phpdocx
  6. * @package elements
  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. include_once dirname(__FILE__) . '/CreateElement.inc';
  15. /**
  16. * Create pages
  17. *
  18. * @category Phpdocx
  19. * @package elements
  20. * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
  21. * (http://www.2mdc.com)
  22. * @license http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php
  23. * @version 1.0
  24. * @link http://www.phpdocx.com
  25. * @since Class available since Release 1.0
  26. */
  27. class CreatePage extends CreateElement
  28. {
  29. /**
  30. * @access protected
  31. * @var string
  32. */
  33. protected $_xml;
  34. /**
  35. * @access private
  36. * @var CreatePage
  37. * @static
  38. */
  39. private static $_instance = NULL;
  40. /**
  41. * Construct
  42. *
  43. * @access public
  44. */
  45. public function __construct()
  46. {
  47. }
  48. /**
  49. * Destruct
  50. *
  51. * @access public
  52. */
  53. public function __destruct()
  54. {
  55. }
  56. /**
  57. *
  58. * @access public
  59. * @return string
  60. */
  61. public function __toString()
  62. {
  63. return $this->_xml;
  64. }
  65. /**
  66. *
  67. * @access public
  68. * @return CreatePage
  69. * @static
  70. */
  71. public static function getInstance()
  72. {
  73. if (self::$_instance == NULL) {
  74. self::$_instance = new CreatePage();
  75. }
  76. return self::$_instance;
  77. }
  78. /**
  79. * Create page
  80. */
  81. public function createPage()
  82. {
  83. $this->_xml = '';
  84. }
  85. /**
  86. * Create sectpr
  87. *
  88. * @access public
  89. * @param array args[0]
  90. */
  91. public function createSECTPR()
  92. {
  93. $this->_xml = '';
  94. $args = func_get_args();
  95. $this->generateSECTPR();
  96. if (!empty($args[0]['orient']) && $args[0]['orient'] == 'landscape') {
  97. $this->generatePGSZ(16838, 11906, 'landscape');
  98. } else {
  99. $this->generatePGSZ(11906, 16838);
  100. }
  101. $this->generatePGMAR($args);
  102. $this->generateCOLS();
  103. if (!empty($args[0]['titlePage'])) $this->generateTITLEPG();
  104. $this->generateDOCGRID();
  105. }
  106. /**
  107. * Gnerate pagebreak
  108. *
  109. * @access public
  110. * @param string $type
  111. */
  112. public function generatePageBreak($type)
  113. {
  114. $this->_xml = '';
  115. $this->generateP();
  116. if ($type != 'line' && $type != '') {
  117. $this->generateR();
  118. $this->generateBR($type);
  119. }
  120. $this->cleanTemplate();
  121. }
  122. /**
  123. * Generate w:sectpr
  124. *
  125. * @access protected
  126. * @param string $rId
  127. */
  128. protected function generateSECTPR($rId = '12240')
  129. {
  130. $this->_xml = '<' . CreateElement::NAMESPACEWORD . ':sectPr ' .
  131. CreateDocx::NAMESPACEWORD . ':rsidR="' . $rId . '" ' .
  132. CreateDocx::NAMESPACEWORD . ':rsidRPr="' . $rId . '" ' .
  133. CreateDocx::NAMESPACEWORD . ':rsidSect="' . $rId .
  134. '">__GENERATEHEADERREFERENCE____GENERATEFOOTERREFERENCE____' .
  135. 'GENERATESECTPR__</' . CreateElement::NAMESPACEWORD .
  136. ':sectPr>';
  137. }
  138. /**
  139. * Generate w:pgsz
  140. *
  141. * @access protected
  142. * @param string $w
  143. * @param string $h
  144. * @param string $orient
  145. */
  146. protected function generatePGSZ($w = '11906', $h = '16838', $orient = '')
  147. {
  148. $xmlAux = '<' . CreateElement::NAMESPACEWORD . ':pgSz ' .
  149. CreateElement::NAMESPACEWORD . ':w="' . $w . '" ' .
  150. CreateElement::NAMESPACEWORD . ':h="' . $h . '"';
  151. if ($orient != '') {
  152. $xmlAux .= ' ' . CreateElement::NAMESPACEWORD . ':orient="' .
  153. $orient . '"';
  154. }
  155. $xmlAux .= '></' . CreateElement::NAMESPACEWORD .
  156. ':pgSz>__GENERATEPGSZ__';
  157. $this->_xml = str_replace('__GENERATESECTPR__', $xmlAux, $this->_xml);
  158. }
  159. /**
  160. * Generate w:pgmar
  161. *
  162. * @access protected
  163. * @param array $args[0]
  164. */
  165. protected function generatePGMAR()
  166. {
  167. $top = '1440';
  168. $right = '1800';
  169. $bottom = '1440';
  170. $left = '1800';
  171. $header = '0';
  172. $footer = '0';
  173. $gutter = '0';
  174. $args = func_get_args();
  175. if (isset($args[0][0]['top'])) $top = $args[0][0]['top'];
  176. if (isset($args[0][0]['bottom'])) $bottom = $args[0][0]['bottom'];
  177. if (isset($args[0][0]['right'])) $right = $args[0][0]['right'];
  178. if (isset($args[0][0]['left'])) $left = $args[0][0]['left'];
  179. $xml = '<' . CreateElement::NAMESPACEWORD . ':pgMar ' .
  180. CreateElement::NAMESPACEWORD . ':top="' . $top . '" ' .
  181. CreateElement::NAMESPACEWORD . ':right="' . $right . '" ' .
  182. CreateElement::NAMESPACEWORD . ':bottom="' . $bottom . '" ' .
  183. CreateElement::NAMESPACEWORD . ':left="' . $left . '" ' .
  184. CreateElement::NAMESPACEWORD . ':header="' . $header . '" ' .
  185. CreateElement::NAMESPACEWORD . ':footer="' . $footer . '" ' .
  186. CreateElement::NAMESPACEWORD . ':gutter="' . $gutter . '"></' .
  187. CreateElement::NAMESPACEWORD . ':pgMar>__GENERATEPGMAR__';
  188. $this->_xml = str_replace('__GENERATEPGSZ__', $xml, $this->_xml);
  189. }
  190. /**
  191. * Generate w:cols
  192. *
  193. * @access protected
  194. * @param string $num
  195. * @param string $sep
  196. * @param string $space
  197. * @param string $equalWidth
  198. */
  199. protected function generateCOLS($num = '', $sep = '', $space = '708',
  200. $equalWidth = '')
  201. {
  202. $xml = '<' . CreateElement::NAMESPACEWORD . ':cols ' .
  203. CreateElement::NAMESPACEWORD . ':space="' . $space . '"></' .
  204. CreateElement::NAMESPACEWORD . ':cols>__GENERATECOLS__';
  205. $this->_xml = str_replace('__GENERATEPGMAR__', $xml, $this->_xml);
  206. }
  207. /**
  208. * Generate w:col
  209. *
  210. * @access protected
  211. * @deprecated
  212. * @param string $w
  213. * @param string $space
  214. */
  215. protected function generateCOL($w = '', $space = '708')
  216. {
  217. }
  218. /**
  219. * Generate w:docgrid
  220. *
  221. * @access protected
  222. * @param string $linepitch
  223. */
  224. protected function generateDOCGRID($linepitch = '360')
  225. {
  226. $xml = '<' . CreateElement::NAMESPACEWORD . ':docGrid ' .
  227. CreateElement::NAMESPACEWORD . ':linePitch="' .
  228. $linepitch . '"></' . CreateElement::NAMESPACEWORD . ':docGrid>';
  229. $this->_xml = str_replace('__GENERATECOLS__', $xml, $this->_xml);
  230. }
  231. /**
  232. * Generate w:br
  233. *
  234. * @access protected
  235. * @param string $type
  236. */
  237. protected function generateBR($type = '')
  238. {
  239. $xml = '<' . CreateElement::NAMESPACEWORD . ':br ' .
  240. CreateElement::NAMESPACEWORD . ':type="' . $type . '"></' .
  241. CreateElement::NAMESPACEWORD . ':br>';
  242. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  243. }
  244. /**
  245. * Generate w:sectionsectpr
  246. *
  247. * @access protected
  248. * @param string $rId
  249. */
  250. protected function generateSECTIONSECTPR($rId = '12240')
  251. {
  252. $xml = '<' . CreateElement::NAMESPACEWORD . ':sectPr ' .
  253. CreateDocx::NAMESPACEWORD . ':rsidR="' . $rId . '" ' .
  254. CreateDocx::NAMESPACEWORD . ':rsidRPr="' . $rId . '" ' .
  255. CreateDocx::NAMESPACEWORD . ':rsidSect="' . $rId .
  256. '">__GENERATEHEADERREFERENCE____GENERATEFOOTERREFERENCE____' .
  257. 'GENERATESECTPR__</' . CreateElement::NAMESPACEWORD .
  258. ':sectPr>__GENERATEPPR__';
  259. $this->_xml = str_replace('__GENERATEPPR__', $xml, $this->_xml);
  260. }
  261. /**
  262. * Generate w:titlepg
  263. *
  264. * @access protected
  265. */
  266. protected function generateTITLEPG()
  267. {
  268. $xml = '<' . CreateElement::NAMESPACEWORD . ':titlePg></' .
  269. CreateElement::NAMESPACEWORD . ':titlePg>__GENERATECOLS__';
  270. $this->_xml = str_replace('__GENERATECOLS__', $xml, $this->_xml);
  271. }
  272. }