Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions assets/components/formit/js/mgr/widgets/forms.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,27 @@ FormIt.window.ViewForm = function(config) {
anchor : '100%'
}, {
html : '<hr />'
}, this.getValues(config.record.values)]
}, this.getValues(config)],
});

FormIt.window.ViewForm.superclass.constructor.call(this, config);
};

Ext.extend(FormIt.window.ViewForm, MODx.Window, {
getValues: function(values) {
getValues: function(config) {
var values = config.record.values;
var output = [];

for (var key in values) {
if (values[key].length >= FormIt.config['max_chars']) {
if (values[key].includes('formid='+config.record.id)) {
output.push({
xtype : 'box',
fieldLabel : key,
name : 'date',
anchor : '100%',
html : values[key],
});

} else if (values[key].length >= FormIt.config['max_chars']) {
output.push({
xtype : 'textarea',
fieldLabel : key,
Expand Down
11 changes: 11 additions & 0 deletions core/components/formit/controllers/home.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

class FormItHomeManagerController extends FormItBaseManagerController
{
public function initialize()
{
if (isset($_GET['formid']) && isset($_GET['file'])) {
$form = $this->modx->getObject(\Sterc\FormIt\Model\FormItForm::class, $_GET['formid']);
if ($form) {
$form->downloadFile($_GET['file']);
exit;
}
}
return parent::initialize();
}
/**
* @access public.
*/
Expand Down
103 changes: 103 additions & 0 deletions core/components/formit/src/FormIt/Model/FormItForm.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Sterc\FormIt\Model;

use Imagick;
use xPDO\xPDO;
use MODX\Revolution\modX;
use MODX\Revolution\modSystemSetting;
Expand Down Expand Up @@ -259,6 +260,9 @@ public function saveFile($enc_name, $name, $tmp_name, $error, $path)
return;
}

/* Strip Exif data */
$this->stripExif($tmp_name);

/* Check filesize */
$maxFileSize = $this->xpdo->getOption('upload_maxsize', null, 1048576);
$size = filesize($tmp_name);
Expand Down Expand Up @@ -389,4 +393,103 @@ function decryptFile($source)
echo $output;
exit();
}

public function remove(array $ancestors= array ())
{
$this->removeFiles();
return parent::remove($ancestors);
}

protected function removeFiles() {
$mediasourceId = $this->xpdo->getOption('formit.attachment.mediasource');
$mediasource = $this->xpdo->getObject(modMediaSource::class, $mediasourceId);
if ($mediasource) {
$prop = $mediasource->get('properties');
$attachPath = $this->xpdo->getOption('formit.attachment.path');
if (empty($attachPath) || $attachPath == '/') {
$attachPath = $this->xpdo->getOption(
'formit.assets_path',
null,
$this->xpdo->getOption('assets_path', null, MODX_CORE_PATH)
) . 'components/formit/attachments';
} else {
$attachPath = rtrim(MODX_BASE_PATH, '/') . '/'
. trim($prop['basePath']['value'], '/') . '/'
. trim($attachPath,'/');
}
$path = $attachPath . '/' . $this->get('id');
if (is_dir($path)) {
$files = glob($path . '/*');
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
rmdir($path);
}
}
}

private function stripExif($tmp_name): void
{
// check if the file is an image
$finfo = finfo_open(FILEINFO_MIME_TYPE);
if (false === $finfo) {
return;
}
$mime = finfo_file($finfo, $tmp_name);
finfo_close($finfo);
if (strpos($mime, 'image/') !== 0) {
return;
}
// try Imagick first

if (class_exists('Imagick')) {
try {
$image = new \Imagick($tmp_name);
$image->stripImage();
$image->writeImage($tmp_name);
$image->clear();
} catch (\Exception $e) {
$this->modx->log(\xPDO::LOG_LEVEL_ERROR, 'Imagick error: ' . $e->getMessage());
}
} elseif (function_exists('exif_imagetype')) {
$type = exif_imagetype($tmp_name);
$version = phpversion();
$image = null;
// try GD method
if (($type == IMAGETYPE_JPEG || $type == IMAGETYPE_JPEG2000) && function_exists('imagecreatefromjpeg')) {
$image = imagecreatefromjpeg($tmp_name);
if (!$image) return;
imagejpeg($image, $tmp_name, 100);
} elseif ($type == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) {
$image = imagecreatefrompng($tmp_name);
if (!$image) return;
imagepng($image, $tmp_name, 9);
} elseif ($type == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) {
$image = imagecreatefromgif($tmp_name);
if (!$image) return;
imagegif($image, $tmp_name);
} elseif ($type == IMAGETYPE_BMP && function_exists('imagecreatefrombmp')) {
$image = imagecreatefrombmp($tmp_name);
if (!$image) return;
imagebmp($image, $tmp_name);
} elseif ($type == IMAGETYPE_WEBP && function_exists('imagecreatefromwebp')) {
$image = imagecreatefromwebp($tmp_name);
if (!$image) return;
imagewebp($image, $tmp_name, 100);
} elseif (
version_compare($version, '8.1.0', 'ge')
&& $type == 19
&& function_exists('imagecreatefromavif')
&& function_exists('imageavif')) {
$image = imagecreatefromavif($tmp_name);
if (!$image) return;
imageavif($image, $tmp_name, 100);
}
if ($image) {
imagedestroy($image);
}
}
}
}