'mysql', 'username' => LOGIN_DB, 'password' => PASS_DB, 'hostspec' => SERVER, 'database' => NAME_DB, ), $options = array( 'debug' => 2, 'portability' => MDB2_PORTABILITY_DELETE_COUNT, ); public function __construct(){ $this->dbc =& MDB2::connect($this->dsn, $this->options); if (PEAR::isError($this->dbc)) { die($this->dbc->getMessage()); } $this->dbc->setFetchMode(MDB2_FETCHMODE_ASSOC); $query = "SET NAMES utf8"; $res = $this->dbc->query($query); } public function set_users_id($users_id, $remember = FALSE){ $_SESSION['users_id'] = $users_id; if($remember){ setcookie('users_id', $users_id); } } public function get_users_id(){ $users_id = 0; if(isset($_SESSION['users_id']) and intval($_SESSION['users_id']) > 0){ $users_id = intval($_SESSION['users_id']); } elseif(isset($_COOKIE['users_id']) and intval($_COOKIE['users_id']) > 0){ $users_id = $_SESSION['users_id'] = intval($_COOKIE['users_id']); } return $users_id; } public function parseGetVar(&$possibleGETVars, &$virtuals) { $name = ''; $GETVar = array(); foreach ($virtuals as $val) { if ($name != '') { $GETVar[$name] = $val; $name = ''; } elseif (in_array($val, $possibleGETVars)) { $name = $val; } } return $GETVar; } public function is_email ($email) { if ( preg_match('/^[a-z0-9\.\-_]+@[a-z0-9\-_]+\.([a-z0-9\-_]+\.)*?[a-z]+$/is', $email) ) { return true; } else { return false; } } public function resizeImage($file, $max_width = 200, $max_height = 200, $mode = 0, $overlay = '') { $file_info = pathinfo($file); $ext = $file_info['extension']; if (($ext == 'jpg' or $ext == 'jpeg') && function_exists('imagecreatefromjpeg')) { $img = imagecreatefromjpeg($file); } elseif ($ext == 'png' && function_exists('imagecreatefrompng')) { $img = imagecreatefrompng($file); } elseif ($ext == 'gif' && function_exists('imagecreatefromgif')) { $img = imagecreatefromgif($file); } else { return false; } if ($overlay != '' && function_exists('imagecreatefrompng')) { $overlay = imagecreatefrompng($overlay); $overlay_width = imagesx($overlay); $overlay_height = imagesy($overlay); } if ($img) { $src_width = imagesx($img); $src_height = imagesy($img); $ratio_w = $max_width/$src_width; $ratio_h = $max_height/$src_height; $ratio = min($ratio_w, $ratio_h); if ($ratio < 1) {// ���� ����� ��������� if($mode == 0) { $dst_width = ($ratio == $ratio_w) ? $max_width : floor($ratio*$src_width); $dst_height = ($ratio == $ratio_h) ? $max_height : floor($ratio*$src_height); $dst_img = imagecreatetruecolor($dst_width, $dst_height); imagecopyresampled($dst_img, $img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); } elseif ($mode == 1) { $dst_width = ($ratio == $ratio_w) ? $max_width : floor($ratio*$src_width); $dst_height = ($ratio == $ratio_h) ? $max_height : floor($ratio*$src_height); $dst_img = imagecreatetruecolor($max_width, $max_height); $background = imagecolorallocate($dst_img, 255, 255, 255); imagefill($dst_img, 0, 0, $background); if ($dst_width < $max_width) { imagecopyresampled($dst_img, $img, floor($max_width-$dst_width)/2, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); } elseif ($dst_height < $max_height) { imagecopyresampled($dst_img, $img, 0, floor($max_height-$dst_height)/2, 0, 0, $dst_width, $dst_height, $src_width, $src_height); } else { imagecopyresampled($dst_img, $img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); } } elseif ($mode == 2 || $mode == 3) { $ratio = max($ratio_w, $ratio_h); if ($src_width <= $max_width || $ratio >= 1) {//���� ������ ������ ��� ����� ��������� $dst_width = $src_width; } else { $dst_width = ($ratio == $ratio_w) ? $max_width : floor($ratio*$src_width);//���� ���� �� ������ } if ($src_height <= $max_height || $ratio >= 1) {//���� ������ ������ ��� ����� ��������� $dst_height = $src_height; } else { $dst_height = ($ratio == $ratio_h) ? $max_height : floor($ratio*$src_height);//���� ���� �� ������ } if ($ratio_w < 1 && $ratio_h < 1) {//������������, ��� ������� $tmp_img = imagecreatetruecolor($dst_width, $dst_height); imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); } else { $tmp_img = $img; } if ($dst_width > $max_width) {//����� ������ $dst_img = imagecreatetruecolor($max_width, $dst_height); // imagecopyresampled($dst_img, $tmp_img, 0, 0, 0, 0, $max_width, $dst_height, $max_width, $dst_height); // �� ������ ���� imagecopyresampled($dst_img, $tmp_img, 0, 0, floor($dst_width-$max_width)/2, 0, $max_width, $dst_height, $max_width, $dst_height); // �� �������� } elseif ($dst_height > $max_height) {//����� ������ $dst_img = imagecreatetruecolor($dst_width, $max_height); imagecopyresampled($dst_img, $tmp_img, 0, 0, 0, 0, $dst_width, $max_height, $dst_width, $max_height); // �� ����� // imagecopyresampled($dst_img, $tmp_img, 0, 0, 0, floor($dst_height-$max_height)/2, $dst_width, $max_height, $dst_width, $max_height); // �� �������� } else { $dst_img = $tmp_img; } } if ($mode == 3) {//��������� ���� if ($dst_width < $max_width) {//������ � ����� $max_img = imagecreatetruecolor($max_width, $max_height); $background = imagecolorallocate($max_img, 255, 255, 255); imagefill($max_img, 0, 0, $background); imagecopyresampled($max_img, $dst_img, floor($max_width-$dst_width)/2, 0, 0, 0, $dst_width, $dst_height, $dst_width, $dst_height); $dst_img = $max_img; } elseif ($dst_height < $max_height) {//�� ����� $max_img = imagecreatetruecolor($max_width, $max_height); $background = imagecolorallocate($max_img, 255, 255, 255); imagefill($max_img, 0, 0, $background); imagecopyresampled($max_img, $dst_img, 0, floor($max_height-$dst_height)/2, 0, 0, $dst_width, $dst_height, $dst_width, $dst_height); $dst_img = $max_img; } } imagedestroy($img); $img = $dst_img; } } else {// ��������� ����������� ��� ������ $img = imagecreate($max_width, $max_height); imagecolorallocate($img,0,0,0); $c = imagecolorallocate($img,70,70,70); imageline($img,0,0,$max_width,$max_height,$c2); imageline($img,$max_width,0,0,$max_height,$c2); } if ($overlay != '') { imagecopyresampled($img, $overlay, 0, 0, 0, 0, $overlay_width, $overlay_height, $overlay_width, $overlay_height); } if (($ext == 'jpg' or $ext == 'jpeg') && function_exists('imagejpeg')) { $img = imagejpeg($img, $file, 100); } elseif ($ext == 'png' && function_exists('imagepng')) { $img = imagepng($img, $file); } elseif ($ext == 'gif' && function_exists('imagegif')) { $img = imagegif($img, $file); } else { return false; } } } ?>