Commit | Line | Data |
---|---|---|
301b8b4b SL |
1 | <?php |
2 | ||
3 | // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file | |
4 | ||
5 | /** | |
6 | * The ExtensionUtil class provides small stubs for accessing resources of this | |
7 | * extension. | |
8 | */ | |
9 | class CRM_Ckeditor4_ExtensionUtil { | |
10 | const SHORT_NAME = 'ckeditor4'; | |
11 | const LONG_NAME = 'ckeditor4'; | |
12 | const CLASS_PREFIX = 'CRM_Ckeditor4'; | |
13 | ||
14 | /** | |
15 | * Translate a string using the extension's domain. | |
16 | * | |
17 | * If the extension doesn't have a specific translation | |
18 | * for the string, fallback to the default translations. | |
19 | * | |
20 | * @param string $text | |
21 | * Canonical message text (generally en_US). | |
22 | * @param array $params | |
23 | * @return string | |
24 | * Translated text. | |
25 | * @see ts | |
26 | */ | |
27 | public static function ts($text, $params = []) { | |
28 | if (!array_key_exists('domain', $params)) { | |
29 | $params['domain'] = [self::LONG_NAME, NULL]; | |
30 | } | |
31 | return ts($text, $params); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Get the URL of a resource file (in this extension). | |
36 | * | |
37 | * @param string|NULL $file | |
38 | * Ex: NULL. | |
39 | * Ex: 'css/foo.css'. | |
40 | * @return string | |
41 | * Ex: 'http://example.org/sites/default/ext/org.example.foo'. | |
42 | * Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'. | |
43 | */ | |
44 | public static function url($file = NULL) { | |
45 | if ($file === NULL) { | |
46 | return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/'); | |
47 | } | |
48 | return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file); | |
49 | } | |
50 | ||
51 | /** | |
52 | * Get the path of a resource file (in this extension). | |
53 | * | |
54 | * @param string|NULL $file | |
55 | * Ex: NULL. | |
56 | * Ex: 'css/foo.css'. | |
57 | * @return string | |
58 | * Ex: '/var/www/example.org/sites/default/ext/org.example.foo'. | |
59 | * Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'. | |
60 | */ | |
61 | public static function path($file = NULL) { | |
62 | // return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file); | |
63 | return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file)); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Get the name of a class within this extension. | |
68 | * | |
69 | * @param string $suffix | |
70 | * Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'. | |
71 | * @return string | |
72 | * Ex: 'CRM_Foo_Page_HelloWorld'. | |
73 | */ | |
74 | public static function findClass($suffix) { | |
75 | return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix); | |
76 | } | |
77 | ||
78 | } | |
79 | ||
80 | use CRM_Ckeditor4_ExtensionUtil as E; | |
81 | ||
82 | /** | |
83 | * (Delegated) Implements hook_civicrm_config(). | |
84 | * | |
85 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config | |
86 | */ | |
87 | function _ckeditor4_civix_civicrm_config(&$config = NULL) { | |
88 | static $configured = FALSE; | |
89 | if ($configured) { | |
90 | return; | |
91 | } | |
92 | $configured = TRUE; | |
93 | ||
94 | $template =& CRM_Core_Smarty::singleton(); | |
95 | ||
96 | $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR; | |
97 | $extDir = $extRoot . 'templates'; | |
98 | ||
99 | if (is_array($template->template_dir)) { | |
100 | array_unshift($template->template_dir, $extDir); | |
101 | } | |
102 | else { | |
103 | $template->template_dir = [$extDir, $template->template_dir]; | |
104 | } | |
105 | ||
106 | $include_path = $extRoot . PATH_SEPARATOR . get_include_path(); | |
107 | set_include_path($include_path); | |
108 | } | |
109 | ||
110 | /** | |
111 | * (Delegated) Implements hook_civicrm_xmlMenu(). | |
112 | * | |
113 | * @param $files array(string) | |
114 | * | |
115 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu | |
116 | */ | |
117 | function _ckeditor4_civix_civicrm_xmlMenu(&$files) { | |
118 | foreach (_ckeditor4_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) { | |
119 | $files[] = $file; | |
120 | } | |
121 | } | |
122 | ||
123 | /** | |
124 | * Implements hook_civicrm_install(). | |
125 | * | |
126 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install | |
127 | */ | |
128 | function _ckeditor4_civix_civicrm_install() { | |
129 | _ckeditor4_civix_civicrm_config(); | |
130 | if ($upgrader = _ckeditor4_civix_upgrader()) { | |
131 | $upgrader->onInstall(); | |
132 | } | |
133 | } | |
134 | ||
135 | /** | |
136 | * Implements hook_civicrm_postInstall(). | |
137 | * | |
138 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall | |
139 | */ | |
140 | function _ckeditor4_civix_civicrm_postInstall() { | |
141 | _ckeditor4_civix_civicrm_config(); | |
142 | if ($upgrader = _ckeditor4_civix_upgrader()) { | |
143 | if (is_callable([$upgrader, 'onPostInstall'])) { | |
144 | $upgrader->onPostInstall(); | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | /** | |
150 | * Implements hook_civicrm_uninstall(). | |
151 | * | |
152 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall | |
153 | */ | |
154 | function _ckeditor4_civix_civicrm_uninstall() { | |
155 | _ckeditor4_civix_civicrm_config(); | |
156 | if ($upgrader = _ckeditor4_civix_upgrader()) { | |
157 | $upgrader->onUninstall(); | |
158 | } | |
159 | } | |
160 | ||
161 | /** | |
162 | * (Delegated) Implements hook_civicrm_enable(). | |
163 | * | |
164 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable | |
165 | */ | |
166 | function _ckeditor4_civix_civicrm_enable() { | |
167 | _ckeditor4_civix_civicrm_config(); | |
168 | if ($upgrader = _ckeditor4_civix_upgrader()) { | |
169 | if (is_callable([$upgrader, 'onEnable'])) { | |
170 | $upgrader->onEnable(); | |
171 | } | |
172 | } | |
173 | } | |
174 | ||
175 | /** | |
176 | * (Delegated) Implements hook_civicrm_disable(). | |
177 | * | |
178 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable | |
179 | * @return mixed | |
180 | */ | |
181 | function _ckeditor4_civix_civicrm_disable() { | |
182 | _ckeditor4_civix_civicrm_config(); | |
183 | if ($upgrader = _ckeditor4_civix_upgrader()) { | |
184 | if (is_callable([$upgrader, 'onDisable'])) { | |
185 | $upgrader->onDisable(); | |
186 | } | |
187 | } | |
188 | } | |
189 | ||
190 | /** | |
191 | * (Delegated) Implements hook_civicrm_upgrade(). | |
192 | * | |
193 | * @param $op string, the type of operation being performed; 'check' or 'enqueue' | |
194 | * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks | |
195 | * | |
196 | * @return mixed | |
197 | * based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending) | |
198 | * for 'enqueue', returns void | |
199 | * | |
200 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade | |
201 | */ | |
202 | function _ckeditor4_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { | |
203 | if ($upgrader = _ckeditor4_civix_upgrader()) { | |
204 | return $upgrader->onUpgrade($op, $queue); | |
205 | } | |
206 | } | |
207 | ||
208 | /** | |
209 | * @return CRM_Ckeditor4_Upgrader | |
210 | */ | |
211 | function _ckeditor4_civix_upgrader() { | |
212 | if (!file_exists(__DIR__ . '/CRM/Ckeditor4/Upgrader.php')) { | |
213 | return NULL; | |
214 | } | |
215 | else { | |
216 | return CRM_Ckeditor4_Upgrader_Base::instance(); | |
217 | } | |
218 | } | |
219 | ||
220 | /** | |
221 | * Search directory tree for files which match a glob pattern. | |
222 | * | |
223 | * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored. | |
224 | * Note: Delegate to CRM_Utils_File::findFiles(), this function kept only | |
225 | * for backward compatibility of extension code that uses it. | |
226 | * | |
227 | * @param string $dir base dir | |
228 | * @param string $pattern , glob pattern, eg "*.txt" | |
229 | * | |
230 | * @return array | |
231 | */ | |
232 | function _ckeditor4_civix_find_files($dir, $pattern) { | |
233 | return CRM_Utils_File::findFiles($dir, $pattern); | |
234 | } | |
235 | ||
236 | /** | |
237 | * (Delegated) Implements hook_civicrm_managed(). | |
238 | * | |
239 | * Find any *.mgd.php files, merge their content, and return. | |
240 | * | |
241 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed | |
242 | */ | |
243 | function _ckeditor4_civix_civicrm_managed(&$entities) { | |
244 | $mgdFiles = _ckeditor4_civix_find_files(__DIR__, '*.mgd.php'); | |
245 | sort($mgdFiles); | |
246 | foreach ($mgdFiles as $file) { | |
247 | $es = include $file; | |
248 | foreach ($es as $e) { | |
249 | if (empty($e['module'])) { | |
250 | $e['module'] = E::LONG_NAME; | |
251 | } | |
252 | if (empty($e['params']['version'])) { | |
253 | $e['params']['version'] = '3'; | |
254 | } | |
255 | $entities[] = $e; | |
256 | } | |
257 | } | |
258 | } | |
259 | ||
260 | /** | |
261 | * (Delegated) Implements hook_civicrm_caseTypes(). | |
262 | * | |
263 | * Find any and return any files matching "xml/case/*.xml" | |
264 | * | |
265 | * Note: This hook only runs in CiviCRM 4.4+. | |
266 | * | |
267 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes | |
268 | */ | |
269 | function _ckeditor4_civix_civicrm_caseTypes(&$caseTypes) { | |
270 | if (!is_dir(__DIR__ . '/xml/case')) { | |
271 | return; | |
272 | } | |
273 | ||
274 | foreach (_ckeditor4_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) { | |
275 | $name = preg_replace('/\.xml$/', '', basename($file)); | |
276 | if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) { | |
277 | $errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name)); | |
278 | throw new CRM_Core_Exception($errorMessage); | |
279 | } | |
280 | $caseTypes[$name] = [ | |
281 | 'module' => E::LONG_NAME, | |
282 | 'name' => $name, | |
283 | 'file' => $file, | |
284 | ]; | |
285 | } | |
286 | } | |
287 | ||
288 | /** | |
289 | * (Delegated) Implements hook_civicrm_angularModules(). | |
290 | * | |
291 | * Find any and return any files matching "ang/*.ang.php" | |
292 | * | |
293 | * Note: This hook only runs in CiviCRM 4.5+. | |
294 | * | |
295 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules | |
296 | */ | |
297 | function _ckeditor4_civix_civicrm_angularModules(&$angularModules) { | |
298 | if (!is_dir(__DIR__ . '/ang')) { | |
299 | return; | |
300 | } | |
301 | ||
302 | $files = _ckeditor4_civix_glob(__DIR__ . '/ang/*.ang.php'); | |
303 | foreach ($files as $file) { | |
304 | $name = preg_replace(':\.ang\.php$:', '', basename($file)); | |
305 | $module = include $file; | |
306 | if (empty($module['ext'])) { | |
307 | $module['ext'] = E::LONG_NAME; | |
308 | } | |
309 | $angularModules[$name] = $module; | |
310 | } | |
311 | } | |
312 | ||
313 | /** | |
314 | * (Delegated) Implements hook_civicrm_themes(). | |
315 | * | |
316 | * Find any and return any files matching "*.theme.php" | |
317 | */ | |
318 | function _ckeditor4_civix_civicrm_themes(&$themes) { | |
319 | $files = _ckeditor4_civix_glob(__DIR__ . '/*.theme.php'); | |
320 | foreach ($files as $file) { | |
321 | $themeMeta = include $file; | |
322 | if (empty($themeMeta['name'])) { | |
323 | $themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file)); | |
324 | } | |
325 | if (empty($themeMeta['ext'])) { | |
326 | $themeMeta['ext'] = E::LONG_NAME; | |
327 | } | |
328 | $themes[$themeMeta['name']] = $themeMeta; | |
329 | } | |
330 | } | |
331 | ||
332 | /** | |
333 | * Glob wrapper which is guaranteed to return an array. | |
334 | * | |
335 | * The documentation for glob() says, "On some systems it is impossible to | |
336 | * distinguish between empty match and an error." Anecdotally, the return | |
337 | * result for an empty match is sometimes array() and sometimes FALSE. | |
338 | * This wrapper provides consistency. | |
339 | * | |
340 | * @link http://php.net/glob | |
341 | * @param string $pattern | |
342 | * | |
343 | * @return array | |
344 | */ | |
345 | function _ckeditor4_civix_glob($pattern) { | |
346 | $result = glob($pattern); | |
347 | return is_array($result) ? $result : []; | |
348 | } | |
349 | ||
350 | /** | |
351 | * Inserts a navigation menu item at a given place in the hierarchy. | |
352 | * | |
353 | * @param array $menu - menu hierarchy | |
354 | * @param string $path - path to parent of this item, e.g. 'my_extension/submenu' | |
355 | * 'Mailing', or 'Administer/System Settings' | |
356 | * @param array $item - the item to insert (parent/child attributes will be | |
357 | * filled for you) | |
358 | * | |
359 | * @return bool | |
360 | */ | |
361 | function _ckeditor4_civix_insert_navigation_menu(&$menu, $path, $item) { | |
362 | // If we are done going down the path, insert menu | |
363 | if (empty($path)) { | |
364 | $menu[] = [ | |
365 | 'attributes' => array_merge([ | |
366 | 'label' => CRM_Utils_Array::value('name', $item), | |
367 | 'active' => 1, | |
368 | ], $item), | |
369 | ]; | |
370 | return TRUE; | |
371 | } | |
372 | else { | |
373 | // Find an recurse into the next level down | |
374 | $found = FALSE; | |
375 | $path = explode('/', $path); | |
376 | $first = array_shift($path); | |
377 | foreach ($menu as $key => &$entry) { | |
378 | if ($entry['attributes']['name'] == $first) { | |
379 | if (!isset($entry['child'])) { | |
380 | $entry['child'] = []; | |
381 | } | |
382 | $found = _ckeditor4_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item); | |
383 | } | |
384 | } | |
385 | return $found; | |
386 | } | |
387 | } | |
388 | ||
389 | /** | |
390 | * (Delegated) Implements hook_civicrm_navigationMenu(). | |
391 | */ | |
392 | function _ckeditor4_civix_navigationMenu(&$nodes) { | |
393 | if (!is_callable(['CRM_Core_BAO_Navigation', 'fixNavigationMenu'])) { | |
394 | _ckeditor4_civix_fixNavigationMenu($nodes); | |
395 | } | |
396 | } | |
397 | ||
398 | /** | |
399 | * Given a navigation menu, generate navIDs for any items which are | |
400 | * missing them. | |
401 | */ | |
402 | function _ckeditor4_civix_fixNavigationMenu(&$nodes) { | |
403 | $maxNavID = 1; | |
404 | array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) { | |
405 | if ($key === 'navID') { | |
406 | $maxNavID = max($maxNavID, $item); | |
407 | } | |
408 | }); | |
409 | _ckeditor4_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL); | |
410 | } | |
411 | ||
412 | function _ckeditor4_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) { | |
413 | $origKeys = array_keys($nodes); | |
414 | foreach ($origKeys as $origKey) { | |
415 | if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) { | |
416 | $nodes[$origKey]['attributes']['parentID'] = $parentID; | |
417 | } | |
418 | // If no navID, then assign navID and fix key. | |
419 | if (!isset($nodes[$origKey]['attributes']['navID'])) { | |
420 | $newKey = ++$maxNavID; | |
421 | $nodes[$origKey]['attributes']['navID'] = $newKey; | |
422 | $nodes[$newKey] = $nodes[$origKey]; | |
423 | unset($nodes[$origKey]); | |
424 | $origKey = $newKey; | |
425 | } | |
426 | if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) { | |
427 | _ckeditor4_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']); | |
428 | } | |
429 | } | |
430 | } | |
431 | ||
432 | /** | |
433 | * (Delegated) Implements hook_civicrm_alterSettingsFolders(). | |
434 | * | |
435 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders | |
436 | */ | |
437 | function _ckeditor4_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { | |
438 | $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings'; | |
439 | if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) { | |
440 | $metaDataFolders[] = $settingsDir; | |
441 | } | |
442 | } | |
443 | ||
444 | /** | |
445 | * (Delegated) Implements hook_civicrm_entityTypes(). | |
446 | * | |
447 | * Find any *.entityType.php files, merge their content, and return. | |
448 | * | |
449 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes | |
450 | */ | |
451 | function _ckeditor4_civix_civicrm_entityTypes(&$entityTypes) { | |
452 | $entityTypes = array_merge($entityTypes, []); | |
453 | } |