PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/album_pic_nuffed.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 208 lines | 116 code | 43 blank | 49 comment | 70 complexity | d607a41aef549e665bd0f583c02ad2c0 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. define('IN_ICYPHOENIX', true);
  11. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  12. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  13. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  14. // Start session management
  15. $user->session_begin();
  16. $auth->acl($user->data);
  17. $user->setup();
  18. // End session management
  19. // Get general album information
  20. include(ALBUM_MOD_PATH . 'album_common.' . PHP_EXT);
  21. require(IP_ROOT_PATH . 'includes/class_image.' . PHP_EXT);
  22. // ------------------------------------
  23. // Check the request
  24. // ------------------------------------
  25. $pic_id = request_var('pic_id', 0);
  26. if ($pic_id <= 0)
  27. {
  28. image_no_thumbnail('no_thumb.jpg');
  29. exit;
  30. //die($lang['NO_PICS_SPECIFIED']);
  31. //message_die(GENERAL_MESSAGE, $lang['NO_PICS_SPECIFIED']);
  32. }
  33. // ------------------------------------
  34. // Get this pic info and current category info
  35. // ------------------------------------
  36. $sql = "SELECT p.*, c.*
  37. FROM " . ALBUM_TABLE . " AS p, " . ALBUM_CAT_TABLE . " AS c
  38. WHERE pic_id = '" . $pic_id . "'
  39. AND c.cat_id = p.pic_cat_id
  40. LIMIT 1";
  41. $result = $db->sql_query($sql);
  42. $thispic = $db->sql_fetchrow($result);
  43. $db->sql_freeresult($result);
  44. $cat_id = $thispic['pic_cat_id'];
  45. $album_user_id = $thispic['cat_user_id'];
  46. $pic_info = array();
  47. $pic_info = pic_info($thispic['pic_filename'], $thispic['pic_thumbnail'], $thispic['pic_title']);
  48. if(empty($thispic) || ($pic_info['exists'] == false) || !file_exists($pic_info['fullpath']))
  49. {
  50. message_die(GENERAL_MESSAGE, $lang['Pic_not_exist']);
  51. }
  52. // ------------------------------------
  53. // Check the permissions
  54. // ------------------------------------
  55. $album_user_access = album_permissions($album_user_id, $cat_id, ALBUM_AUTH_VIEW, $thispic);
  56. if($album_user_access['view'] == false)
  57. {
  58. message_die(GENERAL_MESSAGE, $lang['Not_Authorized']);
  59. }
  60. // ------------------------------------
  61. // Check Pic Approval
  62. // ------------------------------------
  63. if($user->data['user_level'] != ADMIN)
  64. {
  65. if(($thispic['cat_approval'] == ADMIN) || (($thispic['cat_approval'] == MOD) && !$album_user_access['moderator']))
  66. {
  67. if($thispic['pic_approval'] != 1)
  68. {
  69. message_die(GENERAL_MESSAGE, $lang['Not_Authorized']);
  70. }
  71. }
  72. }
  73. // ------------------------------------
  74. // Check hotlink
  75. // ------------------------------------
  76. if(($album_config['hotlink_prevent'] == true) && (isset($_SERVER['HTTP_REFERER'])))
  77. {
  78. $check_referer = explode('?', $_SERVER['HTTP_REFERER']);
  79. $check_referer = trim($check_referer[0]);
  80. $good_referers = array();
  81. if ($album_config['hotlink_allowed'] != '')
  82. {
  83. $good_referers = explode(',', $album_config['hotlink_allowed']);
  84. }
  85. $good_referers[] = $config['server_name'] . $config['script_path'];
  86. $errored = true;
  87. for ($i = 0; $i < sizeof($good_referers); $i++)
  88. {
  89. $good_referers[$i] = trim($good_referers[$i]);
  90. if((strstr($check_referer, $good_referers[$i])) && ($good_referers[$i] != ''))
  91. {
  92. $errored = false;
  93. }
  94. }
  95. if($errored)
  96. {
  97. message_die(GENERAL_MESSAGE, $lang['Not_Authorized']);
  98. /*
  99. image_no_thumbnail($pic_info['title_reg'] . '.' . $pic_info['filetype']);
  100. exit;
  101. */
  102. }
  103. }
  104. $nuff_http = nuff_http_vars();
  105. $Image = new ImgObj();
  106. $Image->ReadSourceFile($pic_info['fullpath']);
  107. if((($nuff_http['nuff_sepia'] == true) || ($nuff_http['nuff_bw'] == true) || ($nuff_http['nuff_blur'] == true) || ($nuff_http['nuff_scatter'] == true)) && ($album_config['enable_sepia_bw'] == true))
  108. {
  109. (($nuff_http['nuff_resize_w'] == 0) || ($nuff_http['nuff_resize_w'] > 200)) ? ($nuff_http['nuff_resize_w'] = 200) : false;
  110. (($nuff_http['nuff_resize_h'] == 0) || ($nuff_http['nuff_resize_h'] > 150)) ? ($nuff_http['nuff_resize_h'] = 150) : false;
  111. $Image->Resize($nuff_http['nuff_resize_w'], $nuff_http['nuff_resize_h']);
  112. //Apply sepia filter (best to resize before this)
  113. ($nuff_http['nuff_sepia'] == true) ? $Image->Sepia() : false;
  114. //Apply grayscale filter (best to resize before this)
  115. ($nuff_http['nuff_bw'] == true) ? $Image->Grayscale() : false;
  116. //Apply blur filter (best to resize before this)
  117. ($nuff_http['nuff_blur'] == true) ? $Image->Blur(10, 10) : false;
  118. //Apply scatter filter (best to resize before this)
  119. ($nuff_http['nuff_scatter'] == true) ? $Image->Scatter(3) : false;
  120. }
  121. else
  122. {
  123. if ($nuff_http['nuff_resize'] == true)
  124. {
  125. $Image->Resize($nuff_http['nuff_resize_w'], $nuff_http['nuff_resize_h']);
  126. }
  127. }
  128. //Apply pixelate filter
  129. ($nuff_http['nuff_pixelate'] == true) ? $Image->Pixelate(4) : false;
  130. //Apply stereogram (best to resize before this)
  131. ($nuff_http['nuff_stereogram'] == true) ? $Image->Stereogram(1) : false;
  132. //Apply infrared filter
  133. ($nuff_http['nuff_infrared'] == true) ? $Image->Infrared() : false;
  134. //Apply tint filter
  135. ($nuff_http['nuff_tint'] == true) ? $Image->Tint(160, 0, 0) : false;
  136. //Apply interlace filter
  137. ($nuff_http['nuff_interlace'] == true) ? $Image->Interlace() : false;
  138. //Apply screen filter
  139. ($nuff_http['nuff_screen'] == true) ? $Image->Screen() : false;
  140. //Mirror image [1=horizontal, 2=vertical, 3=both]
  141. ($nuff_http['nuff_mirror'] == true) ? $Image->Flip(1) : false;
  142. //Flip image [1=horizontal, 2=vertical, 3=both]
  143. ($nuff_http['nuff_flip'] == true) ? $Image->Flip(2) : false;
  144. //Rotate anti-clockwise degrees (transparency lost)
  145. if($nuff_http['nuff_rotation_d'] > 0)
  146. {
  147. ($nuff_http['nuff_rotation'] == true) ? $Image->Rotate($nuff_http['nuff_rotation_d']) : false;
  148. }
  149. //WatermarkPos(File, Pos, Size, Transition)
  150. if(($pic_info['filetype'] != 'gif') && ($album_config['use_watermark'] == true) && ($user->data['user_level'] != ADMIN) &&
  151. ((!$user->data['session_logged_in']) || ($album_config['wut_users'] == 1)))
  152. {
  153. //$wm_file = ALBUM_WM_FILE;
  154. $wm_file = (file_exists($thispic['cat_wm']) ? $thispic['cat_wm'] : ALBUM_WM_FILE);
  155. $wm_position = (($album_config['disp_watermark_at'] > 0) && ($album_config['disp_watermark_at'] < 10)) ? $album_config['disp_watermark_at'] : 5;
  156. $wm_maxsize = 50;
  157. $wm_transition = 100;
  158. $Image->WatermarkPos($wm_file, $wm_position, $wm_maxsize, $wm_transition);
  159. }
  160. //$Image->SendToFile("cache/test2"); //Write image to file
  161. //JPG Compression
  162. (($nuff_http['nuff_recompress'] == false) || ($nuff_http['nuff_recompress_r'] == 0)) ? ($nuff_http['nuff_recompress_r'] = 75) : false;
  163. $Image->SendToBrowser($pic_info['title_reg'], $pic_info['filetype'], '', '_nuffed', $nuff_http['nuff_recompress_r']);
  164. $Image->Destroy(); //Destroy whole class including GD image in memory.
  165. ?>