require_once("gettext.inc"); class Gettext { private $locale; private $encoding = "UTF-8"; //edit this function to implement all folders from locals private $supportedLocales = array( array("English","en"), array("Deutsch","de") ); function __construct($lang="",$userModel=NULL,$domain="default") { $update = false; //check if the language has been set to another one if(check($_GET['lang']) AND in_array($_GET['lang'],$this->supportedLocales)) { $lang = escape($_GET['lang']); if(check($userModel) AND $userModel !== NULL AND $userModel->getLang() != $lang) { $userModel->updateLang($lang); } $update = true; } else if(check($_POST['lang']) AND in_array($_POST['lang'],$this->supportedLocales)) { $lang = escape($_POST['lang']); if(check($userModel) AND $userModel !== NULL AND $userModel->getLang() != $lang) { $userModel->updateLang($lang); } $update = true; } else if(!check($_SESSION[LANG]) AND in_array($_SESSION[LANG],$this->supportedLocales)) // if no language is set now, f.e. on the first visit { $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); $update = true; } else { $lang = "en"; } //set locale to en for test phase, remove both lines //$lang = "en"; //$update = true; // ---------------- $_SESSION[LANG] = $lang; if($update) { $this->locale = $lang; T_setLocale(LC_ALL,$this->locale); T_bindtextdomain($domain,ROOT_DIR."/locale/"); T_bind_textdomain_codeset($domain,$this->encoding); T_textdomain($domain); } } public function getSupportedLocales() { $r = array(); foreach($this->supportedLocales as $l) { if(file_exists(LOCALEDIR."/".$l[1]) OR $l[1]=="en") { array_push($r,$l); } } return $r; } } ?> //shortcut for every select db query /*----- Copy paste EXAMPLE--------- // stdSelectDB($this->sql,DB_USER,"*","id='".$id."'"); stdSelectDB($sql,DB_IMAGES,"*","showid='".$idImg."'","single_assoc","id","ASC",MYSQL_DB_IMAGES); mysqli_fetch_assoc($result); Returns an associative array of strings representing the fetched row. NULL if there are no more rows in result-set //--------------------------------- */ function stdSelectDB($sql,$tablename,$selectfields="*",$conditions="",$fetch="single_assoc",$orderkeyword = "id", $asc = "ASC",$db=MYSQL_DB,$limit="") { $tablename = $db.".".$tablename; //mail("bug@depixit.com","bootstraptest","SELECT ".$selectfields." FROM ".$tablename." WHERE ".$conditions." ORDER BY ".$orderkeyword." ".$asc); $result = $sql->query("SELECT ".$selectfields." FROM ".$tablename." WHERE ".$conditions." ORDER BY ".$orderkeyword." ".$asc." ".$limit) or mail(BUGEMAIL,"MYSQL ERROR","Select Error for conditions:".$conditions." on table:".$tablename.". Selectedfield: ".$selectfields."\nError Message:".mysqli_error($sql)); //mail(BUGEMAIL,"ARCHIVE ERROR","Select Error for conditions:".$conditions." on table:".$tablename.". Selectedfield: ".$selectfields."\nError Selected:".mysqli_num_rows($result)); //use this if there is only one result expected if($fetch=="single_assoc") { $final = mysqli_fetch_assoc($result); } //use this if multiple results are expected else if($fetch=="multi_assoc") { $final = array(); if(mysqli_num_rows($result)>0) { while($output = mysqli_fetch_assoc($result)) { array_push($final,$output); } } } //use this for alternative treatment else $final = $result; return $final; } //-----Copy paste EXAMPLE--------- // stdUpdateDB($this->sql,DB_USER,"lang='$newlang',kirmes=$lol'","id='".$id."'"); //--------------------------------- function stdUpdateDB($sql,$tablename,$updatestring="*",$conditions="",$db=MYSQL_DB) { $tablename = $db.".".$tablename; $result = $sql->query("UPDATE ". $tablename . " SET ". $updatestring . " WHERE " . $conditions) or mail(BUGEMAIL,"MYSQL ERROR","Update Error for conditions:".$conditions." on table:".$tablename.". Updatestringfield: ".$updatestring."\nError Message:".mysqli_error($sql)); return $result; } //-----Copy paste EXAMPLE--------- // stdInsertDB($this->sql,DB_USER,"email,username,firstname,lastname,lang,activated","'$email',$username','','','$lang',0"); //--------------------------------- function stdInsertDB($sql,$tablename,$rownames,$values,$db=MYSQL_DB) { $tablename = $db.".".$tablename; $result = $sql->query("INSERT INTO ".$tablename." (".$rownames.") VALUES (".$values.")") or mail(EMAIL,"MYSQL ERROR","Insert Error for rownames:".$rownames.", Error Message:".mysqli_error($sql)); return $result; } //-----Copy paste EXAMPLE--------- // stdDeleteDB($this->sql,DB_USER,"id='".$id."'"); //--------------------------------- function stdDeleteDB($sql,$tablename,$conditions,$db=MYSQL_DB) { $tablename = $db.".".$tablename; $result = $sql->query("DELETE FROM ".$tablename . " WHERE " . $conditions); return $result; } function stdWriteToFileDB($result,$filename) { if(!is_bool($result) && mysqli_num_fields($result)>0) { $fh = fopen($filename, 'w'); while ($row = mysqli_fetch_array($result)) { $last = end($row); $num = mysqli_num_fields($result) ; for($i = 0; $i < $num; $i++) { fwrite($fh, $row[$i]); if ($row[$i] != $last) fwrite($fh, ", "); } fwrite($fh, "\n"); } fclose($fh); } else{ mail(BUGEMAIL,"MYSQL WRITEFILE ERROR","Not a valid mysql Result in function stdWriteToFileDB for filename: ".$filename); } } ?> /* SITE SPECIFIC */ /*function printIconReward($size="32",$wrap=true,$imgclass="") { ?> if($wrap){ ?>
if($wrap){ ?>