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");
41 page_footer($no_menu, $is_index);
44 function flush_dir($path) {
45 $dir = opendir($path);
46 while(false !== ($fname = readdir($dir))) {
47 if($fname=='.' || $fname=='..') continue;
48 if(is_dir($path.'/'.$fname)) {
49 flush_dir($path.'/'.$fname);
50 @rmdir($path.'/'.$fname);
52 @unlink($path.'/'.$fname);
56 function cache_js_file($fpath, $text)
60 if(!$go_debug) $text = js_compress($text);
62 $file = fopen($fpath, 'w');
63 if (!$file) return false;
64 if (!fwrite($file, $text)) return false;
69 function add_js_file($filename)
73 $search = array_search($filename, $js_static);
74 if ($search === false || $search === null) // php>4.2.0 returns null
75 $js_static[] = $filename;
78 function add_js_ufile($filename)
82 $search = array_search($filename, $js_userlib);
83 if ($search === false || $search === null) // php>4.2.0 returns null
84 $js_userlib[] = $filename;
87 function add_js_source($text)
91 $search = array_search($text, $js_lib);
92 if ($search === false || $search === null) // php>4.2.0 returns null
97 * Compresses the Javascript code for more efficient delivery.
98 * copyright (c) 2005 by Jared White & J. Max Wilson
99 * http://www.xajaxproject.org
100 * Added removing comments from output.
101 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
103 function js_compress($sJS)
105 //remove windows cariage returns
106 $sJS = str_replace("\r","",$sJS);
108 //array to store replaced literal strings
109 $literal_strings = array();
111 //explode the string into lines
112 $lines = explode("\n",$sJS);
113 //loop through all the lines, building a new string at the same time as removing literal strings
121 for($i=0;$i<count($lines);$i++)
124 $inNormalComment = false;
126 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
127 for($j=0;$j<strlen($line);$j++)
129 $c = substr($line,$j,1);
130 $d = substr($line,$j,2);
132 //look for start of quote
133 if(!$inQuote && !$inComment)
135 //is this character a quote or a comment
136 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
144 else if($d=="/*" && !$inNormalComment)
153 else if($d=="//") //ignore string markers that are found inside comments
155 $inNormalComment = true;
163 else //allready in a string so find end quote
165 if($c == $quoteChar && !$escaped && !$inComment)
170 //subsitute in a marker for the string
171 $clean .= "___" . count($literal_strings) . "___";
173 //push the string onto our array
174 array_push($literal_strings,$literal);
177 else if($inComment && $d=="*/")
182 //subsitute in a marker for the string
183 $clean .= "___" . count($literal_strings) . "___";
185 //push the string onto our array
186 array_push($literal_strings,$literal);
190 else if($c == "\\" && !$escaped)
198 if($inComment) $literal .= "\n";
201 //explode the clean string into lines again
202 $lines = explode("\n",$clean);
204 //now process each line at a time
205 for($i=0;$i<count($lines);$i++)
210 $line = preg_replace("/\/\/(.*)/","",$line);
212 //strip leading and trailing whitespace
215 //remove all whitespace with a single space
216 $line = preg_replace("/\s+/"," ",$line);
218 //remove any whitespace that occurs after/before an operator
219 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
225 $sJS = implode("\n",$lines);
227 //make sure there is a max of 1 \n after each line
228 $sJS = preg_replace("/[\n]+/","\n",$sJS);
230 //strip out line breaks that immediately follow a semi-colon
231 $sJS = preg_replace("/;\n/",";",$sJS);
233 //curly brackets aren't on their own
234 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
236 //finally loop through and replace all the literal strings:
237 for($i=0;$i<count($literal_strings);$i++) {
238 if (strpos($literal_strings[$i],"/*")!==false)
239 $literal_strings[$i]= '';
240 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);