Merge pull request #15666 from revati90/shared_address
[civicrm-core.git] / CRM / Utils / Hook / Joomla.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
f299f7db 6 | Copyright CiviCRM LLC (c) 2004-2020 |
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
f299f7db 31 * @copyright CiviCRM LLC (c) 2004-2020
6a488035
TO
32 */
33class 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 */
6714d8d2 56
5bc392e6
EM
57 /**
58 * @param int $numParams
59 * @param mixed $arg1
60 * @param mixed $arg2
61 * @param mixed $arg3
62 * @param mixed $arg4
63 * @param mixed $arg5
64 * @param mixed $arg6
65 * @param string $fnSuffix
66 *
67 * @return mixed
68 */
354345c9 69 public function invokeViaUF(
a3e55d9c 70 $numParams,
353ffa53
TO
71 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
72 $fnSuffix
6a488035
TO
73 ) {
74 // ensure that we are running in a joomla context
75 // we've not yet figured out how to bootstrap joomla, so we should
76 // not execute hooks if joomla is not loaded
77 if (defined('_JEXEC')) {
78 //Invoke the Joomla plugin system to observe to civicrm events.
7d875bd6 79 jimport('joomla.plugin.helper');
c1f3c6da 80 jimport('cms.plugin.helper');
6a488035
TO
81 JPluginHelper::importPlugin('civicrm');
82
6fde79f5 83 // get app based on cli or web
7d875bd6
TO
84 if (PHP_SAPI != 'cli') {
85 $app = JFactory::getApplication('administrator');
6fde79f5
BS
86 }
87 else {
88 // condition on Joomla version
7d875bd6 89 if (version_compare(JVERSION, '3.0', 'lt')) {
6fde79f5
BS
90 $app = JCli::getInstance();
91 }
92 else {
93 $app = JApplicationCli::getInstance();
94 }
6a488035
TO
95 }
96
87dab4a4 97 $result = $app->triggerEvent($fnSuffix, array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6));
6a488035 98
7d875bd6 99 $moduleResult = $this->commonInvoke($numParams,
87dab4a4 100 $arg1, $arg2, $arg3, $arg4, $arg5, $arg6,
7d875bd6
TO
101 $fnSuffix, 'joomla');
102 if (!empty($moduleResult) && is_array($moduleResult)) {
103 if (empty($result)) {
104 $result = $moduleResult;
105 }
106 else {
107 if (is_array($moduleResult)) {
108 $result = array_merge($result, $moduleResult);
109 }
110 }
111 }
6a488035
TO
112
113 if (!empty($result)) {
114 // collapse result returned from hooks
115 // CRM-9XXX
be2fb01f 116 $finalResult = [];
6a488035
TO
117 foreach ($result as $res) {
118 if (!is_array($res)) {
be2fb01f 119 $res = [$res];
6a488035
TO
120 }
121 $finalResult = array_merge($finalResult, $res);
122 }
123 $result = $finalResult;
124 }
125 return $result;
126 }
35e02b5d
JP
127 else {
128 // CRM-20904: We should still call Civi extension hooks even if Joomla isn't online yet.
129 return $this->commonInvoke($numParams,
130 $arg1, $arg2, $arg3, $arg4, $arg5, $arg6,
131 $fnSuffix, 'joomla');
132 }
6a488035 133 }
96025800 134
6a488035 135}