Ejemplo n.º 1
0
 public function upload_avatar()
 {
     $upload = array();
     if (!empty($_FILES['avatar']['tmp_name']) && $_FILES['avatar']['size'] <= AmpConfig::get('max_upload_size')) {
         $path_info = pathinfo($_FILES['avatar']['name']);
         $upload['file'] = $_FILES['avatar']['tmp_name'];
         $upload['mime'] = 'image/' . $path_info['extension'];
         $image_data = Art::get_from_source($upload, 'user');
         if ($image_data) {
             $art = new Art($this->id, 'user');
             $art->insert($image_data, $upload['0']['mime']);
         }
     }
 }
Ejemplo n.º 2
0
            // Store the results for further use
            $_SESSION['form']['images'] = $images;
            require_once AmpConfig::get('prefix') . '/templates/show_arts.inc.php';
        } else {
            show_confirmation(T_('Art Not Located'), T_('Art could not be located at this time. This may be due to write access error, or the file is not received correctly.'), $burl);
        }
        require_once AmpConfig::get('prefix') . '/templates/show_get_art.inc.php';
        break;
    case 'select_art':
        /* Check to see if we have the image url still */
        $image_id = $_REQUEST['image'];
        // Prevent the script from timing out
        set_time_limit(0);
        $image = Art::get_from_source($_SESSION['form']['images'][$image_id], 'album');
        $mime = $_SESSION['form']['images'][$image_id]['mime'];
        // Special case for albums, I'm not sure if we should keep it, remove it or find a generic way
        if ($object_type == 'album') {
            $album = new $object_type($object_id);
            $album_groups = $album->get_group_disks_ids();
            foreach ($album_groups as $a_id) {
                $art = new Art($a_id, $object_type);
                $art->insert($image, $mime);
            }
        } else {
            $art = new Art($object_id, $object_type);
            $art->insert($image, $mime);
        }
        header("Location:" . $burl);
        break;
}
UI::show_footer();
Ejemplo n.º 3
0
 public static function library_metadata($params)
 {
     $r = Plex_XML_Data::createLibContainer();
     $n = count($params);
     $litem = null;
     $createMode = $_SERVER['REQUEST_METHOD'] == 'POST';
     $editMode = $_SERVER['REQUEST_METHOD'] == 'PUT';
     if ($n > 0) {
         $key = $params[0];
         $id = Plex_XML_Data::getAmpacheId($key);
         if ($editMode) {
             self::check_access(50);
         }
         if ($n == 1) {
             // Should we check that files still exists here?
             $checkFiles = $_REQUEST['checkFiles'];
             $extra = $_REQUEST['includeExtra'];
             if (Plex_XML_Data::isArtist($key)) {
                 $litem = new Artist($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name', 'summary' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addArtist($r, $litem);
             } elseif (Plex_XML_Data::isAlbum($key)) {
                 $litem = new Album($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name', 'year' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addAlbum($r, $litem);
             } elseif (Plex_XML_Data::isTrack($key)) {
                 $litem = new Song($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addSong($r, $litem);
             } elseif (Plex_XML_Data::isTVShow($key)) {
                 $litem = new TVShow($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name', 'year' => null, 'summary' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addTVShow($r, $litem);
             } elseif (Plex_XML_Data::isTVShowSeason($key)) {
                 $litem = new TVShow_Season($id);
                 $litem->format();
                 Plex_XML_Data::addTVShowSeason($r, $litem);
             } elseif (Plex_XML_Data::isVideo($key)) {
                 $litem = Video::create_from_id($id);
                 if ($editMode) {
                     $dmap = array('title' => null, 'year' => null, 'originallyAvailableAt' => 'release_date', 'originalTitle' => 'original_name', 'summary' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 $litem->format();
                 $subtype = strtolower(get_class($litem));
                 if ($subtype == 'tvshow_episode') {
                     Plex_XML_Data::addEpisode($r, $litem, true);
                 } elseif ($subtype == 'movie') {
                     Plex_XML_Data::addMovie($r, $litem, true);
                 }
             } elseif (Plex_XML_Data::isPlaylist($key)) {
                 $litem = new Playlist($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name');
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addPlaylist($r, $litem);
             }
         } else {
             $subact = $params[1];
             if ($subact == "children") {
                 if (Plex_XML_Data::isArtist($key)) {
                     $litem = new Artist($id);
                     $litem->format();
                     Plex_XML_Data::setArtistRoot($r, $litem);
                 } else {
                     if (Plex_XML_Data::isAlbum($key)) {
                         $litem = new Album($id);
                         $litem->format();
                         Plex_XML_Data::setAlbumRoot($r, $litem);
                     } else {
                         if (Plex_XML_Data::isTVShow($key)) {
                             $litem = new TVShow($id);
                             $litem->format();
                             Plex_XML_Data::setTVShowRoot($r, $litem);
                         } else {
                             if (Plex_XML_Data::isTVShowSeason($key)) {
                                 $litem = new TVShow_Season($id);
                                 $litem->format();
                                 Plex_XML_Data::setTVShowSeasonRoot($r, $litem);
                             }
                         }
                     }
                 }
             } elseif ($subact == "thumbs" || $subact == "posters" || $subact == "arts" || $subact == 'backgrounds') {
                 $kind = Plex_XML_Data::getPhotoKind($subact);
                 if ($createMode) {
                     // Upload art
                     $litem = Plex_XML_Data::createLibraryItem($key);
                     if ($litem != null) {
                         $uri = Plex_XML_Data::getMetadataUri($key) . '/' . Plex_XML_Data::getPhotoPlexKind($kind) . '/' . $key;
                         if (is_a($litem, 'video')) {
                             $type = 'video';
                         } else {
                             $type = get_class($litem);
                         }
                         $art = new Art($litem->id, $type, $kind);
                         $raw = file_get_contents("php://input");
                         $art->insert($raw);
                         header('Content-Type: text/html');
                         echo $uri;
                         exit;
                     }
                 }
                 Plex_XML_Data::addPhotos($r, $key, $kind);
             } elseif ($subact == "thumb" || $subact == "poster" || $subact == "art" || $subact == "background") {
                 if ($n == 3) {
                     $kind = Plex_XML_Data::getPhotoKind($subact);
                     // Ignore art id as we can only have 1 thumb
                     $art = null;
                     if (Plex_XML_Data::isArtist($key)) {
                         $art = new Art($id, "artist", $kind);
                     } else {
                         if (Plex_XML_Data::isAlbum($key)) {
                             $art = new Art($id, "album", $kind);
                         } else {
                             if (Plex_XML_Data::isTrack($key)) {
                                 $art = new Art($id, "song", $kind);
                             } else {
                                 if (Plex_XML_Data::isTVShow($key)) {
                                     $art = new Art($id, "tvshow", $kind);
                                 } else {
                                     if (Plex_XML_Data::isTVShowSeason($key)) {
                                         $art = new Art($id, "tvshow_season", $kind);
                                     } else {
                                         if (Plex_XML_Data::isVideo($key)) {
                                             $art = new Art($id, "video", $kind);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($art != null) {
                         $art->get_db();
                         ob_clean();
                         if (!isset($size)) {
                             self::setHeader($art->raw_mime);
                             echo $art->raw;
                         } else {
                             $dim = array();
                             $dim['width'] = $size;
                             $dim['height'] = $size;
                             $thumb = $art->get_thumb($dim);
                             self::setHeader($art->thumb_mime);
                             echo $thumb['thumb'];
                         }
                         exit;
                     }
                 }
             }
         }
     }
     if ($litem != null) {
         $catalog_ids = $litem->get_catalogs();
         if (count($catalog_ids) > 0) {
             $catalog = Catalog::create_from_id($catalog_ids[0]);
             Plex_XML_Data::addCatalogIdentity($r, $catalog);
         }
     }
     Plex_XML_Data::setContainerSize($r);
     self::apiOutputXml($r->asXML());
 }
Ejemplo n.º 4
0
 /**
  * gather_art
  *
  * This runs through all of the albums and finds art for them
  * This runs through all of the needs art albums and trys
  * to find the art for them from the mp3s
  */
 public function gather_art()
 {
     // Make sure they've actually got methods
     $art_order = AmpConfig::get('art_order');
     if (!count($art_order)) {
         debug_event('gather_art', 'art_order not set, Catalog::gather_art aborting', 3);
         return true;
     }
     // Prevent the script from timing out
     set_time_limit(0);
     $search_count = 0;
     $albums = $this->get_album_ids();
     // Run through them and get the art!
     foreach ($albums as $album_id) {
         $art = new Art($album_id, 'album');
         $album = new Album($album_id);
         // We're going to need the name here
         $album->format();
         debug_event('gather_art', 'Gathering art for ' . $album->name, 5);
         $options = array('album_name' => $album->full_name, 'artist' => $album->artist_name, 'keyword' => $album->artist_name . ' ' . $album->full_name);
         $results = $art->gather($options, 1);
         if (count($results)) {
             // Pull the string representation from the source
             $image = Art::get_from_source($results[0], 'album');
             if (strlen($image) > '5') {
                 $art->insert($image, $results[0]['mime']);
                 // If they've enabled resizing of images generate a thumbnail
                 if (AmpConfig::get('resize_images')) {
                     $thumb = $art->generate_thumb($image, array('width' => 275, 'height' => 275), $results[0]['mime']);
                     if (is_array($thumb)) {
                         $art->save_thumb($thumb['thumb'], $thumb['thumb_mime'], '275x275');
                     }
                 }
             } else {
                 debug_event('gather_art', 'Image less than 5 chars, not inserting', 3);
             }
         }
         // Stupid little cutesie thing
         $search_count++;
         if (UI::check_ticker()) {
             UI::update_text('count_art_' . $this->id, $search_count);
             UI::update_text('read_art_' . $this->id, scrub_out($album->name));
         }
         unset($found);
     }
     // foreach albums
     // One last time for good measure
     UI::update_text('count_art_' . $this->id, $search_count);
 }
Ejemplo n.º 5
0
 /**
  *
  * @param string $type
  * @param int $id
  */
 public function gather_art_item($type, $id)
 {
     debug_event('gather_art', 'Gathering art for ' . $type . '/' . $id . '...', 5);
     // Should be more generic !
     if ($type == 'video') {
         $libitem = Video::create_from_id($id);
     } else {
         $libitem = new $type($id);
     }
     $options = array();
     $libitem->format();
     if ($libitem->id) {
         if (count($options) == 0) {
             // Only search on items with default art kind as `default`.
             if ($libitem->get_default_art_kind() == 'default') {
                 $keywords = $libitem->get_keywords();
                 $keyword = '';
                 foreach ($keywords as $key => $word) {
                     $options[$key] = $word['value'];
                     if ($word['important']) {
                         if (!empty($word['value'])) {
                             $keyword .= ' ' . $word['value'];
                         }
                     }
                 }
                 $options['keyword'] = $keyword;
             }
             $parent = $libitem->get_parent();
             if ($parent != null) {
                 if (!Art::has_db($parent['object_id'], $parent['object_type'])) {
                     $this->gather_art_item($parent['object_type'], $parent['object_id']);
                 }
             }
         }
     }
     $art = new Art($id, $type);
     $results = $art->gather($options, 1);
     if (count($results)) {
         // Pull the string representation from the source
         $image = Art::get_from_source($results[0], $type);
         if (strlen($image) > '5') {
             $art->insert($image, $results[0]['mime']);
             // If they've enabled resizing of images generate a thumbnail
             if (AmpConfig::get('resize_images')) {
                 $size = array('width' => 275, 'height' => 275);
                 $thumb = $art->generate_thumb($image, $size, $results[0]['mime']);
                 if (is_array($thumb)) {
                     $art->save_thumb($thumb['thumb'], $thumb['thumb_mime'], $size);
                 }
             }
         } else {
             debug_event('gather_art', 'Image less than 5 chars, not inserting', 3);
         }
     }
     if ($type == 'video' && AmpConfig::get('generate_video_preview')) {
         Video::generate_preview($id);
     }
     if (UI::check_ticker()) {
         UI::update_text('read_art_' . $this->id, $libitem->get_fullname());
     }
 }
Ejemplo n.º 6
0
 /**
  * get_artist_info
  * Returns artist information
  */
 public static function get_artist_info($artist_id, $fullname = '')
 {
     $artist = null;
     if ($artist_id) {
         $artist = new Artist($artist_id);
         $artist->format();
         $fullname = $artist->f_full_name;
         // Data newer than 6 months, use it
         if ($artist->last_update + 15768000 > time()) {
             $results = array();
             $results['summary'] = $artist->summary;
             $results['placeformed'] = $artist->placeformed;
             $results['yearformed'] = $artist->yearformed;
             $results['largephoto'] = Art::url($artist->id, 'artist');
             $results['megaphoto'] = $results['largephoto'];
             return $results;
         }
     }
     $query = 'artist=' . rawurlencode($fullname);
     $xml = self::get_lastfm_results('artist.getinfo', $query);
     $results = array();
     $results['summary'] = strip_tags(preg_replace("#<a href=([^<]*)Last\\.fm</a>.#", "", (string) $xml->artist->bio->summary));
     $results['placeformed'] = (string) $xml->artist->bio->placeformed;
     $results['yearformed'] = (string) $xml->artist->bio->yearformed;
     $results['largephoto'] = $xml->artist->image[2];
     $results['megaphoto'] = $xml->artist->image[4];
     if ($artist) {
         if (!empty($results['summary']) || !empty($results['megaphoto'])) {
             $artist->update_artist_info($results['summary'], $results['placeformed'], $results['yearformed']);
             $image = Art::get_from_source(array('url' => $results['megaphoto']), 'artist');
             $rurl = pathinfo($results['megaphoto']);
             $mime = 'image/' . $rurl['extension'];
             $art = new Art($artist->id, 'artist');
             $art->reset();
             $art->insert($image, $mime);
             $results['largephoto'] = Art::url($artist->id, 'artist');
             $results['megaphoto'] = $results['largephoto'];
         }
     }
     return $results;
 }
Ejemplo n.º 7
0
 public static function generate_preview($video_id, $overwrite = false)
 {
     if ($overwrite || !Art::has_db($video_id, 'video', 'preview')) {
         $artp = new Art($video_id, 'video', 'preview');
         $video = new Video($video_id);
         $image = Stream::get_image_preview($video);
         $artp->insert($image, 'image/png');
     }
 }