Skip to content
Permalink
Browse files

Custom fields in CP tabs are now bound to the tabs template

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.
  • Loading branch information
slackero committed Dec 19, 2015
1 parent aad9226 commit 1bac96a52806f8a4dde49dcdcea71ab08776effa
@@ -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]
)
)
*/
)
);
@@ -72,5 +72,3 @@


$CNT_TMP .= LF.trim($crow["acontent_template"]).LF;

?>
@@ -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);

?>
@@ -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?';
@@ -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?';

@@ -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;
}
@@ -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'];
@@ -17,14 +17,10 @@
}
// ----------------------------------------------------------------



// Content Type Tabs

//$SQL .= "acontent_html="._dbEscape($content["image_html"]).", ";
$SQL .= "acontent_template="._dbEscape($content["tabs_template"]).", ";
$SQL .= "acontent_form="._dbEscape(serialize($content["tabs"])).", ";
$SQL .= "acontent_text="._dbEscape($content['search']).", ";
$SQL .= "acontent_html="._dbEscape($content['html'])." ";

?>
@@ -17,11 +17,6 @@
}
// ----------------------------------------------------------------



// Content Type Tabs

$content["tabs"] = @unserialize($row["acontent_form"]);
$content["tabs_template"] = $row["acontent_template"];

?>

0 comments on commit 1bac96a

Please sign in to comment.
You can’t perform that action at this time.