/**
  * @param FORM_RENDERER $renderer
  * @access private
  */
 protected function _draw_controls($renderer)
 {
     $renderer->start();
     if ($this->object_exists()) {
         /** @var ATTACHMENT $attachment */
         $attachment = $this->_object;
         $img = $attachment->icon_as_html(Thirty_two_px);
         if ($attachment->is_image) {
             $thumb = $attachment->thumbnail_as_html();
             if ($thumb) {
                 $img = $thumb;
             }
         }
         $renderer->start_row('Current file');
         echo '<div class="info-box-top"><p>' . $this->_object->original_file_name . '</p>';
         echo '<p>' . $this->_object->mime_type . ' (' . file_size_as_text($this->_object->size) . ')</p></div>';
         echo '<p>' . $img . '</p>';
         $renderer->finish_row();
         $renderer->draw_text_line_row('title');
         $renderer->draw_check_box_row('is_visible');
         $renderer->draw_text_box_row('description');
         if ($this->login->is_allowed(Privilege_set_attachment, Privilege_upload, $this->_folder)) {
             $renderer->start_block('Options');
             $renderer->draw_text_row(' ', 'Replacing the file for the attachment is optional; you can regenerate the thumbnail from the current image by clicking "Save" below.', 'notes');
             $this->_draw_file_controls($renderer);
             $renderer->finish_block();
         }
     } else {
         if ($this->login->is_allowed(Privilege_set_attachment, Privilege_upload, $this->_folder)) {
             $this->_draw_file_controls($renderer);
         }
         $renderer->draw_text_line_row('title');
         $renderer->draw_check_box_row('is_visible');
         $renderer->draw_text_box_row('description');
     }
     $renderer->draw_submit_button_row();
     $this->_draw_history_item_controls($renderer);
     $renderer->finish();
 }
    /**
     * Show all details for an object.
     * @param OBJECT_IN_FOLDER $obj
     * @access private
     */
    protected function _echo_header($obj)
    {
        ?>
  <table class="basic columns left-labels top">
    <?php 
        $this->_echo_details($obj);
        ?>
    <tr>
      <th>Location</th>
      <td>
        <?php 
        $this->_echo_folders($obj);
        ?>
      </td>
    </tr>
    <tr>
      <th>Size</th>
      <td>
      <?php 
        echo file_size_as_text($this->_size_of($obj));
        ?>
      </td>
    </tr>
  </table>
<?php 
    }
示例#3
0
 /**
  * Returns a readable version of the given size.
  * Translates to MB, KB, etc.
  * @param integer $size
  * @return string
  */
 public function size_as_text()
 {
     return file_size_as_text($this->size);
 }
 public function process_file($archive, $entry, $error_callback)
 {
     $this->_log('Found ' . $entry->name . ' (' . file_size_as_text($entry->size) . ')', Msg_type_info);
     $entry->extract_to($this->_temp_path, $error_callback);
 }
    /**
     * @param ATTACHMENT $obj
     * @access private
     */
    protected function _draw_box($obj)
    {
        $this->_display_start_overlay_commands($obj);
        ?>
  <a href="<?php 
        echo $obj->home_page_as_html();
        ?>
"><?php 
        if ($obj->is_image) {
            $thumb = $obj->thumbnail_as_html();
            if ($thumb) {
                echo $thumb;
            } else {
                echo $obj->icon_as_html(One_hundred_px);
            }
        } else {
            echo $obj->icon_as_html(One_hundred_px);
        }
        ?>
</a>
  <h3>
    <?php 
        echo $obj->title_as_html();
        ?>
  </h3>
  <p class="detail">
    <?php 
        echo $obj->mime_type . ' (' . file_size_as_text($obj->size) . ')';
        ?>
  </p>
  <div class="text-flow">
  <?php 
        echo $obj->description_as_html();
        ?>
  </div>
<?php 
        $this->_display_finish_overlay_commands();
    }
 /**
  * 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>';
 }
示例#7
0
 /**
  * @var FORM $form
  */
 public function validate($form)
 {
     parent::validate($form);
     if ($this->continue_validating($form)) {
         $idx = 0;
         /** @var UPLOADED_FILE_SET $file_value */
         $file_value = $this->_value;
         foreach ($file_value->files as $file) {
             if (!$file->is_valid()) {
                 if ($this->required || $file->error != Uploaded_file_error_missing) {
                     $form->record_error($this->id, $file->error_message(), $idx);
                 }
             } else {
                 if ($this->max_bytes && $file->size > $this->max_bytes) {
                     $form->record_error($this->id, "{$this->caption} can be at most " . file_size_as_text($this->max_bytes) . '.', $idx);
                 }
             }
             $idx += 1;
         }
     }
 }
 /**
  * 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;
 }