= 7) $mysqli = new mysqli('localhost', 'dongnudmtb_user', 'dggfgfig56767@', 'dongnudmtb_data'); else { $db = @mysql_connect("localhost","dongnudmtb_user","dggfgfig56767@"); $dbuse = @mysql_select_db("dongnudmtb_data",$db); } if(is_string($mysqli)){ include("config/db_mysql_error.php"); exit(); } if($version_php >= 7) $mysqli->query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary"); else mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary"); @date_default_timezone_set('Asia/Saigon'); $domain_main = $_SERVER['SERVER_NAME']; $fullpath = 'https://'.$domain_main; $auto_key_pass = "2u.com.vn"; $check_fl_domain = "localhost"; $_SESSION['sub_demo'] = "/"; $_SESSION['thumuc'] = "content_dongnudaminhthaibinh"; $array_tiennghi = array('Bar', 'BBQ Area', 'Car parking', 'Coffee shop', 'Elevator', 'Event room', 'Fitness center', 'Front desk', 'Guest room', 'Housekeeping', 'Laundry', 'Minimart', 'Motobike parking', 'Playground indoor', 'Playground outdoor', 'Putting green', 'Relax area', 'Restaurant', 'Sauna', 'Security', 'Shop', 'Shuttle bus', 'Spa', 'Steam room', 'Supermarket', 'Swimming pool', "Kid's pool", 'Table tennis', 'Tennis court', 'Yoga'); $pos = strpos($_SERVER['REQUEST_URI'], "nguoiquanly"); $token = '6468EF442F8962959169778Be43e2589e149878d'; if ($pos == false) { require_once 'Mobile_Detect.php'; $detect = new Mobile_Detect; } ?> $line) { if ($line_num == 0) { $maxu = $line; } else { $fp = strpos($line, '****'); $nam = substr($line, 0, $fp); $sp = strpos($line, '++++'); $val = substr($line, $fp + 4, $sp - ($fp + 4)); $diff = $sd - $val; if ($diff < 300 && $nam != $rip) { $count = $count + 1; $line2 = $line2 . $line; } } } $my = $rip . "****" . $sd . "++++\n"; if ($count > $maxu) $maxu = $count; $open1 = fopen($file1, "w"); fwrite($open1, "$maxu\n"); fwrite($open1, "$line2"); fwrite($open1, "$my"); fclose($open1); $count = $count; $maxu = $maxu + 200; return $count; } function today() { $file_count = fopen('counter/count.txt', 'rb'); $data = ''; while (!feof($file_count)) $data .= fread($file_count, 4096); fclose($file_count); list($today, $yesterday, $total, $date, $days) = explode("%", $data); return $today; } function yesterday() { $file_count = fopen('counter/count.txt', 'rb'); $data = ''; while (!feof($file_count)) $data .= fread($file_count, 4096); fclose($file_count); list($today, $yesterday, $total, $date, $days) = explode("%", $data); return $yesterday; } function total() { $file_count = fopen('counter/count.txt', 'rb'); $data = ''; while (!feof($file_count)) $data .= fread($file_count, 4096); fclose($file_count); list($today, $yesterday, $total, $date, $days) = explode("%", $data); echo $total; } function avg() { $file_count = fopen('counter/count.txt', 'rb'); $data = ''; while (!feof($file_count)) $data .= fread($file_count, 4096); fclose($file_count); list($today, $yesterday, $total, $date, $days) = explode("%", $data); echo ceil($total / $days); } function onlineuser($timeroff = 360, $sidd) { $ipadd = $_SERVER['REMOTE_ADDR']; $baygio = time(); ///$deluser $sql_del = query("delete from phl_online where timer+$timeroff < $baygio"); /// Check user hien tai $sqltim = query("SELECT `uid` FROM phl_online WHERE `sidd`='$sidd'"); if (!num_rows($sqltim)) { $_SESSION['web_user'] = NULL; } ///$them vao hay khong? $sql_tim = query("select uip,sidd from phl_online where uip='$ipadd' and sidd='$sidd'"); $cohaykhong = fetch_array($sql_tim); if ($cohaykhong) { $sql_upd = query("update from phl_online SET timer='$baygio' where uip='$ipadd'"); } else { $sql_them = query("insert into phl_online(uip,sidd,timer) values ('$ipadd','$sidd','$baygio')"); $sql_counter = query("update phl_bodem SET coonter=coonter+1"); } /// xuat ra $sql_show = query("select count(*) as tongso from phl_online"); $sho = fetch_array($sql_show); return $sho['tongso']; } function thongke() { $sql = query("select * from phl_bodem"); $sho = fetch_array($sql); return $sho['coonter']; } function actionDB($array, $table, $type = 'add', $array_remove = array(), $condition = NULL) { global $mysqli; $bang_db = ""; $bang_value = ""; if ($type == 'delete') { $sql_del = $mysqli->query("DELETE FROM $table WHERE $condition"); if ($sql_del) { return true; } } foreach ($array as $key => $value) { if ($type == 'add') { if (is_array($array_remove)) { if (in_array($key, $array_remove)) continue; } $bang_db .= "$key,"; $bang_value .= "'" . PlanText($value) . "',"; } if ($type == 'update') { if (is_array($array_remove)) { if (in_array($key, $array_remove)) continue; } $bang_db .= "`$key`='" . PlanText($value) . "',"; } } $bang_db = substr($bang_db, 0, -1); $bang_value = substr($bang_value, 0, -1); if ($type == 'add') { $mysqli->query("INSERT INTO `$table`($bang_db) VALUES($bang_value)"); return $mysqli->insert_id; } if ($type == 'update') { $mysqli->query("UPDATE $table SET $bang_db WHERE $condition"); return true; } } function Mail_Sender($mailto, $nameto, $subject, $body, $kieu) { //$kieu: 1 - Mail liên hệ; 2 - Mail tour lẻ; 3 - Tour customer; 4 - Tư vấn tour miễn phí; 5 - Mail dang ky đại lý; 6 - Tiếp thị liên kết; 7 - Đặt phòng khách sạn global $mysqli; $body = $mysqli->real_escape_string($body); $array_mailto = explode(';', $mailto); $nameto = explode(';', $nameto); if (count($array_mailto) > 0) { foreach ($array_mailto as $key => $value) { $sql = $mysqli->query("INSERT INTO `phl_mail_sender`(`mailto` ,`nameto` ,`subject` ,`content`,`thoigian` ,`kieu`) VALUES('$value','$nameto[$key]','$subject','$body','" . time() . "','$kieu')"); } } elseif (!empty($mailto)) { $sql = $mysqli->query("INSERT INTO `phl_mail_sender`(`mailto` ,`nameto` ,`subject` ,`content`,`thoigian` ,`kieu`) VALUES('$mailto','$nameto','$subject','$body','" . time() . "','$kieu')"); } } function query($query, $versionphp = '7') { if (VERSIONPHP > 7) { global $mysqli; return @$mysqli->query("$query"); } else { return @mysql_query($query); } } function real_escape_string($str, $versionphp = '7') { if (VERSIONPHP > 7) { global $mysqli; return @$mysqli->real_escape_string($str); } else return @mysql_real_escape_string($str); } function num_rows($db, $versionphp = '7') { if (VERSIONPHP > 7) { return @$db->num_rows; } else { return @mysql_num_rows($db); } } function insert_id($versionphp = '7') { if (VERSIONPHP > 7) { global $mysqli; return @$mysqli->insert_id; } else { return @mysql_insert_id(); } } function fetch_array($db, $versionphp = '7') { if (VERSIONPHP > 7) { return @$db->fetch_array(); } else { return @mysql_fetch_array($db); } } function fetch_assoc($db, $versionphp = '7') { if (VERSIONPHP > 7) { return @$db->fetch_assoc(); } else { return @mysql_fetch_assoc($db); } } function PlanText($text) { return real_escape_string(stripslashes(trim($text))); } function getRouter($option) { $slug = isset($option['slug']) ? $option['slug'] : ''; $more = isset($option['key']) ? " AND `key`='" . $option['key'] . "'" : ''; return query("SELECT * FROM `phl_router` WHERE `slug`='" . $slug . "' $more LIMIT 1"); } function checkIdHaveRouter($option) { $table = isset($option['table']) ? $option['table'] : ''; $more = isset($option['key']) ? " AND `key`='" . $option['key'] . "'" : ''; return query("SELECT * FROM `phl_router` WHERE `table`='" . $table . "' $more LIMIT 1"); } function get_root_cat($id, $cat, $table) { if ($id AND $table == 'phl_baiviet') { $sql = query("SELECT `step` FROM `phl_baiviet` WHERE `pid`='$id'"); $row = fetch_assoc($sql); $step = $row['step']; } if ($cat AND $table == 'phl_danhmuc') { $sql = query("SELECT `step` FROM `phl_danhmuc` WHERE `pid`='$cat'"); $row = fetch_assoc($sql); $step = $row['step']; } return $step; } function get_name_kietxuat_cat($step, $id) { $sql_a = query("SELECT `tieude_vi`, `tieude_en` FROM `phl_danhmuc` WHERE `step`='$step' AND `pid`='$id' AND `trangthai`='1'"); $row = fetch_assoc($sql_a); return $row["tieude_" . $_SESSION["lang"]]; } function get_no_follow($nid, $type = 1) { if ($type == 1) $sql_a = query("SELECT `cindex` FROM `phl_danhmuc` WHERE `pid`='$nid' LIMIT 1"); else $sql_a = query("SELECT `cindex` FROM `phl_baiviet` WHERE `pid`='$nid' LIMIT 1"); $row = fetch_assoc($sql_a); return $row["cindex"]; } function get_id_topic_current($id) { $sql_a = query("SELECT `id_danhmuc` FROM `phl_baiviet` WHERE `pid`='$id' LIMIT 1"); $row = fetch_assoc($sql_a); return $row["id_danhmuc"]; } function get_id_danhmuc($id) { $sql_a = query("SELECT * FROM `phl_baiviet` WHERE `id_danhmuc`='$id' LIMIT 1"); return fetch_assoc($sql_a); } function banner_img($kietxuat, $name) { $sqllogo = query("SELECT * FROM phl_hinhanh WHERE trangthai = 1 AND id_loaihinhanh =" . $kietxuat . " ORDER BY ngaydang DESC LIMIT 1"); $result = fetch_array($sqllogo); return $result["duongdantin"] . '/' . $result["$name"]; } function move_to_url($fullpath, $mess, $url, $title, $tim) ///Chuyen qua 1 URL khac { $f = @file_get_contents("redirect.html"); $a = array($fullpath, $mess, $url, $title, $tim); $b = array("[%FULLPATH%]", "[%CONTENTS%]", "[%REDIRECT%]", "[%TITLE%]", "[%TIME%]"); echo str_replace($b, $a, $f); } function create_pass($pass, $key) { return strtoupper(md5($pass . md5($key)) . sha1($key . sha1($pass))); } function create_key() { $alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; $text = substr(str_shuffle($alphanum), 0, rand(5, 9)); return $text; } function kiem_tra_cap_con($stepid, $nid = 0) { $sql_a = query("SELECT * FROM `phl_danhmuc` WHERE `step`='$stepid' AND `cha`='$nid' ORDER BY `sapxep` ASC LIMIT 1"); $count = num_rows($sql_a); if ($count > 0) return 1; else return 0; } function kiem_tra_bai_viet_chu_de($stepid, $nid = 0) { $sql_a = query("SELECT * FROM `phl_baiviet` WHERE `step`='$stepid' AND `id_danhmuc`='$nid' ORDER BY `pid` DESC LIMIT 1"); $count = num_rows($sql_a); if ($count > 0) return 1; else return 0; } function png2jpg($UploadFile, $NameFile, $duongdantin, $ext) { //new file name once the picture is converted $namepic = time() . rand(1111, 9999) . "_" . str_replace('.', '', $NameFile) . '.jpg'; $converted_filename = "../" . $duongdantin . "/" . $namepic; if ($ext == "png") $new_pic = imagecreatefrompng($UploadFile); if ($ext == "gif") $new_pic = imagecreatefromgif($UploadFile); // Create a new true color image with the same size $w = @imagesx($new_pic); $h = @imagesy($new_pic); $white = imagecreatetruecolor($w, $h); // Fill the new image with white background $bg = @imagecolorallocate($white, 255, 255, 255); @imagefill($white, 0, 0, $bg); // Copy original transparent image onto the new image @imagecopy($white, $new_pic, 0, 0, 0, 0, $w, $h); $new_pic = $white; @imagejpeg($new_pic, $converted_filename); $return = true; @imagedestroy($new_pic); return $namepic; } function chmod_not_ftp($duongdan) { if (!is_dir($duongdantin)) { @mkdir($duongdan); @chmod(755, $duongdan); } } function is_domain($domain) { if (preg_match("/^([0-9a-z\-]{1,}\.)?[0-9a-z\-]{2,}\.([0-9a-z\-]{2,}\.)?[a-z]{2,}$/i", $domain)) { return true; } else { return false; } } function CovertVn($str) { $str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str); $str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str); $str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str); $str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str); $str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str); $str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str); $str = preg_replace("/(đ)/", 'd', $str); $str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str); $str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str); $str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str); $str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str); $str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str); $str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str); $str = preg_replace("/(Đ|đ)/", 'd', $str); $str = preg_replace("/( )/", '-', $str); $str = preg_replace("/%/", 'phan-tram', $str); $str = preg_replace("@[^A-Za-z0-9./\-_]+@i", "", $str); $str = preg_replace("/(--)/", '-', $str); $str = str_replace("/", '-', $str); return strtolower($str); } function name_of_cat($id, $table) { $sql = query("SELECT `tieude_vi` FROM `$table` WHERE `pid`='$id' LIMIT 1"); $row = fetch_assoc($sql); return $row['tieude_vi']; } function get_root_by_step($step, $lang = 'vi') { $sql_a = query("SELECT `tieude_vi`, `tieude_en` FROM `phl_danhmuc` WHERE `pid`='$step' AND `level`='1' LIMIT 1"); $row = fetch_assoc($sql_a); return $row['tieude_vi']; } function kiem_tra_hinh_anh_bai_viet($nid) { $sql = " SELECT pid from phl_baiviet_img where id_danhmuc = " . $nid; $check = query($sql); return fetch_array($check); } function boxdishome_by_doc_2($url, $id, $table, $name, $langone, $step = 1) { $sql = query("SELECT * FROM $table WHERE `cha`='0' AND `step`='$step' ORDER BY `sapxep` ASC"); $box .= ""; return $box; } function member_checkuser($user) { $sql = query("SELECT `pid` FROM `phl_thanhvien` WHERE `tentruycap`='$user' LIMIT 1"); $row = fetch_array($sql); if (num_rows($sql)) { return $row['pid']; } else { return 0; } } function get_name_member($uid, $field = 'hoten') { if ($uid > 0 AND is_numeric($uid)) { $sql = query("SELECT `$field` FROM `phl_thanhvien` WHERE `pid`='$uid' LIMIT 1"); $row = fetch_array($sql); return $row["$field"]; } else return 0; } function create_date3($dater, $l_d, $l_m, $l_y, $l_h, $l_i, $n_d, $n_m, $n_y, $n_h, $n_i) { if (!$dater) $dater = time(); $nowday = date("d", $dater); $nowmon = date("m", $dater); $nowyer = date("Y", $dater); $nowhou = date("H", $dater); $nowmin = date("i", $dater); $nowy = date("Y", time()); $day = ""; $mon = " / "; $yea = " / "; return $day . $mon . $yea . $hou . $min; } function catapath2($url, $cataid, $aid, $cat_db_name, $sp_db_name, $level) { if (is_numeric($cataid) AND $cataid > 0) { $cat = $cataid; } if ($cat) { $cataparent = $cat; $num = 1; do { $sql_sub = query("SELECT `pid`,`tieude_vi`,`tieude_en`,`cha`,`seo_name` FROM `$cat_db_name` WHERE `pid`='$cataparent' limit 1"); while ($rowssub = fetch_array($sql_sub)) { $cataname_vi = $rowssub['tieude_vi']; $cataname_en = $rowssub['tieude_en']; $cataparent = $rowssub['cha']; $cataid = $rowssub['pid']; $seo_name = $rowssub['seo_name']; if ($num == 1) $muiten = NULL; else $muiten = "»"; if ($level == 3) $setcat = "$url/$seo_name/"; elseif ($level == 2) $setcat = "$url/$seo_name/"; elseif ($level == 1) $setcat = "javascript:void(0);"; else { $len1 = query("SELECT `cha` FROM `$cat_db_name` WHERE `pid`='$cataid' LIMIT 1"); $row = fetch_array($len1); $tomco = $row["cha"]; $setcat = "subcat=$tomco&showpro"; } $tx = "$cataname_vi $muiten " . $tx; if ($cataparent == 0) return $tx; $level--; } $num++; } while (1); } } function boxy2($dbtable, $name = 'catalogid', $id = 0, $lang = 'Chọn đề mục', $step = 0, $opt = 0) { if ($opt) $addmo = " AND `chedo`='$opt' "; if ($step) $sql = query("select * from $dbtable where cha=0 $addmo AND trangthai='1' AND `step`='$step' order by sapxep ASC"); else $sql = query("select * from $dbtable where cha=0 $addmo AND trangthai='1' order by tieude_vi ASC"); $box .= ""; return $box; } function boxy($dbtable, $name = 'catalogid', $id = 0, $lang = 'Chọn đề mục', $step = 0) { $sql = query("select * from $dbtable where `cha`='$step' AND trangthai='1' AND `step`='$step' order by sapxep ASC"); $box .= ""; return $box; } function select_box_1($dbtable, $name = 'catalogid', $id = 0, $lang = 'Chọn đề mục') { $sql = query("select * from $dbtable where trangthai='1' order by sapxep ASC"); $box .= ""; return $box; } function member_checkemail($email) { $sql = query("SELECT `pid` FROM `phl_thanhvien` WHERE `email`='$email' LIMIT 1"); $row = fetch_array($sql); if (num_rows($sql) != 0) { return $row["pid"]; } else { return 0; } } function member_checkusername($username) { $sql = query("SELECT `pid` FROM `phl_thanhvien` WHERE `tentruycap`='$username' LIMIT 1"); $row = fetch_array($sql); if (num_rows($sql) != 0) { return $row["pid"]; } else { return 0; } } function boxdishome_gin($url, $id, $table, $name, $langone, $docid = 0) { $sql = query("SELECT * FROM $table WHERE `cha`=0 ORDER BY `sapxep` ASC"); $box .= ""; return $box; } function name_of_chude($id, $cata_table) { if ($id < 1) return 'Tất cả chủ đề sản phẩm'; $sql = query("SELECT `tieude_vi` FROM `$cata_table` WHERE `pid`='$id' LIMIT 1"); $row = fetch_array($sql); return $row["tieude_vi"]; } function sendsmtpmail_test($to_email, $to_name, $subject, $domain, $body, $a = 1) { require_once __DIR__ . '/phpmailer/Exception.php'; require_once __DIR__ . '/phpmailer/PHPMailer.php'; require_once __DIR__ . '/phpmailer/SMTP.php'; //$body = eregi_replace("[\]",'',$body); try { $mail = new PHPMailer\PHPMailer\PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP //$mail->SMTPDebug = 0; // enables SMTP debug information (for testing) $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "mail.anbinhevents.vn"; $mail->Port = 587; // set the SMTP port for the GMAIL server $mail->Username = "no-reply@anbinhevents.vn"; // SMTP account username $mail->Password = "passab123!"; // SMTP account password $mail->CharSet = 'UTF-8'; $frommail = "no-reply@anbinhevents.vn";; $mail->SetFrom($frommail, $domain); $subject = $subject . " - " . date("H:i A | d/m/Y"); $mail->Subject = $subject; $mail->AltBody = $body; // optional, comment out and test $mail->MsgHTML($body); $get_name = explode(";", $to_name); $get_email = explode(";", $to_email); $soluongmail = count($get_email); $mail->AddAddress(trim($to_email, $to_name)); //$mail->AddAddress($to_email,$to_name); //$mail->AddBCC($bcc_email,$bcc_name); $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML if (!$mail->Send()) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; exit; return 0; } else { return 1; } } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; exit; return 0; } } function sendsmtpmail($to_email, $to_name, $subject, $domain, $body, $attachment = null) { require_once __DIR__ . '/phpmailer/Exception.php'; require_once __DIR__ . '/phpmailer/PHPMailer.php'; require_once __DIR__ . '/phpmailer/SMTP.php'; //$body = eregi_replace("[\]",'',$body); try { $mail = new PHPMailer\PHPMailer\PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->SMTPDebug = 0; // enables SMTP debug information (for testing) $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "mail9096.maychuemail.com"; //$mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "no-reply@anbinhevents.vn"; // SMTP account username $mail->Password = "anbinhevents.vn"; // SMTP account password $mail->CharSet = 'UTF-8'; $frommail = "no-reply@anbinhevents.vn";; $mail->SetFrom($frommail, $domain); $subject = $subject . " - " . date("H:i A | d/m/Y"); $mail->Subject = $subject; $mail->AltBody = $body; // optional, comment out and test $mail->MsgHTML($body); $get_name = explode(";", $to_name); $get_email = explode(";", $to_email); $soluongmail = count($get_email); for ($in = 0; $in < $soluongmail; $in++) { if ($in == 0) { if (is_email(trim($get_email[$in]))) { $mail->AddAddress(trim($get_email[$in]), $get_name[$in]); } } else { if (is_email(trim($get_email[$in]))) $mail->AddBCC(trim($get_email[$in]), $get_name[$in]); } } //$mail->AddAddress($to_email,$to_name); //$mail->AddBCC($bcc_email,$bcc_name); $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML if (!empty($attachment)) { if (file_exists($attachment)) { $mail->AddAttachment($attachment); } } if (!$mail->Send()) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; exit; return 0; } else { return 1; } } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; exit; return 0; } } function sendsmtpmail_admin($to_email, $to_name, $subject, $domain, $body, $attachment = null) { require_once __DIR__ . '/phpmailer/Exception.php'; require_once __DIR__ . '/phpmailer/PHPMailer.php'; require_once __DIR__ . '/phpmailer/SMTP.php'; //$body = eregi_replace("[\]",'',$body); try { $mail = new PHPMailer\PHPMailer\PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP //$mail->SMTPDebug = 0; // enables SMTP debug information (for testing) $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "smtp.gmail.com"; $mail->Port = 587; // set the SMTP port for the GMAIL server $mail->Username = "alert@dtptech.com.vn"; // SMTP account username $mail->Password = "phuong1988"; // SMTP account password $mail->CharSet = 'UTF-8'; $frommail = "no-reply@dtptech.com.vn";; $mail->SetFrom($frommail, $domain); $subject = $subject . " - " . date("H:i A | d/m/Y"); $mail->Subject = $subject; $mail->AltBody = $body; // optional, comment out and test $mail->MsgHTML($body); $get_name = explode(";", $to_name); $get_email = explode(";", $to_email); $soluongmail = count($get_email); for ($in = 0; $in < $soluongmail; $in++) { if ($in == 0) { if (is_email(trim($get_email[$in]))) { $mail->AddAddress(trim($get_email[$in]), $get_name[$in]); } } else { if (is_email(trim($get_email[$in]))) $mail->AddBCC(trim($get_email[$in]), $get_name[$in]); } } //$mail->AddAddress($to_email,$to_name); //$mail->AddBCC($bcc_email,$bcc_name); $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML if (!empty($attachment)) { if (file_exists($attachment)) { $mail->AddAttachment($attachment); } } if (!$mail->Send()) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; exit; return 0; } else { return 1; } } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; exit; return 0; } } function uploadImage($file, $dir, $file_name_body_pre, $file_new_name_body, $file_name_body_add, $image_resize = true, $image_ratio_fill, $img_width, $img_height, $image_background_color) { require_once('config/class.upload.php'); $handle = new Upload($file); if ($handle->uploaded) { $_dir = $dir; $handle->file_name_body_pre = $file_name_body_pre; $handle->file_new_name_body = $file_new_name_body; $handle->file_name_body_add = $file_name_body_add; $handle->image_resize = $image_resize; $handle->image_ratio_fill = $image_ratio_fill; $handle->image_x = $img_width; $handle->image_y = $img_height; $handle->image_background_color = $image_background_color; $handle->Process($_dir); if ($handle->processed) { $name_img = $handle->file_dst_name; return $name_img; } else { return false; } } } function company_info($id) { $sql_1 = query("SELECT * FROM `phl_company` WHERE `pid`=" . $id . " LIMIT 1"); $row_1 = fetch_array($sql_1); return stripslashes($row_1['noidung_' . $_SESSION['lang']]); } function company_title($id) { $sql_1 = query("SELECT * FROM `phl_company` WHERE `pid`=" . $id . " LIMIT 1"); $row_1 = fetch_array($sql_1); return stripslashes($row_1['tieude_' . $_SESSION['lang']]); } function lienket($id) { $sql_1 = query("SELECT * FROM `phl_lienket` WHERE `pid`=" . $id . " LIMIT 1"); $row_1 = fetch_array($sql_1); return stripslashes($row_1['link']); } function banner_title($kietxuat) { $sqllogo = query("SELECT `tieude_vi`, `tieude_en` FROM phl_hinhanh WHERE trangthai = 1 AND id_loaihinhanh =" . $kietxuat . " ORDER BY ngaydang DESC LIMIT 1"); $result = fetch_array($sqllogo); return stripslashes($result['tieude_' . $_SESSION['lang']]); } function banner_link($kietxuat) { $sqllogo = query("SELECT `webnguon_vi`, `webnguon_en` FROM phl_hinhanh WHERE trangthai = 1 AND id_loaihinhanh =" . $kietxuat . " ORDER BY ngaydang DESC LIMIT 1"); $result = fetch_array($sqllogo); return stripslashes($result['webnguon_' . $_SESSION['lang']]); } function Flang($str = '') { global $mysqli; $str = trim($str); $sql = "select * from phl_ngonngu where code_lang='" . $str . "' limit 0,1"; $result = query($sql); $rows = fetch_assoc($result); if (!empty($rows)) { if (!isset($_SESSION["lang"])) $_SESSION["lang"] = 'en'; return $rows['lang_' . $_SESSION["lang"]]; } } function findStart($page, $limit) { if (empty($page) || $page == "1") { $start = 0; $page = 1; } else { $start = ($page - 1) * $limit; } return $start; } function findPages($count, $limit) { $pages = (($count % $limit) == 0) ? $count / $limit : floor($count / $limit) + 1; return $pages; } function pageList($current, $total_row, $ctr_name, $ancho) { $div = 10; $row_per_page = 1; if (empty($current)) $current = 1; $npage = floor($total_row / $row_per_page) + (($total_row % $row_per_page) ? 1 : 0); $nDiv = floor($npage / $div) + (($npage % $div) ? 1 : 0); $currentDiv = floor($current / $div); $count = ($npage <= ($currentDiv + 1) * $div) ? ($npage - $currentDiv * $div) : $div; $str_paging = ''; if ($npage > 0) { $npage = intval($total_row / $row_per_page); if ($total_row % $row_per_page > 0) $npage += 1; if ($npage > 1) { if ($current != 1) { /*if (($current != 1) && ($current)) { $str_paging .= '
  • '; }*/ if (($current - 1) > 0) { $str_paging .= '
  • '; } } else { $str_paging .= '
  • '; } if ($current % $div == 0) { $str_paging .= '
  • '; } for ($i = 0; $i < $count; $i++) { $page = ($currentDiv * $div + $i); if (($page + 1) == $current) $str_paging .= '
  • '; } if ((@$page + 1) >= $count) { if (($current + 1) <= $npage) { $str_paging .= '
  • '; } else { $str_paging .= '
  • '; } /*if (($current != $npage) && ($npage != 0)) { $str_paging .= '
  • '; }*/ } } return $str_paging; } } function catchuoi_2($chuoi, $char) { // nếu độ dài chuỗi nhỏ hơn hay bằng vị trí cắt // thì không thay đổi chuỗi ban đầu if (@mb_strlen($chuoi, 'UTF-8') <= $char) { return $chuoi; } else { /* so sánh vị trí cắt với kí tự khoảng trắng đầu tiên trong chuỗi ban đầu tính từ vị trí cắt nếu vị trí khoảng trắng lớn hơn thì cắt chuỗi tại vị trí khoảng trắng đó */ if (@mb_strpos($chuoi, " ", $char, 'UTF-8') > $char) { $new_gioihan = @mb_strpos($chuoi, " ", $char, 'UTF-8'); $new_chuoi = @mb_substr($chuoi, 0, $new_gioihan, 'UTF-8') . " ...

    "; return $new_chuoi; } else { // trường hợp còn lại không ảnh hưởng tới kết quả $new_chuoi = @mb_substr($chuoi, 0, $char, 'UTF-8') . " ...

    "; return $new_chuoi; } } } function get_youtube($url) { $phan1 = explode("=", $url); $phan1_1 = $phan1[1]; $phan2 = explode("&", $phan1_1); $youtu = $phan2[0]; return $youtu; } function get_data_baiviet_data($id, $lang, $type = 1) { $sql_a = query("SELECT `noidung_vi`, `noidung_en`, `gioithieu_vi`, `gioithieu_en` FROM `phl_baiviet_data` WHERE `id_action`='$id' LIMIT 1"); $row = fetch_array($sql_a); if ($type == 1) return $row["noidung_" . $lang]; else return $row["gioithieu_" . $lang]; } function lay_img_cha($step) { $sql_a = query("SELECT `duongdantin`, `icon` FROM `phl_danhmuc` WHERE `pid`='$step' LIMIT 1"); $row = fetch_assoc($sql_a); return $row['duongdantin'] . '/' . $row['icon']; } function lay_noidung_cha($step, $lang = 'vi') { $sql_a = query("SELECT `noidung_vi`, `noidung_en` FROM `phl_danhmuc` WHERE `pid`='$step' LIMIT 1"); $row = fetch_assoc($sql_a); return $row['noidung_' . $lang]; } function day_en_to_vn($date) { $weekday = strtolower($date); switch ($weekday) { case 'monday': $weekday = 'Thứ hai'; break; case 'tuesday': $weekday = 'Thứ ba'; break; case 'wednesday': $weekday = 'Thứ tư'; break; case 'thursday': $weekday = 'Thứ năm'; break; case 'friday': $weekday = 'Thứ sáu'; break; case 'saturday': $weekday = 'Thứ bảy'; break; default: $weekday = 'Chủ nhật'; break; } return $weekday; } function sw_get_weekday($date) { date_default_timezone_set('Asia/Ho_Chi_Minh'); $weekday = date("l", $date); if ($_SESSION['lang'] == 'vi') { $weekday = strtolower($weekday); switch ($weekday) { case 'monday': $weekday = 'Thứ hai'; break; case 'tuesday': $weekday = 'Thứ ba'; break; case 'wednesday': $weekday = 'Thứ tư'; break; case 'thursday': $weekday = 'Thứ năm'; break; case 'friday': $weekday = 'Thứ sáu'; break; case 'saturday': $weekday = 'Thứ bảy'; break; default: $weekday = 'Chủ nhật'; break; } } return date(' d/m/Y H:i', $date); } function is_email($email) ///Kiem tra xac thuc email { return filter_var($email, FILTER_VALIDATE_EMAIL); } function callProcedure($pv_proc, $pt_args) { global $mysqli; if (empty($pv_proc) || empty($pt_args)) { return false; } $lv_call = "CALL `$pv_proc`("; $lv_select = "SELECT"; $lv_log = ""; foreach ($pt_args as $lv_key => $lv_value) { $lv_query = "SET @$lv_key = '$lv_value'"; $lv_log .= $lv_query . ";\n"; if (!$lv_result = query($lv_query)) { /* Write log */ return false; } $lv_call .= " @$lv_key,"; $lv_select .= " @$lv_key AS $lv_key,"; } echo $lv_select; $lv_call = substr($lv_call, 0, -1) . ")"; $lv_select = substr($lv_select, 0, -1); $lv_log .= $lv_call; if ($lv_result = query($lv_call)) { if ($lo_result = query($lv_select)) { $lt_result = fetch_assoc($lo_result); return $lt_result; } /* Write log */ return false; } /* Write log */ return false; } function get_cataparent($id) { $sql = query("SELECT `cha` FROM `phl_danhmuc` WHERE `pid`='$id' LIMIT 1"); $row = fetch_assoc($sql); return $row["cha"]; } function link_cata($id,$lang='vi',$fullpath) { global $mysqli; $sql = query("SELECT * FROM `phl_danhmuc` WHERE `pid`='$id' LIMIT 1"); $row = fetch_assoc($sql); if($row['cha']=='0'){ $l = $fullpath.'/'.$row['seo_name'].'.html'; $arrow = ""; }else{ $sql2 = query("SELECT * FROM `phl_danhmuc` WHERE `pid`='".$row['cha']."' LIMIT 1"); $row2 = fetch_assoc($sql2); $l = $fullpath.'/'.$row['seo_name'].'.html'; $arrow = ""; } $link = "
  • ".$row['tieude_'.$lang]."$arrow
  • "; return $link; } function navi($n,$tree = '',$lang = 'vi',$fullpath) { if ($n == 0){return $tree; } $tree = link_cata($n,$lang,$fullpath).$tree; return navi(get_cataparent($n),$tree,$lang,$fullpath); } function tree_cata($fullpath, $step, $cataid = 0, $lang = 'vi') { $tree = ''; $sql_step = query("SELECT * FROM `phl_danhmuc` WHERE `step`='$step' AND `pid`='$cataid' LIMIT 1"); $cata_step = fetch_array($sql_step); $linkkhac = $cata_step['view1_'.$_SESSION["lang"]]; if(isset($linkkhac) && $linkkhac != ''){ $link = $linkkhac; }else{ $link = $fullpath.'/'.$cata_step['seo_name']; } if($cata_step['cha'] == 0) { $tree = "
  • ".$cata_step['tieude_'.$lang]."
  • "; } else { //$tree = "
  • ".$cata_step['tieude_'.$lang]."
  • "; /*$sql_a = mysql_query("SELECT * FROM `kietxuat` WHERE `step`='$step' AND `cataid`='$cataid' ORDER BY `catasort` ASC LIMIT 1"); $rows_step = mysql_fetch_array($sql_a); $cataname = $rows_step['cataname_'.$lang]; $cataid = $rows_step['cataid']; $seo_name = $rows_step['seo_name']; $tree .= " | ".$cataname." ";*/ $navi = navi($cataid,'',$lang,$fullpath); $tree .= $navi; } return $tree; } function get_youtu($url) { $phan1 = explode("=", $url); $phan1_1 = $phan1[1]; $phan2 = explode("&", $phan1_1); $youtu = $phan2[0]; return $youtu; } function get_stepid_by_type($type) { $list_cata = ''; $sql_cata = query("select `step` from `phl_danhmuc` where trangthai='1' AND `type`='$type' AND `cha`='0' order by sapxep ASC"); while ($ro_cata = fetch_array($sql_cata)) { if (empty($list_cata)) { $list_cata = $ro_cata['step']; } else { $list_cata = $list_cata . ',' . $ro_cata['step']; } } return $list_cata; } function get_stepid_by_multitype($type) { $list_cata = ''; $sql_cata = query("select `step` from `phl_danhmuc` where trangthai='1' AND `type` IN ($type) AND `cha`='0' order by sapxep ASC"); while ($ro_cata = fetch_array($sql_cata)) { if (empty($list_cata)) { $list_cata = $ro_cata['step']; } else { $list_cata = $list_cata . ',' . $ro_cata['step']; } } return $list_cata; } function member_check_email($email) { $sql = query("SELECT `pid` FROM `phl_thanhvien` WHERE `email`='$email' LIMIT 1"); $row = fetch_array($sql); if ($sql->num_rows > 0) { return $row["pid"]; } else { return 0; } } function customer_check_email($email) { $sql = query("SELECT `pid` FROM `phl_khachhang` WHERE `email`='$email' LIMIT 1"); $row = fetch_array($sql); if ($sql->num_rows > 0) { return $row["pid"]; } else { return 0; } } function get_info_khachhang($pid) { $sql = query("SELECT * FROM `phl_khachhang` WHERE `pid`='$pid' LIMIT 1"); $row = fetch_array($sql); return $row; } function ctype_alnum_portable($text) { return (preg_match('~^[0-9a-z]*$~iu', $text) > 0); } function config_email($type) { $list_email = ''; $sql = query("SELECT * FROM `phl_email_config` WHERE `loai`='" . $type . "'"); while ($rim = fetch_array($sql)) { if (empty($list_email)) $list_email = $rim['email']; else $list_email .= ';' . $rim['email']; } return $list_email; } function config_email_all() { $list_email = ''; $sql = query("SELECT * FROM `phl_email_config` WHERE `trangthai`='1'"); while ($rim = fetch_array($sql)) { if (empty($list_email)) $list_email = $rim['email']; else $list_email .= ';' . $rim['email']; } return $list_email; } function resize_and_crop($original_image_url, $thumb_image_url, $thumb_w, $thumb_h, $quality = 75) { // ACQUIRE THE ORIGINAL IMAGE: http://php.net/manual/en/function.imagecreatefromjpeg.php // $original = imagecreatefromjpeg($original_image_url); $pathinfo = pathinfo($original_image_url); // Is gif if ($pathinfo['extension'] == 'gif') { $original = @imagecreatefromgif($original_image_url); } // Is png elseif ($pathinfo['extension'] == 'png') { $original = @imagecreatefrompng($original_image_url); imagealphablending($original, true); } // Is jpg, jpeg else { $original = imagecreatefromjpeg($original_image_url); } if (!$original) return FALSE; // GET ORIGINAL IMAGE DIMENSIONS list($original_w, $original_h) = getimagesize($original_image_url); // RESIZE IMAGE AND PRESERVE PROPORTIONS $thumb_w_resize = $thumb_w; $thumb_h_resize = $thumb_h; if ($original_w > $original_h) { $thumb_h_ratio = $thumb_h / $original_h; $thumb_w_resize = (int)round($original_w * $thumb_h_ratio); } else { $thumb_w_ratio = $thumb_w / $original_w; $thumb_h_resize = (int)round($original_h * $thumb_w_ratio); } if ($thumb_w_resize < $thumb_w) { $thumb_h_ratio = $thumb_w / $thumb_w_resize; $thumb_h_resize = (int)round($thumb_h * $thumb_h_ratio); $thumb_w_resize = $thumb_w; } // CREATE THE PROPORTIONAL IMAGE RESOURCE $thumb = imagecreatetruecolor($thumb_w_resize, $thumb_h_resize); if (!imagecopyresampled($thumb, $original, 0, 0, 0, 0, $thumb_w_resize, $thumb_h_resize, $original_w, $original_h)) return FALSE; // ACTIVATE THIS TO STORE THE INTERMEDIATE IMAGE // imagejpeg($thumb, 'RAY_temp_' . $thumb_w_resize . 'x' . $thumb_h_resize . '.jpg', 100); // CREATE THE CENTERED CROPPED IMAGE TO THE SPECIFIED DIMENSIONS $final = imagecreatetruecolor($thumb_w, $thumb_h); $thumb_w_offset = 0; $thumb_h_offset = 0; if ($thumb_w < $thumb_w_resize) { $thumb_w_offset = (int)round(($thumb_w_resize - $thumb_w) / 2); } else { $thumb_h_offset = (int)round(($thumb_h_resize - $thumb_h) / 2); } if (!imagecopy($final, $thumb, 0, 0, $thumb_w_offset, 0, $thumb_w_resize, $thumb_h_resize)) return FALSE; // STORE THE FINAL IMAGE - WILL OVERWRITE $thumb_image_url //if (!imagejpeg($final, $thumb_image_url, $quality)) return FALSE; if ($pathinfo['extension'] == 'gif') { if (@imagegif($final, $thumb_image_url)) { return true; } else { return false; } } else { if (@imagepng($final, $thumb_image_url)) { return true; } else { return false; } } return TRUE; } function escapeString($postData) { if (!empty($postData)) { if (is_array($postData)) { foreach ($postData as $key => $value) { $postData[$key] = real_escape_string(addslashes($value)); } } else { $postData = real_escape_string(addslashes($postData)); } } return $postData; } function get_client_ip() { $ipaddress = ''; if (getenv('HTTP_CLIENT_IP')) $ipaddress = getenv('HTTP_CLIENT_IP'); else if (getenv('HTTP_X_FORWARDED_FOR')) $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); else if (getenv('HTTP_X_FORWARDED')) $ipaddress = getenv('HTTP_X_FORWARDED'); else if (getenv('HTTP_FORWARDED_FOR')) $ipaddress = getenv('HTTP_FORWARDED_FOR'); else if (getenv('HTTP_FORWARDED')) $ipaddress = getenv('HTTP_FORWARDED'); else if (getenv('REMOTE_ADDR')) $ipaddress = getenv('REMOTE_ADDR'); else $ipaddress = 'UNKNOWN'; return $ipaddress; } function get_cataid_by_id($id) { $list_cata = $id; $sql_cata = query("select `pid` from `phl_danhmuc` where trangthai='1' AND `cha`='$id' order by sapxep ASC"); while ($ro_cata = fetch_array($sql_cata)) { $list_cata .= ',' . $ro_cata['pid']; } return $list_cata; } function GET_max_id() { $sql_cata = query("select `pid` from `phl_baiviet` order by id DESC LIMIT 1"); $ro_cata = fetch_array($sql_cata); return $ro_cata['pid']; } function GET_ID_youtube($url){ preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches); return $matches[1]; } function CAT_chuoi_ki_tu($text, $num = 80) { $num_kitu = explode(" ", $text); $num_kitu_c = count($num_kitu); if ($num_kitu_c <= $num) { return $text; } $kitu_moi = ""; $i = 0; foreach ($num_kitu as $key) { $i++; if($i > $num) { $kitu_moi = trim($kitu_moi); $kitu_moi .= " [...]"; break; } $kitu_moi .= $key." "; } return $kitu_moi; } function CAT_chuoi($text, $num = 80) { if (strlen($text) <= $num) { return $text; } $text= substr($text, 0, $num); if ($text[$num-1] == ' ') { return trim($text)."..."; } $x = explode(" ", $text); $sz = sizeof($x); if ($sz <= 1) { return $text."..."; } $x[$sz-1] = ''; return trim(implode(" ", $x))."..."; } function load_ckeditor($txt) { ?> $old_y) { if ($by_small) { $thumb_w = floor($old_x*($new_w/$old_y)); $thumb_h = $new_h; } } elseif ($old_x == $old_y) { $thumb_w = $new_w; $thumb_h = $new_h; } $thumb_w = ($thumb_w<1) ? 1 : $thumb_w; $thumb_h = ($thumb_h<1) ? 1 : $thumb_h; */ // Get needed data about source image list( $original_width, $original_height, $type, $attr ) = getimagesize( $name ); // Calculate final thumbnail resolution $thumb_ratio = $thumb_width / $thumb_height; $original_ratio = $original_width / $original_height; if( $thumb_ratio > $original_ratio ) { $thumb_w = round( ( $thumb_height * $original_width) / $original_height ); $thumb_h = $thumb_height; } elseif( $thumb_ratio < $original_ratio ) { $thumb_w = $thumb_width; $thumb_h = round( ( $thumb_width * $original_height ) / $original_width ); } else { $thumb_w = $thumb_width; $thumb_h = $thumb_height; } //echo $thumb_w."-".$thumb_h; $new_img = ImageCreateTrueColor($thumb_w, $thumb_h); if($transparency) { if(preg_match('/png/i', $ext)) { imagealphablending($new_img, false); $colorTransparent = imagecolorallocatealpha($new_img, 0, 0, 0, 127); imagefill($new_img, 0, 0, $colorTransparent); imagesavealpha($new_img, true); } elseif(preg_match('/gif/i', $ext)) { $trnprt_indx = imagecolortransparent($img); if ($trnprt_indx >= 0) { //its transparent $trnprt_color = imagecolorsforindex($img, $trnprt_indx); $trnprt_indx = imagecolorallocate($new_img, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']); imagefill($new_img, 0, 0, $trnprt_indx); imagecolortransparent($new_img, $trnprt_indx); } } } else { Imagefill($new_img, 0, 0, imagecolorallocate($new_img, 255, 255, 255)); } //imagecopyresampled($new_img, $img, 0,0,0,0, $thumb_w, $thumb_h, $old_x, $old_y); @imagecopyresampled($new_img, $img, 0,0,0,0, $thumb_w, $thumb_h, $original_width, $original_height); if($border) { $black = imagecolorallocate($new_img, 0, 0, 0); imagerectangle($new_img,0,0, $thumb_w, $thumb_h, $black); } if($base64) { ob_start(); imagepng($new_img); $img = ob_get_contents(); ob_end_clean(); $return = base64_encode($img); } else { if(preg_match('/jpeg/i', $ext)) { imagejpeg($new_img, $newname); $return = true; } elseif( preg_match('/jpg/i', $ext)){ imagejpeg($new_img, $newname); $return = true; } elseif(preg_match('/png/i', $ext)){ imagepng($new_img, $newname); $return = true; } elseif(preg_match('/gif/i', $ext)) { imagegif($new_img, $newname); $return = true; } elseif(preg_match('/bmp/i', $ext)) { imagejpeg($new_img, $newname); $return = true; } } imagedestroy($new_img); imagedestroy($img); //@watermark($newname); return $return; } function watermark($SourceFile) { $watermark_root = $SourceFile; $_image = $_SERVER['DOCUMENT_ROOT'].'/images/trang.png'; $ext_root = strtolower(substr($watermark_root,-3)); if($ext_root =='gif') $watermark = imagecreatefromgif($watermark_root); elseif($ext_root=='png') $watermark = imagecreatefrompng($watermark_root); elseif($ext_root=='jpg') $watermark = imagecreatefromjpeg($watermark_root); elseif($ext_root=='bmp') $watermark = imagecreatefrombmp($watermark_root); else $watermark = imagecreatefromjpeg($watermark_root); //$watermark = imagecreatefromgif($watermark); //gets the watermark //gets the dimensions of the watermark $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); //gets the image to put the watermark on and related information about it $ext = strtolower(substr($_image,-3)); if($ext=='jpg') $image = @imagecreatefromjpeg($_image); elseif($ext=='gif') $image = @imagecreatefromgif($_image); elseif($ext=='png') $image = @imagecreatefrompng($_image); elseif($ext=='png') $image = @imagecreatefrombmp($_image); else $image = @imagecreatefromgd($_image); $size = getimagesize($_image); $dest_x = ($size[0] - $watermark_width)/2; $dest_y = ($size[1] - $watermark_height)/2; @imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); //imagejpeg($image); @imagejpeg ($image, $SourceFile, 100); @imagedestroy($image); @imagedestroy($watermark); } function create_thumb2( $source_path, $destination_path, $thumb_width, $thumb_height, $quality=75, $overwrite=true ) { // If overwrite is set to FALSE and destination file allready exists, than return FALSE and quit execution if( file_exists( $destination_path ) && is_file( $destination_path ) && $overwrite == false ) return false; // Needed definitions $allowed_extensions = array( 'jpg', 'jpeg', 'png', 'gif' ); $pathinfo = pathinfo( $source_path ); // Check if source file exists, and is in array of allowed extensions. // Otherwise return FALSE if( file_exists( $source_path ) && in_array( strtolower( $pathinfo['extension'] ), $allowed_extensions ) ) { // Get needed data about source image list( $original_width, $original_height, $type, $attr ) = @getimagesize( $source_path ); // Calculate cut size and coordinates @$thumb_ratio = @$thumb_width / $thumb_height; @$original_ratio = @$original_width / $original_height; if( $thumb_ratio > $original_ratio ) { $cut_width = $original_width; $cut_height = ( $original_width * $thumb_height ) / $thumb_width; $cut_x = 0; $cut_y = 0; } elseif( $thumb_ratio < $original_ratio ) { $cut_width = ( $original_height * $thumb_width ) / $thumb_height; $cut_height = $original_height; $cut_x = ( $original_width - $cut_width ) / 2; $cut_y = 0; } else { $cut_width = $original_width; $cut_height = $original_height; $cut_x = 0; $cut_y = 0; } // Create final image layout $final_image = @imagecreatetruecolor( $thumb_width, $thumb_height ); imagealphablending($final_image, false); imagesavealpha($final_image, true); // Is gif if( $pathinfo['extension'] == 'gif' ) { $source_image = @imagecreatefromgif( $source_path ); } // Is png elseif( $pathinfo['extension'] == 'png' ) { $source_image = @imagecreatefrompng( $source_path ); imagealphablending($source_image, true); } // Is jpg, jpeg else { $source_image = @imagecreatefromjpeg( $source_path ); } // Cut, resize source, and create final image @imagecopyresampled( $final_image, $source_image, 0, 0, $cut_x, $cut_y, $thumb_width, $thumb_height, $cut_width, $cut_height ); // Return TRUE if the thumbnail was created. Otherwise FALSE if($pathinfo['extension'] == 'gif') { if (@imagegif( $final_image, $destination_path) ) { return true; } else { return false; } } else { if (@imagepng( $final_image, $destination_path) ) { return true; } else { return false; } } } else { return false; } } // ------------------------------------------------------ // By ratio thumbnail generation function // ------------------------------------------------------ function create_ratio_thumb( $source_path, $destination_path, $thumb_width, $thumb_height, $quality=85, $overwrite=true ) { // If overwrite is set to FALSE and destination file allready exists, than return FALSE and quit execution if( file_exists( $destination_path ) && is_file( $destination_path ) && $overwrite == false ) return false; // Needed definitions $allowed_extensions = array( 'jpg', 'jpeg', 'png', 'gif' ); $pathinfo = pathinfo( $source_path ); // Check if source file exists, and is in array of allowed extensions. // Otherwise return FALSE if( file_exists( $source_path ) && in_array( strtolower( $pathinfo['extension'] ), $allowed_extensions ) ) { // Get needed data about source image list( $original_width, $original_height, $type, $attr ) = getimagesize( $source_path ); // Calculate final thumbnail resolution $thumb_ratio = $thumb_width / $thumb_height; $original_ratio = $original_width / $original_height; if( $thumb_ratio > $original_ratio ) { $final_width = round( ( $thumb_height * $original_width) / $original_height ); $final_height = $thumb_height; } elseif( $thumb_ratio < $original_ratio ) { $final_width = $thumb_width; $final_height = round( ( $thumb_width * $original_height ) / $original_width ); } else { $final_width = $thumb_width; $final_height = $thumb_height; } // Create final image layout $final_image = imagecreatetruecolor( $final_width, $final_height ); imagealphablending($final_image, false); imagesavealpha($final_image, true); // Is gif if( $pathinfo['extension'] == 'gif' ) { $source_image = imagecreatefromgif( $source_path ); } // Is png elseif( $pathinfo['extension'] == 'png' ) { $source_image = imagecreatefrompng( $source_path ); imagealphablending($source_image, true); } // Is jpg, jpeg else { $source_image = imagecreatefromjpeg( $source_path ); } // Resize source, and create the final image imagecopyresampled( $final_image, $source_image, 0, 0, 0, 0, $final_width, $final_height, $original_width, $original_height ); // Return TRUE if the thumbnail was created. Otherwise FALSE if($pathinfo['extension'] == 'gif') { if (@imagegif( $final_image, $destination_path) ) { return true; } else { return false; } } else { if (@imagepng( $final_image, $destination_path) ) { return true; } else { return false; } } } else { return false; } } ?>