-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTocForUniversalViewerPlugin.php
More file actions
121 lines (102 loc) · 3.9 KB
/
TocForUniversalViewerPlugin.php
File metadata and controls
121 lines (102 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Table of content for Universal Viewer
*
*
* @copyright Jean-Baptiste Pressac, 2018
* @license https://www.cecill.info/licences/Licence_CeCILL_V2.1-en.html
* */
/**
* A Table of content for the UniversalViewer plugin.
* @package Omeka\Plugins\TocForUniversalViewer
*/
class TocForUniversalViewerPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_filters = array(
'uv_manifest',
);
const ELEMENT_SET_NAME = 'PDF Table of Contents';
const ELEMENT_NAME = 'Text';
protected $_pdfMimeTypes = array(
'application/pdf',
'application/x-pdf',
'application/acrobat',
'text/x-pdf',
'text/pdf',
'applications/vnd.pdf',
);
public function filterUvManifest($manifest, $args)
{
// Fonction executée à la consultation des pages des manifestes, per ex.
// http://localhost/omeka26/iiif/4/manifest
if(array_key_exists('record', $args)){
// Trouvé les paramètres du filtre uv_manifest en cherchant apply_filters dans
// le plugin UniversalViewer et en consultant la documentation
// de apply_filters.
$record = $args['record'];
// The class test is inspired by https://tinyurl.com/yaro5pq6
$recordClass = get_class($record);
if($recordClass == 'Item'){
$item = $record;
$files = $item->getFiles();
// Il est possible de modifier le titre du document dans la visionneuse
// comme suit.
// $manifest['label'] = "Label bleu" ;
// Ce qui suit est inspiré de https://tinyurl.com/ya8osg94
foreach ($files as $file) {
if (in_array($file->mime_type, $this->_pdfMimeTypes)) {
$textElement = $file->getElementTexts(
self::ELEMENT_SET_NAME,
self::ELEMENT_NAME
);
$toc = $textElement[0];
if (!preg_match("/InfoValue/", $toc)) {
/* On est dans le cas où la métadonnée Text du jeux de métadonnées
PDF Table of Contents peut ressembler à :
1|Soun Fantik|3
1|Kola|5
1|Eun eureud|7
1|Ar c'haor|9
1|Izabel|11
*/
$sortie = "";
$toc = rtrim($toc);
$tab_toc = preg_split("/\n/", $toc);
$niveau_pdt = "";
$total = (count($tab_toc)-1);
for ($i = 0; $i <= $total; $i++)
{
$tab_ligne = preg_split("/\|/", $tab_toc[$i]);
$niveau = $tab_ligne[0];
$titre = $tab_ligne[1];
$page = $tab_ligne[2];
$range = $i + 1;
$manifest['structures'][] =
array('@id' => absolute_url("iiif/" . $item->id . "/range/r" . $range),
'@type' => "sc:Range",
'label' => $titre,
'canvases' => array(absolute_url("iiif/" . $item->id . "/canvas/p" . $page))
);
}
}
/*
$manifest['structures'][] =
array('@id' => "http://localhost/omeka26/iiif/3/range/r0",
'@type' => "sc:Range",
'label' => "Page 01",
'canvases' => array("http://localhost/omeka26/iiif/3/canvas/p1")
);
$manifest['structures'][] =
array('@id' => "http://localhost/omeka26/iiif/3/range/r1",
'@type' => "sc:Range",
'label' => "Page 10",
'canvases' => array("http://localhost/omeka26/iiif/3/canvas/p10")
);
*/
} // End if in_array
} // End foeach
} // End of class test
} // End of test array-key-exists
return $manifest ;
}
}