Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
d6694785 | 2 | |
8a8eecf8 TO |
3 | $sourceCheckoutDir = $GLOBALS['_SERVER']['DM_SOURCEDIR'] ?? $argv[1]; |
4 | $targetDir = $GLOBALS['_SERVER']['DM_TMPDIR'] . '/com_civicrm' ?? $argv[2]; | |
5 | $version = $GLOBALS['_SERVER']['DM_VERSION'] ?? $argv[3]; | |
6 | $pkgType = $GLOBALS['_SERVER']['DM_PKGTYPE'] ?? $argv[4]; | |
6a488035 TO |
7 | |
8 | ini_set('include_path', | |
9 | "{$sourceCheckoutDir}:{$sourceCheckoutDir}/packages:" . ini_get('include_path') | |
10 | ); | |
e7ee9c40 TO |
11 | |
12 | define('CIVICRM_UF', 'Joomla'); | |
13 | $GLOBALS['civicrm_root'] = $sourceCheckoutDir; | |
14 | require_once $sourceCheckoutDir . '/CRM/Core/ClassLoader.php'; | |
15 | CRM_Core_ClassLoader::singleton()->register(); | |
16 | ||
6a488035 TO |
17 | require_once 'Smarty/Smarty.class.php'; |
18 | ||
19 | generateJoomlaConfig($version); | |
20 | ||
21 | /** | |
22 | * This function creates destination directory | |
23 | * | |
24 | * @param $dir directory name to be created | |
2a6da8d7 | 25 | * @param int $perm |
6a488035 | 26 | * |
2a6da8d7 | 27 | * @internal param \mode $peram for that directory |
6a488035 TO |
28 | */ |
29 | function createDir($dir, $perm = 0755) { | |
30 | if (!is_dir($dir)) { | |
31 | echo "Outdir: $dir\n"; | |
32 | mkdir($dir, $perm, TRUE); | |
33 | } | |
34 | } | |
35 | ||
627456b5 EM |
36 | /** |
37 | * @param $version | |
38 | */ | |
6a488035 TO |
39 | function generateJoomlaConfig($version) { |
40 | global $targetDir, $sourceCheckoutDir, $pkgType; | |
41 | ||
42 | $smarty = new Smarty(); | |
43 | $smarty->template_dir = $sourceCheckoutDir . '/xml/templates'; | |
90902f77 | 44 | $smarty->compile_dir = '/tmp/templates_c_u' . posix_geteuid(); |
6a488035 TO |
45 | createDir($smarty->compile_dir); |
46 | ||
47 | $smarty->assign('CiviCRMVersion', $version); | |
48 | $smarty->assign('creationDate', date('F d Y')); | |
49 | $smarty->assign('pkgType', $pkgType); | |
50 | ||
51 | $xml = $smarty->fetch('joomla.tpl'); | |
52 | ||
53 | $output = $targetDir . '/civicrm.xml'; | |
54 | $fd = fopen($output, "w"); | |
389bcebf | 55 | fwrite($fd, $xml); |
6a488035 TO |
56 | fclose($fd); |
57 | ||
58 | require_once 'CRM/Core/Config.php'; | |
59 | $config = CRM_Core_Config::singleton(FALSE); | |
60 | ||
61 | require_once 'CRM/Core/Permission.php'; | |
62 | require_once 'CRM/Utils/String.php'; | |
3d710f98 | 63 | require_once 'CRM/Core/I18n.php'; |
7b11eace | 64 | $permissions = CRM_Core_Permission::getCorePermissions(); |
6a488035 TO |
65 | |
66 | $crmFolderDir = $sourceCheckoutDir . DIRECTORY_SEPARATOR . 'CRM'; | |
67 | ||
d2b6eac8 | 68 | // @todo call getCoreAndComponentPermissions instead and let that |
69 | // do the work of these next 15-20 lines. | |
6a488035 TO |
70 | require_once 'CRM/Core/Component.php'; |
71 | $components = CRM_Core_Component::getComponentsFromFile($crmFolderDir); | |
72 | foreach ($components as $comp) { | |
564d1e45 | 73 | $perm = $comp->getPermissions(FALSE, TRUE); |
6a488035 TO |
74 | if ($perm) { |
75 | $info = $comp->getInfo(); | |
444b3e90 AH |
76 | foreach ($perm as $p => $attr) { |
77 | $title = $info['translatedName'] . ': ' . array_shift($attr); | |
78 | array_unshift($attr, $title); | |
79 | $permissions[$p] = $attr; | |
6a488035 TO |
80 | } |
81 | } | |
82 | } | |
83 | ||
84 | $perms_array = array(); | |
564d1e45 AH |
85 | foreach ($permissions as $perm => $attr) { |
86 | // give an empty string as default description | |
87 | $attr[] = ''; | |
1a605e0b | 88 | |
6a488035 | 89 | //order matters here, but we deal with that later |
564d1e45 AH |
90 | $perms_array[CRM_Utils_String::munge(strtolower($perm))] = array( |
91 | 'title' => array_shift($attr), | |
92 | 'description' => array_shift($attr), | |
93 | ); | |
6a488035 TO |
94 | } |
95 | $smarty->assign('permissions', $perms_array); | |
96 | ||
97 | $output = $targetDir . '/admin/access.xml'; | |
98 | $xml = $smarty->fetch('access.tpl'); | |
99 | $fd = fopen($output, "w"); | |
389bcebf | 100 | fwrite($fd, $xml); |
6a488035 TO |
101 | fclose($fd); |
102 | } |