Exemplo n.º 1
0
 /**
  * Import some metadata into the database (if avialable)
  * 
  * @class flagAdmin
  * @param array|int $imagesIds
  * @return bool
  */
 static function import_MetaData($imagesIds)
 {
     global $wpdb;
     require_once FLAG_ABSPATH . 'lib/image.php';
     if (!is_array($imagesIds)) {
         $imagesIds = array($imagesIds);
     }
     foreach ($imagesIds as $imageID) {
         $image = flagdb::find_image($imageID);
         if (!$image->error) {
             $meta = flagAdmin::get_MetaData($image->pid);
             // get the title
             $alttext = empty($meta['title']) ? $image->alttext : $meta['title'];
             // get the caption / description field
             $description = empty($meta['caption']) ? $image->description : $meta['caption'];
             // get the file date/time from exif
             $timestamp = $meta['timestamp'];
             // update database
             $result = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->flagpictures} SET alttext = %s, description = %s, imagedate = %s WHERE pid = %d", $alttext, $description, $timestamp, $image->pid));
             if ($result === false) {
                 return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not update data base)', 'flag') . '</strong>';
             }
             //this flag will inform us the import is already one time performed
             $meta['common']['saved'] = true;
             $result = flagdb::update_image_meta($image->pid, $meta['common']);
             if ($result === false) {
                 return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not update meta data)', 'flag') . '</strong>';
             }
         } else {
             return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not find image)', 'flag') . '</strong>';
         }
         // error check
     }
     return '1';
 }