1
0
mirror of https://github.com/typemill/typemill.git synced 2025-05-01 17:17:50 +02:00

version 1.2.9

This commit is contained in:
Sebastian 2018-12-11 08:42:02 +01:00
parent e51bcbd208
commit 28b6f93a9c
7 changed files with 128 additions and 91 deletions

1
.gitignore vendored

@ -1,5 +1,6 @@
cache
plugins/admin
plugins/contactform
plugins/demo
plugins/disqus
plugins/download

2
cache/lastCache.txt vendored

@ -1 +1 @@
1544113772
1544479161

@ -19,6 +19,7 @@ class ContactForm extends Plugin
);
}
# add the path for session and csrf-protection
public function onSessionSegmentsLoaded($segments)
{
$this->pluginSettings = $this->getPluginSettings('contactform');
@ -31,12 +32,12 @@ class ContactForm extends Plugin
}
}
# get the original html without manipulations
public function onOriginalLoaded($original)
{
{
if(substr($this->getPath(), 0, strlen($this->pluginSettings['area'])) === $this->pluginSettings['area'])
{
# get original html without manipulations
$this->originalHtml = $original->getHTML();
$this->originalHtml = $original->getHTML($urlrel = false);
}
}
@ -48,6 +49,11 @@ class ContactForm extends Plugin
if($this->getPath() == $this->pluginSettings['page'])
{
$this->generateForm('contactform');
# add css
# $this->addCSS('/textadds/css/textadds.css');

@ -3,7 +3,7 @@
namespace Typemill\Controllers;
use \Symfony\Component\Yaml\Yaml;
use Typemill\Models\Field;
use Typemill\Models\Fields;
use Typemill\Models\Validation;
use Typemill\Models\User;
@ -15,7 +15,7 @@ class SettingsController extends Controller
public function showSettings($request, $response, $args)
{
$user = new User();
$user = new User();
$settings = $this->c->get('settings');
$copyright = $this->getCopyright();
$languages = $this->getLanguages();
@ -81,6 +81,7 @@ class SettingsController extends Controller
$userSettings = $this->c->get('settings');
$themes = $this->getThemes();
$themedata = array();
$fieldsModel = new Fields();
foreach($themes as $themeName)
{
@ -103,8 +104,8 @@ class SettingsController extends Controller
if(isset($themeSettings['forms']['fields']))
{
$fields = $this->getFields($userSettings, 'themes', $themeName, $themeSettings);
$fields = $fieldsModel->getFields($userSettings, 'themes', $themeName, $themeSettings);
/* overwrite original theme form definitions with enhanced form objects */
$themedata[$themeName]['forms']['fields'] = $fields;
}
@ -128,6 +129,7 @@ class SettingsController extends Controller
{
$userSettings = $this->c->get('settings');
$plugins = array();
$fieldsModel = new Fields();
$fields = array();
/* iterate through the plugins in the stored user settings */
@ -170,7 +172,7 @@ class SettingsController extends Controller
if(isset($pluginOriginalSettings['forms']['fields']))
{
/* get all the fields and prefill them with the dafault-data, the user-data or old input data */
$fields = $this->getFields($userSettings, 'plugins', $pluginName, $pluginOriginalSettings);
$fields = $fieldsModel->getFields($userSettings, 'plugins', $pluginName, $pluginOriginalSettings);
/* overwrite original plugin form definitions with enhanced form objects */
$plugins[$pluginName]['forms']['fields'] = $fields;
@ -184,85 +186,6 @@ class SettingsController extends Controller
$this->render($response, 'settings/plugins.twig', array('settings' => $userSettings, 'plugins' => $plugins, 'users' => $users, 'route' => $route->getName() ));
}
private function getFields($userSettings, $objectType, $objectName, $objectSettings)
{
$fields = array();
/* then iterate through the fields */
foreach($objectSettings['forms']['fields'] as $fieldName => $fieldConfigs)
{
if($fieldConfigs['type'] == 'fieldset')
{
/* Create an array for the subsettings of the fieldset with the same structure and data as the original settings array */
$subSettings = $objectSettings;
$subSettings['forms'] = $fieldConfigs;
$fieldset = array();
$fieldset['type'] = 'fieldset';
$fieldset['legend'] = $fieldConfigs['legend'];
$fieldset['fields'] = $this->getFields($userSettings, $objectType, $objectName, $subSettings);
$fields[] = $fieldset;
}
else
{
/* and create a new field object with the field name and the field configurations. */
$field = new Field($fieldName, $fieldConfigs);
/* you have to prefil the value for the field with default settings, user settings or old user-input from form */
$userValue = false;
/* first, add the default values from the original plugin or theme settings. Ignore checkboxes, otherwiese they might be always checked */
if(isset($objectSettings['settings'][$fieldName]))
{
$userValue = $objectSettings['settings'][$fieldName];
}
/* now overwrite them with the local stored user settings */
if(isset($userSettings[$objectType][$objectName][$fieldName]))
{
$userValue = $userSettings[$objectType][$objectName][$fieldName];
}
/* overwrite it with old input in form, if exists */
if(isset($_SESSION['old'][$objectName][$fieldName]))
{
$userValue = $_SESSION['old'][$objectName][$fieldName];
}
/* now we have set the uservalue for the field. Prepopulate the field object with it now */
if($field->getType() == "textarea")
{
if($userValue)
{
$field->setContent($userValue);
}
}
elseif($field->getType() == "checkbox")
{
/* needs special treatment, because field does not exist in settings if unchecked by user */
if(isset($userSettings[$objectType][$objectName][$fieldName]))
{
$field->setAttribute('checked', 'checked');
}
else
{
$field->unsetAttribute('checked');
}
}
else
{
$field->setAttributeValue('value', $userValue);
}
/* add the field to the field-List with the plugin-name as key */
$fields[] = $field;
}
}
return $fields;
}
/*************************************
** SAVE THEME- AND PLUGIN-SETTINGS **
*************************************/

@ -24,12 +24,12 @@ class OnOriginalLoaded extends Event
return $this->data;
}
public function getHTML()
public function getHTML($urlrel)
{
$parsedown = new ParsedownExtension();
$contentArray = $parsedown->text($this->data);
$contentHTML = $parsedown->markup($contentArray);
$contentHTML = $parsedown->markup($contentArray, $urlrel);
return $contentHTML;
}
}

90
system/Models/Fields.php Normal file

@ -0,0 +1,90 @@
<?php
namespace Typemill\Models;
use Typemill\Models\Field;
class Fields
{
public function getFields($userSettings, $objectType, $objectName, $objectSettings, $formType = false)
{
# hold all fields in array
$fields = array();
# formtype are backendforms or frontendforms, only relevant for plugins for now
$formType = $formType ? $formType : 'forms';
# iterate through all fields of the objectSetting (theme or plugin)
foreach($objectSettings[$formType]['fields'] as $fieldName => $fieldConfigurations)
{
if($fieldConfigurations['type'] == 'fieldset')
{
# if it is a fieldset, then create a subset for the containing field and read them with a recursive function
$subSettings = $objectSettings;
$subSettings['forms'] = $fieldConfigurations;
$fieldset = array();
$fieldset['type'] = 'fieldset';
$fieldset['legend'] = $fieldConfigurations['legend'];
$fieldset['fields'] = $this->getFields($userSettings, $objectType, $objectName, $subSettings, $formType);
$fields[] = $fieldset;
}
else
{
# for each field generate a new field object with the field name and the field configurations
$field = new Field($fieldName, $fieldConfigurations);
# handle the value for the field
$userValue = false;
# first, add the default value from the original plugin or theme settings
if(isset($objectSettings['settings'][$fieldName]))
{
$userValue = $objectSettings['settings'][$fieldName];
}
# now overwrite the default values with the user values stored in the user settings
if(isset($userSettings[$objectType][$objectName][$fieldName]))
{
$userValue = $userSettings[$objectType][$objectName][$fieldName];
}
# now overwrite user-values, if there are old-input values from the actual form (e.g. after input error)
if(isset($_SESSION['old'][$objectName][$fieldName]))
{
$userValue = $_SESSION['old'][$objectName][$fieldName];
}
# Now prepopulate the field object with the value */
if($field->getType() == "textarea")
{
if($userValue)
{
$field->setContent($userValue);
}
}
elseif($field->getType() == "checkbox")
{
# checkboxes need a special treatment, because field does not exist in settings if unchecked by user
if(isset($userSettings[$objectType][$objectName][$fieldName]))
{
$field->setAttribute('checked', 'checked');
}
else
{
$field->unsetAttribute('checked');
}
}
else
{
$field->setAttributeValue('value', $userValue);
}
# add the field to the field-List
$fields[] = $field;
}
}
return $fields;
}
}

@ -3,6 +3,7 @@
namespace Typemill;
use \Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Typemill\Models\Fields;
abstract class Plugin implements EventSubscriberInterface
{
@ -84,4 +85,20 @@ abstract class Plugin implements EventSubscriberInterface
{
$this->container->assets->addInlineCSS($CSS);
}
protected function generateForm($pluginName)
{
$fieldsModel = new Fields();
$pluginDefinitions = \Typemill\Settings::getObjectSettings('plugins', $pluginName);
if(isset($pluginDefinitions['frontend']['fields']))
{
# get all the fields and prefill them with the dafault-data, the user-data or old input data
$fields = $fieldsModel->getFields($userSettings = false, 'plugins', $pluginName, $pluginDefinitions, 'frontend');
# use the field-objects to generate the html-fields
}
}
}