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