/** * Handle upload. */ protected function handle_upload() { $upload = $this->request->file($this->form_name); if ($upload['name'] != 'none' && trim($upload['name'])) { // Try uploading the file. $this->upload_file(); // Store for easier access $this->errors = array_merge($this->errors, $this->filedata['error']); // If we had no problems we can submit the data to the database. if (empty($this->filedata['error'])) { $order_id = $this->set_custom_order ? $this->operator->get_max_custom_index() + 1 : 0; $data = array('attachment_id' => 0, 'physical_filename' => $this->filedata['physical_filename'], 'attachment_directory' => $this->filedata['attachment_directory'], 'real_filename' => $this->filedata['real_filename'], 'extension' => $this->filedata['extension'], 'mimetype' => $this->filedata['mimetype'], 'filesize' => $this->filedata['filesize'], 'filetime' => $this->filedata['filetime'], 'hash' => $this->filedata['md5_checksum'], 'attachment_order' => $order_id, 'attachment_comment' => $this->request->variable('filecomment', '', true), 'object_type' => $this->object_type, 'object_id' => $this->object_id); $attachment = $this->operator->get_new_entity($data); // Create thumbnail $has_thumbnail = $is_preview = false; if ($this->filedata['is_image']) { $has_thumbnail = $attachment->create_thumbnail($this->max_thumbnail_width, $this->max_thumbnail_width === false ? false : 0); // set first screenshot as preview image when it is uploaded $is_preview = !$this->operator->get_count(); } $attachment->__set_array(array('thumbnail' => $has_thumbnail, 'is_preview' => $is_preview)); $attachment->submit(); // Store in operator $this->operator->set($attachment); $this->uploaded = $attachment->get_id(); } } // We do not want to upload it again if this function is called again. $this->request->overwrite($this->form_name, null, request_interface::FILES); }
/** * Event: rfd.api.pre_update_topic * * Validate trader_type being passed in * * @param phpbbEvent $event */ public function rfd_api_pre_update_topic(phpbbEvent $event) { $data = $event->get_data(); $topic_id = $data['topic_id']; $forum_id = $data['forum_id']; $errors = $data['errors']; $type = $this->request->variable('trader_type', '', false, \phpbb\request\request_interface::POST); // if trader_type is not set, set it to the current trader_type if (!isset($type)) { $type = $this->manager->getTopicType($topic_id); $type = $this->manager->validateForumType($forum_id, $type, false); } else { if ($this->manager->getForumStatus($forum_id)) { $type = $this->manager->validateForumType($forum_id, $type, true); } } // Expose error if trader_type is not supported by the forum if (is_null($type)) { $errors[] = 'This forum does not support that trader type'; $data['errors'] = $errors; $event->set_data($data); } else { // Overwrite the request so that submit_post_end listener can handle trader_type $this->request->overwrite('prefixfield', $type, \phpbb\request\request_interface::POST); } }
/** * Move file from another location to phpBB * * @param string $source_file Filename of source file * @param array|bool $filedata Array with filedata or false * * @return filespec Object "filespec" is returned, all further operations can be done with this object */ protected function local_upload($source_file, $filedata = false) { $upload = $this->get_upload_ary($source_file, $filedata); /** @var filespec $file */ $file = $this->factory->get('filespec')->set_upload_ary($upload)->set_upload_namespace($this->upload); if ($file->init_error()) { $file->error[] = ''; return $file; } // PHP Upload file size check $file = $this->check_upload_size($file); if (sizeof($file->error)) { return $file; } // Not correctly uploaded if (!$file->is_uploaded()) { $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED'); return $file; } $this->upload->common_checks($file); $this->request->overwrite('local', $upload, request_interface::FILES); return $file; }