/** * Import some meta data into the database (if avialable) * * @class nggAdmin * @param array|int $imagesIds * @return string result code */ function import_MetaData($imagesIds) { global $wpdb; require_once NGGALLERY_ABSPATH . '/lib/image.php'; if (!is_array($imagesIds)) { $imagesIds = array($imagesIds); } foreach ($imagesIds as $imageID) { $image = nggdb::find_image($imageID); if (!$image->error) { $meta = nggAdmin::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']; // first update database $result = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggpictures} SET \r\n\t\t\t\t\t\talttext = %s, \r\n\t\t\t\t\t\tdescription = %s, \r\n\t\t\t\t\t\timagedate = %s\r\n\t\t\t\t\tWHERE pid = %d", $alttext, $description, $timestamp, $image->pid)); if ($result === false) { return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not update data base)', 'nggallery') . '</strong>'; } //this flag will inform us that the import is already one time performed $meta['common']['saved'] = true; $result = nggdb::update_image_meta($image->pid, $meta['common']); if ($result === false) { return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not update meta data)', 'nggallery') . '</strong>'; } // add the tags if we found some if ($meta['keywords']) { $taglist = explode(',', $meta['keywords']); wp_set_object_terms($image->pid, $taglist, 'ngg_tag'); } } else { return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not find image)', 'nggallery') . '</strong>'; } // error check } return '1'; }
function import_MetaData($imagesIds) { // add images to database global $wpdb; require_once NGGALLERY_ABSPATH . '/lib/image.php'; if (!is_array($imagesIds)) { $imagesIds = array($imagesIds); } foreach ($imagesIds as $pic_id) { $picture = nggdb::find_image($pic_id); if (!$picture->error) { $meta = nggAdmin::get_MetaData($picture->imagePath); // get the title if (!($alttext = $meta['title'])) { $alttext = $picture->alttext; } // get the caption / description field if (!($description = $meta['caption'])) { $description = $picture->description; } // get the file date/time from exif $timestamp = $meta['timestamp']; // update database $result = $wpdb->query("UPDATE {$wpdb->nggpictures} SET alttext = '{$alttext}', description = '{$description}', imagedate = '{$timestamp}' WHERE pid = {$pic_id}"); // add the tags if ($meta['keywords']) { $taglist = explode(",", $meta['keywords']); wp_set_object_terms($pic_id, $taglist, 'ngg_tag'); } // add tags } // error check } // foreach return true; }