NAVIGATION
This is an old revision of the document!
Forum: http://forum.phpwcms.org/viewtopic.php?p=107107#p107107 - Autor: OG
Eine sehr einfache Methode um eine Benutzerfunktion einzubinden, die immer durchlaufen wird, wenn ein ContentPart geparst wird.
Datei: /template/inc_script/frontend_init/disabled/trigger_test.php
Diese Datei wird ein Verzeichnis nach oben kopiert in - /template/inc_script/frontend_init/.
Der Ersetzer Tag {CPDATE} wird im ContentPart platziert.
Benutzerfunktionen werden wie folgt definiert:
function cp_trigger_function_name($param1, & $param2) { $param1 = do_this_or_that($param2['acontent_id']); return $param1; }
Es wird immer $param1; zurückgegeben.
Die Funktion muss in phpwcms registriert werden, damit diese vom System geparst wird:
register_cp_trigger('cp_trigger_function_name', 'LAST');
Die Funktion kann auch auf einen speziellen ContentPart (siehe ContentPart -Typen) begrenzt werden:
function cp_trigger_function_name($param1, & $param2) { if($param2['acontent_type'] == 14) { // 14 is CP WYSIWYG $param1 = do_this_or_that($param2['acontent_id']); } return $param1; }
Kurze Beschreibung der Tabelle phpwcms_articlecontent
Einiger der Felder sind sehr speziell. Leider ist die Namensgebung historisch bedingt nicht immer eindeutig.
acontent_id auto increment unique ID acontent_aid ID of parent article acontent_uid ID of the user has saved CP at last acontent_created Date: CP created, MySQL date format acontent_tstamp Date: CP updated, MySQL date format acontent_title Title text acontent_text Plain Text (in general) acontent_type Type of the Cntent Part - look at include/inc_lib/article.contenttype.inc.php acontent_sorting sort value: [value] acontent_image Holds image information (older CP) acontent_files Hold file information (older CP) acontent_visible Visible [0/1] acontent_subtitle Subtitle text acontent_before Space: before [value] acontent_after Space: after [value] acontent_top Top anchor jump [0/1] acontent_redirect can hold an URL (cannot remember at the moment) acontent_html also Text, can be HTML styled text but also other texts acontent_trash 0= available 9= trash acontent_alink Also older CP - article link acontent_media CP Multimedia information acontent_form more complex - current CPs store serialized infos there acontent_newsletter ?? (mediumtext) acontent_block display: e.g. [Content] - in general empty mean main block acontent_anchor anchor: [0/1] acontent_template template filename if there acontent_spacer ?? (int(1)) acontent_tid ?? (int(11)) acontent_livedate Livedate (not in use ??) acontent_killdate Killdate (not in use ??) acontent_module Module name acontent_comment notes: [value] acontent_paginate_page Paginate subsection: [value] acontent_paginate_title subsection title: [value] acontent_category ?? acontent_granted if set [0/1] visible for logged-in users only
Als Hilfe kann der Aufruf der integrierten Funktion dumpVar($varname); dienen um mehr Imformationen über die tatsächlichen Daten zu erhalten.
Bitte schaue dir folgendes an: ContentPart-Typen
Forum: http://forum.phpwcms.org/viewtopic.php?p=107107#p107107
Eine Klasse zu einem Bild hinzuzufügen, das aus dem CP Bilder <div> generiert wird. Gegeben ist diese Ausgabe:
<img src="content/images/xyz.jpg" alt="Alt-Text" title="Titel-Text" **border="0"** width="120" height="90">
Die Konstruktion soll strukturell etwa so aussehen:
<img CLASS="MY_CUSTOM_CLASS" src="content/images/xyz.jpg ...."
- mit einem Trigger auf border=“0” und Ersetzung nach class=“MY_CUSTOM_CLASS” border=“0” ergibt:
<img src="content/images/xyz.jpg" alt="Alt-Text" title="Titel-Text" **class="MY_CUSTOM_CLASS" border="0"** width="120" height="90">
Der Ersetzer:
/template/inc_script/frontend_init/rt_cp_trigger.php
<?php // http://forum.phpwcms.org/viewtopic.php?p=107107#p107107 /* ------------------------------------------------------------------ function cp_trigger_function_name($param1, & $param2) { if($param2['acontent_type'] == 14) { // 14 is CP WYSIWYG $param1 = do_this_or_that($param2['acontent_id']); } return $param1; } * cp_trigger_function_name - the unique function name * $param1 - holds the content part html source on which you can parse or do custom processing * $param2 - is a reference to an array which holds content part values like ID, dates and other values - see db table phpwcms_articlecontent Always return $param1; */ // ------------------------------------------------------------------ // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------ function CP_IMGDIV_img_class($text, & $data) { if($data['acontent_type'] == 29) { // 29 is CP img div $text = preg_replace('/border="0"/i', 'border="0" class="MY_CUSTOM_CLASS"', $text); } return $text; } register_cp_trigger('CP_IMGDIV_img_class'); /* ------- and the next one function CP_Other_CP($text, & $data) { if($data['acontent_type'] == XX) { // XX is CP Other CP $text = custom processing ; } return $text; } register_cp_trigger('CP_Other_CP'); ---------- and so on */ ?>
Der Contentpart Einfacher Text/plain text liefert seinen Inhalt zwischen <p> … </p> Tags aus. Je nach Planung der Seite ist dies in vielen Fällen ungünstig. Diese Tags können jedoch recht einfach beseitigt werden.
function CP_PLAINTEXT_P($text, & $data) { if($data['acontent_type'] == 0) { // 0 is CP plain text $text = preg_match("/\<p\>(.*?)\<\/p\>/si", $text, $g) ? $g[1] : $text; } return $text; } register_cp_trigger('CP_PLAINTEXT_P');
Der Contentpart Einfacher Text/plain text ersetzt mehrere aufeinanderfolgende <br /> <br /> in einen einleitenden <p> Tag. Um dieses Verhalten rückgängig zu machen kann der nachfolgende Trigger verwendet werden. (Wandelt alle <p> und </p> in <br /> um).
<?php // ------------------------------------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------------------------------- function CP_PLAINTEXT_P_BR($text, & $data) { if( $data['acontent_type'] == 0 ) // CP: 0 => plain text { $text = str_replace('<p>', '<br />', $text); $text = str_replace('</p>', '<br />', $text); } return $text; } register_cp_trigger('CP_PLAINTEXT_P_BR'); ?>
Bei der Verwendung der CPs Bilder <div> und Bilder Spezial soll der Captiontext (Bildunterzeile) in der einfachen FE-Ausgabe gekürzt werden. In der LightBox bleibt der Text vorhanden.
Angenommener Templateeintrag:
[CAPTION]<p style="margin:3px 0 0 0; width:200px; height:15px;"><span class="cut_caption">{CAPTION}</span></p>[/CAPTION] [CAPTION_ELSE]<p>{IMGNAME}</p>[/CAPTION_ELSE]
Es wird auf die Zeichenfolge <span class=“cut_caption”> Caption-Text </span> getriggert.
Caption-Text wird somit separiert, ausgelesen und verarbeitet.
Die Stelle <span …> …. </span> wird mit dem Ergebnis überschrieben.
In diesem Beispiel werden die Zeichen substr('$1', 0, 8) von Position 0 bis 8 ausgeschnitten und zurückgegeben.
Ergebnis: Yes We Can do many things with this cms → Yes We C
<?php // ------------------------------------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------------------------------- // Cutting the caption text in FE output (substr('$1', 0, 8) = cutting out charakter 0 to 8) // K.Heermann (flip-flop) 17.05.09 /* * cp_trigger_function_name - the unique function name * $text - holds the content part html source on which you can parse or do custom processing * $data - is a reference to an array which holds content part values like ID, dates and other values - see db table phpwcms_articlecontent Always return $text; */ /* e.g. Template ------------------------------------------------------------- [CAPTION]<p style="margin:3px 0 0 0; width:200px; height:15px;"><span class="cut_caption">{CAPTION}</span></p>[/CAPTION] [CAPTION_ELSE]<p>{IMGNAME}</p>[/CAPTION_ELSE] ----------------------------------------------------------------------------- */ function CP_CUT_CAPTION_TEXT($text, & $data) { // CPs: 29 => image <div>, 31 => image special if ( $data['acontent_type'] == 29 OR $data['acontent_type'] == 31 ) { $text = preg_replace("/<span class=\"cut_caption\">(.*?)<\/span>/e","substr('$1', 0, 8).' ...'" , $text); // First word in string // $text = preg_replace("/<span class=\"cut_caption\">(.*?)<\/span>/e","substr('$1', 0, strpos('$1', ' ')).' ...'" , $text); } return $text; } register_cp_trigger('CP_CUT_CAPTION_TEXT'); ?>
Bei der Verwendung der CPs Bilder <div> und Bilder Spezial soll der Captiontext (Bildunterzeile) in der einfachen FE-Ausgabe gekürzt werden. In der LightBox bleibt der Text vorhanden.
Angenommener Templateeintrag:
[CAPTION]<p style="margin:3px 0 0 0; width:200px; height:15px;"><span class="cut_caption-c20-w3">{CAPTION}</span></p>[/CAPTION] [CAPTION_ELSE]<p>{IMGNAME}</p>[/CAPTION_ELSE]
Es wird auf die Zeichenfolge <span class=“cut_caption-c20-w3”> Caption-Text </span> getriggert.
Caption-Text wird somit separiert, ausgelesen und verarbeitet.
V1.1.1: Zusätlich werden die Parameter in cut_caption-c20-w3 getriggert und verarbeitet.
Werden beide Parameter angegeben, gilt folgendes: Ist der String “XX Worte” im Modus [word] länger als max. Zeichen in -cXX angegeben, wird autom. auf den Modus [char] umgeschaltet.
Die Stelle <span …> …. </span> wird mit dem Ergebnis überschrieben.
In diesem Beispiel würden die ersten drei Worte ausgegeben wenn vorhanden oder falls der Wortstring länger als 20 Zeichen sein sollte, diese ausgegeben.
Templateaufruf: <span class=“cut_caption-c20-w3”>.
Gegeben: Yes We Can do many things with this cms
Ergebnis: Yes We Can …
<span class=“cut_caption-c8-w6”>
Gegeben: Yes We Can do many things with this cms
Ergebnis: Yes We C …
<span class=“cut_caption-w6”>
Gegeben: Yes We Can do many things with this cms
Ergebnis: Yes We Can do many things …
// ------------------------------------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------------------------------- // Cutting the caption text in FE output V1.1.1 // K.Heermann (flip-flop) 18.05.09 /* * cp_trigger_function_name - the unique function name * $text - holds the content part html source on which you can parse or do custom processing * $data - is a reference to an array which holds content part values like ID, dates and other values - see db table phpwcms_articlecontent Always return $text; */ /* e.g. Template ------------------------------------------------------------- [CAPTION]<p style="margin:3px 0 0 0; width:200px; height:15px;"><span class="cut_caption-c20-w3">{CAPTION}</span></p>[/CAPTION] [CAPTION_ELSE]<p>{IMGNAME}</p>[/CAPTION_ELSE] ----------------------------------------------------------------------------- */ /* ----------------------------------------------------------------------------- [$text=whole string] [$param=mode e.g. -c20-w3] -cX = max characters to show -wX = max words to show (if word string > max charakters, max.char is used) Yes, I know the php function str_word_count, but there is a problem with utf-8 Sonderzeichen like ä, ü, ö .... ----------------------------------------------------------------------------- */ function String_Word_Limiter($text, $param=''){ // Default, if there is no parameter from client $max_char = 100; $limit_word = 4; $prio_char_word = 'char'; if (!empty($text) ) { // parameter set by user ? $string = $text; // Yes and save $param = strtolower($param); // convert all to lower char $_param = explode('-',$param); // Cut out all parameters $_param[1] - [2] foreach ($_param as $key=>$value) { // Cutting out and allocate the parameters if (substr($value, 0, 1) == 'c') { $max_char = substr($value, 1); $prio_char_word = 'char'; } elseif (substr($value, 0, 1) == 'w') { $limit_word = substr($value, 1); $prio_char_word = 'word'; } } } else { // No parameter set by user $string = $param; } if ($prio_char_word == 'word') { // Is it the word mode? $explode = explode(' ',$text); // Cut out all words $string = ''; for($i=0; $i<$limit_word; $i++){ // Generate the new word string $string .= $explode[$i]." "; } // Fallback, if word string is too lang if (strlen($string) > $max_char ) $string = substr($text, 0, $max_char); } // It is the Charakter mode else $string = substr($text, 0, $max_char); $dots = (strlen($text) > strlen($string) ) ? ' ...' : ''; // Dots set return $string.$dots; } // ---------------------------------------------------------------------------- function CP_CUT_CAPTION_TEXT($text, & $data) { // CPs: 29 => image <div>, 31 => image special if(($data['acontent_type'] == 29 OR $data['acontent_type'] == 31)) { //<span class="cut_caption">Caption-Text</span> // $1 = -c20-w4 // e.g. <span class="cut_caption-c20-w4">Caption-Text</span> $search = "/<span class=\"cut_caption(.*?)\">(.*?)<\/span>/e"; $replace = "String_Word_Limiter('$2','$1')"; $text = preg_replace($search,$replace , $text); } return $text; } register_cp_trigger('CP_CUT_CAPTION_TEXT');