diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-03-15 16:16:04 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-03-15 16:16:04 +0000 |
commit | fdb7c58cb160c5f8f0f0327c11cba93226e062f6 (patch) | |
tree | 6cf57a740799a3a9b9dc9a035ccb66e1e54b053f /lib | |
parent | 86ff429b366080b9203e5ddb1740339c64013853 (diff) | |
download | ampache-fdb7c58cb160c5f8f0f0327c11cba93226e062f6.tar.gz ampache-fdb7c58cb160c5f8f0f0327c11cba93226e062f6.tar.bz2 ampache-fdb7c58cb160c5f8f0f0327c11cba93226e062f6.zip |
fix typo causing height to not display on art retrival, update to db allowing gc of tmp_browse, add extension to api album art image urls
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/album.class.php | 34 | ||||
-rw-r--r-- | lib/class/core.class.php | 2 | ||||
-rw-r--r-- | lib/class/query.class.php | 10 | ||||
-rw-r--r-- | lib/class/stream.class.php | 55 | ||||
-rw-r--r-- | lib/class/update.class.php | 30 | ||||
-rw-r--r-- | lib/class/vauth.class.php | 4 | ||||
-rw-r--r-- | lib/class/xmldata.class.php | 2 | ||||
-rw-r--r-- | lib/init.php | 1 | ||||
-rw-r--r-- | lib/stream.lib.php | 85 | ||||
-rw-r--r-- | lib/ui.lib.php | 16 |
10 files changed, 138 insertions, 101 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 438a9033..017e8147 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -959,6 +959,40 @@ class Album extends database_object { } // get_image_from_source + /** + * get_art_url + * This returns the art URL for the album + */ + public static function get_art_url($album_id,$sid=false) { + + $sid = $sid ? scrub_out($sid) : session_id(); + + $sql = "SELECT `art_mime`,`thumb_mime` FROM `album_data` WHERE `album_id`='" . Dba::escape($album_id) . "'"; + $db_results = Dba::read($sql); + + $row = Dba::fetch_assoc($db_results); + + $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime']; + + switch ($type) { + case 'image/gif': + $type = 'gif'; + break; + case 'image/png': + $type = 'png'; + break; + default: + case 'image/jpeg': + $type = 'jpg'; + break; + } // end type translation + + $name = 'art.' . $type; + + Config::get('web_path') . '/image.php?id=' . scrub_out($album_id) . '&auth=' . $sid . '&name=' . $name; + + } // get_art_url + } //end of album class ?> diff --git a/lib/class/core.class.php b/lib/class/core.class.php index c1d07e86..d93b542a 100644 --- a/lib/class/core.class.php +++ b/lib/class/core.class.php @@ -106,7 +106,7 @@ class Core { if (!$width || !$height) { return false; } - return array('width'=>$width,'heigh'=>$height); + return array('width'=>$width,'height'=>$height); } // image_dimensions diff --git a/lib/class/query.class.php b/lib/class/query.class.php index b1155d1f..9b219f4b 100644 --- a/lib/class/query.class.php +++ b/lib/class/query.class.php @@ -521,9 +521,10 @@ class Query { if (!self::is_simple()) { // If not then we're going to need to read from the database :( - $sid = session_id() . '::' . self::$type; + $sid = session_id(); + $type = Dba::escape(self::$type); - $sql = "SELECT `data` FROM `tmp_browse` WHERE `sid`='$sid'"; + $sql = "SELECT `data` FROM `tmp_browse` WHERE `sid`='$sid' AND `type`='$type'"; $db_results = Dba::read($sql); $row = Dba::fetch_assoc($db_results); @@ -1195,10 +1196,11 @@ class Query { // Only do this if it's a not a simple browse if (!self::is_simple()) { - $sid = session_id() . '::' . self::$type; + $sid = Dba::escape(session_id()); $data = Dba::escape(serialize($object_ids)); + $type = Dba::escape(self::$type); - $sql = "REPLACE INTO `tmp_browse` SET `data`='$data', `sid`='$sid'"; + $sql = "REPLACE INTO `tmp_browse` SET `data`='$data', `sid`='$sid',`type`='$type'"; $db_results = Dba::write($sql); self::$total_objects = count($object_ids); diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 5676490b..d4853780 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -722,14 +722,15 @@ class Stream { * This fucntion is used by the /play/index.php song * primarily, but could be used by other people */ - public static function insert_now_playing($song_id,$uid,$length,$sid,$type) { + public static function insert_now_playing($oid,$uid,$length,$sid,$type) { $time = time()+$length; $session_id = Dba::escape($sid); + $object_type = 'song'; // Do a replace into ensuring that this client always only has a single row - $sql = "REPLACE INTO `now_playing` (`id`,`song_id`, `user`, `expire`)" . - " VALUES ('$session_id','$song_id', '$uid', '$time')"; + $sql = "REPLACE INTO `now_playing` (`id`,`object_id`,`object_type`, `user`, `expire`)" . + " VALUES ('$session_id','$oid','$object_type', '$uid', '$time')"; $db_result = Dba::write($sql); } // insert_now_playing @@ -749,6 +750,54 @@ class Stream { } // clear_now_playing /** + * get_now_playing + * This returns the now playing information + */ + public static function get_now_playing($filter=NULL) { + + $sql = "SELECT `session_stream`.`agent`,`now_playing`.* " . + "FROM `now_playing` " . + "LEFT JOIN `session_stream` ON `session_stream`.`id`=`now_playing`.`id` " . + "ORDER BY `now_playing`.`expire` DESC"; + $db_results = Dba::read($sql); + + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $type = $row['object_type']; + $media = new $type($row['object_id']); + $media->format(); + $client = new User($row['user']); + $results[] = array('media'=>$media,'client'=>$client,'agent'=>$row['agent'],'expire'=>$row['expire']); + } // end while + + return $results; + + } // get_now_playing + + /** + * check_lock_media + * This checks to see if the media is already being played, if it is then it returns false + * else return true + */ + public static function check_lock_media($media_id,$type) { + + $media_id = Dba::escape($media_id); + $type = Dba::escape($type); + + $sql = "SELECT `object_id` FROM `now_playing` WHERE `object_id`='$media_id' AND `object_type`='$type'"; + $db_results = Dba::read($sql); + + if (Dba::num_rows($db_results)) { + debug_event('Stream','Unable to play media currently locked by another user','3'); + return false; + } + + return true; + + } // check_lock_media + + /** * auto_init * This is called on class load it sets the session */ diff --git a/lib/class/update.class.php b/lib/class/update.class.php index e850556d..938d979c 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -315,9 +315,13 @@ class Update { $version[] = array('version'=>'350007','description'=>$update_string); - $update_string = '- Modify Now Playing table to handle Videos'; + $update_string = '- Modify Now Playing table to handle Videos<br />' . + '- Modify tmp_browse to make it easier to prune<br />' . + '- Add missing indexes to the _data tables<br />' . + '- Drop unused song.hash<br />' . + '- Add addition_time and update_time to video table<br />'; - //$version[] = array('version'=>'350008','description'=>$update_string); + $version[] = array('version'=>'350008','description'=>$update_string); return $version; @@ -365,7 +369,7 @@ class Update { /* Nuke All Active session before we start the mojo */ $sql = "TRUNCATE session"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Prevent the script from timing out, which could be bad set_time_limit(0); @@ -1708,18 +1712,27 @@ class Update { */ public static function update_350008() { - $sql = "ALTER TABLE `now_playing` ALTER `song_id` `object_id` INT( 11 ) UNSIGNED NOT NULL"; + $sql = "ALTER TABLE `now_playing` CHANGE `song_id` `object_id` INT( 11 ) UNSIGNED NOT NULL"; $db_results = Dba::write($sql); $sql = "ALTER TABLE `now_playing` ADD `object_type` VARCHAR ( 255 ) NOT NULL AFTER `object_id`"; $db_results = Dba::write($sql); + $sql = "ALTER TABLE `now_playing` ADD INDEX ( `expire` )"; + $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD `addition_time` INT( 11 ) UNSIGNED NOT NULL AFTER `mime`"; $db_results = Dba::write($sql); $sql = "ALTER TABLE `video` ADD `update_time` INT( 11 ) UNSIGNED NULL AFTER `addition_time`"; $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD INDEX (`addition_time`)"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `video` ADD INDEX (`update_time`)"; + $db_results = Dba::write($sql); + $sql = "ALTER TABLE `artist_data` ADD INDEX ( `art_mime` )"; $db_results = Dba::write($sql); @@ -1727,10 +1740,15 @@ class Update { $db_results = Dba::write($sql); $sql = "ALTER TABLE `tmp_browse` ADD `type` VARCHAR ( 255 ) NOT NULL AFTER `sid`"; - $db_results = Dba::wirte($sql); + $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tmp_browse` ADD INDEX (`type)"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `song` DROP `hash`"; + $db_results = Dba::write($sql); - //self::set_version('db_version','350008'); + self::set_version('db_version','350008'); } // update_350008 diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php index 28c9d915..f9e614f9 100644 --- a/lib/class/vauth.class.php +++ b/lib/class/vauth.class.php @@ -137,6 +137,10 @@ 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); + return true; } // gc diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index cfb8805f..c25a5560 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -319,7 +319,7 @@ class xmlData { $rating = new Rating($song_id,'song'); - $art_url = Config::get('web_path') . '/image.php?id=' . $song->album . '&auth=' . scrub_out($_REQUEST['auth']); + $art_url = Album::get_art_url($song->album,$_REQUEST['auth']); $string .= "<song id=\"$song->id\">\n" . "\t<title><![CDATA[$song->title]]></title>\n" . diff --git a/lib/init.php b/lib/init.php index f6ffc311..26cc6fc0 100644 --- a/lib/init.php +++ b/lib/init.php @@ -130,7 +130,6 @@ require_once $prefix . '/lib/ui.lib.php'; require_once $prefix . '/lib/gettext.php'; require_once $prefix . '/lib/batch.lib.php'; require_once $prefix . '/lib/themes.php'; -require_once $prefix . '/lib/stream.lib.php'; require_once $prefix . '/lib/xmlrpc.php'; require_once $prefix . '/lib/class/localplay.abstract.php'; require_once $prefix . '/lib/class/database_object.abstract.php'; diff --git a/lib/stream.lib.php b/lib/stream.lib.php deleted file mode 100644 index 8cc92d50..00000000 --- a/lib/stream.lib.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php -/* - - Copyright Ampache.org - All Rights Reserved - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License v2 - as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -/** - * show_now_playing - * shows the now playing template - */ -function show_now_playing() { - - // GC! - Stream::gc_session(); - Stream::gc_now_playing(); - - $web_path = Config::get('web_path'); - $results = get_now_playing(); - require Config::get('prefix') . '/templates/show_now_playing.inc.php'; - -} // show_now_playing - -/** - * get_now_playing - * gets the now playing information - */ -function get_now_playing($filter='') { - - $sql = "SELECT `session_stream`.`agent`,`now_playing`.`song_id`,`now_playing`.`user`,`now_playing`.`expire` " . - "FROM `now_playing` " . - "LEFT JOIN `session_stream` ON `session_stream`.`id`=`now_playing`.`id` " . - "ORDER BY `now_playing`.`expire` DESC"; - $db_results = Dba::query($sql); - - $results = array(); - - /* While we've got stuff playing */ - while ($r = Dba::fetch_assoc($db_results)) { - $song = new Song($r['song_id']); - $song->format(); - $np_user = new User($r['user']); - $results[] = array('song'=>$song,'user'=>$np_user,'agent'=>$r['agent'],'expire'=>$r['expire']); - } // end while - - return $results; - -} // get_now_playing - - -/** - * check_lock_songs - * This checks to see if the song is already playing, if it is then it prevents the user - * from streaming it - */ -function check_lock_songs($song_id) { - - $sql = "SELECT `song_id` FROM `now_playing` " . - "WHERE `song_id` = '$song_id'"; - $db_results = Dba::query($sql); - - if (Dba::num_rows($db_results)) { - debug_event('lock_songs','Song Already Playing, skipping...','5'); - return false; - } - - return true; - -} // check_lock_songs - -?> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 93e8aeed..5a451a74 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -844,5 +844,21 @@ function toggle_visible($element) { } // toggle_visible +/** + * show_now_playing + * This shows the now playing templates and does some garbage colleciont + * this should really be somewhere else + */ +function show_now_playing() { + + Stream::gc_session(); + Stream::gc_now_playing(); + + $web_path = Config::get('web_path'); + $results = Stream::get_now_playing(); + require_once Config::get('prefix') . '/templates/show_now_playing.inc.php'; + +} // show_now_playing + ?> |