mirror of
https://github.com/typemill/typemill.git
synced 2025-10-17 07:36:24 +02:00
Version 1.2.9: Add videos and frontend forms
This commit is contained in:
@@ -6,70 +6,168 @@ use \Typemill\Plugin;
|
||||
|
||||
class ContactForm extends Plugin
|
||||
{
|
||||
protected $item;
|
||||
protected $originalHtml;
|
||||
protected $settings;
|
||||
protected $pluginSettings;
|
||||
protected $originalHtml;
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'onSessionSegmentsLoaded' => 'onSessionSegmentsLoaded',
|
||||
'onOriginalLoaded' => 'onOriginalLoaded',
|
||||
'onHtmlLoaded' => 'onHtmlLoaded',
|
||||
);
|
||||
}
|
||||
|
||||
# add the path for session and csrf-protection
|
||||
|
||||
# add the path stored in user-settings to initiate session and csrf-protection
|
||||
public function onSessionSegmentsLoaded($segments)
|
||||
{
|
||||
$this->pluginSettings = $this->getPluginSettings('contactform');
|
||||
|
||||
if($this->getPath() == $this->pluginSettings['page'])
|
||||
if($this->getPath() == $this->pluginSettings['page_value'])
|
||||
{
|
||||
$data = $segments->getData();
|
||||
$data[] = $this->pluginSettings['page'];
|
||||
$data = $segments->getData();
|
||||
$data[] = $this->pluginSettings['page_value'];
|
||||
|
||||
$segments->setData($data);
|
||||
}
|
||||
}
|
||||
|
||||
# get the original html without manipulations
|
||||
public function onOriginalLoaded($original)
|
||||
|
||||
# create the output
|
||||
public function onHtmlLoaded($html)
|
||||
{
|
||||
if(substr($this->getPath(), 0, strlen($this->pluginSettings['area'])) === $this->pluginSettings['area'])
|
||||
if($this->getPath() == $this->pluginSettings['page_value'])
|
||||
{
|
||||
$content = $html->getData();
|
||||
|
||||
# add css
|
||||
$this->addCSS('/contactform/css/contactform.css');
|
||||
|
||||
# check if form data have been stored
|
||||
$formdata = $this->getFormdata('contactform');
|
||||
|
||||
if($formdata)
|
||||
{
|
||||
# process the form-data
|
||||
$sendmail = $this->sendMail($formdata);
|
||||
if($sendmail)
|
||||
{
|
||||
$mailresult = '<div class="mailresult">' . $this->markdownToHtml($this->pluginSettings['message_success']) . '</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$mailresult = '<div class="mailresult">' . $this->markdownToHtml($this->pluginSettings['message_error']) . '</div>';
|
||||
}
|
||||
|
||||
# add thank you to the content
|
||||
$content = $content . $mailresult;
|
||||
}
|
||||
else
|
||||
{
|
||||
# get the public forms for the plugin
|
||||
$contactform = $this->generateForm('contactform');
|
||||
|
||||
# add forms to the content
|
||||
$content = $content . $contactform;
|
||||
}
|
||||
$html->setData($content);
|
||||
}
|
||||
}
|
||||
|
||||
private function sendMail($formdata)
|
||||
{
|
||||
$mailto = $this->pluginSettings['mailto'];
|
||||
$subject = $formdata['subject'];
|
||||
$message = wordwrap($formdata['message'],70);
|
||||
$header = 'From: ' . $formdata['email'] . "\r\n" .
|
||||
'Reply-To: ' . $formdata['email'] . "\r\n" .
|
||||
'X-Mailer: PHP/' . phpversion();
|
||||
|
||||
return @mail($mailto, $subject, $message, $header);
|
||||
}
|
||||
|
||||
# check if the mail-plugin is active
|
||||
/*
|
||||
public function onTwigLoaded()
|
||||
{
|
||||
$this->settings = $this->getSettings();
|
||||
|
||||
if(isset($this->settings['plugins']['mail']) OR !$this->settings['plugins']['mail']['active'])
|
||||
{
|
||||
$this->container->flash->addMessage('error', 'You have to activate the mail-plugin to use the contactform.');
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
# get the original html without manipulations from other plugins
|
||||
/*
|
||||
public function onOriginalLoaded($original)
|
||||
{
|
||||
if(substr($this->getPath(), 0, strlen($this->pluginSettings['area_value'])) === $this->pluginSettings['area_value'])
|
||||
{
|
||||
$this->originalHtml = $original->getHTML($urlrel = false);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
# create the output
|
||||
/*
|
||||
public function onHtmlLoaded($html)
|
||||
{
|
||||
if(substr($this->getPath(), 0, strlen($this->pluginSettings['area'])) === $this->pluginSettings['area'])
|
||||
{
|
||||
if(substr($this->getPath(), 0, strlen($this->pluginSettings['area_value'])) === $this->pluginSettings['area_value'])
|
||||
{
|
||||
$content = $this->originalHtml;
|
||||
|
||||
if($this->getPath() == $this->pluginSettings['page'])
|
||||
{
|
||||
|
||||
|
||||
$this->generateForm('contactform');
|
||||
|
||||
|
||||
if($this->getPath() == $this->pluginSettings['page_value'])
|
||||
{
|
||||
# add css
|
||||
# $this->addCSS('/textadds/css/textadds.css');
|
||||
|
||||
# get Twig Instance and add the cookieconsent template-folder to the path
|
||||
$twig = $this->getTwig();
|
||||
$loader = $twig->getLoader();
|
||||
$loader->addPath(__DIR__ . '/templates');
|
||||
|
||||
# fetch the template and render it with twig
|
||||
$contactform = $twig->fetch('/contactform.twig', $this->pluginSettings);
|
||||
$this->addCSS('/contactform/css/contactform.css');
|
||||
|
||||
# check if form data have been stored
|
||||
$formdata = $this->getFormdata('contactform');
|
||||
|
||||
$content = $this->originalHtml . $contactform;
|
||||
if($formdata)
|
||||
{
|
||||
# process the form-data
|
||||
$sendmail = $this->sendMail($formdata);
|
||||
if($sendmail)
|
||||
{
|
||||
$mailresult = '<div class="mailresult"><h2>Thank you!</h2><p>Your Message has been send.</p></div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$mailresult = '<div class="mailresult"><h2>Error</h2><p>We could not send your message. Please send the mail manually.</p></div>';
|
||||
}
|
||||
/*
|
||||
print_r($formdata);
|
||||
die();
|
||||
$mail = $this->container->mail->send('mail/welcome.twig', ['user' => $user, 'url' => $host], function($message) use ($user){
|
||||
$message->to($user['email']);
|
||||
$message->subject('Dein Account bei der Regierungsmannschaft');
|
||||
});
|
||||
|
||||
if(!$mail)
|
||||
{
|
||||
$this->container->flash->addMessage('error', 'Die Bestätigungsmail konnte nicht verschickt werden.');
|
||||
}
|
||||
|
||||
# create thank you page
|
||||
|
||||
# add thank you to the content
|
||||
$content = $this->originalHtml . $mailresult;
|
||||
}
|
||||
else
|
||||
{
|
||||
# get the public forms for the plugin
|
||||
$contactform = $this->generateForm('contactform');
|
||||
|
||||
# add forms to the content
|
||||
$content = $this->originalHtml . $contactform;
|
||||
}
|
||||
}
|
||||
|
||||
$html->setData($content);
|
||||
$html->stopPropagation();
|
||||
$html->stopPropagation();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
@@ -6,91 +6,89 @@ homepage: https://typemill.net
|
||||
licence: MIT
|
||||
|
||||
settings:
|
||||
page: ''
|
||||
name: 'Name: '
|
||||
email: 'E-Mail: '
|
||||
subject: 'Subject: '
|
||||
message: 'Message: '
|
||||
button: 'Send Message'
|
||||
message_success: "## Thank you!\r\n\r\nWe got your message and will answer as soon as possible."
|
||||
message_error: "## Error\r\n\r\nWe could not send your message. Please send your e-mail manually."
|
||||
|
||||
forms:
|
||||
fields:
|
||||
|
||||
page:
|
||||
mailto:
|
||||
type: email
|
||||
label: Your e-mail-address
|
||||
required: true
|
||||
|
||||
page_value:
|
||||
type: text
|
||||
label: Path to the page where to show the form
|
||||
label: Path to page where to include the form
|
||||
placeholder: 'path/to/page'
|
||||
required: true
|
||||
|
||||
area:
|
||||
type: text
|
||||
label: Path to the area with original content
|
||||
placeholder: 'path/to/rootpage'
|
||||
required: true
|
||||
|
||||
name:
|
||||
name_label:
|
||||
type: text
|
||||
label: Label for Name Input Field
|
||||
placeholder: 'Name: '
|
||||
required: true
|
||||
|
||||
email:
|
||||
email_label:
|
||||
type: text
|
||||
label: Label for E-Mail-Field
|
||||
placeholder: 'E-Mail: '
|
||||
required: true
|
||||
|
||||
subject:
|
||||
subject_label:
|
||||
type: text
|
||||
label: Label for Subject-Field
|
||||
placeholder: 'Subject: '
|
||||
required: true
|
||||
|
||||
message:
|
||||
message_label:
|
||||
type: text
|
||||
label: Label for Message
|
||||
placeholder: 'Message: '
|
||||
required: true
|
||||
|
||||
button:
|
||||
button_label:
|
||||
type: text
|
||||
label: Label for Button
|
||||
placeholder: 'Send Message'
|
||||
required: true
|
||||
|
||||
hint:
|
||||
legalnotice:
|
||||
type: textarea
|
||||
rows: 5;
|
||||
label: Text below button (use markdown)
|
||||
placeholder: 'Add your legal text or other hints here'
|
||||
|
||||
frontend:
|
||||
message_success:
|
||||
type: textarea
|
||||
rows: 5;
|
||||
label: Message if mail is send (use markdown)
|
||||
placeholder: 'Add your legal text or other hints here'
|
||||
|
||||
message_error:
|
||||
type: textarea
|
||||
rows: 5;
|
||||
label: Message if mail failed (use markdown)
|
||||
placeholder: 'Add your legal text or other hints here'
|
||||
|
||||
public:
|
||||
fields:
|
||||
|
||||
name:
|
||||
type: text
|
||||
label: Label for Name Input Field
|
||||
placeholder: 'Name: '
|
||||
label: name_label
|
||||
required: true
|
||||
|
||||
email:
|
||||
type: text
|
||||
label: Label for E-Mail-Field
|
||||
placeholder: 'E-Mail: '
|
||||
type: email
|
||||
label: email_label
|
||||
required: true
|
||||
|
||||
subject:
|
||||
type: text
|
||||
label: Label for Subject-Field
|
||||
placeholder: 'Subject: '
|
||||
label: subject_label
|
||||
required: true
|
||||
|
||||
message:
|
||||
type: text
|
||||
label: Label for Message
|
||||
placeholder: 'Message: '
|
||||
type: textarea
|
||||
label: message_label
|
||||
required: true
|
||||
|
||||
hint:
|
||||
type: textarea
|
||||
label: Text below button (use markdown)
|
||||
placeholder: 'Add your legal text or other hints here'
|
||||
legalnotice:
|
||||
type: paragraph
|
@@ -1,26 +0,0 @@
|
||||
.contentadd{
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
border-top: 1px solid #ccc;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
.contentadd span{
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 20px;
|
||||
text-transform: uppercase;
|
||||
color: #ccc;
|
||||
font-size: 0.6em;
|
||||
}
|
||||
.contentadd h3{
|
||||
margin-top: 20px;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
.contentadd small{
|
||||
margin: 0px;
|
||||
}
|
||||
.contentadd p{
|
||||
margin-top: 0px;
|
||||
margin-bottom: 20px;
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
<form method="POST" action="{{ path_for('settings.save') }}">
|
||||
|
||||
<fieldset>
|
||||
|
||||
<div class="medium{{ errors.contact.name ? ' error' : '' }}">
|
||||
<label for="contact[name]">{{ name }} *</label>
|
||||
<input type="text" name="contact[name]" id="name" pattern=".{2,20}" required title="Use 2 to 20 characters." value="{{ old.contact.title ? old.contact.name : contact.name }}" />
|
||||
{% if errors.contact.title %}
|
||||
<span class="error">{{ errors.contact.name | first }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="medium{{ errors.contact.email ? ' error' : '' }}">
|
||||
<label for="contact[email]">{{ email }} *</label>
|
||||
<input type="text" name="contact[email]" id="email" pattern=".{2,20}" required title="Use 2 to 20 characters." value="{{ old.contact.email ? old.contact.email : contact.email }}" />
|
||||
{% if errors.contact.title %}
|
||||
<span class="error">{{ errors.contact.email | first }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="medium{{ errors.contact.subject ? ' error' : '' }}">
|
||||
<label for="contact[email]">{{ subject }} *</label>
|
||||
<input type="text" name="contact[subject]" id="subject" pattern=".{2,20}" required title="Use 2 to 20 characters." value="{{ old.contact.subject ? old.contact.subject : contact.subject }}" />
|
||||
{% if errors.contact.title %}
|
||||
<span class="error">{{ errors.contact.email | first }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="medium{{ errors.contact.message ? ' error' : '' }}">
|
||||
<label for="contact[email]">{{ message }} *</label>
|
||||
<input type="textfield" name="contact[message]" id="message" pattern=".{2,20}" required title="Use 2 to 20 characters." value="{{ old.contact.message ? old.contact.message : contact.message }}" />
|
||||
{% if errors.contact.title %}
|
||||
<span class="error">{{ errors.contact.message | first }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<small>{{ hint }}</small>
|
||||
|
||||
</fieldset>
|
||||
|
||||
<input type="submit" value="{{ button }}" />
|
||||
{{ csrf_field() | raw }}
|
||||
|
||||
</form>
|
Reference in New Issue
Block a user