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