自己的自定义cms的简码插件,例如wordpress简码插件 [英] Shortcode plugins for own custom cms like wordpress shortcode plugins

查看:252
本文介绍了自己的自定义cms的简码插件,例如wordpress简码插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为自己创建了一个自定义CMS,并创建了一个按预期运行的插件系统.

I have created a custom CMS for my own and a plugin system that is working as I expected.

现在,我想基于简码创建插件, 例如: [gallery attr1 = 100 attr2 ="string"]和[mycode title ='message'color ='#F00'] Hello World![/mycode]

Now I want to create plugins based on shortcodes, eg: [gallery attr1=100 attr2="string"] and [mycode title='message' color='#F00']Hello World![/mycode]

我想在CMS中处理上述简短代码. 函数将用HTML替换短代码并获取&将属性设置为mySQL查询或其他内容的参数.

I want to handle the above mentioned shortcodes in my CMS. Functions will replace shortcodes with HTML and get & set attributes as parameters for mySQL queries or something else.

也许正则表达式会有所帮助,但我不是正则表达式专家.如果还有其他微笑者或存在好的方式,我不想使用这样的正则表达式.

may be regular expressions will help, I am not expert in regular expressions. I would don't like to use such regular expressions if there are other smiler or good ways exist .

使用PHP和mySQL开发的CMS.

CMS developed using PHP and mySQL.

我已经访问了wordpress开发人员站点并获得了概念,我已经创建了注册或设置插件,菜单,主题侧边栏等的功能.

I have visited the wordpress developers sites and got the concepts, I have already created functions that register or set plugins, menus, theme sidebars etc.

我认为这种信息足以说明我的意思.

I think this info is enough to get the point as I can just explain in this way.

提前谢谢

推荐答案

此代码解决了逻辑问题

function plugin_sortcode($contents) {
    global $SORTCODES, $DATA;

    foreach ($SORTCODES as $name => $fn) {
        $attr = array();
        preg_match_all("/\[" . $name . " (.*?)\]/", $contents, $matches);
        if ($matches[0]) {

            $code = $matches[0][0];
            if (isset($matches[1])) {
                $attrs = $matches[1][0];
                $attrs = explode(" ", $attrs);
                foreach ($attrs as $values) {
                    $attrs1 = explode("=", $values);
                    $attr[$attrs1[0]] = $attrs1[1];
                }
            }

            $data = $fn($attr, $DATA);
            $contents = str_replace($code, $data, $contents);
        }
    }

    return $contents;
}

这篇关于自己的自定义cms的简码插件,例如wordpress简码插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆