INFRA-132 - Change "else if" to "elseif"
[civicrm-core.git] / CRM / Utils / Hook / Joomla.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
33 * $Id: $
34 *
35 */
36 class CRM_Utils_Hook_Joomla extends CRM_Utils_Hook {
37 /**
38 * Invoke hooks
39 *
40 * @param int $numParams
41 * Number of parameters to pass to the hook.
42 * @param mixed $arg1
43 * Parameter to be passed to the hook.
44 * @param mixed $arg2
45 * Parameter to be passed to the hook.
46 * @param mixed $arg3
47 * Parameter to be passed to the hook.
48 * @param mixed $arg4
49 * Parameter to be passed to the hook.
50 * @param mixed $arg5
51 * Parameter to be passed to the hook.
52 * @param mixed $arg6
53 * Parameter to be passed to the hook.
54 * @param string $fnSuffix
55 * Function suffix, this is effectively the hook name.
56 *
57 * @return mixed
58 */
59 /**
60 * @param int $numParams
61 * @param mixed $arg1
62 * @param mixed $arg2
63 * @param mixed $arg3
64 * @param mixed $arg4
65 * @param mixed $arg5
66 * @param mixed $arg6
67 * @param string $fnSuffix
68 *
69 * @return mixed
70 */
71 function invoke(
72 $numParams,
73 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
74 $fnSuffix
75 ) {
76 // ensure that we are running in a joomla context
77 // we've not yet figured out how to bootstrap joomla, so we should
78 // not execute hooks if joomla is not loaded
79 if (defined('_JEXEC')) {
80 //Invoke the Joomla plugin system to observe to civicrm events.
81 jimport('joomla.plugin.helper');
82 jimport('cms.plugin.helper');
83 JPluginHelper::importPlugin('civicrm');
84
85 // get app based on cli or web
86 if (PHP_SAPI != 'cli') {
87 $app = JFactory::getApplication('administrator');
88 }
89 else {
90 // condition on Joomla version
91 if (version_compare(JVERSION, '3.0', 'lt')) {
92 $app = JCli::getInstance();
93 }
94 else {
95 $app = JApplicationCli::getInstance();
96 }
97 }
98
99 $result = $app->triggerEvent($fnSuffix, array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6));
100
101 $moduleResult = $this->commonInvoke($numParams,
102 $arg1, $arg2, $arg3, $arg4, $arg5, $arg6,
103 $fnSuffix, 'joomla');
104 if (!empty($moduleResult) && is_array($moduleResult)) {
105 if (empty($result)) {
106 $result = $moduleResult;
107 }
108 else {
109 if (is_array($moduleResult)) {
110 $result = array_merge($result, $moduleResult);
111 }
112 }
113 }
114
115 if (!empty($result)) {
116 // collapse result returned from hooks
117 // CRM-9XXX
118 $finalResult = array();
119 foreach ($result as $res) {
120 if (!is_array($res)) {
121 $res = array($res);
122 }
123 $finalResult = array_merge($finalResult, $res);
124 }
125 $result = $finalResult;
126 }
127 return $result;
128 }
129 }
130 }