-
Notifications
You must be signed in to change notification settings - Fork 3
/
Tinymce.php
99 lines (83 loc) · 3.17 KB
/
Tinymce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tinymce;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\Filesystem\Filesystem;
use Thelia\Action\Document;
use Thelia\Model\ConfigQuery;
use Thelia\Module\BaseModule;
class Tinymce extends BaseModule
{
/** The module domain for internationalisation */
public const MODULE_DOMAIN = 'tinymce';
private $jsPath;
private $webJsPath;
private $webMediaPath;
private $webMediaEnvPath;
public function __construct()
{
$this->jsPath = __DIR__.DS.'Resources'.DS.'js'.DS.'tinymce';
$this->webJsPath = THELIA_WEB_DIR.'tinymce';
$this->webMediaPath = THELIA_WEB_DIR.'media';
}
public function postActivation(ConnectionInterface $con = null): void
{
$fileSystem = new Filesystem();
// Check for environment
if ($env = $this->getContainer()->getParameter('kernel.environment')) {
// Check for backward compatibility
if ($env !== 'prod' && $env !== 'dev') {
// Remove separtion between dev and prod in particular environment
$env = str_replace('_dev', '', $env);
$this->webMediaEnvPath = $this->webMediaPath.DS.$env;
}
}
// Create symbolic links or hard copy in the web directory
// (according to \Thelia\Action\Document::CONFIG_DELIVERY_MODE),
// to make the TinyMCE code available.
if (false === $fileSystem->exists($this->webJsPath)) {
if (ConfigQuery::read(Document::CONFIG_DELIVERY_MODE) === 'symlink') {
$fileSystem->symlink($this->jsPath, $this->webJsPath);
} else {
$fileSystem->mirror($this->jsPath, $this->webJsPath);
}
}
// Create the media directory in the web root , if required
if (null !== $this->webMediaEnvPath) {
if (false === $fileSystem->exists($this->webMediaEnvPath)) {
$fileSystem->mkdir($this->webMediaEnvPath.DS.'upload');
$fileSystem->mkdir($this->webMediaEnvPath.DS.'thumbs');
}
} else {
if (false === $fileSystem->exists($this->webMediaPath)) {
$fileSystem->mkdir($this->webMediaPath.DS.'upload');
$fileSystem->mkdir($this->webMediaPath.DS.'thumbs');
}
}
static::setConfigValue(
'available_text_areas',
'#timymce_configuration-id-test_zone, .wysiwyg'
);
}
public function postDeactivation(ConnectionInterface $con = null): void
{
$fileSystem = new Filesystem();
$fileSystem->remove($this->webJsPath);
}
public function destroy(ConnectionInterface $con = null, $deleteModuleData = false): void
{
// If we have to delete module data, remove the media directory.
if ($deleteModuleData) {
$fileSystem = new Filesystem();
$fileSystem->remove($this->webMediaPath);
}
}
}