diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 55f8dde2..a1cfabb7 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,9 +4,8 @@ -------------------------------------------------------------------------- v.3.3.2-Beta2 - - Removed old flagging tables and added a new one as part of - full flagging rewrite. - - Fixed play selected on playlists, it no longer always plays + - Rewrote entire Flag method, this includes the edit functionality + - Fixed play selected on playlists, it no longer always plays everything. - Fixed redirection after applying a rating to an album - Fixed a few typos in the xmlrpc code and playlists and fixed the diff --git a/flag.php b/flag.php index 7754214e..9976fb0b 100644 --- a/flag.php +++ b/flag.php @@ -20,32 +20,43 @@ */ -/* +/** + * Flag Document + * This is called for all of our flagging needs + */ - This will allow users to flag songs for having broken tags or bad rips. -*/ - -require_once("modules/init.php"); - -$action = scrub_in($_REQUEST['action']); -$song = scrub_in($_REQUEST['song']); - -if ( $action == 'flag_song') { - $flagged_type = scrub_in($_REQUEST['flagged_type']); - $comment = scrub_in($_REQUEST['comment']); - insert_flagged_song($song, $flagged_type, $comment); - $flag_text = _("Flagging song completed."); - $action = 'flag'; -} +require_once('modules/init.php'); show_template('header'); -if ( $action == 'flag' ) { - $type = 'show_flagged_form'; - $song_id = $song; - include(conf('prefix') . "/templates/flag.inc"); -} +$action = scrub_in($_REQUEST['action']); +$flag = new Flag($_REQUEST['flag_id']); + +/* Switch on the action */ +switch ($action) { + case 'remove_flag': + break; + case 'flag': + $id = scrub_in($_REQUEST['id']); + $type = scrub_in($_REQUEST['type']); + $flag_type = scrub_in($_REQUEST['flag_type']); + $comment = scrub_in($_REQUEST['comment']); + $flag->add($id,$type,$flag_type,$comment); + show_confirmation(_('Item Flagged'),_('The specified item has been flagged'),$_SESSION['source_page']); + break; + case 'show_flag': + /* Store where they came from */ + $_SESSION['source_page'] = return_referer(); + include(conf('prefix') . '/templates/show_flag.inc.php'); + break; + case 'show_remove_flag': + + break; + default: + + break; +} // end action switch show_footer(); ?> 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 @@ +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); @@ -235,6 +233,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 @@ -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 + ?> diff --git a/modules/init.php b/modules/init.php index 22ca81b6..27144e27 100644 --- a/modules/init.php +++ b/modules/init.php @@ -83,7 +83,7 @@ if (!$results['conf']['allow_stream_playback']) { $results['conf']['raw_web_path'] = $results['conf']['web_path']; $results['conf']['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['conf']['web_path']; -$results['conf']['version'] = '3.3.2-Beta2 (Build 002)'; +$results['conf']['version'] = '3.3.2-Beta2 (Build 003)'; $results['conf']['catalog_file_pattern']= 'mp3|mpc|m4p|m4a|mp4|aac|ogg|rm|wma|asf|flac|spx|ra'; $results['conf']['http_port'] = $_SERVER['SERVER_PORT']; if (!$results['conf']['prefix']) { @@ -164,15 +164,11 @@ require_once(conf('prefix') . "/lib/xmlrpc.php"); require_once(conf('prefix') . "/modules/xmlrpc/xmlrpc.inc"); if (conf('allow_slim_playback')) { - require_once(conf('prefix') . "/modules/slimserver/slim.class.php"); + require_once(conf('prefix') . '/modules/slimserver/slim.class.php'); } if (conf('allow_mpd_playback')) { - require_once(conf('prefix') . "/modules/mpd/mpd.class.php"); -} - -if (conf('allow_xmms2_playback')) { - require_once(conf('prefix') . "/modules/xmms2/xmms2.class.php"); + require_once(conf('prefix') . '/modules/mpd/mpd.class.php'); } if (conf('ratings')) { @@ -181,18 +177,19 @@ if (conf('ratings')) { } // Classes -require_once(conf('prefix') . "/lib/class/catalog.class.php"); -require_once(conf('prefix') . "/lib/class/stream.class.php"); -require_once(conf('prefix') . "/lib/class/playlist.class.php"); -require_once(conf('prefix') . "/lib/class/song.class.php"); -require_once(conf('prefix') . "/lib/class/view.class.php"); -require_once(conf('prefix') . "/lib/class/update.class.php"); -require_once(conf('prefix') . "/lib/class/user.class.php"); -require_once(conf('prefix') . "/lib/class/album.class.php"); -require_once(conf('prefix') . "/lib/class/artist.class.php"); -require_once(conf('prefix') . "/lib/class/access.class.php"); -require_once(conf('prefix') . "/lib/class/error.class.php"); -require_once(conf('prefix') . "/lib/class/genre.class.php"); +require_once(conf('prefix') . '/lib/class/catalog.class.php'); +require_once(conf('prefix') . '/lib/class/stream.class.php'); +require_once(conf('prefix') . '/lib/class/playlist.class.php'); +require_once(conf('prefix') . '/lib/class/song.class.php'); +require_once(conf('prefix') . '/lib/class/view.class.php'); +require_once(conf('prefix') . '/lib/class/update.class.php'); +require_once(conf('prefix') . '/lib/class/user.class.php'); +require_once(conf('prefix') . '/lib/class/album.class.php'); +require_once(conf('prefix') . '/lib/class/artist.class.php'); +require_once(conf('prefix') . '/lib/class/access.class.php'); +require_once(conf('prefix') . '/lib/class/error.class.php'); +require_once(conf('prefix') . '/lib/class/genre.class.php'); +require_once(conf('prefix') . '/lib/class/flag.class.php'); /* Set a new Error Handler */ $old_error_handler = set_error_handler("ampache_error_handler"); diff --git a/modules/lib.php b/modules/lib.php index f35efcc6..020e1819 100644 --- a/modules/lib.php +++ b/modules/lib.php @@ -38,42 +38,6 @@ function show_album_pulldown ($album) { } // show_album_pulldown() -/* - * show_flagged_popup($reason); - * - * Shows a listing of the flagged_types for when people want to mark - * a song as being broken in some way. - */ - -function show_flagged_popup($reason,$label='value', $name='flagged_type', $other='') { - - global $settings; - $dbh = dbh(); - - $access = $_SESSION['userdata']['access']; - - $query = "SELECT type,value FROM flagged_types"; - if ($access !== 'admin') { - $query .= " WHERE access = '$access'"; - } - $db_result = mysql_query($query, $dbh); - - echo "\n\n"; -} // show_flagged_popup() - - /* * delete_user_stats() * @@ -95,87 +59,6 @@ function delete_user_stats ($user) { } // delete_user_stats() -/* - * insert_flagged_song() - * - */ - -function insert_flagged_song($song, $reason, $comment) { - - $user = $_SESSION['userdata']['username']; - $time = time(); - $sql = "INSERT INTO flagged (user,song,type,comment,date)" . - " VALUES ('$user','$song', '$reason', '$comment', '$time')"; - $db_result = mysql_query($sql, dbh()); - -} // insert_flagged_song() - - -/* - * get_flagged(); - * - * Get all of the songs from the flagged table. These are songs that - * may or may not be broken. - * Deprecated by hopson on 7/27 - */ - -function get_flagged() { - - $dbh = dbh(); - - $sql = "SELECT flagged.id, user.username, type, song, date, comment" . - " FROM flagged, user" . - " WHERE flagged.user = user.username" . - " ORDER BY date"; - $db_result = mysql_query($sql, $dbh); - - $arr = array(); - - while ( $flag = mysql_fetch_object($db_result) ) { - $arr[] = $flag; - } - - return $arr; -} // get_flagged() - - -/* - * get_flagged_type($type); - * - * Return the text associated with this type. - */ - -function get_flagged_type($type) { - - $dbh = dbh(); - - $sql = "SELECT value FROM flagged_types WHERE type = '$type'"; - echo $sql; - $db_result = mysql_query($sql, $dbh); - - if ($flagged_type = mysql_fetch_object($db_result)) { - return $flagged_type->value; - } - else { - return FALSE; - } -} // get_flagged_type() - - -/* - * delete_flagged( $flag ); - * - */ - -function delete_flagged($flag) { - - $dbh = dbh(); - - $sql = "DELETE FROM flagged WHERE id = '$flag'"; - $db_result = mysql_query($sql, $dbh); -} // delete_flagged() - - /*********************************************************/ /* Functions for getting songs given artist, album or id */ /*********************************************************/ @@ -285,30 +168,6 @@ function get_songs_from_type ($type, $results, $artist_id = 0) { } -/*********************************************************/ -/* This is the main song display function. I found tieing it to the playlist functions - was really handy in getting added functionality at no cost. -/* Lets tie it to album too, so we can show art ;) */ -/*********************************************************/ -/* One symbol, m(__)m */ -function show_songs ($song_ids, $playlist, $album=0) { - - $dbh = dbh(); - - // Get info about current user - $user = $GLOBALS['user']; - - $totaltime = 0; - $totalsize = 0; - - require (conf('prefix') . "/templates/show_songs.inc"); - - return true; - -} // function show_songs - - - function show_playlist_form () { print <<format_song(); - if (!preg_match('/\.mp3$/', $song->file)) { - echo "

Ampache can only edit MP3 file tags currently.
"; - echo "Back"; - return; - } // end if (!preg_match('/\.mp3$/',$song->file)) -?> - -

-

- - -

- - -
- - - - - - - - - - - - - - - - - - - - - -
:file; ?>
:f_title; ?> by f_artist_full; ?>
:
: -
  - " /> - -
- -
- - -

View Flagged Songs

-

This is the list of songs that have been flagged by your Ampache users. Use - this list to determine what songs you need to re-rip or tags you need to update.

- -
- - - - - - - - - - song); - $song->format_song(); - $alt_title = $song->title; - $artist = $song->f_artist; - $alt_artist = $song->f_full_artist; - - echo "". - "". - "". - ""; - /*echo "\n";*/ - if ($flag->type === 'newid3') { - echo ""; - } else { - echo ""; - echo "\n"; - } // end if ($flag->type === 'newid3') and else - } // end foreach ($flags as $flag) - ?> - -
 SongFlagNew Flag:Flagged byID3 Update:
id."\" name=\"flag[]\" value=\"".$flag->id."\">song\" title=\"$alt_title\">$song->f_title by ". - "artist_id\" title=\"$alt_artist\">$artist$flag->type"; - $onchange = "onchange=\"document.getElementById('flag_".$flag->id."').checked='checked';\""; - show_flagged_popup($flag->type, 'type', $flag->id."_newflag", $onchange); - echo "".$flag->username."
".date('m/d/y',$flag->date)."
id\">Fixed
id."\" value=\"accept\" />Accept"; - echo "id."\" value=\"reject\" />Reject
song."\">edit/view
-
- -

You don't have any flagged songs.

- diff --git a/templates/show_flag.inc.php b/templates/show_flag.inc.php new file mode 100644 index 00000000..571d822d --- /dev/null +++ b/templates/show_flag.inc.php @@ -0,0 +1,136 @@ +format_song(); + $title = scrub_out($song->f_title . " by " . $song->f_artist_full); + $file = scrub_out($song->file); + break; + case 'album': + break; + case 'artist': + break; + default: + break; +} // end type switch +?> + +

+

+ +
+ + + + + + + + + + + + + + + + + + + + + +
:
:
: + +
:
  + + + + +
+
+ +

View Flagged Songs

+

This is the list of songs that have been flagged by your Ampache users. Use +this list to determine what songs you need to re-rip or tags you need to update.

+ +
+ + + + + + + + + + song); + $song->format_song(); + $alt_title = $song->title; + $artist = $song->f_artist; + $alt_artist = $song->f_full_artist; + + echo "". + "". + "". + ""; + /*echo "\n";*/ + if ($flag->type === 'newid3') { + echo ""; + } else { + echo ""; + echo "\n"; + } // end if ($flag->type === 'newid3') and else + } // end foreach ($flags as $flag) + ?> + +
 SongFlagNew Flag:Flagged byID3 Update:
id."\" name=\"flag[]\" value=\"".$flag->id."\">song\" title=\"$alt_title\">$song->f_title by ". + "artist_id\" title=\"$alt_artist\">$artist$flag->type"; + $onchange = "onchange=\"document.getElementById('flag_".$flag->id."').checked='checked';\""; + show_flagged_popup($flag->type, 'type', $flag->id."_newflag", $onchange); + echo "".$flag->username."
".date('m/d/y',$flag->date)."
id\">Fixed
id."\" value=\"accept\" />Accept"; + echo "id."\" value=\"reject\" />Reject
song."\">edit/view
+
+?php } else { ?> +

You don't have any flagged songs.

+ diff --git a/templates/show_songs.inc b/templates/show_songs.inc index e8078231..df1bfeba 100644 --- a/templates/show_songs.inc +++ b/templates/show_songs.inc @@ -21,9 +21,6 @@ */ $web_path = conf('web_path'); -// Need to set the username for the song ratings. -$username = $GLOBALS['user']->username; - /* If it's a playlist and they've got rights */ if (is_object($playlist) && ($GLOBALS['user']->username == $playlist->user || $GLOBALS['user']->has_access('100'))) { $tab = 1; @@ -46,7 +43,6 @@ if (is_object($playlist) && ($GLOBALS['user']->username == $playlist->user || $G - @@ -97,6 +93,7 @@ foreach ($song_ids as $song_id) { + has_flag()) { echo "**"; } ?> >f_title); ?> @@ -120,25 +117,21 @@ foreach ($song_ids as $song_id) { f_genre; ?> - f_style; ?> title="flagcomment; ?>"> - flagtype; ?> - - has_access('100')) { ?> - Edit | Flag | + Flag + has_access('100')) { ?> + | Edit | enabled) { ?> Disable Enable - - Flag - prefs['download']) { ?> + prefs['download']) { ?> | title . "." . $song->type); ?>"> - prefs['direct_link']) { ?> - | title . "." . $song->type); ?>"> + prefs['direct_link']) { ?> + | title . "." . $song->type); ?>"> @@ -150,9 +143,6 @@ foreach ($song_ids as $song_id) { MB - +