/**
  * get_info
  * retrieves the info from the database and puts it in the cache
  */
 public function get_info($id, $table_name = '')
 {
     $table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this)));
     // Make sure we've got a real id
     if (!is_numeric($id)) {
         return array();
     }
     if (self::is_cached($table_name, $id)) {
         return self::get_from_cache($table_name, $id);
     }
     $sql = "SELECT * FROM `{$table_name}` WHERE `id`='{$id}'";
     $db_results = Dba::read($sql);
     if (!$db_results) {
         return array();
     }
     $row = Dba::fetch_assoc($db_results);
     self::add_to_cache($table_name, $id, $row);
     return $row;
 }
Exemplo n.º 2
0
 /**
  * get_songs
  * gets all episodes for this tv show season
  */
 public function get_episodes()
 {
     $sql = "SELECT `tvshow_episode`.`id` FROM `tvshow_episode` ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "LEFT JOIN `video` ON `video`.`id` = `tvshow_episode`.`id` ";
         $sql .= "LEFT JOIN `catalog` ON `catalog`.`id` = `video`.`catalog` ";
     }
     $sql .= "WHERE `tvshow_episode`.`season`='" . Dba::escape($this->id) . "' ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "AND `catalog`.`enabled` = '1' ";
     }
     $sql .= "ORDER BY `tvshow_episode`.`episode_number`";
     $db_results = Dba::read($sql);
     $results = array();
     while ($r = Dba::fetch_assoc($db_results)) {
         $results[] = $r['id'];
     }
     return $results;
 }
Exemplo n.º 3
0
 /**
  * get_recently_played
  * This function returns the last X songs that have been played
  * it uses the popular threshold to figure out how many to pull
  * it will only return unique object
  */
 public static function get_recently_played($user_id = '')
 {
     $user_id = Dba::escape($user_id);
     $sql = "SELECT `object_id`, `user`, `object_type`, `date`, `agent` " . "FROM `object_count` WHERE `object_type`='song' ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "AND " . Catalog::get_enable_filter('song', '`object_id`') . " ";
     }
     if ($user_id) {
         // If user is not empty, we're looking directly to user personal info (admin view)
         $sql .= "AND `user`='{$user_id}' ";
     } else {
         if (!Access::check('interface', '100')) {
             // If user identifier is empty, we need to retrieve only users which have allowed view of personnal info
             $personal_info_id = Preference::id_from_name('allow_personal_info_recent');
             if ($personal_info_id) {
                 $current_user = $GLOBALS['user']->id;
                 $sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='{$personal_info_id}' AND `value`='1') OR `user`='{$current_user}') ";
             }
         }
     }
     $sql .= "ORDER BY `date` DESC ";
     $db_results = Dba::read($sql);
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $results[] = $row;
         if (count($results) >= AmpConfig::get('popular_threshold')) {
             break;
         }
     }
     return $results;
 }
Exemplo n.º 4
0
 /**
  * get
  * This functions returns an array containing information about
  * The songs that vlc currently has in it's playlist. This must be
  * done in a standardized fashion
  * Warning ! if you got files in vlc medialibary those files will be sent to the php xml parser
  * to, not to your browser but still this can take a lot of work for your server.
  * The xml files of vlc need work, not much documentation on them....
  */
 public function get()
 {
     /* Get the Current Playlist */
     $list = $this->_vlc->get_tracks();
     if (!$list) {
         return array();
     }
     $counterforarray = 0;
     // here we look if there are song in the playlist when media libary is used
     if ($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri']) {
         while ($list['node']['node'][0]['leaf'][$counterforarray]) {
             $songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
             $songid[] = $list['node']['node'][0]['leaf'][$counterforarray]['attr']['id'];
             $counterforarray++;
         }
         // if there is only one song look here,and media libary is used
     } elseif ($list['node']['node'][0]['leaf']['attr']['uri']) {
         $songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf']['attr']['uri'], ENT_NOQUOTES);
         $songid[] = $list['node']['node'][0]['leaf']['attr']['id'];
     } elseif ($list['node']['node']['leaf'][$counterforarray]['attr']['uri']) {
         while ($list['node']['node']['leaf'][$counterforarray]) {
             $songs[] = htmlspecialchars_decode($list['node']['node']['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
             $songid[] = $list['node']['node']['leaf'][$counterforarray]['attr']['id'];
             $counterforarray++;
         }
     } elseif ($list['node']['node']['leaf']['attr']['uri']) {
         $songs[] = htmlspecialchars_decode($list['node']['node']['leaf']['attr']['uri'], ENT_NOQUOTES);
         $songid[] = $list['node']['node']['leaf']['attr']['id'];
     } else {
         return array();
     }
     $counterforarray = 0;
     foreach ($songs as $key => $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $songid[$counterforarray];
         // id number of the files in the vlc playlist, needed for other operations
         $data['raw'] = $entry;
         $url_data = $this->parse_url($entry);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $data['oid'] = $url_data['oid'];
                 $song = new Song($data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry);
                 $sql = "SELECT `name` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     //if stream is known just send name
                     $data['name'] = htmlspecialchars(substr($row['name'], 0, 50));
                 } elseif (strncmp($entry, 'http', 4) == 0) {
                     $data['name'] = htmlspecialchars("(VLC stream) " . substr($entry, 0, 50));
                 } else {
                     $getlast = explode("/", $entry);
                     $lastis = count($getlast) - 1;
                     $data['name'] = htmlspecialchars("(VLC local) " . substr($getlast[$lastis], 0, 50));
                 }
                 // end if loop
                 break;
         }
         // end switch on primary key type
         $data['track'] = $key + 1;
         $counterforarray++;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }
Exemplo n.º 5
0
 /**
  * remove_plugin_version
  * This removes the version row from the db done on uninstall
  */
 public function remove_plugin_version()
 {
     $name = Dba::escape('Plugin_' . $this->_plugin->name);
     $sql = "DELETE FROM `update_info` WHERE `key`='{$name}'";
     Dba::write($sql);
     return true;
 }
Exemplo n.º 6
0
 /**
  * count_items
  * This returns a count of the total number of tracks that are in this
  * tmp playlist
  */
 public function count_items()
 {
     $id = Dba::escape($this->id);
     $sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE " . "`tmp_playlist`='{$id}'";
     $db_results = Dba::read($sql);
     $results = Dba::fetch_row($db_results);
     return $results['0'];
 }
Exemplo n.º 7
0
 /**
  * resort_objects
  * This takes the existing objects, looks at the current
  * sort method and then re-sorts them This is internally
  * called by the set_sort() function
  */
 private function resort_objects()
 {
     // There are two ways to do this.. the easy way...
     // and the vollmer way, hopefully we don't have to
     // do it the vollmer way
     if ($this->is_simple()) {
         $sql = $this->get_sql(true);
     } else {
         // FIXME: this is fragile for large browses
         // First pull the objects
         $objects = $this->get_saved();
         // If there's nothing there don't do anything
         if (!count($objects) or !is_array($objects)) {
             return false;
         }
         $type = $this->get_type();
         $where_sql = "WHERE `{$type}`.`id` IN (";
         foreach ($objects as $object_id) {
             $object_id = Dba::escape($object_id);
             $where_sql .= "'{$object_id}',";
         }
         $where_sql = rtrim($where_sql, ',');
         $where_sql .= ")";
         $sql = $this->get_base_sql();
         $order_sql = " ORDER BY ";
         foreach ($this->_state['sort'] as $key => $value) {
             $order_sql .= $this->sql_sort($key, $value);
         }
         // Clean her up
         $order_sql = rtrim($order_sql, "ORDER BY ");
         $order_sql = rtrim($order_sql, ",");
         $sql = $sql . $this->get_join_sql() . $where_sql . $order_sql;
     }
     // if not simple
     $db_results = Dba::read($sql);
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $results[] = $row['id'];
     }
     $this->save_objects($results);
     return true;
 }
Exemplo n.º 8
0
 /**
  * check_username
  * This checks to make sure the username passed doesn't already
  * exist in this instance of ampache
  */
 public static function check_username($username)
 {
     $username = Dba::escape($username);
     $sql = "SELECT `id` FROM `user` WHERE `username`='{$username}'";
     $db_results = Dba::read($sql);
     if (Dba::num_rows($db_results)) {
         return false;
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * advanced
  * This processes the results of a post from a form and returns an
  * array of song items that were returned from said randomness
  */
 public static function advanced($type, $data)
 {
     /* Figure out our object limit */
     $limit = intval($data['random']);
     // Generate our matchlist
     /* If they've passed -1 as limit then get everything */
     $limit_sql = "";
     if ($data['random'] == "-1") {
         unset($data['random']);
     } else {
         $limit_sql = "LIMIT " . Dba::escape($limit);
     }
     $search_data = Search::clean_request($data);
     $search_info = false;
     if (count($search_data) > 1) {
         $search = new Search(null, $type);
         $search->parse_rules($search_data);
         $search_info = $search->to_sql();
     }
     $sql = "";
     switch ($type) {
         case 'song':
             $sql = "SELECT `song`.`id`, `size`, `time` " . "FROM `song` ";
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             break;
         case 'album':
             $sql = "SELECT `album`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `album` ";
             if (!$search_info || !$search_info['join']['song']) {
                 $sql .= "LEFT JOIN `song` ON `song`.`album`=`album`.`id` ";
             }
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             $sql .= ' GROUP BY `album`.`id`';
             break;
         case 'artist':
             $sql = "SELECT `artist`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `artist` ";
             if (!$search_info || !$search_info['join']['song']) {
                 $sql .= "LEFT JOIN `song` ON `song`.`artist`=`artist`.`id` ";
             }
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             $sql .= ' GROUP BY `artist`.`id`';
             break;
     }
     $sql .= " ORDER BY RAND() {$limit_sql}";
     // Run the query generated above so we can while it
     $db_results = Dba::read($sql);
     $results = array();
     $size_total = 0;
     $fuzzy_size = 0;
     $time_total = 0;
     $fuzzy_time = 0;
     while ($row = Dba::fetch_assoc($db_results)) {
         // If size limit is specified
         if ($data['size_limit']) {
             // Convert
             $new_size = $row['size'] / 1024 / 1024;
             // Only fuzzy 100 times
             if ($fuzzy_size > 100) {
                 break;
             }
             // Add and check, skip if over size
             if ($size_total + $new_size > $data['size_limit']) {
                 $fuzzy_size++;
                 continue;
             }
             $size_total = $size_total + $new_size;
             $results[] = $row['id'];
             // If we are within 4mb of target then jump ship
             if ($data['size_limit'] - floor($size_total) < 4) {
                 break;
             }
         }
         // if size_limit
         // If length really does matter
         if ($data['length']) {
             // base on min, seconds are for chumps and chumpettes
             $new_time = floor($row['time'] / 60);
             if ($fuzzy_time > 100) {
                 break;
             }
             // If the new one would go over skip!
             if ($time_total + $new_time > $data['length']) {
                 $fuzzy_time++;
                 continue;
             }
             $time_total = $time_total + $new_time;
             $results[] = $row['id'];
             // If there are less then 2 min of free space return
             if ($data['length'] - $time_total < 2) {
                 return $results;
             }
         }
         // if length does matter
         if (!$data['size_limit'] && !$data['length']) {
             $results[] = $row['id'];
         }
     }
     // end while results
     switch ($type) {
         case 'song':
             return $results;
         case 'album':
             $songs = array();
             foreach ($results as $result) {
                 $album = new Album($result);
                 $songs = array_merge($songs, $album->get_songs());
             }
             return $songs;
         case 'artist':
             $songs = array();
             foreach ($results as $result) {
                 $artist = new Artist($result);
                 $songs = array_merge($songs, $artist->get_songs());
             }
             return $songs;
         default:
             return false;
     }
 }
Exemplo n.º 10
0
 /**
  * get_episodes
  * gets all episodes for this tv show
  */
 public function get_episodes($state_filter = '')
 {
     $params = array();
     $sql = "SELECT `podcast_episode`.`id` FROM `podcast_episode` ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "LEFT JOIN `podcast` ON `podcast`.`id` = `podcast_episode`.`podcast` ";
         $sql .= "LEFT JOIN `catalog` ON `catalog`.`id` = `podcast`.`catalog` ";
     }
     $sql .= "WHERE `podcast_episode`.`podcast`='" . Dba::escape($this->id) . "' ";
     if (!empty($state_filter)) {
         $sql .= "AND `podcast_episode`.`state` = ? ";
         $params[] = $state_filter;
     }
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "AND `catalog`.`enabled` = '1' ";
     }
     $sql .= "ORDER BY `podcast_episode`.`pubdate` DESC";
     $db_results = Dba::read($sql, $params);
     $results = array();
     while ($r = Dba::fetch_assoc($db_results)) {
         $results[] = $r['id'];
     }
     return $results;
 }
Exemplo n.º 11
0
 /**
  * get_artists_like
  * Returns a list of similar artists
  */
 public static function get_artists_like($artist_id, $limit = 10, $local_only = true)
 {
     $artist = new Artist($artist_id);
     $cache = self::get_recommendation_cache('artist', $artist_id, true);
     if (!$cache['id']) {
         $similars = array();
         $query = 'artist=' . rawurlencode($artist->name);
         $xml = self::get_lastfm_results('artist.getsimilar', $query);
         foreach ($xml->similarartists->children() as $child) {
             $name = $child->name;
             $mbid = (string) $child->mbid;
             $local_id = null;
             // First we check by MBID
             if ($mbid) {
                 $sql = "SELECT `artist`.`id` FROM `artist` WHERE `mbid` = ?";
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= " AND " . Catalog::get_enable_filter('artist', '`artist`.`id`');
                 }
                 $db_result = Dba::read($sql, array($mbid));
                 if ($result = Dba::fetch_assoc($db_result)) {
                     $local_id = $result['id'];
                 }
             }
             // Then we fall back to the less likely to work exact
             // name match
             if (is_null($local_id)) {
                 $searchname = Catalog::trim_prefix($name);
                 $searchname = Dba::escape($searchname['string']);
                 $sql = "SELECT `artist`.`id` FROM `artist` WHERE `name` = ?";
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= " AND " . Catalog::get_enable_filter('artist', '`artist`.`id`');
                 }
                 $db_result = Dba::read($sql, array($searchname));
                 if ($result = Dba::fetch_assoc($db_result)) {
                     $local_id = $result['id'];
                 }
             }
             // Then we give up
             if (is_null($local_id)) {
                 debug_event('Recommendation', "{$name} did not match any local artist", 5);
                 $similars[] = array('id' => null, 'name' => $name, 'mbid' => $mbid);
             } else {
                 debug_event('Recommendation', "{$name} matched local artist " . $local_id, 5);
                 $similars[] = array('id' => $local_id, 'name' => $name);
             }
         }
         if (count($similars) > 0) {
             self::update_recommendation_cache('artist', $artist_id, $similars);
         }
     }
     if (!isset($similars) || count($similars) == 0) {
         $similars = $cache['items'];
     }
     if ($similars) {
         $results = array();
         foreach ($similars as $similar) {
             if (!$local_only || !is_null($similar['id'])) {
                 $results[] = $similar;
             }
             if ($limit && count($results) >= $limit) {
                 break;
             }
         }
     }
     if (isset($results)) {
         return $results;
     }
     return false;
 }
Exemplo n.º 12
0
 /**
  * init
  * This grabs the preferences and then loads them into conf it should be run on page load
  * to initialize the needed variables
  */
 public static function init()
 {
     $user_id = $GLOBALS['user']->id ? Dba::escape($GLOBALS['user']->id) : '-1';
     // First go ahead and try to load it from the preferences
     if (self::load_from_session($user_id)) {
         return true;
     }
     /* Get Global Preferences */
     $sql = "SELECT `preference`.`name`,`user_preference`.`value`,`syspref`.`value` AS `system_value` FROM `preference` " . "LEFT JOIN `user_preference` `syspref` ON `syspref`.`preference`=`preference`.`id` AND `syspref`.`user`='-1' AND `preference`.`catagory`='system' " . "LEFT JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` AND `user_preference`.`user`='{$user_id}' AND `preference`.`catagory`!='system'";
     $db_results = Dba::read($sql);
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $value = $row['system_value'] ? $row['system_value'] : $row['value'];
         $name = $row['name'];
         $results[$name] = $value;
     }
     // end while sys prefs
     /* Set the Theme mojo */
     if (strlen($results['theme_name']) > 0) {
         $results['theme_path'] = '/themes/' . $results['theme_name'];
     } else {
         $results['theme_path'] = '/themes/reborn';
     }
     AmpConfig::set_by_array($results, true);
     $_SESSION['userdata']['preferences'] = $results;
     $_SESSION['userdata']['uid'] = $user_id;
 }
Exemplo n.º 13
0
 /**
  * get_vote
  * This returns the current count for a specific song
  */
 public function get_vote($id)
 {
     if (parent::is_cached('democratic_vote', $id)) {
         return parent::get_from_cache('democratic_vote', $id);
     }
     $sql = 'SELECT COUNT(`user`) AS `count` FROM `user_vote` ' . "WHERE `object_id`='" . Dba::escape($id) . "'";
     $db_results = Dba::read($sql);
     $results = Dba::fetch_assoc($db_results);
     parent::add_to_cache('democratic_vote', $id, $results['count']);
     return $results['count'];
 }
Exemplo n.º 14
0
 /**
  * get_from_path
  * This returns all of the songs that exist under the specified path
  * @param string $path
  * @return int[]
  */
 public static function get_from_path($path)
 {
     $path = Dba::escape($path);
     $sql = "SELECT * FROM `song` WHERE `file` LIKE '{$path}%'";
     $db_results = Dba::read($sql);
     $songs = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $songs[] = $row['id'];
     }
     return $songs;
 }
Exemplo n.º 15
0
 /**
  * get_from_source
  * This gets an image for the album art from a source as
  * defined in the passed array. Because we don't know where
  * it's coming from we are a passed an array that can look like
  * ['url']      = URL *** OPTIONAL ***
  * ['file']     = FILENAME *** OPTIONAL ***
  * ['raw']      = Actual Image data, already captured
  */
 public static function get_from_source($data, $type = 'album')
 {
     // Already have the data, this often comes from id3tags
     if (isset($data['raw'])) {
         return $data['raw'];
     }
     // If it came from the database
     if (isset($data['db'])) {
         // Repull it
         $uid = Dba::escape($data['db']);
         $type = Dba::escape($type);
         $sql = "SELECT * FROM `image` WHERE `object_type`='{$type}' AND `object_id`='{$uid}' AND `size`='original'";
         $db_results = Dba::read($sql);
         $row = Dba::fetch_assoc($db_results);
         return $row['art'];
     }
     // came from the db
     // Check to see if it's a URL
     if (isset($data['url'])) {
         $options = array();
         if (AmpConfig::get('proxy_host') and AmpConfig::get('proxy_port')) {
             $proxy = array();
             $proxy[] = AmpConfig::get('proxy_host') . ':' . AmpConfig::get('proxy_port');
             if (AmpConfig::get('proxy_user')) {
                 $proxy[] = AmpConfig::get('proxy_user');
                 $proxy[] = AmpConfig::get('proxy_pass');
             }
             $options['proxy'] = $proxy;
         }
         $request = Requests::get($data['url'], array(), $options);
         return $request->body;
     }
     // Check to see if it's a FILE
     if (isset($data['file'])) {
         $handle = fopen($data['file'], 'rb');
         $image_data = fread($handle, filesize($data['file']));
         fclose($handle);
         return $image_data;
     }
     // Check to see if it is embedded in id3 of a song
     if (isset($data['song'])) {
         // If we find a good one, stop looking
         $getID3 = new getID3();
         $id3 = $getID3->analyze($data['song']);
         if ($id3['format_name'] == "WMA") {
             return $id3['asf']['extended_content_description_object']['content_descriptors']['13']['data'];
         } elseif (isset($id3['id3v2']['APIC'])) {
             // Foreach in case they have more then one
             foreach ($id3['id3v2']['APIC'] as $image) {
                 return $image['data'];
             }
         }
     }
     // if data song
     return false;
 }
Exemplo n.º 16
0
 /**
  * check_title
  * this checks to make sure something is
  * set on the title, if it isn't it looks at the
  * filename and trys to set the title based on that
  */
 public static function check_title($title, $file = 0)
 {
     if (strlen(trim($title)) < 1) {
         $title = Dba::escape($file);
     }
     return $title;
 }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
0
 /**
  * mysql_auth
  *
  * This is the core function of our built-in authentication.
  */
 private static function mysql_auth($username, $password)
 {
     if (strlen($password) && strlen($username)) {
         $sql = 'SELECT `password` FROM `user` WHERE `username` = ?';
         $db_results = Dba::read($sql, array($username));
         if ($row = Dba::fetch_assoc($db_results)) {
             // Use SHA2 now... cooking with fire.
             // For backwards compatibility we hash a couple of different
             // variations of the password. Increases collision chances, but
             // doesn't break things.
             // FIXME: Break things in the future.
             $hashed_password = array();
             $hashed_password[] = hash('sha256', $password);
             $hashed_password[] = hash('sha256', Dba::escape(stripslashes(htmlspecialchars(strip_tags($password)))));
             // Automagically update the password if it's old and busted.
             if ($row['password'] == $hashed_password[1] && $hashed_password[0] != $hashed_password[1]) {
                 $user = User::get_from_username($username);
                 $user->update_password($password);
             }
             if (in_array($row['password'], $hashed_password)) {
                 return array('success' => true, 'type' => 'mysql', 'username' => $username);
             }
         }
     }
     return array('success' => false, 'error' => 'MySQL login attempt failed');
 }
Exemplo n.º 19
0
/**
 * install_create_account
 * this creates your initial account and sets up the preferences for the -1 user and you
 */
function install_create_account($username, $password, $password2)
{
    if (!strlen($username) or !strlen($password)) {
        Error::add('general', T_('No Username/Password specified'));
        return false;
    }
    if ($password !== $password2) {
        Error::add('general', T_('Passwords do not match'));
        return false;
    }
    if (!Dba::check_database()) {
        Error::add('general', sprintf(T_('Database connection failed: %s'), Dba::error()));
        return false;
    }
    if (!Dba::check_database_inserted()) {
        Error::add('general', sprintf(T_('Database select failed: %s'), Dba::error()));
        return false;
    }
    $username = Dba::escape($username);
    $password = Dba::escape($password);
    $insert_id = User::create($username, 'Administrator', '', '', $password, '100');
    if (!$insert_id) {
        Error::add('general', sprintf(T_('Administrative user creation failed: %s'), Dba::error()));
        return false;
    }
    // Fix the system users preferences
    User::fix_preferences('-1');
    return true;
}
Exemplo n.º 20
0
 /**
  * delete
  * this function deletes a specific shoutbox entry
  */
 public function delete($shout_id)
 {
     // Delete the shoutbox post
     $shout_id = Dba::escape($shout_id);
     $sql = "DELETE FROM `user_shout` WHERE `id`='{$shout_id}'";
     Dba::write($sql);
 }
Exemplo n.º 21
0
 /**
  * init
  * This grabs the preferences and then loads them into conf it should be run on page load
  * to initialize the needed variables
  */
 public static function init()
 {
     $user_id = $GLOBALS['user']->id ? Dba::escape($GLOBALS['user']->id) : '-1';
     // First go ahead and try to load it from the preferences
     if (self::load_from_session($user_id)) {
         return true;
     }
     /* Get Global Preferences */
     $sql = "SELECT `preference`.`name`,`user_preference`.`value`,`syspref`.`value` AS `system_value` FROM `preference` " . "LEFT JOIN `user_preference` `syspref` ON `syspref`.`preference`=`preference`.`id` AND `syspref`.`user`='-1' AND `preference`.`catagory`='system' " . "LEFT JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` AND `user_preference`.`user` = ? AND `preference`.`catagory`!='system'";
     $db_results = Dba::read($sql, array($user_id));
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $value = $row['system_value'] ? $row['system_value'] : $row['value'];
         $name = $row['name'];
         $results[$name] = $value;
     }
     // end while sys prefs
     /* Set the Theme mojo */
     if (strlen($results['theme_name']) > 0) {
         $results['theme_path'] = '/themes/' . $results['theme_name'];
         // In case the theme was removed
         if (!Core::is_readable(AmpConfig::get('prefix') . $results['theme_path'])) {
             unset($results['theme_path']);
         }
     }
     // Default theme if we don't get anything from their
     // preferences because we're going to want at least something otherwise
     // the page is going to be really ugly
     if (!isset($results['theme_path'])) {
         $results['theme_path'] = '/themes/reborn';
     }
     AmpConfig::set_by_array($results, true);
     $_SESSION['userdata']['preferences'] = $results;
     $_SESSION['userdata']['uid'] = $user_id;
 }
Exemplo n.º 22
0
 /**
  * get_songs
  * This functions returns an array containing information about
  * the songs that MPD currently has in its playlist. This must be
  * done in a standardized fashion
  */
 public function get()
 {
     // If we don't have the playlist yet, pull it
     if (!isset($this->_mpd->playlist)) {
         $this->_mpd->RefreshInfo();
     }
     /* Get the Current Playlist */
     $playlist = $this->_mpd->playlist;
     foreach ($playlist as $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $entry['Pos'];
         $data['raw'] = $entry['file'];
         $url_data = $this->parse_url($entry['file']);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $data['oid'] = $url_data['oid'];
                 $song = new Song($data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry['file']);
                 $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%{$filename}' " . "UNION ALL " . "SELECT `id`,'live_stream' AS `type` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     $media = new $row['type']($row['id']);
                     $media->format();
                     switch ($row['type']) {
                         case 'song':
                             $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist;
                             $data['link'] = $media->f_link;
                             break;
                         case 'live_stream':
                             $frequency = $media->frequency ? '[' . $media->frequency . ']' : '';
                             $site_url = $media->site_url ? '(' . $media->site_url . ')' : '';
                             $data['name'] = "{$media->name} {$frequency} {$site_url}";
                             $data['link'] = $media->site_url;
                             break;
                     }
                     // end switch on type
                 } else {
                     $data['name'] = T_('Unknown');
                     $data['link'] = '';
                 }
                 break;
         }
         // end switch on primary key type
         /* Optional Elements */
         $data['track'] = $entry['Pos'] + 1;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }
Exemplo n.º 23
0
 /**
  * clear
  * This is really just a wrapper function, it clears the entire playlist
  * including all votes etc.
  */
 public function clear()
 {
     $tmp_id = Dba::escape($this->tmp_playlist);
     if ($tmp_id) {
         /* Clear all votes then prune */
         $sql = "DELETE FROM `user_vote` USING `user_vote` " . "LEFT JOIN `tmp_playlist_data` ON `user_vote`.`object_id` = `tmp_playlist_data`.`id` " . "WHERE `tmp_playlist_data`.`tmp_playlist`='{$tmp_id}'";
         Dba::write($sql);
     }
     // Prune!
     self::prune_tracks();
     // Clean the votes
     self::clear_votes();
     return true;
 }
Exemplo n.º 24
0
 /**
  * update_360003
  *
  * This update moves the image data to its own table.
  */
 public static function update_360003()
 {
     $retval = true;
     $sql = "CREATE TABLE `image` (" . "`id` int(11) unsigned NOT NULL auto_increment," . "`image` mediumblob NOT NULL," . "`mime` varchar(64) NOT NULL," . "`size` varchar(64) NOT NULL," . "`object_type` varchar(64) NOT NULL," . "`object_id` int(11) unsigned NOT NULL," . "PRIMARY KEY  (`id`)," . "KEY `object_type` (`object_type`)," . "KEY `object_id` (`object_id`)" . ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
     $retval &= Dba::write($sql);
     foreach (array('album', 'artist') as $type) {
         $sql = "SELECT `" . $type . "_id` AS `object_id`, " . "`art`, `art_mime` FROM `" . $type . "_data` WHERE `art` IS NOT NULL";
         $db_results = Dba::read($sql);
         while ($row = Dba::fetch_assoc($db_results)) {
             $sql = "INSERT INTO `image` " . "(`image`, `mime`, `size`, " . "`object_type`, `object_id`) " . "VALUES('" . Dba::escape($row['art']) . "', '" . $row['art_mime'] . "', 'original', '" . $type . "', '" . $row['object_id'] . "')";
             Dba::write($sql);
         }
         $sql = "DROP TABLE `" . $type . "_data`";
         $retval &= Dba::write($sql);
     }
     return $retval;
 }
Exemplo n.º 25
0
    }
}
$share_id = intval($_REQUEST['share_id']);
$subtitle = '';
$send_all_in_once = false;
if (!$type) {
    $type = 'song';
}
debug_event('play', 'Asked for type {' . $type . "}", 5);
if ($type == 'playlist') {
    $playlist_type = scrub_in($_REQUEST['playlist_type']);
    $oid = $sid;
}
/* This is specifically for tmp playlist requests */
$demo_id = Dba::escape($_REQUEST['demo_id']);
$random = Dba::escape($_REQUEST['random']);
/* First things first, if we don't have a uid/oid stop here */
if (empty($oid) && empty($demo_id) && empty($random)) {
    debug_event('play', 'No object UID specified, nothing to play', 2);
    header('HTTP/1.1 400 Nothing To Play');
    exit;
}
// Authenticate the user if specified
$u = $_SERVER['PHP_AUTH_USER'];
if (empty($u)) {
    $u = $_REQUEST['u'];
}
$p = $_SERVER['PHP_AUTH_PW'];
if (empty($p)) {
    $p = $_REQUEST['p'];
}
Exemplo n.º 26
0
 /**
  * delete
  *
  * Does what it says on the tin.
  */
 public function delete()
 {
     $id = Dba::escape($this->id);
     $sql = "DELETE FROM `search` WHERE `id` = ?";
     Dba::write($sql, array($id));
     return true;
 }
Exemplo n.º 27
0
    }
}
UI::show_header();
/* Switch on the action passed in */
switch ($_REQUEST['action']) {
    case 'create_playlist':
        /* Check rights */
        if (!Access::check('interface', '25')) {
            UI::access_denied();
            break;
        }
        foreach ($_REQUEST as $key => $value) {
            $prefix = substr($key, 0, 4);
            $value = trim($value);
            if ($prefix == 'rule' && strlen($value)) {
                $rules[$key] = Dba::escape($value);
            }
        }
        switch ($_REQUEST['operator']) {
            case 'or':
                $operator = 'OR';
                break;
            default:
                $operator = 'AND';
                break;
        }
        // end switch on operator
        $playlist_name = (string) scrub_in($_REQUEST['playlist_name']);
        $playlist = new Search(null, 'song');
        $playlist->parse_rules($data);
        $playlist->logic_operator = $operator;
Exemplo n.º 28
0
 /**
  * count
  * This returns the count for the all objects associated with this tag
  * If a type is specific only counts for said type are returned
  */
 public function count($type = '')
 {
     $filter_sql = "";
     if ($type) {
         $filter_sql = " AND `object_type`='" . Dba::escape($type) . "'";
     }
     $results = array();
     $sql = "SELECT COUNT(`id`) AS `count`,`object_type` FROM `tag_map` WHERE `tag_id`='" . Dba::escape($this->id) . "'" . $filter_sql . " GROUP BY `object_type`";
     $db_results = Dba::read($sql);
     while ($row = Dba::fetch_assoc($db_results)) {
         $results[$row['object_type']] = $row['count'];
     }
     return $results;
 }
Exemplo n.º 29
0
 /**
  * get
  * This functions returns an array containing information about
  * The songs that httpQ currently has in its playlist. This must be
  * done in a standardized fashion
  */
 public function get()
 {
     /* Get the Current Playlist */
     $list = $this->_httpq->get_tracks();
     if (!$list) {
         return array();
     }
     $songs = explode("::", $list);
     foreach ($songs as $key => $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $key;
         $data['raw'] = $entry;
         $url_data = $this->parse_url($entry);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $song = new Song($url_data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry['file']);
                 $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%{$filename}' " . "UNION ALL " . "SELECT `id`,'radio' AS `type` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     $media = new $row['type']($row['id']);
                     $media->format();
                     switch ($row['type']) {
                         case 'song':
                             $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist;
                             $data['link'] = $media->f_link;
                             break;
                         case 'radio':
                             $frequency = $media->frequency ? '[' . $media->frequency . ']' : '';
                             $site_url = $media->site_url ? '(' . $media->site_url . ')' : '';
                             $data['name'] = "{$media->name} {$frequency} {$site_url}";
                             $data['link'] = $media->site_url;
                             break;
                     }
                     // end switch on type
                 } else {
                     $data['name'] = basename($data['raw']);
                     $data['link'] = basename($data['raw']);
                 }
                 break;
         }
         // end switch on primary key type
         $data['track'] = $key + 1;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }