added a block of code to help debug fraud details
[trustcommerce.git] / trustcommerce.civix.php
1 <?php
2
3 // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
4
5 /**
6 * The ExtensionUtil class provides small stubs for accessing resources of this
7 * extension.
8 */
9 class CRM_TrustCommerce_ExtensionUtil {
10 const SHORT_NAME = "trustcommerce";
11 const LONG_NAME = "org.fsf.payment.trustcommerce";
12 const CLASS_PREFIX = "CRM_TrustCommerce";
13
14 /**
15 * Translate a string using the extension's domain.
16 *
17 * If the extension doesn't have a specific translation
18 * for the string, fallback to the default translations.
19 *
20 * @param string $text
21 * Canonical message text (generally en_US).
22 * @param array $params
23 * @return string
24 * Translated text.
25 * @see ts
26 */
27 public static function ts($text, $params = array()) {
28 if (!array_key_exists('domain', $params)) {
29 $params['domain'] = array(self::LONG_NAME, NULL);
30 }
31 return ts($text, $params);
32 }
33
34 /**
35 * Get the URL of a resource file (in this extension).
36 *
37 * @param string|NULL $file
38 * Ex: NULL.
39 * Ex: 'css/foo.css'.
40 * @return string
41 * Ex: 'http://example.org/sites/default/ext/org.example.foo'.
42 * Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
43 */
44 public static function url($file = NULL) {
45 if ($file === NULL) {
46 return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
47 }
48 return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
49 }
50
51 /**
52 * Get the path of a resource file (in this extension).
53 *
54 * @param string|NULL $file
55 * Ex: NULL.
56 * Ex: 'css/foo.css'.
57 * @return string
58 * Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
59 * Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
60 */
61 public static function path($file = NULL) {
62 // return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
63 return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
64 }
65
66 /**
67 * Get the name of a class within this extension.
68 *
69 * @param string $suffix
70 * Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
71 * @return string
72 * Ex: 'CRM_Foo_Page_HelloWorld'.
73 */
74 public static function findClass($suffix) {
75 return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
76 }
77
78 }
79
80 use CRM_TrustCommerce_ExtensionUtil as E;
81
82 /**
83 * (Delegated) Implements hook_civicrm_config().
84 *
85 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
86 */
87 function _trustcommerce_civix_civicrm_config(&$config = NULL) {
88 static $configured = FALSE;
89 if ($configured) {
90 return;
91 }
92 $configured = TRUE;
93
94 $template =& CRM_Core_Smarty::singleton();
95
96 $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
97 $extDir = $extRoot . 'templates';
98
99 if (is_array($template->template_dir)) {
100 array_unshift($template->template_dir, $extDir);
101 }
102 else {
103 $template->template_dir = array($extDir, $template->template_dir);
104 }
105
106 $include_path = $extRoot . PATH_SEPARATOR . get_include_path();
107 set_include_path($include_path);
108 }
109
110 /**
111 * (Delegated) Implements hook_civicrm_xmlMenu().
112 *
113 * @param $files array(string)
114 *
115 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
116 */
117 function _trustcommerce_civix_civicrm_xmlMenu(&$files) {
118 foreach (_trustcommerce_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
119 $files[] = $file;
120 }
121 }
122
123 /**
124 * Implements hook_civicrm_install().
125 *
126 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
127 */
128 function _trustcommerce_civix_civicrm_install() {
129 _trustcommerce_civix_civicrm_config();
130 if ($upgrader = _trustcommerce_civix_upgrader()) {
131 $upgrader->onInstall();
132 }
133 }
134
135 /**
136 * Implements hook_civicrm_postInstall().
137 *
138 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
139 */
140 function _trustcommerce_civix_civicrm_postInstall() {
141 _trustcommerce_civix_civicrm_config();
142 if ($upgrader = _trustcommerce_civix_upgrader()) {
143 if (is_callable(array($upgrader, 'onPostInstall'))) {
144 $upgrader->onPostInstall();
145 }
146 }
147 }
148
149 /**
150 * Implements hook_civicrm_uninstall().
151 *
152 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
153 */
154 function _trustcommerce_civix_civicrm_uninstall() {
155 _trustcommerce_civix_civicrm_config();
156 if ($upgrader = _trustcommerce_civix_upgrader()) {
157 $upgrader->onUninstall();
158 }
159 }
160
161 /**
162 * (Delegated) Implements hook_civicrm_enable().
163 *
164 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
165 */
166 function _trustcommerce_civix_civicrm_enable() {
167 _trustcommerce_civix_civicrm_config();
168 if ($upgrader = _trustcommerce_civix_upgrader()) {
169 if (is_callable(array($upgrader, 'onEnable'))) {
170 $upgrader->onEnable();
171 }
172 }
173 }
174
175 /**
176 * (Delegated) Implements hook_civicrm_disable().
177 *
178 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
179 * @return mixed
180 */
181 function _trustcommerce_civix_civicrm_disable() {
182 _trustcommerce_civix_civicrm_config();
183 if ($upgrader = _trustcommerce_civix_upgrader()) {
184 if (is_callable(array($upgrader, 'onDisable'))) {
185 $upgrader->onDisable();
186 }
187 }
188 }
189
190 /**
191 * (Delegated) Implements hook_civicrm_upgrade().
192 *
193 * @param $op string, the type of operation being performed; 'check' or 'enqueue'
194 * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
195 *
196 * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
197 * for 'enqueue', returns void
198 *
199 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
200 */
201 function _trustcommerce_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
202 if ($upgrader = _trustcommerce_civix_upgrader()) {
203 return $upgrader->onUpgrade($op, $queue);
204 }
205 }
206
207 /**
208 * @return CRM_TrustCommerce_Upgrader
209 */
210 function _trustcommerce_civix_upgrader() {
211 if (!file_exists(__DIR__ . '/CRM/TrustCommerce/Upgrader.php')) {
212 return NULL;
213 }
214 else {
215 return CRM_TrustCommerce_Upgrader_Base::instance();
216 }
217 }
218
219 /**
220 * Search directory tree for files which match a glob pattern
221 *
222 * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
223 * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
224 *
225 * @param $dir string, base dir
226 * @param $pattern string, glob pattern, eg "*.txt"
227 * @return array(string)
228 */
229 function _trustcommerce_civix_find_files($dir, $pattern) {
230 if (is_callable(array('CRM_Utils_File', 'findFiles'))) {
231 return CRM_Utils_File::findFiles($dir, $pattern);
232 }
233
234 $todos = array($dir);
235 $result = array();
236 while (!empty($todos)) {
237 $subdir = array_shift($todos);
238 foreach (_trustcommerce_civix_glob("$subdir/$pattern") as $match) {
239 if (!is_dir($match)) {
240 $result[] = $match;
241 }
242 }
243 if ($dh = opendir($subdir)) {
244 while (FALSE !== ($entry = readdir($dh))) {
245 $path = $subdir . DIRECTORY_SEPARATOR . $entry;
246 if ($entry{0} == '.') {
247 }
248 elseif (is_dir($path)) {
249 $todos[] = $path;
250 }
251 }
252 closedir($dh);
253 }
254 }
255 return $result;
256 }
257 /**
258 * (Delegated) Implements hook_civicrm_managed().
259 *
260 * Find any *.mgd.php files, merge their content, and return.
261 *
262 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
263 */
264 function _trustcommerce_civix_civicrm_managed(&$entities) {
265 $mgdFiles = _trustcommerce_civix_find_files(__DIR__, '*.mgd.php');
266 foreach ($mgdFiles as $file) {
267 $es = include $file;
268 foreach ($es as $e) {
269 if (empty($e['module'])) {
270 $e['module'] = E::LONG_NAME;
271 }
272 $entities[] = $e;
273 if (empty($e['params']['version'])) {
274 $e['params']['version'] = '3';
275 }
276 }
277 }
278 }
279
280 /**
281 * (Delegated) Implements hook_civicrm_caseTypes().
282 *
283 * Find any and return any files matching "xml/case/*.xml"
284 *
285 * Note: This hook only runs in CiviCRM 4.4+.
286 *
287 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
288 */
289 function _trustcommerce_civix_civicrm_caseTypes(&$caseTypes) {
290 if (!is_dir(__DIR__ . '/xml/case')) {
291 return;
292 }
293
294 foreach (_trustcommerce_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
295 $name = preg_replace('/\.xml$/', '', basename($file));
296 if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
297 $errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
298 CRM_Core_Error::fatal($errorMessage);
299 // throw new CRM_Core_Exception($errorMessage);
300 }
301 $caseTypes[$name] = array(
302 'module' => E::LONG_NAME,
303 'name' => $name,
304 'file' => $file,
305 );
306 }
307 }
308
309 /**
310 * (Delegated) Implements hook_civicrm_angularModules().
311 *
312 * Find any and return any files matching "ang/*.ang.php"
313 *
314 * Note: This hook only runs in CiviCRM 4.5+.
315 *
316 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules
317 */
318 function _trustcommerce_civix_civicrm_angularModules(&$angularModules) {
319 if (!is_dir(__DIR__ . '/ang')) {
320 return;
321 }
322
323 $files = _trustcommerce_civix_glob(__DIR__ . '/ang/*.ang.php');
324 foreach ($files as $file) {
325 $name = preg_replace(':\.ang\.php$:', '', basename($file));
326 $module = include $file;
327 if (empty($module['ext'])) {
328 $module['ext'] = E::LONG_NAME;
329 }
330 $angularModules[$name] = $module;
331 }
332 }
333
334 /**
335 * Glob wrapper which is guaranteed to return an array.
336 *
337 * The documentation for glob() says, "On some systems it is impossible to
338 * distinguish between empty match and an error." Anecdotally, the return
339 * result for an empty match is sometimes array() and sometimes FALSE.
340 * This wrapper provides consistency.
341 *
342 * @link http://php.net/glob
343 * @param string $pattern
344 * @return array, possibly empty
345 */
346 function _trustcommerce_civix_glob($pattern) {
347 $result = glob($pattern);
348 return is_array($result) ? $result : array();
349 }
350
351 /**
352 * Inserts a navigation menu item at a given place in the hierarchy.
353 *
354 * @param array $menu - menu hierarchy
355 * @param string $path - path where insertion should happen (ie. Administer/System Settings)
356 * @param array $item - menu you need to insert (parent/child attributes will be filled for you)
357 */
358 function _trustcommerce_civix_insert_navigation_menu(&$menu, $path, $item) {
359 // If we are done going down the path, insert menu
360 if (empty($path)) {
361 $menu[] = array(
362 'attributes' => array_merge(array(
363 'label' => CRM_Utils_Array::value('name', $item),
364 'active' => 1,
365 ), $item),
366 );
367 return TRUE;
368 }
369 else {
370 // Find an recurse into the next level down
371 $found = FALSE;
372 $path = explode('/', $path);
373 $first = array_shift($path);
374 foreach ($menu as $key => &$entry) {
375 if ($entry['attributes']['name'] == $first) {
376 if (!isset($entry['child'])) {
377 $entry['child'] = array();
378 }
379 $found = _trustcommerce_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
380 }
381 }
382 return $found;
383 }
384 }
385
386 /**
387 * (Delegated) Implements hook_civicrm_navigationMenu().
388 */
389 function _trustcommerce_civix_navigationMenu(&$nodes) {
390 if (!is_callable(array('CRM_Core_BAO_Navigation', 'fixNavigationMenu'))) {
391 _trustcommerce_civix_fixNavigationMenu($nodes);
392 }
393 }
394
395 /**
396 * Given a navigation menu, generate navIDs for any items which are
397 * missing them.
398 */
399 function _trustcommerce_civix_fixNavigationMenu(&$nodes) {
400 $maxNavID = 1;
401 array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) {
402 if ($key === 'navID') {
403 $maxNavID = max($maxNavID, $item);
404 }
405 });
406 _trustcommerce_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL);
407 }
408
409 function _trustcommerce_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
410 $origKeys = array_keys($nodes);
411 foreach ($origKeys as $origKey) {
412 if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) {
413 $nodes[$origKey]['attributes']['parentID'] = $parentID;
414 }
415 // If no navID, then assign navID and fix key.
416 if (!isset($nodes[$origKey]['attributes']['navID'])) {
417 $newKey = ++$maxNavID;
418 $nodes[$origKey]['attributes']['navID'] = $newKey;
419 $nodes[$newKey] = $nodes[$origKey];
420 unset($nodes[$origKey]);
421 $origKey = $newKey;
422 }
423 if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) {
424 _trustcommerce_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']);
425 }
426 }
427 }
428
429 /**
430 * (Delegated) Implements hook_civicrm_alterSettingsFolders().
431 *
432 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
433 */
434 function _trustcommerce_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
435 static $configured = FALSE;
436 if ($configured) {
437 return;
438 }
439 $configured = TRUE;
440
441 $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
442 if (is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) {
443 $metaDataFolders[] = $settingsDir;
444 }
445 }