Browse Source

Initial upload to Launchpad.

tags/v1.2.0
Sebastian Meyer 11 years ago
commit
65ccaf31ce
  1. 119
      dlf/cli/class.tx_dlf_cli.php
  2. 1824
      dlf/common/class.tx_dlf_document.php
  3. 62
      dlf/common/class.tx_dlf_format.php
  4. 846
      dlf/common/class.tx_dlf_helper.php
  5. 540
      dlf/common/class.tx_dlf_indexing.php
  6. 416
      dlf/common/class.tx_dlf_list.php
  7. 231
      dlf/common/class.tx_dlf_mods.php
  8. 229
      dlf/common/class.tx_dlf_module.php
  9. 304
      dlf/common/class.tx_dlf_plugin.php
  10. 171
      dlf/common/class.tx_dlf_solr.php
  11. BIN
      dlf/doc/METS_Anwendungsprofil_2.0.pdf
  12. 4720
      dlf/doc/METS_Anwendungsprofil_2.0.xml
  13. BIN
      dlf/doc/METS_Application_Profile_2.0.pdf
  14. 4652
      dlf/doc/METS_Application_Profile_2.0.xml
  15. BIN
      dlf/doc/MODS_Anwendungsprofil_1.0.pdf
  16. BIN
      dlf/doc/MODS_Application_Profile_1.0.pdf
  17. 30
      dlf/ext_autoload.php
  18. 23
      dlf/ext_conf_template.txt
  19. 68
      dlf/ext_emconf.php
  20. BIN
      dlf/ext_icon.gif
  21. 54
      dlf/ext_localconf.php
  22. 309
      dlf/ext_tables.php
  23. 223
      dlf/ext_tables.sql
  24. 40
      dlf/ext_tables_static+adt.sql
  25. 134
      dlf/hooks/class.tx_dlf_em.php
  26. 111
      dlf/hooks/class.tx_dlf_hacks.php
  27. 157
      dlf/hooks/class.tx_dlf_tceforms.php
  28. 274
      dlf/hooks/class.tx_dlf_tcemain.php
  29. 367
      dlf/lib/SolrPhpClient/Apache/Solr/Document.php
  30. 50
      dlf/lib/SolrPhpClient/Apache/Solr/Exception.php
  31. 89
      dlf/lib/SolrPhpClient/Apache/Solr/HttpTransport/Abstract.php
  32. 198
      dlf/lib/SolrPhpClient/Apache/Solr/HttpTransport/Curl.php
  33. 196
      dlf/lib/SolrPhpClient/Apache/Solr/HttpTransport/CurlNoReuse.php
  34. 216
      dlf/lib/SolrPhpClient/Apache/Solr/HttpTransport/FileGetContents.php
  35. 94
      dlf/lib/SolrPhpClient/Apache/Solr/HttpTransport/Interface.php
  36. 255
      dlf/lib/SolrPhpClient/Apache/Solr/HttpTransport/Response.php
  37. 79
      dlf/lib/SolrPhpClient/Apache/Solr/HttpTransportException.php
  38. 50
      dlf/lib/SolrPhpClient/Apache/Solr/InvalidArgumentException.php
  39. 50
      dlf/lib/SolrPhpClient/Apache/Solr/NoServiceAvailableException.php
  40. 50
      dlf/lib/SolrPhpClient/Apache/Solr/ParserException.php
  41. 247
      dlf/lib/SolrPhpClient/Apache/Solr/Response.php
  42. 1181
      dlf/lib/SolrPhpClient/Apache/Solr/Service.php
  43. 914
      dlf/lib/SolrPhpClient/Apache/Solr/Service/Balancer.php
  44. 26
      dlf/lib/SolrPhpClient/LICENSE.txt
  45. 1
      dlf/lib/SolrPhpClient/NOTICE.txt
  46. 231
      dlf/locallang_db.xml
  47. 49
      dlf/modules/conf.php
  48. 35
      dlf/modules/indexing/conf.php
  49. 422
      dlf/modules/indexing/index.php
  50. 49
      dlf/modules/indexing/locallang.xml
  51. 23
      dlf/modules/indexing/locallang_mod.xml
  52. 32
      dlf/modules/indexing/template.tmpl
  53. 19
      dlf/modules/locallang_mod.xml
  54. 301
      dlf/plugins/collection/class.tx_dlf_collection.php
  55. 88
      dlf/plugins/collection/flexform.xml
  56. 25
      dlf/plugins/collection/locallang.xml
  57. 9
      dlf/plugins/collection/template.tmpl
  58. 311
      dlf/plugins/listview/class.tx_dlf_listview.php
  59. 72
      dlf/plugins/listview/flexform.xml
  60. 35
      dlf/plugins/listview/locallang.xml
  61. 30
      dlf/plugins/listview/template.tmpl
  62. 267
      dlf/plugins/metadata/class.tx_dlf_metadata.php
  63. 108
      dlf/plugins/metadata/flexform.xml
  64. 31
      dlf/plugins/metadata/locallang.xml
  65. 7
      dlf/plugins/metadata/template.tmpl
  66. 246
      dlf/plugins/navigation/class.tx_dlf_navigation.php
  67. 44
      dlf/plugins/navigation/flexform.xml
  68. 33
      dlf/plugins/navigation/locallang.xml
  69. 18
      dlf/plugins/navigation/template.tmpl
  70. 1388
      dlf/plugins/oai/class.tx_dlf_oai.php
  71. 110
      dlf/plugins/oai/flexform.xml
  72. 43
      dlf/plugins/oai/locallang.xml
  73. 101
      dlf/plugins/oai/template.tmpl
  74. 648
      dlf/plugins/oai/transform.xsl
  75. 251
      dlf/plugins/pageview/class.tx_dlf_pageview.php
  76. 1138
      dlf/plugins/pageview/dlfOL.js
  77. 829
      dlf/plugins/pageview/ext_viewer.js
  78. 42
      dlf/plugins/pageview/flexform.xml
  79. 17
      dlf/plugins/pageview/locallang.xml
  80. 111
      dlf/plugins/pageview/viewer.js
  81. 141
      dlf/plugins/search/class.tx_dlf_search.php
  82. 73
      dlf/plugins/search/flexform.xml
  83. 29
      dlf/plugins/search/locallang.xml
  84. 7
      dlf/plugins/search/template.tmpl
  85. 288
      dlf/plugins/toc/class.tx_dlf_toc.php
  86. 71
      dlf/plugins/toc/flexform.xml
  87. 21
      dlf/plugins/toc/locallang.xml
  88. 27
      dlf/plugins/toc/setup.txt
  89. 11
      dlf/plugins/toc/template.tmpl
  90. 4
      dlf/repository/.htaccess
  91. 1
      dlf/repository/ApacheSolr/NOTICE.txt
  92. BIN
      dlf/repository/ApacheSolr/apache-solr-1.4.1-dlf.war
  93. 6
      dlf/repository/ApacheSolr/conf/context.xml
  94. 34
      dlf/repository/ApacheSolr/conf/elevate.xml
  95. 15
      dlf/repository/ApacheSolr/conf/protwords.txt
  96. 176
      dlf/repository/ApacheSolr/conf/schema.xml
  97. 502
      dlf/repository/ApacheSolr/conf/solrconfig.xml
  98. 52
      dlf/repository/ApacheSolr/conf/stopwords.txt
  99. 18
      dlf/repository/ApacheSolr/conf/synonyms.txt
  100. 6
      dlf/repository/ApacheSolr/solr.xml

119
dlf/cli/class.tx_dlf_cli.php

@ -0,0 +1,119 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
if (!defined('TYPO3_cliMode')) {
die('You cannot run this script directly!');
}
/**
* CLI script for the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @copyright Copyright (c) 2010, Sebastian Meyer, SLUB Dresden
* @version $Id: class.tx_dlf_cli.php 481 2010-12-22 18:22:54Z smeyer $
* @package TYPO3
* @subpackage tx_dlf
* @access public
*/
class tx_dlf_cli extends t3lib_cli {
public $cli_help = array (
'name' => 'Command Line Interface for the Digital Library Framework',
'synopsis' => '###OPTIONS###',
'description' => '',
'examples' => '/PATH/TO/TYPO3/cli_dispatch.phpsh dlf TASK -ARG1=VALUE1 -ARG2=VALUE2',
'options' => '',
'license' => 'GNU GPL - free software!',
'author' => 'Sebastian Meyer <sebastian.meyer@slub-dresden.de>',
);
/**
* Main function of the script.
*
* @access public
*
* @return void
*/
public function main() {
switch ((string) $this->cli_args['_DEFAULT'][1]) {
case 'index':
// Add command line arguments.
$this->cli_options[] = array ('-doc UID/URL', 'UID or URL of the document.');
$this->cli_options[] = array ('-pid UID', 'UID of the page the document should be added to.');
$this->cli_options[] = array ('-core UID', 'UID of the Solr core the document should be added to.');
// Check the command line arguments.
$this->cli_validateArgs();
// Get the document...
$doc = tx_dlf_document::getInstance($this->cli_args['-doc'][0], 0, TRUE);
// ...save it to the database...
if (!$doc->save(intval($this->cli_args['-pid'][0]), $this->cli_args['-core'][0])) {
$this->cli_echo('ERROR: Document '.$this->cli_args['-doc'][0].' not saved and indexed'.LF);
return 1;
}
break;
default:
$this->cli_help();
break;
}
return 0;
}
public function __construct() {
// Run parent constructor.
parent::t3lib_cli();
}
}
$SOBE = t3lib_div::makeInstance('tx_dlf_cli');
$SOBE->main();
?>

1824
dlf/common/class.tx_dlf_document.php

File diff suppressed because it is too large

62
dlf/common/class.tx_dlf_format.php

@ -0,0 +1,62 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
/**
* Base class 'tx_dlf_format' for the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @copyright Copyright (c) 2010, Sebastian Meyer, SLUB Dresden
* @version $Id: class.tx_dlf_document.php 104 2010-06-12 21:12:03Z smeyer $
* @package TYPO3
* @subpackage tx_dlf
* @access public
* @abstract
*/
interface tx_dlf_format {
/**
* This extracts metadata from XML
*
* @access public
*
* @param SimpleXMLElement $xml: The XML to extract the metadata from
* @param array &$metadata: The metadata array to fill
*
* @return void
*/
public function extractMetadata(SimpleXMLElement $xml, array &$metadata);
}
/* No xclasses for interfaces!
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_format.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_format.php']);
}
*/
?>

846
dlf/common/class.tx_dlf_helper.php

@ -0,0 +1,846 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
/**
* Helper class 'tx_dlf_helper' for the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @copyright Copyright (c) 2010, Sebastian Meyer, SLUB Dresden
* @version $Id: class.tx_dlf_helper.php 499 2010-12-23 12:40:24Z smeyer $
* @package TYPO3
* @subpackage tx_dlf
* @access public
*/
class tx_dlf_helper {
/**
* The extension key
*
* @var string
* @access public
*/
public static $extKey = 'dlf';
/**
* Searches the array recursively for a given value and returns the corresponding key if successful
* @see http://php.net/array_search
*
* @access public
*
* @param mixed $needle: The searched value
* @param array $haystack: The array to search in
* @param boolean $strict: Check needle's type, too?
*
* @return mixed Returns the needle's key if found and FALSE otherwise
*/
public static function array_search_recursive($needle, $haystack, $strict = FALSE) {
foreach ($haystack as $key => $value) {
$current = $key;
if (($strict && $value === $needle) || (!$strict && $value == $needle) || (is_array($value) && self::array_search_recursive($needle, $value, $strict) !== FALSE)) {
return $current;
}
}
return FALSE;
}
/**
* Check if given identifier is a valid identifier of the German National Library
* @see http://support.d-nb.de/iltis/onlineRoutinen/Pruefziffernberechnung.htm
*
* @access public
*
* @param string $id: The identifier to check
* @param string $type: What type is the identifier supposed to be?
* Possible values: PPN, IDN, PND, ZDB, SWD, GKD
*
* @return boolean Is $id a valid GNL identifier of the given $type?
*/
public static function checkIdentifier($id, $type) {
$digits = substr($id, 0, 8);
$checksum = 0;
for ($i = 0; $i < strlen($digits); $i++) {
$checksum += (9 - $i) * intval(substr($digits, $i, 1));
}
$checksum = (11 - ($checksum % 11)) % 11;
switch (strtoupper($type)) {
case 'PPN':
case 'IDN':
case 'PND':
if ($checksum == 10) {
$checksum = 'X';
}
if (!preg_match('/[0-9]{8}[0-9X]{1}/i', $id)) {
return FALSE;
} elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
return FALSE;
}
break;
case 'ZDB':
if ($checksum == 10) {
$checksum = 'X';
}
if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) {
return FALSE;
} elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
return FALSE;
}
break;
case 'SWD':
$checksum = 11 - $checksum;
if (!preg_match('/[0-9]{8}-[0-9]{1}/i', $id)) {
return FALSE;
} elseif ($checksum == 10) {
return self::checkIdentifier(($digits + 1).substr($id, -2, 2), 'SWD');
} elseif (substr($id, -1, 1) != $checksum) {
return FALSE;
}
break;
case 'GKD':
$checksum = 11 - $checksum;
if ($checksum == 10) {
$checksum = 'X';
}
if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) {
return FALSE;
} elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
return FALSE;
}
break;
}
return TRUE;
}
/**
* Get a backend user object (even in frontend mode)
*
* @access public
*
* @return t3lib_beUserAuth Instance of t3lib_beUserAuth or NULL on failure
*/
public static function getBeUser() {
if (TYPO3_MODE === 'FE') {
// TODO: Anpassen! (aus typo3/init.php übernommen)
$userObj = t3lib_div::makeInstance('t3lib_beUserAuth');
$userObj->start();
$userObj->backendCheckLogin();
return $userObj;
} elseif (TYPO3_MODE === 'BE') {
return $GLOBALS['BE_USER'];
} else {
trigger_error('Unexpected TYPO3_MODE', E_USER_WARNING);
return;
}
}
/**
* Get the "index_name" for an UID
*
* @access public
*
* @param integer $uid: The UID of the record
* @param string $table: Get the "index_name" from this table
* @param string $pid: Get the "index_name" from this page
*
* @return string "index_name" for the given UID
*/
public static function getIndexName($uid, $table, $pid) {
$uid = max(intval($uid), 0);
$pid = max(intval($pid), 0);
if (!$uid || !$pid || !in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures'))) {
trigger_error('At least one argument is not valid', E_USER_WARNING);
return '';
}
$_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
$table.'.index_name AS index_name',
$table,
$table.'.uid='.$uid.' AND '.$table.'.pid='.$pid.self::whereClause($table),
'',
'',
'1'
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($_result) > 0) {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result);
return $resArray['index_name'];
}
trigger_error('No "index_name" with UID '.$uid.' found for PID '.$pid.' in table '.$table, E_USER_WARNING);
return '';
}
/**
* Get language name from 'static_info_tables'
* TODO: 3-stellige Sprachcodes
*
* @access public
*
* @param string $code: ISO 3166-2 language code
*
* @return string Localized full name of language or unchanged input
*/
public static function getLanguageName($code) {
$code = strtoupper(trim($code));
if (!preg_match('/^[A-Z]{2}$/', $code) || !t3lib_extMgm::isLoaded('static_info_tables')) {
trigger_error('Invalid language code or extension "static_info_tables" not loaded', E_USER_WARNING);
return $code;
}
if (!$GLOBALS['TSFE']->lang || !t3lib_extMgm::isLoaded('static_info_tables_'.$GLOBALS['TSFE']->lang)) {
$field = 'lg_name_en';
} else {
$field = 'lg_name_'.$GLOBALS['TSFE']->lang;
}
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'static_languages.'.$field.' AS '.$field,
'static_languages',
'static_languages.lg_iso_2='.$GLOBALS['TYPO3_DB']->fullQuoteStr($code, 'static_languages'),
'',
'',
'1'
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
return $resArray[$field];
} else {
trigger_error('Language code not found in extension "static_info_tables"', E_USER_WARNING);
return $code;
}
}
/**
* Get the URN of an object
* @see http://www.persistent-identifier.de/?link=316
*
* @access public
*
* @param string $base: The namespace and base URN
* @param string $id: The object's identifier
*
* @return string Uniform Resource Name as string
*/
public static function getURN($base, $id) {
$concordance = array(
'0' => 1,
'1' => 2,
'2' => 3,
'3' => 4,
'4' => 5,
'5' => 6,
'6' => 7,
'7' => 8,
'8' => 9,
'9' => 41,
'a' => 18,
'b' => 14,
'c' => 19,
'd' => 15,
'e' => 16,
'f' => 21,
'g' => 22,
'h' => 23,
'i' => 24,
'j' => 25,
'k' => 42,
'l' => 26,
'm' => 27,
'n' => 13,
'o' => 28,
'p' => 29,
'q' => 31,
'r' => 12,
's' => 32,
't' => 33,
'u' => 11,
'v' => 34,
'w' => 35,
'x' => 36,
'y' => 37,
'z' => 38,
'-' => 39,
':' => 17,
);
$urn = strtolower($base.$id);
if (preg_match('/[^a-z0-9:-]/', $urn)) {
trigger_error('Invalid chars in URN', E_USER_WARNING);
return '';
}
$digits = '';
for ($i = 0; $i < strlen($urn); $i++) {
$digits .= $concordance[substr($urn, $i, 1)];
}
$checksum = 0;
for ($i = 0; $i < strlen($digits); $i++) {
$checksum += ($i + 1) * intval(substr($digits, $i, 1));
}
$checksum = substr(intval($checksum / intval(substr($digits, -1, 1))), -1, 1);
return $base.$id.$checksum;
}
/**
* Check if given ID is a valid Pica Production Number (PPN)
*
* @access public
*
* @param string $ppn: The identifier to check
*
* @return boolean Is $id a valid PPN?
*/
public static function isPPN($id) {
return self::checkIdentifier($id, 'PPN');
}
/**
* Check if given internal "index_name" is translatable
*
* @access public
*
* @param string $index_name: The internal "index_name" to translate
* @param string $table: Get the translation from this table
* @param string $pid: Get the translation from this page
*
* @return boolean Is $index_name translatable?
*/
public static function isTranslatable($index_name, $table, $pid = 0) {
return self::translate($index_name, $table, $pid, TRUE);
}
/**
* Load value from user's session.
*
* @access public
*
* @param string $key: Session key for retrieval
*
* @return mixed Session value for given key or NULL on failure
*/
public static function loadFromSession($key) {
// Cast to string for security reasons.
$key = (string) $key;
if (!$key) {
trigger_error('No session key given', E_USER_WARNING);
return;
}
if (TYPO3_MODE === 'FE') {
return $GLOBALS['TSFE']->fe_user->getKey('ses', $key);
} elseif (TYPO3_MODE === 'BE') {
return $GLOBALS['BE_USER']->getSessionData($key);
} else {
trigger_error('Unexpected TYPO3_MODE', E_USER_WARNING);
return;
}
}
/**
* Process a data and/or command map with TYPO3 core engine.
*
* @access public
*
* @return array Array of substituted "NEW..." identifiers and their actual UIDs.
*/
public static function processDB(array $data = array (), array $cmd = array (), $reverseOrder = FALSE) {
// Instantiate TYPO3 core engine.
$tce = t3lib_div::makeInstance('t3lib_TCEmain');
// Set some configuration variables.
$tce->stripslashes_values = FALSE;
// Load data and command arrays.
$tce->start($data, $cmd, self::getBeUser());
// Process command map first if default order is reversed.
if ($cmd && $reverseOrder) {
$tce->process_cmdmap();
}
// Process data map.
if ($data) {
$tce->process_datamap();
}
// Process command map if processing order is not reversed.
if ($cmd && !$reverseOrder) {
$tce->process_cmdmap();
}
return $tce->substNEWwithIDs;
}
/**
* Save given value to user's session.
*
* @access public
*
* @param string $value: Value to save
* @param string $key: Session key for retrieval
*
* @return boolean TRUE on success, FALSE on failure
*/
public static function saveToSession($value, $key) {
// Cast to string for security reasons.
$key = (string) $key;
if (!$key) {
trigger_error('No session key given', E_USER_WARNING);
return FALSE;
}
if (TYPO3_MODE === 'FE') {
$GLOBALS['TSFE']->fe_user->setKey('ses', $key, $value);
$GLOBALS['TSFE']->fe_user->storeSessionData();
return TRUE;
} elseif (TYPO3_MODE === 'BE') {
$GLOBALS['BE_USER']->setAndSaveSessionData($key, $value);
return TRUE;
} else {
trigger_error('Unexpected TYPO3_MODE', E_USER_WARNING);
return FALSE;
}
}
/**
* This validates a METS file against its schemas
* TODO: nicht funktionstüchtig!
*
* @access public
*
* @param SimpleXMLElement $xml:
*
* @return void
*/
public static function schemaValidate(SimpleXMLElement $xml) {
$_libxmlErrors = libxml_use_internal_errors(TRUE);
// Get schema locations.
$xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$_schemaLocations = $xml->xpath('//*[@xsi:schemaLocation]');
foreach ($_schemaLocations as $_schemaLocation) {
$_schemas = explode(' ', (string) $_schemaLocation->attributes('http://www.w3.org/2001/XMLSchema-instance')->schemaLocation);
for ($i = 1; $i <= count($_schemas); $i++) {
if ($_schemas[$i] == 'http://www.loc.gov/METS/') {
$schema['mets'] = $_schemas[$i + 1];
} elseif ($_schemas[$i] == 'http://www.loc.gov/mods/v3') {
$schema['mods'] = $_schemas[$i + 1];
}
}
}
// TODO: Error-Handling (keine Schemas gefunden)
// Validate METS part against schema.
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->appendChild($dom->importNode(dom_import_simplexml($this->mets), TRUE));
$dom->schemaValidate($schema['mets']);
// TODO: Error-Handling (invalider METS-Part)
// libxml_get_last_error() || libxml_get_errors() || libxml_clear_errors()
// Validate dmdSec parts against schema.
foreach ($this->dmdSec as $dmdSec) {
switch ($dmdSec['type']) {
case 'MODS':
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->appendChild($dom->importNode(dom_import_simplexml($dmdSec['xml']), TRUE));
$dom->schemaValidate($schema['mods']);
// TODO: Error-Handling (invalider MODS-Part)
// libxml_get_last_error() || libxml_get_errors() || libxml_clear_errors()
break;
}
}
libxml_use_internal_errors($_libxmlErrors);
}
/**
* This translates an internal "index_name"
*
* @access public
*
* @param string $index_name: The internal "index_name" to translate
* @param string $table: Get the translation from this table
* @param string $pid: Get the translation from this page
* @param boolean $checkOnly: Don't translate, only check for translation
*
* @return mixed Translated label or boolean value if $checkOnly is set
*/
public static function translate($index_name, $table, $pid, $checkOnly = FALSE) {
static $labels = array ();
$pid = max(intval($pid), 0);
if (!$pid) {
trigger_error('No PID given for translations', E_USER_WARNING);
return $index_name;
}
// Check if "index_name" is an UID.
if (t3lib_div::testInt($index_name)) {
$index_name = self::getIndexName($index_name, $table, $pid);
}
// Check if we already got a translation.
if (empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) {
// Check if this table is allowed for translation.
if (in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures'))) {
$additionalWhere = ' AND sys_language_uid IN (-1,0)';
if ($GLOBALS['TSFE']->sys_language_content > 0) {
$additionalWhere = ' AND (sys_language_uid IN (-1,0) OR (sys_language_uid='.intval($GLOBALS['TSFE']->sys_language_content).' AND l18n_parent=0))';
}
// Get labels from database.
$_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
$table,
'pid='.$pid.$additionalWhere.self::whereClause($table),
'',
'',
''
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($_result) > 0) {
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result)) {
// Overlay localized labels if available.
if ($GLOBALS['TSFE']->sys_language_content > 0) {
$resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $resArray, $GLOBALS['TSFE']->sys_language_content, ($GLOBALS['TSFE']->sys_language_mode == 'strict' ? 'hideNonTranslated' : ''));
}
if ($resArray) {
$labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$resArray['index_name']] = $resArray['label'];
}
}
} else {
trigger_error('There are no entries with PID '.$pid.' in table '.$table.' or you are not allowed to access them', E_USER_ERROR);
exit;
}
} else {
trigger_error('The table '.$table.' is not allowed for translation', E_USER_ERROR);
exit;
}
}
if (!empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) {
if ($checkOnly) {
return TRUE;
} else {
return $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name];
}
} else {
if ($checkOnly) {
return FALSE;
} else {
return $index_name;
}
}
}
/**
* This returns the additional WHERE clause of a table based on its TCA configuration
*
* @access public
*
* @param string $table: Table name as defined in TCA
*
* @return string Additional WHERE clause
*/
public static function whereClause($table) {
if (TYPO3_MODE === 'FE') {
// Tables "tx_dlf_solrcores" and "tx_dlf_formats" always have PID 0.
if (in_array($table, array ('tx_dlf_solrcores', 'tx_dlf_formats'))) {
return t3lib_BEfunc::deleteClause($table);
}
// $GLOBALS['TSFE']->sys_page is not always available in frontend.
if (is_object($GLOBALS['TSFE']->sys_page)) {
return $GLOBALS['TSFE']->sys_page->enableFields($table);
} else {
$t3lib_pageSelect = t3lib_div::makeInstance('t3lib_pageSelect');
$GLOBALS['TSFE']->includeTCA();
return $t3lib_pageSelect->enableFields($table);
}
} elseif (TYPO3_MODE === 'BE') {
return t3lib_BEfunc::deleteClause($table);
} else {
trigger_error('Unexpected TYPO3_MODE', E_USER_ERROR);
exit;
}
}
/**
* This is a static class, thus no instances should be created
*
* @access protected
*/
protected function __construct() {}
}
/* No xclasses for static classes!
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_helper.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_helper.php']);
}
*/
?>

540
dlf/common/class.tx_dlf_indexing.php

@ -0,0 +1,540 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
/**
* Indexing class 'tx_dlf_indexing' for the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @copyright Copyright (c) 2010, Sebastian Meyer, SLUB Dresden
* @version $Id: class.tx_dlf_indexing.php 487 2010-12-22 19:55:15Z smeyer $
* @package TYPO3
* @subpackage tx_dlf
* @access public
*/
class tx_dlf_indexing {
/**
* The extension key
*
* @var string
* @access public
*/
public static $extKey = 'dlf';
/**
* Array of facets
* @see loadIndexConf()
*
* @var array
* @access protected
*/
protected static $facets = array ();
/**
* Array of fields' boost values
* @see loadIndexConf()
*
* @var array
* @access protected
*/
protected static $fieldboost = array ();
/**
* Array of indexed metadata
* @see loadIndexConf()
*
* @var array
* @access protected
*/
protected static $indexed = array ();
/**
* List of already processed documents
*
* @var array
* @access protected
*/
protected static $processedDocs = array ();
/**
* Instance of Apache_Solr_Service class
*
* @var Apache_Solr_Service
* @access protected
*/
protected static $solr;
/**
* Array of sortable metadata
* @see loadIndexConf()
*
* @var array
* @access protected
*/
protected static $sortables = array ();
/**
* Array of stored metadata
* @see loadIndexConf()
*
* @var array
* @access protected
*/
protected static $stored = array ();
/**
* Array of tokenized metadata
* @see loadIndexConf()
*
* @var array
* @access protected
*/
protected static $tokenized = array ();
/**
* Array of toplevel structure elements
* @see loadIndexConf()
*
* @var array
* @access protected
*/
protected static $toplevel = array ();
/**
* Insert given document into Solr index
*
* @access public
*
* @param tx_dlf_document &$doc: The document to index
* @param integer $core: UID of the Solr core to use
*
* @return void
*/
public static function addToIndex(tx_dlf_document &$doc, $core = 1) {
if (in_array($doc->uid, self::$processedDocs)) {
return 0;
} elseif (self::solrConnect($core, $doc->pid)) {
$errors = 0;
// Handle multi-volume documents.
if ($doc->parentid) {
$errors = self::addToIndex(tx_dlf_document::getInstance($doc->parentid, 0, TRUE), $core);
}
try {
// Add document to list of processed documents.
self::$processedDocs[] = $doc->uid;
// Index every logical unit as separate Solr document.
foreach ($doc->tableOfContents as $logicalUnit) {
if (!$errors) {
$errors = self::process($doc, $logicalUnit);
} else {
break;
}
}
self::$solr->commit();
// Get document title from database.
$_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.title AS title',
'tx_dlf_documents',
'tx_dlf_documents.uid='.intval($doc->uid).tx_dlf_helper::whereClause('tx_dlf_documents'),
'',
'',
'1'
);
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result);
if (!defined('TYPO3_cliMode')) {
$_message = t3lib_div::makeInstance(
't3lib_FlashMessage',
htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('flash.documentIndexed'), $resArray['title'], $doc->uid)),
$GLOBALS['LANG']->getLL('flash.done', TRUE),
t3lib_FlashMessage::OK,
TRUE
);
t3lib_FlashMessageQueue::addMessage($_message);
}
return $errors;
} catch (Exception $e) {
if (!defined('TYPO3_cliMode')) {
$_message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('flash.solrException', TRUE).'<br />'.htmlspecialchars($e->getMessage()),
$GLOBALS['LANG']->getLL('flash.error', TRUE),
t3lib_FlashMessage::ERROR,
TRUE
);
t3lib_FlashMessageQueue::addMessage($_message);
}
trigger_error('Apache Solr exception thrown: '.$e->getMessage(), E_USER_ERROR);
return 1;
}
} else {
if (!defined('TYPO3_cliMode')) {
$_message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('flash.solrNoConnection', TRUE),
$GLOBALS['LANG']->getLL('flash.error', TRUE),
t3lib_FlashMessage::ERROR,
TRUE
);
t3lib_FlashMessageQueue::addMessage($_message);
}
trigger_error('Could not connect to Apache Solr server', E_USER_ERROR);
return 1;
}
}
/**
* Load indexing configuration
*
* @access protected
*
* @param integer $pid: The configuration page's UID
*
* @return void
*/
protected static function loadIndexConf($pid) {
// Get the list of toplevel structures.
$_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_structures.index_name AS index_name',
'tx_dlf_structures',
'tx_dlf_structures.toplevel=1 AND tx_dlf_structures.pid='.intval($pid).tx_dlf_helper::whereClause('tx_dlf_structures'),
'',
'',
''
);
while ($_toplevel = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result)) {
self::$toplevel[] = $_toplevel['index_name'];
}
// Get the metadata indexing options.
$_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.tokenized AS tokenized,tx_dlf_metadata.stored AS stored,tx_dlf_metadata.indexed AS indexed,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.boost AS boost',
'tx_dlf_metadata',
'tx_dlf_metadata.pid='.intval($pid).tx_dlf_helper::whereClause('tx_dlf_metadata'),
'',
'',
''
);
while ($_indexing = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result)) {
if ($_indexing['tokenized']) {
self::$tokenized[] = $_indexing['index_name'];
}
if ($_indexing['stored'] || $_indexing['is_listed']) {
self::$stored[] = $_indexing['index_name'];
}
if ($_indexing['indexed']) {
self::$indexed[] = $_indexing['index_name'];
}
if ($_indexing['boost'] > 0.0) {
self::$fieldboost[$_indexing['index_name']] = $_indexing['boost'];
} else {
self::$fieldboost[$_indexing['index_name']] = FALSE;
}
}
}
/**
* Processes a logical unit (and its children) for the Solr index
*
* @access protected
*
* @param tx_dlf_document &$doc: The METS document
* @param array $logicalUnit: Array of the logical unit to process
*
* @return void
*/
protected static function process(tx_dlf_document &$doc, array $logicalUnit) {
$errors = 0;
// Get metadata for logical unit.
$metadata = $doc->metadataArray[$logicalUnit['id']];
if (!empty($metadata)) {
// Load class.
if (!class_exists('Apache_Solr_Document')) {
require_once(t3lib_div::getFileAbsFileName('EXT:'.self::$extKey.'/lib/SolrPhpClient/Apache/Solr/Document.php'));
}
// Create new Solr document.
$solrDoc = new Apache_Solr_Document();
// Create unique identifier from document's UID and unit's XML ID.
$solrDoc->setField('id', $doc->uid.$logicalUnit['id']);
$solrDoc->setField('uid', $doc->uid);
$solrDoc->setField('pid', $doc->pid);
$solrDoc->setField('page', $logicalUnit['points'][0]);
$solrDoc->setField('partof', $doc->parentid);
$solrDoc->setField('sid', $logicalUnit['id']);
$solrDoc->setField('toplevel', in_array($logicalUnit['type'], self::$toplevel));
$solrDoc->setField('type', $logicalUnit['type'], self::$fieldboost['type']);
unset ($metadata['type']);
$solrDoc->setField('title', $metadata['title'][0], self::$fieldboost['title']);
unset ($metadata['title']);
$solrDoc->setField('title_sorting', $metadata['title_sorting'][0]);
unset ($metadata['title_sorting']);
$solrDoc->setField('author', $metadata['author'], self::$fieldboost['author']);
$solrDoc->setField('author_faceting', $metadata['author']);
unset ($metadata['author']);
if (!empty($metadata['author_sorting'][0])) {
$solrDoc->setField('author_sorting', $metadata['author_sorting'][0]);
}
unset ($metadata['author_sorting']);
$solrDoc->setField('year', $metadata['year'], self::$fieldboost['year']);
$solrDoc->setField('year_faceting', $metadata['year']);
unset ($metadata['year']);
if (!empty($metadata['year_sorting'][0])) {
$solrDoc->setField('year_sorting', $metadata['year_sorting'][0]);
}
unset ($metadata['year_sorting']);
$solrDoc->setField('place', $metadata['place'], self::$fieldboost['place']);
$solrDoc->setField('place_faceting', $metadata['place']);
unset ($metadata['place']);
if (!empty($metadata['place_sorting'][0])) {
$solrDoc->setField('place_sorting', $metadata['place_sorting'][0]);
}
unset ($metadata['place_sorting']);
foreach ($metadata as $index_name => $data) {
if (!empty($data)) {
$suffix = (in_array($index_name, self::$tokenized) ? 't' : 'u');
$suffix .= (in_array($index_name, self::$stored) ? 's' : 'u');
$suffix .= (in_array($index_name, self::$indexed) ? 'i' : 'u');
$solrDoc->setField($index_name.'_'.$suffix, $data, self::$fieldboost[$index_name]);
// Add sortable fields to index.
$solrDoc->setField($index_name.'_sorting', $data[0]);
// Add facets to index.
$solrDoc->setField($index_name.'_faceting', $data);
}
}
try {
self::$solr->addDocument($solrDoc);
} catch (Exception $e) {
if (!defined('TYPO3_cliMode')) {
$_message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('flash.solrException', TRUE).'<br />'.htmlspecialchars($e->getMessage()),
$GLOBALS['LANG']->getLL('flash.error', TRUE),
t3lib_FlashMessage::ERROR,
TRUE
);
t3lib_FlashMessageQueue::addMessage($_message);
}
return 1;
}
}
// Check for child elements...
if (!empty($logicalUnit['children'])) {
foreach ($logicalUnit['children'] as $child) {
if (!$errors) {
// ...and process them, too.
$errors = self::process($doc, $child);
} else {
break;
}
}
}
return $errors;
}
/**
* Connects to Solr server.
*
* @access protected
*
* @param integer $core: UID of the Solr core
* @param integer $pid: UID of the configuration page
*
* @return boolean TRUE on success or FALSE on failure
*/
protected static function solrConnect($core, $pid) {
if (!self::$solr) {
// Connect to Solr server.
if (self::$solr = tx_dlf_solr::solrConnect($core)) {
// Load indexing configuration.
self::loadIndexConf($pid);
} else {
return FALSE;
}
}
return TRUE;
}
/**
* This is a static class, thus no instances should be created
*
* @access protected
*/
protected function __construct() {}
}
/* No xclasses for static classes!
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_indexing.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_indexing.php']);
}
*/
?>

416
dlf/common/class.tx_dlf_list.php

@ -0,0 +1,416 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
/**
* Document class 'tx_dlf_list' for the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @copyright Copyright (c) 2010, Sebastian Meyer, SLUB Dresden
* @version $Id: class.tx_dlf_list.php 15 2010-01-19 17:07:03Z smeyer $
* @package TYPO3
* @subpackage tx_dlf
* @access public
*/
class tx_dlf_list implements t3lib_Singleton {
/**
* This holds the documents in sorted order
*
* @var array
* @access protected
*/
protected $elements = array ();
/**
* This holds the number of documents in the list
*
* @var integer
* @access protected
*/
protected $count = 0;
/**
* This holds the list's metadata
*
* @var array
* @access protected
*/
protected $metadata = array ();
/**
* This adds an array of elements at the given position to the list
*
* @access public
*
* @param array $elements: Array of elements to add to list
* @param integer $position: Numeric position for including
*
* @return void
*/
public function add(array $elements, $position = -1) {
$position = intval($position);
if ($position < 0 || $position > $this->count) {
$position = $this->count;
}
array_splice($this->elements, $position, 0, $elements);
$this->count = count($this->elements);
}
/**
* This removes the element at the given position from the list
*
* @access public
*
* @param integer $position: Numeric position for removing
*
* @return mixed The removed element
*/
public function remove($position) {
$position = intval($position);
if ($position < 0 || $position >= $this->count) {
trigger_error('No valid list position for removal', E_USER_WARNING);
return;
}
$removed = array_splice($this->elements, $position, 1);
$this->count = count($this->elements);
return $removed[0];
}
/**
* This moves the element at the given position up
*
* @access public
*
* @param integer $position: Numeric position for moving
*
* @return void
*/
public function moveUp($position) {
$position = intval($position);
if ($position < 1 || $position >= $this->count) {
trigger_error('No valid list position for moving up', E_USER_WARNING);
return;
}
array_splice($this->elements, $position - 1, 0, $this->elements[$position]);
array_splice($this->elements, $position + 1, 1);
}
/**
* This moves the element at the given position down
*
* @access public
*
* @param integer $position: Numeric position for moving
*
* @return void
*/
public function moveDown($position) {
$position = intval($position);
if ($position < 0 || $position >= ($this->count - 1)) {
trigger_error('No valid list position for moving down', E_USER_WARNING);
return;
}
array_splice($this->elements, $position + 2, 0, $this->elements[$position]);
array_splice($this->elements, $position, 1);
}
/**
* This empties the current list
*
* @access public
*
* @return void
*/
public function reset() {
$this->elements = array ();
$this->metadata = array ();
$this->count = 0;
}
/**
* This saves the current list
*
* @access public
*
* @param integer $pid: PID for saving in database
*
* @return void
*/
public function save($pid = 0) {
$pid = max(intval($pid), 0);
// If no PID is given, save to the user's session instead
if ($pid > 0) {
// TODO: Liste in Datenbank speichern (inkl. Sichtbarkeit, Beschreibung, etc.)
} else {
tx_dlf_helper::saveToSession(array ($this->elements, $this->metadata), get_class($this));
}
}
/**
* This returns $this->count via __get()
*
* @access protected
*
* @return integer The number of elements in the list
*/
protected function _getCount() {
return $this->count;
}
/**
* This returns $this->elements via __get()
*
* @access protected
*
* @return array The documents in sorted order
*/
protected function _getElements() {
return $this->elements;
}
/**
* This returns $this->metadata via __get()
*
* @access protected
*
* @return array The list's metadata
*/
protected function _getMetadata() {
return $this->metadata;
}
/**
* This sets $this->metadata via __set()
*
* @access protected
*
* @param array $metadata: Array of new metadata
*
* @return void
*/
protected function _setMetadata(array $metadata = array ()) {
$this->metadata = $metadata;
}
/**
* This is the constructor
*
* @access public
*
* @param array $elements: Array of documents initially setting up the list
* @param array $metadata: Array of initial metadata
*
* @return void
*/
public function __construct(array $elements = array (), array $metadata = array ()) {
if (!$elements && !$metadata) {
// Let's check the user's session.
$sessionData = tx_dlf_helper::loadFromSession(get_class($this));
// Restore list from session data.
if (is_array($sessionData)) {
if (is_array($sessionData[0])) {
$this->elements = $sessionData[0];
}
if (is_array($sessionData[1])) {
$this->metadata = $sessionData[1];
}
}
} else {
// Add metadata to the list.
$this->metadata = $metadata;
// Add initial set of elements to the list.
$this->elements = $elements;
}
$this->count = count($this->elements);
}
/**
* This magic method is invoked each time a clone is called on the object variable
* (This method is defined as private/protected because singleton objects should not be cloned)
*
* @access protected
*
* @return void
*/
protected function __clone() {}
/**
* This magic method is called each time an invisible property is referenced from the object
*
* @access public
*
* @param string $var: Name of variable to get
*
</