Verfügbare Chains für Contenido sind der Chain-Konfigurationsdatei "/contenido/includes/config.chains.php" definiert. Jede Chain hat normalerweise einen eindeutigen Namen, aus der man ableiten kann, wo es eingesetzt wird.
Beispiel:
Code: Alles auswählen
/* Chain Contenido.Content.SaveContentEntry
* This chain is called everytime when content is saved
*
* Parameters & order:
* int idartlang idartlang (Article ID)
* string type type (e.g. CMS_HTML)
* int typeid typeid (e.g. CMS_HTML[1])
* string value value for that type
*
* Returns:
* string The processed value
*/
$_cecRegistry->registerChain("Contenido.Content.SaveContentEntry", "int", "int", "int", "string");
In diesem Fall sollte eine eigene hinzugefüge Chainfunktion 4 Parameter annehmen und den letzten zurückliefern.
Such man in den Sourcen nach der Chain "Contenido.Content.SaveContentEntry", wird man in der Datei "/contenido/includes/functions.con.php" fündig - genauer in der Funktion conSaveContentEntry(), darin wird die Chain abgearbeitet.
Da fällt mir z. B. folgende Einsatzmöglichkeit ein. Das Inlinediting von Contenido ist zwar eine wunderbare Sache, generiert aber unter IE leider HTML-Code, der nicht valide ist. Das könnte man doch sehr gut mit Tidy wieder geradebiegen, Voraussetzung ist natürlich, dass Tidy HTML als PHP-Modul verfügbar und geladen ist (Das ist aber nicht bei jedem Provider der Fall).
Erstellen eines Plugins
Erstellen wir dazu z. B. ein Plugin, legen also einen Ordner "tidy_html" in "/contenido/plugins/" sowie unter "tidy_html" noch einen Ordner "includes" an.
Code: Alles auswählen
/contenido
/plugins
/tidy_html
/includes
Code: Alles auswählen
/**
* Userdefined function, which will be added to Chain "Contenido.Content.SaveContentEntry",
* processes contents of Contenido CMS_HTML types.
*
* @param int $idartlang idartlang (con_art_lang.idartlang)
* @param string $type CMS Typ (con_type.type)
* @param int $typeid Position of CMS-Type, e. g. 5 for CMS_HTML[5]
* @param string $value The value (HTML-Code)
* @return string Processed value
*/
function myCmsHtmlCleanup($idartlang, $type, $typeid, $value) {
if ($type !== 'CMS_HTML') {
// type is not CMS_HTML, return value
return $value;
} elseif (trim($value) == '') {
// empty value should not cleaned by tidy, return value
return $value;
}
// some tidy options, like indentation and xhtml output
$options = array('indent'=>true, 'output-xhtml'=>true);
// do cleanup using tidy
$value = tidy_parse_string($value, $options);
tidy_clean_repair($value);
// result is a full XHTML page, but we need only the content extract it...
if (preg_match('~<body(.*)>(.*)<\/body>~Uis', $value, $match)) {
$value = preg_replace(array('~(<body(.*)>)~Uis', '~(<\/body>)~Uis'), '', $match[0]);
$value = trim($value);
}
// decorate value with comments to see the result
return "\n<!-- tidy -->\n" . $value . "\n<!-- /tidy -->\n";
}
Code: Alles auswählen
// get cec registry instance
$_cecRegistry = cApiCECRegistry::getInstance();
// add a function to Contenido Extension Chainer
$_cecRegistry->addChainFunction('Contenido.Content.SaveContentEntry', 'myCmsHtmlCleanup');
Zu guter letzt sollte das nun getestet werden, dafür am besten einen Artikel im inline Editingmodus bearbeiten und speichern. Das Ergebnis im Frontend sollte ein XHML-Valider sauberer Code sein.
Die war nur ein Beispiel darüber, wie einfach eine Contenidoinstallation über Contenido Extension Chainer um eigene Features erweitert werden kann.
Das Beispiel Plugin downloaden.
Grüße
xmurrix