CreateFooter.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /**
  3. * Create footer
  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 footer
  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 CreateFooter extends CreateElement
  28. {
  29. /**
  30. *
  31. * @var CreateFooter
  32. * @access private
  33. * @static
  34. */
  35. private static $_instance = NULL;
  36. /**
  37. *
  38. * @var int
  39. * @access private
  40. * @static
  41. */
  42. private static $_numberPage = 0;
  43. /**
  44. * Construct
  45. *
  46. * @access public
  47. */
  48. public function __construct()
  49. {
  50. }
  51. /**
  52. * Destruct
  53. *
  54. * @access public
  55. */
  56. public function __destruct()
  57. {
  58. }
  59. /**
  60. *
  61. * @return string
  62. * @access public
  63. */
  64. public function __toString()
  65. {
  66. return $this->_xml;
  67. }
  68. /**
  69. *
  70. * @return CreateFooter
  71. * @access public
  72. * @static
  73. */
  74. public static function getInstance()
  75. {
  76. if (self::$_instance == NULL) {
  77. self::$_instance = new CreateFooter();
  78. }
  79. return self::$_instance;
  80. }
  81. /**
  82. * Create footer
  83. *
  84. * @access public
  85. * @param string args[0]
  86. * @param array args[1]
  87. */
  88. public function createFooter()
  89. {
  90. $this->_xml = '';
  91. $args = func_get_args();
  92. $this->generateFTR();
  93. if ($args[1]['pager'] == 'true') {
  94. $this->generateP();
  95. $this->generateR();
  96. $this->generatePTAB('margin', $args[1]['pagerAlignment']);
  97. $this->generateFLDSIMPLE();
  98. }
  99. $text = CreateText::getInstance();
  100. $text->createText($args[0], $args[1]);
  101. $obj = preg_replace('/__[A-Z]+__/', '', (string) $text);
  102. $xml = $obj . '__GENERATEFTR__';
  103. $this->_xml = str_replace('__GENERATEFTR__', $xml, $this->_xml);
  104. }
  105. /**
  106. * Generate ftr token
  107. *
  108. * @access protected
  109. */
  110. protected function generateFTR()
  111. {
  112. //$this->_xml = '__GENERATEFTR____GENERATEIMGFTR__';
  113. $this->_xml = '';
  114. }
  115. /**
  116. * Generate w:p
  117. *
  118. * @access protected
  119. */
  120. protected function generateP()
  121. {
  122. $xml = '<' . CreateElement::NAMESPACEWORD .
  123. ':p>__GENERATEP__</' . CreateElement::NAMESPACEWORD .
  124. ':p>__GENERATEFTR__';
  125. $this->_xml = str_replace('__GENERATEFTR__', $xml, $this->_xml);
  126. }
  127. /**
  128. * Generate w:r
  129. *
  130. * @access protected
  131. */
  132. protected function generateR()
  133. {
  134. if (!empty($this->_xml)) {
  135. if (preg_match("/__GENERATEP__/", $this->_xml)) {
  136. $xml = '<' . CreateElement::NAMESPACEWORD .
  137. ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
  138. ':r>__GENERATERSUB__';
  139. $this->_xml = str_replace('__GENERATEP__', $xml, $this->_xml);
  140. } elseif (preg_match("/__GENERATER__/", $this->_xml)) {
  141. $xml = '<' . CreateElement::NAMESPACEWORD .
  142. ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
  143. ':r>__GENERATERSUB__';
  144. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  145. } elseif (preg_match("/__GENERATERSUB__/", $this->_xml)) {
  146. $xml = '<' . CreateElement::NAMESPACEWORD .
  147. ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
  148. ':r>__GENERATERSUB__';
  149. $this->_xml = str_replace(
  150. '__GENERATERSUB__', $xml, $this->_xml
  151. );
  152. }
  153. } else {
  154. $this->_xml = '<' . CreateElement::NAMESPACEWORD .
  155. ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
  156. ':r>__GENERATERSUB__';
  157. }
  158. }
  159. /**
  160. * Generate w:ptab
  161. *
  162. * @param string $relativeTo
  163. * @param string $alignment
  164. * @param string $leader
  165. * @access protected
  166. */
  167. protected function generatePTAB($relativeTo = 'margin',
  168. $alignment = 'right',
  169. $leader = 'none')
  170. {
  171. $xml = '<' . CreateElement::NAMESPACEWORD .
  172. ':ptab ' . CreateElement::NAMESPACEWORD .
  173. ':relativeTo="' . $relativeTo .
  174. '" ' . CreateElement::NAMESPACEWORD .
  175. ':alignment="' . $alignment .
  176. '" ' . CreateElement::NAMESPACEWORD .
  177. ':leader="' . $leader .
  178. '"></' . CreateElement::NAMESPACEWORD . ':ptab>';
  179. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  180. }
  181. /**
  182. * Generate w:fldsimple
  183. *
  184. * @access protected
  185. */
  186. protected function generateFLDSIMPLE()
  187. {
  188. $xml = '<' . CreateElement::NAMESPACEWORD .
  189. ':fldSimple ' . CreateElement::NAMESPACEWORD .
  190. ':instr=" PAGE \* MERGEFORMAT "></'
  191. . CreateElement::NAMESPACEWORD . ':fldSimple>';
  192. $this->_xml = str_replace('__GENERATERSUB__', $xml, $this->_xml);
  193. }
  194. }