root/modules/branches/bootstrap-2.9/fw_langpacks/install.php

Revision 9488, 3.5 kB (checked in by mickecarlsson, 3 years ago)

Re r9459, Best Practise: always do a php -l before submitting php

Line 
1 <?php
2
3 // HELPER FUNCTIONS:
4
5 function fw_langpacks_print_errors($src, $dst, $errors) {
6     echo "error copying fw_langpacks files:<br />'cp -rf' from src: '$src' to dst: '$dst'...details follow<br />";
7     foreach ($errors as $error) {
8         echo "$error<br />";
9     }
10 }
11
12 if (! function_exists('out')) {
13     function out($text) {
14         echo $text."<br>";
15     }
16 }
17
18 if (! function_exists('outn')) {
19     function outn($text) {
20         echo $text;
21     }
22 }
23
24 if (! function_exists('error')) {
25     function error($text) {
26         echo "[ERROR] ".$text."<br>";
27     }
28 }
29
30 if (! function_exists('fatal')) {
31     function fatal($text) {
32         echo "[FATAL] ".$text."<br>";
33         exit(1);
34     }
35 }
36
37 if (! function_exists('debug')) {
38     function debug($text) {
39         global $debug;
40         
41         if ($debug) echo "[DEBUG-preDB] ".$text."<br>";
42     }
43 }
44
45 global $amp_conf;
46
47 $debug = false;
48 $dryrun = false;
49
50 /** verison_compare that works with freePBX version numbers
51  *  included here because there are some older versions of functions.inc.php that do not have
52  *  it included as it was added during 2.3.0beta1
53  */
54 if (!function_exists('version_compare_freepbx')) {
55     function version_compare_freepbx($version1, $version2, $op = null) {
56         $version1 = str_replace("rc","RC", strtolower($version1));
57         $version2 = str_replace("rc","RC", strtolower($version2));
58         if (!is_null($op)) {
59             return version_compare($version1, $version2, $op);
60         } else {
61             return version_compare($version1, $version2);
62         }
63     }
64 }
65
66 /*
67  * fw_langpacks install script
68  *
69  * for each installed component on the target system, copy localization files using the -u option
70  * on copy which will only copy them if our copy is newer then the destination which protects
71  * from overwriting destination files that have been updated by the user.
72  */
73     $htdocs_source = dirname(__FILE__)."/htdocs";
74     $htdocs_dest = $amp_conf['AMPWEBROOT'];
75
76     if (!file_exists($htdocs_source)) {
77     out(sprintf(_("No directory %s, install script not needed"),$htdocs_source));
78     return true;
79   }
80
81     // Always copy main FreePBX amp.po/mo files
82     //
83     out(sprintf(_("Preparing to copy %s to %s"),'i18n',"$htdocs_dest/admin"));
84     $htdocs_copy[] = array("source" => "$htdocs_source/admin/i18n", "dest" => "$htdocs_dest/admin");
85
86     // If ARI is there copy those
87     //
88     if (is_dir("$htdocs_dest/recordings")) {
89         $htdocs_copy[] = array("source" => "$htdocs_source/recordings", "dest" => "$htdocs_dest");
90         out(sprintf(_("Preparing to copy %s to %s"),'recordings',"$htdocs_dest"));
91     } else {
92         out(sprintf(_("No destination directory %s to copy %s to"),"$htdocs_dest/recordings","recordings"));
93     }
94
95     // Now for each module we have, make sure the module is in the destination as we don't want to create
96     // empty destinatino folders with just i18n directories.
97     //
98     $dir = opendir($htdocs_source.'/admin/modules');
99     while ($file = readdir($dir)) {
100         if (is_dir("$htdocs_dest/admin/modules/$file") && ($file != ".") && ($file != "..")) {
101             out(sprintf(_("Preparing to copy %s to %s"),"$file","$htdocs_dest/admin/modules"));
102             $htdocs_copy[] = array("source" => "$htdocs_source/admin/modules/$file", "dest" => "$htdocs_dest/admin/modules");
103         } else if ($file != "." && $file != "..") {
104             out(sprintf(_("No destination directory %s to copy %s to"),"$htdocs_dest/modules/$file","$file"));
105         }
106     }
107
108     foreach ($htdocs_copy as $translations) {
109         exec("cp -ru ".$translations['source']." ".$translations['dest']." 2>&1",$out,$ret);
110         if ($ret != 0) {
111             fw_langpacks_print_errors($translations['source'], $translations['dest'], $out);
112         } else {
113             out(sprintf(_("Updated %s"),basename($translations['source'])));
114         }
115     }
116 ?>
117
Note: See TracBrowser for help on using the browser.