CreateLink.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /**
  3. * Create links using text strings
  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 links using text strings
  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 CreateLink extends CreateElement
  28. {
  29. /**
  30. *
  31. * @access private
  32. * @static
  33. */
  34. private static $_instance = null;
  35. /**
  36. *
  37. * @access private
  38. * @var string
  39. */
  40. private $_link;
  41. /**
  42. *
  43. * @access private
  44. * @var string
  45. */
  46. private $_title;
  47. /**
  48. *
  49. * @access private
  50. * @var string
  51. */
  52. private $_font;
  53. /**
  54. * Construct
  55. *
  56. * @access public
  57. */
  58. public function __construct()
  59. {
  60. }
  61. /**
  62. * Destruct
  63. *
  64. * @access public
  65. */
  66. public function __destruct()
  67. {
  68. }
  69. /**
  70. * Magic method, returns current XML
  71. *
  72. * @access public
  73. * @return string Return current XML
  74. */
  75. public function __toString()
  76. {
  77. return $this->_xml;
  78. }
  79. /**
  80. * Singleton, return instance of class
  81. *
  82. * @access public
  83. * @return CreateLink
  84. * @static
  85. */
  86. public static function getInstance()
  87. {
  88. if (self::$_instance == NULL) {
  89. self::$_instance = new CreateLink();
  90. }
  91. return self::$_instance;
  92. }
  93. /**
  94. * Getter. Access to link var
  95. *
  96. * @access public
  97. * @return string
  98. */
  99. public function getLink()
  100. {
  101. return $this->_link;
  102. }
  103. /**
  104. * Getter. Access to title var
  105. *
  106. * @access public
  107. * @return string
  108. */
  109. public function getTitle()
  110. {
  111. return $this->_title;
  112. }
  113. /**
  114. * Getter. Access to font var
  115. *
  116. * @access public
  117. * @return string
  118. */
  119. public function getFont()
  120. {
  121. return $this->_font;
  122. }
  123. /**
  124. * Create a link
  125. *
  126. * @access public
  127. * @param string $arrArgs[0] Text to add
  128. * @param string $arrArgs[1] URL to add
  129. * @param string $arrArgs[2] RFONTS
  130. */
  131. public function createLink()
  132. {
  133. $this->_xml = '';
  134. $args = func_get_args();
  135. $this->generateP();
  136. $this->generateR();
  137. $this->generateFLDCHAR('begin');
  138. $this->generateR();
  139. $this->generateINSTRTEXT($args[1]);
  140. $this->generateR();
  141. $this->generateFLDCHAR('separate');
  142. $this->generatePROOFERR('gramStart');
  143. $this->generateR();
  144. $this->generateRPR();
  145. $this->generateRFONTS($args[2]);
  146. $this->generateRSTYLE('Hipervnculo');
  147. $this->generateT($args[0]);
  148. $this->generatePROOFERR('gramEnd');
  149. $this->generateR();
  150. $this->generateFLDCHAR('end');
  151. }
  152. /**
  153. * Generate w:fldChar
  154. *
  155. * @access protected
  156. * @param string $fldCharType
  157. */
  158. protected function generateFLDCHAR($fldCharType)
  159. {
  160. $strXML = '<' . CreateElement::NAMESPACEWORD . ':fldChar '
  161. . CreateElement::NAMESPACEWORD . ':fldCharType="'
  162. . $fldCharType . '"></'
  163. . CreateElement::NAMESPACEWORD . ':fldChar>';
  164. $this->_xml = str_replace('__GENERATER__', $strXML, $this->_xml);
  165. }
  166. /**
  167. * Generate w:hyperlink
  168. *
  169. * @access protected
  170. * @param string $type
  171. */
  172. protected function generateHYPERLINK($type)
  173. {
  174. $this->_xml = '<' . createElement::NAMESPACEWORD
  175. . ':hyperlink r:id="rId5" w:history="1">__GENERATEP__</'
  176. . createElement::NAMESPACEWORD . ':hyperlink>';
  177. }
  178. /**
  179. * Generate w:instrText
  180. *
  181. * @access protected
  182. * @param string $link. Optional, use http://localhost as default
  183. */
  184. protected function generateINSTRTEXT($link = 'http://localhost')
  185. {
  186. $xml = '<' . createElement::NAMESPACEWORD
  187. . ':instrText xml:space="preserve"> HYPERLINK "'
  188. . $link . '"</' . createElement::NAMESPACEWORD
  189. . ':instrText>';
  190. $this->_xml = str_replace('__GENERATER__', $xml, $this->_xml);
  191. }
  192. /**
  193. * Generate w:proofErr
  194. *
  195. * @access protected
  196. * @param string $type
  197. */
  198. protected function generatePROOFERR($type)
  199. {
  200. $xml = '<' . createElement::NAMESPACEWORD . ':proofErr '
  201. . createElement::NAMESPACEWORD . ':type="' . $type
  202. . '"></' . createElement::NAMESPACEWORD
  203. . ':proofErr>__GENERATERSUB__';
  204. $this->_xml = str_replace('__GENERATERSUB__', $xml, $this->_xml);
  205. }
  206. /**
  207. * Generate w:r
  208. *
  209. * @access protected
  210. */
  211. protected function generateR()
  212. {
  213. if (preg_match("/__GENERATEP__/", $this->_xml)) {
  214. $xml = '<' . createElement::NAMESPACEWORD
  215. . ':r>__GENERATER__</' . createElement::NAMESPACEWORD
  216. . ':r>__GENERATERSUB__';
  217. $this->_xml = str_replace('__GENERATEP__', $xml, $this->_xml);
  218. } elseif (preg_match("/__GENERATERSUB__/", $this->_xml)) {
  219. $xml = '<' . createElement::NAMESPACEWORD . ':r>'
  220. . '__GENERATER__</' . createElement::NAMESPACEWORD
  221. . ':r>__GENERATERSUB__';
  222. $this->_xml = str_replace('__GENERATERSUB__', $xml, $this->_xml);
  223. } else {
  224. $this->_xml = '<' . createElement::NAMESPACEWORD
  225. . ':r>__GENERATER__</' . createElement::NAMESPACEWORD
  226. . ':r>__GENERATERSUB__';
  227. }
  228. }
  229. /**
  230. * Generate w:rStyle
  231. *
  232. * @access protected
  233. * @param string $val
  234. */
  235. protected function generateRSTYLE($val)
  236. {
  237. $xml = '<' . createElement::NAMESPACEWORD . ':rStyle '
  238. . createElement::NAMESPACEWORD . ':val="' . $val . '"></'
  239. . createElement::NAMESPACEWORD . ':rStyle>';
  240. $this->_xml = str_replace('__GENERATERPR__', $xml, $this->_xml);
  241. }
  242. }