/** * File type icon. * Retrieves file type to icon mappings from the {@link APPLICATION::file_type_manager()}. * @param string $size The size of the icon to return. * @return string */ public function icon_as_html($size = One_hundred_px) { $ft = $this->app->file_type_manager(); $url = new FILE_URL($this->file_name); return $ft->icon_as_html($this->mime_type, $url->extension(), $size); }
/** * Copy the object to the specified folder. * If both the source and target albums are {@link Album_location_type_local}, * and they are different folders, copy the pictures to the new folder. * @param ALBUM $folder * @param FOLDER_OPERATION_OPTIONS $options */ protected function _copy_to($folder, $options) { if ($options->update_now) { /** @var ALBUM $parent */ $parent = $this->parent_folder(); $old_location = $parent->location; $old_folder = url_to_folder($parent->picture_folder_url(true)); } parent::_copy_to($folder, $options); if ($options->update_now) { if ($old_location == Album_location_type_local && $folder->location == Album_location_type_local) { $new_folder = url_to_folder($folder->picture_folder_url(true)); if ($old_folder != $new_folder) { $old_url = new FILE_URL($old_folder); $old_url->replace_name($this->file_name); if ($old_url->extension() == '') { $old_url->replace_extension('jpg'); } $new_url = new FILE_URL($new_folder); $new_url->replace_name($this->file_name); if ($new_url->extension() == '') { $new_url->replace_extension('jpg'); } if (file_exists($old_url->as_text())) { ensure_path_exists($new_folder); log_message('Copied [' . $old_url->as_text() . '] to [' . $new_url->as_text() . ']', Msg_type_debug_info, Msg_channel_system); if (!copy($old_url->as_text(), $new_url->as_text())) { $this->raise('_copy_to', 'PICTURE', 'Could not copy main image for [' . $this->title_as_plain_text() . '].'); } } $old_url->append_to_name(Picture_thumbnail_suffix); $new_url->append_to_name(Picture_thumbnail_suffix); if (file_exists($old_url->as_text())) { ensure_path_exists($new_folder); log_message('Copied [' . $old_url->as_text() . '] to [' . $new_url->as_text() . ']', Msg_type_debug_info, Msg_channel_system); if (!copy($old_url->as_text(), $new_url->as_text())) { $this->raise('_copy_to', 'PICTURE', 'Could not copy thumbnail image for [' . $this->title_as_plain_text() . '].'); } } } } } }
/** * Draw information for a file as HTML. * Passed as a {@link CALLBACK} if the attachment is an {@link ARCHIVE}. * @param ARCHIVE $archive * @param COMPRESSED_FILE_ENTRY $entry * @param WEBCORE_CALLBACK $error_callback Function prototype: function ({@link COMPRESSED_FILE} $archive, string $msg, {@link COMPRESSED_FILE_ENTRY} $entry) * @access private */ public function list_file_as_html($archive, $entry, $error_callback = null) { $ft = $this->context->file_type_manager(); $url = new FILE_URL($entry->name); $icon_with_text = $this->context->get_icon_with_text($ft->icon_url('', $url->extension()), Sixteen_px, $entry->name); echo '<tr><td>' . $icon_with_text . '</td><td>' . file_size_as_text($entry->size) . '</td></tr>'; }
/** * Return HTML for a file upload control. * If the file has already been uploaded and processed, the name is shown instead of a control * so that the user doesn't have to upload again if there were validation errors elsewhere. * @param string $id Name of field. * @param FORM_TEXT_CONTROL_OPTIONS $options * @return string */ public function file_as_html($id, $options = null) { /** @var UPLOAD_FILE_FIELD $field */ $field = $this->_field_at($id); if (!isset($options)) { $options = clone default_text_options(); } if (!isset($this->_num_controls[$id])) { $this->_num_controls[$id] = 0; } if ($field->is_processed($this->_num_controls[$id])) { $file = $field->file_at($this->_num_controls[$id]); $ft = $this->context->file_type_manager(); $url = new FILE_URL($file->name); $icon = $ft->icon_as_html($file->mime_type, $url->extension(), Sixteen_px); // TODO Wrap in an .input class container $Result = '<div class="detail">' . $icon . ' ' . $file->name . ' (' . file_size_as_text($file->size) . ")</div>"; $file_info = $file->store_to_text($id); $uploader = $this->_form->uploader(); $Result .= '<input type="hidden" name="' . $uploader->stored_info_name . '[]" value="' . $file_info . "\">\n"; if ($field->description) { $Result .= '<div class="description">' . $field->description . "</div>"; } } else { $max_size = $this->_form->max_upload_file_size(); if ($field->max_bytes) { $max_size = min($field->max_bytes, $max_size); } $desc = 'Maximum file size is ' . file_size_as_text($max_size) . '. '; $saved_desc = $options->extra_description; $options->extra_description .= $desc; $Result = $this->_text_line_as_html($id, 'file', $options); $options->extra_description = $saved_desc; } $this->_num_controls[$id] += 1; return $Result; }