function compressContent($content) { ## this needs loads more testing across systems to be sure return $content; $content = preg_replace("/\n/", ' ', $content); $content = preg_replace("/\r/", '', $content); $content = removeJavascript($content); $content = stripComments($content); ## find some clean way to remove double spacing $content = preg_replace("/\t/", ' ', $content); while (preg_match('/ /', $content)) { $content = preg_replace('/ /', ' ', $content); } return $content; }
function sanitizeString($str) { return mysql_escape_string(stripSpecials(stripComments(utf_for_db($str)))); }
<?php require_once 'functions_utility.inc'; require_once 'functions_main.inc'; $configLinesWithoutIncludes = readConfig($_GET["action"]); checkIfError(); $configLinesWithIncludes = doIMPORT($configLinesWithoutIncludes); checkIfError(); $linesToParse = stripComments($configLinesWithIncludes); checkIfError(); checkMETHOD($linesToParse); checkIfError(); $passedVariables = MapVariables($linesToParse); checkIfError(); doCHECK($linesToParse, $passedVariables); checkIfError(); $sqlConnection = initDB($linesToParse); checkIfError(); doDBCHECK($linesToParse, $sqlConnection); checkIfError(); doACTION($linesToParse, $sqlConnection); checkIfError();
function validateEmailAddress($email) { $no_ws_ctl = "[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]"; $alpha = "[\\x41-\\x5a\\x61-\\x7a]"; $digit = "[\\x30-\\x39]"; $cr = "\\x0d"; $lf = "\\x0a"; $crlf = "(?:{$cr}{$lf})"; $obs_char = "[\\x00-\\x09\\x0b\\x0c\\x0e-\\x7f]"; $obs_text = "(?:{$lf}*{$cr}*(?:{$obs_char}{$lf}*{$cr}*)*)"; $text = "(?:[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f]|{$obs_text})"; $text = "(?:{$lf}*{$cr}*{$obs_char}{$lf}*{$cr}*)"; $obs_qp = "(?:\\x5c[\\x00-\\x7f])"; $quoted_pair = "(?:\\x5c{$text}|{$obs_qp})"; $wsp = "[\\x20\\x09]"; $obs_fws = "(?:{$wsp}+(?:{$crlf}{$wsp}+)*)"; $fws = "(?:(?:(?:{$wsp}*{$crlf})?{$wsp}+)|{$obs_fws})"; $ctext = "(?:{$no_ws_ctl}|[\\x21-\\x27\\x2A-\\x5b\\x5d-\\x7e])"; $ccontent = "(?:{$ctext}|{$quoted_pair})"; $comment = "(?:\\x28(?:{$fws}?{$ccontent})*{$fws}?\\x29)"; $cfws = "(?:(?:{$fws}?{$comment})*(?:{$fws}?{$comment}|{$fws}))"; $outer_ccontent_dull = "(?:{$fws}?{$ctext}|{$quoted_pair})"; $outer_ccontent_nest = "(?:{$fws}?{$comment})"; $outer_comment = "(?:\\x28{$outer_ccontent_dull}*(?:{$outer_ccontent_nest}{$outer_ccontent_dull}*)+{$fws}?\\x29)"; $atext = "(?:{$alpha}|{$digit}|[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b-\\x7e])"; $atext_domain = "(?:{$alpha}|{$digit}|[\\x2b\\x2d\\x5f])"; $atom = "(?:{$cfws}?(?:{$atext})+{$cfws}?)"; $atom_domain = "(?:{$cfws}?(?:{$atext_domain})+{$cfws}?)"; $qtext = "(?:{$no_ws_ctl}|[\\x21\\x23-\\x5b\\x5d-\\x7e])"; $qcontent = "(?:{$qtext}|{$quoted_pair})"; $quoted_string = "(?:{$cfws}?\\x22(?:{$fws}?{$qcontent})*{$fws}?\\x22{$cfws}?)"; $quoted_string = "(?:{$cfws}?\\x22(?:{$fws}?{$qcontent})+{$fws}?\\x22{$cfws}?)"; $word = "(?:{$atom}|{$quoted_string})"; $obs_local_part = "(?:{$word}(?:\\x2e{$word})*)"; $obs_domain = "(?:{$atom_domain}(?:\\x2e{$atom_domain})*)"; $dot_atom_text = "(?:{$atext}+(?:\\x2e{$atext}+)*)"; $dot_atom_text_domain = "(?:{$atext_domain}+(?:\\x2e{$atext_domain}+)*)"; $dot_atom = "(?:{$cfws}?{$dot_atom_text}{$cfws}?)"; $dot_atom_domain = "(?:{$cfws}?{$dot_atom_text_domain}{$cfws}?)"; $dtext = "(?:{$no_ws_ctl}|[\\x21-\\x5a\\x5e-\\x7e])"; $dcontent = "(?:{$dtext}|{$quoted_pair})"; $domain_literal = "(?:{$cfws}?\\x5b(?:{$fws}?{$dcontent})*{$fws}?\\x5d{$cfws}?)"; $local_part = "(({$dot_atom})|({$quoted_string})|({$obs_local_part}))"; $domain = "(({$dot_atom_domain})|({$domain_literal})|({$obs_domain}))"; $addr_spec = "{$local_part}\\x40{$domain}"; if (strlen($email) > 256) { return FALSE; } $email = stripComments($outer_comment, $email, "(x)"); if (!preg_match("!^{$addr_spec}\$!", $email, $m)) { return FALSE; } $bits = array('local' => isset($m[1]) ? $m[1] : '', 'local-atom' => isset($m[2]) ? $m[2] : '', 'local-quoted' => isset($m[3]) ? $m[3] : '', 'local-obs' => isset($m[4]) ? $m[4] : '', 'domain' => isset($m[5]) ? $m[5] : '', 'domain-atom' => isset($m[6]) ? $m[6] : '', 'domain-literal' => isset($m[7]) ? $m[7] : '', 'domain-obs' => isset($m[8]) ? $m[8] : ''); $bits['local'] = stripComments($comment, $bits['local']); $bits['domain'] = stripComments($comment, $bits['domain']); if (strlen($bits['local']) > 64) { return FALSE; } if (strlen($bits['domain']) > 255) { return FALSE; } if (strlen($bits['domain-literal'])) { $Snum = "(\\d{1,3})"; $IPv4_address_literal = "{$Snum}\\.{$Snum}\\.{$Snum}\\.{$Snum}"; $IPv6_hex = "(?:[0-9a-fA-F]{1,4})"; $IPv6_full = "IPv6\\:{$IPv6_hex}(:?\\:{$IPv6_hex}){7}"; $IPv6_comp_part = "(?:{$IPv6_hex}(?:\\:{$IPv6_hex}){0,5})?"; $IPv6_comp = "IPv6\\:({$IPv6_comp_part}\\:\\:{$IPv6_comp_part})"; $IPv6v4_full = "IPv6\\:{$IPv6_hex}(?:\\:{$IPv6_hex}){5}\\:{$IPv4_address_literal}"; $IPv6v4_comp_part = "{$IPv6_hex}(?:\\:{$IPv6_hex}){0,3}"; $IPv6v4_comp = "IPv6\\:((?:{$IPv6v4_comp_part})?\\:\\:(?:{$IPv6v4_comp_part}\\:)?){$IPv4_address_literal}"; if (preg_match("!^\\[{$IPv4_address_literal}\\]\$!", $bits['domain'], $m)) { if (intval($m[1]) > 255) { return FALSE; } if (intval($m[2]) > 255) { return FALSE; } if (intval($m[3]) > 255) { return FALSE; } if (intval($m[4]) > 255) { return FALSE; } } else { while (1) { if (preg_match("!^\\[{$IPv6_full}\\]\$!", $bits['domain'])) { break; } if (preg_match("!^\\[{$IPv6_comp}\\]\$!", $bits['domain'], $m)) { list($a, $b) = explode('::', $m[1]); $folded = strlen($a) && strlen($b) ? "{$a}:{$b}" : "{$a}{$b}"; $groups = explode(':', $folded); if (count($groups) > 6) { return FALSE; } break; } if (preg_match("!^\\[{$IPv6v4_full}\\]\$!", $bits['domain'], $m)) { if (intval($m[1]) > 255) { return FALSE; } if (intval($m[2]) > 255) { return FALSE; } if (intval($m[3]) > 255) { return FALSE; } if (intval($m[4]) > 255) { return FALSE; } break; } if (preg_match("!^\\[{$IPv6v4_comp}\\]\$!", $bits['domain'], $m)) { list($a, $b) = explode('::', $m[1]); $b = substr($b, 0, -1); # remove the trailing colon before the IPv4 address $folded = strlen($a) && strlen($b) ? "{$a}:{$b}" : "{$a}{$b}"; $groups = explode(':', $folded); if (count($groups) > 4) { return FALSE; } break; } return FALSE; } } } else { $labels = explode('.', $bits['domain']); if (count($labels) == 1) { return FALSE; } foreach ($labels as $label) { if (strlen($label) > 63) { return FALSE; } if (substr($label, 0, 1) == '-') { return FALSE; } if (substr($label, -1) == '-') { return FALSE; } } if (preg_match('!^[0-9]+$!', array_pop($labels))) { return FALSE; } } return TRUE; }
function compile($script, $noheader = false) { global $inlineFlagStack; global $localVarRegistry; global $currentFunction; global $globalVarRegistry; global $pramsRegistry; if (!is_array($inlineFlagStack)) { $inlineFlagStack = array(); } if (!is_array($pramsRegistry)) { $pramsRegistry = array(); } array_push($pramsRegistry, array()); if (!is_array($localVarRegistry)) { $localVarRegistry = array(); } if (!is_array($currentFunction)) { $currentFunction = array(); } if (!is_array($globalVarRegistry)) { $globalVarRegistry = array(); } array_push($currentFunction, "global"); array_push($localVarRegistry, array("", array())); array_push($inlineFlagStack, false); $source = ""; $script = explode("\n", $script); if (!$noheader) { $source .= "/* Generated By jsCc */\n\n"; } if ($script[0] == "/* Generated By jsCc */") { return "[jsCc: error: Line 1] Cannot compile already compiled code."; } $doCompile = true; foreach ($script as $scriptLine) { $scriptLine = stripComments($scriptLine); if ($scriptLine != "") { if ($scriptLine == "[begin js]") { $doCompile = false; continue; } if ($doCompile == true) { $source .= (!$noheader ? "\n// " . $scriptLine . "\n" : "") . compileLine(tokenize($scriptLine)); } else { if ($scriptLine == "[end js]") { $doCompile = true; } else { $source .= $scriptLine . "\n"; } } } } $source = "trainStations = [];\ntrainLines = [];\n" . $source; $source .= "executeTrain();\n"; array_pop($inlineFlagStack); $lvr = array_pop($localVarRegistry); $lvk = array_keys($lvr); foreach ($lvk as $lkey) { $lvars = $lvr[$lkey]; $vars = ""; if (is_array($lvr[$lkey])) { foreach ($lvars as $lvar) { $vars .= "var " . $lvar . " = \"" . $lvar . "\";\n"; } $source = str_replace("@localvars_" . $lkey, $vars, $source); } } array_pop($pramsRegistry); $source = str_replace("\r", "", str_replace("\n", "\\n", str_replace("\"", "\\\"", $source))); return $source; }