/system/thirdparty/Zend/Search/Lucene/Document/OpenXml.php

http://mortar.googlecode.com/ · PHP · 129 lines · 45 code · 13 blank · 71 comment · 7 complexity · 798651763aed336536754894de10a706 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Search_Lucene
  17. * @subpackage Document
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: OpenXml.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. /** Zend_Search_Lucene_Document */
  23. // require_once 'Zend/Search/Lucene/Document.php';
  24. /**
  25. * OpenXML document.
  26. *
  27. * @category Zend
  28. * @package Zend_Search_Lucene
  29. * @subpackage Document
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. abstract class Zend_Search_Lucene_Document_OpenXml extends Zend_Search_Lucene_Document
  34. {
  35. /**
  36. * Xml Schema - Relationships
  37. *
  38. * @var string
  39. */
  40. const SCHEMA_RELATIONSHIP = 'http://schemas.openxmlformats.org/package/2006/relationships';
  41. /**
  42. * Xml Schema - Office document
  43. *
  44. * @var string
  45. */
  46. const SCHEMA_OFFICEDOCUMENT = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument';
  47. /**
  48. * Xml Schema - Core properties
  49. *
  50. * @var string
  51. */
  52. const SCHEMA_COREPROPERTIES = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties';
  53. /**
  54. * Xml Schema - Dublin Core
  55. *
  56. * @var string
  57. */
  58. const SCHEMA_DUBLINCORE = 'http://purl.org/dc/elements/1.1/';
  59. /**
  60. * Xml Schema - Dublin Core Terms
  61. *
  62. * @var string
  63. */
  64. const SCHEMA_DUBLINCORETERMS = 'http://purl.org/dc/terms/';
  65. /**
  66. * Extract metadata from document
  67. *
  68. * @param ZipArchive $package ZipArchive OpenXML package
  69. * @return array Key-value pairs containing document meta data
  70. */
  71. protected function extractMetaData(ZipArchive $package)
  72. {
  73. // Data holders
  74. $coreProperties = array();
  75. // Read relations and search for core properties
  76. $relations = simplexml_load_string($package->getFromName("_rels/.rels"));
  77. foreach ($relations->Relationship as $rel) {
  78. if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_COREPROPERTIES) {
  79. // Found core properties! Read in contents...
  80. $contents = simplexml_load_string(
  81. $package->getFromName(dirname($rel["Target"]) . "/" . basename($rel["Target"]))
  82. );
  83. foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_DUBLINCORE) as $child) {
  84. $coreProperties[$child->getName()] = (string)$child;
  85. }
  86. foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_COREPROPERTIES) as $child) {
  87. $coreProperties[$child->getName()] = (string)$child;
  88. }
  89. foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_DUBLINCORETERMS) as $child) {
  90. $coreProperties[$child->getName()] = (string)$child;
  91. }
  92. }
  93. }
  94. return $coreProperties;
  95. }
  96. /**
  97. * Determine absolute zip path
  98. *
  99. * @param string $path
  100. * @return string
  101. */
  102. protected function absoluteZipPath($path) {
  103. $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
  104. $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
  105. $absolutes = array();
  106. foreach ($parts as $part) {
  107. if ('.' == $part) continue;
  108. if ('..' == $part) {
  109. array_pop($absolutes);
  110. } else {
  111. $absolutes[] = $part;
  112. }
  113. }
  114. return implode('/', $absolutes);
  115. }
  116. }