PageRenderTime 31ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Portal_XL50_Premod-3.0.8/phpBB3/gallery/posting.php

https://github.com/Lucky65/phpBB-Portal-XL-5.0-italian
PHP | 1439 lines | 1287 code | 118 blank | 34 comment | 282 complexity | 89524dfe9d65a33d401b10c6ee253cf9 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package phpBB Gallery
  5. * @version $Id$
  6. * @copyright (c) 2007 nickvergessen nickvergessen@gmx.de http://www.flying-bits.org
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = $gallery_root_path = '';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . $gallery_root_path . 'includes/root_path.' . $phpEx);
  17. include($phpbb_root_path . 'common.' . $phpEx);
  18. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  19. include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  20. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  21. include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  22. // Start session management
  23. $user->session_begin();
  24. $auth->acl($user->data);
  25. $user->setup(array('mods/gallery', 'posting'));
  26. $gallery_root_path = GALLERY_ROOT_PATH;
  27. include($phpbb_root_path . $gallery_root_path . 'includes/common.' . $phpEx);
  28. include($phpbb_root_path . $gallery_root_path . 'includes/permissions.' . $phpEx);
  29. include($phpbb_root_path . $gallery_root_path . 'includes/functions_display.' . $phpEx);
  30. include($phpbb_root_path . $gallery_root_path . 'includes/functions_posting.' . $phpEx);
  31. add_form_key('gallery');
  32. $submit = (isset($_POST['submit'])) ? true : false;
  33. $mode = request_var('mode', '');
  34. $submode = request_var('submode', '');
  35. $album_id = request_var('album_id', 0);
  36. $image_id = request_var('image_id', 0);
  37. $comment_id = request_var('comment_id', 0);
  38. $error = $message = $s_album_action = '';
  39. $error_count = array();
  40. $slower_redirect = false;
  41. // Check for permissions cheaters!
  42. if ($comment_id)
  43. {
  44. $sql = 'SELECT *
  45. FROM ' . GALLERY_COMMENTS_TABLE . '
  46. WHERE comment_id = ' . $comment_id;
  47. $result = $db->sql_query($sql);
  48. $comment_data = $db->sql_fetchrow($result);
  49. $db->sql_freeresult($result);
  50. $image_id = $comment_data['comment_image_id'];
  51. }
  52. if ($image_id)
  53. {
  54. $image_data = get_image_info($image_id);
  55. $album_id = $image_data['image_album_id'];
  56. }
  57. $album_data = get_album_info($album_id);
  58. generate_album_nav($album_data);
  59. if ($image_id)
  60. {
  61. $image_backlink = append_sid("{$phpbb_root_path}{$gallery_root_path}image_page.$phpEx", "album_id=$album_id&amp;image_id=$image_id");
  62. $image_loginlink = append_sid("{$gallery_root_path}image_page.$phpEx", "album_id=$album_id&amp;image_id=$image_id");
  63. }
  64. if ($album_id)
  65. {
  66. $album_backlink = append_sid("{$phpbb_root_path}{$gallery_root_path}album.$phpEx", "album_id=$album_id");
  67. $album_loginlink = append_sid("{$gallery_root_path}album.$phpEx", "album_id=$album_id");
  68. }
  69. $index_backlink = append_sid("{$phpbb_root_path}{$gallery_root_path}index.$phpEx");
  70. // Send some cheaters back
  71. if ($user->data['is_bot'])
  72. {
  73. redirect(($image_id) ? $image_backlink : $album_backlink);
  74. }
  75. if ($album_data['album_type'] == ALBUM_CAT)
  76. {
  77. meta_refresh(3, $album_backlink);
  78. trigger_error('ALBUM_IS_CATEGORY');
  79. }
  80. switch ($mode)
  81. {
  82. case 'album':
  83. switch ($submode)
  84. {
  85. case 'watch':
  86. case 'unwatch':
  87. if (!gallery_acl_check('i_view', $album_id, $album_data['album_user_id']))
  88. {
  89. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  90. }
  91. break;
  92. default:
  93. trigger_error('MISSING_SUBMODE');
  94. break;
  95. }
  96. break;
  97. case 'image':
  98. if (!gallery_acl_check('m_status', $album_id, $album_data['album_user_id']) && ($album_data['album_status'] == ITEM_LOCKED))
  99. {
  100. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  101. }
  102. if ($image_id && (!gallery_acl_check('m_status', $album_id, $album_data['album_user_id']) && ($image_data['image_status'] != IMAGE_APPROVED)))
  103. {
  104. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  105. }
  106. switch ($submode)
  107. {
  108. case 'upload':
  109. if (!gallery_acl_check('i_upload', $album_id, $album_data['album_user_id']) || ($album_data['album_status'] == ITEM_LOCKED))
  110. {
  111. gallery_not_authorised($album_backlink, $user, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD');
  112. }
  113. if ($album_data['contest_id'] && (time() < $album_data['contest_start']))
  114. {
  115. gallery_not_authorised($album_backlink, $user, $album_loginlink);
  116. }
  117. elseif ($album_data['contest_id'] && (time() > ($album_data['contest_start'] + $album_data['contest_rating'])))
  118. {
  119. gallery_not_authorised($album_backlink, $user, $album_loginlink);
  120. }
  121. break;
  122. case 'edit':
  123. if (!gallery_acl_check('i_edit', $album_id, $album_data['album_user_id']))
  124. {
  125. if (!gallery_acl_check('m_edit', $album_id, $album_data['album_user_id']))
  126. {
  127. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  128. }
  129. }
  130. else if (($image_data['image_user_id'] != $user->data['user_id']) && !gallery_acl_check('m_edit', $album_id, $album_data['album_user_id']))
  131. {
  132. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  133. }
  134. break;
  135. case 'report':
  136. if (!gallery_acl_check('i_report', $album_id, $album_data['album_user_id']) || ($image_data['image_user_id'] == $user->data['user_id']))
  137. {
  138. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  139. }
  140. break;
  141. case 'delete':
  142. if (!gallery_acl_check('i_delete', $album_id, $album_data['album_user_id']))
  143. {
  144. if (!gallery_acl_check('m_delete', $album_id, $album_data['album_user_id']))
  145. {
  146. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  147. }
  148. }
  149. else if (($image_data['image_user_id'] != $user->data['user_id']) && !gallery_acl_check('m_delete', $album_id, $album_data['album_user_id']))
  150. {
  151. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  152. }
  153. break;
  154. case 'watch':
  155. case 'unwatch':
  156. case 'favorite':
  157. case 'unfavorite':
  158. if (!gallery_acl_check('i_view', $album_id, $album_data['album_user_id']))
  159. {
  160. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  161. }
  162. break;
  163. default:
  164. trigger_error('MISSING_SUBMODE');
  165. break;
  166. }
  167. break;
  168. case 'comment':
  169. if (!gallery_acl_check('m_status', $album_id, $album_data['album_user_id']) && (($image_data['image_status'] != IMAGE_APPROVED) || ($album_data['album_status'] == ITEM_LOCKED)))
  170. {
  171. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  172. }
  173. if (($submode != 'rate') && (!$gallery_config['allow_comments']))
  174. {
  175. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  176. }
  177. if (((!$submit || !$gallery_config['allow_rates'])) && ($submode == 'rate'))
  178. {
  179. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  180. }
  181. if ($submode == 'rate')
  182. {
  183. if (time() < ($album_data['contest_start'] + $album_data['contest_rating']))
  184. {
  185. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  186. }
  187. }
  188. else
  189. {
  190. if (time() < ($album_data['contest_start'] + $album_data['contest_end']))
  191. {
  192. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  193. }
  194. }
  195. switch ($submode)
  196. {
  197. case 'add':
  198. if (!gallery_acl_check('c_post', $album_id, $album_data['album_user_id']))
  199. {
  200. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  201. }
  202. break;
  203. case 'edit':
  204. if (!gallery_acl_check('c_edit', $album_id, $album_data['album_user_id']))
  205. {
  206. if (!gallery_acl_check('m_comments', $album_id, $album_data['album_user_id']))
  207. {
  208. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  209. }
  210. }
  211. else if (($comment_data['comment_user_id'] != $user->data['user_id']) && !gallery_acl_check('m_comments', $album_id, $album_data['album_user_id']))
  212. {
  213. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  214. }
  215. break;
  216. case 'delete':
  217. if (!gallery_acl_check('c_delete', $album_id, $album_data['album_user_id']))
  218. {
  219. if (!gallery_acl_check('m_comments', $album_id, $album_data['album_user_id']))
  220. {
  221. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  222. }
  223. }
  224. else if (($comment_data['comment_user_id'] != $user->data['user_id']) && !gallery_acl_check('m_comments', $album_id, $album_data['album_user_id']))
  225. {
  226. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  227. }
  228. break;
  229. case 'rate':
  230. if (!gallery_acl_check('i_rate', $album_id, $album_data['album_user_id']) || ($image_data['image_user_id'] == $user->data['user_id']))
  231. {
  232. gallery_not_authorised($image_backlink, $user, $image_loginlink);
  233. }
  234. break;
  235. default:
  236. trigger_error('MISSING_SUBMODE');
  237. break;
  238. }
  239. break;
  240. default:
  241. trigger_error('MISSING_MODE');
  242. break;
  243. }
  244. function gallery_not_authorised($backlink, $user, $loginlink, $login_explain = '')
  245. {
  246. if (!$user->data['is_registered'])
  247. {
  248. if ($login_explain && isset($user->lang[$login_explain]))
  249. {
  250. $login_explain = $user->lang[$login_explain];
  251. }
  252. else
  253. {
  254. $login_explain = '';
  255. }
  256. login_box($loginlink, $login_explain);
  257. }
  258. else
  259. {
  260. meta_refresh(3, $backlink);
  261. trigger_error('NOT_AUTHORISED');
  262. }
  263. }
  264. $bbcode_status = ($config['allow_bbcode']) ? true : false;
  265. $smilies_status = ($config['allow_smilies']) ? true : false;
  266. $img_status = ($bbcode_status) ? true : false;
  267. $url_status = ($config['allow_post_links']) ? true : false;
  268. $flash_status = false;
  269. $quote_status = true;
  270. $template->assign_vars(array(
  271. 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
  272. 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
  273. 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
  274. 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
  275. 'URL_STATUS' => ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
  276. 'S_BBCODE_ALLOWED' => $bbcode_status,
  277. 'S_SMILIES_ALLOWED' => $smilies_status,
  278. 'S_LINKS_ALLOWED' => $url_status,
  279. 'S_BBCODE_IMG' => $img_status,
  280. 'S_BBCODE_URL' => $url_status,
  281. 'S_BBCODE_FLASH' => $flash_status,
  282. 'S_BBCODE_QUOTE' => $quote_status,
  283. ));
  284. // Build custom bbcodes array
  285. display_custom_bbcodes();
  286. // Build smilies array
  287. generate_smilies('inline', 0);
  288. switch ($mode)
  289. {
  290. case 'album':
  291. if ($mode == 'album')
  292. {
  293. switch ($submode)
  294. {
  295. case 'watch':
  296. if ($submode == 'watch')
  297. {
  298. $sql_ary = array(
  299. 'album_id' => $album_id,
  300. 'user_id' => $user->data['user_id'],
  301. );
  302. $sql = 'INSERT INTO ' . GALLERY_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  303. $db->sql_query($sql);
  304. $message = $user->lang['WATCHING_ALBUM'] . '<br />';
  305. $submit = true; // For redirect
  306. }
  307. break;
  308. case 'unwatch':
  309. if ($submode == 'unwatch')
  310. {
  311. $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . '
  312. WHERE album_id = ' . (int) $album_id . '
  313. AND user_id = ' . $user->data['user_id'];
  314. $db->sql_query($sql);
  315. $message = $user->lang['UNWATCHED_ALBUM'] . '<br />';
  316. $submit = true; // For redirect
  317. }
  318. break;
  319. }
  320. }
  321. break;
  322. case 'image':
  323. if ($mode == 'image')
  324. {
  325. switch ($submode)
  326. {
  327. case 'upload':
  328. if ($submode == 'upload')
  329. {
  330. // Upload Quota Check
  331. // 1. Check album-configuration Quota
  332. if ($gallery_config['images_per_album'] >= 0)
  333. {
  334. if ($album_data['album_images'] >= $gallery_config['images_per_album'])
  335. {
  336. trigger_error('ALBUM_REACHED_QUOTA');
  337. }
  338. }
  339. // 2. Check user-limit, if he is not allowed to go unlimited
  340. if (!gallery_acl_check('i_unlimited', $album_id, $album_data['album_user_id']))
  341. {
  342. $sql = 'SELECT COUNT(image_id) count
  343. FROM ' . GALLERY_IMAGES_TABLE . '
  344. WHERE image_user_id = ' . $user->data['user_id'] . '
  345. AND image_album_id = ' . $album_id;
  346. $result = $db->sql_query($sql);
  347. $own_images = (int) $db->sql_fetchfield('count');
  348. $db->sql_freeresult($result);
  349. if ($own_images >= gallery_acl_check('i_count', $album_id, $album_data['album_user_id']))
  350. {
  351. trigger_error(sprintf($user->lang['USER_REACHED_QUOTA'], gallery_acl_check('i_count', $album_id, $album_data['album_user_id'])));
  352. }
  353. }
  354. if (gallery_display_captcha('upload'))
  355. {
  356. include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
  357. $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
  358. $captcha->init(CONFIRM_POST);
  359. $s_captcha_hidden_fields = '';
  360. }
  361. $images = 0;
  362. if($submit)
  363. {
  364. if (!check_form_key('gallery'))
  365. {
  366. trigger_error('FORM_INVALID');
  367. }
  368. if (gallery_display_captcha('upload'))
  369. {
  370. $captcha_error = $captcha->validate();
  371. if ($captcha_error)
  372. {
  373. trigger_error($captcha_error);
  374. }
  375. }
  376. $allowed_extensions = array();
  377. if ($gallery_config['jpg_allowed'])
  378. {
  379. $allowed_extensions[] = 'jpg';
  380. $allowed_extensions[] = 'jpeg';
  381. }
  382. if ($gallery_config['gif_allowed'])
  383. {
  384. $allowed_extensions[] = 'gif';
  385. }
  386. if ($gallery_config['png_allowed'])
  387. {
  388. $allowed_extensions[] = 'png';
  389. }
  390. if (!class_exists('fileupload'))
  391. {
  392. include($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
  393. }
  394. $fileupload = new fileupload();
  395. $fileupload->fileupload('', $allowed_extensions, (4 * $gallery_config['max_file_size']));
  396. $upload_image_files = (gallery_acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) ? $gallery_config['upload_images'] : min((gallery_acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images), $gallery_config['upload_images']);
  397. // Get File Upload Info
  398. $image_id_ary = array();
  399. $loop = request_var('image_num', 0);
  400. $rotate = request_var('rotate', array(0));
  401. $loop = ($loop != 0) ? $loop - 1 : $loop;
  402. for ($i = 0; $i < $upload_image_files; $i++)
  403. {
  404. $image_file = $fileupload->form_upload('image_file_' . $i);
  405. if (!$image_file->uploadname)
  406. {
  407. continue;
  408. }
  409. $image_file->clean_filename('unique_ext'/*, $user->data['user_id'] . '_'*/);
  410. $image_file->move_file(substr(GALLERY_UPLOAD_PATH, 0, -1), false, false, CHMOD_ALL);
  411. if (sizeof($image_file->error) && $image_file->uploadname)
  412. {
  413. $image_file->remove();
  414. trigger_error(implode('<br />', $image_file->error));
  415. }
  416. @chmod($image_file->destination_file, 0777);
  417. $image_data = array();
  418. if (1 == 1)
  419. {
  420. $loop = $loop + 1;
  421. $images = $images + 1;
  422. switch ($image_file->mimetype)
  423. {
  424. case 'image/jpeg':
  425. case 'image/jpg':
  426. case 'image/pjpeg':
  427. $image_type = 'jpg';
  428. break;
  429. case 'image/png':
  430. case 'image/x-png':
  431. $image_type = 'png';
  432. break;
  433. case 'image/gif':
  434. case 'image/giff':
  435. $image_type = 'gif';
  436. break;
  437. }
  438. $image_data = array(
  439. 'filename' => $image_file->realname,
  440. 'image_album_id' => $album_data['album_id'],
  441. 'image_album_name' => $album_data['album_name'],
  442. 'image_name' => str_replace('{NUM}', $loop, request_var('image_name', '', true)),
  443. 'image_desc' => str_replace('{NUM}', $loop, request_var('message', '', true)),
  444. 'image_time' => time() + $loop,
  445. 'image_contest' => ($album_data['album_contest']) ? IMAGE_CONTEST : IMAGE_NO_CONTEST,
  446. 'thumbnail' => '',
  447. 'username' => request_var('username', $user->data['username']),
  448. );
  449. $image_data['image_name'] = ((request_var('filename', '') == 'filename') || ($image_data['image_name'] == '')) ? str_replace("_", " ", utf8_substr($image_file->uploadname, 0, utf8_strrpos($image_file->uploadname, '.'))) : $image_data['image_name'];
  450. if (!$image_data['image_name'])
  451. {
  452. trigger_error('MISSING_IMAGE_NAME');
  453. }
  454. if (!$user->data['is_registered'] && $image_data['username'])
  455. {
  456. if (validate_username($image_data['username']))
  457. {
  458. trigger_error('INVALID_USERNAME');
  459. }
  460. }
  461. if (!class_exists('nv_image_tools'))
  462. {
  463. include($phpbb_root_path . $gallery_root_path . 'includes/functions_image.' . $phpEx);
  464. }
  465. $image_tools = new nv_image_tools();
  466. $image_tools->set_image_options($gallery_config['max_file_size'], $gallery_config['max_height'], $gallery_config['max_width']);
  467. $image_tools->set_image_data($image_file->destination_file, $image_data['image_name'], $image_file->filesize);
  468. // Read exif data from file
  469. $image_tools->read_exif_data();
  470. $image_data['image_exif_data'] = $image_tools->exif_data_serialized;
  471. $image_data['image_has_exif'] = $image_tools->exif_data_exist;
  472. /// Rotate the image
  473. if ($gallery_config['allow_rotate_images'])
  474. {
  475. $image_tools->rotate_image($rotate[$i], $gallery_config['allow_resize_images']);
  476. if ($image_tools->rotated)
  477. {
  478. $image_file->height = $image_tools->image_size['height'];
  479. $image_file->width = $image_tools->image_size['width'];
  480. }
  481. }
  482. // Resize overside images
  483. if (($image_file->width > $gallery_config['max_width']) || ($image_file->height > $gallery_config['max_height']))
  484. {
  485. if ($gallery_config['allow_resize_images'])
  486. {
  487. $image_tools->resize_image($gallery_config['max_width'], $gallery_config['max_height']);
  488. if ($image_tools->resized)
  489. {
  490. $image_file->height = $image_tools->image_size['height'];
  491. $image_file->width = $image_tools->image_size['width'];
  492. }
  493. }
  494. else
  495. {
  496. @unlink($image_file->destination_file);
  497. trigger_error('UPLOAD_IMAGE_SIZE_TOO_BIG');
  498. }
  499. }
  500. if ($image_tools->resized || $image_tools->rotated)
  501. {
  502. $image_tools->write_image($image_file->destination_file, $gallery_config['jpg_quality'], true);
  503. $image_file->filesize = $image_tools->image_size['file'];
  504. }
  505. if (!$image_tools->exif_data_force_db && ($image_data['image_has_exif'] == EXIF_DBSAVED))
  506. {
  507. // Image was not resized, so we can pull the Exif from the image to save db-memory.
  508. $image_data['image_has_exif'] = EXIF_AVAILABLE;
  509. $image_data['image_exif_data'] = '';
  510. }
  511. $image_data['image_filesize'] = $image_file->filesize;
  512. if ($image_data['image_filesize'] > (1.2 * $gallery_config['max_file_size']))
  513. {
  514. @unlink($image_file->destination_file);
  515. trigger_error('BAD_UPLOAD_FILE_SIZE');
  516. }
  517. $image_data = upload_image($image_data);
  518. $image_id = $image_data['image_id'];
  519. $image_name = $image_data['image_name'];
  520. $image_id_ary[] = $image_id;
  521. }
  522. }
  523. $image_id = ($images > 1) ? 0 : $image_id;
  524. // Complete... now send a message to user
  525. if ($images < 1)
  526. {
  527. $error .= (($error) ? '<br />' : '') . $user->lang['UPLOAD_NO_FILE'];
  528. }
  529. else
  530. {
  531. gallery_notification('album', $album_id, $image_name);
  532. handle_image_counter($image_id_ary, true);
  533. $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "
  534. SET album_images_real = album_images_real + $images
  535. WHERE album_id = $album_id";
  536. $db->sql_query($sql);
  537. }
  538. if (gallery_display_captcha('upload'))
  539. {
  540. $captcha->reset();
  541. }
  542. }
  543. $allowed_filetypes = array();
  544. if ($gallery_config['gif_allowed'])
  545. {
  546. $allowed_filetypes[] = $user->lang['FILETYPES_GIF'];
  547. }
  548. if ($gallery_config['jpg_allowed'])
  549. {
  550. $allowed_filetypes[] = $user->lang['FILETYPES_JPG'];
  551. }
  552. if ($gallery_config['png_allowed'])
  553. {
  554. $allowed_filetypes[] = $user->lang['FILETYPES_PNG'];
  555. }
  556. $template->assign_vars(array(
  557. 'ERROR' => $error,
  558. 'U_VIEW_ALBUM' => append_sid("{$phpbb_root_path}{$gallery_root_path}album.$phpEx", "album_id=$album_id"),
  559. 'CAT_TITLE' => $album_data['album_name'],
  560. 'S_MAX_FILESIZE' => $gallery_config['max_file_size'],
  561. 'S_MAX_WIDTH' => $gallery_config['max_width'],
  562. 'S_MAX_HEIGHT' => $gallery_config['max_height'],
  563. 'S_ALLOWED_FILETYPES' => implode(', ', $allowed_filetypes),
  564. 'S_THUMBNAIL_SIZE' => $gallery_config['thumbnail_size'],//@todo
  565. 'S_THUMBNAIL' => ($gallery_config['gd_version']) ? true : false,//@todo
  566. 'S_MULTI_IMAGES' => ($gallery_config['upload_images'] > 1) ? true : false,
  567. 'S_ALBUM_ACTION' => append_sid("{$phpbb_root_path}{$gallery_root_path}posting.$phpEx", "mode=image&amp;submode=upload&amp;album_id=$album_id"),
  568. 'IMAGE_RSZ_WIDTH' => $gallery_config['preview_rsz_width'],
  569. 'IMAGE_RSZ_HEIGHT' => $gallery_config['preview_rsz_height'],
  570. 'L_DESCRIPTION_LENGTH' => sprintf($user->lang['DESCRIPTION_LENGTH'], $gallery_config['description_length']),
  571. 'USERNAME' => request_var('username', '', true),
  572. 'IMAGE_NAME' => request_var('image_name', '', true),
  573. 'MESSAGE' => request_var('message', '', true),
  574. 'S_IMAGE' => true,
  575. 'S_UPLOAD' => true,
  576. 'S_ALLOW_ROTATE' => ($gallery_config['allow_rotate_images'] && function_exists('imagerotate')),
  577. ));
  578. if (gallery_display_captcha('upload'))
  579. {
  580. if (!$submit || !$captcha->is_solved())
  581. {
  582. $template->assign_vars(array(
  583. 'S_CONFIRM_CODE' => true,
  584. 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
  585. ));
  586. }
  587. $template->assign_vars(array(
  588. 'S_CAPTCHA_HIDDEN_FIELDS' => $s_captcha_hidden_fields,
  589. ));
  590. }
  591. if (!$error)
  592. {
  593. if (gallery_acl_check('i_approve', $album_id, $album_data['album_user_id']))
  594. {
  595. $message = $user->lang['ALBUM_UPLOAD_SUCCESSFUL'];
  596. }
  597. else
  598. {
  599. $message = $user->lang['ALBUM_UPLOAD_NEED_APPROVAL'];
  600. $slower_redirect = true;
  601. $image_id = false;
  602. }
  603. }
  604. else
  605. {
  606. $submit = false;
  607. $message = $user->lang['UPLOAD_NO_FILE'];
  608. }
  609. $count = 0;
  610. $upload_image_files = $gallery_config['upload_images'];
  611. if (!gallery_acl_check('i_unlimited', $album_id, $album_data['album_user_id']) && ((gallery_acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images) < $upload_image_files))
  612. {
  613. $upload_image_files = (gallery_acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images);
  614. $error .= (($error) ? '<br />' : '') . sprintf($user->lang['USER_NEARLY_REACHED_QUOTA'], gallery_acl_check('i_count', $album_id, $album_data['album_user_id']), $own_images, $upload_image_files);
  615. $template->assign_vars(array(
  616. 'ERROR' => $error,
  617. ));
  618. }
  619. while ($count < $upload_image_files)
  620. {
  621. $template->assign_block_vars('upload_image', array());
  622. $count++;
  623. }
  624. $message .= '<br />';
  625. update_album_info($album_id);
  626. $page_title = $user->lang['UPLOAD_IMAGE'];
  627. }
  628. break;
  629. case 'edit':
  630. if ($submode == 'edit')
  631. {
  632. if ($submit)
  633. {
  634. if (!check_form_key('gallery'))
  635. {
  636. trigger_error('FORM_INVALID');
  637. }
  638. $image_desc = request_var('message', '', true);
  639. $image_name = request_var('image_name', '', true);
  640. if (empty($image_name))
  641. {
  642. trigger_error('MISSING_IMAGE_NAME');
  643. }
  644. $message_parser = new parse_message();
  645. $message_parser->message = utf8_normalize_nfc($image_desc);
  646. if ($message_parser->message)
  647. {
  648. $message_parser->parse(true, true, true, true, false, true, true, true);
  649. }
  650. $sql_ary = array(
  651. 'image_name' => $image_name,
  652. 'image_name_clean' => utf8_clean_string($image_name),
  653. 'image_desc' => $message_parser->message,
  654. 'image_desc_uid' => $message_parser->bbcode_uid,
  655. 'image_desc_bitfield' => $message_parser->bbcode_bitfield,
  656. );
  657. $move_to_personal = request_var('move_to_personal', 0);
  658. if ($move_to_personal)
  659. {
  660. $personal_album_id = 0;
  661. if ($user->data['user_id'] != $image_data['image_user_id'])
  662. {
  663. $sql = 'SELECT personal_album_id
  664. FROM ' . GALLERY_USERS_TABLE . '
  665. WHERE user_id = ' . $image_data['image_user_id'];
  666. $result = $db->sql_query($sql);
  667. $personal_album_id = (int) $db->sql_fetchfield('personal_album_id');
  668. $db->sql_freeresult($result);
  669. $user_entry_exists = ($db->sql_affectedrows()) ? true : false;
  670. // The User has no personal album, moderators can created that without the need of permissions
  671. if (!$personal_album_id)
  672. {
  673. $personal_album_id = generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], $user_entry_exists);
  674. }
  675. }
  676. else
  677. {
  678. $personal_album_id = $user->gallery['personal_album_id'];
  679. if (!$personal_album_id && gallery_acl_check('i_upload', OWN_GALLERY_PERMISSIONS))
  680. {
  681. $user_entry_exists = ($user->gallery['exists']) ? true : false;
  682. $personal_album_id = generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], $user_entry_exists);
  683. }
  684. }
  685. if ($personal_album_id)
  686. {
  687. $sql_ary['image_album_id'] = $personal_album_id;
  688. }
  689. }
  690. else if ($album_data['album_last_image_id'] == $image_id)
  691. {
  692. $album_sql_ary = array(
  693. 'album_last_image_name' => $image_name,
  694. );
  695. $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $album_sql_ary) . '
  696. WHERE ' . $db->sql_in_set('album_id', $image_data['image_album_id']);
  697. $db->sql_query($sql);
  698. }
  699. $rotate = request_var('rotate', 0);
  700. if ($gallery_config['allow_rotate_images'] && ($rotate > 0) && (($rotate % 90) == 0))
  701. {
  702. if (!class_exists('nv_image_tools'))
  703. {
  704. include($phpbb_root_path . $gallery_root_path . 'includes/functions_image.' . $phpEx);
  705. }
  706. $image_tools = new nv_image_tools();
  707. $image_tools->set_image_options($gallery_config['max_file_size'], $gallery_config['max_height'], $gallery_config['max_width']);
  708. $image_tools->set_image_data($phpbb_root_path . GALLERY_UPLOAD_PATH . $image_data['image_filename']);
  709. if (($image_data['image_has_exif'] != EXIF_UNAVAILABLE) && ($image_data['image_has_exif'] != EXIF_DBSAVED))
  710. {
  711. // Store exif-data to database if there are any and we didn't already do that.
  712. $image_tools->read_exif_data();
  713. $sql_ary['image_exif_data'] = $image_tools->exif_data_serialized;
  714. $sql_ary['image_has_exif'] = $image_tools->exif_data_exist;
  715. }
  716. // Rotate the image
  717. $image_tools->rotate_image($rotate, $gallery_config['allow_resize_images']);
  718. if ($image_tools->rotated)
  719. {
  720. $image_tools->write_image($image_tools->image_source, $gallery_config['jpg_quality'], true);
  721. }
  722. @unlink($phpbb_root_path . GALLERY_CACHE_PATH . $image_data['image_filename']);
  723. @unlink($phpbb_root_path . GALLERY_MEDIUM_PATH . $image_data['image_filename']);
  724. }
  725. $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
  726. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  727. WHERE image_id = ' . $image_id;
  728. $db->sql_query($sql);
  729. if ($move_to_personal && $personal_album_id)
  730. {
  731. update_album_info($album_data['album_id']);
  732. update_album_info($personal_album_id);
  733. }
  734. if ($user->data['user_id'] != $image_data['image_user_id'])
  735. {
  736. add_log('gallery', $image_data['image_album_id'], $image_id, 'LOG_GALLERY_EDITED', $image_name);
  737. }
  738. }
  739. $message_parser = new parse_message();
  740. $message_parser->message = $image_data['image_desc'];
  741. $message_parser->decode_message($image_data['image_desc_uid']);
  742. $template->assign_vars(array(
  743. 'IMAGE_NAME' => $image_data['image_name'],
  744. 'MESSAGE' => $message_parser->message,
  745. 'L_DESCRIPTION_LENGTH' => sprintf($user->lang['DESCRIPTION_LENGTH'], $gallery_config['description_length']),
  746. 'U_IMAGE' => ($image_id) ? append_sid("{$phpbb_root_path}{$gallery_root_path}image.$phpEx", "album_id=$album_id&amp;image_id=$image_id") : '',
  747. 'U_VIEW_IMAGE' => ($image_id) ? append_sid("{$phpbb_root_path}{$gallery_root_path}image_page.$phpEx", "album_id=$album_id&amp;image_id=$image_id") : '',
  748. 'IMAGE_RSZ_WIDTH' => $gallery_config['preview_rsz_width'],
  749. 'IMAGE_RSZ_HEIGHT' => $gallery_config['preview_rsz_height'],
  750. 'S_IMAGE' => true,
  751. 'S_EDIT' => true,
  752. 'S_ALLOW_ROTATE' => ($gallery_config['allow_rotate_images'] && function_exists('imagerotate')),
  753. 'S_MOVE_PERSONAL' => ((gallery_acl_check('i_upload', OWN_GALLERY_PERMISSIONS) || $user->gallery['personal_album_id']) || ($user->data['user_id'] != $image_data['image_user_id'])) ? true : false,
  754. 'S_MOVE_MODERATOR' => ($user->data['user_id'] != $image_data['image_user_id']) ? true : false,
  755. 'S_ALBUM_ACTION' => append_sid("{$phpbb_root_path}{$gallery_root_path}posting.$phpEx", "mode=image&amp;submode=edit&amp;album_id=$album_id&amp;image_id=$image_id"),
  756. ));
  757. $message = $user->lang['IMAGES_UPDATED_SUCCESSFULLY'] . '<br />';
  758. $page_title = $user->lang['EDIT_IMAGE'];
  759. }
  760. break;
  761. case 'report':
  762. if ($submode == 'report')
  763. {
  764. if ($submit)
  765. {
  766. if (!check_form_key('gallery'))
  767. {
  768. trigger_error('FORM_INVALID');
  769. }
  770. $report_message = request_var('message', '', true);
  771. $error = '';
  772. if ($report_message == '')
  773. {
  774. $error = $user->lang['MISSING_REPORT_REASON'];
  775. $submit = false;
  776. }
  777. $sql_ary = array(
  778. 'report_album_id' => $album_id,
  779. 'report_image_id' => $image_id,
  780. 'reporter_id' => $user->data['user_id'],
  781. 'report_note' => $report_message,
  782. 'report_time' => time(),
  783. 'report_status' => REPORT_OPEN,
  784. );
  785. if (!$error)
  786. {
  787. if ($image_data['image_reported'])
  788. {
  789. trigger_error('IMAGE_ALREADY_REPORTED');
  790. }
  791. $sql = 'INSERT INTO ' . GALLERY_REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  792. $db->sql_query($sql);
  793. $report_id = $db->sql_nextid();
  794. $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
  795. SET image_reported = ' . $report_id . '
  796. WHERE image_id = ' . (int) $image_id;
  797. $db->sql_query($sql);
  798. }
  799. }
  800. $template->assign_vars(array(
  801. 'ERROR' => $error,
  802. 'U_IMAGE' => ($image_id) ? append_sid("{$phpbb_root_path}{$gallery_root_path}image.$phpEx", "album_id=$album_id&amp;image_id=$image_id") : '',
  803. 'U_VIEW_IMAGE' => ($image_id) ? append_sid("{$phpbb_root_path}{$gallery_root_path}image_page.$phpEx", "album_id=$album_id&amp;image_id=$image_id") : '',
  804. 'IMAGE_RSZ_WIDTH' => $gallery_config['preview_rsz_width'],
  805. 'IMAGE_RSZ_HEIGHT' => $gallery_config['preview_rsz_height'],
  806. 'S_REPORT' => true,
  807. 'S_ALBUM_ACTION' => append_sid("{$phpbb_root_path}{$gallery_root_path}posting.$phpEx", "mode=image&amp;submode=report&amp;album_id=$album_id&amp;image_id=$image_id"),
  808. ));
  809. $message = $user->lang['IMAGES_REPORTED_SUCCESSFULLY'] . '<br />';
  810. $page_title = $user->lang['REPORT_IMAGE'];
  811. }
  812. break;
  813. case 'watch':
  814. if ($submode == 'watch')
  815. {
  816. $sql_ary = array(
  817. 'image_id' => $image_id,
  818. 'user_id' => $user->data['user_id'],
  819. );
  820. $sql = 'INSERT INTO ' . GALLERY_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  821. $db->sql_query($sql);
  822. $message = $user->lang['WATCHING_IMAGE'] . '<br />';
  823. $submit = true; // For redirect
  824. }
  825. break;
  826. case 'unwatch':
  827. if ($submode == 'unwatch')
  828. {
  829. $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . "
  830. WHERE image_id = $image_id
  831. AND user_id = " . $user->data['user_id'];
  832. $db->sql_query($sql);
  833. $message = $user->lang['UNWATCHED_IMAGE'] . '<br />';
  834. $submit = true; // For redirect
  835. }
  836. break;
  837. case 'favorite':
  838. if ($submode == 'favorite')
  839. {
  840. $sql_ary = array(
  841. 'image_id' => $image_id,
  842. 'user_id' => $user->data['user_id'],
  843. );
  844. $sql = 'INSERT INTO ' . GALLERY_FAVORITES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  845. $db->sql_query($sql);
  846. $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
  847. SET image_favorited = image_favorited + 1
  848. WHERE image_id = ' . $image_id;
  849. $db->sql_query($sql);
  850. if ($user->gallery['watch_favo'] && !$image_data['watch_id'])
  851. {
  852. $sql_ary = array(
  853. 'image_id' => $image_id,
  854. 'user_id' => $user->data['user_id'],
  855. );
  856. $sql = 'INSERT INTO ' . GALLERY_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  857. $db->sql_query($sql);
  858. }
  859. $message = $user->lang['FAVORITED_IMAGE'] . '<br />';
  860. $submit = true; // For redirect
  861. }
  862. break;
  863. case 'unfavorite':
  864. if ($submode == 'unfavorite')
  865. {
  866. $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . "
  867. WHERE image_id = $image_id
  868. AND user_id = " . $user->data['user_id'];
  869. $db->sql_query($sql);
  870. $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
  871. SET image_favorited = image_favorited - 1
  872. WHERE image_id = ' . $image_id;
  873. $db->sql_query($sql);
  874. $message = $user->lang['UNFAVORITED_IMAGE'] . '<br />';
  875. $submit = true; // For redirect
  876. }
  877. break;
  878. case 'delete':
  879. if ($submode == 'delete')
  880. {
  881. $s_hidden_fields = build_hidden_fields(array(
  882. 'album_id' => $album_id,
  883. 'image_id' => $image_id,
  884. 'mode' => 'image',
  885. 'submode' => 'delete',
  886. ));
  887. if (confirm_box(true))
  888. {
  889. @unlink($phpbb_root_path . GALLERY_CACHE_PATH . $image_data['image_thumbnail']);
  890. @unlink($phpbb_root_path . GALLERY_MEDIUM_PATH . $image_data['image_thumbnail']);
  891. @unlink($phpbb_root_path . GALLERY_UPLOAD_PATH . $image_data['image_filename']);
  892. handle_image_counter($image_id, false);
  893. $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . "
  894. WHERE comment_image_id = $image_id";
  895. $db->sql_query($sql);
  896. $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . "
  897. WHERE image_id = $image_id";
  898. $db->sql_query($sql);
  899. $sql = 'DELETE FROM ' . GALLERY_RATES_TABLE . "
  900. WHERE rate_image_id = $image_id";
  901. $db->sql_query($sql);
  902. $sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . "
  903. WHERE report_image_id = $image_id";
  904. $db->sql_query($sql);
  905. $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . "
  906. WHERE image_id = $image_id";
  907. $db->sql_query($sql);
  908. $sql = 'DELETE FROM ' . GALLERY_IMAGES_TABLE . "
  909. WHERE image_id = $image_id";
  910. $db->sql_query($sql);
  911. update_album_info($album_id);
  912. $submit = true;
  913. $message = $user->lang['DELETED_IMAGE'] . '<br />';
  914. $image_id = false;
  915. if ($user->data['user_id'] != $image_data['image_user_id'])
  916. {
  917. add_log('gallery', $image_data['image_album_id'], $image_id, 'LOG_GALLERY_DELETED', $image_data['image_name']);
  918. }
  919. }
  920. else
  921. {
  922. if (isset($_POST['cancel']))
  923. {
  924. $message = $user->lang['DELETED_IMAGE_NOT'] . '<br />';
  925. $submit = true;
  926. }
  927. else
  928. {
  929. confirm_box(false, 'DELETE_IMAGE2', $s_hidden_fields);
  930. }
  931. }
  932. }
  933. break;
  934. }
  935. }
  936. break;
  937. case 'comment':
  938. if ($mode == 'comment')
  939. {
  940. $comment = $comment_username = $s_captcha_hidden_fields = '';
  941. $comment_username_req = $contest_rating_msg = false;
  942. /**
  943. * Rating-System: now you can comment and rate in one form
  944. */
  945. $rate_point = request_var('rate', 0);
  946. if ($gallery_config['allow_rates'] && ($submode != 'edit'))
  947. {
  948. $allowed_to_rate = $your_rating = false;
  949. if ($user->data['is_registered'])
  950. {
  951. $sql = 'SELECT rate_point
  952. FROM ' . GALLERY_RATES_TABLE . '
  953. WHERE rate_image_id = ' . (int) $image_id . '
  954. AND rate_user_id = ' . (int) $user->data['user_id'];
  955. $result = $db->sql_query($sql);
  956. if ($db->sql_affectedrows($result) > 0)
  957. {
  958. $your_rating = $db->sql_fetchfield('rate_point');
  959. }
  960. $db->sql_freeresult($result);
  961. }
  962. // Check: User didn't rate yet, has permissions, it's not the users own image and the user is logged in
  963. if (!$your_rating && gallery_acl_check('i_rate', $album_id, $album_data['album_user_id']) && ($user->data['user_id'] != $image_data['image_user_id']) && ($user->data['user_id'] != ANONYMOUS))
  964. {
  965. $hide_rate = false;
  966. if ($album_data['contest_id'])
  967. {
  968. if (time() < ($album_data['contest_start'] + $album_data['contest_rating']))
  969. {
  970. $hide_rate = true;
  971. $contest_rating_msg = sprintf($user->lang['CONTEST_RATING_STARTS'], $user->format_date(($album_data['contest_start'] + $album_data['contest_rating']), false, true));
  972. }
  973. if (($album_data['contest_start'] + $album_data['contest_end']) < time())
  974. {
  975. $hide_rate = true;
  976. $contest_rating_msg = sprintf($user->lang['CONTEST_RATING_ENDED'], $user->format_date(($album_data['contest_start'] + $album_data['contest_end']), false, true));
  977. }
  978. }
  979. // User just rated the image, so we store it
  980. if (!$hide_rate && $rate_point > 0)
  981. {
  982. if ($rate_point > $gallery_config['rate_scale'])
  983. {
  984. trigger_error('OUT_OF_RANGE_VALUE');
  985. }
  986. $sql_ary = array(
  987. 'rate_image_id' => $image_id,
  988. 'rate_user_id' => $user->data['user_id'],
  989. 'rate_user_ip' => $user->ip,
  990. 'rate_point' => $rate_point,
  991. );
  992. $db->sql_query('INSERT INTO ' . GALLERY_RATES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
  993. $sql = 'SELECT rate_image_id, COUNT(rate_user_ip) image_rates, AVG(rate_point) image_rate_avg, SUM(rate_point) image_rate_points
  994. FROM ' . GALLERY_RATES_TABLE . "
  995. WHERE rate_image_id = $image_id
  996. GROUP BY rate_image_id";
  997. $result = $db->sql_query($sql);
  998. while ($row = $db->sql_fetchrow($result))
  999. {
  1000. $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
  1001. SET image_rates = ' . $row['image_rates'] . ',
  1002. image_rate_points = ' . $row['image_rate_points'] . ',
  1003. image_rate_avg = ' . round($row['image_rate_avg'], 2) * 100 . '
  1004. WHERE image_id = ' . $row['rate_image_id'];
  1005. $db->sql_query($sql);
  1006. }
  1007. $db->sql_freeresult($result);
  1008. $message .= $user->lang['RATING_SUCCESSFUL'] . '<br />';
  1009. }
  1010. // else we show the drop down
  1011. else if (!$hide_rate)
  1012. {
  1013. for ($rate_scale = 1; $rate_scale <= $gallery_config['rate_scale']; $rate_scale++)
  1014. {
  1015. $template->assign_block_vars('rate_scale', array(
  1016. 'RATE_POINT' => $rate_scale,
  1017. ));
  1018. }
  1019. $allowed_to_rate = true;
  1020. }
  1021. else
  1022. {
  1023. $allowed_to_rate = true;
  1024. }
  1025. }
  1026. $template->assign_vars(array(
  1027. 'S_ALLOWED_TO_RATE' => $allowed_to_rate,
  1028. 'CONTEST_RATING' => $contest_rating_msg,
  1029. ));
  1030. if ($submode == 'rate')
  1031. {
  1032. $s_album_action = '';
  1033. }
  1034. }
  1035. switch ($submode)
  1036. {
  1037. case 'add':
  1038. if (gallery_display_captcha('comment'))
  1039. {
  1040. include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
  1041. $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
  1042. $captcha->init(CONFIRM_POST);
  1043. }
  1044. if ($submit)
  1045. {
  1046. if (!check_form_key('gallery'))
  1047. {
  1048. trigger_error('FORM_INVALID');
  1049. }
  1050. if (gallery_display_captcha('comment'))
  1051. {
  1052. $captcha_error = $captcha->validate();
  1053. if ($captcha_error)
  1054. {
  1055. $error .= (($error) ? '<br />' : '') . $captcha_error;
  1056. $submit = false;
  1057. }
  1058. }
  1059. $comment = request_var('message', '', true);
  1060. $comment_text = $comment;
  1061. $comment_username = request_var('username', '', true);
  1062. if ($user->data['user_id'] == ANONYMOUS)
  1063. {
  1064. $comment_username_req = true;
  1065. }
  1066. if ($comment_username_req)
  1067. {
  1068. if ($comment_username == '')
  1069. {
  1070. $submit = false;
  1071. $error .= (($error) ? '<br />' : '') . $user->lang['MISSING_USERNAME'];
  1072. }
  1073. if (validate_username($comment_username))
  1074. {
  1075. $error .= (($error) ? '<br />' : '') . $user->lang['INVALID_USERNAME'];
  1076. $submit = false;
  1077. }
  1078. }
  1079. if (($comment_text == '') && !$rate_point)
  1080. {
  1081. $submit = false;
  1082. $error .= (($error) ? '<br />' : '') . $user->lang['MISSING_COMMENT'];
  1083. }
  1084. if (utf8_strlen($comment_text) > $gallery_config['desc_length'])
  1085. {
  1086. $submit = false;
  1087. $error .= (($error) ? '<br />' : '') . $user->lang['COMMENT_TOO_LONG'];
  1088. }
  1089. $message_parser = new parse_message();
  1090. $message_parser->message = utf8_normalize_nfc($comment_text);
  1091. if ($message_parser->message)
  1092. {
  1093. $message_parser->parse(true, true, true, true, false, true, true, true);
  1094. }
  1095. $sql_ary = array(
  1096. 'comment_image_id' => $image_id,
  1097. 'comment_user_id' => $user->data['user_id'],
  1098. 'comment_username' => ($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : $comment_username,
  1099. 'comment_user_colour' => $user->data['user_colour'],
  1100. 'comment_user_ip' => $user->ip,
  1101. 'comment_time' => time(),
  1102. 'comment' => $message_parser->message,
  1103. 'comment_uid' => $message_parser->bbcode_uid,
  1104. 'comment_bitfield' => $message_parser->bbcode_bitfield,
  1105. );
  1106. if ((!$error) && ($sql_ary['comment'] != ''))
  1107. {
  1108. $db->sql_query('INSERT INTO ' . GALLERY_COMMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
  1109. $newest_comment = $db->sql_nextid();
  1110. set_gallery_config_count('num_comments', 1);
  1111. if (gallery_display_captcha('comment'))
  1112. {
  1113. $captcha->reset();
  1114. }
  1115. $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . "
  1116. SET image_comments = image_comments + 1,
  1117. image_last_comment = $newest_comment
  1118. WHERE " . $db->sql_in_set('image_id', $image_id);
  1119. $db->sql_query($sql);
  1120. if ($user->gallery['watch_com'] && !$image_data['watch_id'])
  1121. {
  1122. $sql_ary = array(
  1123. 'image_id' => $image_id,
  1124. 'user_id' => $user->data['user_id'],
  1125. );
  1126. $sql = 'INSERT INTO ' . GALLERY_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  1127. $db->sql_query($sql);
  1128. }
  1129. gallery_notification('image', $image_id, $image_data['image_name']);
  1130. $message .= $user->lang['COMMENT_STORED'] . '<br />';
  1131. }
  1132. else if (gallery_display_captcha('comment'))
  1133. {
  1134. $s_captcha_hidden_fields = ($captcha->is_solved()) ? build_hidden_fields($captcha->get_hidden_fields()) : '';
  1135. }
  1136. }
  1137. else
  1138. {
  1139. if ($user->data['user_id'] != ANONYMOUS)
  1140. {
  1141. $comment_username_req = true;
  1142. }
  1143. }
  1144. if (gallery_display_captcha('comment'))
  1145. {
  1146. if (!$submit || !$captcha->is_solved())
  1147. {
  1148. $template->assign_vars(array(
  1149. 'S_CONFIRM_CODE' => true,
  1150. 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
  1151. ));
  1152. }
  1153. $template->assign_vars(array(
  1154. 'S_CAPTCHA_HIDDEN_FIELDS' => $s_captcha_hidden_fields,
  1155. ));
  1156. }
  1157. $s_album_action = append_sid("{$phpbb_root_path}{$gallery_root_path}posting.$phpEx", "mode=comment&amp;submode=add&amp;album_id=$album_id&amp;image_id=$image_id");
  1158. $page_title = $user->lang['POST_COMMENT'];
  1159. break;
  1160. case 'edit':
  1161. if ($comment_data['comment_user_id'] == ANONYMOUS)
  1162. {
  1163. $comment_username_req = true;
  1164. }
  1165. if ($submit)
  1166. {
  1167. if (!check_form_key('gallery'))
  1168. {
  1169. trigger_error('FORM_INVALID');
  1170. }
  1171. $sql_ary = array();
  1172. $comment = request_var('message', '', true);
  1173. $comment_text = $comment;
  1174. if ($comment_username_req)
  1175. {
  1176. $comment_username = request_var('username', '');
  1177. if ($comment_username == '')
  1178. {
  1179. $submit = false;
  1180. $error .= (($error) ? '<br />' : '') . $user->lang['MISSING_USERNAME'];
  1181. $comment_username_req = true;
  1182. }
  1183. if (validate_username($comment_username))
  1184. {
  1185. $error .= (($error) ? '<br />' : '') . $user->lang['INVALID_USERNAME'];
  1186. $comment_username = '';
  1187. $comment_username_req = true;
  1188. $submit = false;
  1189. }
  1190. $sql_ary = array(
  1191. 'comment_username' => $comment_username,
  1192. );
  1193. }
  1194. if ($comment_text == '')
  1195. {
  1196. $submit = false;
  1197. $error .= (($error) ? '<br />' : '') . $user->lang['MISSING_COMMENT'];
  1198. }
  1199. if (utf8_strlen($comment_text) > $gallery_config['desc_length'])
  1200. {
  1201. $submit = false;
  1202. $error .= (($error) ? '<br />' : '') . $user->lang['COMMENT_TOO_LONG'];
  1203. }
  1204. $message_parser = new parse_message();
  1205. $message_parser->message = utf8_normalize_nfc($comment_text);
  1206. if ($message_parser->message)
  1207. {
  1208. $message_parser->parse(true, true, true, true, false, true, true, true);
  1209. }
  1210. $sql_ary = array_merge($sql_ary, array(
  1211. 'comment' => $message_parser->message,
  1212. 'comment_uid' => $message_parser->bbcode_uid,
  1213. 'comment_bitfield' => $message_parser->bbcode_bitfield,
  1214. 'comment_edit_count' => $comment_data['comment_edit_count'] + 1,
  1215. 'comment_edit_time' => time(),
  1216. 'comment_edit_user_id' => $user->data['user_id'],
  1217. ));
  1218. if (!$error)
  1219. {
  1220. $db->sql_query('UPDATE ' . GALLERY_COMMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE comment_id = ' . (int) $comment_id);
  1221. $message .= $user->lang['COMMENT_STORED'] . '<br />';
  1222. if ($user->data['user_id'] != $comment_data['comment_user_id'])
  1223. {
  1224. add_log('gallery', $image_data['image_album_id'], $image_data['image_id'], 'LOG_GALLERY_COMMENT_EDITED', $image_data['image_name']);
  1225. }
  1226. }
  1227. }
  1228. else
  1229. {
  1230. $comment_ary = generate_text_for_edit($comment_data['comment'], $comment_data['comment_uid'], $comment_data['comment_bitfield'], 7);
  1231. $comment = $comment_ary['text'];
  1232. $comment_username = $comment_data['comment_username'];
  1233. }
  1234. $s_album_action = append_sid("{$phpbb_root_path}{$gallery_root_path}posting.$phpEx", "mode=comment&amp;submode=edit&amp;album_id=$album_id&amp;image_id=$image_id&amp;comment_id=$comment_id");
  1235. $page_title = $user->lang['EDIT_COMMENT'];
  1236. break;
  1237. case 'delete':
  1238. $s_hidden_fields = build_hidden_fields(array(
  1239. 'album_id' => $album_id,
  1240. 'image_id' => $image_id,
  1241. 'comment_id' => $comment_id,
  1242. 'mode' => 'comment',
  1243. 'submode' => 'delete',
  1244. ));
  1245. $comment = $comment_username = $comment_username_req = '';
  1246. if (confirm_box(true))
  1247. {
  1248. $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . " WHERE comment_id = $comment_id;";
  1249. $db->sql_query($sql);
  1250. set_gallery_config_count('num_comments', -1);
  1251. $sql = 'SELECT MAX(comment_id) last_comment
  1252. FROM ' . GALLERY_COMMENTS_TABLE . "
  1253. WHERE comment_image_id = $image_id
  1254. ORDER BY comment_id";
  1255. $result = $db->sql_query_limit($sql, 1);
  1256. $last_comment_id = (int) $db->sql_fetchfield('last_comment');
  1257. $db->sql_freeresult($result);
  1258. $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . "
  1259. SET image_comments = image_comments - 1,
  1260. image_last_comment = $last_comment_id
  1261. WHERE " . $db->sql_in_set('image_id', $image_id);
  1262. $db->sql_query($sql);
  1263. if ($user->data['user_id'] != $comment_data['comment_user_id'])
  1264. {
  1265. add_log('gallery', $image_data['image_album_id'], $image_data['image_id'], 'LOG_GALLERY_COMMENT_DELETED', $image_data['image_name']);
  1266. }
  1267. $submit = true;
  1268. $message = $user->lang['DELETED_COMMENT'] . '<br />';
  1269. }
  1270. else
  1271. {
  1272. if (isset($_POST['cancel']))
  1273. {
  1274. $message = $user->lang['DELETED_COMMENT_NOT'] . '<br />';
  1275. $submit = true;
  1276. }
  1277. else
  1278. {
  1279. confirm_box(false, 'DELETE_COMMENT2', $s_hidden_fields);
  1280. }
  1281. }
  1282. break;
  1283. }
  1284. $template->assign_vars(array(
  1285. 'ERROR' => $error,
  1286. 'MESSAGE' => $comment,
  1287. 'USERNAME' => $comment_username,
  1288. 'REQ_USERNAME' => $comment_username_req,
  1289. 'L_COMMENT_LENGTH' => sprintf($user->lang['COMMENT_LENGTH'], $gallery_config['comment_length']),
  1290. 'IMAGE_RSZ_WIDTH' => $gallery_config['preview_rsz_width'],
  1291. 'IMAGE_RSZ_HEIGHT' => $gallery_config['preview_rsz_height'],
  1292. 'U_IMAGE' => ($image_id) ? append_sid("{$phpbb_root_path}{$gallery_root_path}image.$phpEx", "album_id=$album_id&amp;image_id=$image_id") : '',
  1293. 'U_VIEW_IMAGE' => ($image_id) ? append_sid("{$phpbb_root_path}{$gallery_root_path}image_page.$phpEx", "album_id=$album_id&amp;image_id=$image_id") : '',
  1294. 'IMAGE_NAME' => ($image_id) ? $image_data['image_name'] : '',
  1295. 'S_ALBUM_ACTION' => $s_album_action,
  1296. 'S_COMMENT' => true,
  1297. ));
  1298. }
  1299. break;
  1300. }
  1301. if ($submit)
  1302. {
  1303. if ($image_id)
  1304. {
  1305. $image_backlink = append_sid("{$phpbb_root_path}{$gallery_root_path}image_page.$phpEx", (($album_id) ? "album_id=$album_id&amp;" : '') . "image_id=$image_id");
  1306. $message .= '<br />' . sprintf($user->lang['CLICK_RETURN_IMAGE'], '<a href="' . $image_backlink . '">', '</a>');
  1307. }
  1308. if ($album_id)
  1309. {
  1310. $album_backlink = append_sid("{$phpbb_root_path}{$gallery_root_path}album.$phpEx", "album_id=$album_id");
  1311. $message .= '<br />' . sprintf($user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>');
  1312. }
  1313. meta_refresh((($slower_redirect) ? 10 : 3), ($image_id) ? $image_backlink : $album_backlink);
  1314. trigger_error($message);
  1315. }
  1316. page_header($page_title, false);
  1317. $template->set_filenames(array(
  1318. 'body' => 'gallery/posting_body.html',
  1319. ));
  1320. page_footer();
  1321. ?>