Merge pull request #19357 from totten/master-joomla
[civicrm-core.git] / distmaker / utils / joomlaxml.php
1 <?php
2
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];
7
8 ini_set('include_path',
9 "{$sourceCheckoutDir}:{$sourceCheckoutDir}/packages:" . ini_get('include_path')
10 );
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
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
25 * @param int $perm
26 *
27 * @internal param \mode $peram for that directory
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
36 /**
37 * @param $version
38 */
39 function generateJoomlaConfig($version) {
40 global $targetDir, $sourceCheckoutDir, $pkgType;
41
42 $smarty = new Smarty();
43 $smarty->template_dir = $sourceCheckoutDir . '/xml/templates';
44 $smarty->compile_dir = '/tmp/templates_c_u' . posix_geteuid();
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");
55 fwrite($fd, $xml);
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';
63 require_once 'CRM/Core/I18n.php';
64 $permissions = CRM_Core_Permission::getCorePermissions(TRUE);
65
66 $crmFolderDir = $sourceCheckoutDir . DIRECTORY_SEPARATOR . 'CRM';
67
68 require_once 'CRM/Core/Component.php';
69 $components = CRM_Core_Component::getComponentsFromFile($crmFolderDir);
70 foreach ($components as $comp) {
71 $perm = $comp->getPermissions(FALSE, TRUE);
72 if ($perm) {
73 $info = $comp->getInfo();
74 foreach ($perm as $p => $attr) {
75 $title = $info['translatedName'] . ': ' . array_shift($attr);
76 array_unshift($attr, $title);
77 $permissions[$p] = $attr;
78 }
79 }
80 }
81
82 $perms_array = array();
83 foreach ($permissions as $perm => $attr) {
84 // give an empty string as default description
85 $attr[] = '';
86
87 //order matters here, but we deal with that later
88 $perms_array[CRM_Utils_String::munge(strtolower($perm))] = array(
89 'title' => array_shift($attr),
90 'description' => array_shift($attr),
91 );
92 }
93 $smarty->assign('permissions', $perms_array);
94
95 $output = $targetDir . '/admin/access.xml';
96 $xml = $smarty->fetch('access.tpl');
97 $fd = fopen($output, "w");
98 fwrite($fd, $xml);
99 fclose($fd);
100 }