PageRenderTime 64ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/root/gallery/posting.php

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