From 2a2a2ba2f6092b0b68a7de0ccc798062682487f4 Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Fri, 2 Aug 2013 21:35:13 +0100 Subject: added basic suport for embedding (html5) videos --- inc/parser/xhtml.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 84a999e56..747f0e8a0 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -795,8 +795,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext,$mime,$dl) = mimetype($src,false); if(substr($mime,0,5) == 'image' && $render){ $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); - }elseif($mime == 'application/x-shockwave-flash' && $render){ - // don't link flash movies + }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){ + // don't link movies $noLink = true; }else{ // add file icons @@ -831,8 +831,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(substr($mime,0,5) == 'image' && $render){ // link only jpeg images // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; - }elseif($mime == 'application/x-shockwave-flash' && $render){ - // don't link flash movies + }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){ + // don't link movies $noLink = true; }else{ // add file icons @@ -1093,6 +1093,28 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $ret .= ' />'; + }elseif(substr($mime,0,5) == 'video'){ + + // first get the $title + if (!is_null($title)) { + $title = $this->_xmlEntities($title); + } + if (!$title) { + // just show the sourcename + $title = $this->_xmlEntities(utf8_basename(noNS($src))); + } + if (!$render) { + // if the video is not supposed to be rendered + // return the title of the video + return $title; + } + + $att = array(); + $att['class'] = "media$align"; + + //add video(s) + $ret .= $this->_video($src, $title, $mime, $width, $height, $att); + }elseif($mime == 'application/x-shockwave-flash'){ if (!$render) { // if the flash is not supposed to be rendered @@ -1226,6 +1248,42 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } + /** + * Embed video(s) in HTML + * + * @author Anika Henke <anika@selfthinker.org> + * + * @param string $src - ID of video to embed + * @param string $title - title of the video + * @param string $mime - mimetype of the video + * @param int $width - width of the video in pixels + * @param int $height - height of the video in pixels + * @param array $atts - additional attributes for the <video> tag + */ + function _video($src,$title,$mime,$width,$height,$atts=null){ + + // prepare width and height + if(is_null($atts)) $atts = array(); + $atts['width'] = (int) $width; + $atts['height'] = (int) $height; + if(!$atts['width']) $atts['width'] = 320; + if(!$atts['height']) $atts['height'] = 240; + + $url = ml($src,array('cache'=>$cache),true,'&'); + + // @todo: add poster + $this->doc .= '<video '.buildAttributes($atts).' controls="controls">'.NL; + // @todo: foreach all extensions + $this->doc .= '<source src="'.hsc($url).'" />'.NL; + + // alternative content + // @todo: foreach all extensions + $this->internalmedia($src, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + + // finish + $this->doc .= '</video>'.NL; + } + } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7 Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Fri, 2 Aug 2013 23:13:41 +0100 Subject: Add several alternative formats to video for better browser compatibility All .webm, .ogv and .mp4 files with the same filename are automatically chosen as alternative sources when only one of them is mentioned in the media syntax. --- inc/parser/xhtml.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 747f0e8a0..bb5f6a4d2 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1095,9 +1095,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { }elseif(substr($mime,0,5) == 'video'){ + $origTitle = ''; // first get the $title if (!is_null($title)) { $title = $this->_xmlEntities($title); + $origTitle = $title; } if (!$title) { // just show the sourcename @@ -1113,7 +1115,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $att['class'] = "media$align"; //add video(s) - $ret .= $this->_video($src, $title, $mime, $width, $height, $att); + $ret .= $this->_video($src, $origTitle, $mime, $width, $height, $att); }elseif($mime == 'application/x-shockwave-flash'){ if (!$render) { @@ -1269,16 +1271,30 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(!$atts['width']) $atts['width'] = 320; if(!$atts['height']) $atts['height'] = 240; - $url = ml($src,array('cache'=>$cache),true,'&'); + // prepare alternative formats + $extensions = array('webm', 'ogv', 'mp4'); + $types['webm'] = 'video/webm; codecs="vp8, vorbis"'; + $types['ogv'] = 'video/ogg; codecs="theora, vorbis"'; + // mp4 would be 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', but Android doesn't like it + $types['mp4'] = ''; + $alternatives = media_alternativefiles($src, $extensions); // @todo: add poster $this->doc .= '<video '.buildAttributes($atts).' controls="controls">'.NL; - // @todo: foreach all extensions - $this->doc .= '<source src="'.hsc($url).'" />'.NL; + foreach($alternatives as $ext => $file) { + $url = ml($file,array('cache'=>$cache),true,'&'); + $type = $types[$ext]; + if (!$title) { + $title = $this->_xmlEntities(utf8_basename(noNS($file))); + } - // alternative content - // @todo: foreach all extensions - $this->internalmedia($src, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + $this->doc .= '<source src="'.hsc($url).'"'; + if (!empty($type)) $this->doc .= ' type=\''.$type.'\''; + $this->doc .= ' />'.NL; + + // alternative content + $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + } // finish $this->doc .= '</video>'.NL; -- cgit v1.2.3 From 99f943f68e3a6bd43d9b5b90f39e058ee2acfa9d Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Fri, 2 Aug 2013 23:53:28 +0100 Subject: added poster attribute to video if jpg or png with same file name exists --- inc/parser/xhtml.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index bb5f6a4d2..8b7405402 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1278,9 +1278,15 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // mp4 would be 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', but Android doesn't like it $types['mp4'] = ''; $alternatives = media_alternativefiles($src, $extensions); + $poster = media_alternativefiles($src, array('jpg', 'png'), true); + $posterUrl = ''; + if (!empty($poster)) { + $posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&'); + } - // @todo: add poster - $this->doc .= '<video '.buildAttributes($atts).' controls="controls">'.NL; + $this->doc .= '<video '.buildAttributes($atts).' controls="controls"'; + if ($posterUrl) $this->doc .= ' poster="'.$posterUrl.'"'; + $this->doc .= '>'.NL; foreach($alternatives as $ext => $file) { $url = ml($file,array('cache'=>$cache),true,'&'); $type = $types[$ext]; -- cgit v1.2.3 From 79e53fe5a44293a82486c7228deb6d435768bc04 Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Sat, 3 Aug 2013 14:34:17 +0100 Subject: improved code for videos (restrict to 3 mimetypes, removed codec info from type attribute) --- inc/parser/xhtml.php | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 8b7405402..b1bfaae5d 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1093,13 +1093,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $ret .= ' />'; - }elseif(substr($mime,0,5) == 'video'){ - - $origTitle = ''; + }elseif($mime == 'video/webm' || $mime == 'video/ogg' || $mime == 'video/mp4' ){ // first get the $title if (!is_null($title)) { $title = $this->_xmlEntities($title); - $origTitle = $title; } if (!$title) { // just show the sourcename @@ -1115,7 +1112,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $att['class'] = "media$align"; //add video(s) - $ret .= $this->_video($src, $origTitle, $mime, $width, $height, $att); + $ret .= $this->_video($src, $width, $height, $att); }elseif($mime == 'application/x-shockwave-flash'){ if (!$render) { @@ -1262,7 +1259,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @param int $height - height of the video in pixels * @param array $atts - additional attributes for the <video> tag */ - function _video($src,$title,$mime,$width,$height,$atts=null){ + function _video($src,$width,$height,$atts=null){ // prepare width and height if(is_null($atts)) $atts = array(); @@ -1273,10 +1270,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // prepare alternative formats $extensions = array('webm', 'ogv', 'mp4'); - $types['webm'] = 'video/webm; codecs="vp8, vorbis"'; - $types['ogv'] = 'video/ogg; codecs="theora, vorbis"'; - // mp4 would be 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', but Android doesn't like it - $types['mp4'] = ''; $alternatives = media_alternativefiles($src, $extensions); $poster = media_alternativefiles($src, array('jpg', 'png'), true); $posterUrl = ''; @@ -1284,21 +1277,18 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&'); } + // open video tag $this->doc .= '<video '.buildAttributes($atts).' controls="controls"'; if ($posterUrl) $this->doc .= ' poster="'.$posterUrl.'"'; $this->doc .= '>'.NL; - foreach($alternatives as $ext => $file) { - $url = ml($file,array('cache'=>$cache),true,'&'); - $type = $types[$ext]; - if (!$title) { - $title = $this->_xmlEntities(utf8_basename(noNS($file))); - } - $this->doc .= '<source src="'.hsc($url).'"'; - if (!empty($type)) $this->doc .= ' type=\''.$type.'\''; - $this->doc .= ' />'.NL; + // output source for each alternative video format + foreach($alternatives as $mime => $file) { + $url = ml($file,array('cache'=>$cache),true,'&'); + $title = $this->_xmlEntities(utf8_basename(noNS($file))); - // alternative content + $this->doc .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; + // alternative content (just a link to the file) $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); } -- cgit v1.2.3 From b44a5dce182bb65063dd1868e92954520e8fab88 Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Sat, 3 Aug 2013 16:56:16 +0100 Subject: added support for html5 audio Similar to videos, all .ogg, .mp3 and .wav files with the same filename are automatically chosen as alternative sources when only one of them is mentioned in the media syntax. --- inc/parser/xhtml.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index b1bfaae5d..c6e5a8e22 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1114,6 +1114,27 @@ class Doku_Renderer_xhtml extends Doku_Renderer { //add video(s) $ret .= $this->_video($src, $width, $height, $att); + }elseif($mime == 'audio/ogg' || $mime == 'audio/mpeg' || $mime == 'audio/wav' ){ + // first get the $title + if (!is_null($title)) { + $title = $this->_xmlEntities($title); + } + if (!$title) { + // just show the sourcename + $title = $this->_xmlEntities(utf8_basename(noNS($src))); + } + if (!$render) { + // if the video is not supposed to be rendered + // return the title of the video + return $title; + } + + $att = array(); + $att['class'] = "media$align"; + + //add audio + $ret .= $this->_audio($src, $att); + }elseif($mime == 'application/x-shockwave-flash'){ if (!$render) { // if the flash is not supposed to be rendered @@ -1253,8 +1274,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @author Anika Henke <anika@selfthinker.org> * * @param string $src - ID of video to embed - * @param string $title - title of the video - * @param string $mime - mimetype of the video * @param int $width - width of the video in pixels * @param int $height - height of the video in pixels * @param array $atts - additional attributes for the <video> tag @@ -1296,6 +1315,37 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= '</video>'.NL; } + /** + * Embed audio in HTML + * + * @author Anika Henke <anika@selfthinker.org> + * + * @param string $src - ID of audio to embed + * @param array $atts - additional attributes for the <video> tag + */ + function _audio($src,$atts=null){ + + // prepare alternative formats + $extensions = array('ogg', 'mp3', 'wav'); + $alternatives = media_alternativefiles($src, $extensions); + + // open audio tag + $this->doc .= '<audio '.buildAttributes($atts).' controls="controls">'.NL; + + // output source for each alternative audio format + foreach($alternatives as $mime => $file) { + $url = ml($file,array('cache'=>$cache),true,'&'); + $title = $this->_xmlEntities(utf8_basename(noNS($file))); + + $this->doc .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; + // alternative content (just a link to the file) + $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + } + + // finish + $this->doc .= '</audio>'.NL; + } + } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 6d4af72aa6e7a34b426f494eedb8a93cf2ce097a Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Sun, 4 Aug 2013 09:08:02 +0100 Subject: fixed typo --- inc/parser/xhtml.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index c6e5a8e22..05472db1d 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1321,7 +1321,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @author Anika Henke <anika@selfthinker.org> * * @param string $src - ID of audio to embed - * @param array $atts - additional attributes for the <video> tag + * @param array $atts - additional attributes for the <audio> tag */ function _audio($src,$atts=null){ -- cgit v1.2.3 From f50634f0c2d6669655b684449d5a6ef44e5ca3f1 Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Sun, 4 Aug 2013 10:35:00 +0100 Subject: refactored audio/video code, removed wrong link around audio --- inc/parser/xhtml.php | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 05472db1d..32aa99a1b 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -783,7 +783,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, - $height=NULL, $cache=NULL, $linking=NULL) { + $height=NULL, $cache=NULL, $linking=NULL, $return=NULL) { global $ID; list($src,$hash) = explode('#',$src,2); resolve_mediaid(getNS($ID),$src, $exists); @@ -795,7 +795,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext,$mime,$dl) = mimetype($src,false); if(substr($mime,0,5) == 'image' && $render){ $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); - }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){ + }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){ // don't link movies $noLink = true; }else{ @@ -814,8 +814,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } //output formatted - if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; - else $this->doc .= $this->_formatLink($link); + if ($return) { + if ($linking == 'nolink' || $noLink) return $link['name']; + else return $this->_formatLink($link); + } else { + if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; + else $this->doc .= $this->_formatLink($link); + } } function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, @@ -831,7 +836,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(substr($mime,0,5) == 'image' && $render){ // link only jpeg images // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; - }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){ + }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){ // don't link movies $noLink = true; }else{ @@ -1093,7 +1098,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $ret .= ' />'; - }elseif($mime == 'video/webm' || $mime == 'video/ogg' || $mime == 'video/mp4' ){ + }elseif(media_supportedav($mime, 'video')){ // first get the $title if (!is_null($title)) { $title = $this->_xmlEntities($title); @@ -1114,7 +1119,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { //add video(s) $ret .= $this->_video($src, $width, $height, $att); - }elseif($mime == 'audio/ogg' || $mime == 'audio/mpeg' || $mime == 'audio/wav' ){ + }elseif(media_supportedav($mime, 'audio')){ // first get the $title if (!is_null($title)) { $title = $this->_xmlEntities($title); @@ -1277,6 +1282,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @param int $width - width of the video in pixels * @param int $height - height of the video in pixels * @param array $atts - additional attributes for the <video> tag + * @return string */ function _video($src,$width,$height,$atts=null){ @@ -1296,23 +1302,25 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&'); } + $out = ''; // open video tag - $this->doc .= '<video '.buildAttributes($atts).' controls="controls"'; - if ($posterUrl) $this->doc .= ' poster="'.$posterUrl.'"'; - $this->doc .= '>'.NL; + $out .= '<video '.buildAttributes($atts).' controls="controls"'; + if ($posterUrl) $out .= ' poster="'.$posterUrl.'"'; + $out .= '>'.NL; // output source for each alternative video format foreach($alternatives as $mime => $file) { $url = ml($file,array('cache'=>$cache),true,'&'); $title = $this->_xmlEntities(utf8_basename(noNS($file))); - $this->doc .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; + $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) - $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + $out .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); } // finish - $this->doc .= '</video>'.NL; + $out .= '</video>'.NL; + return $out; } /** @@ -1322,6 +1330,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * * @param string $src - ID of audio to embed * @param array $atts - additional attributes for the <audio> tag + * @return string */ function _audio($src,$atts=null){ @@ -1329,21 +1338,23 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $extensions = array('ogg', 'mp3', 'wav'); $alternatives = media_alternativefiles($src, $extensions); + $out = ''; // open audio tag - $this->doc .= '<audio '.buildAttributes($atts).' controls="controls">'.NL; + $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL; // output source for each alternative audio format foreach($alternatives as $mime => $file) { $url = ml($file,array('cache'=>$cache),true,'&'); $title = $this->_xmlEntities(utf8_basename(noNS($file))); - $this->doc .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; + $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) - $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + $out .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); } // finish - $this->doc .= '</audio>'.NL; + $out .= '</audio>'.NL; + return $out; } } -- cgit v1.2.3 From 45d5ad751f327b10e7256d448d5595daa82c98c4 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag <klapinklapin@gmail.com> Date: Tue, 15 Oct 2013 13:03:30 +0200 Subject: fix php strict notices --- inc/parser/handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 1de981b48..63a4104e2 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -70,7 +70,7 @@ class Doku_Handler { */ function plugin($match, $state, $pos, $pluginname){ $data = array($match); - $plugin =& plugin_load('syntax',$pluginname); + $plugin = plugin_load('syntax',$pluginname); if($plugin != null){ $data = $plugin->handle($match, $state, $pos, $this); } -- cgit v1.2.3 From 443e135d59e9d227eec818dabf9ee64d7a73d474 Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Wed, 16 Oct 2013 22:04:01 +0100 Subject: replace boolean conditional checks on possibly uninitialized vars with \!empty/empty/isset as appropriate --- inc/parser/handler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 63a4104e2..bb284136f 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -653,8 +653,8 @@ function Doku_Handler_Parse_Media($match) { //parse width and height if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){ - ($size[1]) ? $w = $size[1] : $w = null; - ($size[3]) ? $h = $size[3] : $h = null; + !empty($size[1]) ? $w = $size[1] : $w = null; + !empty($size[3]) ? $h = $size[3] : $h = null; } else { $w = null; $h = null; -- cgit v1.2.3 From 53bfcb5964deda22607f47981b51d17e0f48d7ca Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Wed, 16 Oct 2013 22:06:51 +0100 Subject: initialize $inParagraph before use --- inc/parser/handler.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index bb284136f..8ae991209 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1432,6 +1432,7 @@ class Doku_Handler_Table { class Doku_Handler_Block { var $calls = array(); var $skipEol = false; + var $inParagraph = false; // Blocks these should not be inside paragraphs var $blockOpen = array( -- cgit v1.2.3 From 9269d0b1fb78c217069efd497734c183df9937be Mon Sep 17 00:00:00 2001 From: Michael Hamann <michael@content-space.de> Date: Tue, 29 Oct 2013 20:52:27 +0100 Subject: Fix the media usage index to include local links --- inc/parser/metadata.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 437559370..8ba159d62 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -274,7 +274,12 @@ class Doku_Renderer_metadata extends Doku_Renderer { $this->internallink($link, $link); } - function locallink($hash, $name = null){} + function locallink($hash, $name = null){ + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } + } /** * keep track of internal links in $this->meta['relation']['references'] -- cgit v1.2.3 From 5a41afe6e3b958291893a0a10105cd41971fb141 Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Sun, 1 Dec 2013 17:57:03 +0000 Subject: FS#1833 (b) Prevent table entry syntax swallowing multiple preceeding blank lines (a) this shouldn't be necessary, blank lines are handled by paragraph processing (b) avoids issues with greedy table syntax competing with plugins --- inc/parser/parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index e39a4daf5..1f14b98a3 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -454,8 +454,8 @@ class Doku_Parser_Mode_table extends Doku_Parser_Mode { } function connectTo($mode) { - $this->Lexer->addEntryPattern('\s*\n\^',$mode,'table'); - $this->Lexer->addEntryPattern('\s*\n\|',$mode,'table'); + $this->Lexer->addEntryPattern('[\t ]*\n\^',$mode,'table'); + $this->Lexer->addEntryPattern('[\t ]*\n\|',$mode,'table'); } function postConnect() { -- cgit v1.2.3 From 72d89f96f31af5c92f96fa16f0d1adf15c0bf4e8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Tue, 7 Jan 2014 19:16:54 +0100 Subject: remove duplicate plugin code for syntax plugins This makes Doku_Parser_Mode inherit from DokuWiki_Plugin which allows for the removal of a bunch of duplicate code form DokuWiki_Syntax_Plugin. This makes the code easier to maintain and makes sure all DokuWiki plugins are actual instances of DokuWiki_Plugin. However this adds a bunch of functions to the "normal" parser modes that don't need them which could have performance/RAM implications. --- inc/parser/parser.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 1f14b98a3..43a1c22fa 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -126,16 +126,14 @@ class Doku_Parser { //------------------------------------------------------------------- /** - * This class and all the subclasses below are - * used to reduce the effort required to register - * modes with the Lexer. For performance these - * could all be eliminated later perhaps, or - * the Parser could be serialized to a file once - * all modes are registered + * This class and all the subclasses below are used to reduce the effort required to register + * modes with the Lexer. + * + * Inherits from DokuWiki_Plugin for giving additional functions to syntax plugins * * @author Harry Fuecks <hfuecks@gmail.com> */ -class Doku_Parser_Mode { +class Doku_Parser_Mode extends DokuWiki_Plugin { /** * @var Doku_Lexer $Lexer -- cgit v1.2.3 From 5a3e1f53b18728d500b3505f4fbd8c78848120e0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Tue, 7 Jan 2014 19:35:57 +0100 Subject: reintroduce a tiny bit of duplication This reads some duplication in the from of haveing a Doku_Parser_Mode and Doku_Parser_Mode_Plugin class which are basically the same but only the latter extends DokuWiki_Plugin. This avoids the performance/RAM problems mentioned in my previous commit. An interface keeps both logically together. With PHP 5.4 further deduplication could be done via Traits. --- inc/parser/parser.php | 74 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 12 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 43a1c22fa..252bd9170 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -125,41 +125,91 @@ class Doku_Parser { } //------------------------------------------------------------------- + +/** + * Class Doku_Parser_Mode_Interface + * + * Defines a mode (syntax component) in the Parser + */ +interface Doku_Parser_Mode_Interface { + /** + * returns a number used to determine in which order modes are added + */ + public function getSort(); + + /** + * Called before any calls to connectTo + */ + function preConnect(); + + /** + * Connects the mode + * + * @param string $mode + */ + function connectTo($mode); + + /** + * Called after all calls to connectTo + */ + function postConnect(); + + /** + * Check if given mode is accepted inside this mode + * + * @param string $mode + * @return bool + */ + function accepts($mode); +} + /** * This class and all the subclasses below are used to reduce the effort required to register * modes with the Lexer. * - * Inherits from DokuWiki_Plugin for giving additional functions to syntax plugins - * * @author Harry Fuecks <hfuecks@gmail.com> */ -class Doku_Parser_Mode extends DokuWiki_Plugin { - +class Doku_Parser_Mode implements Doku_Parser_Mode_Interface { /** * @var Doku_Lexer $Lexer */ var $Lexer; - var $allowedModes = array(); - // returns a number used to determine in which order modes are added function getSort() { trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); } - // Called before any calls to connectTo function preConnect() {} - - // Connects the mode function connectTo($mode) {} - - // Called after all calls to connectTo function postConnect() {} - function accepts($mode) { return in_array($mode, (array) $this->allowedModes ); } +} +/** + * Basically the same as Doku_Parser_Mode but extends from DokuWiki_Plugin + * + * Adds additional functions to syntax plugins + */ +class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mode_Interface { + /** + * @var Doku_Lexer $Lexer + */ + var $Lexer; + var $allowedModes = array(); + + function getSort() { + trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); + } + + function preConnect() {} + function connectTo($mode) {} + function postConnect() {} + function accepts($mode) { + return in_array($mode, (array) $this->allowedModes ); + } } //------------------------------------------------------------------- -- cgit v1.2.3 From 8cc41db0f42cbb8028c05720e98b98451463c403 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Wed, 8 Jan 2014 21:14:51 +0100 Subject: fix renderer:plugin() signature in 82d616353e4c3680d88f083eb6f88fe68de92904 we introduced passing the raw match for syntax plugins to the plugin method of the renderer. This was introduced for renderer plugins that might need access to the raw syntax (like the table editor or WYSIWYG plugins). However the function signature was never updated, making these additional parameter basically secret. With strict standard this throws errors. This patch fixes this. --- inc/parser/renderer.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index c697e990c..e3401fd48 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -59,9 +59,15 @@ class Doku_Renderer extends DokuWiki_Plugin { return false; } - - //handle plugin rendering - function plugin($name,$data){ + /** + * handle plugin rendering + * + * @param string $name Plugin name + * @param mixed $data custom data set by handler + * @param string $state matched state if any + * @param string $match raw matched syntax + */ + function plugin($name,$data,$state='',$match=''){ $plugin = plugin_load('syntax',$name); if($plugin != null){ $plugin->render($this->getFormat(),$this,$data); -- cgit v1.2.3 From 3641199a253e8f92f378f03926af80724ef04146 Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Sun, 2 Feb 2014 14:42:47 +0000 Subject: fixed html errors in video and audio rendering --- inc/parser/xhtml.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 5fca1bf45..80701cd2e 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1302,8 +1302,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $out = ''; // open video tag $out .= '<video '.buildAttributes($atts).' controls="controls"'; - if ($posterUrl) $out .= ' poster="'.$posterUrl.'"'; + if ($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"'; $out .= '>'.NL; + $fallback = ''; // output source for each alternative video format foreach($alternatives as $mime => $file) { @@ -1312,10 +1313,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) - $out .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); + $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); } // finish + $out .= $fallback; $out .= '</video>'.NL; return $out; } @@ -1338,6 +1340,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $out = ''; // open audio tag $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL; + $fallback = ''; // output source for each alternative audio format foreach($alternatives as $mime => $file) { @@ -1346,10 +1349,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) - $out .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); + $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); } // finish + $out .= $fallback; $out .= '</audio>'.NL; return $out; } -- cgit v1.2.3 From 17954bb5e3033069554ebb963fb9040c52b4760b Mon Sep 17 00:00:00 2001 From: Anika Henke <anika@selfthinker.org> Date: Sat, 15 Feb 2014 22:46:32 +0000 Subject: added title to video/audio tags, use title for fallback links, refactored duplicate code --- inc/parser/xhtml.php | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 80701cd2e..9d75c271d 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1096,48 +1096,30 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $ret .= ' />'; - }elseif(media_supportedav($mime, 'video')){ + }elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')){ // first get the $title - if (!is_null($title)) { - $title = $this->_xmlEntities($title); - } - if (!$title) { - // just show the sourcename - $title = $this->_xmlEntities(utf8_basename(noNS($src))); - } + $title = !is_null($title) ? $this->_xmlEntities($title) : false; if (!$render) { - // if the video is not supposed to be rendered - // return the title of the video - return $title; + // 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"; - - //add video(s) - $ret .= $this->_video($src, $width, $height, $att); - - }elseif(media_supportedav($mime, 'audio')){ - // first get the $title - if (!is_null($title)) { - $title = $this->_xmlEntities($title); + if ($title) { + $att['title'] = $title; } - if (!$title) { - // just show the sourcename - $title = $this->_xmlEntities(utf8_basename(noNS($src))); + + if (media_supportedav($mime, 'video')) { + //add video + $ret .= $this->_video($src, $width, $height, $att); } - if (!$render) { - // if the video is not supposed to be rendered - // return the title of the video - return $title; + if (media_supportedav($mime, 'audio')) { + //add audio + $ret .= $this->_audio($src, $att); } - $att = array(); - $att['class'] = "media$align"; - - //add audio - $ret .= $this->_audio($src, $att); - }elseif($mime == 'application/x-shockwave-flash'){ if (!$render) { // if the flash is not supposed to be rendered @@ -1282,7 +1264,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @return string */ function _video($src,$width,$height,$atts=null){ - // prepare width and height if(is_null($atts)) $atts = array(); $atts['width'] = (int) $width; @@ -1309,7 +1290,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // output source for each alternative video format foreach($alternatives as $mime => $file) { $url = ml($file,array('cache'=>$cache),true,'&'); - $title = $this->_xmlEntities(utf8_basename(noNS($file))); + $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) @@ -1345,7 +1326,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // output source for each alternative audio format foreach($alternatives as $mime => $file) { $url = ml($file,array('cache'=>$cache),true,'&'); - $title = $this->_xmlEntities(utf8_basename(noNS($file))); + $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) -- cgit v1.2.3 From f23eef27e07dfe76ab76fda68242d44de10e4022 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag <klapinklapin@gmail.com> Date: Mon, 17 Feb 2014 17:56:58 +0100 Subject: PHPDocs internallink --- inc/parser/xhtml.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 9d75c271d..315b4d640 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -562,6 +562,12 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * $search,$returnonly & $linktype are not for the renderer but are used * elsewhere - no need to implement them in other renderers * + * @param string $id pageid + * @param string|null $name link name + * @param string|null $search adds search url param + * @param bool $returnonly whether to return html or write to doc attribute + * @param string $linktype type to set use of headings + * @return void|string writes to doc attribute or returns html depends on $returnonly * @author Andreas Gohr <andi@splitbrain.org> */ function internallink($id, $name = null, $search=null,$returnonly=false,$linktype='content') { -- cgit v1.2.3 From 2ada8709d3a0cea872f117823b244b400fac5f87 Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Tue, 25 Feb 2014 20:32:56 +0000 Subject: add renderers to autolader --- inc/parser/code.php | 1 - inc/parser/metadata.php | 2 -- inc/parser/renderer.php | 1 - inc/parser/xhtml.php | 3 --- inc/parser/xhtmlsummary.php | 1 - 5 files changed, 8 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/code.php b/inc/parser/code.php index 0b8e3ee02..d77ffd1aa 100644 --- a/inc/parser/code.php +++ b/inc/parser/code.php @@ -5,7 +5,6 @@ * @author Andreas Gohr <andi@splitbrain.org> */ if(!defined('DOKU_INC')) die('meh.'); -require_once DOKU_INC . 'inc/parser/renderer.php'; class Doku_Renderer_code extends Doku_Renderer { var $_codeblock=0; diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 8ba159d62..73bae190f 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -16,8 +16,6 @@ if ( !defined('DOKU_TAB') ) { define ('DOKU_TAB',"\t"); } -require_once DOKU_INC . 'inc/parser/renderer.php'; - /** * The Renderer */ diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index e3401fd48..6b6a1770b 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -6,7 +6,6 @@ * @author Andreas Gohr <andi@splitbrain.org> */ if(!defined('DOKU_INC')) die('meh.'); -require_once DOKU_INC . 'inc/plugin.php'; require_once DOKU_INC . 'inc/pluginutils.php'; /** diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 315b4d640..184e62fe3 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -17,9 +17,6 @@ if ( !defined('DOKU_TAB') ) { define ('DOKU_TAB',"\t"); } -require_once DOKU_INC . 'inc/parser/renderer.php'; -require_once DOKU_INC . 'inc/html.php'; - /** * The Renderer */ diff --git a/inc/parser/xhtmlsummary.php b/inc/parser/xhtmlsummary.php index 95f86cbef..867b71f6a 100644 --- a/inc/parser/xhtmlsummary.php +++ b/inc/parser/xhtmlsummary.php @@ -1,6 +1,5 @@ <?php if(!defined('DOKU_INC')) die('meh.'); -require_once DOKU_INC . 'inc/parser/xhtml.php'; /** * The summary XHTML form selects either up to the first two paragraphs -- cgit v1.2.3 From 489dcad6f038c54dda1f29c0887fa43f5b3f7fcb Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Fri, 28 Feb 2014 16:56:29 +0000 Subject: remove require handled by autoloader --- inc/parser/renderer.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 6b6a1770b..1f9ad00a2 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -6,7 +6,6 @@ * @author Andreas Gohr <andi@splitbrain.org> */ if(!defined('DOKU_INC')) die('meh.'); -require_once DOKU_INC . 'inc/pluginutils.php'; /** * An empty renderer, produces no output -- cgit v1.2.3 From 6d2af55dde922ac10a288b4195b1bf338e7bc5a9 Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Wed, 5 Mar 2014 22:01:20 +0000 Subject: suppress errors where list() may not fill all vars --- inc/parser/metadata.php | 2 +- inc/parser/renderer.php | 6 +++--- inc/parser/xhtml.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 73bae190f..82a268fd6 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -299,7 +299,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { // first resolve and clean up the $id resolve_pageid(getNS($ID), $id, $exists); - list($page, $hash) = explode('#', $id, 2); + @list($page, $hash) = explode('#', $id, 2); // set metadata $this->meta['relation']['references'][$page] = $exists; diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 1f9ad00a2..e748c36d8 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -274,8 +274,8 @@ class Doku_Renderer extends DokuWiki_Plugin { function _simpleTitle($name){ global $conf; - //if there is a hash we use the ancor name only - list($name,$hash) = explode('#',$name,2); + //if there is a hash we use the anchor name only + @list($name,$hash) = explode('#',$name,2); if($hash) return $hash; if($conf['useslash']){ @@ -301,7 +301,7 @@ class Doku_Renderer extends DokuWiki_Plugin { } //split into hash and url part - list($reference,$hash) = explode('#',$reference,2); + @list($reference,$hash) = explode('#',$reference,2); //replace placeholder if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 184e62fe3..4966f103a 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -606,7 +606,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } //keep hash anchor - list($id,$hash) = explode('#',$id,2); + @list($id,$hash) = explode('#',$id,2); if(!empty($hash)) $hash = $this->_headerToLink($hash); //prepare for formating -- cgit v1.2.3