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="", $script_only=false)
23 $hide_menu = $no_menu;
25 include($path_to_root . "/includes/page/header.inc");
27 page_header($title, $no_menu, $is_index, $onload, $js);
31 echo display_heading(_('This page is usable only with javascript enabled browsers.'));
33 div_start('_page_body', null, true);
35 div_start('_page_body'); // whole page content for ajax reloading
39 function end_page($no_menu=false, $is_index=false)
41 global $path_to_root, $Ajax;
43 $hide_menu = $no_menu;
45 div_end(); // _page_body section
46 include($path_to_root . "/includes/page/footer.inc");
48 page_footer($no_menu, $is_index);
51 function flush_dir($path) {
52 $dir = opendir($path);
53 while(false !== ($fname = readdir($dir))) {
54 if($fname=='.' || $fname=='..' || $fname=='index.php') continue;
55 if(is_dir($path.'/'.$fname)) {
56 flush_dir($path.'/'.$fname);
57 @rmdir($path.'/'.$fname);
59 @unlink($path.'/'.$fname);
63 function cache_js_file($fpath, $text)
67 if(!$go_debug) $text = js_compress($text);
69 $file = fopen($fpath, 'w');
70 if (!$file) return false;
71 if (!fwrite($file, $text)) return false;
76 function add_js_file($filename)
80 $search = array_search($filename, $js_static);
81 if ($search === false || $search === null) // php>4.2.0 returns null
82 $js_static[] = $filename;
85 function add_js_ufile($filename)
89 $search = array_search($filename, $js_userlib);
90 if ($search === false || $search === null) // php>4.2.0 returns null
91 $js_userlib[] = $filename;
94 function add_js_source($text)
98 $search = array_search($text, $js_lib);
99 if ($search === false || $search === null) // php>4.2.0 returns null
104 * Compresses the Javascript code for more efficient delivery.
105 * copyright (c) 2005 by Jared White & J. Max Wilson
106 * http://www.xajaxproject.org
107 * Added removing comments from output.
108 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
110 function js_compress($sJS)
112 //remove windows cariage returns
113 $sJS = str_replace("\r","",$sJS);
115 //array to store replaced literal strings
116 $literal_strings = array();
118 //explode the string into lines
119 $lines = explode("\n",$sJS);
120 //loop through all the lines, building a new string at the same time as removing literal strings
128 for($i=0;$i<count($lines);$i++)
131 $inNormalComment = false;
133 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
134 for($j=0;$j<strlen($line);$j++)
136 $c = substr($line,$j,1);
137 $d = substr($line,$j,2);
139 //look for start of quote
140 if(!$inQuote && !$inComment)
142 //is this character a quote or a comment
143 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
151 else if($d=="/*" && !$inNormalComment)
160 else if($d=="//") //ignore string markers that are found inside comments
162 $inNormalComment = true;
170 else //allready in a string so find end quote
172 if($c == $quoteChar && !$escaped && !$inComment)
177 //subsitute in a marker for the string
178 $clean .= "___" . count($literal_strings) . "___";
180 //push the string onto our array
181 array_push($literal_strings,$literal);
184 else if($inComment && $d=="*/")
189 //subsitute in a marker for the string
190 $clean .= "___" . count($literal_strings) . "___";
192 //push the string onto our array
193 array_push($literal_strings,$literal);
197 else if($c == "\\" && !$escaped)
205 if($inComment) $literal .= "\n";
208 //explode the clean string into lines again
209 $lines = explode("\n",$clean);
211 //now process each line at a time
212 for($i=0;$i<count($lines);$i++)
217 $line = preg_replace("/\/\/(.*)/","",$line);
219 //strip leading and trailing whitespace
222 //remove all whitespace with a single space
223 $line = preg_replace("/\s+/"," ",$line);
225 //remove any whitespace that occurs after/before an operator
226 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
232 $sJS = implode("\n",$lines);
234 //make sure there is a max of 1 \n after each line
235 $sJS = preg_replace("/[\n]+/","\n",$sJS);
237 //strip out line breaks that immediately follow a semi-colon
238 $sJS = preg_replace("/;\n/",";",$sJS);
240 //curly brackets aren't on their own
241 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
243 //finally loop through and replace all the literal strings:
244 for($i=0;$i<count($literal_strings);$i++) {
245 if (strpos($literal_strings[$i],"/*")!==false)
246 $literal_strings[$i]= '';
247 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
251 //-----------------------------------------------------------------------------
252 // Inserts $elements into $array at position $index.
253 // In contrast to array_splice() preserves keys of $elements array.
255 function array_insert(&$array, $index, $elements)
257 if (!is_array($elements)) $elements = array($elements);
259 $head = array_splice($array, 0, $index);
260 $array = array_merge($head, $elements, $array);
264 function array_remove(&$array, $index, $len=1)
266 array_splice($array, $index, $len);