Merge pull request #15785 from eileenmcnaughton/contribution_url_params
[civicrm-core.git] / CRM / Utils / Hook / Joomla.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CiviCRM_Hook
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Utils_Hook_Joomla extends CRM_Utils_Hook {
18 /**
19 * Invoke hooks.
20 *
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.
37 *
38 * @return mixed
39 */
40
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 */
53 public function invokeViaUF(
54 $numParams,
55 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
56 $fnSuffix
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.
63 jimport('joomla.plugin.helper');
64 jimport('cms.plugin.helper');
65 JPluginHelper::importPlugin('civicrm');
66
67 // get app based on cli or web
68 if (PHP_SAPI != 'cli') {
69 $app = JFactory::getApplication('administrator');
70 }
71 else {
72 // condition on Joomla version
73 if (version_compare(JVERSION, '3.0', 'lt')) {
74 $app = JCli::getInstance();
75 }
76 else {
77 $app = JApplicationCli::getInstance();
78 }
79 }
80
81 $result = $app->triggerEvent($fnSuffix, array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6));
82
83 $moduleResult = $this->commonInvoke($numParams,
84 $arg1, $arg2, $arg3, $arg4, $arg5, $arg6,
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 }
96
97 if (!empty($result)) {
98 // collapse result returned from hooks
99 // CRM-9XXX
100 $finalResult = [];
101 foreach ($result as $res) {
102 if (!is_array($res)) {
103 $res = [$res];
104 }
105 $finalResult = array_merge($finalResult, $res);
106 }
107 $result = $finalResult;
108 }
109 return $result;
110 }
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 }
117 }
118
119 }