Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

mod/ckeditor/start.php (3 issues)

1
<?php
2
/**
3
 * CKEditor wysiwyg editor
4
 *
5
 * @package ElggCKEditor
6
 */
7
8
/**
9
 * CKEditor init
10
 *
11
 * @return void
12
 */
13
function ckeditor_init() {
14 31
	elgg_extend_view('elgg.css', 'ckeditor.css');
15 31
	elgg_extend_view('admin.css', 'ckeditor.css');
16
17 31
	elgg_extend_view('elgg/wysiwyg.css', 'elements/reset.css', 100);
18 31
	elgg_extend_view('elgg/wysiwyg.css', 'elements/typography.css', 100);
19
20 31
	elgg_define_js('ckeditor/ckeditor', [
21 31
		'exports' => 'CKEDITOR',
22
	]);
23 31
	elgg_define_js('jquery.ckeditor', [
24 31
		'deps' => ['jquery', 'ckeditor/ckeditor'],
25
		'exports' => 'jQuery.fn.ckeditor',
26
	]);
27
28 31
	elgg_extend_view('input/longtext', 'ckeditor/init');
29
30 31
	elgg_register_plugin_hook_handler('register', 'menu:longtext', 'ckeditor_longtext_menu');
31 31
	elgg_register_plugin_hook_handler('view_vars', 'input/longtext', 'ckeditor_longtext_id');
32 31
}
33
34
/**
35
 * Add a menu item to an longtext
36
 *
37
 * @param string         $hook  'register'
38
 * @param string         $type  'menu:longtext'
39
 * @param ElggMenuItem[] $items current return value
40
 * @param array          $vars  supplied params
41
 *
42
 * @return void|ElggMenuItem[]
43
 */
44
function ckeditor_longtext_menu($hook, $type, $items, $vars) {
2 ignored issues
show
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
function ckeditor_longtext_menu($hook, /** @scrutinizer ignore-unused */ $type, $items, $vars) {

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

Loading history...
The parameter $hook is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
function ckeditor_longtext_menu(/** @scrutinizer ignore-unused */ $hook, $type, $items, $vars) {

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

Loading history...
45
46
	$id = elgg_extract('textarea_id', $vars);
47
	if ($id === null) {
48
		return;
49
	}
50
	
51
	$items[] = ElggMenuItem::factory([
52
		'name' => 'ckeditor_toggler',
53
		'link_class' => 'ckeditor-toggle-editor elgg-longtext-control hidden',
54
		'href' => "#{$id}",
55
		'text' => elgg_echo('ckeditor:html'),
56
	]);
57
58
	return $items;
59
}
60
61
/**
62
 * Set an id on input/longtext
63
 *
64
 * @param string $hook   'view_vars'
65
 * @param string $type   'input/longtext'
66
 * @param array  $vars   current return value
67
 * @param array  $params supplied params
68
 *
69
 * @return void|array
70
 */
71
function ckeditor_longtext_id($hook, $type, $vars, $params) {
1 ignored issue
show
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

71
function ckeditor_longtext_id($hook, $type, $vars, /** @scrutinizer ignore-unused */ $params) {

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

Loading history...
72
73
	$id = elgg_extract('id', $vars);
74
	if ($id !== null) {
75
		return;
76
	}
77
	
78
	// input/longtext view vars need to contain an id for editors to be initialized
79
	// random id generator is the same as in input/longtext
80
	$vars['id'] = 'elgg-input-' . base_convert(mt_rand(), 10, 36);
81
82
	return $vars;
83
}
84
85
return function() {
86 18
	elgg_register_event_handler('init', 'system', 'ckeditor_init');
87
};
88