{{indexmenu_n>10}}
====== cp-trigger ======
Forum: [[http://forum.phpwcms.org/viewtopic.php?p=107107#p107107]] \\
- Autor: OG
A very simple way to implement custom functions which are pocessed each time a [[:english:phpwcms-system:article:contentparts|content part]] is parsed in phpwcms.
!!Unlike to a function running in [[:deutsch:ersetzer_rts:frontend_render|/frontend_render/]] is the purposeful processing of a content subarea. Only the cp content is processed, not the whole side contents. !!
===== Definition =====
Just take that and move the file one directory up - put it in here template/inc_script/frontend_init/.
Put in the replacement tag in your [[:english:phpwcms-system:article:contentparts|content part]]: **{CPDATE}** and check the preview link.
Custom functions have to be defined this way:
function cp_trigger_function_name($param1, & $param2) {
$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;**
And must be registered in phpwcms - just tell the system to parse it:
register_cp_trigger('cp_trigger_function_name', 'LAST');
You can also limit your function to work for special [[:english:phpwcms-system:article:contentparts|content parts]] (especially [[:english:technics:internal-function-call:content-part-types|content part types]]):
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;
}
==== TABLE phpwcms_articlecontent ====
Short description of the TABLE phpwcms_articlecontent
Some more of the fields are very specific and - yes sorry - not clear by name. It's historical and cannot be changed easy again
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
Some enhancements only
dumpVar($varname);
to get more information based on real data.
=== Content Part Types ===
Please have a look into: [[:/english/technics/internal-function-call/content-part-types|Content Part Types]]
===== 1. example: CP_IMGDIV_img_class =====
Forum: [[http://forum.phpwcms.org/viewtopic.php?p=107107#p107107]]
Add a class to an image, based on the cp image
The construction structurally is look like:
==== Method of resolution: ====
- using a trigger to **border="0"** and replace to **class="MY_CUSTOM_CLASS" border="0"** ends in this result: \\
\\
===== 2. example: CP_PLAINTEXT_P =====
The contentpart //plain text// is delivering out the content between ** ...
** tags. Depending upon planning of the side this is unfavorable in many cases. These tags can be quite simply eliminated.
function ($text, & $data) {
if($data['acontent_type'] == 0) { // 0 is CP plain text
$text = preg_match("/\(.*?)\<\/p\>/si", $text, $g) ? $g[1] : $text;
}
return $text;
}
register_cp_trigger('CP_PLAINTEXT_P');
\\
===== 3. example: CP_PLAINTEXT_P_BR =====
The contentpart //plain text// replaces several successive **
** to one **** tag. To cancel this behavior, the following trigger can be used. (Every **
** and **
** is converted into **
**).
plain text
{
$text = str_replace('', '
', $text);
$text = str_replace('
', '
', $text);
}
return $text;
}
register_cp_trigger('CP_PLAINTEXT_P_BR');
?>
\\
===== 4. example: CP_SEARCH_NO_SUMMARY =====
Using the content part //search// in search result we need only the article title without the summary.
At this moment (2009/09) a non summary output is not possible. If we insert the value zero into [results per page (summary)] it is the same as an "empty" input. -> (If empty, show all).
The standard output encloses the found summary in each case with **... Summary ...
**. Thus it is possible to search for **...
** and replace all **...
** by an empty quantity.
Forum: [[http://forum.phpwcms.org/viewtopic.php?p=120031#p120031]][DE]
and in search result
// -------------------------------------------------------------------------------------------
function CP_SEARCH_NO_SUMMARY($text, & $data) {
if( $data['acontent_type'] == 13 ) // CP: 13 => search
{
$text = preg_replace("/\(.*?)\<\/p\>/si", '', $text); // kill all
....
}
return $text;
}
register_cp_trigger('CP_SEARCH_NO_SUMMARY');
?>
\\