/** * comment Controller * Route: gallery/comment/{image_id}/add * * @param int $image_id Image ID * @return Symfony\Component\HttpFoundation\Response A Symfony Response object */ public function add($image_id, $comment_id) { $this->user->add_lang_ext('phpbbgallery/core', array('gallery')); add_form_key('gallery'); if ($comment_id != 0) { $sql = 'SELECT * FROM ' . $this->table_comments . ' WHERE comment_id = ' . $comment_id; $result = $this->db->sql_query($sql); $comment_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $image_id = (int) $comment_data['comment_image_id']; } $submit = $this->request->variable('submit', false); $error = $message = ''; // load Image Data $image_data = $this->image->get_image_data($image_id); $album_id = (int) $image_data['image_album_id']; $album_data = $this->loader->get($album_id); $this->display->generate_navigation($album_data); $page_title = $image_data['image_name']; $image_backlink = $this->helper->route('phpbbgallery_image', array('image_id' => $image_id)); $album_backlink = $this->helper->route('phpbbgallery_album', array('album_id' => $album_id)); $image_loginlink = $this->url->append_sid('relative', 'image_page', "album_id={$album_id}&image_id={$image_id}"); $this->gallery_auth->load_user_premissions($this->user->data['user_id']); if (!$this->gallery_auth->acl_check('c_post', $album_id, $album_data['album_user_id'])) { $this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD'); } add_form_key('gallery'); $this->user->add_lang('posting'); include_once $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext; $bbcode_status = $this->config['allow_bbcode'] ? true : false; $smilies_status = $this->config['allow_smilies'] ? true : false; $img_status = $bbcode_status ? true : false; $url_status = $this->config['allow_post_links'] ? true : false; $flash_status = false; $quote_status = true; include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext; // Build custom bbcodes array display_custom_bbcodes(); // Build smilies array generate_smilies('inline', 0); //$s_hide_comment_input = (time() < ($album_data['contest_start'] + $album_data['contest_end'])) ? true : false; $s_hide_comment_input = false; $this->template->assign_vars(array('BBCODE_STATUS' => $bbcode_status ? sprintf($this->user->lang['BBCODE_IS_ON'], '<a href="' . $this->url->append_sid('phpbb', 'faq', 'mode=bbcode') . '">', '</a>') : sprintf($this->user->lang['BBCODE_IS_OFF'], '<a href="' . $this->url->append_sid('phpbb', 'faq', 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $flash_status ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $smilies_status ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $bbcode_status && $url_status ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status)); if ($this->misc->display_captcha('comment')) { global $phpbb_container; $captcha = $phpbb_container->get('captcha.factory')->get_instance($this->config['captcha_plugin']); $captcha->init(CONFIRM_POST); $this->template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template())); } $s_captcha_hidden_fields = ''; $comment_username_req = $this->user->data['user_id'] == ANONYMOUS; if ($submit) { if (!check_form_key('gallery')) { trigger_error('FORM_INVALID'); } if ($this->misc->display_captcha('comment')) { $captcha_error = $captcha->validate(); if ($captcha_error) { $error .= ($error ? '<br />' : '') . $captcha_error; } } $comment_plain = $this->request->variable('message', '', true); $comment_username = $this->request->variable('username', '', true); if ($comment_username_req) { global $phpbb_root_path, $phpEx; include $phpbb_root_path . 'includes/functions_user.' . $phpEx; if ($comment_username == '') { $error .= ($error ? '<br />' : '') . $user->lang['MISSING_USERNAME']; } if ($result = validate_username($comment_username)) { $this->user->add_lang('ucp'); $error .= ($error ? '<br />' : '') . $this->user->lang[$result . '_USERNAME']; $submit = false; } } if ($comment_plain == '' && !$s_user_rated) { $error .= ($error ? '<br />' : '') . $user->lang['MISSING_COMMENT']; } if (utf8_strlen($comment_plain) > $this->gallery_config->get('comment_length')) { $error .= ($error ? '<br />' : '') . $this->user->lang['COMMENT_TOO_LONG']; } if (!class_exists('bbcode')) { include $this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext; } include_once $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext; $message_parser = new \parse_message(); $message_parser->message = utf8_normalize_nfc($comment_plain); if ($message_parser->message) { $message_parser->parse(true, true, true, true, false, true, true, true); } $sql_ary = array('comment_image_id' => $image_id, 'comment' => $message_parser->message, 'comment_uid' => $message_parser->bbcode_uid, 'comment_bitfield' => $message_parser->bbcode_bitfield, 'comment_signature' => $this->auth->acl_get('u_sig') && isset($_POST['attach_sig'])); if (!$error && $sql_ary['comment'] != '') { if ($this->misc->display_captcha('comment')) { $captcha->reset(); } $comment_post_id = $this->comment->add($sql_ary, $comment_username); $phpbb_gallery_notification = new \phpbbgallery\core\notification(); if ($this->gallery_user->get_data('watch_com')) { $phpbb_gallery_notification->add($image_id); } $data = array('image_id' => $image_id, 'comment_id' => $comment_post_id, 'poster_id' => $this->user->data['user_id']); $this->notification_helper->notify('new_comment', $data); //$phpbb_gallery_notification->send_notification('image', $image_id, $image_data['image_name']); $message .= $this->user->lang['COMMENT_STORED'] . '<br />'; } else { if ($this->misc->display_captcha('comment')) { $s_captcha_hidden_fields = $captcha->is_solved() ? build_hidden_fields($captcha->get_hidden_fields()) : ''; } } $sig_checked = $this->auth->acl_get('u_sig') && isset($_POST['attach_sig']); } else { if ($comment_id != 0) { $comment_ary = generate_text_for_edit($comment_data['comment'], $comment_data['comment_uid'], $comment_data['comment_bitfield'], 7); $comment_plain = '[quote="' . $comment_data['comment_username'] . '"]' . $comment_ary['text'] . '[/quote]'; } $sig_checked = $this->user->optionget('attachsig'); } $preview = $this->request->variable('preview', false); if ($preview) { $comment_plain = $this->request->variable('message', '', true); } if ($this->misc->display_captcha('comment')) { if (!$submit || !$captcha->is_solved()) { $this->template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template())); } $this->template->assign_vars(array('S_CAPTCHA_HIDDEN_FIELDS' => $s_captcha_hidden_fields)); } $this->template->assign_vars(array('ERROR' => $error, 'MESSAGE' => isset($comment_plain) ? $comment_plain : '', 'USERNAME' => isset($comment_username) ? $comment_username : '', 'REQ_USERNAME' => !empty($comment_username_req) ? true : false, 'L_COMMENT_LENGTH' => sprintf($this->user->lang['COMMENT_LENGTH'], $this->gallery_config->get('comment_length')), 'IMAGE_RSZ_WIDTH' => $this->gallery_config->get('medium_width'), 'IMAGE_RSZ_HEIGHT' => $this->gallery_config->get('medium_height'), 'U_IMAGE' => append_sid($this->url->path('full') . 'image/' . $image_id . '/medium'), 'U_VIEW_IMAGE' => append_sid($this->url->path('full') . 'image/' . $image_id), 'IMAGE_NAME' => $image_data['image_name'], 'S_SIGNATURE_CHECKED' => isset($sig_checked) && $sig_checked ? ' checked="checked"' : '', 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_comment_add', array('image_id' => $image_id, 'comment_id' => 0)))); if ($submit && !$error) { $message .= '<br />' . sprintf($this->user->lang['CLICK_RETURN_IMAGE'], '<a href="' . $image_backlink . '">', '</a>'); $message .= '<br />' . sprintf($this->user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>'); $this->url->meta_refresh(3, $image_backlink); trigger_error($message); } return $this->helper->render('gallery/comment_body.html', $page_title); }
public function main($album_id) { $this->user->add_lang_ext('phpbbgallery/core', array('gallery')); $album_data = $this->album->get_info($album_id); $this->display->generate_navigation($album_data); add_form_key('gallery'); $album_backlink = $this->helper->route('phpbbgallery_album', array('album_id' => $album_id)); $album_loginlink = 'ucp.php?mode=login'; $error = ''; //Let's get authorization $this->auth->load_user_premissions($this->user->data['user_id']); if (!$this->auth->acl_check('i_upload', $album_id, $album_data['album_user_id']) || $album_data['album_status'] == $this->album->status_locked()) { $this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD'); } $page_title = 'Upload to "' . $album_data['album_name'] . '"'; // Before all if (!$this->check_fs()) { trigger_error('NO_WRITE_ACCESS'); } $submit = $this->request->variable('submit', false); $mode = $this->request->variable('mode', 'upload'); if ($mode == 'upload') { // Upload Quota Check // 1. Check album-configuration Quota if ($this->gallery_config->get('album_images') >= 0 && $album_data['album_images'] >= $this->gallery_config->get('album_images')) { //@todo: Add return link trigger_error('ALBUM_REACHED_QUOTA'); } // 2. Check user-limit, if he is not allowed to go unlimited if (!$this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) { $sql = 'SELECT COUNT(image_id) count FROM ' . $this->images_table . ' WHERE image_user_id = ' . $this->user->data['user_id'] . ' AND image_status <> ' . $this->image->get_status_orphan() . ' AND image_album_id = ' . $album_id; $result = $this->db->sql_query($sql); $own_images = (int) $this->db->sql_fetchfield('count'); $this->db->sql_freeresult($result); if ($own_images >= $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])) { //@todo: Add return link trigger_error($this->user->lang('USER_REACHED_QUOTA', $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']))); } } if ($this->misc->display_captcha('upload')) { phpbb_gallery_url::_include('captcha/captcha_factory', 'phpbb'); $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']); $captcha->init(CONFIRM_POST); $s_captcha_hidden_fields = ''; } $upload_files_limit = $this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id']) ? $this->gallery_config->get('num_uploads') : min($this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images, $this->gallery_config->get('num_uploads')); $process = new \phpbbgallery\core\upload($album_id, $upload_files_limit); if ($submit) { if (!check_form_key('gallery')) { trigger_error('FORM_INVALID'); } //$process = new \phpbbgallery\core\upload($album_id, $upload_files_limit); $process->set_rotating($this->request->variable('rotate', array(0))); $process->set_allow_comments($this->request->variable('allow_comments', false)); /*if ($this->misc->display_captcha('upload')) { $captcha_error = $captcha->validate(); if ($captcha_error !== false) { $process->new_error($captcha_error); } } */ if (!$this->user->data['is_registered']) { $username = $this->request->variable('username', $user->data['username']); if ($result = validate_username($username)) { $this->user->add_lang('ucp'); $error_array[] = $this->user->lang[$result . '_USERNAME']; } else { $process->set_username($username); } } if (empty($process->errors)) { for ($file_count = 0; $file_count < $upload_files_limit; $file_count++) { /** * Upload an image from the FILES-array, * call some functions (rotate, resize, ...) * and store the image to the database */ $file = $this->request->file('image_file_' . $file_count, ''); if (isset($file['size'])) { if ($file['size'] > 0) { $process->upload_file($file_count); } } } } if (!$process->uploaded_files) { $process->new_error($this->user->lang['UPLOAD_NO_FILE']); } else { $mode = 'upload_edit'; // Remove submit, so we get the first screen of step 2. $submit = false; } $error = implode('<br />', $process->errors); /*if (phpbb_gallery_misc::display_captcha('upload')) { $captcha->reset(); }*/ } if (!$submit || isset($process) && !$process->uploaded_files) { for ($i = 0; $i < $upload_files_limit; $i++) { $this->template->assign_block_vars('upload_image', array()); } } if ($mode == 'upload') { $this->template->assign_vars(array('ERROR' => $error, 'S_MAX_FILESIZE' => get_formatted_filesize($this->gallery_config->get('max_filesize')), 'S_MAX_WIDTH' => $this->gallery_config->get('max_width'), 'S_MAX_HEIGHT' => $this->gallery_config->get('max_height'), 'S_ALLOWED_FILETYPES' => implode(', ', $process->get_allowed_types(true)), 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_album_upload', array('album_id' => $album_id)), 'S_UPLOAD' => true, 'S_ALLOW_ROTATE' => $this->gallery_config->get('allow_rotate') && function_exists('imagerotate'), 'S_UPLOAD_LIMIT' => $upload_files_limit, 'S_COMMENTS_ENABLED' => $this->gallery_config->get('allow_comments') && $this->gallery_config->get('comment_user_control'), 'S_ALLOW_COMMENTS' => true, 'L_ALLOW_COMMENTS' => $this->user->lang('ALLOW_COMMENTS_ARY', $upload_files_limit))); /*if (phpbb_gallery_misc::display_captcha('upload')) { if (!$submit || !$captcha->is_solved()) { $template->assign_vars(array( 'S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template(), )); } $template->assign_vars(array( 'S_CAPTCHA_HIDDEN_FIELDS' => $s_captcha_hidden_fields, )); }*/ } } if ($mode == 'upload_edit') { if ($submit) { // Upload Quota Check // 1. Check album-configuration Quota if ($this->gallery_config->get('album_images') >= 0 && $album_data['album_images'] >= $this->gallery_config->get('album_images')) { //@todo: Add return link trigger_error('ALBUM_REACHED_QUOTA'); } // 2. Check user-limit, if he is not allowed to go unlimited if (!$this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) { $sql = 'SELECT COUNT(image_id) count FROM ' . $this->images_table . ' WHERE image_user_id = ' . $this->user->data['user_id'] . ' AND image_status <> ' . $this->image->get_status_orphan() . ' AND image_album_id = ' . $album_id; $result = $this->db->sql_query($sql); $own_images = (int) $this->db->sql_fetchfield('count'); $this->db->sql_freeresult($result); if ($own_images >= $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])) { //@todo: Add return link trigger_error($this->user->lang('USER_REACHED_QUOTA', $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']))); } } $description_array = $this->request->variable('message', array(''), true); foreach ($description_array as $var) { if (strlen($var) > $this->gallery_config->get('description_length')) { trigger_error($this->user->lang('DESC_TOO_LONG')); } } $upload_files_limit = $this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id']) ? $this->gallery_config->get('num_uploads') : min($this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images, $this->gallery_config->get('num_uploads')); $upload_ids = $this->request->variable('upload_ids', array('')); $process = new \phpbbgallery\core\upload($album_id, $upload_files_limit); $process->set_rotating($this->request->variable('rotate', array(0))); $process->get_images($upload_ids); $image_names = $this->request->variable('image_name', array(''), true); $process->set_names($image_names); $process->set_descriptions($description_array); $process->set_image_num($this->request->variable('image_num', 0)); $process->use_same_name($this->request->variable('same_name', false)); $success = true; $phpbb_gallery_notification = new \phpbbgallery\core\notification(); foreach ($process->images as $image_id) { $success = $success && $process->update_image($image_id, !$this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id']), $album_data['album_contest']); if ($this->gallery_user->get_data('watch_own')) { $phpbb_gallery_notification->add($image_id); } } $message = ''; $error = implode('<br />', $process->errors); if ($this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id'])) { $message .= !$error ? $this->user->lang['ALBUM_UPLOAD_SUCCESSFUL'] : $this->user->lang('ALBUM_UPLOAD_SUCCESSFUL_ERROR', $error); $meta_refresh_time = $success ? 3 : 20; //$this->notification_helper->notify_album($album_id, $this->user->data['user_id']); $data = array('targets' => array($this->user->data['user_id']), 'album_id' => $album_id, 'last_image' => end($process->images)); $this->notification_helper->new_image($data); } else { $target = array('album_id' => $album_id, 'last_image' => end($process->images), 'uploader' => $this->user->data['user_id']); $this->notification_helper->notify('approval', $target); $message .= !$error ? $this->user->lang['ALBUM_UPLOAD_NEED_APPROVAL'] : $this->user->lang('ALBUM_UPLOAD_NEED_APPROVAL_ERROR', $error); $meta_refresh_time = 20; } $message .= '<br /><br />' . sprintf($this->user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>'); // ToDo - notifications!!! //$phpbb_gallery_notification->send_notification('album', $album_id, $image_names[0]); $this->image->handle_counter($process->images, true); $this->album->update_info($album_id); $this->url->meta_refresh($meta_refresh_time, $album_backlink); trigger_error($message); } $num_images = 0; foreach ($process->images as $image_id) { $data = $process->image_data[$image_id]; $this->template->assign_block_vars('image', array('U_IMAGE' => $this->image->generate_link('thumbnail', 'plugin', $image_id, $data['image_name'], $album_id), 'IMAGE_NAME' => $data['image_name'], 'IMAGE_DESC' => $data['image_desc'])); $num_images++; } $s_hidden_fields = build_hidden_fields(array('upload_ids' => $process->generate_hidden_fields())); $s_can_rotate = $this->gallery_config->get('allow_rotate') && function_exists('imagerotate'); $this->template->assign_vars(array('ERROR' => $error, 'S_UPLOAD_EDIT' => true, 'S_ALLOW_ROTATE' => $s_can_rotate, 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_album_upload', array('album_id' => $album_id)), 'S_USERNAME' => !$this->user->data['is_registered'] ? $username : '', 'NUM_IMAGES' => $num_images, 'COLOUR_ROWSPAN' => $s_can_rotate ? $num_images * 3 : $num_images * 2, 'L_DESCRIPTION_LENGTH' => $this->user->lang('DESCRIPTION_LENGTH', $this->gallery_config->get('description_length')), 'S_HIDDEN_FIELDS' => $s_hidden_fields)); } return $this->helper->render('gallery/posting_body.html', $page_title); }