externalmedia() public method

Render an external media file
public externalmedia ( string $src, string $title = null, string $align = null, integer $width = null, integer $height = null, string $cache = null, string $linking = null, boolean $return = false ) : void | string
$src string full media URL
$title string descriptive text
$align string left|center|right
$width integer width of media in pixel
$height integer height of media in pixel
$cache string cache|recache|nocache
$linking string linkonly|detail|nolink
$return boolean return HTML instead of adding to $doc
return void | string writes to doc attribute or returns html depends on $return
示例#1
0
 function testVideoOGVInternal()
 {
     $file = 'wiki:kind_zu_katze.ogv';
     $parser_response = p_get_instructions('{{' . $file . '}}');
     $calls = array(array('document_start', array()), array('p_open', array()), array('internalmedia', array($file, null, null, null, null, 'cache', 'details')), array('cdata', array(null)), array('p_close', array()), array('document_end', array()));
     $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls);
     $Renderer = new Doku_Renderer_xhtml();
     $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true);
     $video = '<video class="media" width="320" height="240" controls="controls" poster="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.png">';
     $substr_start = 0;
     $substr_len = strlen($video);
     $this->assertEquals($video, substr($url, $substr_start, $substr_len));
     // find $source_webm in $url
     $source_webm = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" type="video/webm" />';
     $substr_start = strpos($url, $source_webm, $substr_start + $substr_len);
     $this->assertNotSame(false, $substr_start, 'Substring not found.');
     // find $source_ogv in $url
     $source_ogv = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" type="video/ogg" />';
     $substr_start = strpos($url, $source_ogv, $substr_start + strlen($source_webm));
     $this->assertNotSame(false, $substr_start, 'Substring not found.');
     // find $a_webm in $url
     $a_webm = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.webm" class="media mediafile mf_webm" title="wiki:kind_zu_katze.webm (99.1 KB)">kind_zu_katze.webm</a>';
     $substr_start = strpos($url, $a_webm, $substr_start + strlen($source_ogv));
     $this->assertNotSame(false, $substr_start, 'Substring not found.');
     // find $a_webm in $url
     $a_ogv = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.ogv" class="media mediafile mf_ogv" title="wiki:kind_zu_katze.ogv (44.8 KB)">kind_zu_katze.ogv</a>';
     $substr_start = strpos($url, $a_ogv, $substr_start + strlen($a_webm));
     $this->assertNotSame(false, $substr_start, 'Substring not found.');
     $rest = '</video>' . "\n";
     $substr_start = strlen($url) - strlen($rest);
     $this->assertEquals($rest, substr($url, $substr_start));
 }
 function testVideoOGVInternal()
 {
     $this->markTestSkipped('Skipped because it is failing');
     $file = 'wiki:kind_zu_katze.ogv';
     $parser_response = p_get_instructions('{{' . $file . '}}');
     $calls = array(array('document_start', array()), array('p_open', array()), array('internalmedia', array($file, null, null, null, null, 'cache', 'details')), array('cdata', array(null)), array('p_close', array()), array('document_end', array()));
     $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls);
     $Renderer = new Doku_Renderer_xhtml();
     $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true);
     $video = '<video class="media" width="320" height="240" controls="controls" poster="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.png">';
     $this->assertEquals(substr($url, 0, 125), $video);
     $source_webm = '<source src="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" type="video/webm" />';
     $this->assertEquals(substr($url, 126, 85), $source_webm);
     $source_ogv = '<source src="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" type="video/ogg" />';
     $this->assertEquals(substr($url, 212, 83), $source_ogv);
     $a_webm = '<a href="/./lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.webm" class="media mediafile mf_webm" title="wiki:kind_zu_katze.webm (99.1 KB)">kind_zu_katze.webm</a>';
     $a_ogv = '<a href="/./lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.ogv" class="media mediafile mf_ogv" title="wiki:kind_zu_katze.ogv (44.8 KB)">kind_zu_katze.ogv</a>';
     $this->assertEquals(substr($url, 296, 176), $a_webm);
     $this->assertEquals(substr($url, 472, 172), $a_ogv);
     $rest = '</video>' . "\n";
     $this->assertEquals(substr($url, 644), $rest);
 }
 /**
  * Return XHTML formated data, depending on column type
  *
  * @param array               $column
  * @param string              $value
  * @param Doku_Renderer_xhtml $R
  * @return string
  */
 function _formatData($column, $value, Doku_Renderer_xhtml $R)
 {
     global $conf;
     $vals = explode("\n", $value);
     $outs = array();
     //multivalued line from db result for pageid and wiki has only in first value the ID
     $storedID = '';
     foreach ($vals as $val) {
         $val = trim($val);
         if ($val == '') {
             continue;
         }
         $type = $column['type'];
         if (is_array($type)) {
             $type = $type['type'];
         }
         switch ($type) {
             case 'page':
                 $val = $this->_addPrePostFixes($column['type'], $val);
                 $val = $this->ensureAbsoluteId($val);
                 $outs[] = $R->internallink($val, null, null, true);
                 break;
             case 'title':
                 list($id, $title) = explode('|', $val, 2);
                 $id = $this->_addPrePostFixes($column['type'], $id);
                 $id = $this->ensureAbsoluteId($id);
                 $outs[] = $R->internallink($id, $title, null, true);
                 break;
             case 'pageid':
                 list($id, $title) = explode('|', $val, 2);
                 //use ID from first value of the multivalued line
                 if ($title == null) {
                     $title = $id;
                     if (!empty($storedID)) {
                         $id = $storedID;
                     }
                 } else {
                     $storedID = $id;
                 }
                 $id = $this->_addPrePostFixes($column['type'], $id);
                 $outs[] = $R->internallink($id, $title, null, true);
                 break;
             case 'nspage':
                 // no prefix/postfix here
                 $val = ':' . $column['key'] . ":{$val}";
                 $outs[] = $R->internallink($val, null, null, true);
                 break;
             case 'mail':
                 list($id, $title) = explode(' ', $val, 2);
                 $id = $this->_addPrePostFixes($column['type'], $id);
                 $id = obfuscate(hsc($id));
                 if (!$title) {
                     $title = $id;
                 } else {
                     $title = hsc($title);
                 }
                 if ($conf['mailguard'] == 'visible') {
                     $id = rawurlencode($id);
                 }
                 $outs[] = '<a href="mailto:' . $id . '" class="mail" title="' . $id . '">' . $title . '</a>';
                 break;
             case 'url':
                 $val = $this->_addPrePostFixes($column['type'], $val);
                 $outs[] = $this->external_link($val, false, 'urlextern');
                 break;
             case 'tag':
                 // per default use keyname as target page, but prefix on aliases
                 if (!is_array($column['type'])) {
                     $target = $column['key'] . ':';
                 } else {
                     $target = $this->_addPrePostFixes($column['type'], '');
                 }
                 $outs[] = '<a href="' . wl(str_replace('/', ':', cleanID($target)), $this->_getTagUrlparam($column, $val)) . '" title="' . sprintf($this->getLang('tagfilter'), hsc($val)) . '" class="wikilink1">' . hsc($val) . '</a>';
                 break;
             case 'timestamp':
                 $outs[] = dformat($val);
                 break;
             case 'wiki':
                 global $ID;
                 $oldid = $ID;
                 list($ID, $data) = explode('|', $val, 2);
                 //use ID from first value of the multivalued line
                 if ($data == null) {
                     $data = $ID;
                     $ID = $storedID;
                 } else {
                     $storedID = $ID;
                 }
                 $data = $this->_addPrePostFixes($column['type'], $data);
                 // Trim document_{start,end}, p_{open,close} from instructions
                 $allinstructions = p_get_instructions($data);
                 $wraps = 1;
                 if (isset($allinstructions[1]) && $allinstructions[1][0] == 'p_open') {
                     $wraps++;
                 }
                 $instructions = array_slice($allinstructions, $wraps, -$wraps);
                 $outs[] = p_render('xhtml', $instructions, $byref_ignore);
                 $ID = $oldid;
                 break;
             default:
                 $val = $this->_addPrePostFixes($column['type'], $val);
                 //type '_img' or '_img<width>'
                 if (substr($type, 0, 3) == 'img') {
                     $width = (int) substr($type, 3);
                     if (!$width) {
                         $width = $this->getConf('image_width');
                     }
                     list($mediaid, $title) = explode('|', $val, 2);
                     if ($title === null) {
                         $title = $column['key'] . ': ' . basename(str_replace(':', '/', $mediaid));
                     } else {
                         $title = trim($title);
                     }
                     if (media_isexternal($val)) {
                         $html = $R->externalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true);
                     } else {
                         $html = $R->internalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true);
                     }
                     if (strpos($html, 'mediafile') === false) {
                         $html = str_replace('href', 'rel="lightbox" href', $html);
                     }
                     $outs[] = $html;
                 } else {
                     $outs[] = hsc($val);
                 }
         }
     }
     return join(', ', $outs);
 }