function nv_resize_crop_image($img_path, $width, $height, $module_name = '', $id = 0) { $new_img_path = ''; if (file_exists($img_path)) { $imginfo = nv_is_image($img_path); $basename = basename($img_path); if ($imginfo['width'] > $width or $imginfo['height'] > $height) { $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', $module_name . '_' . $id . '_\\1_' . $width . '-' . $height . '\\2', $basename); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $new_img_path = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } else { $img_path = new image($img_path, NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_width = $width; $thumb_height = $height; $maxwh = max($thumb_width, $thumb_height); if ($img_path->fileinfo['width'] > $img_path->fileinfo['height']) { $width = 0; $height = $maxwh; } else { $width = $maxwh; $height = 0; } $img_path->resizeXY($width, $height); $img_path->cropFromCenter($thumb_width, $thumb_height); $img_path->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $new_img_path = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } } } } return $new_img_path; }
function creat_thumbs($id, $homeimgfile, $module_name, $width = 200, $height = 150) { if ($width >= $height) { $rate = $width / $height; } else { $rate = $height / $width; } $image = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $homeimgfile; if ($homeimgfile != '' and file_exists($image)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_name . '/' . $homeimgfile; $imginfo = nv_is_image($image); $basename = $module_name . $width . 'x' . $height . '-' . $id . '-' . md5_file($image) . '.' . $imginfo['ext']; if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $imgsource = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } else { require_once NV_ROOTDIR . '/includes/class/image.class.php'; $_image = new image($image, NV_MAX_WIDTH, NV_MAX_HEIGHT); if ($imginfo['width'] <= $imginfo['height']) { $_image->resizeXY($width, 0); } elseif ($imginfo['width'] / $imginfo['height'] < $rate) { $_image->resizeXY($width, 0); } elseif ($imginfo['width'] / $imginfo['height'] >= $rate) { $_image->resizeXY(0, $height); } $_image->cropFromCenter($width, $height); $_image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $imgsource = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } } } elseif (nv_is_url($homeimgfile)) { $imgsource = $homeimgfile; } else { $imgsource = ''; } return $imgsource; }
function photos_thumbs($id, $file, $module_upload, $width = 270, $height = 210, $quality = 90) { if ($width >= $height) { $rate = $width / $height; } else { $rate = $height / $width; } $image = NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/images/' . $file; if ($file != '' and file_exists($image)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/images/' . $file; $imginfo = nv_is_image($image); $basename = $module_upload . '_' . $width . 'x' . $height . '-' . $id . '-' . md5_file($image) . '.' . $imginfo['ext']; if (file_exists(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename; } else { $_image = new image($image, NV_MAX_WIDTH, NV_MAX_HEIGHT); if ($imginfo['width'] <= $imginfo['height']) { $_image->resizeXY($width, 0); } elseif ($imginfo['width'] / $imginfo['height'] < $rate) { $_image->resizeXY($width, 0); } elseif ($imginfo['width'] / $imginfo['height'] >= $rate) { $_image->resizeXY(0, $height); } $_image->cropFromCenter($width, $height); $_image->save(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/', $basename, $quality); if (file_exists(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename; } } } elseif (nv_is_url($file)) { $imgsource = $file; } else { $imgsource = ''; } return $imgsource; }
function resizeimg($folder, $linkanh) { global $global_config, $module, $module_name, $module_config; require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($linkanh); $i = 1; while (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module_config[$module_name]['module'] . '/' . $folder . '/' . $basename)) { $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); $i++; } $image = new image($linkanh); $image_info1 = $image->fileinfo; if ($image_info1['width'] > $module_config[$module_name]['bodyimg']) { $image->resizeXY($module_config[$module_name]['bodyimg'], NV_MAX_HEIGHT); } $thumb_basename = $basename; $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_config[$module_name]['module'] . '/' . $folder, $thumb_basename); $image_info = $image->create_Image_info; $img = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_config[$module_name]['module'] . '/', '', $image_info['src']); $image->close(); return $img; }
if (!defined('NV_IS_FILE_ADMIN')) { die('Stop!!!'); } $path = nv_check_path_upload($nv_Request->get_string('path', 'post')); $check_allow_upload_dir = nv_check_allow_upload_dir($path); if (!isset($check_allow_upload_dir['create_file'])) { die('ERROR_' . $lang_module['notlevel']); } $width = $nv_Request->get_int('width', 'post'); $height = $nv_Request->get_int('height', 'post'); $imagename = htmlspecialchars(trim($nv_Request->get_string('img', 'post')), ENT_QUOTES); $imagename = basename($imagename); $file = preg_replace('/^(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $width . '_' . $height . '\\2', $imagename); $i = 1; while (file_exists(NV_ROOTDIR . '/' . $path . '/' . $file)) { $file = preg_replace('/^(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $width . '_' . $height . '_' . $i . '\\2', $imagename); ++$i; } $createImage = new image(NV_ROOTDIR . '/' . $path . '/' . $imagename, NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->resizeXY($width, $height); $createImage->save(NV_ROOTDIR . '/' . $path, $file, 75); $createImage->close(); if (isset($array_dirname[$path])) { $did = $array_dirname[$path]; $info = nv_getFileInfo($path, $file); $info['userid'] = $admin_info['userid']; $db->query("INSERT INTO " . NV_UPLOAD_GLOBALTABLE . "_file\n\t\t\t\t\t\t\t(name, ext, type, filesize, src, srcwidth, srcheight, sizes, userid, mtime, did, title) VALUES\n\t\t\t\t\t\t\t('" . $info['name'] . "', '" . $info['ext'] . "', '" . $info['type'] . "', " . $info['filesize'] . ", '" . $info['src'] . "', " . $info['srcwidth'] . ", " . $info['srcheight'] . ", '" . $info['size'] . "', " . $info['userid'] . ", " . $info['mtime'] . ", " . $did . ", '" . $file . "')"); } nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['upload_createimage'], $path . '/' . $file, $admin_info['userid']); echo $file; exit;
$array['thumbnail'] = $thumbnail; } } elseif (!empty($array['image'])) { $check_thumb = true; } if ($check_thumb and is_file(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . "/" . $module_name . "/topics/" . $array['image'])) { require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($array['image']); $image = new image(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . "/" . $module_name . "/topics/" . $array['image'], NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_basename = $basename; $i = 1; while (is_file(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/topics/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); ++$i; } $image->resizeXY($module_config[$module_name]['homewidth'], $module_config[$module_name]['homeheight']); $image->save(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/topics', $thumb_basename); $image_info = $image->create_Image_info; $array['thumbnail'] = str_replace(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/topics/', '', $image_info['src']); } $array['alias'] = $array['alias'] == "" ? change_alias($array['title']) : change_alias($array['alias']); if (empty($array['title'])) { $error = $lang_module['topics_error_title']; } elseif ($array['topicid'] == 0) { list($weight) = $db->sql_fetchrow($db->sql_query("SELECT max(`weight`) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_topics`")); $weight = intval($weight) + 1; $query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_topics` (`topicid`, `title`, `alias`, `description`, `image`, `thumbnail`, `weight`, `keywords`, `add_time`, `edit_time`) VALUES (NULL, " . $db->dbescape($array['title']) . ", " . $db->dbescape($array['alias']) . ", " . $db->dbescape($array['description']) . ", " . $db->dbescape($array['image']) . ", " . $db->dbescape($array['thumbnail']) . ", " . $db->dbescape($weight) . ", " . $db->dbescape($array['keywords']) . ", UNIX_TIMESTAMP( ), UNIX_TIMESTAMP( ))"; if ($db->sql_query_insert_id($query)) { nv_insert_logs(NV_LANG_DATA, $module_name, 'log_add_topic', " ", $admin_info['userid']); $db->sql_freeresult(); Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "");
/** * nv_ImageInfo() * Function xuat ra cac thong tin ve IMAGE de dua vao HTML (src, width, height). * * @param mixed $original_name - duong dan tuyet doi den file goc (bat buoc) * @param integer $width - chieu rong xuat ra HTML (neu bang 0 se xuat ra kich thuoc thuc) * @param bool $is_create_thumb - Neu chieu rong cua hinh lon hon $width, co the tao thumbnail * @param string $thumb_path - neu tao thumbnail thi chi ra thu muc chua file thumbnail nay. * @return array('src','width','height') */ function nv_ImageInfo($original_name, $width = 0, $is_create_thumb = false, $thumb_path = '') { if (empty($original_name)) { return false; } $original_name = realpath($original_name); if (empty($original_name)) { return false; } $original_name = str_replace('\\', '/', $original_name); $original_name = rtrim($original_name, "\\/"); unset($matches); if (!preg_match("/^" . nv_preg_quote(NV_ROOTDIR) . "\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))\$/i", $original_name, $matches)) { return false; } $imageinfo = array(); $size = @getimagesize($original_name); if (!$size or !isset($size[0]) or !isset($size[1]) or !$size[0] or !$size[1]) { return false; } $imageinfo['orig_src'] = $imageinfo['src'] = NV_BASE_SITEURL . $matches[1]; $imageinfo['orig_width'] = $imageinfo['width'] = $size[0]; $imageinfo['orig_height'] = $imageinfo['height'] = $size[1]; if ($width) { $imageinfo['width'] = $width; $imageinfo['height'] = ceil($width * $imageinfo['orig_height'] / $imageinfo['orig_width']); } if ($is_create_thumb and $width and $imageinfo['orig_width'] > $width) { if (empty($thumb_path) or !is_dir($thumb_path) or !is_writeable($thumb_path)) { $thumb_path = $matches[2]; } else { $thumb_path = realpath($thumb_path); if (empty($thumb_path)) { $thumb_path = $matches[2]; } else { $thumb_path = str_replace('\\', '/', $thumb_path); unset($matches2); if (preg_match("/^" . nv_preg_quote(NV_ROOTDIR) . "([a-z0-9\\-\\_\\/]+)*\$/i", $thumb_path, $matches2)) { $thumb_path = ltrim($matches2[1], "\\/"); } else { $thumb_path = $matches[2]; } } } if (!empty($thumb_path) and !preg_match("/\\/\$/", $thumb_path)) { $thumb_path = $thumb_path . '/'; } $new_src = $thumb_path . $matches[3] . '_' . $width . $matches[4]; $is_create = true; if (file_exists(NV_ROOTDIR . '/' . $new_src)) { $size = @getimagesize(NV_ROOTDIR . '/' . $new_src); if ($size and isset($size[0]) and isset($size[1]) and $size[0] and $size[1]) { $imageinfo['src'] = NV_BASE_SITEURL . $new_src; $imageinfo['width'] = $size[0]; $imageinfo['height'] = $size[1]; $is_create = false; } } if ($is_create) { include NV_ROOTDIR . "/includes/class/image.class.php"; $image = new image($original_name, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($width); $image->save(NV_ROOTDIR . '/' . $thumb_path, $matches[3] . '_' . $width . $matches[4]); $image_info = $image->create_Image_info; if (file_exists(NV_ROOTDIR . '/' . $new_src)) { $imageinfo['src'] = NV_BASE_SITEURL . $new_src; $imageinfo['width'] = $image_info['width']; $imageinfo['height'] = $image_info['height']; } } } return $imageinfo; }
if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $row['imgsource'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } else { require_once NV_ROOTDIR . '/includes/class/image.class.php'; $image = new image($image, NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_width = $width; $thumb_height = $height; $maxwh = max($thumb_width, $thumb_height); if ($image->fileinfo['width'] > $image->fileinfo['height']) { $width = 0; $height = $maxwh; } else { $width = $maxwh; $height = 0; } $image->resizeXY($width, $height); $image->cropFromCenter($thumb_width, $thumb_height); $image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $row['imgsource'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } } } } elseif (nv_is_url($row['homeimgfile'])) { $row['imgsource'] = $row['homeimgfile']; } elseif (!empty($module_config[$module_name]['show_no_image'])) { $row['imgsource'] = NV_BASE_SITEURL . $module_config[$module]['show_no_image']; } else { $row['imgsource'] = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/no_image.gif'; } $array_data[$row['id']] = $row;
if (isset($_FILES['avatar']) and is_uploaded_file($_FILES['avatar']['tmp_name'])) { @(require_once NV_ROOTDIR . "/includes/class/upload.class.php"); $upload = new upload(array('images'), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT); $upload_info = $upload->save_file($_FILES['avatar'], NV_UPLOADS_REAL_DIR . '/' . $module_name, false); @unlink($_FILES['avatar']['tmp_name']); if (empty($upload_info['error'])) { @chmod($upload_info['name'], 0644); if (!empty($array_data['photo']) and is_file(NV_ROOTDIR . '/' . $array_data['photo'])) { @nv_deletefile(NV_ROOTDIR . '/' . $array_data['photo']); } $image = $upload_info['name']; $basename = $upload_info['basename']; $imginfo = nv_is_image($image); $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $user_info['userid'] . '-80-80\\2', $basename); $_image = new image($image, 80, 80); $_image->resizeXY(80, 80); $_image->save(NV_UPLOADS_REAL_DIR . '/' . $module_name, $basename); if (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $basename)) { $file_name = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $basename; //@chmod($file_name, 0644); $file_name = str_replace(NV_ROOTDIR . "/", "", $file_name); @nv_deletefile($upload_info['name']); } $sql = "UPDATE `" . NV_USERS_GLOBALTABLE . "` SET `photo`=" . $db->dbescape_string($file_name) . " WHERE `userid`=" . $user_info['userid']; $db->sql_query($sql); } else { $error[] = $lang_module['avata']; } } $info = $lang_module['editinfo_ok']; $sec = 3;
function nv_get_viewImage($fileName) { global $array_thumb_config; if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))$/i', $fileName, $m)) { $viewFile = NV_FILES_DIR . '/' . $m[1]; if (file_exists(NV_ROOTDIR . '/' . $viewFile)) { $size = @getimagesize(NV_ROOTDIR . '/' . $viewFile); return array($viewFile, $size[0], $size[1]); } else { $m[2] = rtrim($m[2], '/'); if (isset($array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]])) { $thumb_config = $array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]]; } else { $thumb_config = $array_thumb_config['']; $_arr_path = explode('/', NV_UPLOADS_DIR . '/' . $m[2]); while (sizeof($_arr_path) > 1) { array_pop($_arr_path); $_path = implode('/', $_arr_path); if (isset($array_thumb_config[$_path])) { $thumb_config = $array_thumb_config[$_path]; break; } } } $viewDir = NV_FILES_DIR; if (!empty($m[2])) { if (!is_dir(NV_ROOTDIR . '/' . $m[2])) { $e = explode('/', $m[2]); $cp = NV_FILES_DIR; foreach ($e as $p) { if (is_dir(NV_ROOTDIR . '/' . $cp . '/' . $p)) { $viewDir .= '/' . $p; } else { $mk = nv_mkdir(NV_ROOTDIR . '/' . $cp, $p); if ($mk[0] > 0) { $viewDir .= '/' . $p; } } $cp .= '/' . $p; } } } $image = new image(NV_ROOTDIR . '/' . $fileName, NV_MAX_WIDTH, NV_MAX_HEIGHT); if ($thumb_config['thumb_type'] == 4) { $thumb_width = $thumb_config['thumb_width']; $thumb_height = $thumb_config['thumb_height']; $maxwh = max($thumb_width, $thumb_height); if ($image->fileinfo['width'] > $image->fileinfo['height']) { $thumb_config['thumb_width'] = 0; $thumb_config['thumb_height'] = $maxwh; } else { $thumb_config['thumb_width'] = $maxwh; $thumb_config['thumb_height'] = 0; } } $image->resizeXY($thumb_config['thumb_width'], $thumb_config['thumb_height']); if ($thumb_config['thumb_type'] == 4) { $image->cropFromCenter($thumb_width, $thumb_height); } $image->save(NV_ROOTDIR . '/' . $viewDir, $m[3] . $m[4], $thumb_config['thumb_quality']); $create_Image_info = $image->create_Image_info; $error = $image->error; $image->close(); if (empty($error)) { return array($viewDir . '/' . basename($create_Image_info['src']), $create_Image_info['width'], $create_Image_info['height']); } } } else { $size = @getimagesize(NV_ROOTDIR . '/' . $fileName); return array($viewFile, $size[0], $size[1]); } return false; }
/** * nv_get_viewImage() * * @param mixed $fileName * @param integer $w * @param integer $h * @return */ function nv_get_viewImage($fileName, $w = 80, $h = 80) { $ext = nv_getextension($fileName); $md5_view_image = md5($fileName); $viewDir = NV_FILES_DIR . '/images'; $viewFile = $viewDir . '/' . $md5_view_image . '.' . $ext; if (file_exists(NV_ROOTDIR . '/' . $viewFile)) { $size = @getimagesize(NV_ROOTDIR . '/' . $viewFile); return array($viewFile, $size[0], $size[1]); } include_once NV_ROOTDIR . "/includes/class/image.class.php"; $image = new image(NV_ROOTDIR . '/' . $fileName, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($w, $h); $image->save(NV_ROOTDIR . '/' . $viewDir, $md5_view_image, 75); $create_Image_info = $image->create_Image_info; $error = $image->error; $image->close(); if (empty($error)) { return array($viewDir . '/' . basename($create_Image_info['src']), $create_Image_info['width'], $create_Image_info['height']); } return false; }
function nv_news_block_newscenter($block_config) { global $module_data, $module_name, $module_file, $module_upload, $global_array_cat, $global_config, $lang_module, $db, $module_config, $module_info; $db->sqlreset()->select('id, catid, publtime, title, alias, hometext, homeimgthumb, homeimgfile')->from(NV_PREFIXLANG . '_' . $module_data . '_rows')->where('status= 1')->order('publtime DESC')->limit(5); $list = nv_db_cache($db->sql(), 'id', $module_name); $list = array_values($list); if (!empty($list)) { $xtpl = new XTemplate('block_newscenter.tpl', NV_ROOTDIR . '/themes/' . $module_info['template'] . '/modules/' . $module_file); $xtpl->assign('lang', $lang_module); $xtpl->assign('TOOLTIP_POSITION', $block_config['tooltip_position']); foreach ($list as $i => $row) { $row['link'] = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $global_array_cat[$row['catid']]['alias'] . '/' . $row['alias'] . '-' . $row['id'] . $global_config['rewrite_exturl']; $row['hometext'] = nv_clean60(strip_tags($row['hometext']), 360); $row['titleclean60'] = nv_clean60($row['title'], 60); if ($i == 0) { $width = isset($block_config['width']) ? $block_config['width'] : 400; $height = isset($block_config['height']) ? $block_config['height'] : 268; if ($row['homeimgfile'] != '' and ($imginfo = nv_is_image(NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/' . $row['homeimgfile'])) != array()) { $image = NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; if ($imginfo['width'] <= $width and $imginfo['height'] <= $height) { $row['imgsource'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; $row['width'] = $imginfo['width']; } else { $basename = preg_replace('/(.*)(\\.[a-z]+)$/i', $module_name . '_' . $row['id'] . '_\\1_' . $width . '-' . $height . '\\2', basename($image)); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $imginfo = nv_is_image(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename); $row['imgsource'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; $row['width'] = $imginfo['width']; } else { $_image = new image($image, NV_MAX_WIDTH, NV_MAX_HEIGHT); $_image->resizeXY($width, $height); $_image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $row['imgsource'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; $row['width'] = $_image->create_Image_info['width']; } } } } elseif (nv_is_url($row['homeimgfile'])) { $row['imgsource'] = $row['homeimgfile']; $row['width'] = $width; } elseif (!empty($module_config[$module_name]['show_no_image'])) { $row['imgsource'] = NV_BASE_SITEURL . $module_config[$module_name]['show_no_image']; $row['width'] = $width; } else { $row['imgsource'] = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/no_image.gif'; $row['width'] = $width; } $xtpl->assign('main', $row); } else { if ($row['homeimgthumb'] == 1) { $row['imgsource'] = NV_BASE_SITEURL . NV_FILES_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; } elseif ($row['homeimgthumb'] == 2) { $row['imgsource'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; } elseif ($row['homeimgthumb'] == 3) { $row['imgsource'] = $row['homeimgfile']; } elseif (!empty($module_config[$module_name]['show_no_image'])) { $row['imgsource'] = NV_BASE_SITEURL . $module_config[$module_name]['show_no_image']; } else { $row['imgsource'] = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/no_image.gif'; } $row['hometext'] = nv_clean60($row['hometext'], $block_config['tooltip_length'], true); $xtpl->assign('othernews', $row); if (!$block_config['showtooltip']) { $xtpl->assign('TITLE', 'title="' . $row['title'] . '"'); } if ($block_config['showtooltip']) { $xtpl->parse('main.othernews.tooltip'); } $xtpl->parse('main.othernews'); } } $xtpl->parse('main'); return $xtpl->text('main'); } }
} require_once NV_ROOTDIR . '/includes/class/upload.class.php'; $upload = new upload($allow_files_type, $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT); if (isset($_FILES['upload']['tmp_name']) and is_uploaded_file($_FILES['upload']['tmp_name'])) { $upload_info = $upload->save_file($_FILES['upload'], NV_ROOTDIR . '/' . $path, false, $global_config['nv_auto_resize']); } else { $urlfile = rawurldecode(trim($nv_Request->get_string('fileurl', 'post'))); $upload_info = $upload->save_urlfile($urlfile, NV_ROOTDIR . '/' . $path, false, $global_config['nv_auto_resize']); } if (!empty($upload_info['error'])) { $error = $upload_info['error']; } elseif (preg_match('#image\\/[x\\-]*([a-z]+)#', $upload_info['mime'])) { if ($global_config['nv_auto_resize'] and ($upload_info['img_info'][0] > NV_MAX_WIDTH or $upload_info['img_info'][0] > NV_MAX_HEIGHT)) { require_once NV_ROOTDIR . '/includes/class/image.class.php'; $createImage = new image(NV_ROOTDIR . '/' . $path . '/' . $upload_info['basename'], $upload_info['img_info'][0], $upload_info['img_info'][1]); $createImage->resizeXY(NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->save(NV_ROOTDIR . '/' . $path, $upload_info['basename'], 90); $createImage->close(); $info = $createImage->create_Image_info; $upload_info['img_info'][0] = $info['width']; $upload_info['img_info'][1] = $info['height']; $upload_info['size'] = filesize(NV_ROOTDIR . '/' . $path . '/' . $upload_info['basename']); } if ($upload_info['size'] > NV_UPLOAD_MAX_FILESIZE) { nv_deletefile(NV_ROOTDIR . '/' . $path . '/' . $upload_info['basename']); $error = sprintf($lang_global['error_upload_max_user_size'], NV_UPLOAD_MAX_FILESIZE); } else { if ($upload_info['img_info'][0] > NV_MAX_WIDTH or $upload_info['img_info'][1] > NV_MAX_HEIGHT) { nv_deletefile(NV_ROOTDIR . '/' . $path . '/' . $upload_info['basename']); if ($upload_info['img_info'][0] > NV_MAX_WIDTH) { $error = sprintf($lang_global['error_upload_image_width'], NV_MAX_WIDTH);
$data['path'] = filter_text_input('pic_path', 'post', '', 0); $data['v_path'] = filter_text_input('v_path', 'post', '', 0); $data['description'] = filter_text_textarea('description', '', NV_ALLOWED_HTML_TAGS); $data['is_show'] = filter_text_input('is_show', 'post', '0', 0); if (!empty($data['v_path']) and file_exists(NV_DOCUMENT_ROOT . $data['v_path'])) { $lu = strlen(NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name); $data['v_path'] = substr($data['v_path'], $lu); } elseif (!nv_is_url($data['v_path']) and !empty($data['v_path'])) { $data['v_path'] = ""; } if (!empty($data['path']) and file_exists(NV_DOCUMENT_ROOT . $data['path'])) { $homeimgfile = NV_DOCUMENT_ROOT . $data['path']; require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($homeimgfile); $image = new image($homeimgfile, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($max_x, $max_y); $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb', $basename); $image_info = $image->create_Image_info; $image->close(); $thumb_name = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/', '', $image_info['src']); $lu = strlen(NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name); $data['path'] = substr($data['path'], $lu); } elseif (!nv_is_url($data['path']) and !empty($data['path'])) { $data['path'] = ""; } if ($data['albumid'] > 0) { if (empty($data['name'])) { $error = $lang_module['err_null_name']; } else { if (empty($data['v_path'])) { $error = $lang_module['err_null_path'];
$array['avatar_width'] = intval($array['x2'] - $array['x1']); $array['avatar_height'] = intval($array['y2'] - $array['y1']); if (sizeof(array_filter(array($array['x1'], $array['y1'], $array['x2'], $array['y2'], $array['w'], $array['h']))) < 4 or $array['avatar_width'] < $global_config['avatar_width'] or $array['avatar_height'] < $global_config['avatar_height']) { $array['error'] = $lang_module['avata_error_data']; } else { $upload = new upload(array('images'), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT); // Storage in temp dir $upload_info = $upload->save_file($_FILES['image_file'], NV_ROOTDIR . '/' . NV_TEMP_DIR, false); // Delete upload tmp @unlink($_FILES['image_file']['tmp_name']); if (empty($upload_info['error'])) { $basename = $upload_info['basename']; $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . nv_genpass(8) . "_" . $user_info['userid'] . '\\2', $basename); $image = new image($upload_info['name'], NV_MAX_WIDTH, NV_MAX_HEIGHT); // Resize image, crop image $image->resizeXY($array['w'], $array['h']); $image->cropFromLeft($array['x1'], $array['y1'], $array['avatar_width'], $array['avatar_height']); $image->resizeXY($global_config['avatar_width'], $global_config['avatar_height']); // Save new image $image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename); $image->close(); if (file_exists($image->create_Image_info['src'])) { $array['success'] = true; $array['filename'] = str_replace(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/', '', $image->create_Image_info['src']); } else { $array['error'] = $lang_module['avata_error_save']; } @nv_deletefile($upload_info['name']); } else { $array['error'] = $upload_info['error']; }
function createthumb($imgpath, $thumbpath, $filename, $thumbwidth, $thumbheight) { global $module_config, $module_name; if (file_exists($imgpath)) { require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($imgpath); $image = new image($imgpath, NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_basename = $basename; $i = 1; while (file_exists($thumbpath . '/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); ++$i; } $image->resizeXY($thumbwidth, $thumbheight); $image->save($thumbpath, $thumb_basename); $image_info = $image->create_Image_info; $thumb_name = str_replace($thumbpath, '', $image_info['src']); $image->close(); return $thumb_name; } else { return false; } }
} } elseif (!empty($p)) { $upload_real_dir_page = NV_ROOTDIR . '/' . NV_UPLOADS_DIR . '/' . $cp . $p; } $cp .= $p . '/'; } } } $currentpath = str_replace(NV_ROOTDIR . '/', '', $upload_real_dir_page); require_once NV_ROOTDIR . "/includes/class/image.class.php"; foreach ($imageMatch as $imageSrc) { if (nv_check_url($imageSrc)) { $_image = new image($imageSrc); if ($_image->fileinfo['width'] > 50) { if ($_image->fileinfo['width'] > NV_MAX_WIDTH) { $_image->resizeXY(NV_MAX_WIDTH, NV_MAX_HEIGHT); } $basename = explode(".", basename($imageSrc)); array_pop($basename); $basename = implode("-", $basename); $basename = preg_replace('/^\\W+|\\W+$/', '', $basename); $basename = preg_replace('/[ ]+/', '_', $basename); $basename = strtolower(preg_replace('/\\W-/', '', $basename)); $basename .= '.' . $_image->fileinfo['ext']; $thumb_basename = $basename; $i = 1; while (file_exists(NV_ROOTDIR . '/' . $currentpath . '/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); $i++; } $_image->save(NV_ROOTDIR . '/' . $currentpath, $thumb_basename);
} elseif (file_exists(NV_ROOTDIR . '/images/logo.png')) { $upload_logo = NV_ROOTDIR . '/images/logo.png'; } else { die("ERROR#" . $lang_module['notlogo']); } $config_logo = array(); $config_logo['x'] = $nv_Request->get_int('x', 'post', 0); $config_logo['y'] = $nv_Request->get_int('y', 'post', 0); $config_logo['w'] = $nv_Request->get_int('w', 'post', 0); $config_logo['h'] = $nv_Request->get_int('h', 'post', 0); if ($config_logo['w'] > 0 and $config_logo['h'] > 0) { require_once NV_ROOTDIR . "/includes/class/image.class.php"; $createImage = new image(NV_ROOTDIR . '/' . $path . '/' . $file, NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->addlogo($upload_logo, '', '', $config_logo); $createImage->save(NV_ROOTDIR . '/' . $path, $file); $createImage->resizeXY(80, 80); $createImage->save(NV_ROOTDIR . '/' . NV_FILES_DIR . '/images', md5($path . '/' . $file), 75); $create_Image_info = $createImage->create_Image_info; $createImage->close(); $info = nv_getFileInfo($path, $file); $tempFile = NV_ROOTDIR . "/" . NV_FILES_DIR . "/dcache/" . md5($path); $results = file_get_contents($tempFile); $results = unserialize($results); $results[$file] = $info; file_put_contents($tempFile, serialize($results)); die("OK#" . basename($create_Image_info['src'])); } else { die("ERROR#" . $lang_module['notlevel']); } } if (file_exists(NV_ROOTDIR . '/' . $global_config['upload_logo'])) {