CreateFootnote.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. /**
  3. * Create footnote
  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 footnote
  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 CreateFootnote extends CreateElement
  28. {
  29. /**
  30. *
  31. * @var bool
  32. * @access public
  33. * @static
  34. */
  35. public static $init = 0;
  36. /**
  37. *
  38. * @var CreateFootnote
  39. * @access private
  40. * @static
  41. */
  42. private static $_instance = NULL;
  43. /**
  44. *
  45. * @var int
  46. * @access private
  47. * @static
  48. */
  49. private static $_id;
  50. /**
  51. * Construct
  52. *
  53. * @access public
  54. */
  55. public function __construct()
  56. {
  57. }
  58. /**
  59. * Destruct
  60. *
  61. * @access public
  62. */
  63. public function __destruct()
  64. {
  65. }
  66. /**
  67. *
  68. * @return string
  69. * @access public
  70. */
  71. public function __toString()
  72. {
  73. return $this->_xml;
  74. }
  75. /**
  76. *
  77. * @return CreateFootnote
  78. * @access public
  79. * @static
  80. */
  81. public static function getInstance()
  82. {
  83. if (self::$_instance == NULL) {
  84. self::$_instance = new CreateFootnote();
  85. }
  86. return self::$_instance;
  87. }
  88. /**
  89. * Create footnote
  90. *
  91. * @access public
  92. * @param array $args[0]
  93. *
  94. */
  95. public function createFootnote()
  96. {
  97. $this->_xml = '';
  98. $args = func_get_args();
  99. $this->generateFOOTNOTE('');
  100. $this->generateP();
  101. $this->generatePPR();
  102. $this->generatePSTYLE();
  103. $this->generateR();
  104. $this->generateRPR();
  105. $this->generateRSTYLE();
  106. $this->generateFOOTNOTEREF();
  107. $this->generateR();
  108. if ($args[0]['font'] != '') {
  109. $this->generateRPR();
  110. $this->generateRFONTS($args[0]['font']);
  111. }
  112. $this->generateT($args[0]['textEndNote']);
  113. $this->cleanTemplate();
  114. }
  115. /**
  116. * Create document footnote
  117. *
  118. * @access public
  119. * @param array $args[0]
  120. *
  121. */
  122. public function createDocumentFootnote()
  123. {
  124. $this->_xml = '';
  125. $args = func_get_args();
  126. parent::generateP();
  127. $this->generateR();
  128. if ($args[0]['font'] != '') {
  129. $this->generateRPR();
  130. $this->generateRFONTS($args[0]['font']);
  131. }
  132. $xml = '';
  133. $this->_xml = str_replace('__GENERATERPR__', $xml, $this->_xml);
  134. $this->generateT($args[0]['textDocument']);
  135. $this->generateR();
  136. $this->generateRPR();
  137. $this->generateRSTYLE();
  138. $this->generateFOOTNOTEREFERENCE(self::$_id - 2);
  139. $this->cleanTemplate();
  140. }
  141. /**
  142. * Create init footnote
  143. *
  144. * @access public
  145. * @param array $args[0]
  146. *
  147. */
  148. public function createInitFootnote()
  149. {
  150. $this->_xml = '';
  151. $args = func_get_args();
  152. $this->generateFOOTNOTE($args[0]['type']);
  153. $this->generateP();
  154. $this->generatePPR();
  155. $this->generateSPACING();
  156. $this->generateR();
  157. $this->generateSEPARATOR($args[0]['type']);
  158. $this->cleanTemplate();
  159. }
  160. /**
  161. * Generate w:footnote
  162. *
  163. * @param string $type
  164. * @access protected
  165. */
  166. protected function generateFOOTNOTE($type)
  167. {
  168. self::$init = 1;
  169. if (empty(self::$_id)) {
  170. self::$_id = 1;
  171. } else {
  172. self::$_id++;
  173. }
  174. $xmlAux = '<' . CreateElement::NAMESPACEWORD . ':footnote';
  175. if ($type != '')
  176. $xmlAux .= ' ' . CreateElement::NAMESPACEWORD .
  177. ':type="' . $type . '"';
  178. $this->_xml = $xmlAux . ' ' . CreateElement::NAMESPACEWORD .
  179. ':id="' . (self::$_id - 2) .
  180. '">__GENERATEFOOTNOTE__</' . CreateElement::NAMESPACEWORD .
  181. ':footnote>';
  182. }
  183. /**
  184. * Generate w:p
  185. *
  186. * @param string $rsidR
  187. * @param string $rsidRDefault
  188. * @param string $rsidP
  189. * @access protected
  190. */
  191. protected function generateP($rsidR = '005F02E5',
  192. $rsidRDefault = '005F02E5',
  193. $rsidP = '005F02E5')
  194. {
  195. $xml = '<' . CreateElement::NAMESPACEWORD .
  196. ':p>__GENERATEP__</' . CreateElement::NAMESPACEWORD . ':p>';
  197. $this->_xml = str_replace('__GENERATEFOOTNOTE__', $xml, $this->_xml);
  198. }
  199. /**
  200. * Generate w:separator
  201. *
  202. * @param string $type
  203. * @access protected
  204. */
  205. protected function generateSEPARATOR($type = 'separator')
  206. {
  207. $xml = '<w:' . $type . '></w:' . $type . '>';
  208. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  209. }
  210. /**
  211. * Generate w:ppr
  212. *
  213. * @access protected
  214. */
  215. protected function generatePPR()
  216. {
  217. $xml = '<' . CreateElement::NAMESPACEWORD .
  218. ':pPr>__GENERATEPPR__</' . CreateElement::NAMESPACEWORD .
  219. ':pPr>__GENERATEP__';
  220. $this->_xml = str_replace('__GENERATEP__', $xml, $this->_xml);
  221. }
  222. /**
  223. * Generate w:spacing
  224. *
  225. * @param string $after
  226. * @param string $line
  227. * @param string $lineRule
  228. * @access protected
  229. */
  230. protected function generateSPACING($after = '0',
  231. $line = '240', $lineRule = 'auto')
  232. {
  233. $xml = '<' . CreateElement::NAMESPACEWORD .
  234. ':spacing w:after="' . $after .
  235. '" ' . CreateElement::NAMESPACEWORD .
  236. ':line="' . $line .
  237. '" ' . CreateElement::NAMESPACEWORD .
  238. ':lineRule="' . $lineRule .
  239. '"></' . CreateElement::NAMESPACEWORD .
  240. ':spacing>';
  241. $this->_xml = str_replace('__GENERATEPPR__', $xml, $this->_xml);
  242. }
  243. /**
  244. * Generate w:r
  245. *
  246. * @access protected
  247. */
  248. protected function generateR()
  249. {
  250. $xml = '<' . CreateElement::NAMESPACEWORD .
  251. ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
  252. ':r>__GENERATEP__';
  253. $this->_xml = str_replace('__GENERATEP__', $xml, $this->_xml);
  254. }
  255. /**
  256. * Generate w:footnoteref
  257. *
  258. * @access protected
  259. */
  260. protected function generateFOOTNOTEREF()
  261. {
  262. $xml = '<' . CreateElement::NAMESPACEWORD .
  263. ':footnoteRef></' . CreateElement::NAMESPACEWORD .
  264. ':footnoteRef>';
  265. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  266. }
  267. /**
  268. * Generate w:footnotereference
  269. *
  270. * @param string $id
  271. * @access protected
  272. */
  273. protected function generateFOOTNOTEREFERENCE($id = '')
  274. {
  275. $xml = '<' . CreateElement::NAMESPACEWORD .
  276. ':footnoteReference ' . CreateElement::NAMESPACEWORD .
  277. ':id="' . $id . '"></' . CreateElement::NAMESPACEWORD .
  278. ':footnoteReference>';
  279. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  280. }
  281. }