{\r
$res = [];\r
foreach ($this as $k => $v) {\r
- $res[$k]=$v;\r
+ $res[$k] = $v;\r
}\r
return $res;\r
}\r
return $v;\r
}\r
\r
+ public function generateV3Form($tab = false)\r
+ {\r
+ ob_end_clean();\r
+ header('Content-type: text/plain');\r
+\r
+\r
+ echo ' public function setSettingsFields()\r
+ {\r
+ ';\r
+ foreach ($this->forms as $formname => $form) {\r
+ if ($tab !== 'form') {\r
+ echo $this->generateV3Field(['name' => 'section_' . $formname, 'type' => 'FormSection', 'label' => $form['label']]);\r
+ $_tab = $tab;\r
+ } else {\r
+ $_tab = $form['label'];\r
+ }\r
+ foreach ($form['fieldsnames'] as $fieldsname) {\r
+ if ($fieldsname === '|') {\r
+ echo $this->generateV3Field(['type' => 'FormSeparator'], $_tab);\r
+ continue;\r
+ }\r
+ $f = $this->fields[$fieldsname];\r
+ echo $this->_generateV3Field($fieldsname, $f, $_tab);\r
+ }\r
+ }\r
+\r
+ echo "\n}";\r
+ exit;\r
+ }\r
+\r
+ public function generateV3Field($attributes, $tab = false)\r
+ {\r
+ if ($tab && !isset($attributes['tab'])) {\r
+ $attributes['tab'] = '§!§' . $tab . '!§!';\r
+ }\r
+ $res = " ";\r
+ $res .= '$this->addField(' . $this->_varexport($attributes, true) . ');';\r
+ $res .= "\n";\r
+\r
+ $res = str_replace("'§!§", '__(\'', $res);\r
+ $res = str_replace("!§!'", '\')', $res);\r
+\r
+ return $res;\r
+ }\r
+\r
+ public function _generateV3Field($name, $f, $tab = false)\r
+ {\r
+ $typeMap = ['combo' => 'SelectFromArray', 'boolean' => 'Checkbox', 'couleur' => 'Color', 'couleurAlpha' => 'Color', 'integer' => 'Integer', 'float' => 'Number', 'text' => 'Text', 'textarea' => 'Textarea', 'file' => 'Images', 'freefile' => 'FilesOrURL'];\r
+ $copyAttrs = ['min' => 'min', 'max' => 'max', 'default' => 'default', 'allows_alpha' => 'allows_alpha'];\r
+ $transAttrs = ['label' => 'label', 'hint' => 'hint'];\r
+\r
+ if ($name === 'iconSet') {\r
+ $f['type'] = 'combo';\r
+ $f['default'] = 15;\r
+ $f['datas'] = [__('Jeu d\'icônes par défaut') => 15];\r
+ }\r
+\r
+ if ($f['type'] === 'couleur') {\r
+ $f['allows_alpha'] = false;\r
+ } else if ($f['type'] === 'couleurAlpha') {\r
+ $f['allows_alpha'] = false;\r
+ }\r
+\r
+ $attrs = ['name' => $name, 'type' => isset($typeMap[$f['type']]) ? $typeMap[$f['type']] : $f['type']];\r
+\r
+ if ($attrs['type'] === 'SelectFromArray') {\r
+ $attrs['options'] = array_flip($f['datas']);\r
+ }\r
+\r
+ if ($attrs['type'] === 'Color' && isset($f['default'])) {\r
+ $f['default'] = CubeIT_Graphics_Color::colorToCSS($f['default']);\r
+ }\r
+ if ($attrs['type'] === 'Images') {\r
+ unset($f['default']);\r
+ }\r
+\r
+ foreach ($transAttrs as $former => $new) {\r
+ if (isset($f[$former])) {\r
+ $attrs[$new] = '§!§' . $f[$former] . '!§!';\r
+ }\r
+ }\r
+ foreach ($copyAttrs as $former => $new) {\r
+ if (isset($f[$former])) {\r
+ $attrs[$new] = $f[$former];\r
+ }\r
+ }\r
+\r
+\r
+ $attrs['fake'] = true;\r
+ $attrs['store_in'] = 'settings';\r
+ $attrs['translatable'] = false;\r
+\r
+ return $this->generateV3Field($attrs, $tab);\r
+ }\r
+\r
+ protected function _varexport($expression, $return = FALSE)\r
+ {\r
+ $export = var_export($expression, TRUE);\r
+ $export = preg_replace("/^([ ]*)(.*)/m", '$1$1$2', $export);\r
+ $array = preg_split("/\r\n|\n|\r/", $export);\r
+ $array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array);\r
+ $export = implode(PHP_EOL, array_filter(["["] + $array));\r
+ if ((bool)$return) return $export; else echo $export;\r
+ }\r
+\r
}
\ No newline at end of file