예제 #1
0
파일: tag.class.php 프로젝트: nioc/ampache
 /**
  * get_tags
  * This is a non-object non type dependent function that just returns tags
  * we've got, it can take filters (this is used by the tag cloud)
  */
 public static function get_tags($type = '', $limit = 0, $order = 'count')
 {
     //debug_event('tag.class.php', 'Get tags list called...', '5');
     if (parent::is_cached('tags_list', 'no_name')) {
         //debug_event('tag.class.php', 'Tags list found into cache memory!', '5');
         return parent::get_from_cache('tags_list', 'no_name');
     }
     $results = array();
     $sql = "SELECT `tag_map`.`tag_id`, `tag`.`name`, `tag`.`is_hidden`, COUNT(`tag_map`.`object_id`) AS `count` " . "FROM `tag_map` " . "LEFT JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . "WHERE `tag`.`is_hidden` = false ";
     if (!empty($type)) {
         $sql .= "AND `tag_map`.`object_type` = '" . scrub_in($type) . "' ";
     }
     $order = "`" . $order . "`";
     if ($order == 'count') {
         $order .= " DESC";
     }
     $sql .= "GROUP BY `tag`.`name` ORDER BY " . $order;
     if ($limit > 0) {
         $sql .= " LIMIT {$limit}";
     }
     $db_results = Dba::read($sql);
     while ($row = Dba::fetch_assoc($db_results)) {
         $results[$row['tag_id']] = array('id' => $row['tag_id'], 'name' => $row['name'], 'is_hidden' => $row['is_hidden'], 'count' => $row['count']);
     }
     parent::add_to_cache('tags_list', 'no_name', $results);
     return $results;
 }
예제 #2
0
 /**
  * _get_extra info
  * This returns the extra information for the tv show, this means totals etc
  */
 private function _get_extra_info()
 {
     // Try to find it in the cache and save ourselves the trouble
     if (parent::is_cached('tvshow_extra', $this->id)) {
         $row = parent::get_from_cache('tvshow_extra', $this->id);
     } else {
         $sql = "SELECT COUNT(`tvshow_episode`.`id`) AS `episode_count`, `video`.`catalog` as `catalog_id` FROM `tvshow_season` " . "LEFT JOIN `tvshow_episode` ON `tvshow_episode`.`season` = `tvshow_season`.`id` " . "LEFT JOIN `video` ON `video`.`id` = `tvshow_episode`.`id` " . "WHERE `tvshow_season`.`tvshow` = ?";
         $db_results = Dba::read($sql, array($this->id));
         $row = Dba::fetch_assoc($db_results);
         $sql = "SELECT COUNT(`tvshow_season`.`id`) AS `season_count` FROM `tvshow_season` " . "WHERE `tvshow_season`.`tvshow` = ?";
         $db_results = Dba::read($sql, array($this->id));
         $row2 = Dba::fetch_assoc($db_results);
         $row['season_count'] = $row2['season_count'];
         parent::add_to_cache('tvshow_extra', $this->id, $row);
     }
     /* Set Object Vars */
     $this->episodes = $row['episode_count'];
     $this->seasons = $row['season_count'];
     $this->catalog_id = $row['catalog_id'];
     return $row;
 }
예제 #3
0
 /**
  * url
  * This returns the constructed URL for the art in question
  * @param int $uid
  * @param string $type
  * @param string $sid
  * @param int|null $thumb
  * @return string
  */
 public static function url($uid, $type, $sid = null, $thumb = null)
 {
     if (!Core::is_library_item($type)) {
         return null;
     }
     if (AmpConfig::get('use_auth') && AmpConfig::get('require_session')) {
         $sid = $sid ? scrub_out($sid) : scrub_out(session_id());
         if ($sid == null) {
             $sid = Session::create(array('type' => 'api'));
         }
     }
     $key = $type . $uid;
     if (parent::is_cached('art', $key . '275x275') && AmpConfig::get('resize_images')) {
         $row = parent::get_from_cache('art', $key . '275x275');
         $mime = $row['mime'];
     }
     if (parent::is_cached('art', $key . 'original')) {
         $row = parent::get_from_cache('art', $key . 'original');
         $thumb_mime = $row['mime'];
     }
     if (!isset($mime) && !isset($thumb_mime)) {
         $sql = "SELECT `object_type`, `object_id`, `mime`, `size` FROM `image` WHERE `object_type` = ? AND `object_id` = ?";
         $db_results = Dba::read($sql, array($type, $uid));
         while ($row = Dba::fetch_assoc($db_results)) {
             parent::add_to_cache('art', $key . $row['size'], $row);
             if ($row['size'] == 'original') {
                 $mime = $row['mime'];
             } else {
                 if ($row['size'] == '275x275' && AmpConfig::get('resize_images')) {
                     $thumb_mime = $row['mime'];
                 }
             }
         }
     }
     $mime = isset($thumb_mime) ? $thumb_mime : (isset($mime) ? $mime : null);
     $extension = self::extension($mime);
     if (AmpConfig::get('stream_beautiful_url')) {
         if (empty($extension)) {
             $extension = 'jpg';
         }
         $url = AmpConfig::get('web_path') . '/play/art/' . $sid . '/' . scrub_out($type) . '/' . scrub_out($uid) . '/thumb';
         if ($thumb) {
             $url .= $thumb;
         }
         $url .= '.' . $extension;
     } else {
         $url = AmpConfig::get('web_path') . '/image.php?object_id=' . scrub_out($uid) . '&object_type=' . scrub_out($type) . '&auth=' . $sid;
         if ($thumb) {
             $url .= '&thumb=' . $thumb;
         }
         if (!empty($extension)) {
             $name = 'art.' . $extension;
             $url .= '&name=' . $name;
         }
     }
     return $url;
 }
예제 #4
0
 /**
  * _get_info
  */
 private function _get_info()
 {
     $id = $this->id;
     if (parent::is_cached('song_preview', $id)) {
         return parent::get_from_cache('song_preview', $id);
     }
     $sql = 'SELECT `id`, `file`, `album_mbid`, `artist`, `artist_mbid`, `title`, `disk`, `track`, `mbid` ' . 'FROM `song_preview` WHERE `id` = ?';
     $db_results = Dba::read($sql, array($id));
     $results = Dba::fetch_assoc($db_results);
     if (!empty($results['id'])) {
         if (empty($results['artist_mbid'])) {
             $sql = 'SELECT `mbid` FROM `artist` WHERE `id` = ?';
             $db_results = Dba::read($sql, array($results['artist']));
             if ($artist_res = Dba::fetch_assoc($db_results)) {
                 $results['artist_mbid'] = $artist_res['mbid'];
             }
         }
         parent::add_to_cache('song_preview', $id, $results);
         return $results;
     }
     return false;
 }
예제 #5
0
 /**
  * get_average_rating
  * Get the floored average rating of what everyone has rated this object
  * as. This is shown if there is no personal rating.
  */
 public function get_average_rating()
 {
     if (parent::is_cached('rating_' . $this->type . '_all', $this->id)) {
         return parent::get_from_cache('rating_' . $this->type . '_user', $this->id);
     }
     $sql = "SELECT AVG(`rating`) as `rating` FROM `rating` WHERE " . "`object_id` = ? AND `object_type` = ?";
     $db_results = Dba::read($sql, array($this->id, $this->type));
     $results = Dba::fetch_assoc($db_results);
     parent::add_to_cache('rating_' . $this->type . '_all', $this->id, $results['rating']);
     return $results['rating'];
 }
예제 #6
0
 /**
  * Get missing artist data.
  * @param string $mbid
  * @return array
  */
 public static function get_missing_artist($mbid)
 {
     $wartist = array();
     if (parent::is_cached('missing_artist', $mbid)) {
         $wartist = parent::get_from_cache('missing_artist', $mbid);
     } else {
         $mb = new MusicBrainz(new RequestsHttpAdapter());
         $wartist['mbid'] = $mbid;
         $wartist['name'] = T_('Unknown Artist');
         try {
             $martist = $mb->lookup('artist', $mbid);
         } catch (Exception $e) {
             return $wartist;
         }
         $wartist['name'] = $martist->name;
         parent::add_to_cache('missing_artist', $mbid, $wartist);
     }
     $wartist['link'] = "<a href=\"" . AmpConfig::get('web_path') . "/artists.php?action=show_missing&mbid=" . $wartist['mbid'] . "\" title=\"" . $wartist['name'] . "\">" . $wartist['name'] . "</a>";
     return $wartist;
 }
예제 #7
0
 /**
  * get_catalogs
  * This returns the catalogs as an array of ids that this user is allowed to access
  */
 public function get_catalogs()
 {
     if (parent::is_cached('user_catalog', $this->id)) {
         return parent::get_from_cache('user_catalog', $this->id);
     }
     $sql = "SELECT * FROM `user_catalog` WHERE `user` = ?";
     $db_results = Dba::read($sql, array($this->id));
     $catalogs = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $catalogs[] = $row['catalog'];
     }
     parent::add_to_cache('user_catalog', $this->id, $catalogs);
     return $catalogs;
 }
예제 #8
0
 /**
  * get_tags
  * This is a non-object non type dependent function that just returns tags
  * we've got, it can take filters (this is used by the tag cloud)
  */
 public static function get_tags($limit = 0)
 {
     //debug_event('tag.class.php', 'Get tags list called...', '5');
     if (parent::is_cached('tags_list', 'no_name')) {
         //debug_event('tag.class.php', 'Tags list found into cache memory!', '5');
         return parent::get_from_cache('tags_list', 'no_name');
     }
     $results = array();
     $sql = "SELECT `tag_map`.`tag_id`, `tag`.`name`, COUNT(`tag_map`.`object_id`) AS `count` " . "FROM `tag_map` " . "LEFT JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . "GROUP BY `tag`.`name` ORDER BY `count` DESC ";
     if ($limit > 0) {
         $sql .= " LIMIT {$limit}";
     }
     $db_results = Dba::read($sql);
     while ($row = Dba::fetch_assoc($db_results)) {
         $results[$row['tag_id']] = array('id' => $row['tag_id'], 'name' => $row['name'], 'count' => $row['count']);
     }
     parent::add_to_cache('tags_list', 'no_name', $results);
     return $results;
 }
예제 #9
0
 /**
  * url
  * This returns the constructed URL for the art in question
  */
 public static function url($uid, $type, $sid = false)
 {
     $sid = $sid ? scrub_out($sid) : scrub_out(session_id());
     $type = self::validate_type($type);
     $key = $type . $uid;
     if (parent::is_cached('art', $key . '275x275') && AmpConfig::get('resize_images')) {
         $row = parent::get_from_cache('art', $key . '275x275');
         $mime = $row['mime'];
     }
     if (parent::is_cached('art', $key . 'original')) {
         $row = parent::get_from_cache('art', $key . 'original');
         $thumb_mime = $row['mime'];
     }
     if (!isset($mime) && !isset($thumb_mime)) {
         $sql = "SELECT `object_type`, `object_id`, `mime`, `size` FROM `image` WHERE `object_type` = ? AND `object_id` = ?";
         $db_results = Dba::read($sql, array($type, $uid));
         while ($row = Dba::fetch_assoc($db_results)) {
             parent::add_to_cache('art', $key . $row['size'], $row);
             if ($row['size'] == 'original') {
                 $mime = $row['mime'];
             } else {
                 if ($row['size'] == '275x275' && AmpConfig::get('resize_images')) {
                     $thumb_mime = $row['mime'];
                 }
             }
         }
     }
     $mime = isset($thumb_mime) ? $thumb_mime : (isset($mime) ? $mime : null);
     $extension = self::extension($mime);
     $name = 'art.' . $extension;
     $url = AmpConfig::get('web_path') . '/image.php?id=' . scrub_out($uid) . '&object_type=' . scrub_out($type) . '&auth=' . $sid . '&name=' . $name;
     return $url;
 }
예제 #10
0
 /**
  * id_from_name
  * This takes a name and returns the id
  */
 public static function id_from_name($name)
 {
     $name = Dba::escape($name);
     if (parent::is_cached('id_from_name', $name)) {
         return parent::get_from_cache('id_from_name', $name);
     }
     $sql = "SELECT `id` FROM `preference` WHERE `name`='{$name}'";
     $db_results = Dba::read($sql);
     $row = Dba::fetch_assoc($db_results);
     parent::add_to_cache('id_from_name', $name, $row['id']);
     return $row['id'];
 }
예제 #11
0
 public function get_flag($user_id = null)
 {
     if (is_null($user_id)) {
         $user_id = $GLOBALS['user']->id;
     }
     $key = 'userflag_' . $this->type . '_user' . $user_id;
     if (parent::is_cached($key, $this->id)) {
         return parent::get_from_cache($key, $this->id);
     }
     $sql = "SELECT `id` FROM `user_flag` WHERE `user` = ? " . "AND `object_id` = ? AND `object_type` = ?";
     $db_results = Dba::read($sql, array($user_id, $this->id, $this->type));
     $flagged = false;
     if (Dba::fetch_assoc($db_results)) {
         $flagged = true;
     }
     parent::add_to_cache($key, $this->id, $flagged);
     return $flagged;
 }
예제 #12
0
 /**
  * _get_extra info
  * This returns the extra information for the artist, this means totals etc
  */
 private function _get_extra_info($catalog = FALSE)
 {
     // Try to find it in the cache and save ourselves the trouble
     if (parent::is_cached('artist_extra', $this->id)) {
         $row = parent::get_from_cache('artist_extra', $this->id);
     } else {
         $uid = Dba::escape($this->id);
         $sql = "SELECT `song`.`artist`,COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog` " . "WHERE `song`.`artist`='{$uid}' ";
         if ($catalog) {
             $sql .= "AND (`song`.`catalog` = '{$catalog}') ";
         }
         if (AmpConfig::get('catalog_disable')) {
             $sql .= " AND `catalog`.`enabled` = '1'";
         }
         $sql .= "GROUP BY `song`.`artist`";
         $db_results = Dba::read($sql);
         $row = Dba::fetch_assoc($db_results);
         if (AmpConfig::get('show_played_times')) {
             $row['object_cnt'] = Stats::get_object_count('artist', $row['artist']);
         }
         parent::add_to_cache('artist_extra', $row['artist'], $row);
     }
     /* Set Object Vars */
     $this->songs = $row['song_count'];
     $this->albums = $row['album_count'];
     $this->time = $row['time'];
     return $row;
 }
예제 #13
0
 /**
  * _get_extra_info
  * This pulls the extra information from our tables, this is a 3 table join, which is why we don't normally
  * do it
  */
 private function _get_extra_info()
 {
     if (parent::is_cached('album_extra', $this->id)) {
         return parent::get_from_cache('album_extra', $this->id);
     }
     $sql = "SELECT " . "COUNT(DISTINCT(`song`.`artist`)) AS `artist_count`, " . "COUNT(`song`.`id`) AS `song_count`, " . "SUM(`song`.`time`) as `total_duration`," . "`song`.`catalog` as `catalog_id`," . "`artist`.`name` AS `artist_name`, " . "`artist`.`prefix` AS `artist_prefix`, " . "`artist`.`id` AS `artist_id` " . "FROM `song` INNER JOIN `artist` " . "ON `artist`.`id`=`song`.`artist` ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog` ";
     }
     $suite_array = array();
     if ($this->allow_group_disks) {
         $suite_array = $this->album_suite;
     }
     if (!count($suite_array)) {
         $suite_array[] = $this->id;
     }
     $idlist = '(' . implode(',', $suite_array) . ')';
     $sql .= "WHERE `song`.`album` IN {$idlist} ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "AND `catalog`.`enabled` = '1' ";
     }
     if (!count($this->album_suite)) {
         $sql .= "GROUP BY `song`.`album`";
     } else {
         $sql .= "GROUP BY `song`.`artist`";
     }
     $db_results = Dba::read($sql);
     $results = Dba::fetch_assoc($db_results);
     $art = new Art($this->id, 'album');
     $art->get_db();
     $results['has_art'] = make_bool($art->raw);
     $results['has_thumb'] = make_bool($art->thumb);
     if (AmpConfig::get('show_played_times')) {
         $results['object_cnt'] = Stats::get_object_count('album', $this->id);
     }
     parent::add_to_cache('album_extra', $this->id, $results);
     return $results;
 }
예제 #14
0
 /**
  * _get_extra info
  * This returns the extra information for the podcast, this means totals etc
  */
 private function _get_extra_info()
 {
     // Try to find it in the cache and save ourselves the trouble
     if (parent::is_cached('podcast_extra', $this->id)) {
         $row = parent::get_from_cache('podcast_extra', $this->id);
     } else {
         $sql = "SELECT COUNT(`podcast_episode`.`id`) AS `episode_count` FROM `podcast_episode` " . "WHERE `podcast_episode`.`podcast` = ?";
         $db_results = Dba::read($sql, array($this->id));
         $row = Dba::fetch_assoc($db_results);
         parent::add_to_cache('podcast_extra', $this->id, $row);
     }
     /* Set Object Vars */
     $this->episodes = $row['episode_count'];
     return $row;
 }
예제 #15
0
 /**
  * _get_extra info
  * This returns the extra information for the artist, this means totals etc
  * @param int $catalog
  * @return array
  */
 private function _get_extra_info($catalog = 0, $limit_threshold = '')
 {
     // Try to find it in the cache and save ourselves the trouble
     if (parent::is_cached('artist_extra', $this->id)) {
         $row = parent::get_from_cache('artist_extra', $this->id);
     } else {
         $params = array($this->id);
         // Calculation
         $sql = "SELECT COUNT(DISTINCT `song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog` ";
         $sqlw = "WHERE `song`.`artist` = ? ";
         if ($catalog) {
             $params[] = $catalog;
             $sqlw .= "AND (`song`.`catalog` = ?) ";
         }
         if (AmpConfig::get('catalog_disable')) {
             $sqlw .= " AND `catalog`.`enabled` = '1' ";
         }
         $sql .= $sqlw . "GROUP BY `song`.`artist`";
         $db_results = Dba::read($sql, $params);
         $row = Dba::fetch_assoc($db_results);
         // Get associated information from first song only
         $sql = "SELECT `song`.`artist`, `song`.`catalog` as `catalog_id` FROM `song` LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog` ";
         $sql .= $sqlw . "LIMIT 1";
         $db_results = Dba::read($sql, $params);
         $row = array_merge($row, Dba::fetch_assoc($db_results));
         if (AmpConfig::get('show_played_times')) {
             $row['object_cnt'] = Stats::get_object_count('artist', $row['artist'], $limit_threshold);
         }
         parent::add_to_cache('artist_extra', $row['artist'], $row);
     }
     /* Set Object Vars */
     $this->songs = $row['song_count'];
     $this->albums = $row['album_count'];
     $this->time = $row['time'];
     $this->catalog_id = $row['catalog_id'];
     return $row;
 }
예제 #16
0
파일: song.class.php 프로젝트: nioc/ampache
 /**
  * _get_ext_info
  * This function gathers information from the song_ext_info table and adds it to the
  * current object
  * @return array
  */
 public function _get_ext_info()
 {
     $id = intval($this->id);
     if (parent::is_cached('song_data', $id)) {
         return parent::get_from_cache('song_data', $id);
     }
     $sql = "SELECT * FROM song_data WHERE `song_id` = ?";
     $db_results = Dba::read($sql, array($id));
     $results = Dba::fetch_assoc($db_results);
     parent::add_to_cache('song_data', $id, $results);
     return $results;
 }