function videos_thumbs($id, $file, $module_upload, $width = 200, $height = 150, $quality = 90) { if ($width >= $height) { $rate = $width / $height; } else { $rate = $height / $width; } $image = NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/img/' . $file; if ($file != '' and file_exists($image)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/img/' . $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 NukeViet\Files\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; }
while (file_exists(NV_ROOTDIR . '/' . $path . '/' . $file)) { $file = preg_replace('/^(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $width . '_' . $height . '_' . $i . '\\2', $imagename); ++$i; } if (isset($array_thumb_config[$path])) { $thumb_config = $array_thumb_config[$path]; } else { $thumb_config = $array_thumb_config['']; $_arr_path = explode('/', $path); 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; } } } $createImage = new NukeViet\Files\Image(NV_ROOTDIR . '/' . $path . '/' . $imagename, NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->resizeXY($width, $height); $createImage->save(NV_ROOTDIR . '/' . $path, $file, $thumb_config['thumb_quality']); $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;
if ($mk[0] > 0) { $upload_real_dir_page = $mk[2]; } } elseif (!empty($p)) { $upload_real_dir_page = NV_ROOTDIR . '/' . NV_UPLOADS_DIR . '/' . $cp . $p; } $cp .= $p . '/'; } } } foreach ($imageMatch as $imageSrc) { if (nv_check_url($imageSrc)) { $_image = new NukeViet\Files\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($upload_real_dir_page . '/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); $i++; } $_image->save($upload_real_dir_page, $thumb_basename);
$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['avatar_error_data']; } else { $upload = new NukeViet\Files\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 NukeViet\Files\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['filename'] = str_replace(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/', '', $image->create_Image_info['src']); if ($array['u'] == "upd") { updateAvatar($array['filename']); $array['success'] = 2; } elseif ($array['u'] == "src") { updateAvatar($array['filename']); $array['filename'] = NV_BASE_SITEURL . SYSTEM_UPLOADS_DIR . '/' . $module_upload . '/' . $array['filename']; $array['success'] = 3; } else {
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')->order('publtime DESC')->limit($block_config['numrow']); if (empty($block_config['nocatid'])) { $db->where('status= 1'); } else { $db->where('status= 1 AND catid NOT IN (' . implode(',', $block_config['nocatid']) . ')'); } $list = $nv_Cache->db($db->sql(), 'id', $module_name); 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']); $_first = true; foreach ($list as $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['titleclean60'] = nv_clean60($row['title'], $block_config['length_title']); if ($_first) { $_first = false; $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 NukeViet\Files\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; } $row['hometext'] = nv_clean60(strip_tags($row['hometext']), $block_config['length_hometext']); $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(strip_tags($row['hometext']), $block_config['tooltip_length']); $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'); } }
$thumb_config = $array_thumb_config[$path]; } else { $thumb_config = $array_thumb_config['']; $_arr_path = explode('/', $path); 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; } } } if ($global_config['nv_auto_resize'] and ($upload_info['img_info'][0] > NV_MAX_WIDTH or $upload_info['img_info'][0] > NV_MAX_HEIGHT)) { $createImage = new NukeViet\Files\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'], $thumb_config['thumb_quality']); $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);
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['avatar_error_data']; } else { $upload = new NukeViet\Files\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 NukeViet\Files\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['filename'] = str_replace(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/', '', $image->create_Image_info['src']); if ($array['u'] == 'upd') { updateAvatar($array['filename']); $array['success'] = 2; } elseif ($array['u'] == 'src') { updateAvatar($array['filename']); $array['filename'] = NV_BASE_SITEURL . SYSTEM_UPLOADS_DIR . '/' . $module_upload . '/' . $array['filename']; $array['success'] = 3; } else { $array['success'] = 1; }
/** * 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|bmp)))$/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] . '_' . md5($original_name . $width) . $matches[4]; $is_create = true; if (is_file(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) { $image = new NukeViet\Files\Image($original_name, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($width); $image->save(NV_ROOTDIR . '/' . $thumb_path, $matches[3] . '_' . md5($original_name . $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; }
/** * nv_get_viewImage() * * @param mixed $fileName * @return */ 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|bmp|ico)))$/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 NukeViet\Files\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; } } if ($image->fileinfo['width'] > $thumb_config['thumb_width'] or $image->fileinfo['height'] > $thumb_config['thumb_height']) { $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']); } } elseif (copy(NV_ROOTDIR . '/' . $fileName, NV_ROOTDIR . '/' . $viewDir . '/' . $m[3] . $m[4])) { $return = array($viewDir . '/' . $m[3] . $m[4], $image->fileinfo['width'], $image->fileinfo['height']); $image->close(); return $return; } else { return false; } } } else { $size = @getimagesize(NV_ROOTDIR . '/' . $fileName); return array($fileName, $size[0], $size[1]); } return false; }