Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
232624b1 | 5 | | CiviCRM version 4.4 | |
6a488035 TO |
6 | +--------------------------------------------------------------------+ |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id: $ | |
34 | * | |
35 | */ | |
36 | class CRM_Utils_Hook_Joomla extends CRM_Utils_Hook { | |
37 | function invoke($numParams, | |
301258d0 | 38 | &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, |
7d875bd6 | 39 | $fnSuffix |
6a488035 TO |
40 | ) { |
41 | // ensure that we are running in a joomla context | |
42 | // we've not yet figured out how to bootstrap joomla, so we should | |
43 | // not execute hooks if joomla is not loaded | |
44 | if (defined('_JEXEC')) { | |
45 | //Invoke the Joomla plugin system to observe to civicrm events. | |
7d875bd6 | 46 | jimport('joomla.plugin.helper'); |
c1f3c6da | 47 | jimport('cms.plugin.helper'); |
6a488035 TO |
48 | JPluginHelper::importPlugin('civicrm'); |
49 | ||
6fde79f5 | 50 | // get app based on cli or web |
7d875bd6 TO |
51 | if (PHP_SAPI != 'cli') { |
52 | $app = JFactory::getApplication('administrator'); | |
6fde79f5 BS |
53 | } |
54 | else { | |
55 | // condition on Joomla version | |
7d875bd6 | 56 | if (version_compare(JVERSION, '3.0', 'lt')) { |
6fde79f5 BS |
57 | $app = JCli::getInstance(); |
58 | } | |
59 | else { | |
60 | $app = JApplicationCli::getInstance(); | |
61 | } | |
6a488035 TO |
62 | } |
63 | ||
87dab4a4 | 64 | $result = $app->triggerEvent($fnSuffix, array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6)); |
6a488035 | 65 | |
7d875bd6 | 66 | $moduleResult = $this->commonInvoke($numParams, |
87dab4a4 | 67 | $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, |
7d875bd6 TO |
68 | $fnSuffix, 'joomla'); |
69 | if (!empty($moduleResult) && is_array($moduleResult)) { | |
70 | if (empty($result)) { | |
71 | $result = $moduleResult; | |
72 | } | |
73 | else { | |
74 | if (is_array($moduleResult)) { | |
75 | $result = array_merge($result, $moduleResult); | |
76 | } | |
77 | } | |
78 | } | |
6a488035 TO |
79 | |
80 | if (!empty($result)) { | |
81 | // collapse result returned from hooks | |
82 | // CRM-9XXX | |
83 | $finalResult = array(); | |
84 | foreach ($result as $res) { | |
85 | if (!is_array($res)) { | |
86 | $res = array($res); | |
87 | } | |
88 | $finalResult = array_merge($finalResult, $res); | |
89 | } | |
90 | $result = $finalResult; | |
91 | } | |
92 | return $result; | |
93 | } | |
94 | } | |
6a488035 TO |
95 | } |
96 |