-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
139 lines (121 loc) · 4.82 KB
/
renderer.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Render Plugin for jQuery Lazy Load
*
* @author duenni
*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_INC . 'inc/parser/xhtml.php';
/**
* The Renderer
*/
class renderer_plugin_lazyload extends Doku_Renderer_xhtml {
function canRender($format) {
return ($format=='xhtml');
}
/**
* Renders internal and external media
*
* @author Andreas Gohr <[email protected]>
* @param string $src media ID
* @param string $title descriptive text
* @param string $align left|center|right
* @param int $width width of media in pixel
* @param int $height height of media in pixel
* @param string $cache cache|recache|nocache
* @param bool $render should the media be embedded inline or just linked
* @return string
*/
function _media($src, $title = null, $align = null, $width = null,
$height = null, $cache = null, $render = true) {
$ret = '';
list($ext, $mime) = mimetype($src);
if(substr($mime, 0, 5) == 'image') {
// first get the $title
if(!is_null($title)) {
$title = $this->_xmlEntities($title);
} elseif($ext == 'jpg' || $ext == 'jpeg') {
//try to use the caption from IPTC/EXIF
require_once(DOKU_INC.'inc/JpegMeta.php');
$jpeg = new JpegMeta(mediaFN($src));
if($jpeg !== false) $cap = $jpeg->getTitle();
if(!empty($cap)) {
$title = $this->_xmlEntities($cap);
}
}
if(!$render) {
// if the picture is not supposed to be rendered
// return the title of the picture
if(!$title) {
// just show the sourcename
$title = $this->_xmlEntities(utf8_basename(noNS($src)));
}
return $title;
}
//add image tag prepared for lazy loading
$ret .= '<img src="'.DOKU_BASE.'lib/plugins/lazyload/small.gif" data-original="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src))).'"';
$ret .= ' class="media'.$align.'"';
if($title) {
$ret .= ' title="'.$title.'"';
$ret .= ' alt="'.$title.'"';
} else {
$ret .= ' alt=""';
}
if(!is_null($width))
$ret .= ' width="'.$this->_xmlEntities($width).'"';
if(!is_null($height))
$ret .= ' height="'.$this->_xmlEntities($height).'"';
$ret .= ' />';
} elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) {
// first get the $title
$title = !is_null($title) ? $this->_xmlEntities($title) : false;
if(!$render) {
// if the file is not supposed to be rendered
// return the title of the file (just the sourcename if there is no title)
return $title ? $title : $this->_xmlEntities(utf8_basename(noNS($src)));
}
$att = array();
$att['class'] = "media$align";
if($title) {
$att['title'] = $title;
}
if(media_supportedav($mime, 'video')) {
//add video
$ret .= $this->_video($src, $width, $height, $att);
}
if(media_supportedav($mime, 'audio')) {
//add audio
$ret .= $this->_audio($src, $att);
}
} elseif($mime == 'application/x-shockwave-flash') {
if(!$render) {
// if the flash is not supposed to be rendered
// return the title of the flash
if(!$title) {
// just show the sourcename
$title = utf8_basename(noNS($src));
}
return $this->_xmlEntities($title);
}
$att = array();
$att['class'] = "media$align";
if($align == 'right') $att['align'] = 'right';
if($align == 'left') $att['align'] = 'left';
$ret .= html_flashobject(
ml($src, array('cache' => $cache), true, '&'), $width, $height,
array('quality' => 'high'),
null,
$att,
$this->_xmlEntities($title)
);
} elseif($title) {
// well at least we have a title to display
$ret .= $this->_xmlEntities($title);
} else {
// just show the sourcename
$ret .= $this->_xmlEntities(utf8_basename(noNS($src)));
}
return $ret;
}
}