2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/db/connect_db.inc");
14 include_once($path_to_root . "/includes/reserved.inc");
15 include_once($path_to_root . "/includes/errors.inc");
16 include_once($path_to_root . "/includes/types.inc");
17 include_once($path_to_root . "/includes/systypes.inc");
18 include_once($path_to_root . "/includes/references.inc");
19 include_once($path_to_root . "/includes/prefs/sysprefs.inc");
20 include_once($path_to_root . "/includes/db/comments_db.inc");
21 include_once($path_to_root . "/includes/db/sql_functions.inc");
23 include_once($path_to_root . "/admin/db/users_db.inc");
24 include_once($path_to_root . "/includes/ui/ui_view.inc");
25 include_once($path_to_root . "/includes/ui/ui_controls.inc");
26 include_once($path_to_root . "/installed_extensions.php");
28 function page($title, $no_menu=false, $is_index=false, $onload="", $js="", $script_only=false)
31 global $path_to_root, $installed_extensions;
33 $hide_menu = $no_menu;
35 if ($no_menu==false && count($installed_extensions))
38 foreach ($installed_extensions as $ext)
40 $s = $applications['system'];
41 array_pop($applications);
42 $applications[$ext['name']] = $ext['title'];;
43 $applications['system'] = $s;
47 include($path_to_root . "/includes/page/header.inc");
49 page_header($title, $no_menu, $is_index, $onload, $js);
53 echo display_heading(_('This page is usable only with javascript enabled browsers.'));
55 div_start('_page_body', null, true);
57 div_start('_page_body'); // whole page content for ajax reloading
61 function end_page($no_menu=false, $is_index=false)
63 global $path_to_root, $Ajax;
65 $hide_menu = $no_menu;
67 div_end(); // _page_body section
68 include($path_to_root . "/includes/page/footer.inc");
70 page_footer($no_menu, $is_index);
73 function flush_dir($path) {
74 $dir = opendir($path);
75 while(false !== ($fname = readdir($dir))) {
76 if($fname=='.' || $fname=='..' || $fname=='index.php') continue;
77 if(is_dir($path.'/'.$fname)) {
78 flush_dir($path.'/'.$fname);
79 @rmdir($path.'/'.$fname);
81 @unlink($path.'/'.$fname);
85 function cache_js_file($fpath, $text)
89 if(!$go_debug) $text = js_compress($text);
91 $file = fopen($fpath, 'w');
92 if (!$file) return false;
93 if (!fwrite($file, $text)) return false;
98 function add_js_file($filename)
102 $search = array_search($filename, $js_static);
103 if ($search === false || $search === null) // php>4.2.0 returns null
104 $js_static[] = $filename;
107 function add_js_ufile($filename)
111 $search = array_search($filename, $js_userlib);
112 if ($search === false || $search === null) // php>4.2.0 returns null
113 $js_userlib[] = $filename;
116 function add_js_source($text)
120 $search = array_search($text, $js_lib);
121 if ($search === false || $search === null) // php>4.2.0 returns null
126 * Compresses the Javascript code for more efficient delivery.
127 * copyright (c) 2005 by Jared White & J. Max Wilson
128 * http://www.xajaxproject.org
129 * Added removing comments from output.
130 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
132 function js_compress($sJS)
134 //remove windows cariage returns
135 $sJS = str_replace("\r","",$sJS);
137 //array to store replaced literal strings
138 $literal_strings = array();
140 //explode the string into lines
141 $lines = explode("\n",$sJS);
142 //loop through all the lines, building a new string at the same time as removing literal strings
150 for($i=0;$i<count($lines);$i++)
153 $inNormalComment = false;
155 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
156 for($j=0;$j<strlen($line);$j++)
158 $c = substr($line,$j,1);
159 $d = substr($line,$j,2);
161 //look for start of quote
162 if(!$inQuote && !$inComment)
164 //is this character a quote or a comment
165 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
173 else if($d=="/*" && !$inNormalComment)
182 else if($d=="//") //ignore string markers that are found inside comments
184 $inNormalComment = true;
192 else //allready in a string so find end quote
194 if($c == $quoteChar && !$escaped && !$inComment)
199 //subsitute in a marker for the string
200 $clean .= "___" . count($literal_strings) . "___";
202 //push the string onto our array
203 array_push($literal_strings,$literal);
206 else if($inComment && $d=="*/")
211 //subsitute in a marker for the string
212 $clean .= "___" . count($literal_strings) . "___";
214 //push the string onto our array
215 array_push($literal_strings,$literal);
219 else if($c == "\\" && !$escaped)
227 if($inComment) $literal .= "\n";
230 //explode the clean string into lines again
231 $lines = explode("\n",$clean);
233 //now process each line at a time
234 for($i=0;$i<count($lines);$i++)
239 $line = preg_replace("/\/\/(.*)/","",$line);
241 //strip leading and trailing whitespace
244 //remove all whitespace with a single space
245 $line = preg_replace("/\s+/"," ",$line);
247 //remove any whitespace that occurs after/before an operator
248 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
254 $sJS = implode("\n",$lines);
256 //make sure there is a max of 1 \n after each line
257 $sJS = preg_replace("/[\n]+/","\n",$sJS);
259 //strip out line breaks that immediately follow a semi-colon
260 $sJS = preg_replace("/;\n/",";",$sJS);
262 //curly brackets aren't on their own
263 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
265 //finally loop through and replace all the literal strings:
266 for($i=0;$i<count($literal_strings);$i++) {
267 if (strpos($literal_strings[$i],"/*")!==false)
268 $literal_strings[$i]= '';
269 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
273 //-----------------------------------------------------------------------------
274 // Inserts $elements into $array at position $index.
275 // $elements is list of any objects
277 function array_insert(&$array, $index, $elements)
279 if (!is_array($elements)) $elements = array($elements);
281 $head = array_splice($array, 0, $index);
282 $array = array_merge($head, $elements, $array);
285 function array_remove(&$array, $index, $len=1)
287 array_splice($array, $index, $len);
290 function array_replace(&$array, $index, $len, $elements)
292 array_splice($array, $index, $len);
293 array_insert($array, $index, $elements);
296 function array_append(&$array, $elements)
298 foreach($elements as $key => $el) {