CreateList.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /**
  3. * Create lists
  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 lists
  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 CreateList extends CreateElement
  28. {
  29. /**
  30. *
  31. * @var mixed
  32. * @access public
  33. */
  34. public $list;
  35. /**
  36. *
  37. * @var array
  38. * @access public
  39. */
  40. public $val;
  41. /**
  42. *
  43. * @var string
  44. * @access public
  45. */
  46. public $font;
  47. /**
  48. *
  49. * @var array
  50. * @access public
  51. */
  52. public $data;
  53. /**
  54. * @access private
  55. * @var CreateList
  56. * @static
  57. */
  58. private static $_instance = NULL;
  59. /**
  60. *
  61. * @access private
  62. * @var int
  63. * @static
  64. */
  65. private static $_numericList = -1;
  66. /**
  67. * Construct
  68. *
  69. * @access public
  70. */
  71. public function __construct()
  72. {
  73. }
  74. /**
  75. * Destruct
  76. *
  77. * @access public
  78. */
  79. public function __destruct()
  80. {
  81. }
  82. /**
  83. *
  84. * @access public
  85. * @return string
  86. */
  87. public function __toString()
  88. {
  89. $this->cleanTemplate();
  90. return $this->_xml;
  91. }
  92. /**
  93. *
  94. * @access public
  95. * @return CreateList
  96. * @static
  97. */
  98. public static function getInstance()
  99. {
  100. if (self::$_instance == NULL) {
  101. self::$_instance = new CreateList();
  102. }
  103. return self::$_instance;
  104. }
  105. /**
  106. * Create list
  107. *
  108. * @access public
  109. * @param array args[0]
  110. * @param array args[1]
  111. */
  112. public function createList()
  113. {
  114. $this->_xml = '';
  115. $args = func_get_args();
  116. $this->list = '';
  117. if ($args[1]['val'] == 2) {
  118. self::$_numericList++;
  119. $this->runArray(
  120. $args[0],
  121. $args[1]['val'] + self::$_numericList,
  122. 1,
  123. $args[1]['font']
  124. );
  125. } else {
  126. $this->runArray($args[0], $args[1]['val'], 1, $args[1]['font']);
  127. }
  128. $this->_xml = $this->list;
  129. }
  130. /**
  131. * Add list
  132. *
  133. * @param string $list
  134. * @access protected
  135. */
  136. protected function addList($list)
  137. {
  138. $this->_xml = str_replace('__GENERATER__', $list, $this->_xml);
  139. }
  140. /**
  141. * Generate w:ilfo
  142. *
  143. * @param int $val
  144. * @access protected
  145. */
  146. protected function generateILFO($val = 0)
  147. {
  148. $xml = '<' . CreateElement::NAMESPACEWORD .
  149. ':ilfo ' . CreateElement::NAMESPACEWORD .
  150. ':val="' . $val .
  151. '"></' . CreateElement::NAMESPACEWORD .
  152. ':ilfo>';
  153. $this->_xml = str_replace('__GENERATEILFO__', $xml, $this->_xml);
  154. }
  155. /**
  156. * Generate w:ilvl
  157. *
  158. * @param string $val
  159. * @access protected
  160. */
  161. protected function generateILVL($val = '')
  162. {
  163. $xml = '<' . CreateElement::NAMESPACEWORD .
  164. ':ilvl ' . CreateElement::NAMESPACEWORD .
  165. ':val="' . $val . '"></' . CreateElement::NAMESPACEWORD .
  166. ':ilvl>__GENERATEPSTYLE__';
  167. $this->_xml = str_replace('__GENERATEPSTYLE__', $xml, $this->_xml);
  168. }
  169. /**
  170. * Generate w:listpr
  171. *
  172. * @access protected
  173. */
  174. protected function generateLISTPR()
  175. {
  176. $xml = '<' . CreateElement::NAMESPACEWORD .
  177. ':listPr>__GENERATEILVL____GENERATEILFO__</' .
  178. CreateElement::NAMESPACEWORD . ':listPr>__GENERATER__';
  179. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  180. }
  181. /**
  182. * Generate w:numid
  183. *
  184. * @param int $val
  185. * @access protected
  186. */
  187. protected function generateNUMID($val)
  188. {
  189. $xml = '<' . CreateElement::NAMESPACEWORD .
  190. ':numId ' . CreateElement::NAMESPACEWORD .
  191. ':val="' . $val . '"></' . CreateElement::NAMESPACEWORD .
  192. ':numId>';
  193. $this->_xml = str_replace('__GENERATEPSTYLE__', $xml, $this->_xml);
  194. }
  195. /**
  196. * Generate w:numpr
  197. *
  198. * @access protected
  199. */
  200. protected function generateNUMPR()
  201. {
  202. $xml = '<' . CreateElement::NAMESPACEWORD .
  203. ':numPr>__GENERATEPSTYLE__</' . CreateElement::NAMESPACEWORD .
  204. ':numPr>';
  205. $this->_xml = str_replace('__GENERATEPSTYLE__', $xml, $this->_xml);
  206. }
  207. /**
  208. * Generate w:pstyle
  209. *
  210. * @param string $val
  211. * @access protected
  212. */
  213. protected function generatePSTYLE($val)
  214. {
  215. $xml = '<' . CreateElement::NAMESPACEWORD .
  216. ':pStyle ' . CreateElement::NAMESPACEWORD . ':val="' . $val .
  217. '">__GENERATEPSTYLE__</' . CreateElement::NAMESPACEWORD .
  218. ':pStyle>';
  219. $this->_xml = str_replace('__GENERATEPPR__', $xml, $this->_xml);
  220. }
  221. /**
  222. * Recursive generation of lists
  223. *
  224. * @param array $dat
  225. * @param string $val
  226. * @param int $depth
  227. * @param string $font
  228. * @access protected
  229. */
  230. protected function runArray($dat, $val, $depth, $font = '')
  231. {
  232. foreach ($dat as $cont) {
  233. $this->generateP();
  234. $this->generatePPR();
  235. $this->generatePSTYLE('Prrafodelista');
  236. $this->generateNUMPR();
  237. $this->generateILVL($depth);
  238. $this->generateNUMID($val);
  239. $this->generateR();
  240. if ($font != '') {
  241. $this->generateRPR();
  242. $this->generateRFONTS($font);
  243. }
  244. $this->generateT($cont);
  245. $this->list .= $this->_xml;
  246. }
  247. }
  248. }