From: Vincent Vanwaelscappel Date: Thu, 5 May 2022 14:15:35 +0000 (+0200) Subject: wip #5228 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=88b698073eb686c50b7c9fb980baa9d9ff16cf38;p=fluidbook-toolbox.git wip #5228 @1.5 --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 902b67339..4539a062f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -24,8 +24,11 @@ - - + + + + + diff --git a/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php b/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php index af7955f06..b8ec38b7e 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php +++ b/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php @@ -15,6 +15,7 @@ use Cubist\Util\ArrayUtil; use Cubist\Util\Files\Files; use Cubist\Util\Str; use Cubist\Util\Zip; +use DOMDocument; use Fluidbook\Tools\Document; use Fluidbook\Tools\Jobs\ProcessFile; use Fluidbook\Tools\Jobs\ProcessPage; @@ -22,6 +23,11 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; trait PDF2SVGOperation { + /** + * @var int + */ + protected static $_svgAttr = 0; + public function pdf2svg() { $form = new Form(backpack_url('tools/convertpdf')); @@ -61,12 +67,54 @@ trait PDF2SVGOperation $f = new ProcessFile($format, $resolution, $withGraphics, $withTexts); $pageJob = new ProcessPage($doc, $page, [$f]); $f->setJob($pageJob); - rename($f->getPath(), $dir . '/' . $n . '-' . $page . '.' . $format); + $fname = $n . '-' . $page ; + $dest = $dir . '/' . $fname. '.' . $format; + rename($f->getPath(), $dest); + if ($format === 'svg') { + self::identifySVG($dest); + } + } + + if (count($pages) === 1) { + $ext = $format; + $tmpfile = $dest; + } else { + $ext = 'zip'; + $fname = $file->getClientOriginalName(); + $tmpfile = Files::tempnam() . '.zip'; + Zip::archive($dir, $tmpfile); } - $tmpfile = Files::tempnam() . '.zip'; - $zip = Zip::archive($dir, $tmpfile); + return response()->download($tmpfile, $fname . '.' . $ext)->deleteFileAfterSend(true); + } + + public static function identifySVG($path) + { + self::$_svgAttr = 0; + $svg = new DOMDocument(); + $svg->preserveWhiteSpace = true; + $svg->load($path, LIBXML_PARSEHUGE); + self::_identifySVGNode($svg); + + file_put_contents($path, $svg->saveXML()); + } - return response()->download($tmpfile, $file->getClientOriginalName() . '.zip')->deleteFileAfterSend(true); + + public static function _identifySVGNode(\DOMNode $node) + { + + if ($node instanceof \DOMElement) { + if (!$node->hasAttribute('id')) { + self::$_svgAttr++; + $node->setAttribute('id', 'e-' . self::$_svgAttr); + + } + } + + if ($node->hasChildNodes()) { + foreach ($node->childNodes as $childNode) { + self::_identifySVGNode($childNode); + } + } } } diff --git a/app/Models/CubedesignersEmails.php b/app/Models/CubedesignersEmails.php index 1acaaf53a..c51167323 100644 --- a/app/Models/CubedesignersEmails.php +++ b/app/Models/CubedesignersEmails.php @@ -115,6 +115,7 @@ class CubedesignersEmails extends CubistMagicAbstractModel } $allAliases[$from . '@' . $domain] = array_merge($allAliases[$from . '@' . $domain], $dest); } +// $allAliases['@' . $domain] = ['postmaster+catchall@' . $maindomain]; } $aliasesFile = []; foreach ($allAliases as $from => $dest) { @@ -144,8 +145,8 @@ class CubedesignersEmails extends CubistMagicAbstractModel } $my_networks = array_unique($my_networks); - $this->_replaceInFile('postfix-main.cf',['my_networks'=> implode(', ', $my_networks)]); - $this->_replaceInFile('fail2ban-jail.cf',['ignoreip'=> implode(',', $my_networks)]); + $this->_replaceInFile('postfix-main.cf', ['my_networks' => implode(', ', $my_networks)]); + $this->_replaceInFile('fail2ban-jail.cf', ['ignoreip' => implode(',', $my_networks)]); touch(storage_path('emailconfig/__UPDATED__')); } diff --git a/app/Models/FluidbookQuote.php b/app/Models/FluidbookQuote.php index ee960f94e..dff1d6115 100644 --- a/app/Models/FluidbookQuote.php +++ b/app/Models/FluidbookQuote.php @@ -10,8 +10,11 @@ use App\Http\Controllers\Admin\Operations\FluidbookQuote\ConfirmAssignmentOperat use App\Http\Controllers\Admin\Operations\FluidbookQuote\CreateFromWebsite; use App\Models\Base\ToolboxModel; use App\Widgets; +use Cubist\Backpack\Magic\Fields\Hidden; use Cubist\Backpack\Magic\Fields\Integer; +use Cubist\Backpack\Magic\Fields\ModelAttribute; use Cubist\Backpack\Magic\Fields\Number; +use Cubist\Backpack\Magic\Fields\StaticValue; class FluidbookQuote extends ToolboxModel { @@ -33,10 +36,6 @@ class FluidbookQuote extends ToolboxModel { parent::setFields(); - $this->addField('type', 'Hidden'); - $this->addField('pages', 'Hidden'); - $this->addField('links', 'Hidden'); - $this->addField('langs', 'Hidden'); $this->addField('user', FluidbookUser::class, __('Utilisateur'), [ @@ -46,6 +45,8 @@ class FluidbookQuote extends ToolboxModel 'can_write' => 'fluidbook-quote:admin', ]); + $this->addField('email', ModelAttribute::class, __('Email'), ['column' => true, 'attribute' => 'useremail', 'column_type' => 'email']); + $this->addField(['name' => 'created_at', 'label' => __('Date'), 'type' => 'Datetime', @@ -67,6 +68,11 @@ class FluidbookQuote extends ToolboxModel ] ); + $this->addField('type', Hidden::class, __('Type')); + $this->addField('pages', Hidden::class, __('Pages')); + $this->addField('links', Hidden::class, __('Liens')); + $this->addField('langs', Hidden::class, __('Langues')); + $this->addField('gclid', 'Text', 'Google Adwords ID (gclid)', ['can' => 'fluidbook-quote:admin',]); $this->addField('coupon', 'Hidden', __('Coupon'), ['can' => 'fluidbook-quote:admin',]); @@ -104,6 +110,11 @@ class FluidbookQuote extends ToolboxModel return $this->getAttribute('gclid') ? 'Paid' : 'Organic'; } + public function getUseremailAttribute() + { + return User::find($this->getAttribute('user'))->getAttribute('email'); + } + public function addWidgets() { Widgets::fluidbookQuoteWidgets(); diff --git a/composer.json b/composer.json index 507422c98..04886302e 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,8 @@ "php": ">=8.0", "ext-json": "*", "ext-simplexml": "*", + "ext-dom": "*", + "ext-libxml": "*", "ext-tidy": "*", "ext-zip": "*", "ahmadshah/lucy": "dev-master", @@ -34,7 +36,8 @@ "mxl/laravel-job": "^1.3", "php-ffmpeg/php-ffmpeg": "^0.18.0", "phpoffice/phpspreadsheet": "^1.22", - "rustici-software/scormcloud-api-v2-client-php": "^2.0" + "rustici-software/scormcloud-api-v2-client-php": "^2.0", + }, "require-dev": { "facade/ignition": "^2.17", diff --git a/composer.lock b/composer.lock index 6bce8e607..15c6c5c32 100644 --- a/composer.lock +++ b/composer.lock @@ -4384,16 +4384,16 @@ }, { "name": "laravel/framework", - "version": "v8.83.10", + "version": "v8.83.11", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "148ae59b7da6c3db6736374d357c5aaef9506fb7" + "reference": "d85c34179f209977043502441f9e44ca432a14b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/148ae59b7da6c3db6736374d357c5aaef9506fb7", - "reference": "148ae59b7da6c3db6736374d357c5aaef9506fb7", + "url": "https://api.github.com/repos/laravel/framework/zipball/d85c34179f209977043502441f9e44ca432a14b4", + "reference": "d85c34179f209977043502441f9e44ca432a14b4", "shasum": "" }, "require": { @@ -4553,7 +4553,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-04-27T14:07:37+00:00" + "time": "2022-05-03T14:47:00+00:00" }, { "name": "laravel/serializable-closure", @@ -5703,16 +5703,16 @@ }, { "name": "nesbot/carbon", - "version": "2.57.0", + "version": "2.58.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "4a54375c21eea4811dbd1149fe6b246517554e78" + "reference": "97a34af22bde8d0ac20ab34b29d7bfe360902055" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4a54375c21eea4811dbd1149fe6b246517554e78", - "reference": "4a54375c21eea4811dbd1149fe6b246517554e78", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/97a34af22bde8d0ac20ab34b29d7bfe360902055", + "reference": "97a34af22bde8d0ac20ab34b29d7bfe360902055", "shasum": "" }, "require": { @@ -5730,7 +5730,8 @@ "phpmd/phpmd": "^2.9", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12.54 || ^1.0", - "phpunit/phpunit": "^7.5.20 || ^8.5.14", + "phpunit/php-file-iterator": "^2.0.5", + "phpunit/phpunit": "^7.5.20 || ^8.5.23", "squizlabs/php_codesniffer": "^3.4" }, "bin": [ @@ -5795,7 +5796,7 @@ "type": "tidelift" } ], - "time": "2022-02-13T18:13:33+00:00" + "time": "2022-04-25T19:31:17+00:00" }, { "name": "neutron/temporary-filesystem", @@ -12641,16 +12642,16 @@ }, { "name": "psy/psysh", - "version": "v0.11.2", + "version": "v0.11.3", "source": { "type": "git", "url": "https://github.com/bobthecow/psysh.git", - "reference": "7f7da640d68b9c9fec819caae7c744a213df6514" + "reference": "6833626ee48ef9bcc8aca8f9f166760441c12573" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bobthecow/psysh/zipball/7f7da640d68b9c9fec819caae7c744a213df6514", - "reference": "7f7da640d68b9c9fec819caae7c744a213df6514", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/6833626ee48ef9bcc8aca8f9f166760441c12573", + "reference": "6833626ee48ef9bcc8aca8f9f166760441c12573", "shasum": "" }, "require": { @@ -12665,15 +12666,13 @@ "symfony/console": "4.4.37 || 5.3.14 || 5.3.15 || 5.4.3 || 5.4.4 || 6.0.3 || 6.0.4" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.2", - "hoa/console": "3.17.05.02" + "bamarni/composer-bin-plugin": "^1.2" }, "suggest": { "ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)", "ext-pdo-sqlite": "The doc command requires SQLite to work.", "ext-posix": "If you have PCNTL, you'll want the POSIX extension as well.", - "ext-readline": "Enables support for arrow-key history navigation, and showing and manipulating command history.", - "hoa/console": "A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit." + "ext-readline": "Enables support for arrow-key history navigation, and showing and manipulating command history." }, "bin": [ "bin/psysh" @@ -12713,9 +12712,9 @@ ], "support": { "issues": "https://github.com/bobthecow/psysh/issues", - "source": "https://github.com/bobthecow/psysh/tree/v0.11.2" + "source": "https://github.com/bobthecow/psysh/tree/v0.11.3" }, - "time": "2022-02-28T15:28:54+00:00" + "time": "2022-05-05T02:19:43+00:00" }, { "name": "sebastian/code-unit-reverse-lookup",