Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CiviCRM_Hook | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Utils_Hook_Joomla extends CRM_Utils_Hook { | |
5bc392e6 | 18 | /** |
fe482240 | 19 | * Invoke hooks. |
5bc392e6 | 20 | * |
77855840 TO |
21 | * @param int $numParams |
22 | * Number of parameters to pass to the hook. | |
23 | * @param mixed $arg1 | |
24 | * Parameter to be passed to the hook. | |
25 | * @param mixed $arg2 | |
26 | * Parameter to be passed to the hook. | |
27 | * @param mixed $arg3 | |
28 | * Parameter to be passed to the hook. | |
29 | * @param mixed $arg4 | |
30 | * Parameter to be passed to the hook. | |
31 | * @param mixed $arg5 | |
32 | * Parameter to be passed to the hook. | |
33 | * @param mixed $arg6 | |
34 | * Parameter to be passed to the hook. | |
35 | * @param string $fnSuffix | |
36 | * Function suffix, this is effectively the hook name. | |
5bc392e6 EM |
37 | * |
38 | * @return mixed | |
39 | */ | |
6714d8d2 | 40 | |
5bc392e6 EM |
41 | /** |
42 | * @param int $numParams | |
43 | * @param mixed $arg1 | |
44 | * @param mixed $arg2 | |
45 | * @param mixed $arg3 | |
46 | * @param mixed $arg4 | |
47 | * @param mixed $arg5 | |
48 | * @param mixed $arg6 | |
49 | * @param string $fnSuffix | |
50 | * | |
51 | * @return mixed | |
52 | */ | |
354345c9 | 53 | public function invokeViaUF( |
a3e55d9c | 54 | $numParams, |
353ffa53 TO |
55 | &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, |
56 | $fnSuffix | |
6a488035 TO |
57 | ) { |
58 | // ensure that we are running in a joomla context | |
59 | // we've not yet figured out how to bootstrap joomla, so we should | |
60 | // not execute hooks if joomla is not loaded | |
61 | if (defined('_JEXEC')) { | |
62 | //Invoke the Joomla plugin system to observe to civicrm events. | |
7d875bd6 | 63 | jimport('joomla.plugin.helper'); |
c1f3c6da | 64 | jimport('cms.plugin.helper'); |
6a488035 TO |
65 | JPluginHelper::importPlugin('civicrm'); |
66 | ||
6fde79f5 | 67 | // get app based on cli or web |
7d875bd6 TO |
68 | if (PHP_SAPI != 'cli') { |
69 | $app = JFactory::getApplication('administrator'); | |
6fde79f5 BS |
70 | } |
71 | else { | |
72 | // condition on Joomla version | |
7d875bd6 | 73 | if (version_compare(JVERSION, '3.0', 'lt')) { |
6fde79f5 BS |
74 | $app = JCli::getInstance(); |
75 | } | |
76 | else { | |
77 | $app = JApplicationCli::getInstance(); | |
78 | } | |
6a488035 TO |
79 | } |
80 | ||
87dab4a4 | 81 | $result = $app->triggerEvent($fnSuffix, array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6)); |
6a488035 | 82 | |
7d875bd6 | 83 | $moduleResult = $this->commonInvoke($numParams, |
87dab4a4 | 84 | $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, |
7d875bd6 TO |
85 | $fnSuffix, 'joomla'); |
86 | if (!empty($moduleResult) && is_array($moduleResult)) { | |
87 | if (empty($result)) { | |
88 | $result = $moduleResult; | |
89 | } | |
90 | else { | |
91 | if (is_array($moduleResult)) { | |
92 | $result = array_merge($result, $moduleResult); | |
93 | } | |
94 | } | |
95 | } | |
6a488035 TO |
96 | |
97 | if (!empty($result)) { | |
98 | // collapse result returned from hooks | |
99 | // CRM-9XXX | |
be2fb01f | 100 | $finalResult = []; |
6a488035 TO |
101 | foreach ($result as $res) { |
102 | if (!is_array($res)) { | |
be2fb01f | 103 | $res = [$res]; |
6a488035 TO |
104 | } |
105 | $finalResult = array_merge($finalResult, $res); | |
106 | } | |
107 | $result = $finalResult; | |
108 | } | |
109 | return $result; | |
110 | } | |
35e02b5d JP |
111 | else { |
112 | // CRM-20904: We should still call Civi extension hooks even if Joomla isn't online yet. | |
113 | return $this->commonInvoke($numParams, | |
114 | $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, | |
115 | $fnSuffix, 'joomla'); | |
116 | } | |
6a488035 | 117 | } |
96025800 | 118 | |
6a488035 | 119 | } |