Sheon
Advanced Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору Step 1. Open /includes/functions.php Find: Code: function show_image($image_row, $mode = "", $show_link = 1, $detailed_view = 0) { Replace with: Code: function show_image($image_row, $mode = "", $show_link = 1, $detailed_view = 0, $encrypt = 0) { Step 1.2. Find: Code: "image" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view), Replace with: Code: "image" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view, $encrypt), Step 1.3. Find: Code: function get_media_code($media_file_name, $image_id = 0, $cat_id = 0, $image_name = "", $mode = "", $show_link = 0, $detailed_view = 0) { Replace with: Code: function get_media_code($media_file_name, $image_id = 0, $cat_id = 0, $image_name = "", $mode = "", $show_link = 0, $detailed_view = 0, $encrypt = 0) { Step 1.4. Find: Code: "media_src" => $media_src, Replace with: Code: "media_src" => ($encrypt) ? ROOT_PATH."show.php?pic=".encrypt_add($media_src) : $media_src, "media_src_original" => $media_src, Step 1.5. At the end of the file, just before closing ?> insert: Code: function encrypt_add($file){ global $_SESSION; @session_name('4images_pic'); @session_start(); $file = base64_encode($file); $id = md5(uniqid(microtime())); $_SESSION['4images_pic'] = $id." ".$file." ".time(); return $id; } Step 1.6. (added 10/15/2004) If u installed [MOD] Show original image in new window by clicking on image then also u'll need do this: Find: Code: "media_src_big" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view, 1), Replace it with: Code: "media_src_big" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view, 1, 1), Also Step 1.2 and Step 1.3. has to be changed for u: in Step 1.2 use this line: Code: function get_media_code($media_file_name, $image_id = 0, $cat_id = 0, $image_name = "", $mode = "", $show_link = 0, $detailed_view = 0, $big=0, $encrypt = 0) { and in Step 1.3 this: Code: "image" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view, $big, $encrypt), Step 2. Open /details.php Find: Code: show_image($image_row, $mode, 0, 1); Replace with: Code: show_image($image_row, $mode, 0, 1, 1); Step 3. Create a new file and save it as show.php in 4images root dir, with this code: Code: <?php //-----------------------------------------------------\\ //--- Created by V@no ©2003 http://gallery.vano.org ---\\ //-----------------------------------------------------\\ //---- Settings -------- $expire = 35; //seconds $reduce = 20; //reduce expire time after first call //-- End Settings ------ define('ROOT_PATH', './'); include(ROOT_PATH.'includes/upload_definitions.php'); @session_name('4images_pic'); @session_start(); function is_remote_file($file_name) { return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.([a-z]{1,4})$)#is", $file_name)) ? 1 : 0; } function get_file_extension($file_name) { ereg("(.+)\.(.+)", basename($file_name), $regs); return strtolower($regs[2]); } function get_file($file){ $file_size = @filesize($file); $fp = @fopen($file, "rb"); $data = @fread ($fp, $file_size); @fclose($fp); return $data; } if (isset($_GET['pic']) || isset($_POST['pic'])) { $id = (isset($_GET['pic'])) ? $_GET['pic'] : $_POST['pic']; }else{ $id = 0; } $error = ""; if ($id && isset($_SESSION['4images_pic']) && $_SESSION['4images_pic']) { $expired = time() - $expire; $pic = explode(" ", $_SESSION['4images_pic']); if (count($pic) != 3) { $error = "no/pic_error.gif"; //general error }elseif ($pic[0] != $id) { $error = "no/pic_image.gif"; //no image found }elseif ($expired >= $pic[2]) { $error = "no/pic_expired.gif"; //image expired } if (!$error) { $file = base64_decode($pic[1]); $file_size = @filesize($file); $_SESSION['4images_pic'] = $pic[0]." ".$pic[1]." ".($pic[2]-$reduce); if ($image_info = @getimagesize($file) && !is_remote_file($file) && $mime_type_match[get_file_extension($file)][0]) { header ("Content-type: ".$mime_type_match[get_file_extension($file)][0]); $file = get_file($file); header ("Content-Length: ".strlen($file)."\n\n"); echo $file; exit; } header ("Location: ".stripslashes($file)); exit; }else{ unset($_SESSION['4images_pic']); } }else{ $error = "no/pic_error.gif"; } header("Content-type: image/gif"); echo get_file($error); ?> Adjust two values: Quote: //---- Settings -------- $expire = 35; //seconds before expiration. If u make it too low, the visitors whos on dialup will get "picture expired". $reduce = 20; //reduce expire time in seconds after each call (not a good idea set this same as $expire time, because some browsers can do "double" page refresh, that will cause of "expire" message.) //-- End Settings ------ Step 4. Create 3 .gif images that would be showed instead of the real image, when something went wrong. Upload them in /no/ folder (create it first. Name of the images must be as followed): /no/pic_error.gif - general error (something wrong with the session or ID didnt match) /no/pic_image.gif - image not found /no/pic_expired.gif - image expired Step 5. (added 09/13/04) Open postcards.php Find: Код: $image = get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, 1); | Replace with: Код: $image = get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, 1, 0, 1); | after all this u can rename your /media/ folder to something else and noone could find where the images are (dont forget adjust /includes/constants.php too) P.S. this method has few down-sides: - each time picture being viewed it will be downloaded from the server, instead of showing from cache (extra trafic) - the script returns the original media path when the media is not an image (.avi, .zip, etc) or when media is remote. And here is how to make sure the browser doesn't cache the viewed file to disk. Change this IN show.php block: Code: header ("Content-Length: ".strlen($file)."\n\n"); echo $file; exit; to this: Code: header ("Content-Length: ".strlen($file)."\n\n"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // expires in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Last modified, right now header("Cache-Control: no-cache, must-revalidate"); // Prevent caching, HTTP/1.1 header("Pragma: no-cache"); // Prevent caching, HTTP/1.0 echo $file; exit; martrix wrote: It would be very nice, if somebody could write how to add this nonono.gif modification to 4images and how to mask the {media_src} url. Я пораньше использовал этот мод. Но в принципе, если ты не хочешь сильно заморачиваться (при использовании указаного выше мода могут не открываться фотки, если связь медленная, надо экспериментировать с настройками). Можешь использовать этот мод в связи с нижним. Это обеспечит вообще полную защиту. Но можно использовать просто нижний мод, если надо что-то простое. Цитата: открой /templates/<yourtemplate>/media/jpg.html (этот пример для jpg.html template, но можно использовать его и для остальных) Замени Код: <img src="{media_src}" border="1" alt="{image_name}"{width_height} /> | на: Код: <table style="background: url({media_src}) no-repeat; background-position: center center" cellpadding="0" cellspacing="0"> <tr> <td><img src="{template_url}/images/spacer.gif" border="1" alt="{image_name}"{width_height} /></td> </tr> </table> | убедитесь что файл spacer.gif находится в папке /templates/<yourtemplate>/images/ | Это мой вольный перевод. Все моды взяты с форума. |