OpenDocument.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Simple interface for creating OASIS OpenDocument files.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin;
  9. use PhpMyAdmin\ZipExtension;
  10. /**
  11. * Simplfied OpenDocument creator class
  12. *
  13. * @package PhpMyAdmin
  14. */
  15. class OpenDocument
  16. {
  17. const NS = <<<EOT
  18. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  19. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  20. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  21. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  22. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  23. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  24. EOT;
  25. /**
  26. * Minimalistic creator of OASIS OpenDocument
  27. *
  28. * @param string $mime desired MIME type
  29. * @param string $data document content
  30. *
  31. * @return string OASIS OpenDocument data
  32. *
  33. * @access public
  34. */
  35. public static function create($mime, $data)
  36. {
  37. $data = array(
  38. $mime,
  39. $data,
  40. '<?xml version="1.0" encoding="UTF-8"?' . '>'
  41. . '<office:document-meta '
  42. . 'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" '
  43. . 'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" '
  44. . 'office:version="1.0">'
  45. . '<office:meta>'
  46. . '<meta:generator>phpMyAdmin ' . PMA_VERSION . '</meta:generator>'
  47. . '<meta:initial-creator>phpMyAdmin ' . PMA_VERSION
  48. . '</meta:initial-creator>'
  49. . '<meta:creation-date>' . strftime('%Y-%m-%dT%H:%M:%S')
  50. . '</meta:creation-date>'
  51. . '</office:meta>'
  52. . '</office:document-meta>',
  53. '<?xml version="1.0" encoding="UTF-8"?' . '>'
  54. . '<office:document-styles ' . OpenDocument::NS
  55. . ' office:version="1.0">'
  56. . '<office:font-face-decls>'
  57. . '<style:font-face style:name="Arial Unicode MS"'
  58. . ' svg:font-family="\'Arial Unicode MS\'" style:font-pitch="variable"/>'
  59. . '<style:font-face style:name="DejaVu Sans1"'
  60. . ' svg:font-family="\'DejaVu Sans\'" style:font-pitch="variable"/>'
  61. . '<style:font-face style:name="HG Mincho Light J"'
  62. . ' svg:font-family="\'HG Mincho Light J\'" style:font-pitch="variable"/>'
  63. . '<style:font-face style:name="DejaVu Serif"'
  64. . ' svg:font-family="\'DejaVu Serif\'" style:font-family-generic="roman"'
  65. . ' style:font-pitch="variable"/>'
  66. . '<style:font-face style:name="Thorndale"'
  67. . ' svg:font-family="Thorndale" style:font-family-generic="roman"'
  68. . ' style:font-pitch="variable"/>'
  69. . '<style:font-face style:name="DejaVu Sans"'
  70. . ' svg:font-family="\'DejaVu Sans\'" style:font-family-generic="swiss"'
  71. . ' style:font-pitch="variable"/>'
  72. . '</office:font-face-decls>'
  73. . '<office:styles>'
  74. . '<style:default-style style:family="paragraph">'
  75. . '<style:paragraph-properties fo:hyphenation-ladder-count="no-limit"'
  76. . ' style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging"'
  77. . ' style:line-break="strict" style:tab-stop-distance="0.4925in"'
  78. . ' style:writing-mode="page"/>'
  79. . '<style:text-properties style:use-window-font-color="true"'
  80. . ' style:font-name="DejaVu Serif" fo:font-size="12pt" fo:language="en"'
  81. . ' fo:country="US" style:font-name-asian="DejaVu Sans1"'
  82. . ' style:font-size-asian="12pt" style:language-asian="none"'
  83. . ' style:country-asian="none" style:font-name-complex="DejaVu Sans1"'
  84. . ' style:font-size-complex="12pt" style:language-complex="none"'
  85. . ' style:country-complex="none" fo:hyphenate="false"'
  86. . ' fo:hyphenation-remain-char-count="2"'
  87. . ' fo:hyphenation-push-char-count="2"/>'
  88. . '</style:default-style>'
  89. . '<style:style style:name="Standard" style:family="paragraph"'
  90. . ' style:class="text"/>'
  91. . '<style:style style:name="Text_body" style:display-name="Text body"'
  92. . ' style:family="paragraph" style:parent-style-name="Standard"'
  93. . ' style:class="text">'
  94. . '<style:paragraph-properties fo:margin-top="0in"'
  95. . ' fo:margin-bottom="0.0835in"/>'
  96. . '</style:style>'
  97. . '<style:style style:name="Heading" style:family="paragraph"'
  98. . ' style:parent-style-name="Standard" style:next-style-name="Text_body"'
  99. . ' style:class="text">'
  100. . '<style:paragraph-properties fo:margin-top="0.1665in"'
  101. . ' fo:margin-bottom="0.0835in" fo:keep-with-next="always"/>'
  102. . '<style:text-properties style:font-name="DejaVu Sans" fo:font-size="14pt"'
  103. . ' style:font-name-asian="DejaVu Sans1" style:font-size-asian="14pt"'
  104. . ' style:font-name-complex="DejaVu Sans1" style:font-size-complex="14pt"/>'
  105. . '</style:style>'
  106. . '<style:style style:name="Heading_1" style:display-name="Heading 1"'
  107. . ' style:family="paragraph" style:parent-style-name="Heading"'
  108. . ' style:next-style-name="Text_body" style:class="text"'
  109. . ' style:default-outline-level="1">'
  110. . '<style:text-properties style:font-name="Thorndale" fo:font-size="24pt"'
  111. . ' fo:font-weight="bold" style:font-name-asian="HG Mincho Light J"'
  112. . ' style:font-size-asian="24pt" style:font-weight-asian="bold"'
  113. . ' style:font-name-complex="Arial Unicode MS"'
  114. . ' style:font-size-complex="24pt" style:font-weight-complex="bold"/>'
  115. . '</style:style>'
  116. . '<style:style style:name="Heading_2" style:display-name="Heading 2"'
  117. . ' style:family="paragraph" style:parent-style-name="Heading"'
  118. . ' style:next-style-name="Text_body" style:class="text"'
  119. . ' style:default-outline-level="2">'
  120. . '<style:text-properties style:font-name="DejaVu Serif"'
  121. . ' fo:font-size="18pt" fo:font-weight="bold"'
  122. . ' style:font-name-asian="DejaVu Sans1" style:font-size-asian="18pt"'
  123. . ' style:font-weight-asian="bold" style:font-name-complex="DejaVu Sans1"'
  124. . ' style:font-size-complex="18pt" style:font-weight-complex="bold"/>'
  125. . '</style:style>'
  126. . '</office:styles>'
  127. . '<office:automatic-styles>'
  128. . '<style:page-layout style:name="pm1">'
  129. . '<style:page-layout-properties fo:page-width="8.2673in"'
  130. . ' fo:page-height="11.6925in" style:num-format="1"'
  131. . ' style:print-orientation="portrait" fo:margin-top="1in"'
  132. . ' fo:margin-bottom="1in" fo:margin-left="1.25in"'
  133. . ' fo:margin-right="1.25in" style:writing-mode="lr-tb"'
  134. . ' style:footnote-max-height="0in">'
  135. . '<style:footnote-sep style:width="0.0071in"'
  136. . ' style:distance-before-sep="0.0398in"'
  137. . ' style:distance-after-sep="0.0398in" style:adjustment="left"'
  138. . ' style:rel-width="25%" style:color="#000000"/>'
  139. . '</style:page-layout-properties>'
  140. . '<style:header-style/>'
  141. . '<style:footer-style/>'
  142. . '</style:page-layout>'
  143. . '</office:automatic-styles>'
  144. . '<office:master-styles>'
  145. . '<style:master-page style:name="Standard" style:page-layout-name="pm1"/>'
  146. . '</office:master-styles>'
  147. . '</office:document-styles>',
  148. '<?xml version="1.0" encoding="UTF-8"?' . '>'
  149. . '<manifest:manifest'
  150. . ' xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">'
  151. . '<manifest:file-entry manifest:media-type="' . $mime
  152. . '" manifest:full-path="/"/>'
  153. . '<manifest:file-entry manifest:media-type="text/xml"'
  154. . ' manifest:full-path="content.xml"/>'
  155. . '<manifest:file-entry manifest:media-type="text/xml"'
  156. . ' manifest:full-path="meta.xml"/>'
  157. . '<manifest:file-entry manifest:media-type="text/xml"'
  158. . ' manifest:full-path="styles.xml"/>'
  159. . '</manifest:manifest>'
  160. );
  161. $name = array(
  162. 'mimetype',
  163. 'content.xml',
  164. 'meta.xml',
  165. 'styles.xml',
  166. 'META-INF/manifest.xml'
  167. );
  168. $zipExtension = new ZipExtension();
  169. return $zipExtension->createFile($data, $name);
  170. }
  171. }