AdminerTinymce   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 74
rs 10
wmc 16
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B head() 0 27 5
B selectVal() 0 19 7
A editInput() 0 13 3
1
<?php
2
3
/** Edit all fields containing "_html" by HTML editor TinyMCE and display the HTML in select
4
* @link https://www.adminer.org/plugins/#use
5
* @uses TinyMCE, http://tinymce.moxiecode.com/
6
* @author Jakub Vrana, http://www.vrana.cz/
7
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
8
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
9
*/
10
class AdminerTinymce {
11
	/** @access protected */
12
	var $path;
13
14
	/**
15
	* @param string
16
	*/
17
	function __construct($path = 'tiny_mce/tiny_mce.js') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18
		$this->path = $path;
19
	}
20
21
	function head() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22
		$lang = 'en';
23
		if (function_exists('get_lang')) { // since Adminer 3.2.0
24
			$lang = get_lang();
25
			$lang = ($lang == 'zh' ? 'zh-cn' : ($lang == 'zh-tw' ? 'zh' : $lang));
26
			if (!file_exists(dirname($this->path) . "/langs/$lang.js")) {
27
				$lang = 'en';
28
			}
29
		}
30
		?>
31
<script type="text/javascript" src="<?php echo h($this->path); ?>"></script>
32
<script type="text/javascript">
33
tinyMCE.init({
34
	mode: 'none',
35
	theme: 'advanced',
36
	plugins: 'contextmenu,paste,table',
37
	entity_encoding: 'raw',
38
	theme_advanced_buttons1: 'bold,italic,link,unlink,|,sub,sup,|,bullist,numlist,|,cleanup,code',
39
	theme_advanced_buttons2: 'tablecontrols',
40
	theme_advanced_buttons3: '',
41
	theme_advanced_toolbar_location: 'top',
42
	theme_advanced_toolbar_align: 'left',
43
	language: '<?php echo $lang; ?>'
44
});
45
</script>
46
<?php
47
	}
48
49
	function selectVal(&$val, $link, $field, $original) {
0 ignored issues
show
Unused Code introduced by
The parameter $link is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $original is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
		if (preg_match('~_html~', $field['field']) && $val != '&nbsp;') {
51
			$shortened = (substr($val, -10) == '<i>...</i>');
52
			if ($shortened) {
53
				$val = substr($val, 0, -10);
54
			}
55
			//! shorten with regard to HTML tags - http://php.vrana.cz/zkraceni-textu-s-xhtml-znackami.php
56
			$val = preg_replace('~<[^>]*$~', '', html_entity_decode($val, ENT_QUOTES)); // remove ending incomplete tag (text can be shortened)
57
			if ($shortened) {
58
				$val .= '<i>...</i>';
59
			}
60
			if (class_exists('DOMDocument')) { // close all opened tags
61
				$dom = new DOMDocument;
62
				if (@$dom->loadHTML("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>$val")) { // @ - $val can contain errors
63
					$val = preg_replace('~.*<body[^>]*>(.*)</body>.*~is', '\\1', $dom->saveHTML());
64
				}
65
			}
66
		}
67
	}
68
69
	function editInput($table, $field, $attrs, $value) {
0 ignored issues
show
Unused Code introduced by
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
70
		if (preg_match('~text~', $field['type']) && preg_match('~_html~', $field['field'])) {
71
			return "<textarea$attrs id='fields-" . h($field['field']) . "' rows='12' cols='50'>" . h($value) . "</textarea><script type='text/javascript'>
72
tinyMCE.remove(tinyMCE.get('fields-" . js_escape($field['field']) . "') || { });
73
tinyMCE.execCommand('mceAddControl', true, 'fields-" . js_escape($field['field']) . "');
74
document.getElementById('form').onsubmit = function () {
75
	tinyMCE.each(tinyMCE.editors, function (ed) {
76
		ed.remove();
77
	});
78
};
79
</script>";
80
		}
81
	}
82
83
}
84