为CMS创建自定义"html"标签? [英] Creating custom "html"-tags for CMS?

查看:83
本文介绍了为CMS创建自定义"html"标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CMS为PHP中的Web应用程序工作,它需要缩短存储在数据库中的插入(嵌入)内容(例如youtube或vimeo的视频)的过程,方法如下:

I am working with a CMS for a web app in PHP, that has the needs of shortening the process for inserting (embedding) stuff, like a video from youtube or vimeo by wroting the following, which are stored in the database:

<youtube id="wfI0Z6YJhL0" />

在进行某种替换后会输出以下内容:

Which would output the following after some sort of replace:

<!-- Custom formatting before object !-->
<object width="640" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/wfI0Z6YJhL0&amp;hl=sv_SE&amp;fs=1?rel=0&amp;color1=0xe1600f&amp;color2=0xfebd01"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/wfI0Z6YJhL0&amp;hl=sv_SE&amp;fs=1?rel=0&amp;color1=0xe1600f&amp;color2=0xfebd01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
<!-- Custom formatting after object !-->

如何在PHP中做到这一点?

How could I do this in PHP?

推荐答案

我编写了一个类,可以完全满足您对自己的cms的要求.我已经为您上传了src,就好像我从未发布过它一样,其源代码是根据BSD样式许可发布的. 自定义标签

I've written a class that does exactly what you ask for my own cms. I've uploaded the src for you as although I've never released it the source is released under a BSD style license. Custom Tags

基本上,它可以让您按照自己的要求去做.在课堂上,有一些示例自定义标签,因此我不会在此处粘贴代码.让我知道你的情况.

It basically allows you do do exactly what you ask for. In the class there are some example custom tags so I won't paste code here. Let me know how you go.

按要求编写示例代码. :-)

Edit 1: Example Code as requested. :-)

我应该添加它支持隐藏的自定义标签.

Edit 2: I should add it supports buried custom tags.

它还支持内联模板和标签替换,即

Edit 3: It also supports inline templating and tag substitution, ie

<ct:inline some="attribute">
    This is an in line template. <br />
    This is a #{tag} that can be accessed by the callback function
</ct:inline>

PHP/HTML: example.php

PHP/HTML: example.php

<?php

$current_dir = dirname(__FILE__).DIRECTORY_SEPARATOR;
require_once dirname($current_dir).DIRECTORY_SEPARATOR.'customtags.php';

$ct = new CustomTags(array(
    'parse_on_shutdown'     => true,
    'tag_directory'         => $current_dir.'tags'.DIRECTORY_SEPARATOR,
    'sniff_for_buried_tags' => true
));

?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>untitled</title>
    <meta name="generator" content="TextMate http://macromates.com/">
    <meta name="author" content="Oliver Lillie">
    <!-- Date: 2010-07-10 -->
</head>
<body> 

    <ct:youtube id="wfI0Z6YJhL0" />

</body>
</html>

自定义标签PHP功能: tags/youtube/tag.php :

Custom Tag PHP Function: tags/youtube/tag.php:

function ct_youtube($tag)
{
    return '<object id="'.$tag['attributes']->id.'" value="http://www.youtube.com/v/'.$tag['attributes']->id.'" /><param ......>';
}

输出:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"> 

<html lang="en"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>untitled</title> 
    <meta name="generator" content="TextMate http://macromates.com/"> 
    <meta name="author" content="Oliver Lillie"> 
    <!-- Date: 2010-07-10 --> 
</head> 
<body> 

    <object id="wfI0Z6YJhL0" value="http://www.youtube.com/v/wfI0Z6YJhL0" /><param ......> 

</body> 
</html>

这篇关于为CMS创建自定义"html"标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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