Merge pull request #3223 from lcdservices/CRM-14672
[civicrm-core.git] / distmaker / utils / joomlaxml.php
1 <?php
2 define('CIVICRM_MYSQL_STRICT', 0);
3 if (isset($GLOBALS['_SERVER']['DM_SOURCEDIR'])) {
4 $sourceCheckoutDir = $GLOBALS['_SERVER']['DM_SOURCEDIR'];
5 }
6 else {
7 $sourceCheckoutDir = $argv[1];
8 }
9 $sourceCheckoutDirLength = strlen($sourceCheckoutDir);
10
11 if (isset($GLOBALS['_SERVER']['DM_TMPDIR'])) {
12 $targetDir = $GLOBALS['_SERVER']['DM_TMPDIR'] . '/com_civicrm';
13 }
14 else {
15 $targetDir = $argv[2];
16 }
17 $targetDirLength = strlen($targetDir);
18
19 if (isset($GLOBALS['_SERVER']['DM_VERSION'])) {
20 $version = $GLOBALS['_SERVER']['DM_VERSION'];
21 }
22 else {
23 $version = $argv[3];
24 }
25
26 if (isset($GLOBALS['_SERVER']['DM_PKGTYPE'])) {
27 $pkgType = $GLOBALS['_SERVER']['DM_PKGTYPE'];
28 }
29 else {
30 $pkgType = $argv[4];
31 }
32
33 ini_set('include_path',
34 "{$sourceCheckoutDir}:{$sourceCheckoutDir}/packages:" . ini_get('include_path')
35 );
36 require_once "$sourceCheckoutDir/civicrm.config.php";
37 require_once 'Smarty/Smarty.class.php';
38
39 generateJoomlaConfig($version);
40
41 /**
42 * This function creates destination directory
43 *
44 * @param $dir directory name to be created
45 * @param int $perm
46 *
47 * @internal param \mode $peram for that directory
48 */
49 function createDir($dir, $perm = 0755) {
50 if (!is_dir($dir)) {
51 echo "Outdir: $dir\n";
52 mkdir($dir, $perm, TRUE);
53 }
54 }
55
56 function generateJoomlaConfig($version) {
57 global $targetDir, $sourceCheckoutDir, $pkgType;
58
59 $smarty = new Smarty();
60 $smarty->template_dir = $sourceCheckoutDir . '/xml/templates';
61 $smarty->compile_dir = '/tmp/templates_c_u' . posix_geteuid();
62 createDir($smarty->compile_dir);
63
64 $smarty->assign('CiviCRMVersion', $version);
65 $smarty->assign('creationDate', date('F d Y'));
66 $smarty->assign('pkgType', $pkgType);
67
68 $xml = $smarty->fetch('joomla.tpl');
69
70 $output = $targetDir . '/civicrm.xml';
71 $fd = fopen($output, "w");
72 fputs($fd, $xml);
73 fclose($fd);
74
75 require_once 'CRM/Core/Config.php';
76 $config = CRM_Core_Config::singleton(FALSE);
77
78 require_once 'CRM/Core/Permission.php';
79 require_once 'CRM/Utils/String.php';
80 $permissions = CRM_Core_Permission::getCorePermissions();
81
82 $crmFolderDir = $sourceCheckoutDir . DIRECTORY_SEPARATOR . 'CRM';
83
84 require_once 'CRM/Core/Component.php';
85 $components = CRM_Core_Component::getComponentsFromFile($crmFolderDir);
86 foreach ($components as $comp) {
87 $perm = $comp->getPermissions();
88 if ($perm) {
89 $info = $comp->getInfo();
90 foreach ($perm as $p) {
91 $permissions[$p] = $info['translatedName'] . ': ' . $p;
92 }
93 }
94 }
95
96 $perms_array = array();
97 foreach ($permissions as $perm => $title) {
98 //order matters here, but we deal with that later
99 $perms_array[CRM_Utils_String::munge(strtolower($perm))] = $title;
100 }
101 $smarty->assign('permissions', $perms_array);
102
103 $output = $targetDir . '/admin/access.xml';
104 $xml = $smarty->fetch('access.tpl');
105 $fd = fopen($output, "w");
106 fputs($fd, $xml);
107 fclose($fd);
108 }
109