Guest User

fusion photo

a guest
May 5th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.42 KB | None | 0 0
  1. <?php
  2. /*-------------------------------------------------------+
  3. | PHP-Fusion Content Management System
  4. | Copyright (C) 2002 - 2011 Nick Jones
  5. | http://www.php-fusion.co.uk/
  6. +--------------------------------------------------------+
  7. | Filename: photo.php
  8. | Author: Robert Gaudyn (Wooya)
  9. +--------------------------------------------------------+
  10. | This program is released as free software under the
  11. | Affero GPL license. You can redistribute it and/or
  12. | modify it under the terms of this license which you
  13. | can read by viewing the included agpl.txt or online
  14. | at www.gnu.org/licenses/agpl.html. Removal of this
  15. | copyright header is strictly prohibited without
  16. | written permission from the original author(s).
  17. +--------------------------------------------------------*/
  18. require_once "maincore.php";
  19. if (!@ini_get("safe_mode")) { define("SAFEMODE", false); } else { define("SAFEMODE", true); }
  20. function convert_color($hex) {
  21.     $len = strlen($hex);
  22.     preg_match("/([0-9]|[A-F]|[a-f]){".$len."}/i", $hex, $arr);
  23.     $hex = $arr[0];
  24.     if ($hex) {
  25.         switch($len) {
  26.             case 2:
  27.                 $red = hexdec($hex);
  28.                 $green = 0;
  29.                 $blue = 0;
  30.             break;
  31.             case 4:
  32.                 $red = hexdec(substr($hex, 0, 2));
  33.                 $green = hexdec(substr($hex, 2, 2));
  34.                 $blue = 0;
  35.             break;
  36.             case 6:
  37.                 $red = hexdec(substr($hex, 0, 2));
  38.                 $green = hexdec(substr($hex, 2, 2));
  39.                 $blue = hexdec(substr($hex, 4, 2));
  40.             break;
  41.         }
  42.         $color['success'] = true;
  43.         $color['r'] = $red;
  44.         $color['g'] = $green;
  45.         $color['b'] = $blue;
  46.         return $color;
  47.     } else {
  48.         $color['success'] = false;
  49.         $color['error'] = $locale['global_900'];
  50.         return $color;
  51.     }
  52. }
  53. if (isset($_GET['photo_id']) && isnum($_GET['photo_id'])) {
  54.     $result = dbquery(
  55.         "SELECT ta.album_id, ta.album_title, ta.album_description, ta.album_access, tp.photo_title, tp.photo_filename, tp.photo_thumb2
  56.         FROM ".DB_PHOTOS." tp INNER JOIN ".DB_PHOTO_ALBUMS." ta USING (album_id)
  57.         WHERE photo_id=".$_GET['photo_id']." GROUP BY tp.photo_id"
  58.     );
  59.     $data = dbarray($result);
  60.     if (checkgroup($data['album_access'])) {
  61.         define("PHOTODIR", PHOTOS.(!SAFEMODE ? "album_".$data['album_id']."/" : ""));
  62.         $parts = explode(".", $data['photo_filename']);
  63.         $wm_file1 = $parts[0]."_w1.".$parts[1];
  64.         $wm_file2 = $parts[0]."_w2.".$parts[1];
  65.         if (!isset($_GET['full'])) {
  66.             $wm_file = PHOTODIR.$wm_file1;
  67.         } else {
  68.             $wm_file = PHOTODIR.$wm_file2;
  69.         }
  70.         header("Content-type: image/jpg");
  71.         $img = PHOTODIR.$data['photo_filename'];
  72.         $cop = BASEDIR.$settings['photo_watermark_image'];
  73.         if (preg_match("/.jpg/i", strtolower($img)) || preg_match("/.jpeg/i", strtolower($img))) {
  74.             $image = ImageCreateFromJPEG($img);
  75.         } else if (preg_match("/.png/i", strtolower($img))) {
  76.             $image = ImageCreateFromPNG($img);
  77.         } else if (preg_match("/.gif/i", strtolower($img))) {
  78.             $image = ImageCreateFromGIF($img);
  79.             $sizeX = ImagesX($image);
  80.             $sizeY = ImagesY($image);
  81.             $image_tmp = ImageCreateTrueColor($sizeX, $sizeY);
  82.             $ica = ImageColorAllocate($image_tmp, 255, 255, 255);
  83.             ImageFill($image_tmp, 0, 0, $ica);
  84.             if ($settings['thumb_compression'] == "gd2") {
  85.                 ImageCopyResampled($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY);
  86.             } else {
  87.                 ImageCopyResized($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY);
  88.             }
  89.             $tmp = PHOTODIR.md5(time().$img).'.tmp';
  90.             ImageJPEG($image_tmp, $tmp);
  91.             ImageDestroy($image_tmp);
  92.             $image = ImageCreateFromJPEG($tmp);
  93.             unlink($tmp);
  94.         }
  95.         if (file_exists($cop) && preg_match("/.png/i", strtolower($cop)) && $settings['photo_watermark']) {
  96.             $image2 = false;
  97.             $image_dim_x = ImagesX($image);
  98.             $image_dim_y = ImagesY($image);
  99.             $copyright = ImageCreateFromPNG($cop);
  100.             $copyright_dim_x = ImagesX($copyright);
  101.             $copyright_dim_y = ImagesY($copyright);
  102.             $where_x = $image_dim_x - $copyright_dim_x - 5;
  103.             $where_y = $image_dim_y - $copyright_dim_y - 5;
  104.             ImageCopy ($image, $copyright, $where_x, $where_y, 0, 0, $copyright_dim_x, $copyright_dim_y);
  105.             $thumb_w = 0; $thumb_h = 0;
  106.             if (!isset($_GET['full'])) {
  107.                 if ($image_dim_x > $settings['photo_w'] || $image_dim_y > $settings['photo_h']) {
  108.                     if ($image_dim_x < $image_dim_y) {
  109.                         $thumb_w = round(($image_dim_x * $settings['photo_h']) / $image_dim_y);
  110.                         $thumb_h = $settings['photo_h'];
  111.                     } elseif ($image_dim_x > $image_dim_y) {
  112.                         $thumb_w = $settings['photo_w'];
  113.                         $thumb_h = round(($image_dim_y * $settings['photo_w']) / $image_dim_x);
  114.                     } else {
  115.                         $thumb_w = $settings['photo_w'];
  116.                         $thumb_h = $settings['photo_h'];
  117.                     }
  118.                 } else {
  119.                     $thumb_w = $image_dim_x;
  120.                     $thumb_h = $image_dim_y;
  121.                 }
  122.                 $image2 = ImageCreateTrueColor($thumb_w, $thumb_h);
  123.                 if ($settings['thumb_compression'] == "gd2") {
  124.                     ImageCopyResampled($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y);
  125.                 } else {
  126.                     ImageCopyResized($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y);
  127.                 }
  128.                 ImageDestroy($image);
  129.             }
  130.             if ($settings['photo_watermark_text']) {
  131.                 $enc = array("&amp;", "&quot;", "&#39;", "&#92;", "&quot;", "&#39;", "&lt;", "&gt;");
  132.                 $dec = array("&", "\"", "'", "\\", '\"', "\'", "<", ">");
  133.                 $black = ImageColorAllocate(($image2 ? $image2 : $image), 0, 0, 0);
  134.                 $colors1 = convert_color($settings['photo_watermark_text_color1']);
  135.                 $colors2 = convert_color($settings['photo_watermark_text_color2']);
  136.                 $colors3 = convert_color($settings['photo_watermark_text_color3']);
  137.                 $color1 = ImageColorAllocate(($image2 ? $image2 : $image), $colors1['r'], $colors1['g'], $colors1['b']);
  138.                 $color2 = ImageColorAllocate(($image2 ? $image2 : $image), $colors2['r'], $colors2['g'], $colors2['b']);
  139.                 $color3 = ImageColorAllocate(($image2 ? $image2 : $image), $colors3['r'], $colors3['g'], $colors3['b']);
  140.                 //move text y
  141.                 $mty1 = ($thumb_h ? $thumb_h : $image_dim_y) - ($thumb_h ? 40 : 50);
  142.                 $mty2 = ($thumb_h ? $thumb_h : $image_dim_y) - ($thumb_h ? 25 : 35);
  143.                 $mty3 = ($thumb_h ? $thumb_h : $image_dim_y) - ($thumb_h ? 15 : 20);
  144.                 $album_title = str_replace("\r", "", $data['album_title']);
  145.                 $album_title = str_replace("\n", "", $album_title);
  146.                 $album_title = preg_replace("[\[(.*?)\]]", "", $album_title);
  147.                 $album_title = preg_replace("<\<(.*?)\>>", "", $album_title);
  148.                 $album_title = trimlink($album_title, 75);
  149.                 $album_title = str_replace($enc, $dec, $album_title);
  150.                 $album_description = str_replace("\r", "", $data['album_description']);
  151.                 $album_description = str_replace("\n", "", $album_description);
  152.                 $album_description = preg_replace("[\[(.*?)\]]", "", $album_description);
  153.                 $album_description = preg_replace("<\<(.*?)\>>", "", $album_description);
  154.                 $album_description = trimlink($album_description, 75);
  155.                 $album_description = str_replace($enc, $dec, $album_description);
  156.                 $photo_title = str_replace("\r", "", $data['photo_title']);
  157.                 $photo_title = str_replace("\n", "", $photo_title);
  158.                 $photo_title = preg_replace("[\[(.*?)\]]", "", $photo_title);
  159.                 $photo_title = preg_replace("<\<(.*?)\>>", "", $photo_title);
  160.                 $photo_title = trimlink($photo_title, 75);
  161.                 $photo_title = str_replace($enc, $dec, $photo_title);
  162.                 $album_title_font_size = !isset($_GET['full']) ? 3 : 5;
  163.                 $album_descr_font_size = !isset($_GET['full']) ? 1 : 3;
  164.                 $photo_title_font_size = !isset($_GET['full']) ? 1 : 3;
  165.                 //album title
  166.                 ImageString(($image2 ? $image2 : $image), $album_title_font_size, 10, $mty1 - 1,  $album_title, $black);
  167.                 ImageString(($image2 ? $image2 : $image), $album_title_font_size, 10, $mty1 + 1,  $album_title, $black);
  168.                 ImageString(($image2 ? $image2 : $image), $album_title_font_size, 9,  $mty1,      $album_title, $black);
  169.                 ImageString(($image2 ? $image2 : $image), $album_title_font_size, 11, $mty1,      $album_title, $black);
  170.                 ImageString(($image2 ? $image2 : $image), $album_title_font_size, 10, $mty1,      $album_title, $color1);
  171.                 //album info
  172.                 ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 10, $mty2 - 1,  $album_description, $black);
  173.                 ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 10, $mty2 + 1,  $album_description, $black);
  174.                 ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 9,  $mty2,      $album_description, $black);
  175.                 ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 11, $mty2,      $album_description, $black);
  176.                 ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 10, $mty2,      $album_description, $color2);
  177.                 //photo name
  178.                 ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 10, $mty3 - 1,  $photo_title, $black);
  179.                 ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 10, $mty3 + 1,  $photo_title, $black);
  180.                 ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 9,  $mty3,      $photo_title, $black);
  181.                 ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 11, $mty3,      $photo_title, $black);
  182.                 ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 10, $mty3,      $photo_title, $color3);
  183.             }
  184.         }
  185.         //create image
  186.         if ($settings['photo_watermark_save']) { ImageJPEG(($image2 ? $image2 : $image), $wm_file); }
  187.         ImageJPEG((isset($image2) && $image2 ? $image2 : $image));
  188.         ImageDestroy((isset($image2) && $image2 ? $image2 : $image));
  189.         if (isset($copyright) && is_resource($copyright)) {  ImageDestroy($copyright); }
  190.     } else {
  191.         redirect("index.php");
  192.     }
  193. } else {
  194.     redirect("index.php");
  195. }
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment