示例#1
0
function perch_gallery_images($opts = array(), $return = false)
{
    $default_opts = array('template' => 'e_list_image.html', 'skip-template' => false);
    $opts = array_merge($default_opts, $opts);
    if ($opts['skip-template']) {
        $return = true;
    }
    $API = new PerchAPI(1.0, 'perch_gallery');
    $Images = new PerchGallery_Images($API);
    $Versions = new PerchGallery_ImageVersions();
    $Versions->preload_all();
    $list = $Images->get_custom(false, $opts, $Versions);
    if (is_array($list)) {
        if ($opts['skip-template']) {
            return $list;
        }
        $Template = $API->get('Template');
        $Template->set('gallery/' . $opts['template'], 'gallery');
        $r = $Template->render_group($list, true);
        if ($return) {
            return $r;
        }
        echo $r;
    }
    return false;
}
 /**
  * Take the original uploaded file and make all the different versions, based on the given template.
  *
  * @param string $filename 
  * @param string $Template 
  * @return void
  * @author Drew McLellan
  */
 public function process_versions($filename, $Template, $bucket)
 {
     $this->delete_versions();
     $result = false;
     $image_file = PerchUtil::file_path($bucket['file_path'] . '/' . $filename);
     PerchUtil::debug('123: ' . $image_file);
     if (!file_exists($image_file)) {
         return false;
     }
     $API = new PerchAPI(1.0, 'perch_gallery');
     $Image = $API->get('Image');
     $Versions = new PerchGallery_ImageVersions();
     $tags = $Template->find_all_tags();
     $Perch = Perch::fetch();
     if (!is_array($tags)) {
         $tags = array();
     }
     // add defaults we need for admin
     $tags[] = new PerchXMLTag('<perch:gallery id="image" type="image" />');
     // default full size
     $tags[] = new PerchXMLTag('<perch:gallery id="image" type="image" width="80" height="80" crop="true" key="admin_thumb" />');
     // admin thumb
     $tags[] = new PerchXMLTag('<perch:gallery id="image" type="image" width="180" key="admin_preview" />');
     // admin preview
     if (PerchUtil::count($tags)) {
         foreach ($tags as $Tag) {
             if ($Tag->id() == 'image' && $Tag->type() == 'image') {
                 //$bucket = $Perch->get_resource_bucket($Tag->bucket());
                 $Image->reset_defaults();
                 if ($Tag->quality()) {
                     $Image->set_quality($Tag->quality());
                 }
                 if ($Tag->sharpen()) {
                     $Image->set_sharpening($Tag->sharpen());
                 }
                 if ($Tag->density()) {
                     $Image->set_density($Tag->density());
                 }
                 if ($Tag->width() || $Tag->height()) {
                     $details = $Image->resize_image($image_file, $Tag->width(), $Tag->height(), $Tag->crop());
                 } else {
                     $details = array();
                     $details['file_name'] = $filename;
                     PerchUtil::debug('152: ' . $filename);
                     $info = getimagesize($image_file);
                     if (is_array($info)) {
                         $details['w'] = $info[0];
                         $details['h'] = $info[1];
                     }
                 }
                 if ($details) {
                     $data = array();
                     $data['imageID'] = $this->id();
                     if (strpos($details['file_name'], DIRECTORY_SEPARATOR) !== false) {
                         $parts = explode(DIRECTORY_SEPARATOR, $details['file_name']);
                         $details['file_name'] = array_pop($parts);
                     }
                     $data['versionPath'] = $details['file_name'];
                     //PerchUtil::debug('167: '. $details['file_name']);
                     if ($Tag->key()) {
                         $data['versionKey'] = $Tag->key();
                     } else {
                         $data['versionKey'] = $this->_generate_version_key($Tag->width(), $Tag->height());
                     }
                     if ($Tag->crop()) {
                         $data['versionWidth'] = $Tag->width();
                         $data['versionHeight'] = $Tag->height();
                     } else {
                         $data['versionWidth'] = $details['w'];
                         $data['versionHeight'] = $details['h'];
                     }
                     $Version = $Versions->create($data);
                     if (is_object($Version)) {
                         $result = true;
                     }
                 }
             }
         }
     }
     return $result;
 }
 public function get_recent_for_dashboard($count = 4)
 {
     $sql = 'SELECT * FROM ' . $this->table . ' 
             ORDER BY imageID DESC LIMIT ' . $count;
     $rows = $this->db->get_rows($sql);
     if (PerchUtil::count($rows)) {
         $PerchGallery_ImageVersions = new PerchGallery_ImageVersions();
         for ($i = 0; $i < count($rows); $i++) {
             /* loop though versions array */
             $Version = $PerchGallery_ImageVersions->get_by_key($rows[$i]['imageID'], 'admin_preview');
             $rows[$i]['image_admin_preview'] = $Version;
         }
     }
     return $this->return_instances($rows);
 }