3 include_once($path_to_root . "/includes/db/connect_db.inc");
5 include_once($path_to_root . "/includes/reserved.inc");
6 include_once($path_to_root . "/includes/errors.inc");
7 include_once($path_to_root . "/includes/types.inc");
8 include_once($path_to_root . "/includes/systypes.inc");
9 include_once($path_to_root . "/includes/references.inc");
10 include_once($path_to_root . "/includes/prefs/sysprefs.inc");
11 include_once($path_to_root . "/includes/db/comments_db.inc");
12 include_once($path_to_root . "/includes/db/sql_functions.inc");
14 include_once($path_to_root . "/admin/db/users_db.inc");
15 include_once($path_to_root . "/includes/ui/ui_view.inc");
17 function page($title, $no_menu=false, $is_index=false, $onload="", $js="")
22 $hide_menu = $no_menu;
24 include($path_to_root . "/includes/page/header.inc");
26 page_header($title, $no_menu, $is_index, $onload, $js);
30 function end_page($no_menu=false, $is_index=false)
32 global $path_to_root, $Ajax;
34 $hide_menu = $no_menu;
36 include($path_to_root . "/includes/page/footer.inc");
39 page_footer($no_menu, $is_index);
42 function flush_dir($path) {
43 $dir = opendir($path);
44 while(false !== ($fname = readdir($dir))) {
45 if($fname=='.' || $fname=='..') continue;
46 if(is_dir($path.'/'.$fname)) {
47 flush_dir($path.'/'.$fname);
48 @rmdir($path.'/'.$fname);
50 @unlink($path.'/'.$fname);
54 function cache_js_file($fpath, $text)
58 if(!$go_debug) $text = js_compress($text);
60 $file = fopen($fpath, 'w');
61 if (!$file) return false;
62 if (!fwrite($file, $text)) return false;
67 function add_js_file($filename)
71 $search = array_search($filename, $js_static);
72 if ($search === false || $search === null) // php>4.2.0 returns null
73 $js_static[] = $filename;
76 function add_js_ufile($filename)
80 $search = array_search($filename, $js_userlib);
81 if ($search === false || $search === null) // php>4.2.0 returns null
82 $js_userlib[] = $filename;
85 function add_js_source($text)
89 $search = array_search($text, $js_lib);
90 if ($search === false || $search === null) // php>4.2.0 returns null
95 * Compresses the Javascript code for more efficient delivery.
96 * copyright (c) 2005 by Jared White & J. Max Wilson
97 * http://www.xajaxproject.org
98 * Added removing comments from output.
99 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
101 function js_compress($sJS)
103 //remove windows cariage returns
104 $sJS = str_replace("\r","",$sJS);
106 //array to store replaced literal strings
107 $literal_strings = array();
109 //explode the string into lines
110 $lines = explode("\n",$sJS);
111 //loop through all the lines, building a new string at the same time as removing literal strings
119 for($i=0;$i<count($lines);$i++)
122 $inNormalComment = false;
124 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
125 for($j=0;$j<strlen($line);$j++)
127 $c = substr($line,$j,1);
128 $d = substr($line,$j,2);
130 //look for start of quote
131 if(!$inQuote && !$inComment)
133 //is this character a quote or a comment
134 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
142 else if($d=="/*" && !$inNormalComment)
151 else if($d=="//") //ignore string markers that are found inside comments
153 $inNormalComment = true;
161 else //allready in a string so find end quote
163 if($c == $quoteChar && !$escaped && !$inComment)
168 //subsitute in a marker for the string
169 $clean .= "___" . count($literal_strings) . "___";
171 //push the string onto our array
172 array_push($literal_strings,$literal);
175 else if($inComment && $d=="*/")
180 //subsitute in a marker for the string
181 $clean .= "___" . count($literal_strings) . "___";
183 //push the string onto our array
184 array_push($literal_strings,$literal);
188 else if($c == "\\" && !$escaped)
196 if($inComment) $literal .= "\n";
199 //explode the clean string into lines again
200 $lines = explode("\n",$clean);
202 //now process each line at a time
203 for($i=0;$i<count($lines);$i++)
208 $line = preg_replace("/\/\/(.*)/","",$line);
210 //strip leading and trailing whitespace
213 //remove all whitespace with a single space
214 $line = preg_replace("/\s+/"," ",$line);
216 //remove any whitespace that occurs after/before an operator
217 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
223 $sJS = implode("\n",$lines);
225 //make sure there is a max of 1 \n after each line
226 $sJS = preg_replace("/[\n]+/","\n",$sJS);
228 //strip out line breaks that immediately follow a semi-colon
229 $sJS = preg_replace("/;\n/",";",$sJS);
231 //curly brackets aren't on their own
232 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
234 //finally loop through and replace all the literal strings:
235 for($i=0;$i<count($literal_strings);$i++) {
236 if (strpos($literal_strings[$i],"/*")!==false)
237 $literal_strings[$i]= '';
238 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);