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");
16 include_once($path_to_root . "/includes/ui/ui_controls.inc");
18 function page($title, $no_menu=false, $is_index=false, $onload="", $js="")
23 $hide_menu = $no_menu;
25 include($path_to_root . "/includes/page/header.inc");
27 page_header($title, $no_menu, $is_index, $onload, $js);
29 div_start('_page_body'); // whole page content for ajax reloading
32 function end_page($no_menu=false, $is_index=false)
34 global $path_to_root, $Ajax;
36 $hide_menu = $no_menu;
38 div_end(); // _page_body section
39 include($path_to_root . "/includes/page/footer.inc");
42 page_footer($no_menu, $is_index);
45 function flush_dir($path) {
46 $dir = opendir($path);
47 while(false !== ($fname = readdir($dir))) {
48 if($fname=='.' || $fname=='..') continue;
49 if(is_dir($path.'/'.$fname)) {
50 flush_dir($path.'/'.$fname);
51 @rmdir($path.'/'.$fname);
53 @unlink($path.'/'.$fname);
57 function cache_js_file($fpath, $text)
61 if(!$go_debug) $text = js_compress($text);
63 $file = fopen($fpath, 'w');
64 if (!$file) return false;
65 if (!fwrite($file, $text)) return false;
70 function add_js_file($filename)
74 $search = array_search($filename, $js_static);
75 if ($search === false || $search === null) // php>4.2.0 returns null
76 $js_static[] = $filename;
79 function add_js_ufile($filename)
83 $search = array_search($filename, $js_userlib);
84 if ($search === false || $search === null) // php>4.2.0 returns null
85 $js_userlib[] = $filename;
88 function add_js_source($text)
92 $search = array_search($text, $js_lib);
93 if ($search === false || $search === null) // php>4.2.0 returns null
98 * Compresses the Javascript code for more efficient delivery.
99 * copyright (c) 2005 by Jared White & J. Max Wilson
100 * http://www.xajaxproject.org
101 * Added removing comments from output.
102 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
104 function js_compress($sJS)
106 //remove windows cariage returns
107 $sJS = str_replace("\r","",$sJS);
109 //array to store replaced literal strings
110 $literal_strings = array();
112 //explode the string into lines
113 $lines = explode("\n",$sJS);
114 //loop through all the lines, building a new string at the same time as removing literal strings
122 for($i=0;$i<count($lines);$i++)
125 $inNormalComment = false;
127 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
128 for($j=0;$j<strlen($line);$j++)
130 $c = substr($line,$j,1);
131 $d = substr($line,$j,2);
133 //look for start of quote
134 if(!$inQuote && !$inComment)
136 //is this character a quote or a comment
137 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
145 else if($d=="/*" && !$inNormalComment)
154 else if($d=="//") //ignore string markers that are found inside comments
156 $inNormalComment = true;
164 else //allready in a string so find end quote
166 if($c == $quoteChar && !$escaped && !$inComment)
171 //subsitute in a marker for the string
172 $clean .= "___" . count($literal_strings) . "___";
174 //push the string onto our array
175 array_push($literal_strings,$literal);
178 else if($inComment && $d=="*/")
183 //subsitute in a marker for the string
184 $clean .= "___" . count($literal_strings) . "___";
186 //push the string onto our array
187 array_push($literal_strings,$literal);
191 else if($c == "\\" && !$escaped)
199 if($inComment) $literal .= "\n";
202 //explode the clean string into lines again
203 $lines = explode("\n",$clean);
205 //now process each line at a time
206 for($i=0;$i<count($lines);$i++)
211 $line = preg_replace("/\/\/(.*)/","",$line);
213 //strip leading and trailing whitespace
216 //remove all whitespace with a single space
217 $line = preg_replace("/\s+/"," ",$line);
219 //remove any whitespace that occurs after/before an operator
220 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
226 $sJS = implode("\n",$lines);
228 //make sure there is a max of 1 \n after each line
229 $sJS = preg_replace("/[\n]+/","\n",$sJS);
231 //strip out line breaks that immediately follow a semi-colon
232 $sJS = preg_replace("/;\n/",";",$sJS);
234 //curly brackets aren't on their own
235 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
237 //finally loop through and replace all the literal strings:
238 for($i=0;$i<count($literal_strings);$i++) {
239 if (strpos($literal_strings[$i],"/*")!==false)
240 $literal_strings[$i]= '';
241 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);