简体   繁体   English

Joomla替换标签

[英]Joomla replacement tags

I am trying to implement this joomla plugin to replace {twitter}demo_user{/twitter} and {facebook}demo_user{/facebook} by links in some content. 我正在尝试实现此joomla插件,以通过某些内容中的链接替换{twitter}demo_user{/twitter}{facebook}demo_user{/facebook}

<?php 
defined('_JEXEC') or die('Access Deny');
class plgContentSocial extends jplugin
{
    function onContentPrepare($context, $article, $params, $limit)
        {
            preg_match_all('/{twitter}(.*?){\/twitter}/is', $article->text, matches)
            $i=0;
            foreach ($matches[0] as $match) {
                $twitter_username=$matches[1][$1];
                $article->text=str_replace($match, '<a href="http://twitter.com/'.$twitter_username.'"follow me on twitter</a>', $article->tex)
                $i++
            }
            preg_match_all('/{facebook}(.*?){\/facebook}/is', $article->text, matches)
            $i=0;
            foreach ($matches[0] as $match) {
                $facebook_username=$matches[1][$1];
                $article->text=str_replace($match, '<a href="http://facebook.com/'.$facebook_username.'"follow me on facebook</a>', $article->tex)
                $i++
            }
        }
}
?>

My problem is: how can I use something like {social type=twitter}demo_user{/social} and {social type=facebook}demo_user{/social} ? 我的问题是:如何使用{social type=twitter}demo_user{/social}{social type=facebook}demo_user{/social} I don't want to repeat the preg_match_all for every social network. 我不想为每个社交网络重复preg_match_all Is there a way to achieve it? 有办法实现吗?

Thank you very much for your guidance 非常感谢您的指导

Please read the manual first. 请先阅读手册。 This is a very basic regular expression issue. 这是一个非常基本的正则表达式问题。

Use the following regular expression. 使用以下正则表达式。

'/{social type="(facebook|twitter)"}(.*?){\/facebook}/is'

You would have to change then 那你就得改变

 $type=$matches[1][$1];
 $username=$matches[2][$1];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM