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;
46 include($path_to_root . "/includes/page/header.inc");
48 page_header($title, $no_menu, $is_index, $onload, $js);
52 echo display_heading(_('This page is usable only with javascript enabled browsers.'));
54 div_start('_page_body', null, true);
56 div_start('_page_body'); // whole page content for ajax reloading
60 function end_page($no_menu=false, $is_index=false)
62 global $path_to_root, $Ajax;
63 $hide_menu = $no_menu;
64 div_end(); // _page_body section
65 include($path_to_root . "/includes/page/footer.inc");
66 page_footer($no_menu, $is_index);
69 function flush_dir($path)
71 $dir = opendir($path);
72 while(false !== ($fname = readdir($dir))) {
73 if($fname=='.' || $fname=='..' || $fname=='index.php') continue;
74 if(is_dir($path.'/'.$fname)) {
75 flush_dir($path.'/'.$fname);
76 @rmdir($path.'/'.$fname);
78 @unlink($path.'/'.$fname);
82 function cache_js_file($fpath, $text)
86 if(!$go_debug) $text = js_compress($text);
88 $file = fopen($fpath, 'w');
89 if (!$file) return false;
90 if (!fwrite($file, $text)) return false;
95 function add_js_file($filename)
99 $search = array_search($filename, $js_static);
100 if ($search === false || $search === null) // php>4.2.0 returns null
101 $js_static[] = $filename;
104 function add_js_ufile($filename)
108 $search = array_search($filename, $js_userlib);
109 if ($search === false || $search === null) // php>4.2.0 returns null
110 $js_userlib[] = $filename;
113 function add_js_source($text)
117 $search = array_search($text, $js_lib);
118 if ($search === false || $search === null) // php>4.2.0 returns null
123 * Compresses the Javascript code for more efficient delivery.
124 * copyright (c) 2005 by Jared White & J. Max Wilson
125 * http://www.xajaxproject.org
126 * Added removing comments from output.
127 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
129 function js_compress($sJS)
131 //remove windows cariage returns
132 $sJS = str_replace("\r","",$sJS);
134 //array to store replaced literal strings
135 $literal_strings = array();
137 //explode the string into lines
138 $lines = explode("\n",$sJS);
139 //loop through all the lines, building a new string at the same time as removing literal strings
147 for($i=0;$i<count($lines);$i++)
150 $inNormalComment = false;
152 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
153 for($j=0;$j<strlen($line);$j++)
155 $c = substr($line,$j,1);
156 $d = substr($line,$j,2);
158 //look for start of quote
159 if(!$inQuote && !$inComment)
161 //is this character a quote or a comment
162 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
170 else if($d=="/*" && !$inNormalComment)
179 else if($d=="//") //ignore string markers that are found inside comments
181 $inNormalComment = true;
189 else //allready in a string so find end quote
191 if($c == $quoteChar && !$escaped && !$inComment)
196 //subsitute in a marker for the string
197 $clean .= "___" . count($literal_strings) . "___";
199 //push the string onto our array
200 array_push($literal_strings,$literal);
203 else if($inComment && $d=="*/")
208 //subsitute in a marker for the string
209 $clean .= "___" . count($literal_strings) . "___";
211 //push the string onto our array
212 array_push($literal_strings,$literal);
216 else if($c == "\\" && !$escaped)
224 if($inComment) $literal .= "\n";
227 //explode the clean string into lines again
228 $lines = explode("\n",$clean);
230 //now process each line at a time
231 for($i=0;$i<count($lines);$i++)
236 $line = preg_replace("/\/\/(.*)/","",$line);
238 //strip leading and trailing whitespace
241 //remove all whitespace with a single space
242 $line = preg_replace("/\s+/"," ",$line);
244 //remove any whitespace that occurs after/before an operator
245 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
251 $sJS = implode("\n",$lines);
253 //make sure there is a max of 1 \n after each line
254 $sJS = preg_replace("/[\n]+/","\n",$sJS);
256 //strip out line breaks that immediately follow a semi-colon
257 $sJS = preg_replace("/;\n/",";",$sJS);
259 //curly brackets aren't on their own
260 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
262 //finally loop through and replace all the literal strings:
263 for($i=0;$i<count($literal_strings);$i++) {
264 if (strpos($literal_strings[$i],"/*")!==false)
265 $literal_strings[$i]= '';
266 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
270 //-----------------------------------------------------------------------------
271 // Inserts $elements into $array at position $index.
272 // $elements is list of any objects
274 function array_insert(&$array, $index, $elements)
276 if (!is_array($elements)) $elements = array($elements);
278 $head = array_splice($array, 0, $index);
279 $array = array_merge($head, $elements, $array);
282 function array_remove(&$array, $index, $len=1)
284 array_splice($array, $index, $len);
287 function array_replace(&$array, $index, $len, $elements)
289 array_splice($array, $index, $len);
290 array_insert($array, $index, $elements);
293 function array_append(&$array, $elements)
295 foreach($elements as $key => $el) {