Skip to content

Commit

Permalink
Merged dev into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubert Prein committed Aug 24, 2016
2 parents 406d8b3 + 359ab85 commit e9dbe87
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 93 deletions.
4 changes: 2 additions & 2 deletions AmFormsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public function getReleaseFeedUrl()
*/
public function getVersion()
{
return '1.4.3';
return '1.4.4';
}

/**
* @return string
*/
public function getSchemaVersion()
{
return '1.4.3';
return '1.4.4';
}

/**
Expand Down
4 changes: 4 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
'name' => 'Ignore Matrix field and block names',
'value' => false,
),
array(
'name' => 'Ignore Matrix multiple rows',
'value' => false,
),
),
'antispam' => array(
array(
Expand Down
2 changes: 1 addition & 1 deletion controllers/AmForms_SubmissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function actionSaveSubmission()
// Front-end submission, trigger AntiSpam or reCAPTCHA?
if (! craft()->request->isCpRequest()) {
// Where was this submission submitted?
$submission->submittedFrom = craft()->request->getUrlReferrer();
$submission->submittedFrom = urldecode(craft()->request->getUrlReferrer());

// Validate AntiSpam settings
$submission->spamFree = craft()->amForms_antispam->verify($form->handle);
Expand Down
25 changes: 25 additions & 0 deletions migrations/m160816_160800_amforms_addMatrixExportSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Craft;

/**
* The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName.
*/
class m160816_160800_amforms_addMatrixExportSetting extends BaseMigration
{
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
$settings = array(
array(
'name' => 'Ignore Matrix multiple rows',
'value' => false,
),
);
return craft()->amForms_install->installSettings($settings, AmFormsModel::SettingExport);
}
}
10 changes: 10 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"version": "1.4.4",
"downloadUrl": "https://github.com/am-impact/amforms/archive/master.zip",
"date": "2016-08-24T10:00:00+01:00",
"notes": [
"[Added] Placeholder on Email FieldType.",
"[Fixed] Perform the onBeforeEmailSubmission later in the code with email param added to it.",
"[Fixed] URL decode on submitted from location URL."
]
},
{
"version": "1.4.3",
"downloadUrl": "https://github.com/am-impact/amforms/archive/master.zip",
Expand Down
24 changes: 16 additions & 8 deletions services/AmForms_ExportsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class AmForms_ExportsService extends BaseApplicationComponent
{
private $_delimiter;
private $_ignoreMatrixMultipleRows;
private $_exportFiles = array();
private $_exportFields = array();
private $_exportColumns = array();
Expand All @@ -15,6 +16,7 @@ class AmForms_ExportsService extends BaseApplicationComponent
public function __construct()
{
$this->_delimiter = craft()->amForms_settings->getSettingsValueByHandleAndType('delimiter', AmFormsModel::SettingExport, ';');
$this->_ignoreMatrixMultipleRows = craft()->amForms_settings->isSettingValueEnabled('ignoreMatrixMultipleRows', AmFormsModel::SettingExport);
}

/**
Expand Down Expand Up @@ -778,25 +780,31 @@ private function _exportSubmission(AmForms_ExportModel $export, $submission, $re
$startFrom = $this->_exportColumns[$export->id][$fieldHandle . ':' . $matrixBlockType->handle];

// Multiple blocks?
if (count($matrixBlocks) > 1 && $blockCounter > 0) {
if (count($matrixBlocks) > 1 && $blockCounter > 0 && ! $this->_ignoreMatrixMultipleRows) {
$hasMoreRows = true;
$moreRowsData[$startFrom][] = $blockData;
}
else {
// Empty cells till we've reached the block type
for ($i = 0; $i < ($startFrom - $columnCounter); $i++) {
$data[] = '';
if (! $this->_ignoreMatrixMultipleRows) {
// Empty cells till we've reached the block type
for ($i = 0; $i < ($startFrom - $columnCounter); $i++) {
$data[] = '';
}
}

// We just have one block or we are adding the first block
$spaceCounter = 0;
foreach ($blockData as $blockValue) {
$data[] = $blockValue;
$spaceCounter ++;
}
// Empty cells till we've reached the next field, if necessary
if ($startFrom == $columnCounter) {
for ($i = 0; $i < ($this->_exportSpaceCounter[$export->id][$fieldHandle] - $spaceCounter); $i++) {
$data[] = '';

if (! $this->_ignoreMatrixMultipleRows) {
// Empty cells till we've reached the next field, if necessary
if ($startFrom == $columnCounter) {
for ($i = 0; $i < ($this->_exportSpaceCounter[$export->id][$fieldHandle] - $spaceCounter); $i++) {
$data[] = '';
}
}
}
}
Expand Down
154 changes: 72 additions & 82 deletions services/AmForms_SubmissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,103 +250,94 @@ public function emailSubmission(AmForms_SubmissionModel $submission, $overrideRe
return false;
}

// Overridden recipients skips before email event, so by default, send the email!
$sendEmail = true;

// Fire an 'onBeforeEmailSubmission' event
if ($overrideRecipients === false) {
$event = new Event($this, array(
'submission' => $submission
));
$this->onBeforeEmailSubmission($event);

// Override sendEmail
$sendEmail = $event->performAction;
}
// Get email body
$body = $this->getSubmissionEmailBody($submission);

// Is the event giving us the go-ahead?
if ($sendEmail) {
// Get email body
$body = $this->getSubmissionEmailBody($submission);

// Other email attributes
if ($form->notificationReplyToEmail) {
$replyTo = $this->_translatedObjectPlusEnvironment($form->notificationReplyToEmail, $submission);
if (! filter_var($replyTo, FILTER_VALIDATE_EMAIL)) {
$replyTo = null;
}
// Other email attributes
if ($form->notificationReplyToEmail) {
$replyTo = $this->_translatedObjectPlusEnvironment($form->notificationReplyToEmail, $submission);
if (! filter_var($replyTo, FILTER_VALIDATE_EMAIL)) {
$replyTo = null;
}
}

// Start mailing!
$success = false;

// @TODO Mandrill
$email = new EmailModel();
$email->htmlBody = $body;
$email->fromEmail = $this->_translatedObjectPlusEnvironment($form->notificationSenderEmail, $submission);
$email->fromName = $this->_translatedObjectPlusEnvironment($form->notificationSenderName, $submission);
$email->subject = $this->_translatedObjectPlusEnvironment($form->notificationSubject, $submission);
if ($replyTo) {
$email->replyTo = $replyTo;
}
// Start mailing!
$success = false;
$email = new EmailModel();
$email->htmlBody = $body;
$email->fromEmail = $this->_translatedObjectPlusEnvironment($form->notificationSenderEmail, $submission);
$email->fromName = $this->_translatedObjectPlusEnvironment($form->notificationSenderName, $submission);
$email->subject = $this->_translatedObjectPlusEnvironment($form->notificationSubject, $submission);
if ($replyTo) {
$email->replyTo = $replyTo;
}

// Add Bcc?
$bccEmailAddress = craft()->amForms_settings->getSettingsByHandleAndType('bccEmailAddress', AmFormsModel::SettingGeneral);
if ($bccEmailAddress && $bccEmailAddress->value) {
$bccAddresses = ArrayHelper::stringToArray($bccEmailAddress->value);
$bccAddresses = array_unique($bccAddresses);
// Add Bcc?
$bccEmailAddress = craft()->amForms_settings->getSettingsByHandleAndType('bccEmailAddress', AmFormsModel::SettingGeneral);
if ($bccEmailAddress && $bccEmailAddress->value) {
$bccAddresses = ArrayHelper::stringToArray($bccEmailAddress->value);
$bccAddresses = array_unique($bccAddresses);

if (count($bccAddresses)) {
$properBccAddresses = array();
if (count($bccAddresses)) {
$properBccAddresses = array();

foreach ($bccAddresses as $bccAddress) {
$bccAddress = $this->_translatedObjectPlusEnvironment($bccAddress, $submission);
foreach ($bccAddresses as $bccAddress) {
$bccAddress = $this->_translatedObjectPlusEnvironment($bccAddress, $submission);

if (filter_var($bccAddress, FILTER_VALIDATE_EMAIL)) {
$properBccAddresses[] = array(
'email' => $bccAddress
);
}
if (filter_var($bccAddress, FILTER_VALIDATE_EMAIL)) {
$properBccAddresses[] = array(
'email' => $bccAddress
);
}
}

if (count($properBccAddresses)) {
$email->bcc = $properBccAddresses;
}
if (count($properBccAddresses)) {
$email->bcc = $properBccAddresses;
}
}
}

// Add files to the notification?
if ($form->notificationFilesEnabled) {
foreach ($submission->getFieldLayout()->getTabs() as $tab) {
// Tab fields
$fields = $tab->getFields();
foreach ($fields as $layoutField) {
// Get actual field
$field = $layoutField->getField();

// Find assets
if ($field->type == 'Assets') {
foreach ($submission->{$field->handle}->find() as $asset) {
if($asset->source->type == 'S3'){
$file = @file_get_contents($asset->url);
// Add asset as attachment
if ($file) {
$email->addStringAttachment($file, $asset->filename);
}
} else {
$assetPath = craft()->amForms->getPathForAsset($asset);

// Add files to the notification?
if ($form->notificationFilesEnabled) {
foreach ($submission->getFieldLayout()->getTabs() as $tab) {
// Tab fields
$fields = $tab->getFields();
foreach ($fields as $layoutField) {
// Get actual field
$field = $layoutField->getField();

// Find assets
if ($field->type == 'Assets') {
foreach ($submission->{$field->handle}->find() as $asset) {
if($asset->source->type == 'S3'){
$file = @file_get_contents($asset->url);
// Add asset as attachment
if ($file) {
$email->addStringAttachment($file, $asset->filename);
}
} else {
$assetPath = craft()->amForms->getPathForAsset($asset);

// Add asset as attachment
if (IOHelper::fileExists($assetPath . $asset->filename)) {
$email->addAttachment($assetPath . $asset->filename);
}
// Add asset as attachment
if (IOHelper::fileExists($assetPath . $asset->filename)) {
$email->addAttachment($assetPath . $asset->filename);
}
}
}
}
}
}
}

// Fire an 'onBeforeEmailSubmission' event
$event = new Event($this, array(
'email' => $email,
'submission' => $submission,
));
$this->onBeforeEmailSubmission($event);

// Is the event giving us the go-ahead?
if ($event->performAction) {
// Send emails
foreach ($recipients as $recipient) {
$email->toEmail = $this->_translatedObjectPlusEnvironment($recipient, $submission);
Expand All @@ -362,13 +353,12 @@ public function emailSubmission(AmForms_SubmissionModel $submission, $overrideRe
// Fire an 'onEmailSubmission' event
$this->onEmailSubmission(new Event($this, array(
'success' => $success,
'submission' => $submission
'email' => $email,
'submission' => $submission,
)));

return $success;
}

return false;
return $success;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions templates/settings/export.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@
on: export.ignoreMatrixFieldAndBlockNames.value,
instructions: 'Don’t include the field and block names in the column name.'|t
}) }}
{{ forms.lightswitchField({
label: export.ignoreMatrixMultipleRows.name|t,
id: export.ignoreMatrixMultipleRows.handle,
name: export.ignoreMatrixMultipleRows.handle,
on: export.ignoreMatrixMultipleRows.value,
instructions: 'Don’t place multiple block types on multiple rows. You need to be sure that block types will not be used more than once.'|t
}) }}
{% endblock %}
2 changes: 2 additions & 0 deletions translations/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
'Design your form' => 'Stel uw formulier samen',
'Display tab titles' => 'Tab titels weergeven',
'Don’t include the field and block names in the column name.' => 'De naam van het veld en de blokken niet opnemen in de kolomnaam.',
'Don’t place multiple block types on multiple rows. You need to be sure that block types will not be used more than once.' => 'Plaats meerdere blok types niet op meerdere regels. U moet er wel zeker van zijn dat de blok types niet meer dan een keer gebruikt zullen worden.',
'Don’t show' => 'Niet weergeven',
'Download' => 'Download',
'Duplicate check enabled' => 'Duplicatie controle inschakelen',
Expand Down Expand Up @@ -93,6 +94,7 @@
'Honeypot enabled' => 'Honeypot inschakelen',
'Honeypot name' => 'Honeypot naam',
'Ignore Matrix field and block names' => 'Negeer Matrix veld en blok namen',
'Ignore Matrix multiple rows' => 'Negeer Matrix meerdere regels',
'Include in export' => 'Opnemen in export',
'Leave this field blank' => 'Laat dit veld leeg',
'Minimum time in seconds' => 'Het minimum aantal seconden',
Expand Down

0 comments on commit e9dbe87

Please sign in to comment.