-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmedia.php
102 lines (84 loc) · 3.7 KB
/
media.php
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
<?php
/*
On a deux types de fichiers inclus:
les distant => table fichiersexternes
soit une URL
soit un code HTML
les docannexe => table fichiers
Les tables sont définis dans le ME, mais on les utilise ici en dur !
*/
function media($text) {
global $db;
$reg = '#\[(image|son|sound|video|animation|pdf):([^\]]*?)\]#';
preg_match_all($reg, $text, $matches, PREG_SET_ORDER);
foreach ($matches as $medium) {
list($media_reference, $media_type, $identifier) = $medium;
// récupérer l'id du document, son status et sa class (fichiers ou fichiersexternes)
$idparent = intval($GLOBALS['context']['id']);
$sql = lq('SELECT e.id, e.status, t.class FROM #_TP_entities as e JOIN #_TP_types as t ON e.idtype=t.id WHERE idparent='.$idparent.' AND identifier='.$GLOBALS['db']->quote($identifier));
$row = $db->GetRow($sql);
// Le media n'est pas trouvé dans la base
if (empty($row)) {
$warning = '<div style="background-color:red;">'.getlodeltextcontents("media_expected","site").' : '.$media_reference.'</div>';
$text = str_replace($media_reference, $warning, $text);
continue;
}
// effacer le <p class="texte"> qui entoure eventuellement le media
$reg = "@<p class=\"texte\">\s*".preg_quote($media_reference)."\s*<\/p>@";
$text = preg_replace($reg, $media_reference, $text);
// populate $id, $status, $class
extract($row);
// Document non publié, utilisateur non logué, on efface toute trace
if (($status <= 0) && !C::get('visitor','lodeluser')) {
$text = str_replace($media_reference, '', $text);
continue;
}
// chercher les infos du document
$sql = ($class == 'fichiers') ?
"select titre, document, description, legende, credits FROM #_TP_$class WHERE identity=$id" :
"select titre, object, description, legende, credits, urlaccesmedia FROM #_TP_$class WHERE identity=$id";
$info = $db->GetRow(lq($sql));
$info['id'] = $id;
$info['media_type'] = $media_type;
// Si class fichiers: créer la balise object qui convient
if ($class == 'fichiers') {
$info['object'] = media_create_object($info['document'], $media_type, $id);
$info['urlaccesmedia'] = "";
}
// créer le HTML selon le type
$html = '<figure id="media-'.$identifier.'" class="doc-media doc-media-type-'.$media_type.'">';
if(!empty($info['titre'])){
$html .= '<p class="media-titre">'.$info['titre'].'</p>';
}
$html .= '<div class="doc-media-contents">'.$info['object'].'</div>';
if(!empty($info['description']))
$html .= '<div class="media-description">'.$info['description'].'</div>';
if(!empty($info['legende']))
$html .= '<figcaption class="media-legende">'.$info['legende'].'</figcaption>';
if(!empty($info['credits'])){
$html .= '<p class="media-credits">'.getlodeltextcontents("Credits","site").': '.$info['credits'].'</p>';
}
if(!empty($info['urlaccesmedia'])){
$html .= '<p class="media-urlaccesmedia">'.getlodeltextcontents("Permalien","site").': <a href="'.$info['urlaccesmedia'].'">'.$info['urlaccesmedia'].'</a></p>';
}
$html .='</figure>';
$text = str_replace($media_reference, $html, $text);
}
return $text;
}
function media_create_object($url, $media_type, $id) {
switch($media_type) {
case "image":
$object = "<img src='$url' />";
break;
case "pdf":
global $context;
$url = urlencode($context['siteurl'] . '/' . makeurlwithfile($id));
$object = "<iframe src='tpl/node_modules/pdfjs-dist-viewer-min/build/minified/web/viewer.html?file=$url'></iframe>";
$object .= "<a class='media-pdf-download' href='tpl/node_modules/pdfjs-dist-viewer-min/build/minified/web/viewer.html?file=$url' target='_blank'>".getlodeltextcontents("TELECHARGER_PDF_EMBED","site")."</a>";
break;
default:
$object = "<img src='$url' />";
}
return $object;
}