size_width(100); // set width for thumbnail, or $thumb->size_height(300); // set height for thumbnail, or $thumb->size_auto(200); // set the biggest width or height for thumbnail $thumb->jpeg_quality(75); // [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75 $thumb->show(); // show your thumbnail $thumb->save("./huhu.jpg"); // save your thumbnail to file ---------------------------------------------- Note : - GD must Enabled - Autodetect file extension (.jpg/jpeg, .png, .gif, .wbmp) but some server can't generate .gif / .wbmp file types - If your GD not support 'ImageCreateTrueColor' function, change one line from 'ImageCreateTrueColor' to 'ImageCreate' (the position in 'show' and 'save' function) */############################################ class thumbnail { var $img; function thumbnail($imgfile) { //detect image format $this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile); $this->img["format"]=strtoupper($this->img["format"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG $this->img["format"]="JPEG"; $this->img["src"] = ImageCreateFromJPEG ($imgfile); } elseif ($this->img["format"]=="PNG") { //PNG $this->img["format"]="PNG"; $this->img["src"] = ImageCreateFromPNG ($imgfile); } elseif ($this->img["format"]=="GIF") { //GIF $this->img["format"]="GIF"; $this->img["src"] = ImageCreateFromGIF ($imgfile); } elseif ($this->img["format"]=="WBMP") { //WBMP $this->img["format"]="WBMP"; $this->img["src"] = ImageCreateFromWBMP ($imgfile); } else { //DEFAULT echo "Not Supported File"; exit(); } @$this->img["lebar"] = imagesx($this->img["src"]); @$this->img["tinggi"] = imagesy($this->img["src"]); //default quality jpeg $this->img["quality"]=75; } function size_height($size=100) { //height $this->img["tinggi_thumb"]=$size; @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; } function size_width($size=100) { //width $this->img["lebar_thumb"]=$size; @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; } function size_auto($size=100) { //size if ($this->img["lebar"]>=$this->img["tinggi"]) { $this->img["lebar_thumb"]=$size; @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; } else { $this->img["tinggi_thumb"]=$size; @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; } } function jpeg_quality($quality=75) { //jpeg quality $this->img["quality"]=$quality; } function show() { //show thumb @Header("Content-Type: image/".$this->img["format"]); /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imageJPEG($this->img["des"],"",$this->img["quality"]); } elseif ($this->img["format"]=="PNG") { //PNG imagePNG($this->img["des"]); } elseif ($this->img["format"]=="GIF") { //GIF imageGIF($this->img["des"]); } elseif ($this->img["format"]=="WBMP") { //WBMP imageWBMP($this->img["des"]); } } function save($save="") { //save thumb if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]); /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imageJPEG($this->img["des"],"$save",$this->img["quality"]); } elseif ($this->img["format"]=="PNG") { //PNG imagePNG($this->img["des"],"$save"); } elseif ($this->img["format"]=="GIF") { //GIF imageGIF($this->img["des"],"$save"); } elseif ($this->img["format"]=="WBMP") { //WBMP imageWBMP($this->img["des"],"$save"); } } } ?> $value ){ if (!is_array($value)){ $cgi[$key]=htmlspecialchars($value,ENT_QUOTES); $cgir[$key]=$value; }else{ $cgi[$key]=$value; $cgir[$key]=$value; } } foreach($HTTP_POST_VARS as $key => $value ){ if (!is_array($value)){ $cgi[$key]=htmlspecialchars($value,ENT_QUOTES); $cgir[$key]=$value; }else{ $cgi[$key]=$value; $cgir[$key]=$value; } } //-----------------------------Database Functions-------------------------------------------- function SQLInsert($query){ //echo "
".$query."
"; $q = @mysql_query($query); if (!$q) { erradd ('Query failed: '.mysql_error()); return; } return mysql_insert_id(); } function SQLUpdate($query){ //echo $query . "
"; $q = @mysql_query($query); if (!$q) { erradd ('Query failed: '.mysql_error()); return; } return $q; } function SQLGetCount($query){ $q = @mysql_query($query); if ($q){ $st = mysql_fetch_array($q); return $st[0]; }else{return 0;} } function SQLGetRow($query){ //echo $query . "\n"; $q = @mysql_query($query); if (!$q) { erradd ('Query failed: '.mysql_error()."
"); return; } if (!@mysql_num_rows($q)) { return 0; } else{ $st=""; $st = mysql_fetch_object($q); return $st; } } function SQLGetRows($query){ ///echo $query . "
"; $q = @mysql_query($query); if (!$q) {erradd ('Query failed: '.mysql_error()."
"); return; } if (!@mysql_num_rows($q)) {return;} else{ $st=""; $i=0; while ($row = mysql_fetch_object($q)){ $st[$i]=$row; $i++; } mysql_free_result ($q); return $st; } } function SQLDelete($query){ //echo $query; $q = @mysql_query($query); if (!$q) {erradd ('Query failed: '.mysql_error()); return; } return $q; } function vDBGetRowsSQL($sql){ /* $Table - table name (e.g. "UserDesigns" ) $Where - where condition (e.g. " ID='1' ") return vDBGetRows("SiteDesigns"); */ $str=$sql; //echo $str; $q = @mysql_query($str); if (!$q) {erradd ('Query failed: '.mysql_error()); return; } if (!@mysql_num_rows($q)) {return;} else{ $st=""; $i=0; while ($row = mysql_fetch_object($q)){ $st[$i]=$row; $i++; } return $st; } } function MySQLConnect ($server, $user, $pass, $dbname){ $lnk = @mysql_connect($server, $user, $pass) or die("Failed to connect MySQL Server: " . mysql_error()); @mysql_select_db($dbname, $lnk) or die ("Failed to connect DBS $dbname : " . mysql_error()); } //---------------------------------------- MySQL Func Finish ---------------------------------------- function valid_email($email) { $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i"; if ( !preg_match($regexp, $email) ) { return false; } return true; } function fsize($size) { $size=(float) $size; //Setup some common file size measurements. $kb=1024; $mb=1048576; $gb=1073741824; $tb=1099511627776; //Get the file size in bytes. //Format file size if($size < $kb) { return $size." B"; } else if($size < $mb) { return round($size/$kb,2)." KB"; } else if($size < $gb) { return round($size/$mb,2)." MB"; } else if($size < $tb) { return round($size/$gb,2)." GB"; } else { return round($size/$tb,2)." TB"; } } function StripNULL ($ch) { if ($ch=='') { return ' '; } else { return $ch; } } function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function erradd ($str){ global $error; array_push ($error, $str); } //------------------------------------------------------------------------------------------ function GetEvents ($id){ global $conf, $error, $cgi, $errors, $msg; if ($id==0) { return SQLGetRows ("select * from events order by dt desc limit {$conf['events_num']};"); } else { return SQLGetRow ("select * from events where ID='$id';"); } } function GetNewEvents ($id){ global $conf, $error, $cgi, $errors, $msg; $dt=date ("Ymd"); $a= SQLGetRows ("select * from events where dt>'$dt' order by dt desc limit {$conf['events_num']};"); if (!$a) { return SQLGetRows ("select * from events order by dt desc limit 1;"); } else { return SQLGetRows ("select * from events where dt>'$dt' order by dt desc limit {$conf['events_num']};"); } } function GetNews ($id, $skip){ global $conf, $error, $cgi, $errors, $msg; if ($id==0) { return SQLGetRows ("select * from news order by dt desc limit {$conf['news_num']} offset $skip;"); } else { return SQLGetRow ("select * from news where ID='$id';"); } } function GetTexts ($module){ global $conf, $error, $cgi, $errors, $msg; return SQLGetRow ("select * from texts where module='$module';"); } function GetGallery ($id, $skip){ global $conf, $error, $cgi, $errors, $msg; if ($id==0) { return SQLGetRows ("select * from gallery order by id desc limit {$conf['gallery_num']} offset $skip;"); } else { return SQLGetRow ("select * from gallery where ID='$id';"); } } function GetGal ($id){ global $conf, $error, $cgi, $errors, $msg; $res['prev']=SQLGetRow ("select ID from gallery where id<$id order by id desc limit 1;"); $res['prev']=$res['prev']->ID; $res['next']=SQLGetRow ("select ID from gallery where id>$id order by id asc limit 1;"); $res['next']=$res['next']->ID; return $res; } function GetGB ($skip, $id){ global $conf, $error, $cgi, $errors, $msg; if ($id>0) { return SQLGetRows ("select * from gb where id=$id;"); } else { return SQLGetRows ("select * from gb order by id desc limit {$conf['gb_num']} offset $skip;"); } } function SaveGB ($name, $post){ global $conf, $error, $cgi, $errors, $msg; if (strlen($name) == 0) { erradd ($errors['name_not_specified']); } if (strlen($post) == 0) { erradd ($errors['no_message']); } if (count ($error)==0) { $dt=time(); $sql=(int) SQLInsert ("INSERT INTO GB (name, dt, full) values ('$name', '$dt', '$post');"); if ((int) @$sql>0) { return 1; } else { erradd ($errors['db_error']); return 0; } } //sreturn SQLGetRows ("select * from gb order by id desc limit {$conf['gb_num']} offset $skip;"); } function GetMusic ($id){ global $conf, $error, $cgi, $errors, $msg; if ($id==0) { return SQLGetRows ("select * from music;"); } else { return SQLGetRows ("select * from tracks where Album='$id';"); } } function register ($name, $mail){ global $conf, $error, $cgi, $errors, $msg; if (strlen($name)==0) { erradd ($errors['empty_name']); } if (!valid_email($mail)) { erradd ($errors['email_invalid']); } if (UserExist($mail)) { erradd ($errors['dup_user']); } if (count ($error)==0) {$hash=md5($mail.$name.time()); $headers=''; // $headers .= "MIME-Version: 1.0\r\n"; // $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; // $headers .= "To: ".$name." <".$mail.">\r\n"; // $headers .= "From: Admin <".$conf['contact_mail'].">\r\n\r\n"; // $message="Hello, $name.
// To Confirm Your Subscription Please follow the Link"; $message="Hello, $name. To Confirm Your Subscription Please follow the link {$conf['sitelink']}index.php?mod=subscribe&mail=$mail&confirm=$hash"; mail ($mail, "Subscription Confirmation", $message, $headers); return SQLInsert ("INSERT INTO subscribers (name, mail, hash, active) values ('$name', '$mail', '$hash', '0');"); } else { return False; } } function UserExist ($mail){ $sql=(integer) SQLGetCount ("select * from subscribers where mail='$mail'"); if ($sql>0) { return True; } else { return False; } } function confirm ($mail, $hash){ $sql=(integer) SQLGetCount ("select * from subscribers where mail='$mail' and hash='$hash'"); if ($sql>0) { sqlupdate ("UPDATE subscribers set active='1' where mail='$mail' and hash='$hash'"); return True; } else { return False; } } function search ($module, $str, $skip){ switch ($module) { default: break; case "events": $res=SQLGetRows ("select * from events where venue like '%$str%' or location like '%$str%' or full like '%$str%' order by id desc limit 10 offset $skip;"); $cnt=SQLGetCount ("select count(*) from events where venue like '%$str%' or location like '%$str%' or full like '%$str%'"); break; case "gallery": $res=SQLGetRows ("select ID, file_desc as stext from gallery where file_desc like '%$str%' order by id desc limit 10 offset $skip;"); $cnt=SQLGetCount ("select count(*) from events where file_desc like '%$str%'"); break; case "gb": $res=SQLGetRows ("select ID, full as stext from gb where full like '%$str%' order by id desc limit 10 offset $skip;"); $cnt=SQLGetCount ("select count(*) from gb where full like '%$str%'"); break; } $x['c']=$cnt; $x['res']=$res; return $x; } function price_store ($nm){ global $conf, $error, $cgi, $errors, $msg; $uploaddir = "download/"; if (basename($_FILES['price']['name']) != '') { $uploadfile = $uploaddir . basename($_FILES['price']['name']); if (move_uploaded_file($_FILES['price']['tmp_name'], $uploadfile)) { if ($conf['price_fname'] != $_FILES['price']['name']) { unlink ($uploaddir . $conf['price_fname']); } $conf['price_fname']=$_FILES['price']['name']; ConfSave ($conf); return 1; } else { erradd ($errors['admin_upload']); return 0; } } } //--------------------------------------------------------------------------------------------------------- function GetModContent ($mod){ return SQLGetRows ("select * from pages where mod='$mod';"); } //function GetProd (){ // return SQLGetRows ("select * from prod;"); // } function AdminLogin ($login, $pass){ global $conf, $error, $errors; if (strlen($login)==0) { erradd ($errors['empty_login']); } if (strlen($pass)==0) { erradd ($errors['empty_pass']); } if (count ($error)>0) { return 0; } else { if (($conf['adminlogin']==$login) and ($conf['adminpass']==$pass)) { $_SESSION['admin']=1; $_SESSION['logged']=1; return 1; } else { erradd ($errors['login_incorrect']); return 0; } } } function AdminModEdit ($param, $mod){ global $conf, $error, $errors, $cgi; if ($param['content'] == '') { erradd ($errors['no_message']); } if ($param['topic'] == '') { erradd ($errors['no_topic']); } if (count ($error)==0) { $sql=(integer) SQLUpdate ("update pages set content='{$param['content']}', topic='{$param['topic']}' where mod='$mod';"); if ((int) @$sql>0) { return 1; } else { erradd ($errors['db_error']); return 0; } } } function ConfSave ($cnf){ global $errors; $str=" $v) { $str.= '$conf["'.$k.'"]="'.$v."\";\n"; } $str.="\n?>"; @$fp=fopen("conf/config.php",'w'); if (!$fp) erradd ($errors['conf_open']); @fwrite($fp,$str); @fclose($fp); } function GetProd ($id=0){ if ((int)$id==0) { return SQLGetRows ("select * from prod order by id desc;"); } else { } return SQLGetRows ("select * from prod where id='$id';"); } function SaveProd ($param, $mod){ global $conf, $error, $errors, $cgi; if ($param['nm'] == '') { erradd ($errors['prod_no_name']); } if ($param['desc'] == '') { erradd ($errors['prod_no_desc']); } if ($param['price'] == '') { erradd ($errors['prod_no_price']); } $uploaddir = $conf['prod_dir']; if (count ($error)==0) { if ((int)@$param['id']>0) { $sql=(integer) SQLUpdate ("update prod set nm='{$param['nm']}', $mod.desc='{$param['desc']}', price='{$param['price']}' where id='{$param['id']}';"); $uploadfile = $uploaddir . $param['id'] . ".jpg"; $uploadfile_temp = $uploaddir . 'temp_' . $param['id'] . ".jpg"; } else { $sql=(integer) SQLInsert ("insert into prod (nm, $mod.desc, price) values ('{$param['nm']}', '{$param['desc']}','{$param['price']}');"); $uploadfile = $uploaddir . $sql . ".jpg"; $uploadfile_temp = $uploaddir . $sql . ".jpg"; } if ((int) @$sql>0) { if (basename($_FILES['photo']['name']) != '') { if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile_temp)) { include 'functions/resize.php'; $thumb=new thumbnail ($uploadfile_temp); // generate image_file, set filename to resize // $thumb->size_auto(100); // set the biggest width or height for thumbnail $thumb->size_width(80); $thumb->jpeg_quality(95); // [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75 $thumb->save($uploadfile); } else { erradd ($errors['upload']); } } return 1; } else { erradd ($errors['db_error']); return 0; } } } function DelProd ($param, $mod){ global $conf, $error, $errors, $cgi; if (count ($error)==0) { $sql=(int) SQLDelete ("delete from prod where id='{$param['id']}';"); if ((int) @$sql>0) { $uploaddir = $conf['prod_dir']; unlink ($uploaddir . "{$param['id']}.jpg"); return 1; } else { erradd ($errors['db_error']); return 0; } } } function sendmail ($email, $subject, $msg, $from){ global $conf; $mailheaders = "From: $from\n"; $mailheaders .= "MIME-Version: 1.0\n"; $mailheaders .= "Content-Type: text/plain; charset=iso-8859-1\n"; $mailheaders .= "Content-Transfer-Encoding: 8bit\n"; $mailheaders .= "X-Priority: 3\n"; $mailheaders .= "X-MSMail-Priority: Normal\n"; $mailheaders .= "X-Mailer: {$conf['sitename']}\n\n"; return (integer) @mail($email, $subject, $msg, $mailheaders); } function contact ($umail, $message, $name){ global $conf, $errors, $error, $msg; if (strlen($name) == 0) { erradd ($errors['name_not_specified']); } if (strlen($message) == 0) { erradd ($errors['no_message']); } if (!valid_email($umail)) { erradd ($errors['email_invalid']); } if (count ($error)>0) { return 0; } $from="$name [$umail] <\"$umail\">"; $subject = "$umail for {$conf['sitename']}"; $message=html_entity_decode($message, ENT_QUOTES); $message=stripcslashes($message); @$ret=sendmail($conf['contact_mail'], $subject, $message, $from); return $ret; } //--------------------------------------------------------------------------------------------------------- ?>