我在Joomla上创建了一个简单的短码插件。实际上,我正在尝试将Cleeng Video与Joomla集成。并将在未来连接它的用户(我希望)。我已经开始创建短码的参数了。我不知道如何解析它的参数和值。我的短码在这里(没有参数)
{cleengvideo}<iframe class="wistia_embed" src="http://fast.wistia.net/embed/iframe/5r8r9ib6di" name="wistia_embed" width="640" height="360" frameborder="0" scrolling="no" allowfullscreen=""></iframe>{/cleengvideo}我的代码在这里
public function onContentPrepare($content, $article, $params, $limit) {
preg_match_all('/{cleengvideo}(.*?){\/cleengvideo}/is', $article->text, $matches);
$i = 0;
foreach ($matches[0] as $match) {
$videoCode = $matches[1][$i];
$article->text = str_replace($match, $videoCode, $article->text);
}我想设置高度,宽度和5r8r9ib6di这个代码至少从短码。有没有人可以帮我添加和解析它的参数
发布于 2013-12-06 19:07:31
要获取参数,只需使用以下代码:
$params->get('param_name', 'default_value');例如,在您的XML文件中,如果您有一个如下所示的字段:
<field name="width" type="text" label="Width" default="60px" />您可以这样调用该参数:
$params->get('width', '60px');请注意,您不必将缺省值添加为第二个字符串,但是我发现这是一个很好的做法。
希望这能有所帮助
发布于 2013-12-06 20:00:28
我想我能找到解决方案。在这里https://github.com/Cleeng/cleeng-wp-plugin/blob/master/php/classes/Frontend.php代码是
$expr = '/\[cleeng_content(.*?[^\\\])\](.*?[^\\\])\[\/cleeng_content\]/is';
preg_match_all( $expr, $post->post_content, $m );
foreach ( $m[0] as $key => $content ) {
$paramLine = $m[1][$key];
$expr = '/(\w+)\s*=\s*(?:\"|")(.*?)(?<!\\\)(?:\"|")/si';
preg_match_all( $expr, $paramLine, $mm );
if ( ! isset( $mm[0] ) || ! count( $mm[0] ) ) {
continue;
}
$params = array( );
foreach ( $mm[1] as $key => $paramName ) {
$params[$paramName] = $mm[2][$key];
}
if ( ! isset( $params['id'] ) ) {
continue;
}
$content = array(
'contentId' => $params['id'],
'shortDescription' => @$params['description'],
'price' => @$params['price'],
'itemType' => 'article',
'purchased' => false,
'shortUrl' => '',
'referred' => false,
'referralProgramEnabled' => false,
'referralRate' => 0,
'rated' => false,
'publisherId' => '000000000',
'publisherName' => '',
'averageRating' => 4,
'canVote' => false,
'currencySymbol' => '',
'sync' => false
);
if ( isset( $params['referral'] ) ) {
$content['referralProgramEnabled'] = true;
$content['referralRate'] = $params['referral'];
}
if ( isset( $params['ls'] ) && isset( $params['le'] ) ) {
$content['hasLayerDates'] = true;
$content['layerStartDate'] = $params['ls'];
$content['layerEndDate'] = $params['le'];
}
$this->cleeng_content[$params['id']] = $content;
}发布于 2017-05-13 20:29:07
希望这能帮助搜索短码参数的人,对于短码中的参数,我们可以像这样使用preg_match_all
preg_match_all('/{cleengvideo(.*?)}(.*?){\/cleengvideo}/is', $article->text, $matches);这将给出一个有3个数组元素的数组,第二个数组有你可以用代码修改的参数。
希望这能有所帮助。
https://stackoverflow.com/questions/20422201
复制相似问题