From 1bac96a52806f8a4dde49dcdcea71ab08776effa Mon Sep 17 00:00:00 2001 From: Oliver Georgi Date: Sat, 19 Dec 2015 21:02:43 +0100 Subject: [PATCH] Custom fields in CP tabs are now bound to the tabs template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New field options: type can be str or textarea, set maxlength or rows and define how the field should render in frontend: markdown, html (as is) or plain — everything else will be html encoded. --- include/config/conf.template_default.inc.php | 12 +- .../inc_front/content/cnt0.article.inc.php | 2 - .../inc_front/content/cnt32.article.inc.php | 60 +++--- include/inc_lang/backend/de/lang.inc.php | 1 + include/inc_lang/backend/en/lang.inc.php | 2 + include/inc_lib/backend.functions.inc.php | 20 ++ .../inc_lib/content/cnt32.readform.inc.php | 14 +- include/inc_lib/content/cnt32.sql.inc.php | 4 - include/inc_lib/content/cnt32.takeval.inc.php | 5 - include/inc_tmpl/content/cnt32.inc.php | 182 +++++++++++++----- include/inc_tmpl/content/cnt32.list.inc.php | 14 +- template/inc_default/tabs.tmpl | 14 +- 12 files changed, 221 insertions(+), 109 deletions(-) diff --git a/include/config/conf.template_default.inc.php b/include/config/conf.template_default.inc.php index 37b2d1c6c..400d5dae4 100644 --- a/include/config/conf.template_default.inc.php +++ b/include/config/conf.template_default.inc.php @@ -440,7 +440,15 @@ 'tabs_custom_fields' => array( // Enable and customise to enable additional tab input fields: - // 'fieldname1' => 'legend', // [TAB_FIELDNAME1]{TAB_FIELDNAME1}[/TAB_FIELDNAME1] - // 'fieldname2_html'=>'legend not html encoded' // [TAB_FIELDNAME2]{TAB_FIELDNAME2}[/TAB_FIELDNAME2] + /* + 'fieldgroup1' => array( + 'legend' => 'Field group name', + 'template' => 'default', // bind the fieldgroup to a specific template, or default + 'fields' => array( + 'fieldname1' => array('legend' => 'field 1', 'type' => 'str', 'render' => 'html', 'maxlength' => 100), // [TAB_FIELDNAME1]{TAB_FIELDNAME1}[/TAB_FIELDNAME1] + 'fieldname2' => array('legend' => 'field 2', 'type' => 'textarea', 'render' => '', 'rows' => 3), // [TAB_FIELDNAME2]{TAB_FIELDNAME2}[/TAB_FIELDNAME2] + ) + ) + */ ) ); diff --git a/include/inc_front/content/cnt0.article.inc.php b/include/inc_front/content/cnt0.article.inc.php index 4c9b52381..a35b99dd8 100644 --- a/include/inc_front/content/cnt0.article.inc.php +++ b/include/inc_front/content/cnt0.article.inc.php @@ -72,5 +72,3 @@ $CNT_TMP .= LF.trim($crow["acontent_template"]).LF; - -?> \ No newline at end of file diff --git a/include/inc_front/content/cnt32.article.inc.php b/include/inc_front/content/cnt32.article.inc.php index 9ee475be6..9d38a7680 100644 --- a/include/inc_front/content/cnt32.article.inc.php +++ b/include/inc_front/content/cnt32.article.inc.php @@ -23,6 +23,9 @@ $tabs['tabs'] = @unserialize($crow["acontent_form"]); unset($tabs['tabs']['tabwysiwygoff']); +$tabs['tab_fieldgroup'] = empty($tabs['tabs']['tab_fieldgroup']) ? '' : $tabs['tabs']['tab_fieldgroup']; +unset($tabs['tabs']['tab_fieldgroup']); + // read template if(empty($crow["acontent_template"]) && is_file(PHPWCMS_TEMPLATE.'inc_default/tabs.tmpl')) { @@ -40,11 +43,18 @@ if($tabs['template']) { - $tabs['entries'] = array(); + $tabs['entries'] = array(); + + $tabs['tmpl_entry'] = get_tmpl_section('TABS_ENTRY', $tabs['template']); + $tabs['template'] = get_tmpl_section('TABS', $tabs['template']); - $tabs['tmpl_entry'] = get_tmpl_section('TABS_ENTRY', $tabs['template']); - $tabs['template'] = get_tmpl_section('TABS', $tabs['template']); - $tabs['custom_tab_fields'] = empty($template_default['settings']['tabs_custom_fields']) ? array() : array_keys($template_default['settings']['tabs_custom_fields']); + if($tabs['tab_fieldgroup'] === '' || empty($template_default['settings']['tabs_custom_fields'][ $tabs['tab_fieldgroup'] ]['fields'])) { + $tabs['custom_tab_fields'] = array(); + } else { + $tabs['custom_tab_fields'] = array_keys($template_default['settings']['tabs_custom_fields'][ $tabs['tab_fieldgroup'] ]['fields']); + $tabs['field_render'] = array('html', 'markdown', 'plain'); + $tabs['fieldgroup'] =& $template_default['settings']['tabs_custom_fields'][ $tabs['tab_fieldgroup'] ]; + } foreach($tabs['tabs'] as $key => $entry) { @@ -61,27 +71,29 @@ $tabs['entries'][$key] = str_replace('{TARGET}', $entry['tablink']['target'], $tabs['entries'][$key]); } - if(!empty($entry['custom_fields']) && count($entry['custom_fields'])) { - - if(count($tabs['custom_tab_fields'])) { - $tabs['custom_field_items'] = array_unique( array_merge($tabs['custom_tab_fields'], array_keys($entry['custom_fields'])) ); - } else { - $tabs['custom_field_items'] = array_keys($entry['custom_fields']); - } - - } else { - - $tabs['custom_field_items'] = $tabs['custom_tab_fields']; - - } - - if($tabs['custom_field_items']) { - foreach($tabs['custom_field_items'] as $custom_field_key) { + if($tabs['custom_tab_fields']) { + foreach($tabs['custom_tab_fields'] as $custom_field_key) { $custom_field_value = isset($entry['custom_fields'][$custom_field_key]) ? $entry['custom_fields'][$custom_field_key] : ''; $custom_field_key = 'TAB_'.strtoupper($custom_field_key); - if(substr($custom_field_key, -5) === '_HTML') { - $custom_field_key = substr($custom_field_key, 0, -5); - $tabs['entries'][$key] = render_cnt_template($tabs['entries'][$key], $custom_field_key, $custom_field_value); + + if($custom_field_value === '') { + render_cnt_template($tabs['entries'][$key], $custom_field_key, ''); + continue; + } + + if(isset($tabs['fieldgroup'][$custom_field_key]['render']) && in_array($tabs['fieldgroup'][$custom_field_key]['render'], $tabs['field_render'])) { + if($tabs['fieldgroup'][$custom_field_key]['render'] === 'markdown') { + if(!isset($phpwcms['parsedown_class'])) { + require_once(PHPWCMS_ROOT.'/include/inc_ext/parsedown/Parsedown.php'); + require_once(PHPWCMS_ROOT.'/include/inc_ext/parsedown-extra/ParsedownExtra.php'); + $phpwcms['parsedown_class'] = new ParsedownExtra(); + } + $tabs['entries'][$key] = render_cnt_template($tabs['entries'][$key], $custom_field_key, $phpwcms['parsedown_class']->text($custom_field_value)); + } elseif($tabs['fieldgroup'][$custom_field_key]['render'] === 'plain') { + $tabs['entries'][$key] = render_cnt_template($tabs['entries'][$key], $custom_field_key, plaintext_htmlencode($custom_field_value)); + } else { + render_cnt_template($tabs['entries'][$key], $custom_field_key, $custom_field_value); + } } else { $tabs['entries'][$key] = render_cnt_template($tabs['entries'][$key], $custom_field_key, html($custom_field_value)); } @@ -105,5 +117,3 @@ } unset($tabs); - -?> \ No newline at end of file diff --git a/include/inc_lang/backend/de/lang.inc.php b/include/inc_lang/backend/de/lang.inc.php index bc68552a0..309216ed0 100644 --- a/include/inc_lang/backend/de/lang.inc.php +++ b/include/inc_lang/backend/de/lang.inc.php @@ -1398,3 +1398,4 @@ $BL['be_fsearch_nor'] = 'KEINES'; $BL['be_tab_toggle'] = 'Reiter aus- bzw. einklappen'; $BL['be_custom_textfield'] = 'Freitext'; +$BL['be_tab_template_toggle_warning'] = 'Wenn Sie die Vorlage umstellen, kann passieren, dass sich die Freitextfelder ändern und Werte verloren gehen.\n\nMöchten Sie wirklich fortfahren?'; diff --git a/include/inc_lang/backend/en/lang.inc.php b/include/inc_lang/backend/en/lang.inc.php index 52803c8a8..777228ad5 100644 --- a/include/inc_lang/backend/en/lang.inc.php +++ b/include/inc_lang/backend/en/lang.inc.php @@ -1407,3 +1407,5 @@ $BL['be_fsearch_nor'] = 'NONE'; $BL['be_tab_toggle'] = 'Toggle tab to expanded or closed'; $BL['be_custom_textfield'] = 'custom text'; +$BL['be_tab_template_toggle_warning'] = 'Changing the template can have the effect that custom fields get changed too and existing values get lost.\n\nAre you really sure to continue?'; + diff --git a/include/inc_lib/backend.functions.inc.php b/include/inc_lib/backend.functions.inc.php index b0172f023..3106ea241 100644 --- a/include/inc_lib/backend.functions.inc.php +++ b/include/inc_lib/backend.functions.inc.php @@ -1307,3 +1307,23 @@ function get_struct_alias($start_id=0, $parent_alias=false) { return implode($GLOBALS['phpwcms']['alias_allow_slash'] ? '/' : '-', array_reverse($data)); } + + +/** + * Correct the text in case phpwcms charset is different from UTF-8 + * + * @access public + * @param string $text + * @param bool $js (default: false) + * @return void + */ +function correct_charset($text='', $js=false) { + + if(PHPWCMS_CHARSET !== 'utf-8' && phpwcms_seems_utf8($text)) { + $text = utf8_decode($text); + } + if($js) { + $text = str_replace("'", "\'", $text); + } + return $text; +} \ No newline at end of file diff --git a/include/inc_lib/content/cnt32.readform.inc.php b/include/inc_lib/content/cnt32.readform.inc.php index ce2adbf63..521a3f702 100644 --- a/include/inc_lib/content/cnt32.readform.inc.php +++ b/include/inc_lib/content/cnt32.readform.inc.php @@ -25,6 +25,17 @@ $content['html'] = array(); $content['tabwysiwygoff'] = empty($_POST['tabwysiwygoff']) ? 0 : 1; +$tab_fieldgroup_fields = null; +$tab_fieldgroup_field_render = array('html', 'markdown'); +if(empty($_POST['tab_fieldgroup'])) { + $content['tab_fieldgroup'] = ''; +} else { + $content['tab_fieldgroup'] = clean_slweg($_POST['tab_fieldgroup']); + if(isset($template_default['settings']['tabs_custom_fields'][ $content['tab_fieldgroup'] ]['fields'])) { + $tab_fieldgroup_fields =& $template_default['settings']['tabs_custom_fields'][ $content['tab_fieldgroup'] ]['fields']; + } +} + // get all tabs if(isset($_POST['tabtitle']) && is_array($_POST['tabtitle']) && count($_POST['tabtitle'])) { @@ -44,7 +55,7 @@ if(!empty($_POST['customfield'][$key]) && count($_POST['customfield'][$key])) { foreach($_POST['customfield'][$key] as $custom_field => $custom_field_value) { - if(substr(strtolower($custom_field), -5) === '_html') { + if($tab_fieldgroup_fields !== null && isset($tab_fieldgroup_fields[$custom_field]['render']) && in_array($tab_fieldgroup_fields[$custom_field]['render'], $tab_fieldgroup_field_render)) { $content["tabs"][$x]['custom_fields'][$custom_field] = slweg($custom_field_value); } else { $content["tabs"][$x]['custom_fields'][$custom_field] = clean_slweg($custom_field_value); @@ -84,3 +95,4 @@ } $content['tabs']['tabwysiwygoff'] = $content['tabwysiwygoff']; +$content['tabs']['tab_fieldgroup'] = $content['tab_fieldgroup']; diff --git a/include/inc_lib/content/cnt32.sql.inc.php b/include/inc_lib/content/cnt32.sql.inc.php index 2277e6ae2..4192d619a 100644 --- a/include/inc_lib/content/cnt32.sql.inc.php +++ b/include/inc_lib/content/cnt32.sql.inc.php @@ -17,8 +17,6 @@ } // ---------------------------------------------------------------- - - // Content Type Tabs //$SQL .= "acontent_html="._dbEscape($content["image_html"]).", "; @@ -26,5 +24,3 @@ $SQL .= "acontent_form="._dbEscape(serialize($content["tabs"])).", "; $SQL .= "acontent_text="._dbEscape($content['search']).", "; $SQL .= "acontent_html="._dbEscape($content['html'])." "; - -?> \ No newline at end of file diff --git a/include/inc_lib/content/cnt32.takeval.inc.php b/include/inc_lib/content/cnt32.takeval.inc.php index 3fd32bea7..8a4ff66dd 100644 --- a/include/inc_lib/content/cnt32.takeval.inc.php +++ b/include/inc_lib/content/cnt32.takeval.inc.php @@ -17,11 +17,6 @@ } // ---------------------------------------------------------------- - - // Content Type Tabs - $content["tabs"] = @unserialize($row["acontent_form"]); $content["tabs_template"] = $row["acontent_template"]; - -?> \ No newline at end of file diff --git a/include/inc_tmpl/content/cnt32.inc.php b/include/inc_tmpl/content/cnt32.inc.php index 0e1b63895..c6670eb60 100644 --- a/include/inc_tmpl/content/cnt32.inc.php +++ b/include/inc_tmpl/content/cnt32.inc.php @@ -24,7 +24,7 @@ $content['tabs'] = array(); } $content['tabwysiwygoff'] = empty($content['tabs']['tabwysiwygoff']) ? 0 : 1; -unset($content['tabs']['tabwysiwygoff']); +unset($content['tabs']['tabwysiwygoff'], $content['tabs']['tab_fieldgroup']); // check which WYSIWYG editor to load // only FCKeditor is supported here @@ -36,35 +36,55 @@ $content['wysiwyg'] = false; } -?> +$tab_fieldgroup_templates = array(); +if(isset($template_default['settings']['tabs_custom_fields']) && is_array($template_default['settings']['tabs_custom_fields']) && count($template_default['settings']['tabs_custom_fields'])) { + $tab_fieldgroups = $template_default['settings']['tabs_custom_fields']; + foreach($template_default['settings']['tabs_custom_fields'] as $key => $tab_fieldgroup) { + $tab_fieldgroup_templates[ $tab_fieldgroup['template'] ] = $key; + } +} else { + $tab_fieldgroups = array(); +} - +$tab_template_options = ''; - - :  - - - + $val = html($val); + $tab_template_options .= ''; + } - +} -
+?> + + + :  + + + @@ -91,13 +111,20 @@ // Sort/Up Down Title $sort_up_down = $BL['be_func_struct_sort_up'] . ' / '. $BL['be_func_struct_sort_down']; - if(isset($template_default['settings']['tabs_custom_fields']) && is_array($template_default['settings']['tabs_custom_fields']) && count($template_default['settings']['tabs_custom_fields'])) { - $custom_tab_fields = array_keys($template_default['settings']['tabs_custom_fields']); + if($tab_fieldgroups_active && isset($template_default['settings']['tabs_custom_fields'][$tab_fieldgroups_active])) { + $tab_fieldgroup =& $template_default['settings']['tabs_custom_fields'][$tab_fieldgroups_active]; + } else { + $tab_fieldgroup = null; + } + if($tab_fieldgroup !== null && isset($tab_fieldgroup['fields']) && is_array($tab_fieldgroup['fields']) && count($tab_fieldgroup['fields'])) { + $custom_tab_fields = array_keys($tab_fieldgroup['fields']); } else { $custom_tab_fields = array(); + $tab_fieldgroup = null; } $value['custom_field_items'] = $custom_tab_fields; + $custom_tab_fields_hidden = array(); if(!empty($content['tabs'])): foreach($content['tabs'] as $key => $value): @@ -111,10 +138,9 @@ } } else { - $value['custom_field_items'] = $custom_tab_fields; - } + ?>
  • @@ -142,21 +168,44 @@ $custom_field): + + // send fields not defined as hidden values, should ensure not loosing values + if(!isset($tab_fieldgroup['fields'][$custom_field]) && isset($value['custom_fields'][$custom_field])) { + // do not store if the value is an empty string + if($value['custom_fields'][$custom_field] !== '') { + $custom_tab_fields_hidden[] = ''; + } + continue; + } ?> - - + ?>" maxlength="" + class="v11 width400" /> + + + + - \ No newline at end of file diff --git a/include/inc_tmpl/content/cnt32.list.inc.php b/include/inc_tmpl/content/cnt32.list.inc.php index b1635976e..571708e21 100644 --- a/include/inc_tmpl/content/cnt32.list.inc.php +++ b/include/inc_tmpl/content/cnt32.list.inc.php @@ -24,23 +24,21 @@ $cinfo["result"] .= $row["acontent_subtitle"] ? cut_string($row["acontent_subtitle"],'…', 55) : ''; $row["acontent_form"] = @unserialize($row["acontent_form"]); -unset($row['acontent_form']['tabwysiwygoff']); +unset($row['acontent_form']['tabwysiwygoff'], $row['acontent_form']['tab_fieldgroup']); if($cinfo["result"] || count($row["acontent_form"])) { echo ""; } - -?> \ No newline at end of file diff --git a/template/inc_default/tabs.tmpl b/template/inc_default/tabs.tmpl index e2136ddcd..d6d819946 100644 --- a/template/inc_default/tabs.tmpl +++ b/template/inc_default/tabs.tmpl @@ -12,18 +12,12 @@ [TABHEADLINE]

    {TABHEADLINE}

    [/TABHEADLINE] [TABTEXT]{TABTEXT}[/TABTEXT] [TABLINK]

    @@read more@@

    [/TABLINK] - - [TAB_VALUE1]

    {TAB_VALUE1}

    [/TAB_VALUE1] - [TAB_VALUE2]

    {TAB_VALUE2}

    [/TAB_VALUE2] - [TAB_VALUE3]{TAB_VALUE3}[/TAB_VALUE3] - [/TABCONTENT] \ No newline at end of file
         + +
     "; echo ''; echo $cinfo["result"]; - + $cinfo["result"] = trim($cinfo["result"]) ? '
    ' : ''; - + foreach($row["acontent_form"] as $value) { - + echo $cinfo["result"] . '» '.html($value['tabtitle'].($value['tabheadline'] != '' ? ' - '.$value['tabheadline'] : '')); $cinfo["result"] = '
    '; - + } - + echo "