Creating custom html tags for CMS?

I work with CMS for a web application in PHP, which has a need to shorten the process of inserting (embedding) material, such as videos from youtube or vimeo, waving the following, which are stored in the database:

<youtube id="wfI0Z6YJhL0" /> 

To display the following after replacement:

 <!-- 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 !--> 

How can I do this in PHP?

+3
object php mysql embed
source share
2 answers

I wrote a class that does exactly what you ask for my own cms. I downloaded src for you, since although I never released it, the source is released under a BSD style license. Custom tags

This basically allows you to do what you ask. There are some examples of custom tags in the class, so I will not embed code here. Let me know how you go.

Edit 1: Sample code as requested. :-)

Edit 2: I have to add that it supports hidden user tags.

Edit 3: It also supports built-in templating and tag replacement, i.e.

 <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 $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> 

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 ......>'; } 

Output:

 <!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> 
+11
source share

I'm not 100% sure how it will respond to non-standard tags, but if it works, simpleHTMLDom will be perfect for this.

 $html = str_get_html('....'); 

then something along the lines ...

 $element = $html->find('youtube',0 ); // Finds first element // - use "foreach" loop for final version $element->tag = 'object'; $element->value = "http://www.youtube.com/v/".$element->id; $element->innertext= "<param ......>" .... echo $html; 

you get a drift.

The beauty of this approach would be that each particular extension could add its data to the pure HTML <tagname attribute="value"> notation, even with the ability to add a subtag for structured information instead of kludgy {placeholder} and regular expressions, etc. ..

I have never tried this, and I don’t have time to check it right now, but if you decide to try it, I would be interested to know if this method turned out to be useful.

+3
source share

All Articles