Mysql
 sql >> Database >  >> RDS >> Mysql

Creare tag html personalizzati per CMS?

Ho scritto una classe che fa esattamente quello che chiedi per i miei cms. Ho caricato l'src per te come anche se non l'ho mai rilasciato, il sorgente è rilasciato con una licenza in stile BSD. Tag personalizzate

Fondamentalmente ti permette di fare esattamente quello che chiedi. Nella classe ci sono alcuni tag personalizzati di esempio, quindi non incollerò il codice qui. Fammi sapere come va.

Modifica 1:codice di esempio come richiesto. :-)

Modifica 2:dovrei aggiungere che supporta tag personalizzati nascosti.

Modifica 3:supporta anche la creazione di modelli in linea e la sostituzione dei tag, ad es.

<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:esempio.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>

Funzione PHP per tag personalizzati:tags/youtube/tag.php :

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

Risultato:

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