【问题标题】:Is it a PHP or Joomla! issue? (or perhaps I'm missing something about the output buffering)是 PHP 还是 Joomla!问题? (或者我可能遗漏了一些关于输出缓冲的东西)
【发布时间】:2012-02-07 17:20:42
【问题描述】:

我正在尝试将 VideoJS 集成到一个插件中,以便在博客和文章视图/布局中显示视频。首先,我使用正则表达式找到插件标签和视频的来源,可以是 YouTube 视频 ID 或视频文件的路径:

YouTube 视频来源:{youtube}y0u7u83v1de0{/youtube} 视频文件 来源:{video}path/to/video.mp4{/video}

找到这些值不是问题,在尝试回显视频源时会出现问题。我正在使用 stdClass 对象来保存 onContentBeforeDisplay 函数中的值:

$width = 636; 
$height = 333; 
$youtubeCode = '/{youtube}(.*?){\/youtube}/'; 
$videoCode = '/{video}(.*?){\/video}/'; 
preg_match($youtubeCode, $article->introtext, $match); 
preg_match($videoCode, $article->introtext, $match); 
$video = new stdClass(); 
$video->source = $match[1]; 
$video->width = $width; 
$video->height = $height; 
$layout = JPATH_SITE . DS . 'plugins' . DS . $this->plugin->type . 
DS . $this->plugin->name . DS . 'tmpl' . DS . 'default.php'; 

if ($layout) { 
    ob_start(); 
    require $layout; 
    $contents = ob_get_contents(); 
    ob_end_clean(); 
    $article->introtext = $contents . $article->introtext; 
}

现在,布局文件只输出带有 各自的价值观:

<video id="<?= $video->id ?>" class="video-js vjs-default-skin" controls width="<?= $video->width ?>" height="<?= $video->height ?>" poster="<?= $video->images['preview'] ?>" data-setup="{techOrder: ['youtube', 'html5']}">
    <source src="<?= $video->source ?>" type="<?= $video->format ?>" /> 
</video>

所有值都正确显示,除了 $video->source 属性,它在开始输出缓冲之前仍然具有正确的值,但似乎开始输出会使该特定值无效。

什么可能导致这种行为?关于我可能缺少的输出缓冲?

提前致谢!

【问题讨论】:

  • Joomla 基于 PHP 你知道...
  • 我实际上找到了“问题”。我与 PHP 和 Joomla! 没有任何关系。我怎样才能结束这个问题?
  • @SaulMartínez:自己回答问题,标记答案。

标签: php joomla joomla1.6


【解决方案1】:

我不知道 VideoJS,我不知道你想要做什么正则表达式首先搜索 {youtube} 标签,然后搜索 {video} 标签,但您使用相同的 $match 变量并且您不测试您(最终)找到的是(是 youtube 视频还是“正常”视频?)。

据我所知,您在布局文件中访问 $video->format 但您没有设置它。

也许你应该写一些这样的东西

[...]
if ( preg_match($youtubeCode, $article->introtext, $match) ) {
    // found a {youtube} tag
    $video->format = "youtube";
    $video->source = $match[1];
} else if ( preg_match($videoCode, $article->introtext, $match) ) {
    // found a {video} tag
    $video->format = "video";
    $video->source = $match[1];
}

// Prepend the <video> element if {youtube} or {video} tag found
if ( $layout && !is_null($video->format) && !is_null($video->format) ) { 
    ob_start(); 
    require $layout; 
    $contents = ob_get_contents(); 
    ob_end_clean(); 
    $article->introtext = $contents . $article->introtext; 
}

但请注意,因为它应该只替换找到的第一个标签,如果您有一篇带有多个 {youtube}/{video} 标签的文章,它应该不起作用。

希望我已经很好地理解了您要做什么:P

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    • 2021-11-01
    • 2011-05-14
    • 1970-01-01
    • 2021-04-25
    • 1970-01-01
    相关资源
    最近更新 更多