opendocument.lib.php 8.0 KB

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