Completed
Branch master (48c558)
by
unknown
05:41
created

Tinymce::renderStart()   B

Complexity

Conditions 5
Paths 3

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 20
Code Lines 11

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 3
nop 0
1
<?php
2
namespace Redaxscript\Modules\Tinymce;
3
4
use Redaxscript\Head;
5
6
/**
7
 * javascript powered wysiwyg editor
8
 *
9
 * @since 3.0.0
10
 *
11
 * @package Redaxscript
12
 * @category Modules
13
 * @author Henry Ruhs
14
 */
15
16
class Tinymce extends Config
17
{
18
	/**
19
	 * array of the module
20
	 *
21
	 * @var array
22
	 */
23
24
	protected static $_moduleArray =
25
	[
26
		'name' => 'Tinymce',
27
		'alias' => 'Tinymce',
28
		'author' => 'Redaxmedia',
29
		'description' => 'JavaScript powered WYSIWYG editor',
30
		'version' => '3.0.0',
31
		'access' => '1'
32
	];
33
34
	/**
35
	 * renderStart
36
	 *
37
	 * @since 3.0.0
38
	 */
39
40
	public function renderStart()
41
	{
42
		if ($this->_registry->get('loggedIn') === $this->_registry->get('token'))
43
		{
44
			$script = Head\Script::getInstance();
45
			$script
46
				->init('foot')
47
				->appendFile('//cdnjs.cloudflare.com/ajax/libs/tinymce/4.4.1/tinymce.min.js')
48
				->appendFile('modules/Tinymce/assets/scripts/init.js')
49
				->appendFile('modules/Tinymce/dist/scripts/tinymce.min.js');
50
51
			/* upload */
52
53
			if ($this->_registry->get('firstParameter') === 'tinymce' && $this->_registry->get('secondParameter') === 'upload' && $this->_registry->get('lastParameter') === $this->_registry->get('token'))
54
			{
55
				$this->_registry->set('renderBreak', true);
56
				echo $this->_upload();
57
			}
58
		}
59
	}
60
61
	/**
62
	 * adminPanelNotification
63
	 *
64
	 * @since 3.0.0
65
	 *
66
	 * @return array
67
	 */
68
69
	public function adminPanelNotification()
70
	{
71
		if (!is_dir($this->_configArray['uploadDirectory']))
72
		{
73
			$this->setNotification('error', $this->_language->get('directory_not_found') . $this->_language->get('colon') . ' ' . $this->_configArray['uploadDirectory'] . $this->_language->get('point'));
74
		}
75
		else if (!chmod($this->_configArray['uploadDirectory'], 0777))
76
		{
77
			$this->setNotification('error', $this->_language->get('directory_permission_grant') . $this->_language->get('colon') . ' ' . $this->_configArray['uploadDirectory']  . $this->_language->get('point'));
78
		}
79
		return $this->getNotification();
80
	}
81
82
	/**
83
	 * upload
84
	 *
85
	 * @since 3.0.0
86
	 */
87
88
	protected function _upload()
89
	{
90
		$filesArray = current($this->_request->getFiles());
91
92
		/* upload file */
93
94
		if (is_uploaded_file($filesArray['tmp_name']))
95
		{
96
			if (move_uploaded_file($filesArray['tmp_name'], $this->_configArray['uploadDirectory'] . '/' . $filesArray['name']))
97
			{
98
				return json_encode(
99
				[
100
					'location' => $this->_configArray['uploadDirectory'] . '/' . $filesArray['name']
101
				]);
102
			}
103
		}
104
		header('http/1.0 404 not found');
105
	}
106
}
107