From 867076ef5450fe18252274f9cda1578e7cf00f86 Mon Sep 17 00:00:00 2001 From: John Rayes Date: Thu, 25 Mar 2021 10:53:05 -0700 Subject: [PATCH] fix: Translate old field names so they can actually be used --- src/Class-CustomForm.php | 21 ++++++++++++++-- src/CustomForm.english.php | 1 + src/CustomForm.php | 16 +++++++++++-- src/ManageCustomForm.php | 49 ++++++++++++++++++++------------------ 4 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/Class-CustomForm.php b/src/Class-CustomForm.php index 3e675b7..3a9580b 100644 --- a/src/Class-CustomForm.php +++ b/src/Class-CustomForm.php @@ -118,14 +118,31 @@ public function setOptions() } } +class CustomForm_info extends CustomFormBase +{ + public function setHtml() + { + $this->input_html = $this->getValue(); + $this->output_html = ''; + } + public function validate(): bool + { + return true; + } + public function getValue(): string + { + return $this->value; + } +} + class CustomForm_check extends CustomFormBase { public function setHtml() { global $txt; $true = (!$this->exists && $this->default) || $this->value; - $this->input_html .= sprintf( - '', + $this->input_html = sprintf( + '', 'CustomFormField', $this->field['id_field'], $true ? ' checked' : '' diff --git a/src/CustomForm.english.php b/src/CustomForm.english.php index 31faecc..df6e6da 100644 --- a/src/CustomForm.english.php +++ b/src/CustomForm.english.php @@ -59,6 +59,7 @@ $txt['customform_type_select'] = 'Select Box'; $txt['customform_type_radio'] = 'Radio Buttons'; $txt['customform_type_check'] = 'Checkbox'; +$txt['customform_type_info'] = 'Information'; $txt['customform_max_length'] = 'Maximum Length'; $txt['customform_max_length_desc'] = '(0 for no limit)'; $txt['customform_dimension'] = 'Dimensions'; diff --git a/src/CustomForm.php b/src/CustomForm.php index 849d105..988dfb3 100644 --- a/src/CustomForm.php +++ b/src/CustomForm.php @@ -84,7 +84,19 @@ function CustomForm() $data = array(); // Get all of data from the db query. while ($row = $smcFunc['db_fetch_assoc']($request)) + { + $row['type2'] = strtr($row['type'], [ + 'largetextbox' =>'textarea', + 'textbox' =>'text', + 'checkbox' =>'check', + 'selectbox' =>'select', + 'float' =>'text', + 'int' =>'text', + 'radiobox' =>'radio', + 'infobox' =>'info' + ]); $data[] = $row; + } // Free the db request. $smcFunc['db_free_result']($request); @@ -180,9 +192,9 @@ function CustomForm() foreach ($data as $field) { $value = isset($_POST['CustomFormField'][$field['id_field']]) ? $_POST['CustomFormField'][$field['id_field']] : ''; - $class_name = 'CustomForm_' . $field['type']; + $class_name = 'CustomForm_' . $field['type2']; if (!class_exists($class_name)) - fatal_error('Param "' . $field['type'] . '" not found for field "' . $field['text'] . '" at ID #' . $field['id_field'] . '.', false); + fatal_error('Param "' . $field['type2'] . '" not found for field "' . $field['text'] . '" at ID #' . $field['id_field'] . '.', false); $type = new $class_name($field, $value, !empty($value)); $type->setOptions(); diff --git a/src/ManageCustomForm.php b/src/ManageCustomForm.php index 609f3e3..1df4384 100644 --- a/src/ManageCustomForm.php +++ b/src/ManageCustomForm.php @@ -493,7 +493,16 @@ function ModifyCustomFormSettings($return_config = false) array( 'select', 'field_type', - 'value' => $data['type'], + 'value' => strtr($data['type'], [ + 'largetextbox' =>'textarea', + 'textbox' =>'text', + 'checkbox' =>'check', + 'selectbox' =>'select', + 'float' =>'text', + 'int' =>'text', + 'radiobox' =>'radio', + 'infobox' =>'info' + ]), 'text_label' => $txt['customform_type'], 'help' => 'customform_type', $result @@ -708,7 +717,7 @@ function list_CustomForms() // Fucntion to produce a list of custom form fields. function list_customform_fields($nul0, $nul1, $nul2, $id) { - global $txt, $scripturl, $smcFunc; + global $txt, $scripturl, $sourcedir, $smcFunc; // Get the data from the cf_fields table. $request = $smcFunc['db_query']( @@ -732,32 +741,26 @@ function list_customform_fields($nul0, $nul1, $nul2, $id) $i = 1; $end = count($data); - // Go through every field. + require_once($sourcedir . '/Class-CustomForm.php'); + $result = []; + foreach (customform_list_classes() as $cn) + $result[$cn] = $txt['customform_type_' . $cn]; + $result += [ + 'largetextbox' =>$result['textarea'], + 'textbox' =>$result['text'], + 'checkbox' =>$result['check'], + 'selectbox' =>$result['select'], + 'float' =>$result['text'], + 'int' =>$result['text'], + 'radiobox' =>$result['radio'], + 'infobox' =>$result['info'] + ]; foreach ($data as $field) { - // Convert the field type into the proper text strings. - $type = str_replace( - // Search array. - array('largetextbox', 'textbox', 'checkbox', 'selectbox', 'float', 'int', 'radiobox', 'infobox'), - // Replace array. - array( - $txt['customform_large_textbox'], - $txt['customform_textbox'], - $txt['customform_checkbox'], - $txt['customform_selectionbox'], - $txt['customform_float'], - $txt['customform_int'], - $txt['customform_radiobox'], - $txt['customform_infoboxa'], - ), - $field['type'] - ); - - // Add the current entry into the list. $list[] = array( 'title' => $field['title'], 'text' => $field['text'], - 'type' => $type, + 'type' => $result[$field['type']]??$field['type'], 'modify' => '