-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileanalyzer.php
More file actions
97 lines (85 loc) · 2.84 KB
/
fileanalyzer.php
File metadata and controls
97 lines (85 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
require_once 'fileanalyzer.civix.php';
use CRM_Fileanalyzer_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function fileanalyzer_civicrm_config(&$config) {
_fileanalyzer_civix_civicrm_config($config);
// Register modifier
static $registered = false;
if (!$registered) {
$smarty = CRM_Core_Smarty::singleton();
$smarty->registerPlugin("modifier", "filesize", "smarty_modifier_filesize");
$registered = true;
}
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function fileanalyzer_civicrm_install() {
_fileanalyzer_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function fileanalyzer_civicrm_enable() {
_fileanalyzer_civix_civicrm_enable();
}
/**
* Menu hook to add navigation items for both custom files and contribute images dashboards
*/
function fileanalyzer_civicrm_navigationMenu(&$menu) {
// Add main File Analyzer menu item with submenu
_fileanalyzer_civix_insert_navigation_menu($menu, 'Administer/System Settings', [
'label' => ts('File Analyzer'),
'name' => 'file_analyzer_main',
'url' => NULL, // This will be a parent menu item
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
]);
// Add Custom Files Dashboard submenu item
_fileanalyzer_civix_insert_navigation_menu($menu, 'Administer/System Settings/file_analyzer_main', [
'label' => ts('Custom Files Dashboard'),
'name' => 'file_analyzer_custom',
'url' => 'civicrm/file-analyzer/dashboard',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
]);
// Add Public Images Dashboard submenu item
_fileanalyzer_civix_insert_navigation_menu($menu, 'Administer/System Settings/file_analyzer_main', [
'label' => ts('Public Images Dashboard'),
'name' => 'file_analyzer_contribute',
'url' => 'civicrm/file-analyzer/public-dashboard',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
]);
// Add Settings submenu item
_fileanalyzer_civix_insert_navigation_menu($menu, 'Administer/System Settings/file_analyzer_main', [
'label' => ts('File Analyzer Settings'),
'name' => 'file_analyzer_settings',
'url' => 'civicrm/admin/setting/fileanalyzer',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 1, // Add separator before settings
]);
_fileanalyzer_civix_navigationMenu($menu);
}
function smarty_modifier_filesize($bytes) {
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
$i = 0;
while ($bytes >= 1024 && $i < count($units) - 1) {
$bytes /= 1024;
$i++;
}
return round($bytes, 2) . ' ' . $units[$i];
}