Example #1
0
 /**
  * flagAdmin::set_gallery_preview() - define a preview pic after the first upload, can be changed in the gallery settings
  * 
  * @class flagAdmin
  * @param int $galleryID
  * @return void
  */
 function set_gallery_preview($galleryID)
 {
     global $wpdb;
     $galleryID = intval($galleryID);
     $gallery = flagdb::find_gallery($galleryID);
     // in the case no preview image is setup, we do this now
     if ($gallery->previewpic == 0) {
         $firstImage = $wpdb->get_var($wpdb->prepare("SELECT `pid` FROM `{$wpdb->flagpictures}` WHERE `exclude` != 1 AND `galleryid` = '%d' ORDER by `pid` DESC limit 0,1", $galleryID));
         if ($firstImage) {
             $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->flaggallery}` SET `previewpic` = '%s' WHERE `gid` = '%d'", $firstImage, $galleryID));
             wp_cache_delete($galleryID, 'flag_gallery');
         }
     }
     return;
 }
Example #2
0
 /**
  * Get the last images registered in the database with a maximum number of $limit results
  *
  * @param integer $page
  * @param integer $limit
  * @param int $exclude
  * @param int $galleryId Only look for images with this gallery id, or in all galleries if id is 0
  * @param string $orderby
  * @param string $orderby is one of "id" (default, order by pid), "date" (order by exif date), sort (order by user sort order)
  * @return array
  */
 function find_last_images($page = 0, $limit = 30, $exclude = 0, $galleryId = 0, $orderby = "id")
 {
     /** @var $wpdb wpdb */
     global $wpdb;
     // Check for the exclude setting
     $exclude_clause = $exclude ? ' AND exclude<>1 ' : '';
     $offset = (int) $page * $limit;
     $galleryId = (int) $galleryId;
     $gallery_clause = $galleryId === 0 ? '' : ' AND galleryid = ' . $galleryId . ' ';
     // default order by pid
     $order = 'pid DESC';
     switch ($orderby) {
         case 'date':
             $order = 'imagedate DESC';
             break;
         case 'sort':
             $order = 'sortorder ASC';
             break;
     }
     $result = array();
     $gallery_cache = array();
     // Query database
     $images = $wpdb->get_results("SELECT * FROM {$wpdb->flagpictures} WHERE 1=1 {$exclude_clause} {$gallery_clause} ORDER BY {$order} LIMIT {$offset}, {$limit}");
     // Build the object from the query result
     if ($images) {
         foreach ($images as $key => $image) {
             // cache a gallery , so we didn't need to lookup twice
             if (!array_key_exists($image->galleryid, $gallery_cache)) {
                 $gallery_cache[$image->galleryid] = flagdb::find_gallery($image->galleryid);
             }
             // Join gallery information with picture information
             foreach ($gallery_cache[$image->galleryid] as $index => $value) {
                 $image->{$index} = $value;
             }
             // Now get the complete image data
             $result[$key] = new flagImage($image);
         }
     }
     return $result;
 }