$current_view = $view == 'grid' ? 'grid' : 'list'; echo PerchUtil::html(http_build_query($opts), true); ?> " class="set asset-view-mode <?php echo $current_view; ?> "><?php echo PerchLang::get('View'); ?> </a></li> <?php // Type filter $types = $Assets->get_available_types(); if (PerchUtil::count($types)) { $items = array(); $group_types = PerchAssets_Asset::get_type_map(); foreach ($group_types as $type => $val) { $items[] = array('arg' => 'type', 'val' => $type, 'label' => $val['label'], 'path' => $base_path); } foreach ($types as $type) { $items[] = array('arg' => 'type', 'val' => $type, 'label' => strtoupper($type), 'path' => $base_path); } echo PerchUtil::smartbar_filter('type', 'By Asset Type', 'Filtered by type ‘%s’', $items, 'asset-icon asset-type', $Alert, "You are viewing assets filtered by type ‘%s’", $base_path); } // Bucket filter $buckets = $Assets->get_available_buckets(); if (PerchUtil::count($buckets)) { $items = array(); foreach ($buckets as $bucket) { $items[] = array('arg' => 'bucket', 'val' => $bucket, 'label' => ucfirst($bucket), 'path' => $base_path); }
public function search($term, $filters) { $term = trim($term); $tag = PerchUtil::urlify($term); $Tags = new PerchAssets_Tags(); $Tag = $Tags->get_one_by('tagSlug', $tag); $sql = 'SELECT * FROM ('; $filter_sql = ''; if (PerchUtil::count($filters)) { foreach ($filters as $filter => $filter_value) { switch ($filter) { case 'bucket': $filter_sql .= ' AND r.resourceBucket=' . $this->db->pdb($filter_value) . ' '; break; case 'app': $filter_sql .= ' AND r.resourceApp=' . $this->db->pdb($filter_value) . ' '; break; case 'type': $type_map = PerchAssets_Asset::get_type_map(); if (array_key_exists($filter_value, $type_map)) { $filter_sql .= ' AND r.resourceType IN (' . $this->db->implode_for_sql_in($type_map[$filter_value]['exts']) . ') '; } else { $filter_sql .= ' AND r.resourceType=' . $this->db->pdb($filter_value) . ' '; } break; case 'date': $ts = strtotime($filter_value); $filter_sql .= ' AND r.resourceCreated BETWEEN ' . $this->db->pdb(date('Y-m-d 00:00:00', $ts)) . ' AND ' . $this->db->pdb(date('Y-m-d 25:59:59', $ts)) . ' '; break; } } } if ($Tag) { $sql .= 'SELECT r.*, 0.5 AS score, r2.resourceFile AS thumb, r2.resourceWidth AS thumbWidth, r2.resourceHeight AS thumbHeight, r2.resourceDensity AS thumbDensity FROM ' . PERCH_DB_PREFIX . 'resources r LEFT OUTER JOIN ' . PERCH_DB_PREFIX . 'resources r2 ON r2.resourceParentID=r.resourceID AND r2.resourceKey=\'thumb\' AND r2.resourceAWOL!=1 JOIN ' . PERCH_DB_PREFIX . 'resources_to_tags r2t ON r.resourceID=r2t.resourceID AND r2t.tagID=' . $Tag->id() . ' WHERE r.resourceAWOL=0 AND r.resourceKey=\'orig\' ' . $filter_sql . ' UNION ALL '; } $sql .= 'SELECT r.*, MATCH(r.resourceTitle) AGAINST(' . $this->db->pdb($term) . ') AS score, r2.resourceFile AS thumb, r2.resourceWidth AS thumbWidth, r2.resourceHeight AS thumbHeight, r2.resourceDensity AS thumbDensity FROM ' . PERCH_DB_PREFIX . 'resources r LEFT OUTER JOIN ' . PERCH_DB_PREFIX . 'resources r2 ON r2.resourceParentID=r.resourceID AND r2.resourceKey=\'thumb\' AND r2.resourceAWOL!=1 WHERE MATCH(r.resourceTitle) AGAINST(' . $this->db->pdb($term) . ') AND r.resourceKey=\'orig\' ' . $filter_sql . ' ORDER BY score DESC, resourceUpdated DESC'; $sql .= ') AS t GROUP BY resourceID'; return $this->return_instances($this->db->get_rows($sql)); }
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; }