Kamron
  1. <?php
  2.  
  3. /**
  4.  * @package JohnCMS
  5.  * @link http://johncms.com
  6.  * @copyright Copyright (C) 2008-2011 JohnCMS Community
  7.  * @license LICENSE.txt (see attached file)
  8.  * @version VERSION.txt (see attached file)
  9.  * @author http://johncms.com/about
  10.  */
  11.  
  12. define('_IN_JOHNCMS', 1);
  13.  
  14. require('../incfiles/core.php');
  15. $headmod = 'gallery';
  16. $lng_gal = core::load_lng('gallery');
  17. $textl = $lng['gallery'];
  18. require('../incfiles/head.php');
  19.  
  20. // Ограничиваем доступ к Галерее
  21. $error = '';
  22. if (!$set['mod_gal'] && $rights < 7) {
  23. $error = $lng_gal['gallery_closed'];
  24. } elseif ($set['mod_gal'] == 1 && !$user_id) {
  25. $error = $lng['access_guest_forbidden'];
  26. }
  27. if ($error) {
  28. require_once('../incfiles/head.php');
  29. echo '<div class="rmenu"><p>' . $error . '</p></div>';
  30. require_once('../incfiles/end.php');
  31. }
  32.  
  33. function setTransparency($new_image, $image_source)
  34. {
  35. $transparencyIndex = imagecolortransparent($image_source);
  36. $transparencyColor = array('red' => 255, 'green' => 255, 'blue' => 255);
  37.  
  38. if ($transparencyIndex >= 0) {
  39. $transparencyColor = imagecolorsforindex($image_source, $transparencyIndex);
  40. }
  41.  
  42. $transparencyIndex = imagecolorallocate($new_image, $transparencyColor['red'], $transparencyColor['green'],
  43. $transparencyColor['blue']);
  44. imagefill($new_image, 0, 0, $transparencyIndex);
  45. imagecolortransparent($new_image, $transparencyIndex);
  46. }
  47.  
  48. $array = array(
  49. 'new',
  50. 'edf',
  51. 'delf',
  52. 'edit',
  53. 'del',
  54. 'load',
  55. 'upl',
  56. 'cral',
  57. 'razd'
  58. );
  59.  
  60. if (in_array($act, $array) && file_exists($act . '.php')) {
  61. require_once($act . '.php');
  62. } else {
  63. if (!$set['mod_gal']) {
  64. echo '<p><font color="#FF0000"><b>' . $lng_gal['gallery_closed'] . '</b></font></p>';
  65. }
  66. if ($id) {
  67. $type = mysql_query("SELECT * FROM `gallery` WHERE `id` = '$id' LIMIT 1");
  68. $ms = mysql_fetch_assoc($type);
  69. switch ($ms['type']) {
  70. case 'rz':
  71. /*
  72.   -----------------------------------------------------------------
  73.   Просмотр раздела
  74.   -----------------------------------------------------------------
  75.   */
  76. echo '<div class="phdr"><i class="fa fa-picture-o" style="color:#ffffff;"></i> <a href="index.php"><b>' . $lng['gallery'] . '</b></a> | ' . $ms['text'] . '</div>';
  77. $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `type` = 'al' AND `refid` = '$id'"),
  78. 0);
  79. if ($total) {
  80. $req = mysql_query("SELECT * FROM `gallery` WHERE `type` = 'al' AND `refid` = '$id' ORDER BY `time` DESC LIMIT $start, $kmess");
  81. while ($res = mysql_fetch_assoc($req)) {
  82. echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
  83. $total_f = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `type` = 'ft' AND `refid` = '" . $res['id'] . "'"),
  84. 0);
  85. echo '<a href="index.php?id=' . $res['id'] . '">' . $res['text'] . '</a> (' . $total_f . ')</div>';
  86. ++$i;
  87. }
  88. } else {
  89. echo '<div class="menu"><p>' . $lng['list_empty'] . '</p></div>';
  90. }
  91. echo '<div class="phdr"><i class="fa fa-spinner" style="color:#ffffff;"></i> ' . $lng['total'] . ': ' . $total . '</div><p>';
  92. if ($total > $kmess) {
  93. echo '<p>' . functions::display_pagination('index.php?id=' . $id . '&amp;', $start, $total,
  94. $kmess) . '</p>' .
  95. '<p><form action="index.php?id=' . $id . '" method="post">' .
  96. '<input type="text" name="page" size="2"/>' .
  97. '<input type="submit" value="' . $lng['to_page'] . ' &gt;&gt;"/>' .
  98. '</form></p>';
  99. }
  100. if ($rights >= 6) {
  101. echo "<div class='menu'><i class='fa fa-plus-square' style='color:red;'></i> <a href='index.php?act=cral&amp;id=" . $id . "'>" . $lng_gal['create_album'] . "</a><br/>";
  102.  
  103.  
  104.  
  105. echo "<i class='fa fa-trash-o' style='color:red;'></i> <a href='index.php?act=del&amp;id=" . $id . "'>" . $lng_gal['delete_section'] . "</a><br/>";
  106. echo "<i class='fa fa-wrench' style='color:red;'></i> <a href='index.php?act=edit&amp;id=" . $id . "'>" . $lng_gal['edit_section'] . "</a><br/>";
  107. }
  108. echo "<i class='fa fa-share-square-o' style='color:red;'></i> <a href='index.php'>Galereya</a></p>";
  109. break;
  110.  
  111. case 'al':
  112. /*
  113.   -----------------------------------------------------------------
  114.   Просмотр альбома
  115.   -----------------------------------------------------------------
  116.   */
  117. $delimag = opendir("temp");
  118. while ($imd = readdir($delimag)) {
  119. if ($imd != "." && $imd != ".." && $imd != "index.php") {
  120. $im[] = $imd;
  121. }
  122. }
  123. closedir($delimag);
  124. $totalim = count($im);
  125. for ($imi = 0; $imi < $totalim; $imi++) {
  126. $filtime[$imi] = filemtime("temp/$im[$imi]");
  127. $tim = time();
  128. $ftime1 = $tim - 10;
  129. if ($filtime[$imi] < $ftime1) {
  130. }
  131. }
  132.  
  133. $rz = mysql_query("SELECT * FROM `gallery` WHERE type='rz' AND id='" . $ms['refid'] . "';");
  134. $rz1 = mysql_fetch_array($rz);
  135. echo '<div class="phdr"><i class="fa fa-picture-o" style="color:#ffffff;"></i> <a href="index.php"><b>' . $lng['gallery'] . '</b></a> | <a href="index.php?id=' . $ms['refid'] . '">' . $rz1['text'] . '</a> | ' . $ms['text'] . '</div>';
  136. $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `type` = 'ft' AND `refid` = '$id'"),
  137. 0);
  138. $req = mysql_query("SELECT * FROM `gallery` WHERE `type` = 'ft' AND `refid` = '$id' ORDER BY `time` DESC LIMIT $start, $kmess");
  139. while ($fot1 = mysql_fetch_array($req)) {
  140. echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
  141. if (file_exists('foto/' . $fot1['name'])) {
  142. echo '<a href="index.php?id=' . $fot1['id'] . '">';
  143. $infile = "foto/$fot1[name]";
  144. if (!empty($_SESSION['frazm'])) {
  145. $razm = $_SESSION['frazm'];
  146. } else {
  147. $razm = 100;
  148. }
  149. $sizs = GetImageSize($infile);
  150. $width = $sizs[0];
  151. $height = $sizs[1];
  152. $quality = 80;
  153. $x_ratio = $razm / $width;
  154. $y_ratio = $razm / $height;
  155. if (($width <= $razm) && ($height <= $razm)) {
  156. $tn_width = $width;
  157. $tn_height = $height;
  158. } else {
  159. if (($x_ratio * $height) < $razm) {
  160. $tn_height = ceil($x_ratio * $height);
  161. $tn_width = $razm;
  162. } else {
  163. $tn_width = ceil($y_ratio * $width);
  164. $tn_height = $razm;
  165. }
  166. }
  167. $format = functions::format($infile);
  168. switch ($format) {
  169. case "gif":
  170. $im = ImageCreateFromGIF($infile);
  171. break;
  172.  
  173. case "jpg":
  174. case "jpeg":
  175. $im = ImageCreateFromJPEG($infile);
  176. break;
  177.  
  178. case "png":
  179. $im = ImageCreateFromPNG($infile);
  180. break;
  181. }
  182. $im1 = imagecreatetruecolor($tn_width, $tn_height);
  183. setTransparency($im1, $im);
  184. $namefile = "$fot1[name]";
  185. imagecopyresized($im1, $im, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
  186. switch ($format) {
  187. case "gif":
  188. $imagnam = "temp/$namefile.temp.gif";
  189. ImageGif($im1, $imagnam);
  190. echo "<img src='" . $imagnam . "' alt=''/><br/>";
  191. break;
  192.  
  193. case "jpg":
  194. case "jpeg":
  195. $imagnam = "temp/$namefile.temp.jpg";
  196. imageJpeg($im1, $imagnam, 75);
  197. echo "<img src='" . $imagnam . "' alt=''/><br/>";
  198. break;
  199.  
  200. case "png":
  201. $imagnam = "temp/$namefile.temp.png";
  202. imagePng($im1, $imagnam, 5);
  203. echo "<img src='" . $imagnam . "' alt=''/><br/>";
  204.  
  205. break;
  206. }
  207. imagedestroy($im1);
  208. $fotsz = filesize("foto/$ms[name]");
  209. echo '</a>';
  210. if (!empty($fot1['text'])) {
  211. echo "$fot1[text]<br/>";
  212. }
  213. if ($rights >= 6) {
  214. echo "<a href='index.php?act=edf&amp;id=" . $fot1['id'] . "'>" . $lng['edit'] . "</a> | <a href='index.php?act=delf&amp;id=" . $fot1['id'] . "'>" . $lng['delete'] . "</a><br/>";
  215. }
  216. } else {
  217. echo $lng_gal['image_missing'] . '<br /><a href="index.php?act=delf&amp;id=' . $fot1['id'] . '">' . $lng['delete'] . '</a>';
  218. }
  219. echo "</div>";
  220. ++$i;
  221. }
  222. echo '<div class="phdr"><i class="fa fa-spinner" style="color:#ffffff;"></i> ' . $lng['total'] . ': ' . $total . '</div><p>';
  223. if ($total > $kmess) {
  224. echo '<p>' . functions::display_pagination('index.php?id=' . $id . '&amp;', $start, $total,
  225. $kmess) . '</p>' .
  226. '<p><form action="index.php?id=' . $id . '" method="post">' .
  227. '<input type="text" name="page" size="2"/>' .
  228. '<input type="submit" value="' . $lng['to_page'] . ' &gt;&gt;"/>' .
  229. '</form></p>';
  230. }
  231. if (($user_id && $rz1['user'] == 1 && $ms['text'] == $login && !$ban['1'] && !$ban['14']) || $rights >= 6) {
  232. echo '<div class="menu"><i class="fa fa-download" style="color:red;"></i> <a href="index.php?act=upl&amp;id=' . $id . '">' . $lng_gal['upload_photo'] . '</a><br/>';
  233. }
  234. if ($rights >= 6) {
  235. echo "<i class='fa fa-trash' style='color:red;'></i> <a href='index.php?act=del&amp;id=" . $id . "'>" . $lng_gal['delete_album'] . "</a><br/>";
  236. echo "<i class='fa fa-pencil' style='color:red;'></i> <a href='index.php?act=edit&amp;id=" . $id . "'>" . $lng_gal['edit_album'] . "</a><br/>";
  237. }
  238. echo "<i class='fa fa-share-square-o' style='color:red;'></i> <a href='index.php'>" . $lng_gal['to_gallery'] . "</a></p>";
  239. break;
  240.  
  241. case 'ft':
  242. /*
  243.   -----------------------------------------------------------------
  244.   Просмотр фото
  245.   -----------------------------------------------------------------
  246.   */
  247. echo "<br/>&#160;";
  248. $infile = "foto/$ms[name]";
  249. if (!empty($_SESSION['frazm'])) {
  250. $razm = $_SESSION['frazm'];
  251. } else {
  252. $razm = 50;
  253. }
  254. $sizs = GetImageSize($infile);
  255. $width = $sizs[0];
  256. $height = $sizs[1];
  257. $format = functions::format($infile);
  258. switch ($format) {
  259. case "gif":
  260. $im = ImageCreateFromGIF($infile);
  261. break;
  262.  
  263. case "jpg":
  264. $im = ImageCreateFromJPEG($infile);
  265. break;
  266.  
  267. case "jpeg":
  268. $im = ImageCreateFromJPEG($infile);
  269. break;
  270.  
  271. case "png":
  272. $im = ImageCreateFromPNG($infile);
  273. break;
  274. }
  275. $im1 = imagecreatetruecolor($width, $height);
  276. setTransparency($im1, $im);
  277. $namefile = "$ms[name]";
  278. imagecopy($im1, $im, 0, 0, 0, 0, $width, $height);
  279. switch ($format) {
  280. case "gif":
  281. $imagnam = "temp/$namefile.gif";
  282. imagegif($im1, $imagnam);
  283. echo "<img src='" . $imagnam . "' alt=''/><br/>";
  284. break;
  285.  
  286. case "jpg":
  287. case "jpeg":
  288. $imagnam = "temp/$namefile.jpg";
  289. imagejpeg($im1, $imagnam, 75);
  290. echo "<img src='" . $imagnam . "' alt=''/><br/>";
  291. break;
  292.  
  293. case "png":
  294. $imagnam = "temp/$namefile.png";
  295. imagePng($im1, $imagnam, 5);
  296. echo "<img src='" . $imagnam . "' alt=''/><br/>";
  297.  
  298. break;
  299. }
  300. imagedestroy($im1);
  301. $fotsz = filesize("foto/$ms[name]");
  302. $fotsz = round($fotsz / 1024, 2);
  303. $sizs = GetImageSize("foto/$ms[name]");
  304. $fwidth = $sizs[0];
  305. $fheight = $sizs[1];
  306. echo "<p>" . $lng['description'] . ": $ms[text]<br/>";
  307. echo $lng_gal['dimensions'] . ": $fwidth*$fheight пкс.<br/>";
  308. echo $lng_gal['weight'] . ": $fotsz кб.<br/>";
  309. echo $lng['date'] . ': ' . functions::display_date($ms['time']) . '<br/>';
  310. echo $lng_gal['posted_by'] . ": $ms[avtor]<br/>";
  311. echo "<a href='foto/$ms[name]'>" . $lng['download'] . "</a><br /><br />";
  312. echo "<a href='index.php?id=" . $ms['refid'] . "'>" . $lng['back'] . "</a><br/>";
  313. echo "<a href='index.php'>" . $lng_gal['to_gallery'] . "</a></p>";
  314. break;
  315. default :
  316. header("location: index.php");
  317. break;
  318. }
  319. } else {
  320. /*
  321.   -----------------------------------------------------------------
  322.   Главная страница Галлереи
  323.   -----------------------------------------------------------------
  324.   */
  325. echo '<p><a href="index.php?act=new">' . $lng_gal['new_photo'] . '</a> (' . counters::gallery(1) . ')</p>';
  326. echo '<div class="phdr"><i class="fa fa-image" style="color:#ffffff;"></i> <b>' . $lng['gallery'] . '</b></div>';
  327. $req = mysql_query("SELECT * FROM `gallery` WHERE `type` = 'rz'");
  328. $total = mysql_num_rows($req);
  329. while ($res = mysql_fetch_assoc($req)) {
  330. echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
  331. $al = mysql_query("SELECT * FROM `gallery` WHERE type='al' AND refid='" . $res['id'] . "'");
  332. $countal = mysql_num_rows($al);
  333. echo '<a href="index.php?id=' . $res['id'] . '">' . $res['text'] . '</a> (' . $countal . ')</div>';
  334. ++$i;
  335. }
  336. echo '<div class="phdr"><i class="fa fa-spinner" style="color:#ffffff;"></i> ' . $lng['total'] . ': ' . $total . '</div><p>';
  337. if ($rights >= 6) {
  338. echo "<div class='menu'><i class='fa fa-plus-square' style='color:red;'></i> <a href='index.php?act=razd'>" . $lng_gal['create_section'] . "</a><br/>";
  339. }
  340. echo "</p>";
  341. }
  342. }
  343.  
  344. require('../incfiles/end.php');
  345. ?>



Shunda rasmlarga qanday o'lcham qo'ysa bo'ladi? Width va height qo'yish kerak