diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-01-15 06:27:55 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-01-15 06:27:55 +0000 |
commit | 2d5ed879bd17024154e87de22c811bbfd0e69433 (patch) | |
tree | fbc39798312d1799510cc5ef0f103ebb554e3776 /lib | |
parent | e3e529394d526608e3ebeadb69234120f0f300ed (diff) | |
download | ampache-2d5ed879bd17024154e87de22c811bbfd0e69433.tar.gz ampache-2d5ed879bd17024154e87de22c811bbfd0e69433.tar.bz2 ampache-2d5ed879bd17024154e87de22c811bbfd0e69433.zip |
more flagging fixes, you can flag files now you just cant do anything about it
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/flag.class.php | 98 | ||||
-rw-r--r-- | lib/class/song.class.php | 112 | ||||
-rw-r--r-- | lib/ui.lib.php | 18 |
3 files changed, 191 insertions, 37 deletions
diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php new file mode 100644 index 00000000..fe5a0f8c --- /dev/null +++ b/lib/class/flag.class.php @@ -0,0 +1,98 @@ +<?php +/* + + Copyright 2001 - 2006 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 + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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. + +*/ + +/** + * Flag Class + * This handles flagging of songs, albums and artists + */ +class Flag { + + /* DB based variables */ + var $id; + var $user; + var $object_id; + var $object_type; + var $comment; + var $flag; + + /** + * Constructor + * This takes a flagged.id and then pulls in the information for said flag entry + */ + function Flag($flag_id=0) { + + $this->id = $flag_id; + + if (!$this->id) { return false; } + + $info = $this->_get_info(); + + $this->user = $info['user']; + $this->object_id = $info['object_id']; + $this->object_type = $info['object_type']; + $this->comment = $info['comment']; + $this->flag = $info['flag']; + + return true; + + } // flag + + /** + * _get_info + * Private function for getting the information for this object from the database + */ + function _get_info() { + + $id = sql_escape($this->id); + + $sql = "SELECT * FROM flagged WHERE id='$id'"; + $db_results = mysql_query($sql, dbh()); + + $results = mysql_fetch_assoc($db_results); + + return $results; + + } // _get_info + + /** + * add + * This adds a flag entry for an item, it takes an id, a type, the flag type + * and a comment and then inserts the mofo + */ + function add($id,$type,$flag,$comment) { + + $id = sql_escape($id); + $type = sql_escape($type); + $flag = sql_escape($flag); + $comment = sql_escape($comment); + + $sql = "INSERT INTO flagged (`object_id`,`object_type`,`flag`,`comment`) VALUES " . + " ('$id','$type','$flag','$comment')"; + $db_results = mysql_query($sql, dbh()); + + return true; + + } // add + +} //end of flag class + +?> diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 910aa1e7..44e90096 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -59,34 +59,30 @@ class Song { if ($song_id) { /* Assign id for use in get_info() */ - $this->id = $song_id; + $this->id = sql_escape($song_id); /* Get the information from the db */ if ($info = $this->get_info()) { /* Assign Vars */ - $this->file = $info->file; - $this->album = $info->album; - $this->artist = $info->artist; - $this->title = $info->title; - $this->comment = $info->comment; - $this->year = $info->year; - $this->bitrate = $info->bitrate; - $this->rate = $info->rate; - $this->mode = $info->mode; - $this->size = $info->size; - $this->time = $info->time; - $this->track = $info->track; - $this->genre = $info->genre; + $this->file = $info->file; + $this->album = $info->album; + $this->artist = $info->artist; + $this->title = $info->title; + $this->comment = $info->comment; + $this->year = $info->year; + $this->bitrate = $info->bitrate; + $this->rate = $info->rate; + $this->mode = $info->mode; + $this->size = $info->size; + $this->time = $info->time; + $this->track = $info->track; + $this->genre = $info->genre; $this->addition_time = $info->addition_time; - $this->catalog = $info->catalog; - $this->played = $info->played; + $this->catalog = $info->catalog; + $this->played = $info->played; $this->update_time = $info->update_time; - $this->flagid = $info->flagid; - $this->flaguser = $info->flaguser; - $this->flagtype = $info->flagtype; - $this->flagcomment = $info->flagcomment; - $this->enabled = $info->enabled; + $this->enabled = $info->enabled; // Format the Type of the song $this->format_type(); @@ -107,7 +103,7 @@ class Song { /* Grab the basic information from the catalog and return it */ $sql = "SELECT song.id,file,catalog,album,song.comment,year,artist,". "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,". - "addition_time FROM song WHERE song.id = '" . sql_escape($this->id) . "'"; + "addition_time FROM song WHERE song.id = '$this->id'"; $db_results = mysql_query($sql, dbh()); @@ -115,7 +111,7 @@ class Song { return $results; - } //get_info + } // get_info /*! @function format_type @@ -144,6 +140,7 @@ class Song { $this->mime = "audio/mpeg"; break; case "rm": + case "ra": $this->mime = "audio/x-realaudio"; break; case "flac"; @@ -163,6 +160,7 @@ class Song { } } // get_type + /*! @function get_album_songs @discussion gets an array of song objects based on album @@ -170,7 +168,7 @@ class Song { function get_album_songs($album_id) { $sql = "SELECT id FROM song WHERE album='$album_id'"; - $db_results = mysql_query($sql, libglue_param(libglue_param('dbh_name'))); + $db_results = mysql_query($sql, dbh()); while ($r = mysql_fetch_object($db_results)) { $results[] = new Song($r->id); @@ -236,6 +234,45 @@ class Song { } // get_genre_name /** + * get_flags + * This gets any flag information this song may have, it always + * returns an array as it may be possible to have more then + * one flag + */ + function get_flags() { + + $sql = "SELECT id,flag,comment FROM flagged WHERE object_type='song' AND object_id='$this->id'"; + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = $r; + } + + return $results; + + } // get_flag + + /** + * has_flag + * This just returns true or false depending on if this song is flagged for something + * We don't care what so we limit the SELECT to 1 + */ + function has_flag() { + + $sql = "SELECT id FROM flagged WHERE object_type='song' AND object_id='$this->id' LIMIT 1"; + $db_results = mysql_query($sql, dbh()); + + if (mysql_fetch_assoc($db_results)) { + return true; + } + + return false; + + } // has_flag + + /** * set_played * this checks to see if the current object has been played * if not then it sets it to played @@ -684,20 +721,21 @@ class Song { //TODO: fill out these cases once we have it working for m4a case "m4a": $return = false; - break; + break; default: $return = true; - break; + break; } // end switch return $return; - } // end native_stream + } // end native_stream - /*! - @function stream_cmd - @discussion test if the song type streams natively and if not returns a transcoding command from the config - */ + /** + * stream_cmd + * test if the song type streams natively and + * if not returns a transcoding command from the config + */ function stream_cmd() { $return = 'downsample_cmd'; @@ -706,16 +744,16 @@ class Song { switch ($this->type) { case "m4a": $return = "stream_cmd_m4a"; - break; + break; default: $return = "downsample_cmd"; - break; - } // end switch - } // end if not native_stream + break; + } // end switch + } // end if not native_stream return $return; - } // end stream_cmd + } // end stream_cmd -} //end of song class +} // end of song class ?> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 24b84ad5..6b984a01 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -1196,4 +1196,22 @@ function show_playlist_import() { } // show_playlist_import +/** + * show_songs + * Still not happy with this function, but at least it's in the right + * place now + */ +function show_songs ($song_ids, $playlist, $album=0) { + + $dbh = dbh(); + + $totaltime = 0; + $totalsize = 0; + + require (conf('prefix') . "/templates/show_songs.inc"); + + return true; + +} // show_songs + ?> |