/** * insert * This takes the string representation of an image and inserts it into * the database. You must also pass the mime type. * @param string $source * @param string $mime * @return boolean */ public function insert($source, $mime = '') { // Disabled in demo mode cause people suck and upload p**n if (AmpConfig::get('demo_mode')) { return false; } // Check to make sure we like this image if (!self::test_image($source)) { debug_event('Art', 'Not inserting image, invalid data passed', 1); return false; } // Default to image/jpeg if they don't pass anything $mime = $mime ? $mime : 'image/jpeg'; // Blow it away! $this->reset(); if (AmpConfig::get('write_id3_art')) { if ($this->type == 'album') { $album = new Album($this->uid); debug_event('Art', 'Inserting image Album ' . $album->name . ' on songs.', 5); $songs = $album->get_songs(); foreach ($songs as $song_id) { $song = new Song($song_id); $song->format(); $id3 = new vainfo($song->file); $data = $id3->read_id3(); if (isset($data['tags']['id3v2'])) { $image_from_tag = ''; if (isset($data['id3v2']['APIC'][0]['data'])) { $image_from_tag = $data['id3v2']['APIC'][0]['data']; } if ($image_from_tag != $source) { $ndata = array(); $ndata['APIC']['data'] = $source; $ndata['APIC']['mime'] = $mime; $ndata = array_merge($ndata, $song->get_metadata()); $id3->write_id3($ndata); Catalog::update_media_from_tags($song); } } } } } $dimensions = Core::image_dimensions($source); $width = intval($dimensions['width']); $height = intval($dimensions['height']); $sizetext = 'original'; if (!self::check_dimensions($dimensions)) { return false; } if (AmpConfig::get('album_art_store_disk')) { self::write_to_dir($source, $sizetext, $this->type, $this->uid, $this->kind); $source = null; } // Insert it! $sql = "INSERT INTO `image` (`image`, `mime`, `size`, `width`, `height`, `object_type`, `object_id`, `kind`) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"; Dba::write($sql, array($source, $mime, $sizetext, $width, $height, $this->type, $this->uid, $this->kind)); return true; }
/** * write_id3 * Write the current song id3 metadata to the file */ public function write_id3() { if (AmpConfig::get('write_id3')) { $catalog = Catalog::create_from_id($this->catalog); if ($catalog->get_type() == 'local') { debug_event('song', 'Writing id3 metadata to file ' . $this->file, 5); $meta = $this->get_metadata(); if (self::isCustomMetadataEnabled()) { foreach ($this->getMetadata() as $metadata) { $meta[$metadata->getField()->getName()] = $metadata->getData(); } } $id3 = new vainfo($this->file); $id3->write_id3($meta); Catalog::update_media_from_tags($this); } } }