00001 <?php
00009 abstract class SWATFunctions {
00010
00011
00012
00013
00014
00023 function safeSqlOld($a, $ignoreBackslash = false) {
00024
00025 $a = addslashes($a);
00026 $a = preg_replace("/'/", "''", $a);
00027 if(!$ignoreBackslash) {
00028 $a = preg_replace("/\\/", "", $a);
00029 $a = preg_replace("/[\\\]*;/", "\\\;", $a);
00030 }
00031 $a = preg_replace("/%/", "", $a);
00032 $a = preg_replace("/\*/", "\\*", $a);
00033 return ($a);
00034 }
00035
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 public function safeSql($a) {
00059 $a = mysql_escape_string($a);
00060 $a = str_replace(array(';', '%', '_'),
00061 array('\\;', '\\%', '\\_'), $a);
00062 return $a;
00063 }
00064
00065
00066
00067
00068
00076 function redirect($url) {
00077 global $USER, $SWAT;
00078 if (isset($SWAT)){
00079 $SWAT->syncSession();
00080 }
00081 if (isset($USER) && isset($_SESSION) && isset($_SESSION['USER'])) {
00082 $_SESSION['USER'] = &$USER;
00083 session_write_close();
00084 }
00085 STimer::enable(false);
00086 header("Location: $url");
00087 exit;
00088 }
00089
00097 function redirectHTTPS($req = "") {
00098 if($req == "")
00099 $req = $_SERVER['REQUEST_URI'];
00100 $req = preg_replace("/%7E/", "~", $req);
00101 $dest = "https://" . $_SERVER['SERVER_NAME'] . $req;
00102 STimer::enable(false);
00103 header("Location: $dest");
00104 exit;
00105 }
00106
00107
00108
00109
00110
00116 function stripArgs($uri) {
00117 $parts = explode("?", $uri);
00118 return $parts[0];
00119 }
00120
00125 function getURI() {
00126 return $_SERVER['REQUEST_URI'];
00127 }
00128
00133 function getURINoArgs() {
00134 return self::stripArgs(self::getURI());
00135 }
00136
00137
00138
00139
00140
00146 function removeSpace($a) {
00147 $a = preg_replace("/\s/", "", $a);
00148 return ($a);
00149 }
00150
00156 function formatTimestamp($timestamp) {
00157 $submissionTime = (int)((time() - strtotime($timestamp))/(60*60*24));
00158 $timeAgo = "";
00159
00160 if ($submissionTime == 1)
00161 $timeAgo = "1 day ago";
00162 else if ($submissionTime == 0)
00163 $timeAgo = "Today";
00164 else if ($submissionTime > 31) {
00165 $months = (int)($submissionTime/31);
00166 $days = $submissionTime%31;
00167 if ($months == 1) $monthFormat = "month";
00168 else $monthFormat = "months";
00169 if ($days == 1) $dayFormat = "day";
00170 else if ($days == 0) $dayFormat = "";
00171 else $dayFormat = "days";
00172
00173 $timeAgo = $months . " " . $monthFormat . " " . $days . " " . $dayFormat . " ago";
00174 } else
00175 $timeAgo = $submissionTime . " days ago";
00176
00177 return ($timeAgo);
00178 }
00179
00180 public static function hashPassword($password, $salt) {
00181 return substr(hash('sha256', $password . $salt), 0, 32);
00182 }
00183 }
00184 ?>