public function render_inputs($details = array()) { $Perch = Perch::fetch(); $Bucket = PerchResourceBuckets::get($this->Tag->bucket()); if (!class_exists('PerchAssets_Assets', false)) { include_once PERCH_CORE . '/apps/assets/PerchAssets_Assets.class.php'; include_once PERCH_CORE . '/apps/assets/PerchAssets_Asset.class.php'; } $s = $this->Form->image($this->Tag->input_id()); $s .= $this->Form->hidden($this->Tag->input_id() . '_field', '1'); $assetID = false; $asset_field = $this->Tag->input_id() . '_assetID'; if (isset($details[$this->Tag->input_id()]['assetID'])) { $assetID = $details[$this->Tag->input_id()]['assetID']; } $s .= $this->Form->hidden($asset_field, $assetID); $Bucket->initialise(); if (!$Bucket->ready_to_write()) { $s .= $this->Form->hint(PerchLang::get('Your resources folder is not writable. Make this folder (') . PerchUtil::html($Bucket->get_web_path()) . PerchLang::get(') writable to upload files.'), 'error'); } if (isset($details[$this->Tag->input_id()]) && $details[$this->Tag->input_id()] != '') { $json = $details[$this->Tag->input_id()]; //PerchUtil::debug($json); if (isset($json['bucket'])) { $Bucket = PerchResourceBuckets::get($json['bucket']); } if (is_array($json) && isset($json['path'])) { $path = $json['path']; } else { if (!is_array($json)) { $path = $json; } else { $path = '--false--'; } } $file_path = PerchUtil::file_path($Bucket->get_file_path() . '/' . $path); if (!file_exists($file_path) && $assetID) { $Assets = new PerchAssets_Assets(); $Asset = $Assets->find($assetID); if (is_object($Asset)) { $file_path = $Asset->file_path(); } } else { $Asset = false; } if (isset($json['sizes']['thumb'])) { $image_src = $json['sizes']['thumb']['path']; $image_w = $json['sizes']['thumb']['w']; $image_h = $json['sizes']['thumb']['h']; $image_path = PerchUtil::file_path($Bucket->get_file_path() . '/' . $image_src); $thumb = true; } else { $thumb = false; } if (file_exists($file_path)) { $s .= '<div class="asset-badge" data-for="' . $asset_field . '">'; $type = PerchAssets_Asset::get_type_from_filename($path); $s .= '<div class="asset-badge-thumb asset-icon icon asset-' . $type . '">'; if ($thumb) { $s .= '<img src="' . PerchUtil::html($Bucket->get_web_path() . '/' . $image_src) . '" width="' . $image_w . '" height="' . $image_h . '" alt="Preview" />'; } $s .= '</div><div class="asset-badge-meta">'; if (!$this->Tag->is_set('app_mode')) { $s .= '<div class="asset-badge-remove">'; $s .= $this->Form->label($this->Tag->input_id() . '_remove', PerchLang::get('Remove'), 'inline') . ' '; $s .= $this->Form->checkbox($this->Tag->input_id() . '_remove', '1', 0); $s .= '</div>'; } if ($json) { $s .= '<ul class="meta">'; $s .= '<li class="title">'; if ($Asset) { $s .= '<a href="' . $Asset->web_path() . '">'; } $s .= isset($json['title']) ? $json['title'] : str_replace(PERCH_RESPATH . '/', '', $path); if ($Asset) { $s .= '</a>'; } $s .= '</li>'; if (isset($json['mime'])) { $s .= '<li>' . ucfirst(str_replace('/', ' / ', $json['mime'])) . '</li>'; } $size = floatval($json['size']); if ($size < 1048576) { $size = round($size / 1024, 0) . 'KB'; } else { $size = round($size / 1024 / 1024, 0) . 'MB'; } $s .= '<li>' . $size . '</li>'; $s .= '</ul>'; } $s .= '</div>'; $s .= '</div>'; } } else { $s .= '<div class="asset-badge hidden" data-for="' . $asset_field . '">'; $s .= '</div>'; } if (isset($file_path) && file_exists($file_path)) { $s .= $this->Form->hidden($this->Tag->input_id() . '_populated', '1'); } $type = 'doc'; if ($this->Tag->file_type()) { $type = $this->Tag->file_type(); } $s .= ' <span class="ft-choose-asset ft-file ' . ($this->Tag->disable_asset_panel() ? ' assets-disabled' : '') . '" data-type="' . $type . '" data-field="' . $asset_field . '" data-bucket="' . PerchUtil::html($Bucket->get_name(), true) . '" data-input="' . $this->Tag->input_id() . '"></span>'; return $s; }
$Tag->set('input_id', 'file'); $API = new PerchAPI(1.0, 'redactorjs'); if (isset($_GET['filetype']) && $_GET['filetype'] == 'image') { $is_image = true; $Tag->set('type', 'image'); } else { $is_image = false; $Tag->set('type', 'file'); } /* -------- GET THE RESOURCE BUCKET TO USE ---------- */ $bucket_name = 'default'; if (isset($_POST['bucket']) && $_POST['bucket'] != '') { $bucket_name = $_POST['bucket']; } $Tag->set('bucket', $bucket_name); $Bucket = PerchResourceBuckets::get($bucket_name); $Bucket->initialise(); if ($is_image) { $width = 800; if (isset($_POST['width']) && $_POST['width'] != '') { $width = (int) $_POST['width']; } $Tag->set('width', $width); $height = false; if (isset($_POST['height']) && $_POST['height'] != '') { $height = (int) $_POST['height']; } $Tag->set('height', $height); $crop = false; if (isset($_POST['crop']) && $_POST['crop'] == 'true') { $crop = true;
/** * Get the (cached) resource bucket details * @return [type] [description] */ public function get_bucket() { if ($this->Bucket) { return $this->Bucket; } $this->Bucket = PerchResourceBuckets::get($this->resourceBucket()); return $this->Bucket; }