Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CiviCRM_Hook | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | class CRM_Utils_Hook_Joomla extends CRM_Utils_Hook { | |
5bc392e6 | 34 | /** |
fe482240 | 35 | * Invoke hooks. |
5bc392e6 | 36 | * |
77855840 TO |
37 | * @param int $numParams |
38 | * Number of parameters to pass to the hook. | |
39 | * @param mixed $arg1 | |
40 | * Parameter to be passed to the hook. | |
41 | * @param mixed $arg2 | |
42 | * Parameter to be passed to the hook. | |
43 | * @param mixed $arg3 | |
44 | * Parameter to be passed to the hook. | |
45 | * @param mixed $arg4 | |
46 | * Parameter to be passed to the hook. | |
47 | * @param mixed $arg5 | |
48 | * Parameter to be passed to the hook. | |
49 | * @param mixed $arg6 | |
50 | * Parameter to be passed to the hook. | |
51 | * @param string $fnSuffix | |
52 | * Function suffix, this is effectively the hook name. | |
5bc392e6 EM |
53 | * |
54 | * @return mixed | |
55 | */ | |
56 | /** | |
57 | * @param int $numParams | |
58 | * @param mixed $arg1 | |
59 | * @param mixed $arg2 | |
60 | * @param mixed $arg3 | |
61 | * @param mixed $arg4 | |
62 | * @param mixed $arg5 | |
63 | * @param mixed $arg6 | |
64 | * @param string $fnSuffix | |
65 | * | |
66 | * @return mixed | |
67 | */ | |
354345c9 | 68 | public function invokeViaUF( |
a3e55d9c | 69 | $numParams, |
353ffa53 TO |
70 | &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, |
71 | $fnSuffix | |
6a488035 TO |
72 | ) { |
73 | // ensure that we are running in a joomla context | |
74 | // we've not yet figured out how to bootstrap joomla, so we should | |
75 | // not execute hooks if joomla is not loaded | |
76 | if (defined('_JEXEC')) { | |
77 | //Invoke the Joomla plugin system to observe to civicrm events. | |
7d875bd6 | 78 | jimport('joomla.plugin.helper'); |
c1f3c6da | 79 | jimport('cms.plugin.helper'); |
6a488035 TO |
80 | JPluginHelper::importPlugin('civicrm'); |
81 | ||
6fde79f5 | 82 | // get app based on cli or web |
7d875bd6 TO |
83 | if (PHP_SAPI != 'cli') { |
84 | $app = JFactory::getApplication('administrator'); | |
6fde79f5 BS |
85 | } |
86 | else { | |
87 | // condition on Joomla version | |
7d875bd6 | 88 | if (version_compare(JVERSION, '3.0', 'lt')) { |
6fde79f5 BS |
89 | $app = JCli::getInstance(); |
90 | } | |
91 | else { | |
92 | $app = JApplicationCli::getInstance(); | |
93 | } | |
6a488035 TO |
94 | } |
95 | ||
87dab4a4 | 96 | $result = $app->triggerEvent($fnSuffix, array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6)); |
6a488035 | 97 | |
7d875bd6 | 98 | $moduleResult = $this->commonInvoke($numParams, |
87dab4a4 | 99 | $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, |
7d875bd6 TO |
100 | $fnSuffix, 'joomla'); |
101 | if (!empty($moduleResult) && is_array($moduleResult)) { | |
102 | if (empty($result)) { | |
103 | $result = $moduleResult; | |
104 | } | |
105 | else { | |
106 | if (is_array($moduleResult)) { | |
107 | $result = array_merge($result, $moduleResult); | |
108 | } | |
109 | } | |
110 | } | |
6a488035 TO |
111 | |
112 | if (!empty($result)) { | |
113 | // collapse result returned from hooks | |
114 | // CRM-9XXX | |
115 | $finalResult = array(); | |
116 | foreach ($result as $res) { | |
117 | if (!is_array($res)) { | |
118 | $res = array($res); | |
119 | } | |
120 | $finalResult = array_merge($finalResult, $res); | |
121 | } | |
122 | $result = $finalResult; | |
123 | } | |
124 | return $result; | |
125 | } | |
35e02b5d JP |
126 | else { |
127 | // CRM-20904: We should still call Civi extension hooks even if Joomla isn't online yet. | |
128 | return $this->commonInvoke($numParams, | |
129 | $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, | |
130 | $fnSuffix, 'joomla'); | |
131 | } | |
6a488035 | 132 | } |
96025800 | 133 | |
6a488035 | 134 | } |