diff options
author | Paul 'flowerysong' Arthur <flowerysong00@yahoo.com> | 2010-06-15 21:18:17 +0000 |
---|---|---|
committer | Paul 'flowerysong' Arthur <flowerysong00@yahoo.com> | 2010-06-15 21:18:17 +0000 |
commit | 733f507937ffaa28b7e8739f63a77c459dfe407b (patch) | |
tree | 6be0a78ba43b89581c6a78af5fc3a46252eb9a6c | |
parent | 33213b8ea84e15863f13affbdb31316e7f89c7d7 (diff) | |
download | ampache-733f507937ffaa28b7e8739f63a77c459dfe407b.tar.gz ampache-733f507937ffaa28b7e8739f63a77c459dfe407b.tar.bz2 ampache-733f507937ffaa28b7e8739f63a77c459dfe407b.zip |
Browsing by tag is broken. This doesn't fix it.
-rw-r--r-- | lib/class/query.class.php | 216 | ||||
-rw-r--r-- | lib/class/tmpplaylist.class.php | 119 | ||||
-rw-r--r-- | lib/class/vauth.class.php | 6 | ||||
-rw-r--r-- | templates/show_tagcloud.inc.php | 2 |
4 files changed, 217 insertions, 126 deletions
diff --git a/lib/class/query.class.php b/lib/class/query.class.php index 15af3cdd..65ee0dc7 100644 --- a/lib/class/query.class.php +++ b/lib/class/query.class.php @@ -32,6 +32,9 @@ class Query { protected $_state = array(); protected $_cache; + private static $allowed_filters; + private static $allowed_sorts; + /** * constructor * This should be called @@ -59,7 +62,7 @@ class Query { if ($results = Dba::fetch_assoc($db_results)) { $this->_state = unserialize($results['data']); - + return true; } Error::add('browse', _('Browse not found or expired, try reloading the page')); @@ -67,20 +70,147 @@ class Query { } /** + * _auto_init + * Automatically called when the class is loaded. + * Populate static arrays if necessary + */ + public static function _auto_init() { + if (is_array(self::$allowed_filters)) { + return true; + } + + self::$allowed_filters = array( + 'album' => array( + 'add_lt', + 'add_gt', + 'update_lt', + 'update_gt', + 'show_art', + 'starts_with', + 'exact_match', + 'alpha_match' + ), + 'artist' => array( + 'add_lt', + 'add_gt', + 'update_lt', + 'update_gt', + 'exact_match', + 'alpha_match', + 'starts_with', + 'tag' + ), + 'song' => array( + 'add_lt', + 'add_gt', + 'update_lt', + 'update_gt', + 'exact_match', + 'alpha_match', + 'starts_with', + 'tag' + ), + 'live_stream' => array( + 'alpha_match', + 'starts_with' + ), + 'playlist' => array( + 'alpha_match', + 'starts_with' + ), + 'tag' => array( + 'tag', + 'object_type', + 'exact_match', + 'alpha_match' + ), + 'video' => array( + 'starts_with', + 'exact_match', + 'alpha_match' + ) + ); + + if (Access::check('interface','50')) { + array_push(self::$allowed_filters['playlist'], 'playlist_type'); + } + + self::$allowed_sorts = array( + 'playlist_song' => array( + 'title', + 'year', + 'track', + 'time', + 'album', + 'artist' + ), + 'song' => array( + 'title', + 'year', + 'track', + 'time', + 'album', + 'artist' + ), + 'artist' => array( + 'name', + 'album' + ), + 'tag' => array( + 'tag' + ), + 'album' => array( + 'name', + 'year', + 'artist' + ), + 'playlist' => array( + 'name', + 'user' + ), + 'shoutbox' => array( + 'date', + 'user', + 'sticky' + ), + 'live_stream' => array( + 'name', + 'call_sign', + 'frequency' + ), + 'video' => array( + 'title', + 'resolution', + 'length', + 'codec' + ), + 'user' => array( + 'fullname', + 'username', + 'last_seen', + 'create_date' + ) + ); + } + + /** + * clean + * This cleans old data out of the table + */ + public static function clean() { + $sql = "DELETE FROM `tmp_browse` USING `tmp_browse` LEFT JOIN ". + "`session` ON `session`.`id`=`tmp_browse`.`sid` " . + "WHERE `session`.`id` IS NULL"; + $db_results = Dba::write($sql); + } + + /** * set_filter * This saves the filter data we pass it. */ public function set_filter($key, $value) { switch ($key) { - case 'show_art': - if ($this->get_filter($key, $id)) { - unset($this->_state['filter'][$key]); - } - else { - $this->_state['filter'][$key] = true; - } - break; case 'tag': if (is_array($value)) { $this->_state['filter'][$key] = $value; @@ -290,38 +420,9 @@ class Query { * sidebar stuff. */ public static function get_allowed_filters($type) { - - switch ($type) { - case 'album': - $valid_array = array('add_lt','add_gt','update_lt','update_gt','show_art', - 'starts_with','exact_match','alpha_match'); - break; - case 'artist': - case 'song': - $valid_array = array('add_lt','add_gt','update_lt','update_gt','exact_match','alpha_match','starts_with','tag'); - break; - case 'live_stream': - $valid_array = array('alpha_match','starts_with'); - break; - case 'playlist': - $valid_array = array('alpha_match','starts_with'); - if (Access::check('interface','50')) { - array_push($valid_array,'playlist_type'); - } - break; - case 'tag': - $valid_array = array('tag','object_type','exact_match','alpha_match'); - break; - case 'video': - $valid_array = array('starts_with','exact_match','alpha_match'); - break; - default: - $valid_array = array(); - break; - } // switch on the browsetype - - return $valid_array; - + return isset(self::$allowed_filters[$type]) + ? self::$allowed_filters[$type] + : array(); } // get_allowed_filters /** @@ -373,39 +474,8 @@ class Query { */ public function set_sort($sort,$order='') { - switch ($this->get_type()) { - case 'playlist_song': - case 'song': - $valid_array = array('title','year','track','time','album','artist'); - break; - case 'artist': - $valid_array = array('name','album'); - break; - case 'tag': - $valid_array = array('tag'); - break; - case 'album': - $valid_array = array('name','year','artist'); - break; - case 'playlist': - $valid_array = array('name','user'); - break; - case 'shoutbox': - $valid_array = array('date','user','sticky'); - break; - case 'live_stream': - $valid_array = array('name','call_sign','frequency'); - break; - case 'video': - $valid_array = array('title','resolution','length','codec'); - break; - case 'user': - $valid_array = array('fullname','username','last_seen','create_date'); - break; - } // end switch - // If it's not in our list, smeg off! - if (!in_array($sort, $valid_array)) { + if (!in_array($sort, self::$allowed_sorts[$this->get_type()])) { return false; } diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php index 4dfc2f92..78612d74 100644 --- a/lib/class/tmpplaylist.class.php +++ b/lib/class/tmpplaylist.class.php @@ -40,8 +40,9 @@ class tmpPlaylist extends database_object { /** * Constructor - * This takes a playlist_id as an optional argument and gathers the information - * if not playlist_id is passed returns false (or if it isn't found + * This takes a playlist_id as an optional argument and gathers the + * information. If no playlist_id is passed or the requested one isn't + * found, return false. */ public function __construct($playlist_id='') { @@ -60,8 +61,8 @@ class tmpPlaylist extends database_object { /** * _get_info - * This is an internal (private) function that gathers the information for this object from the - * playlist_id that was passed in. + * This is an internal (private) function that gathers the information + * for this object from the playlist_id that was passed in. */ private function _get_info() { @@ -76,8 +77,8 @@ class tmpPlaylist extends database_object { /** * get_from_session - * This returns a playlist object based on the session that is passed to us - * this is used by the load_playlist on user for the most part + * This returns a playlist object based on the session that is passed to + * us. This is used by the load_playlist on user for the most part. */ public static function get_from_session($session_id) { @@ -115,8 +116,11 @@ class tmpPlaylist extends database_object { $client = new User($user_id); $username = Dba::escape($client->username); - $sql = "SELECT `tmp_playlist`.`id` FROM `tmp_playlist` LEFT JOIN `session` ON `session`.`id`=`tmp_playlist`.`session` " . - " WHERE `session`.`username`='$username' ORDER BY `session`.`expire` DESC"; + $sql = "SELECT `tmp_playlist`.`id` FROM `tmp_playlist` " . + "LEFT JOIN `session` ON " . + "`session`.`id`=`tmp_playlist`.`session` " . + "WHERE `session`.`username`='$username' " . + "ORDER BY `session`.`expire` DESC"; $db_results = Dba::read($sql); $data = Dba::fetch_assoc($db_results); @@ -127,18 +131,18 @@ class tmpPlaylist extends database_object { /** * get_items - * This returns an array of all object_ids currently in this tmpPlaylist. This - * has gotten a little more complicated because of type, the values are an array - * 0 being ID 1 being TYPE + * Returns an array of all object_ids currently in this tmpPlaylist. + * This has gotten a little more complicated because of type, the values + * are an array (0 being ID, 1 being TYPE). */ public function get_items() { - $order = 'ORDER BY id ASC'; + $id = Dba::escape($this->id); /* Select all objects from this playlist */ - $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id " . - "FROM tmp_playlist_data " . - "WHERE tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "' $order"; + $sql = "SELECT `object_type`, `id`, `object_id` " . + "FROM `tmp_playlist_data` " . + "WHERE `tmp_playlist`='$id' ORDER BY `id` ASC"; $db_results = Dba::read($sql); /* Define the array */ @@ -146,7 +150,8 @@ class tmpPlaylist extends database_object { while ($results = Dba::fetch_assoc($db_results)) { $key = $results['id']; - $items[$key] = array($results['object_type'],$results['object_id']); + $items[$key] = array($results['object_type'], + $results['object_id']); } return $items; @@ -155,17 +160,17 @@ class tmpPlaylist extends database_object { /** * get_next_object - * This returns the next object in the tmp_playlist most of the time this - * will just be the top entry, but if there is a base_playlist and no - * items in the playlist then it returns a random entry from the base_playlist + * This returns the next object in the tmp_playlist. Most of the time + * this will just be the top entry, but if there is a base_playlist and + * no items in the playlist then it returns a random entry from the + * base_playlist */ public function get_next_object() { - $tmp_id = Dba::escape($this->id); - $order = " ORDER BY tmp_playlist_data.id DESC"; + $id = Dba::escape($this->id); - $sql = "SELECT tmp_playlist_data.object_id FROM tmp_playlist_data " . - "WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT 1"; + $sql = "SELECT `object_id` FROM `tmp_playlist_data` " . + "WHERE `tmp_playlist`='$id' ORDER BY `id` LIMIT 1"; $db_results = Dba::read($sql); $results = Dba::fetch_assoc($db_results); @@ -176,11 +181,15 @@ class tmpPlaylist extends database_object { /** * count_items - * This returns a count of the total number of tracks that are in this tmp playlist + * This returns a count of the total number of tracks that are in this + * tmp playlist */ public function count_items() { - $sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'"; + $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); @@ -195,7 +204,10 @@ class tmpPlaylist extends database_object { */ public function clear() { - $sql = "DELETE FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'"; + $id = Dba::escape($this->id); + + $sql = "DELETE FROM `tmp_playlist_data` WHERE " . + "`tmp_playlist`='$id'"; $db_results = Dba::write($sql); return true; @@ -214,20 +226,15 @@ class tmpPlaylist extends database_object { $type = Dba::escape($data['type']); $object_type = Dba::escape($data['object_type']); - $sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`) " . + $sql = "INSERT INTO `tmp_playlist` " . + "(`session`,`type`,`object_type`) " . " VALUES ('$sessid','$type','$object_type')"; $db_results = Dba::write($sql); $id = Dba::insert_id(); - $do_prune = rand(0,4); - if ($do_prune%2) { - self::prune_playlists(); - self::prune_tracks(); - } - /* Clean any other playlists associated with this session */ - self::clean($sessid,$id); + self::session_clean($sessid, $id); return $id; @@ -240,9 +247,10 @@ class tmpPlaylist extends database_object { public function update_playlist($playlist_id) { $playlist_id = Dba::escape($playlist_id); - $tmp_id = Dba::escape($this->id); + $id = Dba::escape($this->id); - $sql = "UPDATE `tmp_playlist` SET tmp_playlist.base_playlist='$playlist_id' WHERE `id`='$tmp_id'"; + $sql = "UPDATE `tmp_playlist` SET " . + "`base_playlist`='$playlist_id' WHERE `id`='$id'"; $db_results = Dba::write($sql); return true; @@ -250,16 +258,17 @@ class tmpPlaylist extends database_object { } // update_playlist /** - * delete + * session_clean * This deletes any other tmp_playlists associated with this * session */ - public static function clean($sessid,$id) { + public static function session_clean($sessid, $id) { $sessid = Dba::escape($sessid); $id = Dba::escape($id); - $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$sessid' AND `id` != '$id'"; + $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$sessid' " . + "AND `id` != '$id'"; $db_results = Dba::write($sql); /* Remove associated tracks */ @@ -267,18 +276,29 @@ class tmpPlaylist extends database_object { return true; - } // delete + } // session_clean + + /** + * clean + * This cleans up old data + */ + public static function clean() { + self::prune_playlists(); + self::prune_tracks(); + } /** * prune_playlists - * This deletes and playlists that don't have an associated session + * This deletes any playlists that don't have an associated session */ public static function prune_playlists() { /* Just delete if no matching session row */ $sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " . - "LEFT JOIN session ON session.id=tmp_playlist.session " . - "WHERE session.id IS NULL AND tmp_playlist.type != 'vote'"; + "LEFT JOIN `session` " . + "ON `session`.`id`=`tmp_playlist`.`session` " . + "WHERE `session`.`id` IS NULL " . + "AND `tmp_playlist`.`type` != 'vote'"; $db_results = Dba::write($sql); return true; @@ -293,9 +313,10 @@ class tmpPlaylist extends database_object { // This prune is always run and clears data for playlists that // don't exist anymore - $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " . - "LEFT JOIN tmp_playlist ON tmp_playlist_data.tmp_playlist=tmp_playlist.id " . - "WHERE tmp_playlist.id IS NULL"; + $sql = "DELETE FROM `tmp_playlist_data` USING " . + "`tmp_playlist_data` LEFT JOIN `tmp_playlist` ON " . + "`tmp_playlist_data`.`tmp_playlist`=`tmp_playlist`.`id` " . + "WHERE `tmp_playlist`.id` IS NULL"; $db_results = Dba::write($sql); } // prune_tracks @@ -311,7 +332,8 @@ class tmpPlaylist extends database_object { $playlist_id = Dba::escape($this->id); $object_type = $object_type ? Dba::escape($object_type) : 'song'; - $sql = "INSERT INTO `tmp_playlist_data` (`object_id`,`tmp_playlist`,`object_type`) " . + $sql = "INSERT INTO `tmp_playlist_data` " . + "(`object_id`,`tmp_playlist`,`object_type`) " . " VALUES ('$object_id','$playlist_id','$object_type')"; $db_results = Dba::write($sql); @@ -342,8 +364,7 @@ class tmpPlaylist extends database_object { $id = Dba::escape($id); /* delete the track its self */ - $sql = "DELETE FROM `tmp_playlist_data` " . - " WHERE `id`='$id'"; + $sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$id'"; $db_results = Dba::write($sql); return true; diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php index d69078b0..761e4dc7 100644 --- a/lib/class/vauth.class.php +++ b/lib/class/vauth.class.php @@ -138,9 +138,9 @@ class vauth { $sql = "DELETE FROM `session` WHERE `expire` < '" . time() . "'"; $db_results = Dba::write($sql); - $sql = "DELETE FROM `tmp_browse` USING `tmp_browse` LEFT JOIN `session` ON `session`.`id`=`tmp_browse`.`sid` " . - "WHERE `session`.`id` IS NULL"; - $db_results = Dba::write($sql); + // Also clean up things that use sessions as keys + Query::clean(); + tmpPlaylist::clean(); return true; diff --git a/templates/show_tagcloud.inc.php b/templates/show_tagcloud.inc.php index a241b65a..5e907254 100644 --- a/templates/show_tagcloud.inc.php +++ b/templates/show_tagcloud.inc.php @@ -28,7 +28,7 @@ $web_path = Config::get('web_path'); $tag->format(); ?> <span id="click_<?php echo intval($tag->id); ?>" class="<?php echo $tag->f_class; ?>"><?php echo $tag->name; ?></span> -<?php echo Ajax::observe('click_' . intval($tag->id),'click',Ajax::action('?page=tag&action=add_filter&tag_id=' . intval($tag->id),'')); ?> +<?php echo Ajax::observe('click_' . intval($tag->id),'click',Ajax::action('?page=tag&action=add_filter&&browse_id=' . $browse->id . '&tag_id=' . intval($tag->id),'')); ?> <?php } ?> <?php if (!count($object_ids)) { ?> <span class="fatalerror"><?php echo _('Not Enough Data'); ?></span> |