OpenDocument.php 8.4 KB

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