|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ScriptsAndStyles |
|
4
|
|
|
* |
|
5
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
|
6
|
|
|
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted to use or copy this program |
|
9
|
|
|
* for any purpose, provided the above notices are retained on all copies. |
|
10
|
|
|
* Permission to modify the code and to distribute modified code is granted, |
|
11
|
|
|
* provided the above notices are retained, and a notice that the code was |
|
12
|
|
|
* modified is included with the above copyright notice. |
|
13
|
|
|
* |
|
14
|
|
|
* @category Wp |
|
15
|
|
|
* @package Punction |
|
16
|
|
|
* @author Andrzej Marcinkowski <[email protected]> |
|
17
|
|
|
* @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz |
|
18
|
|
|
* @license MIT http://opensource.org/licenses/MIT |
|
19
|
|
|
* @version 1.0 $Format:%H$ |
|
20
|
|
|
* @link http:// |
|
21
|
|
|
* @since File available since Release 1.0.0 |
|
22
|
|
|
* PHP Version 5 |
|
23
|
|
|
*/ |
|
24
|
|
|
namespace Hospitalplugin\WP; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* ScriptsAndStyles |
|
28
|
|
|
* |
|
29
|
|
|
* @category Wp |
|
30
|
|
|
* @package Punction |
|
31
|
|
|
* @author Andrzej Marcinkowski <[email protected]> |
|
32
|
|
|
* @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz |
|
33
|
|
|
* @license MIT http://opensource.org/licenses/MIT |
|
34
|
|
|
* @version 1.0 $Format:%H$ |
|
35
|
|
|
* @link http:// |
|
36
|
|
|
* @since File available since Release 1.0.0 |
|
37
|
|
|
* |
|
38
|
|
|
*/ |
|
39
|
|
|
class ScriptsAndStyles |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
private $scripts; |
|
43
|
|
|
|
|
44
|
|
|
private $styles; |
|
45
|
|
|
|
|
46
|
|
|
private $pages; |
|
47
|
|
|
|
|
48
|
|
|
private $path; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* init |
|
52
|
|
|
*/ |
|
53
|
|
|
public function init($path, $pages, $scripts, $styles, $type = 'admin') |
|
54
|
|
|
{ |
|
55
|
|
|
if ($type == 'admin') { |
|
56
|
|
|
$action = 'admin_enqueue_scripts'; |
|
57
|
|
|
} else { |
|
58
|
|
|
$action = 'wp_enqueue_scripts'; |
|
59
|
|
|
} |
|
60
|
|
|
$this->path = $path; |
|
61
|
|
|
$this->pages = $pages; |
|
62
|
|
|
$this->scripts = $scripts; |
|
63
|
|
|
$this->styles = $styles; |
|
64
|
|
|
add_action($action, array( |
|
65
|
|
|
$this, |
|
66
|
|
|
'hospitalPluginStyles' |
|
67
|
|
|
)); |
|
68
|
|
|
add_action($action, array( |
|
69
|
|
|
$this, |
|
70
|
|
|
'hospitalPluginScripts' |
|
71
|
|
|
)); |
|
72
|
|
|
add_action($action, array( |
|
73
|
|
|
$this, |
|
74
|
|
|
'removeCustomScripts' |
|
75
|
|
|
)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* hospitalRegisterStyle |
|
80
|
|
|
* @param $file |
|
81
|
|
|
*/ |
|
82
|
|
|
public function hospitalRegisterStyle($file) |
|
83
|
|
|
{ |
|
84
|
|
|
wp_register_style('hospital_admin_style' . $file, $this->path . '/css/' . $file, array(), '1', 'all'); |
|
85
|
|
|
wp_enqueue_style('hospital_admin_style' . $file); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* hospitalRegisterScript |
|
90
|
|
|
* @param unknown $file |
|
91
|
|
|
* @param unknown $required |
|
92
|
|
|
*/ |
|
93
|
|
|
public function hospitalRegisterScript($file, $required = null, $hook = null) |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
wp_enqueue_script('hospital_admin_script' . $file, $this->path . '/js/' . $file, $required); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* hospitalLocalizeScript |
|
100
|
|
|
* @param unknown $file |
|
101
|
|
|
* @param unknown $data |
|
102
|
|
|
*/ |
|
103
|
|
|
public function hospitalLocalizeScript($file, $data) |
|
104
|
|
|
{ |
|
105
|
|
|
$json_dates = json_encode($data); |
|
106
|
|
|
$params = array( |
|
107
|
|
|
'my_arr' => $json_dates |
|
108
|
|
|
); |
|
109
|
|
|
wp_localize_script('hospital_admin_script' . $file, 'php_params', $params); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* hospitalPluginStyles |
|
114
|
|
|
*/ |
|
115
|
|
|
public function hospitalPluginStyles($hook) |
|
116
|
|
|
{ |
|
117
|
|
|
if (in_array($hook, $this->pages)) { |
|
118
|
|
|
foreach ($this->styles as $style) { |
|
119
|
|
|
self::hospitalRegisterStyle($style); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* hospitalPluginScripts |
|
126
|
|
|
* @param string $hook hook to the page |
|
127
|
|
|
*/ |
|
128
|
|
|
public function hospitalPluginScripts($hook) |
|
129
|
|
|
{ |
|
130
|
|
|
$jQ = array( |
|
131
|
|
|
'jquery' |
|
132
|
|
|
); |
|
133
|
|
|
if (in_array($hook, $this->pages)) { |
|
134
|
|
|
foreach ($this->scripts as $script) { |
|
135
|
|
|
self::hospitalRegisterScript($script, $jQ, $hook); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
*/ |
|
142
|
|
|
public function removeCustomScripts() |
|
143
|
|
|
{ |
|
144
|
|
|
wp_dequeue_style('google-webfonts'); |
|
145
|
|
|
wp_dequeue_script('wplms-events-gmaps-js'); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.